Example #1
0
        public static void Main(string[] args)
        {
            var services = new ServiceContainer();
            var listener = new CmdLineListener
            {
                Quiet = Console.IsOutputRedirected
            };
            var config        = RekoConfigurationService.Load(services);
            var diagnosticSvc = new CmdLineDiagnosticsService(Console.Out);
            var fsSvc         = new FileSystemServiceImpl();
            var dcSvc         = new DecompilerService();

            services.AddService <IDecompilerService>(dcSvc);
            services.AddService <DecompilerEventListener>(listener);
            services.AddService <IConfigurationService>(config);
            services.AddService <ITypeLibraryLoaderService>(new TypeLibraryLoaderServiceImpl(services));
            services.AddService <IDiagnosticsService>(diagnosticSvc);
            services.AddService <IFileSystemService>(fsSvc);
            services.AddService <IDecompiledFileService>(new DecompiledFileService(fsSvc));
            services.AddService <ITestGenerationService>(new TestGenerationService(services));
            var ldr        = new Loader(services);
            var decompiler = new Decompiler(ldr, services);

            dcSvc.Decompiler = decompiler;
            var driver = new CmdLineDriver(services, ldr, decompiler, listener);

            driver.Execute(args);
        }
Example #2
0
        private void DecompileAssembler(string archName, Address loadAddress)
        {
            var sc      = new ServiceContainer();
            var cfg     = RekoConfigurationService.Load(sc);
            var arch    = cfg.GetArchitecture(archName);
            var asm     = arch.CreateAssembler(null);
            var program = asm.AssembleFragment(loadAddress, txtAssembler.Text + Environment.NewLine);
            var loader  = new Loader(sc);
            var decomp  = new Decompiler(loader, sc);
            var proj    = new Project {
                Programs =
                {
                    program
                }
            };

            decomp.Project = proj;
            decomp.ScanPrograms();
            decomp.AnalyzeDataFlow();
            decomp.ReconstructTypes();
            decomp.StructureProgram();
            decomp.WriteDecompilerProducts();

            plcOutput.Text     = host.DisassemblyWriter.ToString();
            plcDecompiled.Text = host.DecompiledCodeWriter.ToString();
        }
Example #3
0
        public Sifter(string[] args)
        {
            var sc = new ServiceContainer();

            testGen = new TestGenerationService(sc)
            {
                OutputDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
            };
            fsSvc       = new FileSystemServiceImpl();
            this.cfgSvc = RekoConfigurationService.Load(sc, "reko/reko.config");
            sc.AddService <ITestGenerationService>(testGen);
            sc.AddService <IFileSystemService>(fsSvc);
            sc.AddService <IConfigurationService>(cfgSvc);
            this.processInstr = new Action <byte[], MachineInstruction?>(ProcessInstruction);
            IProcessorArchitecture?arch;

            (arch, this.instrRenderer) = ProcessArgs(args);
            if (arch is null)
            {
                throw new ApplicationException("Unable to load Reko architecture.");
            }
            this.arch        = arch;
            this.baseAddress = Address.Create(arch.PointerType, 0x00000000);    //$TODO allow customization?
            this.progress    = new Progress();
        }
Example #4
0
        public static void Main(string [] args)
        {
            var services = new ServiceContainer();

            if (args.Length == 0)
            {
                services.AddService(typeof(IServiceFactory), new ServiceFactory(services));
                services.AddService(typeof(IDialogFactory), new WindowsFormsDialogFactory(services));
                services.AddService(typeof(IRegistryService), new WindowsFormsRegistryService());
                services.AddService(typeof(ISettingsService), new WindowsFormsSettingsService(services));
                var interactor = new MainFormInteractor(services);
                interactor.Run();
            }
            else
            {
                var listener = NullDecompilerEventListener.Instance;

                services.AddService(typeof(DecompilerEventListener), listener);
                services.AddService(typeof(IRegistryService), new WindowsFormsRegistryService());
                services.AddService(typeof(IConfigurationService), RekoConfigurationService.Load());
                var ldr = new Loader(services);
                var dec = new DecompilerDriver(ldr, services);
                dec.Decompile(args[0]);
            }
        }
