Skip to content

Instantly share code, notes, and snippets.

@gavz
Forked from xpn/ReadGadget.cs
Created December 25, 2023 23:06
Show Gist options
  • Select an option

  • Save gavz/29a6efe3c7e4082d3fc579681ed3a190 to your computer and use it in GitHub Desktop.

Select an option

Save gavz/29a6efe3c7e4082d3fc579681ed3a190 to your computer and use it in GitHub Desktop.
using System;
using System.Reflection;
using System.Runtime.InteropServices;
namespace NautilusProject
{
public class ReadGadget
{
public static IntPtr ReadMemory(IntPtr addr)
{
var stubHelper = typeof(System.String).Assembly.GetType("System.StubHelpers.StubHelpers");
var GetNDirectTarget = stubHelper.GetMethod("GetNDirectTarget", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
// Spray away
IntPtr unmanagedPtr = Marshal.AllocHGlobal(200);
for (int i = 0; i < 200; i += IntPtr.Size)
{
Marshal.Copy(new[] { addr }, 0, unmanagedPtr + i, 1);
}
return (IntPtr)GetNDirectTarget.Invoke(null, new object[] { unmanagedPtr });
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment