public Disassembler(int bitness, string commentPrefix, SourceCodeProvider sourceCodeProvider, KnownSymbols knownSymbols, DisassemblerOptions disassemblerOptions) { this.bitness = bitness; this.commentPrefix = commentPrefix; this.sourceCodeProvider = sourceCodeProvider; if (bitness == 64) { diffableSymAddrLo = DIFFABLE_SYM_ADDR64_LO; diffableSymAddrHi = DIFFABLE_SYM_ADDR64_HI; } else { diffableSymAddrLo = DIFFABLE_SYM_ADDR32_LO; diffableSymAddrHi = DIFFABLE_SYM_ADDR32_HI; } targets = new Dictionary <ulong, AddressInfo>(); sortedTargets = new List <KeyValuePair <ulong, AddressInfo> >(); formatterOutput = new FormatterOutputImpl(); charBuf = new char[100]; this.knownSymbols = knownSymbols; this.disassemblerOptions = disassemblerOptions; if ((disassemblerOptions & DisassemblerOptions.Diffable) != 0) { this.disassemblerOptions = (disassemblerOptions & ~(DisassemblerOptions.ShowAddresses | DisassemblerOptions.ShowHexBytes)); } }
static int Main(string[] args) { try { switch (System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture) { case System.Runtime.InteropServices.Architecture.X64: case System.Runtime.InteropServices.Architecture.X86: break; default: throw new ApplicationException($"Unsupported CPU arch: {System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture}"); } var jitDasmOptions = CommandLineParser.Parse(args); if (!string2.IsNullOrEmpty(jitDasmOptions.LoadModule)) { MethodJitter.JitMethods(jitDasmOptions.LoadModule, jitDasmOptions.TypeFilter, jitDasmOptions.MethodFilter, jitDasmOptions.RunClassConstructors, jitDasmOptions.AssemblySearchPaths); } var(bitness, methods, knownSymbols) = GetMethodsToDisassemble(jitDasmOptions.Pid, jitDasmOptions.ModuleName, jitDasmOptions.TypeFilter, jitDasmOptions.MethodFilter, jitDasmOptions.HeapSearch); var jobs = GetJobs(methods, jitDasmOptions.OutputDir, jitDasmOptions.FileOutputKind, jitDasmOptions.FilenameFormat, out var baseDir); if (!string2.IsNullOrEmpty(baseDir)) { Directory.CreateDirectory(baseDir); } var sourceDocumentProvider = new SourceDocumentProvider(); using (var mdProvider = new MetadataProvider()) { var sourceCodeProvider = new SourceCodeProvider(mdProvider, sourceDocumentProvider); using (var context = new DisasmJobContext(bitness, knownSymbols, sourceCodeProvider, jitDasmOptions.DisassemblerOutputKind, jitDasmOptions.Diffable, jitDasmOptions.ShowAddresses, jitDasmOptions.ShowHexBytes, jitDasmOptions.ShowSourceCode)) { foreach (var job in jobs) { Disassemble(context, job); } } } return(0); } catch (ShowCommandLineHelpException) { CommandLineParser.ShowHelp(); return(1); } catch (CommandLineParserException ex) { Console.WriteLine(ex.Message); return(1); } catch (ApplicationException ex) { Console.WriteLine(ex.Message); return(1); } catch (ClrDiagnosticsException ex) { Console.WriteLine(ex.Message); Console.WriteLine("Make sure this process has the same bitness as the target process"); return(1); } catch (Exception ex) { Console.WriteLine(ex.ToString()); return(1); } }