Example #5
0
        public async Task Zot()
        {
            var sc    = new ServiceContainer();
            var plSvc = new PluginLoaderService();

            sc.AddService <IPluginLoaderService>(plSvc);
            var fsSvc = new FileSystemServiceImpl();

            sc.AddService <IFileSystemService>(fsSvc);
            var cfgSvc = RekoConfigurationService.Load(sc, @"D:\dev\uxmal\reko\extras\parallel\UnitTests\bin\Debug\net5.0\reko\reko.config");

            sc.AddService <IConfigurationService>(cfgSvc);
            var listener = new NullDecompilerEventListener();

            sc.AddService <DecompilerEventListener>(listener);
            var dechost = new Reko.DecompiledFileService(sc, fsSvc, listener);

            sc.AddService <IDecompiledFileService>(dechost);
            var tlSvc = new TypeLibraryLoaderServiceImpl(sc);

            sc.AddService <ITypeLibraryLoaderService>(tlSvc);
            var loader  = new Reko.Loading.Loader(sc);
            var program = (Program)loader.Load(ImageLocation.FromUri(@"D:\dev\uxmal\reko\users\smx-zoo\RELEASE_MIPS\RELEASE"));
            var project = Project.FromSingleProgram(program);
            var reko    = new Reko.Decompiler(project, sc);

            TryFindSegment(program, ".text", out var seg);
            var scanner = new Scanner(seg.MemoryArea);
            var result  = await scanner.ScanAsync(program.EntryPoints.Values);

            Console.Write(result.B.Count);
        }
Example #6
0
        public Sifter(string[] args)
        {
            this.cfgSvc       = RekoConfigurationService.Load("reko/reko.config");
            this.processInstr = new Action <byte[], MachineInstruction?>(ProcessInstruction);
            (this.arch, this.instrRenderer) = ProcessArgs(args);
            var baseAddress = Address.Ptr32(0x00000000);    //$TODO allow customization?

            this.mem      = new MemoryArea(baseAddress, new byte[100]);
            this.rdr      = arch.CreateImageReader(mem, 0);
            this.dasm     = arch.CreateDisassembler(rdr);
            this.progress = new Progress();
        }
Example #7
0
        public static void Main(string[] args)
        {
            var services      = new ServiceContainer();
            var listener      = new CmdLineListener();
            var config        = RekoConfigurationService.Load();
            var diagnosticSvc = new CmdLineDiagnosticsService(Console.Out);

            services.AddService <DecompilerEventListener>(listener);
            services.AddService <IConfigurationService>(config);
            services.AddService <ITypeLibraryLoaderService>(new TypeLibraryLoaderServiceImpl(services));
            services.AddService <IDiagnosticsService>(diagnosticSvc);
            services.AddService <IFileSystemService>(new FileSystemServiceImpl());
            services.AddService <DecompilerHost>(new CmdLineHost());
            var driver = new CmdLineDriver(services, config);

            driver.Execute(args);
        }
Example #8
0
        private void DecompileC()
        {
            string tmpName = Guid.NewGuid().ToString();
            string tmpDir  = Server.MapPath("tmp");
            string cFile   = Path.Combine(tmpDir, tmpName + ".c");
            string asmFile = Path.Combine(tmpDir, tmpName + ".asm");

            try
            {
                CopyCSourceToTempFile(txtAssembler.Text, cFile);
                if (CompileCFile(tmpDir, cFile))
                {
                    var sc       = new ServiceContainer();
                    var ldr      = new Loader(sc);
                    var cfg      = RekoConfigurationService.Load(sc);
                    var arch     = cfg.GetArchitecture("x86-protected-32");
                    var env      = cfg.GetEnvironment("win32");
                    var platform = env.Load(sc, arch);
                    var asm      = arch.CreateAssembler(null);
                    var program  = asm.AssembleFragment(Address.Ptr32(0x10000000), txtAssembler.Text + Environment.NewLine);
                    program.Platform = platform;
                    var decomp  = new Decompiler(ldr, sc);
                    var project = new Project
                    {
                        Programs = { program }
                    };
                    decomp.Project = project;
                    decomp.ScanPrograms();
                    decomp.AnalyzeDataFlow();
                    decomp.ReconstructTypes();
                    decomp.StructureProgram();
                    decomp.WriteDecompilerProducts();

                    plcOutput.Text     = host.DisassemblyWriter.ToString();
                    plcDecompiled.Text = host.DecompiledCodeWriter.ToString();
                }
            }
            finally
            {
                if (File.Exists(asmFile))
                {
                    File.Delete(asmFile);
                }
            }
        }
Example #9
0
        private static RekoConfigurationService MakeServices()
        {
            var services = new ServiceContainer();
            var cfg      = RekoConfigurationService.Load(services, "reko/reko.config");

            services.AddService <IFileSystemService>(new FileSystemServiceImpl());
            var testSvc = new TestGenerationService(services)
            {
                OutputDirectory = Path.GetDirectoryName(typeof(Program).Assembly.Location !)
            };
            var mutable = new MutableTestGenerationService(testSvc)
            {
                IsMuted = true
            };

            services.AddService <ITestGenerationService>(mutable);
            return(cfg);
        }
        private Reko.Decompiler CreateRekoInstance(CefV8Context context)
        {
            var fsSvc    = new FileSystemServiceImpl();
            var listener = new ListenerService(context, eventListeners);
            var dfSvc    = new DecompiledFileService(fsSvc, listener);

            services.AddService(typeof(IFileSystemService), fsSvc);
            services.AddService(typeof(DecompilerEventListener), listener);
            var configSvc = RekoConfigurationService.Load(services, "reko/reko.config");

            services.AddService(typeof(IConfigurationService), configSvc);
            services.AddService(typeof(IDecompiledFileService), dfSvc);
            services.AddService(typeof(ITypeLibraryLoaderService), new TypeLibraryLoaderServiceImpl(services));
            services.AddService(typeof(IPluginLoaderService), new PluginLoaderService());
            var loader = new Reko.Loading.Loader(services);

            return(new Reko.Decompiler(loader, services));
        }
