Example #1
0
 public SourceCodeProvider(MetadataProvider metadataProvider, SourceDocumentProvider sourceDocumentProvider)
 {
     this.metadataProvider       = metadataProvider;
     this.sourceDocumentProvider = sourceDocumentProvider;
 }
Example #2
0
        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))
                {
#if DEBUG
                    Console.Error.WriteLine($"Trying to jit methods in module '{jitDasmOptions.LoadModule}' but JitDasm is a debug build, not a release build!");
#endif
                    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);
            }
        }