VB读写进程的内存
在窗体部分简单测试了ReadProcessMemory和WriteProcessMemory对另一个程序进程的读写.
由于临时项目变动,又不需要了,所以直接封类,删工程.以下代码没有一个函数经过测试,编译都没有进行...
Option Explicit
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal dwProcess As Long, lpBaseAddress As Any, lpbuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal dwProcess As Long, lpBaseAddress As Any, lpbuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Dim dwProc As Long
Dim dwPid As Long
'设置进程
Public Function SetProcess(Pid As Long)
Call Terminate
dwProc = OpenProcess(PROCESS_ALL_ACCESS, False, Pid)
dwPid = Pid
End Function
'读取,分别对应 字节组,十六进制和整数
Private Function ReadMemoryA(Addr As Long, Size As Long) As Byte()
If Size < Then Exit Function
Dim Ret As Boolean, buf() As Byte
ReDim buf(Size - ) As Byte
Ret = ReadProcessMemory(dwProc, ByVal Addr, buf(), Size, )
If Ret Then ReadMemory = buf
End Function
Private Function ReadMemoryH(Addr As Long, Size As Long) As String
If Size < Then Exit Function
Dim Ret As Boolean, buf() As Byte
ReDim buf(Size - ) As Byte
Ret = ReadProcessMemory(dwProc, ByVal Addr, buf(), Size, )
If Ret Then
Dim i As Long
For i = To UBound(buf)
If buf(i) > Then
ReadMemoryH = ReadMemoryH & Hex(buf(i)) & " "
Else
ReadMemoryH = ReadMemoryH & "" & Hex(buf(i)) & " "
End If
Next
End If
End Function
Private Function ReadMemoryL(Addr As Long) As Long
If Size < Then Exit Function
Dim Ret As Boolean, L As Long
ReadProcessMemory dwProc, ByVal Addr, L, ,
ReadMemoryL = L
End Function
'写入,分别对应 单字节,字节组,和整数
Private Function WriteMemory(Addr As Long, buf As Byte)
WriteProcessMemory dwProc, ByVal Addr, buf, , &
End Function
Private Function WriteMemoryA(Addr As Long, buf() As Byte)
WriteProcessMemory dwProc, ByVal Addr, buf(), UBound(buf) + , &
End Function
Private Function WriteMemoryL(Addr As Long, L As Long)
WriteProcessMemory dwProc, ByVal Addr, L, , &
End Function
'销毁资源占用
Private Sub Terminate()
If dwPid <> Then CloseHandle dwPid
If dwProc <> Then CloseHandle dwProc
End Sub
Private Sub Class_Terminate()
Call Terminate
End Sub
VB读写进程的内存的更多相关文章
- 通过WriteProcessMemory改写进程的内存
http://www.cnblogs.com/feiyucq/archive/2009/10/21/1587628.html 以PROCESS_ALL_ACCESS权限打开进程以后既能够使用ReadP ...
- Linux进程分配内存的两种方式--brk() 和mmap()
如何查看进程发生缺页中断的次数? 用ps -o majflt,minflt -C program命令查看. majflt代表major fault,中文名叫大错误,minflt代表minor faul ...
- 内存分配的原理__进程分配内存有两种方式,分别由两个系统调用完成:brk和mmap(不考虑共享内存)
如何查看进程发生缺页中断的次数? 用ps -o majflt,minflt -C program命令查看. majflt代表major fault,中文名叫大错误,minflt代表minor faul ...
- Linux 查看进程消耗内存情况总结
在Linux中,有很多命令或工具查看内存使用情况,今天我们来看看如何查看进程消耗.占用的内存情况,Linux的内存管理和相关概念要比Windows复杂一些.在此之前,我们需要了解一下Linux系统下面 ...
- postgresql进程及内存结
一.进程和内存架构图 postgresql数据库启动时,先启动一个postmaster的主进程,然后fork出一些辅助子进程. 二.主进程postmaster -bash-4.2$ which pos ...
- 进程分配内存的两种方式--brk() 和mmap()(不设计共享内存)(转)
如何查看进程发生缺页中断的次数? 用ps -o majflt,minflt -C program命令查看. majflt代表major fault,中文名叫大错误,minflt代表minor faul ...
- linux下对进程按照内存使用情况进行排序
linux下对进程按照内存使用情况进行排序的命令为:ps aux --sort -rss 详细解说参见 http://alvinalexander.com/linux/unix-linux-proce ...
- VB读写INI文件的四个函数以及相关API详细说明
WritePrivateProfileString函数说明 来源:http://blog.csdn.net/wjb9921/article/details/2005000 在我们写的程序当中,总有一 ...
- HBase 学习笔记---守护进程及内存调优
1.HMaster HMaster的任务前面已经说过了,两个大方向:一.管理Hbase Table的 DDL操作 二.region的分配工作,任务不是很艰巨,但是如果采用默认自动s ...
随机推荐
- git应用
安装 Git for windows git config --global user.name "zhangyue" git config --global user.mail ...
- ipmitool 工具使用
ipmi 工具使用: 一. ipmitool lan print ipmitool -I open lan set 1 ipsrc static 设置本地BMC地址为静态,才能设置IP ipmit ...
- 记我在github上参与的Star增长最快的十万级项目。。。
前言 GitHub作为程序员的圣地. 用了两三年,一直都觉得,他可以代码托管,项目管理,为项目建立静态主页,个人简历,找工作,面试加分. 然而>>>....昨天才认识到我还是太年轻, ...
- android TextView加载html 过滤所有标签,保留换行标签
情景: TextView加载后端接口获取到的html富文本 遇到的问题: 客户端通过接口取到的数据如下: <p style="margin-top: 0px; margin-botto ...
- Non-decreasing Array
Given an array with n integers, your task is to check if it could become non-decreasing by modifying ...
- 微信中音乐播放在ios不能自动播放解决
在微信中,ios手机下面音乐被自动禁掉无法自动播放,我们可以执行触发body上的元素,自动进行播放. //音乐 var x = document.getElementById("myAudi ...
- 谷歌的Android Q到底有哪些新特性及变更?
Android Q 隐私更改相关介绍 存储范围变更 Android Q 改变了应用程序访问设备外部存储上文件的方式. 通过使用更细粒度的媒体特定权限替换以前的 READ_EXTERNAL_STORAG ...
- Docker----搭建自己的gitlab(填坑之旅)
在成功完成docker的基础实验之后,尝试着使用docker搭建自己的gitlab,用来存放自己的代码.本文主要介绍使用docker搭建gitlab过程中遇到的问题,我的服务器系统是:Ubuntu S ...
- python的pandas库学习笔记
导入: import pandas as pd from pandas import Series,DataFrame 1.两个主要数据结构:Series和DataFrame (1)Series是一种 ...
- selenium笔记(1)
selenium笔记(1) 一.关闭页面:1.driver.close() 关闭当前页面2.driver.quit() 退出整个浏览器 二.定位元素:1.find_element_by_id: 根据i ...