Created
March 26, 2022 15:18
-
-
Save kevingosse/6dfcec04499ea20e843fbe967c28be45 to your computer and use it in GitHub Desktop.
Extract native code from dynamic method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Diagnostics.Runtime; | |
using System; | |
using System.Linq; | |
namespace ExtractDynamicMethod | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var target = DataTarget.LoadDump(@"E:\DecompileDynamicMethod.exe_220326_161151.dmp"); | |
var runtime = target.ClrVersions[0].CreateRuntime(); | |
var heap = runtime.Heap; | |
var dynamicMethod = heap.GetProxies("System.Reflection.Emit.DynamicMethod").Single(); | |
var mdToken = (ulong)dynamicMethod.m_methodHandle.m_value.m_handle; | |
var method = runtime.GetMethodByHandle(mdToken); | |
Console.WriteLine($"Native code address: {method.NativeCode:x2}"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment