Skip to content

Commit

Permalink
Refactor: use majorCommand property in CmdLineDriver.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
uxmal committed Mar 12, 2023
1 parent 82df5b1 commit b3d6f88
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/Drivers/CmdLine/CmdLineDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void Execute(string[] args)
if (pArgs is null)
return;

if(pArgs.TryGetValue("--locale", out var localeName)){
if (pArgs.TryGetValue("--locale", out var localeName)){
Thread.CurrentThread.CurrentUICulture = new CultureInfo((string)localeName);
}

Expand Down Expand Up @@ -227,7 +227,7 @@ private void Decompile(Dictionary<string, object> pArgs)
}
decompiler.ExtractResources();
decompiler.ScanPrograms();
if (!pArgs.ContainsKey("disassemble"))
if ((string)pArgs["majorCommand"] != "disassemble")
{
decompiler.AnalyzeDataFlow();
decompiler.ReconstructTypes();
Expand Down Expand Up @@ -360,17 +360,17 @@ private void DecompileRawImage(Dictionary<string, object> pArgs)
var state = CreateInitialState(arch, program.SegmentMap, pArgs);
if (pArgs.TryGetValue("heuristics", out object oHeur))
{
decompiler.Project.Programs[0].User.Heuristics = ((string[]) oHeur).ToSortedSet();
program.User.Heuristics = ((string[]) oHeur).ToSortedSet();
}
if (pArgs.TryGetValue("aggressive-branch-removal", out object oAggressiveBranchRemoval))
{
if (oAggressiveBranchRemoval is bool flag && flag)
{
decompiler.Project.Programs[0].User.Heuristics.Add("aggressive-branch-removal");
program.User.Heuristics.Add("aggressive-branch-removal");
}
}
decompiler.ScanPrograms();
if (!pArgs.ContainsKey("scan-only"))
if ((string) pArgs["majorCommand"] != "disassemble")
{
decompiler.AnalyzeDataFlow();
decompiler.ReconstructTypes();
Expand Down Expand Up @@ -412,9 +412,11 @@ private static ProcessorState CreateInitialState(IProcessorArchitecture arch, Se
foreach (var regValue in regs.Where(r => !string.IsNullOrEmpty(r)))
{
var rr = regValue.Split(':');
if (rr == null || rr.Length != 2)
if (rr is null || rr.Length != 2)
continue;
var reg = arch.GetRegister(rr[0]);
if (reg is null)
continue;
state.SetRegister(reg, Constant.Create(reg.DataType, Convert.ToInt64(rr[1], 16)));
}
return state;
Expand All @@ -429,22 +431,24 @@ private static ProcessorState CreateInitialState(IProcessorArchitecture arch, Se
}
var parsedArgs = new Dictionary<string, object>();

// Eat major commands
// Eat major commands. The default major command is
// "decompile".
parsedArgs["majorCommand"] = "decompile";
int i = 0;
switch (args[0])
{
case "asm":
case "assemble":
parsedArgs["assemble"] = true;
parsedArgs["majorCommand"] = "assemble";
++i;
break;
case "decompile":
parsedArgs["decompile"] = true;
parsedArgs["majorCommand"] = "decompile";
++i;
break;
case "dasm":
case "disassemble":
parsedArgs["disassemble"] = true;
parsedArgs["majorCommand"] = "disassemble";
++i;
break;
}
Expand Down Expand Up @@ -574,7 +578,8 @@ private static ProcessorState CreateInitialState(IProcessorArchitecture arch, Se
}
else if (args[i] == "--scan-only")
{
parsedArgs["disassemble"] = true;
//$TODO: deprecate this command
parsedArgs["majorCommand"] = "disassemble";
}
else if (args[i] == "--extract-resources")
{
Expand Down Expand Up @@ -672,7 +677,7 @@ private static void ShowVersion(TextWriter w)
if (attrs.Length < 1)
return;
var attr = (AssemblyFileVersionAttribute)attrs[0];
w.Write("Decompile.exe version {0}", attr.Version);
w.Write("Reko decompiler version {0}", attr.Version);
var githashAttr = typeof(AssemblyMetadata).Assembly.GetCustomAttributes<AssemblyMetadataAttribute>()
.FirstOrDefault(a => a.Key == "GitHash");
if (githashAttr != null)
Expand Down Expand Up @@ -721,8 +726,6 @@ private void Usage(TextWriter w)
w.WriteLine(" calls-respect-abi Assume procedure calls respect the platform ABI");
w.WriteLine(" --aggressive-branch-removal Be more aggressive in removing unused branches");
w.WriteLine(" --metadata <filename> Use the file <filename> as a source of metadata");
w.WriteLine(" --scan-only Only scans the binary to find instructions, forgoing");
w.WriteLine(" full decompilation.");
w.WriteLine(" --time-limit <s> Limit execution time to s seconds");
w.WriteLine(" --debug-trace-proc <p1>[,<p2>...] Debug: trace Reko analysis phases of the");
w.WriteLine(" given procedure names p1, p2 etc.");
Expand Down

0 comments on commit b3d6f88

Please sign in to comment.