Skip to content

Instantly share code, notes, and snippets.

@kevingosse
Created March 26, 2022 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevingosse/6dfcec04499ea20e843fbe967c28be45 to your computer and use it in GitHub Desktop.
Save kevingosse/6dfcec04499ea20e843fbe967c28be45 to your computer and use it in GitHub Desktop.
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