博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
VB读写进程的内存
阅读量:4353 次
发布时间:2019-06-07

本文共 2595 字,大约阅读时间需要 8 分钟。

在窗体部分简单测试了ReadProcessMemory和WriteProcessMemory对另一个程序进程的读写,确实管用.

由于临时项目变动,又不需要了,所以直接封类,删工程.以下代码没有一个函数经过测试,编译都没有进行...

Option ExplicitPrivate Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As LongPrivate Const PROCESS_ALL_ACCESS = &H1F0FFFPrivate Declare Function ReadProcessMemory Lib "kernel32" (ByVal dwProcess As Long, lpBaseAddress As Any, lpbuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As LongPrivate Declare Function WriteProcessMemory Lib "kernel32" (ByVal dwProcess As Long, lpBaseAddress As Any, lpbuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As LongPrivate Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As LongDim dwProc As LongDim dwPid As Long'设置进程Public Function SetProcess(Pid As Long)    Call Terminate    dwProc = OpenProcess(PROCESS_ALL_ACCESS, False, Pid)    dwPid = PidEnd Function'读取,分别对应 字节组,十六进制和整数Private Function ReadMemoryA(Addr As Long, Size As Long) As Byte()    If Size < 1 Then Exit Function    Dim Ret As Boolean, buf() As Byte    ReDim buf(Size - 1) As Byte    Ret = ReadProcessMemory(dwProc, ByVal Addr, buf(0), Size, 0)    If Ret Then ReadMemory = bufEnd FunctionPrivate Function ReadMemoryH(Addr As Long, Size As Long) As String    If Size < 1 Then Exit Function    Dim Ret As Boolean, buf() As Byte    ReDim buf(Size - 1) As Byte    Ret = ReadProcessMemory(dwProc, ByVal Addr, buf(0), Size, 0)    If Ret Then        Dim i As Long        For i = 0 To UBound(buf)            If buf(i) > 15 Then                ReadMemoryH = ReadMemoryH & Hex(buf(i)) & " "            Else                ReadMemoryH = ReadMemoryH & "0" & Hex(buf(i)) & " "            End If        Next    End IfEnd FunctionPrivate Function ReadMemoryL(Addr As Long) As Long    If Size < 1 Then Exit Function    Dim Ret As Boolean, L As Long    ReadProcessMemory dwProc, ByVal Addr, L, 4, 0    ReadMemoryL = LEnd Function'写入,分别对应 单字节,字节组,和整数Private Function WriteMemory(Addr As Long, buf As Byte)    WriteProcessMemory dwProc, ByVal Addr, buf, 1, 0&End FunctionPrivate Function WriteMemoryA(Addr As Long, buf() As Byte)    WriteProcessMemory dwProc, ByVal Addr, buf(0), UBound(buf) + 1, 0&End FunctionPrivate Function WriteMemoryL(Addr As Long, L As Long)    WriteProcessMemory dwProc, ByVal Addr, L, 4, 0&End Function'销毁资源占用Private Sub Terminate()    If dwPid <> 0 Then CloseHandle dwPid    If dwProc <> 0 Then CloseHandle dwProcEnd SubPrivate Sub Class_Terminate()    Call TerminateEnd Sub

 

转载于:https://www.cnblogs.com/youyouran/p/5322610.html

你可能感兴趣的文章
angularJS之$watch、$digest和$apply方法
查看>>
设计模式之--单例模式(singleton)
查看>>
nyoj 1091 还是01背包(超大数dp)
查看>>
[Leetcode] jump game 跳跃游戏
查看>>
Linux两台服务器mysql数据库同步
查看>>
Git入门及上传项目到github中
查看>>
MyBatis源码解析(十)——Type类型模块之类型处理器TypeHandler
查看>>
关于unity3d调用摄像头的方法
查看>>
搜索--P1605 迷宫
查看>>
【XSY3344】连续段 DP 牛顿迭代 NTT
查看>>
【THUSC2017】【LOJ2978】杜老师 高斯消元
查看>>
RxJS核心概念之Subjet在angular2+上的应用
查看>>
[转]eclipse下编写android程序突然不会自动生成R.java文件和包的解决办法
查看>>
Sphinx+MySQL5.1x+SphinxSE+mmseg中文分词
查看>>
AlertDialog的onCreateDialog与onPrepareDialog用法
查看>>
swift菜鸟入门视频教程-12-21讲
查看>>
PL/SQL 异常处理程序
查看>>
javascript小白学习指南1---0
查看>>
div:给div加滚动栏 div的滚动栏设置
查看>>
java随机函数使用方法Random
查看>>