Browse Source

Upgrade ready to run binary

pull/1968/head
Andrew Au 5 years ago
parent
commit
732962fd08
  1. 2
      ILSpy.ReadyToRun/ILSpy.ReadyToRun.csproj
  2. 23
      ILSpy.ReadyToRun/ReadyToRunLanguage.cs

2
ILSpy.ReadyToRun/ILSpy.ReadyToRun.csproj

@ -57,7 +57,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Iced" Version="1.4.0" /> <PackageReference Include="Iced" Version="1.4.0" />
<PackageReference Include="ILCompiler.Reflection.ReadyToRun" Version="1.0.5-alpha" /> <PackageReference Include="ILCompiler.Reflection.ReadyToRun" Version="1.0.6-alpha" />
</ItemGroup> </ItemGroup>
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" /> <Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" />

23
ILSpy.ReadyToRun/ReadyToRunLanguage.cs

@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System; using System;
using System.Collections.Generic;
using System.ComponentModel.Composition; using System.ComponentModel.Composition;
using System.Diagnostics; using System.Diagnostics;
using System.Reflection.Metadata; using System.Reflection.Metadata;
@ -73,17 +74,13 @@ namespace ICSharpCode.ILSpy.ReadyToRun
Debug.Assert(reader.Machine == Machine.I386); Debug.Assert(reader.Machine == Machine.I386);
bitness = 32; bitness = 32;
} }
foreach (ReadyToRunMethod readyToRunMethod in reader.Methods) { foreach (List<ReadyToRunMethod> readyToRunMethodList in reader.Methods.Values) {
foreach (ReadyToRunMethod readyToRunMethod in readyToRunMethodList) {
if (readyToRunMethod.MethodHandle == method.MetadataToken) { if (readyToRunMethod.MethodHandle == method.MetadataToken) {
// TODO: Indexing // TODO: Indexing
foreach (RuntimeFunction runtimeFunction in readyToRunMethod.RuntimeFunctions) { foreach (RuntimeFunction runtimeFunction in readyToRunMethod.RuntimeFunctions) {
WriteCommentLine(output, readyToRunMethod.SignatureString); Disassemble(output, reader, readyToRunMethod, runtimeFunction, bitness, (ulong)runtimeFunction.StartAddress);
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();
} }
} }
} }
@ -95,8 +92,14 @@ namespace ICSharpCode.ILSpy.ReadyToRun
output.WriteLine("; " + comment); output.WriteLine("; " + comment);
} }
private void Disassemble(ITextOutput output, byte[] codeBytes, int bitness, ulong address) private void Disassemble(ITextOutput output, ReadyToRunReader reader, ReadyToRunMethod readyToRunMethod, RuntimeFunction runtimeFunction, int bitness, ulong address)
{ {
WriteCommentLine(output, readyToRunMethod.SignatureString);
byte[] codeBytes = new byte[runtimeFunction.Size];
for (int i = 0; i < runtimeFunction.Size; i++) {
codeBytes[i] = reader.Image[reader.GetOffset(runtimeFunction.StartAddress) + i];
}
// TODO: Decorate the disassembly with Unwind, GC and debug info // TODO: Decorate the disassembly with Unwind, GC and debug info
var codeReader = new ByteArrayCodeReader(codeBytes); var codeReader = new ByteArrayCodeReader(codeBytes);
var decoder = Decoder.Create(bitness, codeReader); var decoder = Decoder.Create(bitness, codeReader);
@ -120,11 +123,11 @@ namespace ICSharpCode.ILSpy.ReadyToRun
formatter.Options.FirstOperandCharIndex = 10; formatter.Options.FirstOperandCharIndex = 10;
var tempOutput = new StringBuilderFormatterOutput(); var tempOutput = new StringBuilderFormatterOutput();
foreach (var instr in instructions) { foreach (var instr in instructions) {
int byteBaseIndex = (int)(instr.IP - address);
formatter.Format(instr, tempOutput); formatter.Format(instr, tempOutput);
output.Write(instr.IP.ToString("X16")); output.Write(instr.IP.ToString("X16"));
output.Write(" "); output.Write(" ");
int instrLen = instr.ByteLength; int instrLen = instr.ByteLength;
int byteBaseIndex = (int)(instr.IP - address);
for (int i = 0; i < instrLen; i++) for (int i = 0; i < instrLen; i++)
output.Write(codeBytes[byteBaseIndex + i].ToString("X2")); output.Write(codeBytes[byteBaseIndex + i].ToString("X2"));
int missingBytes = 10 - instrLen; int missingBytes = 10 - instrLen;
@ -133,6 +136,7 @@ namespace ICSharpCode.ILSpy.ReadyToRun
output.Write(" "); output.Write(" ");
output.WriteLine(tempOutput.ToStringAndReset()); output.WriteLine(tempOutput.ToStringAndReset());
} }
output.WriteLine();
} }
private ReadyToRunReaderCacheEntry GetReader(LoadedAssembly assembly, PEFile module) private ReadyToRunReaderCacheEntry GetReader(LoadedAssembly assembly, PEFile module)
@ -142,7 +146,6 @@ namespace ICSharpCode.ILSpy.ReadyToRun
if (!readyToRunReaders.TryGetValue(module, out result)) { if (!readyToRunReaders.TryGetValue(module, out result)) {
result = new ReadyToRunReaderCacheEntry(); result = new ReadyToRunReaderCacheEntry();
try { try {
// TODO: avoid eager parsing
result.readyToRunReader = new ReadyToRunReader(new ReadyToRunAssemblyResolver(assembly), module.Metadata, module.Reader, module.FileName); result.readyToRunReader = new ReadyToRunReader(new ReadyToRunAssemblyResolver(assembly), module.Metadata, module.Reader, module.FileName);
if (result.readyToRunReader.Machine != Machine.Amd64 && result.readyToRunReader.Machine != Machine.I386) { if (result.readyToRunReader.Machine != Machine.Amd64 && result.readyToRunReader.Machine != Machine.I386) {
result.failureReason = $"Architecture {result.readyToRunReader.Machine} is not currently supported."; result.failureReason = $"Architecture {result.readyToRunReader.Machine} is not currently supported.";

Loading…
Cancel
Save