using System.Diagnostics;
using System.Runtime.InteropServices;
static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, IntPtr lpBuffer, uint nSize, out uint lpNumberOfBytesRead);
public unsafe static void Main(string[] args) {
IntPtr pAgeAddress = new IntPtr(&myAge), pResultAge;
pResultAge = Marshal.AllocHGlobal(4);
if ( !ReadProcessMemory(Process.GetCurrentProcess().Handle, pAgeAddress, pResultAge, 4, out reads) ) {
Console.WriteLine("메모리 읽기 실패!");
Console.WriteLine("메모리 읽기 성공!");
Console.WriteLine("myAge 변수의 값: {0}", myAge);
Console.WriteLine("pResultAge 변수가 가리키는 주소의 값: {0}", *(int *)pResultAge.ToPointer());
Console.WriteLine("pResultAge 변수가 가리키는 주소의 값: {0}", Marshal.ReadInt32(pResultAge));
Marshal.FreeHGlobal(pResultAge);