Browse Source

Changed to use a type switch and using the InstructionOutputExtensions.WriteTo() method to display decoded signature

pull/1991/head
Andrew Au 5 years ago
parent
commit
ad1d22222e
  1. 28
      ILSpy.ReadyToRun/ReadyToRunLanguage.cs

28
ILSpy.ReadyToRun/ReadyToRunLanguage.cs

@ -27,6 +27,7 @@ using System.Reflection.PortableExecutable;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using Iced.Intel; using Iced.Intel;
using ICSharpCode.Decompiler; using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.IL;
using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.Solution; using ICSharpCode.Decompiler.Solution;
using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.TypeSystem;
@ -85,7 +86,7 @@ namespace ICSharpCode.ILSpy.ReadyToRun
if (cacheEntry.methodMap.TryGetValue(method.MetadataToken, out var methods)) { if (cacheEntry.methodMap.TryGetValue(method.MetadataToken, out var methods)) {
foreach (var readyToRunMethod in methods) { foreach (var readyToRunMethod in methods) {
foreach (RuntimeFunction runtimeFunction in readyToRunMethod.RuntimeFunctions) { foreach (RuntimeFunction runtimeFunction in readyToRunMethod.RuntimeFunctions) {
Disassemble(method, output, reader, readyToRunMethod, runtimeFunction, bitness, (ulong)runtimeFunction.StartAddress); Disassemble(method.ParentModule.PEFile, output, reader, readyToRunMethod, runtimeFunction, bitness, (ulong)runtimeFunction.StartAddress);
} }
} }
} }
@ -97,7 +98,7 @@ namespace ICSharpCode.ILSpy.ReadyToRun
output.WriteLine("; " + comment); output.WriteLine("; " + comment);
} }
private void Disassemble(IMethod method, ITextOutput output, ReadyToRunReader reader, ReadyToRunMethod readyToRunMethod, RuntimeFunction runtimeFunction, int bitness, ulong address) private void Disassemble(PEFile currentFile, ITextOutput output, ReadyToRunReader reader, ReadyToRunMethod readyToRunMethod, RuntimeFunction runtimeFunction, int bitness, ulong address)
{ {
WriteCommentLine(output, readyToRunMethod.SignatureString); WriteCommentLine(output, readyToRunMethod.SignatureString);
byte[] codeBytes = new byte[runtimeFunction.Size]; byte[] codeBytes = new byte[runtimeFunction.Size];
@ -157,17 +158,18 @@ namespace ICSharpCode.ILSpy.ReadyToRun
if (instr.IsCallNearIndirect && reader.ImportCellNames.ContainsKey(importCellAddress)) { if (instr.IsCallNearIndirect && reader.ImportCellNames.ContainsKey(importCellAddress)) {
output.Write(" ;"); output.Write(" ;");
ReadyToRunSignature signature = reader.ImportSignatures[(int)instr.IPRelativeMemoryAddress]; ReadyToRunSignature signature = reader.ImportSignatures[(int)instr.IPRelativeMemoryAddress];
string formattedSignatureString = reader.ImportCellNames[importCellAddress]; switch(signature) {
MethodDefEntrySignature methodDefSignature = signature as MethodDefEntrySignature; case MethodDefEntrySignature methodDefSignature:
MethodRefEntrySignature methodRefSignature = signature as MethodRefEntrySignature; int methodDefToken = unchecked((int)methodDefSignature.MethodDefToken);
if (methodDefSignature != null) { InstructionOutputExtensions.WriteTo((EntityHandle)MetadataTokens.Handle(methodDefToken), currentFile, output, null);
int methodDefToken = unchecked((int)methodDefSignature.MethodDefToken); break;
output.WriteReference(method.ParentModule.PEFile, MetadataTokens.Handle(methodDefToken), formattedSignatureString); case MethodRefEntrySignature methodRefSignature:
} else if (methodRefSignature != null) { int methodRefToken = unchecked((int)methodRefSignature.MethodRefToken);
int methodRefToken = unchecked((int)methodRefSignature.MethodRefToken); InstructionOutputExtensions.WriteTo((EntityHandle)MetadataTokens.Handle(methodRefToken), currentFile, output, null);
output.WriteReference(method.ParentModule.PEFile, MetadataTokens.Handle(methodRefToken), formattedSignatureString); break;
} else { default:
output.WriteLine(formattedSignatureString); output.WriteLine(reader.ImportCellNames[importCellAddress]);
break;
} }
output.WriteLine(); output.WriteLine();
} else { } else {

Loading…
Cancel
Save