示例#1
0
 protected Program RewriteProgram32(string sourceFilename, Address addrBase)
 {
     var sc = new ServiceContainer();
     sc.AddService<IConfigurationService>(new FakeDecompilerConfiguration());
     var ldr = new Loader(sc);
     var arch = new X86ArchitectureFlat32();
     program = ldr.AssembleExecutable(
         FileUnitTester.MapTestPath(sourceFilename),
         new X86TextAssembler(arch) { Platform = new DefaultPlatform(null, arch) },
         addrBase);
     return RewriteProgram();
 }
示例#2
0
        private void btnLoad_Click(object sender, EventArgs e)
        {
            var mem      = new ByteMemoryArea(Address.Ptr32(0x12312300), new byte[0x1000]);
            var imageMap = new SegmentMap(
                mem.BaseAddress,
                new ImageSegment("code", mem, AccessMode.ReadWriteExecute));
            var sc      = new ServiceContainer();
            var arch    = new X86ArchitectureFlat32(sc, "x86-protected-32");
            var program = new Core.Program(imageMap, arch, new DefaultPlatform(sc, arch));
            var project = new Project {
                Programs = { program }
            };

            pbs.Load(project);
        }
示例#3
0
        private void Given_x86_Image(Action <X86Assembler> asm)
        {
            var addrBase = Address.Ptr32(0x100000);
            var entry    = new ImageSymbol(addrBase)
            {
                Type = SymbolType.Procedure
            };
            var arch = new X86ArchitectureFlat32("x86-protected-32");
            var m    = new X86Assembler(null, new DefaultPlatform(null, arch), addrBase, new List <ImageSymbol> {
                entry
            });

            asm(m);
            this.program = m.GetImage();
        }
        public void Setup()
        {
            form  = new Mock <IMainForm>();
            sc    = new ServiceContainer();
            uiSvc = AddService <IDecompilerShellUiService>();
            sc.AddService <IDecompilerUIService>(uiSvc.Object);
            codeViewSvc   = AddService <ICodeViewerService>();
            memViewSvc    = AddService <ILowLevelViewService>();
            disasmViewSvc = AddService <IDisassemblyViewService>();
            pbSvc         = AddService <IProjectBrowserService>();

            form.Setup(f => f.Show());

            var platform = new Mock <IPlatform>();

            platform.Setup(p => p.CreateMetadata()).Returns(new TypeLibrary());
            var loadAddress = Address.Ptr32(0x100000);
            var bytes       = new byte[4711];
            var arch        = new X86ArchitectureFlat32("x86-protected-32");
            var mem         = new MemoryArea(loadAddress, bytes);

            this.program = new Program
            {
                SegmentMap = new SegmentMap(
                    mem.BaseAddress,
                    new ImageSegment(".text", mem, AccessMode.ReadExecute)),
                Architecture = arch,
                Platform     = platform.Object,
            };
            var ldr = new Mock <ILoader>();

            ldr.Setup(l => l.LoadExecutable(
                          It.IsAny <string>(),
                          It.IsAny <byte[]>(),
                          It.IsAny <string>(),
                          It.IsAny <Address>())).Returns(program);
            ldr.Setup(l => l.LoadImageBytes(
                          It.IsAny <string>(),
                          It.IsAny <int>())).Returns(bytes);
            sc.AddService <DecompilerEventListener>(new FakeDecompilerEventListener());
            sc.AddService <IDecompiledFileService>(new FakeDecompiledFileService());
            this.decSvc       = new DecompilerService();
            decSvc.Decompiler = new DecompilerDriver(ldr.Object, sc);
            decSvc.Decompiler.Load("test.exe");
            this.program = this.decSvc.Decompiler.Project.Programs.First();
            sc.AddService <IDecompilerService>(decSvc);
            sc.AddService <IWorkerDialogService>(new FakeWorkerDialogService());
        }
示例#5
0
        protected Program RewriteProgram32(string sourceFilename, Address addrBase)
        {
            sc = new ServiceContainer();
            sc.AddService <IConfigurationService>(new FakeDecompilerConfiguration());
            sc.AddService <IFileSystemService>(new FileSystemServiceImpl());
            sc.AddService <DecompilerEventListener>(new FakeDecompilerEventListener());
            var ldr  = new Loader(sc);
            var arch = new X86ArchitectureFlat32(sc, "x86-protected-32", new Dictionary <string, object>());

            program = ldr.AssembleExecutable(
                FileUnitTester.MapTestPath(sourceFilename),
                new X86TextAssembler(arch),
                new DefaultPlatform(sc, arch),
                addrBase);
            return(RewriteProgram());
        }
