Example #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();

		}
Example #2
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);
			}
		}