Imports System.Diagnostics
Imports System.Runtime.InteropServices
Shared Function ReadProcessMemory(hProcess As IntPtr, lpBaseAddress As IntPtr, lpBuffer As IntPtr, nSize As UInteger, ByRef lpNumberOfBytesRead As UInteger) As Boolean
Public Shared Sub Main(args As String())
Dim myAge As Integer = 23
Dim pAgeAddress, pResultAge As IntPtr
pAgeAddress = Marshal.AllocHGlobal(4)
pResultAge = Marshal.AllocHGlobal(4)
Marshal.StructureToPtr(myAge, pAgeAddress, False)
If Not ReadProcessMemory(Process.GetCurrentProcess().Handle, pAgeAddress, pResultAge, 4, reads) Then
Console.WriteLine("메모리 읽기 실패!")
Console.WriteLine("메모리 읽기 성공!")
Console.WriteLine("myAge 변수의 값: {0}", myAge)
Console.WriteLine("pResultAge 변수가 가리키는 주소의 값: {0}", Marshal.ReadInt32(pResultAge))
Marshal.FreeHGlobal(pResultAge)