示例#1
0
        protected void RunHexTest(string hexFile, string outputFile)
        {
            var svc           = new ServiceContainer();
            var cfg           = new FakeDecompilerConfiguration();
            var eventListener = new FakeDecompilerEventListener();

            svc.AddService <IConfigurationService>(cfg);
            svc.AddService <DecompilerEventListener>(eventListener);
            svc.AddService <IDecompiledFileService>(new FakeDecompiledFileService());
            ILoader ldr       = new Loader(svc);
            var     imgLoader = new DchexLoader(FileUnitTester.MapTestPath(hexFile), svc, null);
            var     program   = imgLoader.Load(null);
            var     project   = new Project {
                Programs = { program }
            };
            var ep             = ImageSymbol.Procedure(program.Architecture, program.ImageMap.BaseAddress);
            var importResolver = new ImportResolver(project, program, eventListener);
            var scan           = new Scanner(program, importResolver, svc);

            scan.EnqueueImageSymbol(ep, true);
            scan.ScanImage();

            var dfa = new DataFlowAnalysis(program, null, eventListener);

            dfa.AnalyzeProgram();
            RunTest(program, outputFile);
        }
示例#2
0
        private static void Rewrite(Program program, Assembler asm, string configFile)
        {
            var fakeDiagnosticsService = new FakeDiagnosticsService();
            var fakeConfigService      = new FakeDecompilerConfiguration();
            var eventListener          = new FakeDecompilerEventListener();
            var sc = new ServiceContainer();

            sc.AddService(typeof(IDiagnosticsService), fakeDiagnosticsService);
            sc.AddService(typeof(IConfigurationService), fakeConfigService);
            sc.AddService <DecompilerEventListener>(eventListener);
            sc.AddService <DecompilerHost>(new FakeDecompilerHost());
            var loader  = new Loader(sc);
            var project = string.IsNullOrEmpty(configFile)
                ? new Project()
                : new ProjectLoader(sc, loader, eventListener).LoadProject(FileUnitTester.MapTestPath(configFile));
            var scan = new Scanner(
                program,
                new ImportResolver(project, program, eventListener),
                sc);

            scan.EnqueueImageSymbol(new ImageSymbol(asm.StartAddress), true);
            foreach (var f in project.Programs)
            {
                foreach (var sp in f.User.Procedures.Values)
                {
                    scan.EnqueueUserProcedure(sp);
                }
            }
            scan.ScanImage();
        }
示例#3
0
        private static void Rewrite(Program program, IAssembler asm, Action <Program> postLoad)
        {
            var fakeConfigService = new FakeDecompilerConfiguration();
            var eventListener     = new FakeDecompilerEventListener();
            var sc = new ServiceContainer();

            sc.AddService <IConfigurationService>(fakeConfigService);
            sc.AddService <DecompilerEventListener>(eventListener);
            sc.AddService <IFileSystemService>(new FileSystemServiceImpl());
            var loader  = new Loader(sc);
            var project = new Project
            {
                Programs = { program }
            };

            postLoad(program);
            var scan = new Scanner(
                program,
                new DynamicLinker(project, program, eventListener),
                sc);

            scan.EnqueueImageSymbol(ImageSymbol.Location(program.Architecture, asm.StartAddress), true);
            foreach (var f in project.Programs)
            {
                foreach (var sp in f.User.Procedures.Values)
                {
                    scan.EnqueueUserProcedure(program.Architecture, sp);
                }
            }
            scan.ScanImage();
        }
示例#4
0
        private static void Rewrite(Program prog, Assembler asm, string configFile)
        {
            var fakeDiagnosticsService = new FakeDiagnosticsService();
            var fakeConfigService      = new FakeDecompilerConfiguration();
            var sc = new ServiceContainer();

            sc.AddService(typeof(IDiagnosticsService), fakeDiagnosticsService);
            sc.AddService(typeof(IConfigurationService), fakeConfigService);
            var loader  = new Loader(sc);
            var project = string.IsNullOrEmpty(configFile)
                ? new Project()
                : new ProjectLoader(sc, loader).LoadProject(FileUnitTester.MapTestPath(configFile));
            var scan = new Scanner(
                prog,
                new Dictionary <Address, ProcedureSignature>(),
                new ImportResolver(project),
                new FakeDecompilerEventListener());

            scan.EnqueueEntryPoint(new EntryPoint(asm.StartAddress, prog.Architecture.CreateProcessorState()));
            foreach (var f in project.Programs)
            {
                foreach (var sp in f.UserProcedures.Values)
                {
                    scan.EnqueueUserProcedure(sp);
                }
            }
            scan.ScanImage();
        }
示例#5
0
        protected Program RewriteFile(string relativePath, Address addrBase)
        {
            var sc            = new ServiceContainer();
            var config        = new FakeDecompilerConfiguration();
            var eventListener = new FakeDecompilerEventListener();

            sc.AddService <IConfigurationService>(config);
            sc.AddService <DecompilerHost>(new FakeDecompilerHost());
            sc.AddService <DecompilerEventListener>(eventListener);
            sc.AddService <IFileSystemService>(new FileSystemServiceImpl());
            ILoader ldr     = new Loader(sc);
            var     program = ldr.AssembleExecutable(
                FileUnitTester.MapTestPath(relativePath),
                new X86TextAssembler(sc, new X86ArchitectureReal()),
                addrBase);

            program.Platform = new DefaultPlatform(sc, program.Architecture);
            var ep      = new EntryPoint(program.ImageMap.BaseAddress, program.Architecture.CreateProcessorState());
            var project = new Project {
                Programs = { program }
            };
            var scan = new Scanner(
                program,
                new ImportResolver(project, program, eventListener),
                sc);

            scan.EnqueueEntryPoint(ep);
            scan.ScanImage();

            var importResolver = new ImportResolver(project, program, eventListener);
            var dfa            = new DataFlowAnalysis(program, importResolver, eventListener);

            dfa.AnalyzeProgram();
            return(program);
        }
示例#6
0
        private static void Rewrite(Program program, IAssembler asm, string configFile)
        {
            var fakeConfigService = new FakeDecompilerConfiguration();
            var eventListener     = new FakeDecompilerEventListener();
            var sc = new ServiceContainer();

            sc.AddService <IConfigurationService>(fakeConfigService);
            sc.AddService <DecompilerEventListener>(eventListener);
            sc.AddService <IDecompiledFileService>(new FakeDecompiledFileService());
            sc.AddService <IFileSystemService>(new FileSystemServiceImpl());
            var loader  = new Loader(sc);
            var project = string.IsNullOrEmpty(configFile)
                ? new Project()
                : new ProjectLoader(sc, loader, eventListener).LoadProject(FileUnitTester.MapTestPath(configFile));
            var scan = new Scanner(
                program,
                new DynamicLinker(project, program, eventListener),
                sc);

            scan.EnqueueImageSymbol(ImageSymbol.Procedure(program.Architecture, asm.StartAddress), true);
            foreach (var f in project.Programs)
            {
                foreach (var sp in f.User.Procedures.Values)
                {
                    scan.EnqueueUserProcedure(program.Architecture, sp);
                }
            }
            scan.ScanImage();
        }
示例#7
0
        protected Program RewriteFile(string relativePath, Address addrBase)
        {
            var services = new ServiceContainer();
            var config   = new FakeDecompilerConfiguration();

            services.AddService <IConfigurationService>(config);
            ILoader ldr     = new Loader(services);
            var     program = ldr.AssembleExecutable(
                FileUnitTester.MapTestPath(relativePath),
                new X86TextAssembler(new IntelArchitecture(ProcessorMode.Real)),
                addrBase);

            program.Platform = new DefaultPlatform(services, program.Architecture);
            var ep      = new EntryPoint(program.Image.BaseAddress, program.Architecture.CreateProcessorState());
            var project = new Project {
                Programs = { program }
            };
            var scan = new Scanner(
                program,
                new Dictionary <Address, ProcedureSignature>(),
                new ImportResolver(project),
                new FakeDecompilerEventListener());

            scan.EnqueueEntryPoint(ep);
            scan.ScanImage();

            var dfa = new DataFlowAnalysis(program, new FakeDecompilerEventListener());

            dfa.AnalyzeProgram();
            return(program);
        }
