private void SaveToScript() { // convert the script string back to a script StackHashScript script = new StackHashScript(); bool isNoCommentCommand = false; string line = null; for (int i = 0; i < textScript.LineCount; i++) { isNoCommentCommand = false; line = textScript.GetLineText(i).Trim(); // for certain commands comments are ignored (because the * is part of the command) foreach (string noCommentCommand in NoCommentCommands) { if (line.IndexOf(noCommentCommand, StringComparison.OrdinalIgnoreCase) == 0) { isNoCommentCommand = true; break; } } if (isNoCommentCommand) { StackHashScriptLine scriptLine = new StackHashScriptLine(); scriptLine.Command = line; script.Add(scriptLine); } else { StackHashScriptLine scriptLine = new StackHashScriptLine(); int lastCommentSeparator = line.LastIndexOf(ScriptCommentSeparator); if (lastCommentSeparator > 0) { scriptLine.Command = line.Substring(0, lastCommentSeparator).Trim(); scriptLine.Comment = line.Substring(lastCommentSeparator + 1).Trim(); } else { scriptLine.Command = line; } script.Add(scriptLine); } } _scriptSettings.Name = textScriptName.Text; _scriptSettings.RunAutomatically = _contextValidation.RunAutomatically; _scriptSettings.Script = script; _scriptSettings.DumpType = _contextValidation.DumpType.Type; }
public void ScriptGenerate2LinesOtherWayAround() { String testScriptName = "Name"; String testCommand2 = @"$$ Command 1"; String testComment2 = @"Demo Comment 1"; String testCommand1 = @"$$ Command 2"; String testComment1 = @"Another comment"; // Create a script - empty. StackHashScript script = new StackHashScript(); script.Add(new StackHashScriptLine(testCommand1, testComment1)); script.Add(new StackHashScriptLine(testCommand2, testComment2)); StackHashScriptSettings scriptSettings = new StackHashScriptSettings(testScriptName, script); String tempFileName = m_TempPath + "\\GeneratedScript.wds"; String outputFileName = "c:\\test\\results.log"; String symPath = null; String exePath = null; String srcPath = null; scriptSettings.GenerateScriptFile(tempFileName, outputFileName, ref symPath, ref exePath, ref srcPath); Assert.AreEqual(null, symPath); Assert.AreEqual(null, exePath); Assert.AreEqual(null, srcPath); // Read all of the data in. String[] allLines = File.ReadAllLines(tempFileName); Assert.AreEqual(true, File.Exists(tempFileName)); // Should contain the script header comment plus one command and one comment line for each command. Assert.AreEqual(10, allLines.Length); Assert.AreEqual(true, allLines[0].Contains(outputFileName)); Assert.AreEqual(true, allLines[1].Contains(testScriptName)); Assert.AreEqual(true, allLines[1].Contains(scriptSettings.LastModifiedDate.ToString(CultureInfo.InvariantCulture))); Assert.AreEqual(true, allLines[2].Contains(scriptSettings.Script[0].Comment)); Assert.AreEqual(true, allLines[3].StartsWith(scriptSettings.Script[0].Command)); Assert.AreEqual(true, allLines[4].Contains(scriptSettings.Script[0].Comment)); Assert.AreEqual(true, allLines[5].Contains(scriptSettings.Script[1].Comment)); Assert.AreEqual(true, allLines[6].StartsWith(scriptSettings.Script[1].Command)); Assert.AreEqual(true, allLines[7].Contains(scriptSettings.Script[1].Comment)); Assert.AreEqual(true, allLines[8].Contains("Script Complete")); Assert.AreEqual(true, allLines[9].Contains(".logclose")); }
public void ScriptContainsPssCorIa64Clr4() { String testScriptName = "Name"; String testCommand = @".load psscor.dll"; String testComment = @"loads psscor from correct location"; StackHashScript script = new StackHashScript(); script.Add(new StackHashScriptLine(testCommand, testComment)); StackHashScriptSettings scriptSettings = new StackHashScriptSettings(testScriptName, script); scriptSettings.FixUp(StackHashScriptDumpArchitecture.IA64, "4.0.2355.2233", "C:\\test"); Assert.AreEqual(0, String.Compare(".load C:\\test\\psscor4\\ia64\\psscor4.dll", scriptSettings.Script[0].Command, StringComparison.OrdinalIgnoreCase)); }
private void scriptSaveLoadNCommands(int numCommands, bool addComment) { StackHashScript script = new StackHashScript(); for (int i = 0; i < numCommands; i++) { String command = "command" + i.ToString(); String comment = null; if (addComment) { comment = "comment" + i.ToString(); } script.Add(new StackHashScriptLine(command, comment)); } String testScriptName = m_TempPath + "\\scriptsettings.wds"; StackHashScriptSettings scriptSettings = new StackHashScriptSettings(testScriptName, script); scriptSettings.Name = "TestName"; scriptSettings.CreationDate = DateTime.Now.ToUniversalTime(); scriptSettings.LastModifiedDate = DateTime.Now.ToUniversalTime(); scriptSettings.Owner = StackHashScriptOwner.System; scriptSettings.RunAutomatically = true; scriptSettings.Version = 2; scriptSettings.Save(testScriptName); // And load in again and compare. StackHashScriptSettings loadedSettings = StackHashScriptSettings.Load(testScriptName); Assert.AreEqual(scriptSettings.CreationDate, loadedSettings.CreationDate); Assert.AreEqual(scriptSettings.LastModifiedDate, loadedSettings.LastModifiedDate); Assert.AreEqual(scriptSettings.Name, loadedSettings.Name); Assert.AreEqual(scriptSettings.Script.Count, loadedSettings.Script.Count); Assert.AreEqual(scriptSettings.RunAutomatically, loadedSettings.RunAutomatically); Assert.AreEqual(scriptSettings.Version, loadedSettings.Version); Assert.AreEqual(scriptSettings.Owner, loadedSettings.Owner); for (int i = 0; i < scriptSettings.Script.Count; i++) { Assert.AreEqual(scriptSettings.Script[i].Command, loadedSettings.Script[i].Command); Assert.AreEqual(scriptSettings.Script[i].Comment, loadedSettings.Script[i].Comment); } }
public void ScriptConstructor() { String testCommand = @"$$ This is a simple command"; String testComment = @"Just a demo"; String testScriptName = "Name"; // Create a script. StackHashScript script = new StackHashScript(); script.Add(new StackHashScriptLine(testCommand, testComment)); StackHashScriptSettings scriptSettings = new StackHashScriptSettings(testScriptName, script); Assert.AreEqual(testCommand, script[0].Command); Assert.AreEqual(testComment, script[0].Comment); Assert.AreEqual(StackHashScriptDumpType.UnmanagedAndManaged, scriptSettings.DumpType); Assert.AreEqual(testScriptName, scriptSettings.Name); Assert.AreEqual(scriptSettings.LastModifiedDate, scriptSettings.CreationDate); Assert.AreEqual(true, DateTime.Now.ToUniversalTime().Second - scriptSettings.CreationDate.Second <= 2); }
public void ScriptGenerate1Line() { String testScriptName = "Name"; String testCommand = @"$$ This is a simple command"; String testComment = @"Just a demo"; // Create a script - empty. StackHashScript script = new StackHashScript(); script.Add(new StackHashScriptLine(testCommand, testComment)); StackHashScriptSettings scriptSettings = new StackHashScriptSettings(testScriptName, script); String m_TempFileName = m_TempPath + "\\GeneratedScript.wds"; String outputFileName = "c:\\test\\results.log"; String symPath = null; String exePath = null; String srcPath = null; scriptSettings.GenerateScriptFile(m_TempFileName, outputFileName, ref symPath, ref exePath, ref srcPath); Assert.AreEqual(null, symPath); Assert.AreEqual(null, exePath); Assert.AreEqual(null, srcPath); // Read all of the data in. String[] allLines = File.ReadAllLines(m_TempFileName); Assert.AreEqual(true, File.Exists(m_TempFileName)); // Should contain the script header comment, and one command comment and one command. Assert.AreEqual(7, allLines.Length); Assert.AreEqual(true, allLines[0].Contains(outputFileName)); Assert.AreEqual(true, allLines[1].Contains(testScriptName)); Assert.AreEqual(true, allLines[1].Contains(scriptSettings.LastModifiedDate.ToString(CultureInfo.InvariantCulture))); Assert.AreEqual(true, allLines[2].Contains(scriptSettings.Script[0].Comment)); Assert.AreEqual(true, allLines[3].StartsWith(scriptSettings.Script[0].Command)); Assert.AreEqual(true, allLines[4].Contains(scriptSettings.Script[0].Comment)); Assert.AreEqual(true, allLines[5].Contains("Script Complete")); Assert.AreEqual(true, allLines[6].Contains(".logclose")); }
public void RunSimpleScript() { // Create a test script. String testScriptName = "ScriptName"; String testCommand = @"r"; String testComment = @"Just a demo"; StackHashScript script = new StackHashScript(); script.Add(new StackHashScriptLine(testCommand, testComment)); StackHashScriptSettings scriptSettings = new StackHashScriptSettings(testScriptName, script); String scriptFileName = m_TempPath + @"\GeneratedScript.wds"; String resultsFileName = m_TempPath + @"\Results.log"; String symPath = null; String exePath = null; String srcPath = null; scriptSettings.GenerateScriptFile(scriptFileName, resultsFileName, ref symPath, ref exePath, ref srcPath); Assert.AreEqual(null, symPath); Assert.AreEqual(null, exePath); Assert.AreEqual(null, srcPath); // Run the script with the debugger. Windbg debugger = new Windbg(); String dumpFileName = TestSettings.TestDataFolder + @"Dumps\Cucku.exe.mdmp"; StackHashDebuggerSettings debuggerSettings = new StackHashDebuggerSettings(); debuggerSettings.DebuggerPathAndFileName = StackHashDebuggerSettings.Default32BitDebuggerPathAndFileName; debuggerSettings.SymbolPath = StackHashSearchPath.DefaultSymbolPath; debugger.RunScript(debuggerSettings, true, scriptFileName, dumpFileName, resultsFileName, symPath, exePath, srcPath); Assert.AreEqual(true, File.Exists(resultsFileName)); String[] allResults = File.ReadAllLines(resultsFileName, Encoding.Unicode); Assert.AreEqual(true, allResults.Length > 0); }
public void simpleScriptNCommands(int numCommands, bool addComment) { // Create a test script. String testScriptName = "ScriptName"; String testCommand = @"r"; String testComment = null; if (addComment) { testComment = @"Just a demo"; } StackHashScript script = new StackHashScript(); for (int i = 0; i < numCommands; i++) { script.Add(new StackHashScriptLine(testCommand, testComment + i.ToString())); } StackHashScriptSettings scriptSettings = new StackHashScriptSettings(testScriptName, script); String scriptFileName = m_TempPath + @"\GeneratedScript.wds"; String resultsFileName = m_TempPath + @"\Results.log"; String symPath = null; String exePath = null; String srcPath = null; scriptSettings.GenerateScriptFile(scriptFileName, resultsFileName, ref symPath, ref exePath, ref srcPath); Assert.AreEqual(null, symPath); Assert.AreEqual(null, exePath); Assert.AreEqual(null, srcPath); // Run the script with the debugger. Windbg debugger = new Windbg(); String dumpFileName = TestSettings.TestDataFolder + @"Dumps\Cucku.exe.mdmp"; DateTime startTime = DateTime.Now.ToUniversalTime(); StackHashDebuggerSettings debuggerSettings = new StackHashDebuggerSettings(); debuggerSettings.DebuggerPathAndFileName = StackHashDebuggerSettings.Default32BitDebuggerPathAndFileName; debuggerSettings.SymbolPath = StackHashSearchPath.DefaultSymbolPath; debuggerSettings.BinaryPath = StackHashSearchPath.DefaultBinaryPath; debugger.RunScript(debuggerSettings, true, scriptFileName, dumpFileName, resultsFileName, symPath, exePath, srcPath); DateTime endTime = DateTime.Now.ToUniversalTime(); Assert.AreEqual(true, File.Exists(resultsFileName)); // Now load in the test results. StackHashScriptResult result = new StackHashScriptResult(resultsFileName); Assert.AreEqual(scriptSettings.Name, result.Name); Assert.AreEqual(scriptSettings.LastModifiedDate.Date, result.LastModifiedDate.Date); Assert.AreEqual(scriptSettings.LastModifiedDate.Hour, result.LastModifiedDate.Hour); Assert.AreEqual(scriptSettings.LastModifiedDate.Minute, result.LastModifiedDate.Minute); Assert.AreEqual(scriptSettings.LastModifiedDate.Second, result.LastModifiedDate.Second); // Recorded time is only accurate to the second. long ticksInASecond = 10000000; startTime = new DateTime((startTime.Ticks / ticksInASecond) * ticksInASecond, DateTimeKind.Utc); endTime = new DateTime((endTime.Ticks / ticksInASecond) * ticksInASecond, DateTimeKind.Utc); bool isGreaterEqual = result.RunDate >= startTime; bool isLessThanEqual = result.RunDate <= endTime; long ticks1 = result.RunDate.Ticks; long ticks2 = startTime.Ticks; long ticks3 = endTime.Ticks; Assert.AreEqual(true, (result.RunDate >= startTime) && (result.RunDate <= endTime)); Assert.AreEqual(numCommands, scriptSettings.Script.Count); for (int i = 0; i < numCommands; i++) { Assert.AreEqual(scriptSettings.Script[i].Command, result.ScriptResults[i].ScriptLine.Command); Assert.AreEqual(scriptSettings.Script[i].Comment, result.ScriptResults[i].ScriptLine.Comment); Assert.AreEqual(5, result.ScriptResults[i].ScriptLineOutput.Count); Assert.AreEqual(true, result.ScriptResults[i].ScriptLineOutput[0].StartsWith("eax=")); Assert.AreEqual(true, result.ScriptResults[i].ScriptLineOutput[1].StartsWith("eip=")); Assert.AreEqual(true, result.ScriptResults[i].ScriptLineOutput[2].StartsWith("cs=")); } }
public void ScriptContainsSymPathMultipleCommandsWithReplace() { String testScriptName = "Name"; String symbolPath1 = "c:\\test1"; String symbolPath2 = "c:\\test2"; String testCommand1 = @".sympath+" + symbolPath1; String testComment1 = @"Comment 1"; String testCommand2 = @".Sympath" + symbolPath2; // No + on this one so should replace all previous symbols. String testComment2 = @"Comment 2"; // Create a script - empty. StackHashScript script = new StackHashScript(); script.Add(new StackHashScriptLine(testCommand1, testComment1)); script.Add(new StackHashScriptLine(testCommand2, testComment2)); StackHashScriptSettings scriptSettings = new StackHashScriptSettings(testScriptName, script); String tempFileName = m_TempPath + "\\GeneratedScript.wds"; String outputFileName = "c:\\test\\results.log"; String originalSymPath = "c:\\symbols"; String originalExePath = "c:\\binary"; String originalSrcPath = "c:\\source"; String symPath = originalSymPath; String exePath = originalExePath; String srcPath = originalSrcPath; scriptSettings.GenerateScriptFile(tempFileName, outputFileName, ref symPath, ref exePath, ref srcPath); Assert.AreEqual(symbolPath2, symPath); Assert.AreEqual(originalExePath, exePath); Assert.AreEqual(originalSrcPath, srcPath); // Read all of the data in. String[] allLines = File.ReadAllLines(tempFileName); Assert.AreEqual(true, File.Exists(tempFileName)); // Should contain the script header comment plus one command and one comment line for each command. // Should contain an entry for sympath and exepath. Assert.AreEqual(8, allLines.Length); Assert.AreEqual(true, allLines[0].Contains(outputFileName)); Assert.AreEqual(true, allLines[1].Contains(testScriptName)); Assert.AreEqual(true, allLines[1].Contains(scriptSettings.LastModifiedDate.ToString(CultureInfo.InvariantCulture))); Assert.AreEqual(true, allLines[2].Contains("Command")); Assert.AreEqual(true, allLines[2].Contains(testCommand1)); Assert.AreEqual(true, allLines[2].Contains(testComment1)); Assert.AreEqual(true, allLines[3].Contains("CommandEnd")); Assert.AreEqual(true, allLines[3].Contains(testCommand1)); Assert.AreEqual(true, allLines[3].Contains(testComment1)); Assert.AreEqual(true, allLines[4].Contains("Command")); Assert.AreEqual(true, allLines[4].Contains(testCommand2)); Assert.AreEqual(true, allLines[4].Contains(testComment2)); Assert.AreEqual(true, allLines[5].Contains("CommandEnd")); Assert.AreEqual(true, allLines[5].Contains(testCommand2)); Assert.AreEqual(true, allLines[5].Contains(testComment2)); Assert.AreEqual(true, allLines[6].Contains("Script Complete")); Assert.AreEqual(true, allLines[7].Contains(".logclose")); }
public void ScriptContainsSymAndExePathStatementWithConcat() { String testScriptName = "Name"; String symbolPath = "some symbol path **"; String binaryPath = "some exe path **"; String sourcePath = "some src path **"; String testCommand1 = @".exepath+" + binaryPath; String testComment1 = @"Another comment"; String testCommand2 = @" .symPath + " + symbolPath; String testComment2 = @"Demo Comment 1"; String testCommand3 = @" .SrcPath +" + sourcePath; String testComment3 = @"Demo Comment 2"; // Create a script - empty. StackHashScript script = new StackHashScript(); script.Add(new StackHashScriptLine(testCommand1, testComment1)); script.Add(new StackHashScriptLine(testCommand2, testComment2)); script.Add(new StackHashScriptLine(testCommand3, testComment3)); StackHashScriptSettings scriptSettings = new StackHashScriptSettings(testScriptName, script); String tempFileName = m_TempPath + "\\GeneratedScript.wds"; String outputFileName = "c:\\test\\results.log"; String originalSymPath = "c:\\symbols"; String originalExePath = "c:\\binary"; String originalSrcPath = "c:\\source"; String symPath = originalSymPath; String exePath = originalExePath; String srcPath = originalSrcPath; scriptSettings.GenerateScriptFile(tempFileName, outputFileName, ref symPath, ref exePath, ref srcPath); Assert.AreEqual(symPath, originalSymPath + ";" + symbolPath); Assert.AreEqual(exePath, originalExePath + ";" + binaryPath); Assert.AreEqual(srcPath, originalSrcPath + ";" + sourcePath); // Read all of the data in. String[] allLines = File.ReadAllLines(tempFileName); Assert.AreEqual(true, File.Exists(tempFileName)); // Should contain the script header comment plus one command and one comment line for each command. // Should contain an entry for sympath and exepath. Assert.AreEqual(10, allLines.Length); Assert.AreEqual(true, allLines[0].Contains(outputFileName)); Assert.AreEqual(true, allLines[1].Contains(testScriptName)); Assert.AreEqual(true, allLines[1].Contains(scriptSettings.LastModifiedDate.ToString(CultureInfo.InvariantCulture))); Assert.AreEqual(true, allLines[2].Contains("Command")); Assert.AreEqual(true, allLines[2].Contains(testCommand1)); Assert.AreEqual(true, allLines[2].Contains(testComment1)); Assert.AreEqual(true, allLines[3].Contains("CommandEnd")); Assert.AreEqual(true, allLines[3].Contains(testCommand1)); Assert.AreEqual(true, allLines[3].Contains(testComment1)); Assert.AreEqual(true, allLines[4].Contains("Command")); Assert.AreEqual(true, allLines[4].Contains(testCommand2)); Assert.AreEqual(true, allLines[4].Contains(testComment2)); Assert.AreEqual(true, allLines[5].Contains("CommandEnd")); Assert.AreEqual(true, allLines[5].Contains(testCommand2)); Assert.AreEqual(true, allLines[5].Contains(testComment2)); Assert.AreEqual(true, allLines[6].Contains("Command")); Assert.AreEqual(true, allLines[6].Contains(testCommand3)); Assert.AreEqual(true, allLines[6].Contains(testComment3)); Assert.AreEqual(true, allLines[7].Contains("CommandEnd")); Assert.AreEqual(true, allLines[7].Contains(testCommand3)); Assert.AreEqual(true, allLines[7].Contains(testComment3)); Assert.AreEqual(true, allLines[8].Contains("Script Complete")); Assert.AreEqual(true, allLines[9].Contains(".logclose")); }