Exemplo n.º 1
0
        private void DecompileAssembler(string asmLabel, Address loadAddress)
        {
            var cfg    = RekoConfigurationService.Load();
            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();
        }
Exemplo n.º 2
0
        private void DecompileRawImage(DecompilerDriver dec, Dictionary <string, object> pArgs)
        {
            var arch = config.GetArchitecture((string)pArgs["--arch"]);

            if (arch == null)
            {
                throw new ApplicationException(string.Format("Unknown architecture {0}", pArgs["--arch"]));
            }

            object   sEnv;
            Platform platform;

            if (pArgs.TryGetValue("--env", out sEnv))
            {
                var opEnv = config.GetEnvironment((string)sEnv);
                if (opEnv == null)
                {
                    throw new ApplicationException(string.Format("Unknown operating environment {0}", sEnv));
                }
                platform = opEnv.Load(services, arch);
            }
            else
            {
                platform = new DefaultPlatform(services, arch);
            }

            Address addrBase;
            Address addrEntry;

            if (!arch.TryParseAddress((string)pArgs["--base"], out addrBase))
            {
                throw new ApplicationException(string.Format("'{0}' doesn't appear to be a valid address.", pArgs["--base"]));
            }
            if (pArgs.ContainsKey("--entry"))
            {
                if (!arch.TryParseAddress((string)pArgs["--base"], out addrEntry))
                {
                    throw new ApplicationException(string.Format("'{0}' doesn't appear to be a valid address.", pArgs["--base"]));
                }
            }
            else
            {
                addrEntry = addrBase;
            }


            var state = CreateInitialState(arch, pArgs);

            dec.LoadRawImage((string)pArgs["filename"], arch, platform, addrBase);
            dec.Project.Programs[0].EntryPoints.Add(new EntryPoint(addrEntry, state));
            dec.ScanPrograms();
            dec.AnalyzeDataFlow();
            dec.ReconstructTypes();
            dec.StructureProgram();
            dec.WriteDecompilerProducts();
        }
Exemplo n.º 3
0
        private void DecompileRawImage(DecompilerDriver dec, Dictionary <string, object> pArgs)
        {
            var arch = config.GetArchitecture((string)pArgs["--arch"]);

            if (arch == null)
            {
                throw new ApplicationException(string.Format("Unknown architecture {0}", pArgs["--arch"]));
            }

            object sEnv;

            pArgs.TryGetValue("--env", out sEnv);

            Address addrBase;
            Address addrEntry;

            if (!arch.TryParseAddress((string)pArgs["--base"], out addrBase))
            {
                throw new ApplicationException(string.Format("'{0}' doesn't appear to be a valid address.", pArgs["--base"]));
            }
            if (pArgs.ContainsKey("--entry"))
            {
                if (!arch.TryParseAddress((string)pArgs["--base"], out addrEntry))
                {
                    throw new ApplicationException(string.Format("'{0}' doesn't appear to be a valid address.", pArgs["--base"]));
                }
            }
            else
            {
                addrEntry = addrBase;
            }


            var state = CreateInitialState(arch, pArgs);

            dec.LoadRawImage((string)pArgs["filename"], (string)pArgs["--arch"], (string)sEnv, addrBase);
            dec.Project.Programs[0].EntryPoints.Add(
                addrEntry,
                new ImageSymbol(addrEntry)
            {
                ProcessorState = state
            });
            object oHeur;

            if (pArgs.TryGetValue("heuristics", out oHeur))
            {
                dec.Project.Programs[0].User.Heuristics = ((string[])oHeur).ToSortedSet();
            }
            dec.ScanPrograms();
            dec.AnalyzeDataFlow();
            dec.ReconstructTypes();
            dec.StructureProgram();
            dec.WriteDecompilerProducts();
        }
Exemplo n.º 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                 = RekoConfigurationService.Load();
                    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);
                }
            }
        }
Exemplo n.º 5
0
        private void DecompileRawImage(DecompilerDriver dec, Dictionary<string, object> pArgs)
        {
            var arch = config.GetArchitecture((string)pArgs["--arch"]);
            if (arch == null)
                throw new ApplicationException(string.Format("Unknown architecture {0}", pArgs["--arch"]));

            object sEnv;
            pArgs.TryGetValue("--env", out sEnv);

            Address addrBase;
            Address addrEntry;
            if (!arch.TryParseAddress((string)pArgs["--base"], out addrBase))
                throw new ApplicationException(string.Format("'{0}' doesn't appear to be a valid address.", pArgs["--base"]));
            if (pArgs.ContainsKey("--entry"))
            {
                if (!arch.TryParseAddress((string)pArgs["--base"], out addrEntry))
                    throw new ApplicationException(string.Format("'{0}' doesn't appear to be a valid address.", pArgs["--base"]));
            }
            else
                addrEntry = addrBase;


            var state = CreateInitialState(arch, pArgs);
            dec.LoadRawImage((string)pArgs["filename"], (string)pArgs["--arch"], (string) sEnv, addrBase);
            dec.Project.Programs[0].EntryPoints.Add(
                addrEntry,
                new ImageSymbol(addrEntry)
                {
                    ProcessorState = state
                });
            object oHeur;
            if (pArgs.TryGetValue("heuristics", out oHeur))
            {
                dec.Project.Programs[0].User.Heuristics = ((string[])oHeur).ToSortedSet();
            }
            dec.ScanPrograms();
            dec.AnalyzeDataFlow();
            dec.ReconstructTypes();
            dec.StructureProgram();
            dec.WriteDecompilerProducts();
        }
Exemplo n.º 6
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);
			}
		}
Exemplo n.º 7
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();

		}
Exemplo n.º 8
0
        private void DecompileRawImage(DecompilerDriver dec, Dictionary<string, object> pArgs)
        {
            var arch = config.GetArchitecture((string)pArgs["--arch"]);
            if (arch == null)
                throw new ApplicationException(string.Format("Unknown architecture {0}", pArgs["--arch"]));

            object sEnv;
            Platform platform;
            if (pArgs.TryGetValue("--env", out sEnv))
            {
                var opEnv = config.GetEnvironment((string)sEnv);
                if (opEnv == null)
                    throw new ApplicationException(string.Format("Unknown operating environment {0}", sEnv));
                platform = opEnv.Load(services, arch);
            }
            else
            {
                platform = new DefaultPlatform(services, arch);
            }

            Address addrBase;
            Address addrEntry;
            if (!arch.TryParseAddress((string)pArgs["--base"], out addrBase))
                throw new ApplicationException(string.Format("'{0}' doesn't appear to be a valid address.", pArgs["--base"]));
            if (pArgs.ContainsKey("--entry"))
            {
                if (!arch.TryParseAddress((string)pArgs["--base"], out addrEntry))
                    throw new ApplicationException(string.Format("'{0}' doesn't appear to be a valid address.", pArgs["--base"]));
            }
            else
                addrEntry = addrBase;


            var state = CreateInitialState(arch, pArgs);
            dec.LoadRawImage((string)pArgs["filename"], arch, platform, addrBase);
            dec.Project.Programs[0].EntryPoints.Add(new EntryPoint(addrEntry, state));
            dec.ScanPrograms();
            dec.AnalyzeDataFlow();
            dec.ReconstructTypes();
            dec.StructureProgram();
            dec.WriteDecompilerProducts();
        }