// called by WebSocketManager public void StartSession(string socketId, string bundleId, string dumpId, string initialCommand) { try { System.Console.WriteLine($"StartSession ({socketId}): {bundleId}, {dumpId}"); if (string.IsNullOrEmpty(bundleId) || string.IsNullOrEmpty(dumpId)) { return; } var dumpInfo = dumpRepo.Get(bundleId, dumpId); var dumpFilePath = dumpRepo.GetDumpFilePath(bundleId, dumpId); var dumpFilePathInfo = dumpFilePath != null ? new FileInfo(dumpFilePath) : null; var workingDirectory = dumpFilePathInfo?.Directory; var sdResult = dumpRepo.GetResult(bundleId, dumpId).Result; bool is64bit = sdResult?.SystemContext.ProcessArchitecture.Contains("64") ?? true; // default to 64 bit in case it's not known ConsoleAppManager mgr = null; var initialCommands = new List <string>(); if (dumpInfo.DumpFileName.EndsWith(".dmp", StringComparison.OrdinalIgnoreCase)) { mgr = StartCdb(socketId, workingDirectory, dumpFilePathInfo, is64bit, bundleId, dumpId); initialCommands.Add(".cordll -ve -u -l"); // load DAC and SOS } else { throw new NotSupportedException($"file extension of '{dumpInfo.DumpFileName}' not supported for interactive mode."); } if (mgr != null && !string.IsNullOrEmpty(initialCommand)) { initialCommands.Add(WebUtility.UrlDecode(initialCommand)); } RunInitialCommandsAsync(socketId, mgr, initialCommands); } catch (Exception e) { Console.WriteLine($"Error in StartSession: {e}"); } }
private void RunInitialCommandsAsync(string socketId, ConsoleAppManager mgr, List <string> initialCommands) { Task.Run(async() => { await Task.Delay(1000); // that's pretty ugly. we actually would need to wait until the console is ready for input, then run this command. foreach (var cmd in initialCommands) { await WriteLineAndTellClient(socketId, cmd, mgr); await Task.Delay(1000); // that's pretty ugly. we actually would need to wait until the console is ready for input, then run this command. } }); }
private ConsoleAppManager RunConsoleApp(string socketId, DirectoryInfo workingDir, FileInfo dumpPath, string command, DumpIdentifier id) { command = command.Replace("{bundleid}", id.BundleId); command = command.Replace("{dumpid}", id.DumpId); command = command.Replace("{dumppath}", dumpPath?.FullName); command = command.Replace("{dumpname}", dumpPath?.Name); command = command.Replace("{dumpdir}", workingDir?.FullName); Utility.ExtractExe(command, out string executable, out string arguments); var mgr = new ConsoleAppManager(executable, workingDir); socketIdToProcess[socketId] = mgr; processToSocketId[mgr] = socketId; mgr.StandartTextReceived += Mgr_StandartTextReceived; mgr.ErrorTextReceived += Mgr_ErrorTextReceived; mgr.ExecuteAsync(arguments); return(mgr); }
private void StartCdb(string socketId, string dumpPath, bool is64Bit) { string cdbPath; if (is64Bit) { cdbPath = settings.Value.Cdbx64; } else { cdbPath = settings.Value.Cdbx86; } var mgr = new ConsoleAppManager(cdbPath); socketIdToProcess[socketId] = mgr; processToSocketId[mgr] = socketId; mgr.StandartTextReceived += Mgr_StandartTextReceived; mgr.ErrorTextReceived += Mgr_ErrorTextReceived; mgr.ExecuteAsync($"-z {dumpPath}"); mgr.WriteLine(".cordll -ve -u -l"); // load DAC and SOS }
private async Task WriteLineAndTellClient(string socketId, string line, ConsoleAppManager mgr) { await SendToClient(socketId, line + "\n", null); mgr.WriteLine(line); }