Exemple #1
0
        private void DecompileAssembler(string asmLabel, Address loadAddress)
        {
            var cfg    = new DecompilerConfiguration();
            var asm    = cfg.GetAssembler(asmLabel);
            var prog   = asm.AssembleFragment(loadAddress, txtAssembler.Text + Environment.NewLine);
            var sc     = new ServiceContainer();
            var loader = new Loader(sc);
            DecompilerDriver decomp = new DecompilerDriver(loader, host, sc);
            var proj = new Project {
                Programs =
                {
                    prog
                }
            };

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

            plcOutput.Text     = host.DisassemblyWriter.ToString();
            plcDecompiled.Text = host.DecompiledCodeWriter.ToString();
        }
Exemple #2
0
 private static void DumpRawFiles(DecompilerConfiguration config, TextWriter w, string fmtString)
 {
     foreach (var raw in config.GetRawFiles()
              .OfType <RawFileElement>()
              .OrderBy(a => a.Name))
     {
         w.WriteLine(fmtString, raw.Name, raw.Description);
     }
 }
Exemple #3
0
 private static void DumpEnvironments(DecompilerConfiguration config, TextWriter w, string fmtString)
 {
     foreach (var arch in config.GetEnvironments()
              .OfType <OperatingEnvironmentElement>()
              .OrderBy(a => a.Name))
     {
         w.WriteLine(fmtString, arch.Name, arch.Description);
     }
 }
Exemple #4
0
        public static void Main(string[] args)
        {
            var services      = new ServiceContainer();
            var listener      = new CmdLineListener();
            var config        = new DecompilerConfiguration();
            var diagnosticSvc = new CmdLineDiagnosticsService(Console.Out);

            services.AddService(typeof(DecompilerEventListener), listener);
            services.AddService(typeof(IConfigurationService), config);
            services.AddService(typeof(ITypeLibraryLoaderService), new TypeLibraryLoaderServiceImpl());
            services.AddService(typeof(IDiagnosticsService), diagnosticSvc);
            var driver = new CmdLineDriver(services, config);

            driver.Execute(args);
        }
Exemple #5
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                 = new DecompilerConfiguration();
                    var asm                 = cfg.GetAssembler("x86-masm");
                    var program             = asm.AssembleFragment(Address.Ptr32(0x10000000), txtAssembler.Text + Environment.NewLine);
                    DecompilerDriver decomp = new DecompilerDriver(ldr, host, 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);
                }
            }
        }
Exemple #6
0
 public CmdLineDriver(IServiceProvider services, DecompilerConfiguration config)
 {
     this.services = services;
     this.config   = config;
 }