Esempio n. 1
0
        private void Given_MsDosRawFileFormat()
        {
            this.x86arch = mr.Stub <IProcessorArchitecture>();
            var env = mr.Stub <OperatingEnvironment>();

            this.msdosPlatform = mr.Stub <IPlatform>();
            var map     = new SegmentMap(Address.SegPtr(0x0C00, 0));
            var state   = new FakeProcessorState(x86arch);
            var rawFile = new RawFileElementImpl
            {
                BaseAddress  = "0C00:0100",
                Environment  = "ms-dos",
                Architecture = "x86-real-16",
            };

            rawFile.EntryPoint.Address = null;
            rawFile.EntryPoint.Name    = "Start_Here";
            cfgSvc.Stub(d => d.GetRawFile("ms-dos-com")).Return(rawFile);
            cfgSvc.Stub(d => d.GetArchitecture("x86-real-16")).Return(x86arch);
            cfgSvc.Stub(d => d.GetEnvironment("ms-dos")).Return(env);
            env.Stub(e => e.Load(null, null)).IgnoreArguments().Return(msdosPlatform);
            x86arch.Stub(a => a.TryParseAddress(
                             Arg <string> .Is.Equal("0C00:0100"),
                             out Arg <Address> .Out(Address.SegPtr(0x0C00, 0x0100)).Dummy))
            .Return(true);
            x86arch.Stub(a => a.CreateProcessorState()).Return(state);
        }
Esempio n. 2
0
        public void Bwi_CallingAllocaWithConstant()
        {
            program.Architecture = new X86ArchitectureFlat32("x86-protected-32");
            program.Platform     = new DefaultPlatform(null, program.Architecture);
            var sig    = CreateSignature(Registers.esp, Registers.eax);
            var alloca = new ExternalProcedure("alloca", sig)
            {
                Characteristics = new ProcedureCharacteristics
                {
                    IsAlloca = true
                }
            };

            using (mr.Record())
            {
                scanner.Stub(x => x.FindContainingBlock(
                                 Arg <Address> .Is.Anything)).Return(block);
                scanner.Expect(x => x.GetImportedProcedure(
                                   Arg <Address> .Matches(a => a.ToLinear() == 0x102000u),
                                   Arg <Address> .Is.NotNull)).Return(alloca);
                scanner.Stub(x => x.GetTrace(null, null, null)).IgnoreArguments().Return(trace);
            }
            trace.Add(m => m.Call(Address.Ptr32(0x102000), 4));
            var state = new FakeProcessorState(program.Architecture);

            state.SetRegister(Registers.eax, Constant.Word32(0x0400));
            var wi = CreateWorkItem(Address.Ptr32(0x1000), state);

            wi.Process();

            mr.VerifyAll();
            Assert.AreEqual(1, block.Statements.Count);
            Assert.AreEqual("esp = esp - 0x00000400", block.Statements.Last.ToString());
        }
Esempio n. 3
0
        public void CmdLine_EntryPoint()
        {
            var arch  = new Mock <IProcessorArchitecture>();
            var map   = new SegmentMap(Address.Ptr32(0x010000));
            var state = new FakeProcessorState(arch.Object);

            configSvc.Setup(s => s.GetArchitecture("mmix")).Returns(arch.Object);

            Address addr = Address.Ptr32(0x010000);

            arch.Setup(a => a.TryParseAddress(
                           "010000",
                           out addr))
            .Returns(true);
            addr = Address.Ptr32(0x010100);
            arch.Setup(a => a.TryParseAddress(
                           "010100",
                           out addr))
            .Returns(true);
            arch.Setup(a => a.CreateProcessorState()).Returns(state);
            decompiler.Setup(d => d.LoadRawImage(
                                 It.IsAny <string>(),
                                 It.IsAny <LoadDetails>()))
            .Returns(new Program());

            var cmdline = new CmdLineDriver(sc, ldr.Object, decompiler.Object, new CmdLineListener());

            cmdline.Execute(new string[]
            {
                "--arch", "mmix",
                "--base", "010000",
                "--entry", "010100",
                "foo.exe"
            });
        }
Esempio n. 4
0
        public void Bwi_CallingAllocaWithConstant()
        {
            program.Architecture = new X86ArchitectureFlat32("x86-protected-32");
            program.Platform     = new DefaultPlatform(null, program.Architecture);
            var sig    = CreateSignature(Registers.esp, Registers.eax);
            var alloca = new ExternalProcedure("alloca", sig)
            {
                Characteristics = new ProcedureCharacteristics
                {
                    IsAlloca = true
                }
            };

            scanner.Setup(x => x.FindContainingBlock(
                              It.IsAny <Address>())).Returns(block);
            scanner.Setup(x => x.GetImportedProcedure(
                              It.IsNotNull <IProcessorArchitecture>(),
                              It.Is <Address>(a => a.ToLinear() == 0x102000u),
                              It.IsNotNull <Address>())).Returns(alloca);
            Given_SimpleTrace(trace);
            trace.Add(m => m.Call(Address.Ptr32(0x102000), 4));
            var state = new FakeProcessorState(program.Architecture);

            state.SetRegister(Registers.eax, Constant.Word32(0x0400));
            var wi = CreateWorkItem(Address.Ptr32(0x1000), state);

            wi.Process();

            scanner.Verify();
            Assert.AreEqual(1, block.Statements.Count);
            Assert.AreEqual("esp = esp - 0x00000400", block.Statements.Last.ToString());
        }
Esempio n. 5
0
        private void Given_MsDosRawFileFormat()
        {
            this.x86arch = new Mock <IProcessorArchitecture>();
            this.x86arch.Setup(a => a.Name).Returns("x86-real-16");
            var env = new Mock <PlatformDefinition>();

            this.msdosPlatform = new Mock <IPlatform>();
            var map     = new SegmentMap(Address.SegPtr(0x0C00, 0));
            var state   = new FakeProcessorState(x86arch.Object);
            var rawFile = new RawFileDefinition
            {
                BaseAddress  = "0C00:0100",
                Environment  = "ms-dos",
                Architecture = "x86-real-16",
            };

            rawFile.EntryPoint.Address = null;
            rawFile.EntryPoint.Name    = "Start_Here";
            cfgSvc.Setup(d => d.GetRawFile("ms-dos-com")).Returns(rawFile);
            cfgSvc.Setup(d => d.GetArchitecture("x86-real-16")).Returns(x86arch.Object);
            cfgSvc.Setup(d => d.GetEnvironment("ms-dos")).Returns(env.Object);
            env.Setup(e => e.Load(It.IsAny <IServiceProvider>(), It.IsAny <IProcessorArchitecture>()))
            .Returns(msdosPlatform.Object);

            var addr = Address.SegPtr(0x0C00, 0x0100);

            x86arch.Setup(a => a.TryParseAddress(
                              "0C00:0100",
                              out addr))
            .Returns(true);
            x86arch.Setup(a => a.CreateProcessorState()).Returns(state);
        }
Esempio n. 6
0
        public void CmdLine_EntryPoint()
        {
            var arch  = mr.Stub <IProcessorArchitecture>();
            var map   = new SegmentMap(Address.Ptr32(0x010000));
            var state = new FakeProcessorState(arch);

            configSvc.Stub(s => s.GetArchitecture("mmix")).Return(arch);
            arch.Stub(a => a.TryParseAddress(
                          Arg <string> .Is.Equal("010000"),
                          out Arg <Address> .Out(Address.Ptr32(0x010000)).Dummy))
            .Return(true);
            arch.Stub(a => a.TryParseAddress(
                          Arg <string> .Is.Equal("010100"),
                          out Arg <Address> .Out(Address.Ptr32(0x010100)).Dummy))
            .Return(true); mr.ReplayAll();
            arch.Stub(a => a.CreateProcessorState()).Return(state);
            decompiler.Stub(d => d.LoadRawImage(null, null))
            .IgnoreArguments()
            .Return(new Program());
            mr.ReplayAll();

            var cmdline = new CmdLineDriver(sc, ldr, decompiler, null);

            cmdline.Execute(new string[]
            {
                "--arch", "mmix",
                "--base", "010000",
                "--entry", "010100",
                "foo.exe"
            });

            mr.VerifyAll();
        }
Esempio n. 7
0
        public void Setup()
        {
            sp   = new RegisterStorage("sp", 42, 0, PrimitiveType.Pointer32);
            arch = new FakeArchitecture();
            arch.StackRegister = sp;

            sce = new FakeProcessorState(arch);

            idSp = new Identifier(sp.Name, sp.DataType, sp);
            m    = new ExpressionEmitter();
        }
Esempio n. 8
0
        public void Setup()
        {
            sp = new RegisterStorage("sp", 42, 0, PrimitiveType.Pointer32);
            arch = new FakeArchitecture();
            arch.StackRegister = sp;

            sce = new FakeProcessorState(arch);

            idSp = new Identifier(sp.Name, sp.DataType, sp);
            m = new ExpressionEmitter();
        }
Esempio n. 9
0
        public void Vb_CreateVector_ModifiesImageMap()
        {
            Given_Program(new byte[]
            {
                0x10, 0x00, 0x01, 0x00,
                0x11, 0x00, 0x01, 0x00,
                0x12, 0x00, 0x01, 0x00,
                0xCC, 0xCC, 0xCC, 0xCC,
                0xC3, 0xC3, 0xC3, 0xCC,
            });
            var scanner = new Mock <IScanner>();

            scanner.Setup(s => s.Services).Returns(sc);
            arch.Setup(s => s.CreateImageReader(this.mem, this.program.ImageMap.BaseAddress))
            .Returns(this.mem.CreateLeReader(0));
            var state = new FakeProcessorState(arch.Object);

            var vb     = new VectorBuilder(scanner.Object.Services, program, new DirectedGraphImpl <object>());
            var vector = vb.BuildTable(this.program.ImageMap.BaseAddress, 12, null, 4, state);

            Assert.AreEqual(3, vector.Count);
        }