public void HasColonInWrongPlace() { writer.WriteLine(":"); writer.Flush(); parser = new DumpFileParser(stream, "main"); CollectionAssert.AreEqual(new Byte[] { 0xc9 }, parser.GetBytes()); }
public void HasColonInWrongPlace() { writer.WriteLine(":"); writer.Flush(); parser = new DumpFileParser(stream, "main"); CollectionAssert.AreEqual(new Byte[] {0xc9}, parser.GetBytes()); }
public void EmptyLine() { writer.WriteLine(String.Empty); writer.Flush(); parser = new DumpFileParser(stream, "main"); Assert.IsNull(parser.GetBytes()); }
public void GetBytesReturnAllInstructions() { writer.WriteLine(" 804837d: c3 ret "); writer.WriteLine(" 804837e: 90 nop "); writer.Flush(); parser = new DumpFileParser(stream, "main"); var code = parser.GetBytes(); CollectionAssert.AreEqual(new Byte[] {0xc9, 0xc3, 0x90}, code); }
public void GetBytesIsNull() { writer.WriteLine(" 804837f: 55 push ebp"); writer.Flush(); parser = new DumpFileParser(stream, "main"); Assert.IsNull(parser.GetBytes()); Assert.AreEqual(0, parser.BaseAddress); Assert.AreEqual(0, parser.EntryPointAddress); }
public void TearDown() { if (parser == null) { return; } parser.Dispose(); parser = null; }
public void LineWithSpaceTab() { writer.WriteLine(" 8048388: c7 04 24 10 00 00 00 \tmov DWORD PTR [esp],0x10"); writer.Flush(); parser = new DumpFileParser(stream, "main"); var expectedResult = new Byte[] { 0xc9, 0xc7, 0x04, 0x24, 0x10, 0x00, 0x00, 0x00 }; CollectionAssert.AreEqual(expectedResult, parser.GetBytes()); }
public void LineWithSingleHex() { writer.WriteLine(" 804837c: 55 push ebp"); writer.Flush(); parser = new DumpFileParser(stream, "main"); var expectedResult = new Byte[] { 0xc9, 0x55 }; CollectionAssert.AreEqual(expectedResult, parser.GetBytes()); }
public void LineWithMultipleHex() { writer.WriteLine(" 8048385: 83 ec 10 sub esp,0x10"); writer.Flush(); parser = new DumpFileParser(stream, "main"); var expectedResult = new Byte[] { 0xc9, 0x83, 0xec, 0x10 }; CollectionAssert.AreEqual(expectedResult, parser.GetBytes()); }
public void GetBytesReturnAllInstructions() { writer.WriteLine(" 804837d: c3 ret "); writer.WriteLine(" 804837e: 90 nop "); writer.Flush(); parser = new DumpFileParser(stream, "main"); var code = parser.GetBytes(); CollectionAssert.AreEqual(new Byte[] { 0xc9, 0xc3, 0x90 }, code); }
public void WithExpectedReportItmes() { writer.WriteLine(" //<OutOfBoundsMemoryAccess Location=0x8000ffff Exploitable=True/>"); writer.WriteLine(" //<OutOfBoundsMemoryAccess Location=0x8000FFFA Exploitable=False/>"); writer.Flush(); parser = new DumpFileParser(stream, "main"); Assert.AreEqual(2, parser.ExpectedReportItems.Count); Assert.AreEqual(0x8000ffff, parser.ExpectedReportItems[0].InstructionPointer); Assert.AreEqual(true, parser.ExpectedReportItems[0].IsTainted); Assert.AreEqual(0x8000FFFA, parser.ExpectedReportItems[1].InstructionPointer); Assert.AreEqual(false, parser.ExpectedReportItems[1].IsTainted); }
public void ParseNonMain() { writer.WriteLine(" 804837d: c3 ret "); writer.WriteLine(); writer.Flush(); parser = new DumpFileParser(stream, "_start"); Assert.AreEqual(0x0804837c, parser.BaseAddress); Assert.AreEqual(0x0804837c, parser.EntryPointAddress); var code = parser.GetBytes(); Assert.AreEqual(0xc9, code[0]); }
public void MainIsLastFunction() { writer.WriteLine(" 804837d: c3 ret "); writer.Flush(); parser = new DumpFileParser(stream, "main"); Assert.AreEqual(0x0804837c, parser.BaseAddress); Assert.AreEqual(0x0804837d, parser.EntryPointAddress); var code = parser.GetBytes(); CollectionAssert.AreEqual(new Byte[] { 0xc9, 0xc3 }, code); Assert.AreEqual(2, code.Length); Assert.AreEqual(0, parser.ExpectedReportItems.Count); }
private void HandleInputIfNecessary() { if (!interactive) { return; } // TODO: cover this with a system-level test var enterPressed = false; while (!enterPressed) { var input = GetInput(); var command = new DebuggerCommand(input); if (command.IsEnter) { enterPressed = true; continue; } if (command.IsStackPrint) { PrintStackFor(state); continue; } if (command.IsDisassemble) { var hex = input.Substring("disasm".Length + 1); var code = DumpFileParser.GetByteArrayFor(hex); PrintOpcodeInfoFor(code); continue; } if (command.IsQuit) { Environment.Exit(0); } Console.WriteLine("invalid command"); } }
public void LineWithMuchoHex() { writer.WriteLine(" 8048388: c7 04 24 10 00 00 00 mov DWORD PTR [esp],0x10"); writer.Flush(); parser = new DumpFileParser(stream, "main"); var expectedResult = new Byte[] {0xc9, 0xc7, 0x04, 0x24, 0x10, 0x00, 0x00, 0x00}; CollectionAssert.AreEqual(expectedResult, parser.GetBytes()); }
public void LineWithBadHex() { writer.WriteLine(" 8048385: 83 ej 10 sub esp,0x10"); writer.Flush(); parser = new DumpFileParser(stream, "main"); }
public void LineWithSingleHex() { writer.WriteLine(" 804837c: 55 push ebp"); writer.Flush(); parser = new DumpFileParser(stream, "main"); var expectedResult = new Byte[] {0xc9, 0x55}; CollectionAssert.AreEqual(expectedResult, parser.GetBytes()); }
public void NoLines() { parser = new DumpFileParser(stream, "main"); Assert.IsNull(parser.GetBytes()); }
public void NextLineSkipsBadLines() { writer.WriteLine("BADLINE"); writer.WriteLine(" 8048385: 83 ec 10 sub esp,0x10"); writer.Flush(); parser = new DumpFileParser(stream, "main"); var expectedResult = new Byte[] {0xc9, 0x83, 0xec, 0x10}; CollectionAssert.AreEqual(expectedResult, parser.GetBytes()); }
public void MainIsNotLastFunction() { writer.WriteLine(" 804837d: c3 ret "); writer.WriteLine(); writer.WriteLine("0804837e <nonmain2>:"); writer.WriteLine(" 804837e: 90 nop "); writer.Flush(); parser = new DumpFileParser(stream, "main"); Assert.AreEqual(0x0804837c, parser.BaseAddress); Assert.AreEqual(0x0804837d, parser.EntryPointAddress); var code = parser.GetBytes(); CollectionAssert.AreEqual(new Byte[] {0xc9, 0xc3, 0x90}, code); Assert.AreEqual(3, code.Length); Assert.AreEqual(0, parser.ExpectedReportItems.Count); }