示例#8
0
        protected virtual void PopulateServiceContainer(ServiceContainer sc)
        {
            var config = new FakeDecompilerConfiguration();

            eventListener = new FakeDecompilerEventListener();
            sc.AddService <IConfigurationService>(config);
            sc.AddService <IDecompiledFileService>(new FakeDecompiledFileService());
            sc.AddService <DecompilerEventListener>(eventListener);
            sc.AddService <IFileSystemService>(new FileSystemServiceImpl());
        }
示例#9
0
        public void Setup()
        {
            mr = new MockRepository();
            var config = new FakeDecompilerConfiguration();
            var host   = new FakeDecompilerHost();
            var sp     = new ServiceContainer();

            loader = mr.StrictMock <ILoader>();
            sp.AddService(typeof(DecompilerEventListener), new FakeDecompilerEventListener());
            loader.Replay();
            decompiler = new TestDecompiler(loader, host, sp);
            loader.BackToRecord();
        }
示例#10
0
        protected Program RewriteFile(
            string relativePath,
            Address addrBase,
            Func <IServiceProvider, IProcessorArchitecture, IPlatform> mkPlatform)
        {
            sc = new ServiceContainer();
            var config        = new FakeDecompilerConfiguration();
            var eventListener = new FakeDecompilerEventListener();

            sc.AddService <IConfigurationService>(config);
            sc.AddService <IDecompiledFileService>(new FakeDecompiledFileService());
            sc.AddService <DecompilerEventListener>(eventListener);
            sc.AddService <IFileSystemService>(new FileSystemServiceImpl());
            var     arch    = new X86ArchitectureReal(sc, "x86-real-16");
            ILoader ldr     = new Loader(sc);
            var     program = ldr.AssembleExecutable(
                FileUnitTester.MapTestPath(relativePath),
                new X86TextAssembler(arch),
                null,
                addrBase);

            program.Platform = mkPlatform(sc, program.Architecture);

            var ep      = ImageSymbol.Procedure(arch, program.SegmentMap.BaseAddress);
            var project = new Project {
                Programs = { program }
            };
            var scan = new Scanner(
                program,
                new DynamicLinker(project, program, eventListener),
                sc);

            scan.EnqueueImageSymbol(ep, true);
            scan.ScanImage();

            var dynamicLinker = new DynamicLinker(project, program, eventListener);
            var dfa           = new DataFlowAnalysis(program, dynamicLinker, eventListener);

            dfa.AnalyzeProgram();
            return(program);
        }
示例#11
0
        protected void RunHexTest(string hexFile, string outputFile)
        {
            var svc = new ServiceContainer();
            var cfg = new FakeDecompilerConfiguration();

            svc.AddService <IConfigurationService>(cfg);
            ILoader ldr       = new Loader(svc);
            var     imgLoader = new DchexLoader(FileUnitTester.MapTestPath(hexFile), svc, null);
            var     img       = imgLoader.Load(null);
            var     program   = new Program(img.Image, img.Image.CreateImageMap(), img.Architecture, img.Platform);
            var     project   = new Project {
                Programs = { program }
            };
            var ep   = new EntryPoint(program.Image.BaseAddress, program.Architecture.CreateProcessorState());
            var scan = new Scanner(program, new Dictionary <Address, ProcedureSignature>(), new ImportResolver(project), new FakeDecompilerEventListener());

            scan.EnqueueEntryPoint(ep);
            scan.ScanImage();

            var dfa = new DataFlowAnalysis(program, new FakeDecompilerEventListener());

            dfa.AnalyzeProgram();
            RunTest(program, outputFile);
        }