您好,登錄后才能下訂單哦!
網上好多關于ReadprocessMemory、WriteprocessMemory使用方法的貼子都不能用,下面是本人親自測過可用的,望對大家有用。
''' <summary>
''' 讀取內存地址
''' </summary>
''' <param name="hProcess">進程句柄</param>
''' <param name="lpBaseAddress">內存地址</param>
''' <param name="lpBuffer">數據存儲變量</param>
''' <param name="nSize">長度sizeof(lpBuffer)</param>
''' <param name="lpNumberOfBytesRead">讀取長度</param>
''' <returns></returns>
''' <remarks></remarks>
Declare Function ReadProcessMemory Lib "kernel32.dll" (ByVal hProcess As Integer, ByVal lpBaseAddress As IntPtr, ByVal lpBuffer As IntPtr, ByVal nSize As Integer, ByRef lpNumberOfBytesRead As Integer) As Boolean
''' <summary>
''' 寫入內存地址
''' </summary>
''' <param name="hProcess">進程句柄</param>
''' <param name="lpBaseAddress">寫入進程的內存地址</param>
''' <param name="lpBuffer">數據存儲變量</param>
''' <param name="nSize">長度sizeof(lpBuffer)</param>
''' <param name="lpNumberOfBytesWritten">實際數據的長度</param>
''' <returns></returns>
''' <remarks></remarks>
Declare Function WriteProcessMemory Lib "kernel32" Alias "WriteProcessMemory" _
(ByVal hProcess As Integer, ByVal lpBaseAddress As IntPtr, _
ByVal lpBuffer As Byte(), ByVal nSize As Integer, ByVal lpNumberOfBytesWritten As IntPtr) As Boolean
Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As Integer
Friend Const PROCESS_ALL_ACCESS = &H1F0FFF = 2035711
Friend Const PROCESS_VM_READ = &H10
Friend Const PROCESS_VM_WRITE = &H20
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim hw As Integer = OpenProcess(PROCESS_VM_READ, False, 4304)
Dim getstr(12) As Byte
Dim GetStrIntptr = Marshal.UnsafeAddrOfPinnedArrayElement(getstr, 0)
Button1.Text = "read結果:" & ReadProcessMemory(hw, CType(&H4D45A0, IntPtr), GetStrIntptr, 12, 0)
TextBox1.Text = Marshal.PtrToStringUni(GetStrIntptr)
TextBox3.Text = "GLE:" & GetLastError
CloseHandle(hw)
End Sub
‘需要注意:readprocessmemory的lpBuffer放的地數組地址的基址,需要用marshal轉化一下。Marshal.PtrToStringUni(GetStrIntptr)輸出內容。
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim hw As Integer = OpenProcess(&H1F0FFF, False, 4304)
Dim Wrtstr(12) As Byte
Wrtstr = System.Text.Encoding.Unicode.GetBytes("vbWrit")
Button2.Text = "Write結果:" & WriteProcessMemory(hw, CType(&H4D45A0, IntPtr), Wrtstr, 12, 0)
TextBox3.Text = "GLE:" & GetLastError
CloseHandle(hw)
End Sub
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。