Example #11
0
        public int Execute(string [] args)
        {
            TextReader input   = Console.In;
            TextWriter output  = Console.Out;
            var        sc      = new ServiceContainer();
            var        rekoCfg = RekoConfigurationService.Load();

            sc.AddService <IConfigurationService>(rekoCfg);

            var docopt = new Docopt();
            IDictionary <string, ValueObject> options;

            try {
                options = docopt.Apply(usage, args);
            } catch (Exception ex)
            {
                Console.Error.WriteLine(ex);
                return(1);
            }
            var arch = rekoCfg.GetArchitecture(options["-a"].ToString());

            if (arch == null)
            {
                Console.WriteLine(
                    "c2xml: unknown architecture '{0}'. Check the c2xml config file for supported architectures.",
                    options["-a"]);
                return(-1);
            }
            var envElem = rekoCfg.GetEnvironment(options["-e"].ToString());

            if (envElem == null)
            {
                Console.WriteLine(
                    "c2xml: unknown environment '{0}'. Check the c2xml config file for supported architectures.",
                    options["-e"]);
                return(-1);
            }

            var platform = envElem.Load(sc, arch);

            try
            {
                input = new StreamReader(options["<inputfile>"].ToString());
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("c2xml: unable to open file {0} for reading. {1}", options["<inputfile>"], ex.Message);
                return(1);
            }

            if (options.ContainsKey("<outputfile>") &&
                options["<outputfile>"] != null)
            {
                try
                {
                    output = new StreamWriter(options["<outputfile>"].ToString());
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine("c2xml: unable to open file {0} for writing. {1}", options["<outputfile>"], ex.Message);
                    return(1);
                }
            }
            var xWriter = new XmlTextWriter(output)
            {
                Formatting = Formatting.Indented
            };

            XmlConverter c = new XmlConverter(input, xWriter, platform);

            c.Convert();
            output.Flush();
            return(0);
        }
Example #12
0
        public int Execute(string [] args)
        {
            TextReader input;
            Stream     output = Console.OpenStandardOutput();
            var        sc     = new ServiceContainer();

            sc.AddService(typeof(IPluginLoaderService), new PluginLoaderService());
            var rekoCfg = RekoConfigurationService.Load(sc);

            sc.AddService <IConfigurationService>(rekoCfg);

            var docopt = new Docopt();
            IDictionary <string, ValueObject> options;

            try {
                options = docopt.Apply(usage, args);
            } catch (Exception ex)
            {
                Console.Error.WriteLine(ex);
                return(1);
            }

            var arch = rekoCfg.GetArchitecture(options["-a"].ToString());

            if (arch == null)
            {
                Console.WriteLine(
                    "c2xml: unknown architecture '{0}'. Check the c2xml config file for supported architectures.",
                    options["-a"]);
                return(-1);
            }

            var envElem = rekoCfg.GetEnvironment(options["-e"].ToString());

            if (envElem == null)
            {
                Console.WriteLine(
                    "c2xml: unknown environment '{0}'. Check the c2xml config file for supported architectures.",
                    options["-e"]);
                return(-1);
            }
            var platform = envElem.Load(sc, arch);

            try
            {
                input = new StreamReader(options["<inputfile>"].ToString());
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("c2xml: unable to open file {0} for reading. {1}", options["<inputfile>"], ex.Message);
                return(1);
            }

            if (options.ContainsKey("<outputfile>") && options["<outputfile>"] != null)
            {
                try
                {
                    output = new FileStream(options["<outputfile>"].ToString(), FileMode.Create, FileAccess.Write);
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine("c2xml: unable to open file {0} for writing. {1}", options["<outputfile>"], ex.Message);
                    return(1);
                }
            }
            string dialect = null;

            if (options.TryGetValue("-d", out var optDialect) && optDialect != null)
            {
                dialect = (string)optDialect.Value;
            }
            var xWriter = new XmlTextWriter(output, new UTF8Encoding(false))
            {
                Formatting = Formatting.Indented
            };

            XmlConverter c = new XmlConverter(input, xWriter, platform, dialect);

            c.Convert();
            output.Flush();
            output.Close();
            return(0);
        }
Example #13
0
 public IConfigurationService CreateDecompilerConfiguration()
 {
     return(RekoConfigurationService.Load());
 }