public AssemblyTreeNode FindAssemblyNode(PEFile module) { if (module == null) { return(null); } return(FindAssemblyNode(module.GetLoadedAssembly())); }
public override void DecompileMethod(IMethod method, ITextOutput output, DecompilationOptions options) { PEFile module = method.ParentModule.PEFile; ReadyToRunReaderCacheEntry cacheEntry = GetReader(module.GetLoadedAssembly(), module); if (cacheEntry.readyToRunReader == null) { WriteCommentLine(output, cacheEntry.failureReason); } else { ReadyToRunReader reader = cacheEntry.readyToRunReader; int bitness = -1; if (reader.Machine == Machine.Amd64) { bitness = 64; } else { Debug.Assert(reader.Machine == Machine.I386); bitness = 32; } if (cacheEntry.methodMap == null) { cacheEntry.methodMap = reader.Methods.ToList() .GroupBy(m => m.MethodHandle) .ToDictionary(g => g.Key, g => g.ToArray()); } bool showMetadataTokens = ILSpy.Options.DisplaySettingsPanel.CurrentDisplaySettings.ShowMetadataTokens; bool showMetadataTokensInBase10 = ILSpy.Options.DisplaySettingsPanel.CurrentDisplaySettings.ShowMetadataTokensInBase10; #if STRESS ITextOutput originalOutput = output; output = new DummyOutput(); { foreach (var readyToRunMethod in reader.Methods) { #else if (cacheEntry.methodMap.TryGetValue(method.MetadataToken, out var methods)) { foreach (var readyToRunMethod in methods) { #endif foreach (RuntimeFunction runtimeFunction in readyToRunMethod.RuntimeFunctions) { new ReadyToRunDisassembler(output, reader, runtimeFunction).Disassemble(method.ParentModule.PEFile, bitness, (ulong)runtimeFunction.StartAddress, showMetadataTokens, showMetadataTokensInBase10); } } } #if STRESS output = originalOutput; output.WriteLine("Passed"); #endif } }
public override void DecompileMethod(IMethod method, ITextOutput output, DecompilationOptions options) { PEFile module = method.ParentModule.PEFile; R2RReaderCacheEntry r2rReaderCacheEntry = GetReader(module.GetLoadedAssembly(), module); if (r2rReaderCacheEntry.r2rReader == null) { WriteCommentLine(output, r2rReaderCacheEntry.failureReason); } else { R2RReader reader = r2rReaderCacheEntry.r2rReader; int bitness = -1; if (reader.Machine == Machine.Amd64) { bitness = 64; } else { Debug.Assert(reader.Machine == Machine.I386); bitness = 32; } foreach (var m in reader.R2RMethods) { if (m.MethodHandle == method.MetadataToken) { // TODO: Indexing foreach (RuntimeFunction runtimeFunction in m.RuntimeFunctions) { WriteCommentLine(output, m.SignatureString); byte[] code = new byte[runtimeFunction.Size]; for (int i = 0; i < runtimeFunction.Size; i++) { code[i] = reader.Image[reader.GetOffset(runtimeFunction.StartAddress) + i]; } Disassemble(output, code, bitness, (ulong)runtimeFunction.StartAddress); output.WriteLine(); } } } } }
public override void DecompileMethod(IMethod method, ITextOutput output, DecompilationOptions options) { PEFile module = method.ParentModule.PEFile; ReadyToRunReaderCacheEntry cacheEntry = GetReader(module.GetLoadedAssembly(), module); if (cacheEntry.readyToRunReader == null) { WriteCommentLine(output, cacheEntry.failureReason); } else { ReadyToRunReader reader = cacheEntry.readyToRunReader; int bitness = -1; if (reader.Machine == Machine.Amd64) { bitness = 64; } else { Debug.Assert(reader.Machine == Machine.I386); bitness = 32; } if (cacheEntry.methodMap == null) { cacheEntry.methodMap = reader.Methods.Values .SelectMany(m => m) .GroupBy(m => m.MethodHandle) .ToDictionary(g => g.Key, g => g.ToArray()); } if (cacheEntry.methodMap.TryGetValue(method.MetadataToken, out var methods)) { foreach (var readyToRunMethod in methods) { foreach (RuntimeFunction runtimeFunction in readyToRunMethod.RuntimeFunctions) { Disassemble(output, reader, readyToRunMethod, runtimeFunction, bitness, (ulong)runtimeFunction.StartAddress); } } } } }