void App_Startup(object sender, StartupEventArgs e) { (Application.Current as App).PropertyChanged += App_PropertyChanged; Phlib.InitializePhLib(); // Load singleton for binary caching BinaryCache.InitializeBinaryCache(Dependencies.BinaryCacheOption.GetGlobalBehaviour() == Dependencies.BinaryCacheOption.BinaryCacheOptionValue.Yes); // https://www.red-gate.com/simple-talk/blogs/wpf-menu-displays-to-the-left-of-the-window/ SetDropDownMenuToBeRightAligned(); mainWindow = new MainWindow(); mainWindow.IsMaster = true; switch (Phlib.GetClrPhArch()) { case CLRPH_ARCH.x86: mainWindow.Title = "Dependencies (x86)"; break; case CLRPH_ARCH.x64: mainWindow.Title = "Dependencies (x64)"; break; case CLRPH_ARCH.WOW64: mainWindow.Title = "Dependencies (WoW64)"; break; } mainWindow.Show(); // Process command line args if (e.Args.Length > 0) { mainWindow.OpenNewDependencyWindow(e.Args[0]); } }
static void Main(string[] args) { // always the first call to make Phlib.InitializePhLib(); int recursion_depth = 0; bool early_exit = false; bool show_help = false; bool export_as_json = false; bool use_bin_cache = false; DumpCommand command = null; OptionSet opts = new OptionSet() { { "h|help", "show this message and exit", v => show_help = v != null }, { "json", "Export results in json format", v => export_as_json = v != null }, { "cache", "load and use binary cache to prevent dll file locking", v => use_bin_cache = v != null }, { "d|depth=", "limit recursion depth when analysing loaded modules or dependency chain. Default value is infinite", (int v) => recursion_depth = v }, { "knowndll", "List all known dlls", v => { DumpKnownDlls(GetObjectPrinter(export_as_json)); early_exit = true; } }, { "apisets", "List apisets redirections", v => { DumpApiSets(GetObjectPrinter(export_as_json)); early_exit = true; } }, { "apisetsdll", "List apisets redirections from apisetschema <FILE>", v => command = DumpApiSets }, { "manifest", "show manifest information embedded in <FILE>", v => command = DumpManifest }, { "sxsentries", "dump all of <FILE>'s sxs dependencies", v => command = DumpSxsEntries }, { "imports", "dump <FILE> imports", v => command = DumpImports }, { "exports", "dump <FILE> exports", v => command = DumpExports }, { "assemblyrefs", "dump <FILE> assemblyrefs", v => command = DumpAssemblyReferences }, { "modulerefs", "dump <FILE> modulerefs", v => command = DumpModuleReferences }, { "chain", "dump <FILE> whole dependency chain", v => command = DumpDependencyChain }, { "modules", "dump <FILE> resolved modules", v => command = DumpModules }, }; List <string> eps = opts.Parse(args); if (early_exit) { return; } if ((show_help) || (args.Length == 0) || (command == null)) { DumpUsage(); return; } BinaryCache.InitializeBinaryCache(use_bin_cache); if (eps.Count == 0) { Console.Error.WriteLine("[x] Command {0:s} needs to have a PE <FILE> argument", command.Method.Name); Console.Error.WriteLine(""); DumpUsage(); return; } String FileName = eps[0]; if (!NativeFile.Exists(FileName)) { Console.Error.WriteLine("[x] Could not find file {0:s} on disk", FileName); return; } Debug.WriteLine("[-] Loading file {0:s} ", FileName); PE Pe = new PE(FileName); if (!Pe.Load()) { Console.Error.WriteLine("[x] Could not load file {0:s} as a PE", FileName); return; } command(Pe, GetObjectPrinter(export_as_json), recursion_depth); }