示例#6
0
        protected Program RewriteProgram32(string sourceFilename, Address addrBase)
        {
            var sc = new ServiceContainer();

            sc.AddService <IConfigurationService>(new FakeDecompilerConfiguration());
            var ldr  = new Loader(sc);
            var arch = new X86ArchitectureFlat32();

            program = ldr.AssembleExecutable(
                FileUnitTester.MapTestPath(sourceFilename),
                new X86TextAssembler(arch)
            {
                Platform = new DefaultPlatform(null, arch)
            },
                addrBase);
            return(RewriteProgram());
        }
        public void Setup()
        {
            //$REVIEW: we can probably remove the code below, it never is called
            // anymore.

            form  = new Mock <IMainForm>();
            sc    = new ServiceContainer();
            uiSvc = AddService <IDecompilerShellUiService>();
            sc.AddService <IDecompilerUIService>(uiSvc.Object);
            codeViewSvc   = AddService <ICodeViewerService>();
            memViewSvc    = AddService <ILowLevelViewService>();
            disasmViewSvc = AddService <IDisassemblyViewService>();
            pbSvc         = AddService <IProjectBrowserService>();

            form.Setup(f => f.Show());

            var arch     = new X86ArchitectureFlat32(sc, "x86-protected-32", new Dictionary <string, object>());
            var platform = new Mock <IPlatform>();

            platform.Setup(p => p.CreateMetadata()).Returns(new TypeLibrary());
            platform.Setup(p => p.Architecture).Returns(arch);
            var loadAddress = Address.Ptr32(0x100000);
            var bytes       = new byte[4711];
            var mem         = new ByteMemoryArea(loadAddress, bytes);

            this.program = new Program
            {
                SegmentMap = new SegmentMap(
                    mem.BaseAddress,
                    new ImageSegment(".text", mem, AccessMode.ReadExecute)),
                Architecture = arch,
                Platform     = platform.Object,
            };
            var project = new Project(ImageLocation.FromUri("/home/bob/reko.project"));

            project.AddProgram(ImageLocation.FromUri("/home/bob/test.exe"), program);

            sc.AddService <DecompilerEventListener>(new FakeDecompilerEventListener());
            sc.AddService <IDecompiledFileService>(new FakeDecompiledFileService());
            this.decSvc       = new DecompilerService();
            decSvc.Decompiler = new Decompiler(project, sc);
            this.program      = this.decSvc.Decompiler.Project.Programs.First();
            sc.AddService <IDecompilerService>(decSvc);
            sc.AddService <IWorkerDialogService>(new FakeWorkerDialogService());
        }
示例#8
0
        public void Setup()
        {
            mr = new MockRepository();

            form  = mr.StrictMock <IMainForm>();
            sc    = new ServiceContainer();
            uiSvc = AddService <IDecompilerShellUiService>();
            sc.AddService(typeof(IDecompilerUIService), uiSvc);
            codeViewSvc   = AddService <ICodeViewerService>();
            memViewSvc    = AddService <ILowLevelViewService>();
            disasmViewSvc = AddService <IDisassemblyViewService>();
            pbSvc         = AddService <IProjectBrowserService>();

            form.Stub(f => f.Show());

            var     platform    = mr.Stub <IPlatform>();
            var     loadAddress = Address.Ptr32(0x100000);
            var     bytes       = new byte[4711];
            var     arch        = new X86ArchitectureFlat32();
            var     mem         = new MemoryArea(loadAddress, bytes);
            Program prog        = new Program
            {
                SegmentMap = new SegmentMap(
                    mem.BaseAddress,
                    new ImageSegment(".text", mem, AccessMode.ReadExecute)),
                Architecture = arch,
                Platform     = platform,
            };
            ILoader ldr = mr.StrictMock <ILoader>();

            ldr.Stub(l => l.LoadExecutable(null, null, null)).IgnoreArguments().Return(prog);
            ldr.Stub(l => l.LoadImageBytes(null, 0)).IgnoreArguments().Return(bytes);
            ldr.Replay();
            sc.AddService(typeof(DecompilerEventListener), new FakeDecompilerEventListener());
            sc.AddService <DecompilerHost>(new FakeDecompilerHost());
            this.decSvc       = new DecompilerService();
            decSvc.Decompiler = new DecompilerDriver(ldr, sc);
            decSvc.Decompiler.Load("test.exe");
            program = decSvc.Decompiler.Project.Programs.First();
            decSvc.Decompiler.ScanPrograms();
            sc.AddService(typeof(IDecompilerService), decSvc);

            sc.AddService(typeof(IWorkerDialogService), new FakeWorkerDialogService());
        }
