public static void Main(string[] args) { PrintAbout(); bool pauseOnExit = true; var consoleLogger = new FilteredLogger(new ConsoleLogger()); var counter = new LogCounter(); var loggers = new LoggerCollection { consoleLogger, counter }; FileOutputLogger fileLogger = null; var parser = new CommandLineParser(); foreach (var @switch in CommandLineSwitches.AllSwitches) { parser.AddSwitch(@switch); } try { var result = parser.Parse(args); if (result.Flags.Contains(CommandLineSwitches.EnableTroublenoobing)) { throw new DevirtualisationException("Magikarp uses Splash! It was not very effective..."); } pauseOnExit = !result.Flags.Contains(CommandLineSwitches.NoPause); if (result.Flags.Contains(CommandLineSwitches.Help)) { PrintHelp(); } else { consoleLogger.IncludeDebug = result.Flags.Contains(CommandLineSwitches.VerboseOutput) || result.Flags.Contains(CommandLineSwitches.VeryVerboseOutput); consoleLogger.IncludeDebug2 = result.Flags.Contains(CommandLineSwitches.VeryVerboseOutput); var options = GetDevirtualisationOptions(result); options.OutputOptions.EnsureDirectoriesExist(); if (result.Flags.Contains(CommandLineSwitches.OutputLogFile)) { fileLogger = new FileOutputLogger(Path.Combine(options.OutputOptions.RootDirectory, "report.log")); loggers.Add(fileLogger); } if (result.Flags.Contains(CommandLineSwitches.SalvageData)) { loggers.Warning(Tag, "Salvage mode is enabled. Output files might not be an accurate representation of the original binary."); } var devirtualiser = new Devirtualiser(loggers); devirtualiser.Devirtualise(options); } } catch (CommandLineParseException ex) { consoleLogger.Error(Tag, ex.Message); consoleLogger.Log(Tag, "Use -h for help."); } catch (Exception ex) when(!Debugger.IsAttached) { consoleLogger.Error(Tag, "Something went wrong! Try the latest version or report a bug at the repository."); if (consoleLogger.IncludeDebug) { loggers.Error(Tag, ex.ToString()); } else { PrintExceptions(new LoggerCollection { consoleLogger, counter }, new[] { ex }); fileLogger?.Error(Tag, ex.ToString()); consoleLogger.Error(Tag, "Use --verbose or inspect the full report.log using --log-file for more details."); } } finally { loggers.Log(Tag, $"Process finished with {counter.Warnings} warnings and {counter.Errors} errors."); fileLogger?.Dispose(); } if (pauseOnExit) { Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } }