Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Extract native code from dynamic method
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