网上好多关于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
创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。
当前文章:vb.netReadProcessMemory使用方法-创新互联
文章地址:https://www.cdcxhl.com/article42/dsddhc.html
成都网站建设公司_创新互联,为您提供电子商务、品牌网站建设、网站策划、微信公众号、云服务器、企业建站
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联