--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Reflection.PortableExecutable;
+using System.Runtime.InteropServices;
+
+namespace R2RDump
+{
+ class CoreDisTools
+ {
+ public enum TargetArch
+ {
+ Target_Host, // Target is the same as host architecture
+ Target_X86,
+ Target_X64,
+ Target_Thumb,
+ Target_Arm64
+ };
+
+ [DllImport("coredistools.dll")]
+ [return: MarshalAs(UnmanagedType.I8)]
+ public static extern long InitDisasm(TargetArch Target);
+
+ [DllImport("coredistools.dll")]
+ public static extern void DumpCodeBlock(long Disasm, ulong Address, IntPtr Bytes, int Size);
+
+ [DllImport("coredistools.dll")]
+ public static extern void FinishDisasm(long Disasm);
+
+ public unsafe static void DumpCodeBlock(long Disasm, int Address, int Offset, byte[] image, int Size)
+ {
+ fixed (byte* p = image)
+ {
+ IntPtr ptr = (IntPtr)(p + Offset);
+ DumpCodeBlock(Disasm, (ulong)Address, ptr, Size);
+ }
+ }
+
+ public static long GetDisasm(Machine machine)
+ {
+ TargetArch target = TargetArch.Target_Host;
+ switch (machine)
+ {
+ case Machine.Amd64:
+ target = TargetArch.Target_X64;
+ break;
+ case Machine.I386:
+ target = TargetArch.Target_X86;
+ break;
+ case Machine.Arm64:
+ target = TargetArch.Target_Arm64;
+ break;
+ case Machine.ArmThumb2:
+ target = TargetArch.Target_Thumb;
+ break;
+ }
+ return InitDisasm(target);
+ }
+ }
+}
-using System;
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
using System.Collections.Generic;
using System.Text;
private IReadOnlyList<int> _runtimeFunctions = Array.Empty<int>();
private IReadOnlyList<string> _sections = Array.Empty<string>();
private bool _diff = false;
+ private long _disassembler;
private TextWriter _writer;
private R2RDump()
private void WriteSubDivider()
{
- _writer.WriteLine("------------------");
+ _writer.WriteLine("_______________________________________________");
_writer.WriteLine();
}
/// </summary>
private void DumpRuntimeFunction(R2RReader r2r, RuntimeFunction rtf)
{
- _writer.WriteLine(rtf.ToString());
+ if (_disasm)
+ {
+ _writer.WriteLine($"Id: {rtf.Id}");
+ CoreDisTools.DumpCodeBlock(_disassembler, rtf.StartAddress, r2r.GetOffset(rtf.StartAddress), r2r.Image, rtf.Size);
+ }
+ else
+ {
+ _writer.Write($"{rtf}");
+ }
if (_raw)
{
DumpBytes(r2r, rtf.StartAddress, (uint)rtf.Size);
QueryMethod(r2r, "R2R Methods by Keyword", _keywords, false);
}
- _writer.WriteLine("========================================================");
+ _writer.WriteLine("=============================================================");
_writer.WriteLine();
}
foreach (string filename in _inputFilenames)
{
R2RReader r2r = new R2RReader(filename);
+ if (_disasm)
+ {
+ _disassembler = CoreDisTools.GetDisasm(r2r.Machine);
+ }
+
Dump(r2r);
+
+ if (_disasm)
+ {
+ CoreDisTools.FinishDisasm(_disassembler);
+ }
}
}
catch (Exception e)
</PropertyGroup>
<ItemGroup>
+ <PackageReference Include="Microsoft.NETCore.CoreDisTools" Version="1.0.1-prerelease-00003" />
<PackageReference Include="System.CommandLine" Version="0.1.0-e160119-1" />
+ <PackageReference Include="System.Reflection.Metadata" Version="1.7.0-preview1-26530-04" />
</ItemGroup>
</Project>
TypeDefinitionHandle declaringTypeHandle = _methodDef.GetDeclaringType();
TypeDefinition declaringTypeDef;
- while (!declaringTypeHandle.IsNil)
+ do
{
declaringTypeDef = mdReader.GetTypeDefinition(declaringTypeHandle);
DeclaringType = mdReader.GetString(declaringTypeDef.Name) + "." + DeclaringType;
declaringTypeHandle = declaringTypeDef.GetDeclaringType();
}
-
+ while (!declaringTypeHandle.IsNil);
+
NamespaceDefinitionHandle namespaceHandle = declaringTypeDef.NamespaceDefinition;
while (!namespaceHandle.IsNil)
{
-using System;
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
using System.Collections.Generic;
using System.Text;