示例#9
0
        private void Given_Program(Address address, byte[] bytes)
        {
            var mem        = new MemoryArea(address, bytes);
            var segmentMap = new SegmentMap(
                mem.BaseAddress,
                new ImageSegment("proggie", mem, AccessMode.ReadExecute));
            var arch     = new X86ArchitectureFlat32("x86-protected-32");
            var platform = new FakePlatform(null, arch);

            platform.Test_DefaultCallingConvention = "__cdecl";
            this.program = new Program
            {
                Architecture = arch,
                SegmentMap   = segmentMap,
                Platform     = platform
            };
            platform.Test_GetCallingConvention = (ccName) => {
                return(new X86CallingConvention(4, 4, 4, true, false));
            };
        }
示例#10
0
        public void SlLookupType()
        {
            var slib = new SerializedLibrary
            {
                Types = new SerializedType[]
                {
                    new SerializedTypedef {
                        Name     = "int",
                        DataType = new PrimitiveType_v1 {
                            Domain = Reko.Core.Types.Domain.SignedInt, ByteSize = 4
                        }
                    }
                }
            };
            var arch     = new X86ArchitectureFlat32();
            var platform = new SysVPlatform(null, arch);
            var tldser   = new TypeLibraryDeserializer(platform, true, new TypeLibrary());
            var lib      = tldser.Load(slib);

            Assert.AreEqual(PrimitiveType.Int32, lib.LookupType("int"));
        }
示例#11
0
        private void Given_Program(Address address, byte[] bytes)
        {
            var mem      = new MemoryArea(address, bytes);
            var imageMap = new ImageMap(
                mem.BaseAddress,
                new ImageSegment("proggie", mem, AccessMode.ReadExecute));
            var arch     = new X86ArchitectureFlat32();
            var platform = new FakePlatform(null, arch);

            this.program = new Program
            {
                Architecture = arch,
                ImageMap     = imageMap,
                Platform     = platform
            };
            platform.Test_CreateProcedureSerializer = (t, d) =>
            {
                var typeLoader = new TypeLibraryDeserializer(platform, false, new TypeLibrary());
                return(new X86ProcedureSerializer((IntelArchitecture)program.Architecture, typeLoader, ""));
            };
        }
示例#12
0
        public void EP_TestCondition()
        {
            var p = new ProgramBuilder();

            p.Add("main", (m) =>
            {
                m.Label("foo");
                m.BranchCc(ConditionCode.EQ, "foo");
                m.Return();
            });

            var proc       = p.BuildProgram().Procedures.Values.First();
            var arch       = new X86ArchitectureFlat32();
            var ctx        = new SymbolicEvaluationContext(arch, proc.Frame);
            var simplifier = new ExpressionSimplifier(ctx, listener);
            var ep         = new ExpressionPropagator(null, simplifier, ctx, new ProgramDataFlow());

            var newInstr = proc.EntryBlock.Succ[0].Statements[0].Instruction.Accept(ep);

            Assert.AreEqual("branch Test(EQ,Z) foo", newInstr.ToString());
        }
示例#13
0
        private Program RewriteFile32(string relativePath, string configFile)
        {
            Program program;
            var     arch = new X86ArchitectureFlat32("x86-protected-32");
            var     asm  = new X86TextAssembler(arch);

            using (var rdr = new StreamReader(FileUnitTester.MapTestPath(relativePath)))
            {
                if (this.platform == null)
                {
                    this.platform = new Reko.Environments.Windows.Win32Platform(sc, arch);
                }
                program          = asm.Assemble(Address.Ptr32(0x10000000), rdr);
                program.Platform = this.platform;
            }
            foreach (var item in asm.ImportReferences)
            {
                program.ImportReferences.Add(item.Key, item.Value);
            }
            Rewrite(program, asm, configFile);
            return(program);
        }
        public static string Execute(string sAddress, string sOTherArg)
        {
            //Thread.Sleep(5000); // Simulate a slow running thread.
            var rnd = new Random();
            var buf = new byte[100];

            rnd.NextBytes(buf);
            var mem      = new ByteMemoryArea(Address.Ptr32(0x00123400), buf);
            var arch     = new X86ArchitectureFlat32(new ServiceContainer(), "x86-protected-32", new Dictionary <string, object>());
            var rdr      = arch.Endianness.CreateImageReader(mem, mem.BaseAddress);
            var dasm     = arch.CreateDisassembler(rdr);
            var sw       = new StringWriter();
            var renderer = new HtmlMachineInstructionRenderer(sw);
            var options  = new MachineInstructionRendererOptions();

            foreach (var instr in dasm)
            {
                instr.Render(renderer, options);
            }
            var sDasm = sw.ToString();

            return(sDasm);
        }
