public void RunAllAutoScripts() { String dumpFileName = m_TempPath + "Cucku.exe.mdmp"; // First make a copy of the test cab file. File.Copy(TestSettings.TestDataFolder + @"Dumps\Cucku.exe.mdmp", dumpFileName, true); FileAttributes attributes = File.GetAttributes(dumpFileName); File.SetAttributes(dumpFileName, attributes & ~FileAttributes.ReadOnly); ScriptManager scriptManager = new ScriptManager(m_TempPath); // Now execute the script. StackHashDebug.Windbg winDbg = new Windbg(); try { Collection <AutoScriptBase> autoScripts = scriptManager.AutoScripts; foreach (AutoScriptBase autoScript in autoScripts) { // Generate the script settings structure in memory. StackHashScriptSettings scriptSettings = autoScript.GenerateScript(); // Those settings are now used to create a WinDbg script file (wds). This file has a command // to create a log file (the resultsFileName). String resultsFileName = String.Format("{0}.log", Path.Combine(m_TempPath, autoScript.ScriptName)); String scriptFileName = String.Format("{0}.wds", Path.Combine(m_TempPath, autoScript.ScriptName)); String symPath = null; String exePath = null; String srcPath = null; scriptSettings.GenerateScriptFile(scriptFileName, resultsFileName, ref symPath, ref exePath, ref srcPath); // Run the wds file through the debugger to produce the results.log file. winDbg.RunScript(m_DebuggerSettings, false, scriptFileName, dumpFileName, m_TempPath, symPath, exePath, srcPath); // Load the results.log file. StackHashScriptResult scriptResults = new StackHashScriptResult(resultsFileName); // Analyse the results. StackHashDumpAnalysis analysis = new StackHashDumpAnalysis(); analysis = autoScript.AnalyzeScriptResults(analysis, scriptResults); } } finally { scriptManager.RemoveAutoScripts(); } }
public void RunAutoScript() { String dumpFileName = m_TempPath + "Cucku.exe.mdmp"; String scriptFileName = m_TempPath + "AutoScript.wds"; String resultsFileName = m_TempPath + "AutoScript.log"; // First make a copy of the test cab file. File.Copy(TestSettings.TestDataFolder + @"Dumps\Cucku.exe.mdmp", dumpFileName, true); FileAttributes attributes = File.GetAttributes(dumpFileName); File.SetAttributes(dumpFileName, attributes & ~FileAttributes.ReadOnly); AutoScript autoScript = new AutoScript(m_TempPath); StackHashScriptSettings scriptSettings = autoScript.GenerateScript(); 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); // Now execute the script. StackHashDebug.Windbg winDbg = new Windbg(); winDbg.RunScript(m_DebuggerSettings, false, scriptFileName, dumpFileName, m_TempPath, symPath, exePath, srcPath); // Load the results file. StackHashScriptResult scriptResults = new StackHashScriptResult(resultsFileName); // Analyse the results. StackHashDumpAnalysis analysis = new StackHashDumpAnalysis(); analysis = autoScript.AnalyzeScriptResults(analysis, scriptResults); Assert.AreEqual("not available", analysis.SystemUpTime); Assert.AreEqual("0 days 0:02:20.000", analysis.ProcessUpTime); Assert.AreEqual("2.0.50727.3603", analysis.DotNetVersion); }
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=")); } }