Beispiel #1
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);
 }
Beispiel #2
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<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);
 }
Beispiel #3
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, 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();
        }
Beispiel #4
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, 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);
			}
		}
Beispiel #5
0
 public CmdLineDriver(IServiceProvider services, DecompilerConfiguration config)
 {
     this.services = services;
     this.config = config;
 }
Beispiel #6
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);
     }
 }
Beispiel #7
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);
     }
 }
Beispiel #8
0
        public int Execute(string [] args)
        {
            TextReader input = Console.In;
            TextWriter output = Console.Out;
            var sc = new ServiceContainer();
            var rekoCfg = new DecompilerConfiguration();

            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;
        }