Exemplo n.º 1
0
 public void HasColonInWrongPlace()
 {
     writer.WriteLine(":");
     writer.Flush();
     parser = new DumpFileParser(stream, "main");
     CollectionAssert.AreEqual(new Byte[] { 0xc9 }, parser.GetBytes());
 }
Exemplo n.º 2
0
 public void HasColonInWrongPlace()
 {
     writer.WriteLine(":");
     writer.Flush();
     parser = new DumpFileParser(stream, "main");
     CollectionAssert.AreEqual(new Byte[] {0xc9}, parser.GetBytes());
 }
Exemplo n.º 3
0
        public void EmptyLine()
        {
            writer.WriteLine(String.Empty);
            writer.Flush();
            parser = new DumpFileParser(stream, "main");

            Assert.IsNull(parser.GetBytes());
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        public void TearDown()
        {
            if (parser == null)
            {
                return;
            }

            parser.Dispose();
            parser = null;
        }
Exemplo n.º 7
0
        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());
        }
Exemplo n.º 8
0
        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());
        }
Exemplo n.º 9
0
        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());
        }
Exemplo n.º 10
0
        public void TearDown()
        {
            if (parser == null)
            {
                return;
            }

            parser.Dispose();
            parser = null;
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        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]);
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
0
        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");
            }
        }
Exemplo n.º 16
0
        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());
        }
Exemplo n.º 17
0
 public void LineWithBadHex()
 {
     writer.WriteLine(" 8048385:       83 ej 10                sub    esp,0x10");
     writer.Flush();
     parser = new DumpFileParser(stream, "main");
 }
Exemplo n.º 18
0
 public void LineWithBadHex()
 {
     writer.WriteLine(" 8048385:       83 ej 10                sub    esp,0x10");
     writer.Flush();
     parser = new DumpFileParser(stream, "main");
 }
Exemplo n.º 19
0
        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());
        }
Exemplo n.º 20
0
 public void NoLines()
 {
     parser = new DumpFileParser(stream, "main");
     Assert.IsNull(parser.GetBytes());
 }
Exemplo n.º 21
0
        public void EmptyLine()
        {
            writer.WriteLine(String.Empty);
            writer.Flush();
            parser = new DumpFileParser(stream, "main");

            Assert.IsNull(parser.GetBytes());
        }
Exemplo n.º 22
0
 public void NoLines()
 {
     parser = new DumpFileParser(stream, "main");
     Assert.IsNull(parser.GetBytes());
 }
Exemplo n.º 23
0
        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);
        }
Exemplo n.º 24
0
        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);
        }
Exemplo n.º 25
0
        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]);
        }
Exemplo n.º 26
0
        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());
        }
Exemplo n.º 27
0
        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);
        }