示例#15
0
        public void EP_ConditionOf()
        {
            var p    = new ProgramBuilder();
            var proc = p.Add("main", (m) =>
            {
                var szo = m.Frame.EnsureFlagGroup(Registers.eflags, 0x7, "SZO", PrimitiveType.Byte);
                var ebx = m.Frame.EnsureRegister(new RegisterStorage("ebx", 3, 0, PrimitiveType.Word32));
                var v4  = m.Frame.CreateTemporary(PrimitiveType.Word16);

                m.Assign(v4, m.IAdd(m.LoadW(ebx), 1));
                m.Store(ebx, v4);
                m.Assign(szo, m.Cond(v4));
                m.Return();
            });

            var arch       = new X86ArchitectureFlat32();
            var ctx        = new SymbolicEvaluationContext(arch, proc.Frame);
            var simplifier = new ExpressionSimplifier(ctx);
            var ep         = new ExpressionPropagator(arch, simplifier, ctx, new ProgramDataFlow());

            var newInstr = proc.EntryBlock.Succ[0].Statements[2].Instruction.Accept(ep);

            Assert.AreEqual("SZO = cond(v4)", newInstr.ToString());
        }
示例#16
0
        public IPlatform CreatePlatform()
        {
            if (platform != null)
            {
                return(platform);
            }

            platform = mr.Stub <IPlatform>();

            platform.Stub(p => p.Name).Return("TestPlatform");
            platform.Stub(p => p.PointerType).Return(PrimitiveType.Pointer32);
            platform.Stub(p => p.GetByteSizeFromCBasicType(CBasicType.Char)).Return(1);
            platform.Stub(p => p.GetByteSizeFromCBasicType(CBasicType.Short)).Return(2);
            platform.Stub(p => p.GetByteSizeFromCBasicType(CBasicType.Int)).Return(4);
            platform.Stub(p => p.GetByteSizeFromCBasicType(CBasicType.Long)).Return(4);
            platform.Stub(p => p.GetByteSizeFromCBasicType(CBasicType.LongLong)).Return(8);
            platform.Stub(p => p.GetByteSizeFromCBasicType(CBasicType.Float)).Return(4);
            platform.Stub(p => p.GetByteSizeFromCBasicType(CBasicType.Double)).Return(8);
            platform.Stub(p => p.GetByteSizeFromCBasicType(CBasicType.LongDouble)).Return(8);
            platform.Stub(p => p.GetByteSizeFromCBasicType(CBasicType.Int64)).Return(8);
            platform.Stub(p => p.CreateMetadata()).Do(new Func <TypeLibrary>(() => this.platformMetadata.Clone()));
            var arch = new X86ArchitectureFlat32();

            platform.Stub(p => p.Architecture).Return(arch);
            platform.Stub(p => p.DefaultCallingConvention).Return("__cdecl");

            platform.Stub(s => s.CreateProcedureSerializer(null, null)).IgnoreArguments().Do(
                new Func <ISerializedTypeVisitor <DataType>, string, ProcedureSerializer>((tlDeser, dc) =>
                                                                                          new X86ProcedureSerializer(arch, tlDeser, dc)
                                                                                          )
                );
            platform.Stub(p => p.SaveUserOptions()).Return(null);

            platform.Replay();
            return(platform);
        }
        public void Setup()
        {
            mr              = new MockRepository();
            services        = new ServiceContainer();
            declarationForm = mr.Stub <IDeclarationForm>();
            textBox         = new FakeTextBox();
            declarationForm.Stub(f => f.TextBox).Return(textBox);
            declarationForm.Stub(f => f.ShowAt(new Point()));
            declarationForm.Stub(f => f.Hide());
            declarationForm.Stub(f => f.Dispose());
            var dlgFactory = mr.Stub <IDialogFactory>();

            dlgFactory.Stub(f => f.CreateDeclarationForm()).Return(declarationForm);
            services.AddService <IDialogFactory>(dlgFactory);
            mr.ReplayAll();
            interactor = new DeclarationFormInteractor(services);
            var mem      = new MemoryArea(Address32.Ptr32(0x10), new byte[40]);
            var seg      = new ImageSegment(".text", mem, AccessMode.ReadWrite);
            var imageMap = new ImageMap(Address32.Ptr32(0x05), seg);
            var arch     = new X86ArchitectureFlat32();
            var platform = new Win32Platform(null, arch);

            program = new Program(imageMap, arch, platform);
        }
 public void Setup()
 {
     arch = new X86ArchitectureFlat32();
     asm = new X86Assembler(arch, loadAddress, new List<EntryPoint>());
 }
示例#19
0
        private void BuildTest32(Action <X86Assembler> m)
        {
            var arch = new X86ArchitectureFlat32("x86-protected-32");

            BuildTest(arch, Address.Ptr32(0x10000), new FakePlatform(sc, arch), m);
        }
示例#20
0
 public void Setup()
 {
     mr          = new MockRepository();
     mockFactory = new MockFactory(mr);
     arch        = new X86ArchitectureFlat32();
 }
示例#21
0
 public void Setup()
 {
     arch = new X86ArchitectureFlat32();
     asm  = new X86Assembler(arch, loadAddress, new List <EntryPoint>());
 }