private void Decompile(Dictionary <string, object> pArgs) { pArgs.TryGetValue("--loader", out object loader); try { var fileName = (string)pArgs["filename"]; var filePath = Path.GetFullPath(fileName); if (!decompiler.Load(filePath, (string)loader)) { return; } decompiler.Project.Programs[0].User.ExtractResources = !pArgs.TryGetValue("extract-resources", out var oExtractResources) || ((string)oExtractResources != "no" && (string)oExtractResources != "false"); if (pArgs.TryGetValue("heuristics", out var oHeur)) { decompiler.Project.Programs[0].User.Heuristics = ((string[])oHeur).ToSortedSet(); } if (pArgs.TryGetValue("metadata", out var oMetadata)) { decompiler.Project.MetadataFiles.Add(new MetadataFile { Filename = (string)oMetadata }); } if (pArgs.ContainsKey("dasm-address")) { decompiler.Project.Programs[0].User.ShowAddressesInDisassembly = true; } if (pArgs.ContainsKey("dasm-bytes")) { decompiler.Project.Programs[0].User.ShowBytesInDisassembly = true; } if (pArgs.TryGetValue("aggressive-branch-removal", out object oAggressiveBranchRemoval)) { decompiler.Project.Programs[0].User.AggressiveBranchRemoval = oAggressiveBranchRemoval is bool flag && flag; } if (pArgs.TryGetValue("debug-types", out var oProcRange)) { decompiler.Project.Programs[0].DebugProcedureRange = ((int, int))oProcRange; } if (pArgs.TryGetValue("debug-trace-proc", out object oTraceProcs)) { decompiler.Project.Programs[0].User.DebugTraceProcedures = (HashSet <string>)oTraceProcs; } decompiler.ExtractResources(); decompiler.ScanPrograms(); if (!pArgs.ContainsKey("scan-only")) { decompiler.AnalyzeDataFlow(); decompiler.ReconstructTypes(); decompiler.StructureProgram(); decompiler.WriteDecompilerProducts(); } } catch (Exception ex) { listener.Error(ex, "An error occurred during decompilation."); } }
private void Decompile(Dictionary <string, object> pArgs) { pArgs.TryGetValue("--loader", out object imgLoader); var addrLoad = ParseAddress(pArgs, "--base"); try { var fileName = (string)pArgs["filename"]; var filePath = Path.GetFullPath(fileName); var imageLocation = ImageLocation.FromUri(filePath); var loadedImage = ldr.Load(imageLocation, (string)imgLoader, addrLoad); Project project; switch (loadedImage) { case Program loadedProgram: project = Project.FromSingleProgram(loadedProgram); break; case Project loadedProject: project = loadedProject; break; default: this.listener.Error("Cannot decompile {0}.", fileName); return; } var decompiler = new Decompiler(project, services); dcSvc.Decompiler = decompiler; var program = decompiler.Project.Programs[0]; program.User.ExtractResources = ShouldExtractResources(program, pArgs); if (pArgs.TryGetValue("heuristics", out var oHeur)) { decompiler.Project.Programs[0].User.Heuristics = ((string[])oHeur).ToSortedSet(); } if (pArgs.TryGetValue("metadata", out var oMetadata)) { decompiler.Project.MetadataFiles.Add(new MetadataFile { Location = ImageLocation.FromUri((string)oMetadata) }); } if (pArgs.ContainsKey("dasm-address")) { decompiler.Project.Programs[0].User.ShowAddressesInDisassembly = true; } if (pArgs.ContainsKey("dasm-bytes")) { decompiler.Project.Programs[0].User.ShowBytesInDisassembly = true; } if (pArgs.TryGetValue("aggressive-branch-removal", out object oAggressiveBranchRemoval)) { decompiler.Project.Programs[0].User.AggressiveBranchRemoval = oAggressiveBranchRemoval is bool flag && flag; } if (pArgs.TryGetValue("debug-types", out var oProcRange)) { decompiler.Project.Programs[0].DebugProcedureRange = ((int, int))oProcRange; } if (pArgs.TryGetValue("debug-trace-proc", out object oTraceProcs)) { decompiler.Project.Programs[0].User.DebugTraceProcedures = (HashSet <string>)oTraceProcs; } decompiler.ExtractResources(); decompiler.ScanPrograms(); if (!pArgs.ContainsKey("scan-only")) { decompiler.AnalyzeDataFlow(); decompiler.ReconstructTypes(); decompiler.StructureProgram(); decompiler.WriteDecompilerProducts(); } } catch (Exception ex) { listener.Error(ex, "An error occurred during decompilation."); } }