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 ...
随机推荐
- 使用antd Table + mobx 处理数组 出现的一系列问题
在store中定义了一个数组: @observable list = [...] 若是在table组件中直接使用list: <Table className={styles.table} col ...
- 论文翻译——Lattice indexing for spoken term detection
第II节简要介绍与本文有关的先前工作第III节介绍文中使用的定义以及术语 第IV节介绍如何从原始ASR lattices中生成倒排索引结构 第V节详细介绍了ASR结构以及实验使用的数据 第VI节提供了 ...
- HTML5+CSS3-学习总结
这是第三次学标签和样式了,虽然距离上次差不多2年.可学过的东西依旧还在. 体会 1. 相对于前端技术,基础还是很重要的. 2. 虽然很繁多.并不是杂乱无章的. 3. HTML5在新增的几个标签, ...
- git知识总结-1.git基础之数据存储
1.前言 git包含四种对象文件: blob tree commit tag(目前没用到,暂时忽略) 2. git对象的关系 图 git三种对象关系 粗略一看,可以大致感觉出blob类似于文件 ...
- Spring Cloud Commons模块
上一篇介绍了 Spring Cloud Context模块 ,本文介绍SpringCloud的另一个基础模块 SpringCloud Commons模块 .只要在项目的pom文件中引入了spring- ...
- find 命令局部小结之 xtime
大家在使用find命令的时候往往会使用它的 -name 或者 -xtime,在这里就说下他的xtime. find / -mtime +7 .find / -mtime -7.find / -mti ...
- 题解-POI2014 Supercomputer
Problem 辣鸡bzoj权限题,洛谷链接 题意概要:一棵 \(n\) 个点有根树.\(Q\) 次询问给出一个 \(K\),回答遍历完整棵树所需最少操作次数.每次操作可以选择访问不超过 \(K\) ...
- 前端笔记知识点整合之JavaScript(三)关于条件判断语句、循环语句那点事
一.条件分支语句 条件分支语句,也叫作条件判断语句,就是根据某种条件执行某些语句,不执行某些语句. JS中有三种语法是可以表示条件分支的 1.1 if……else…… 条件分支的主力语法,这个主力 ...
- Lua教程
Lua中的类型与值 Lua中的表达式 Lua中的语句 Lua中的函数 Lua中的闭包 Lua 中 pairs 和 ipairs 的区别 Lua中的迭代器与泛型for Lua中的协同程序 Lua中__i ...
- 【转载 | 笔记】IIS无法删除应该程序池 因为它包含X个应用程序
IIS无法删除应该程序池 因为它包含X个应用程序 今天代码主分支在vs2015创建了虚拟目录http://localhost/webapp指向的物理路径是E:\webapp 之后新开了一个分支把代码放 ...