Skip to content

Commit b3d6f88

Browse files
committed
Refactor: use majorCommand property in CmdLineDriver.cs
1 parent 82df5b1 commit b3d6f88

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/Drivers/CmdLine/CmdLineDriver.cs

+17-14
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void Execute(string[] args)
9090
if (pArgs is null)
9191
return;
9292

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

@@ -227,7 +227,7 @@ private void Decompile(Dictionary<string, object> pArgs)
227227
}
228228
decompiler.ExtractResources();
229229
decompiler.ScanPrograms();
230-
if (!pArgs.ContainsKey("disassemble"))
230+
if ((string)pArgs["majorCommand"] != "disassemble")
231231
{
232232
decompiler.AnalyzeDataFlow();
233233
decompiler.ReconstructTypes();
@@ -360,17 +360,17 @@ private void DecompileRawImage(Dictionary<string, object> pArgs)
360360
var state = CreateInitialState(arch, program.SegmentMap, pArgs);
361361
if (pArgs.TryGetValue("heuristics", out object oHeur))
362362
{
363-
decompiler.Project.Programs[0].User.Heuristics = ((string[]) oHeur).ToSortedSet();
363+
program.User.Heuristics = ((string[]) oHeur).ToSortedSet();
364364
}
365365
if (pArgs.TryGetValue("aggressive-branch-removal", out object oAggressiveBranchRemoval))
366366
{
367367
if (oAggressiveBranchRemoval is bool flag && flag)
368368
{
369-
decompiler.Project.Programs[0].User.Heuristics.Add("aggressive-branch-removal");
369+
program.User.Heuristics.Add("aggressive-branch-removal");
370370
}
371371
}
372372
decompiler.ScanPrograms();
373-
if (!pArgs.ContainsKey("scan-only"))
373+
if ((string) pArgs["majorCommand"] != "disassemble")
374374
{
375375
decompiler.AnalyzeDataFlow();
376376
decompiler.ReconstructTypes();
@@ -412,9 +412,11 @@ private static ProcessorState CreateInitialState(IProcessorArchitecture arch, Se
412412
foreach (var regValue in regs.Where(r => !string.IsNullOrEmpty(r)))
413413
{
414414
var rr = regValue.Split(':');
415-
if (rr == null || rr.Length != 2)
415+
if (rr is null || rr.Length != 2)
416416
continue;
417417
var reg = arch.GetRegister(rr[0]);
418+
if (reg is null)
419+
continue;
418420
state.SetRegister(reg, Constant.Create(reg.DataType, Convert.ToInt64(rr[1], 16)));
419421
}
420422
return state;
@@ -429,22 +431,24 @@ private Dictionary<string,object> ProcessArguments(TextWriter w, string[] args)
429431
}
430432
var parsedArgs = new Dictionary<string, object>();
431433

432-
// Eat major commands
434+
// Eat major commands. The default major command is
435+
// "decompile".
436+
parsedArgs["majorCommand"] = "decompile";
433437
int i = 0;
434438
switch (args[0])
435439
{
436440
case "asm":
437441
case "assemble":
438-
parsedArgs["assemble"] = true;
442+
parsedArgs["majorCommand"] = "assemble";
439443
++i;
440444
break;
441445
case "decompile":
442-
parsedArgs["decompile"] = true;
446+
parsedArgs["majorCommand"] = "decompile";
443447
++i;
444448
break;
445449
case "dasm":
446450
case "disassemble":
447-
parsedArgs["disassemble"] = true;
451+
parsedArgs["majorCommand"] = "disassemble";
448452
++i;
449453
break;
450454
}
@@ -574,7 +578,8 @@ private Dictionary<string,object> ProcessArguments(TextWriter w, string[] args)
574578
}
575579
else if (args[i] == "--scan-only")
576580
{
577-
parsedArgs["disassemble"] = true;
581+
//$TODO: deprecate this command
582+
parsedArgs["majorCommand"] = "disassemble";
578583
}
579584
else if (args[i] == "--extract-resources")
580585
{
@@ -672,7 +677,7 @@ private static void ShowVersion(TextWriter w)
672677
if (attrs.Length < 1)
673678
return;
674679
var attr = (AssemblyFileVersionAttribute)attrs[0];
675-
w.Write("Decompile.exe version {0}", attr.Version);
680+
w.Write("Reko decompiler version {0}", attr.Version);
676681
var githashAttr = typeof(AssemblyMetadata).Assembly.GetCustomAttributes<AssemblyMetadataAttribute>()
677682
.FirstOrDefault(a => a.Key == "GitHash");
678683
if (githashAttr != null)
@@ -721,8 +726,6 @@ private void Usage(TextWriter w)
721726
w.WriteLine(" calls-respect-abi Assume procedure calls respect the platform ABI");
722727
w.WriteLine(" --aggressive-branch-removal Be more aggressive in removing unused branches");
723728
w.WriteLine(" --metadata <filename> Use the file <filename> as a source of metadata");
724-
w.WriteLine(" --scan-only Only scans the binary to find instructions, forgoing");
725-
w.WriteLine(" full decompilation.");
726729
w.WriteLine(" --time-limit <s> Limit execution time to s seconds");
727730
w.WriteLine(" --debug-trace-proc <p1>[,<p2>...] Debug: trace Reko analysis phases of the");
728731
w.WriteLine(" given procedure names p1, p2 etc.");

0 commit comments

Comments
 (0)