要修改指定程序的指定地址数据,我们需要用到两个api函数,分别是ReadProcessMemory和WriteProcessMemory。

下载是函数的定义:

BOOL ReadProcessMemory(  
  HANDLE hProcess,  
  LPCVOID lpBaseAddress,  
  LPVOID lpBuffer,  
  SIZE_T nSize,  
  SIZE_T* lpNumberOfBytesRead  
);  
Parameters  
  
hProcess  
[in] A handle to the process with memory that is being read. The handle must have PROCESS_VM_READ access to the process.  
lpBaseAddress  
[in] A pointer to the base address in the specified process from which to read. Before any data transfer occurs, the system verifies that all data in the base address and memory of the specified size is accessible for read access, and if it is not accessible the function fails.  
lpBuffer  
[out] A pointer to a buffer that receives the contents from the address space of the specified process.  
nSize  
[in] The number of bytes to be read from the specified process.  
lpNumberOfBytesRead  
[out] A pointer to a variable that receives the number of bytes transferred into the specified buffer. If lpNumberOfBytesRead is NULL, the parameter is ignored.  
Return Value  
  
If the function succeeds, the return value is nonzero.  
  
If the function fails, the return value is 0 (zero). To get extended error information, call GetLastError.  
  
The function fails if the requested read operation crosses into an area of the process that is inaccessible.  
  
WriteProcessMemory  
  
Writes data to an area of memory in a specified process. The entire area to be written to must be accessible or the operation fails.  
  
BOOL WriteProcessMemory(  
  HANDLE hProcess,  
  LPVOID lpBaseAddress,  
  LPCVOID lpBuffer,  
  SIZE_T nSize,  
  SIZE_T* lpNumberOfBytesWritten  
);  
Parameters  
  
hProcess  
[in] A handle to the process memory to be modified. The handle must have PROCESS_VM_WRITE and PROCESS_VM_OPERATION access to the process.  
lpBaseAddress  
[in] A pointer to the base address in the specified process to which data is written. Before data transfer occurs, the system verifies that all data in the base address and memory of the specified size is accessible for write access, and if it is not accessible, the function fails.  
lpBuffer  
[in] A pointer to the buffer that contains data to be written in the address space of the specified process.  
nSize  
[in] The number of bytes to be written to the specified process.  
lpNumberOfBytesWritten  
[out] A pointer to a variable that receives the number of bytes transferred into the specified process. This parameter is optional. If lpNumberOfBytesWritten is NULL, the parameter is ignored.  
Return Value  
  
If the function succeeds, the return value is nonzero.  
  
If the function fails, the return value is 0 (zero). To get extended error information, call GetLastError. The function fails if the requested write operation crosses into an area of the process that is inaccessible.  

下面以星际争霸的矿石修改为例,简述这两个函数的用法。

先获取当前的矿石数,用ReadProcessMemory

ReadProcessMemory(h, ptr(GoldA + i * 4), @Gold, 4, tt);

h是程序进程的句柄,其中GoldA就是地址偏移基准数值,@Gold是一个byte型的数组buffer,读取到的数据也就存放在里面,接下来的4表示buffer的长度,最后的tt是传出值,它显示了成功读取的长度。

好了,现在读取到了,我们把@Gold的值进行一番修改后,再写回去,使用WriteProcessMemory方法

WriteProcessMemory(h, ptr(GoldA + i * 4), @Gold, 4, tt);

与上面的Read过程一模一样,这样就能够写回去了。

下面附上一段完整代码

procedure TFormMain.Cheat113;  
var  
hw: HWND;  
pid: DWord;  
h: THandle;  
tt: Cardinal;  
Gold: array[0..3] of byte;  
Gas: array[0..3] of byte;  
GoldA: integer;  
GasA: integer;  
i: integer;  
const  
Gold130 = $508600;  
Gas130 = $508630;  
begin  
hw := FindWindow(nil, 'Brood War');  
if hw = 0 then  
    Exit;  
GetWindowThreadProcessId(hw, @pid);  
h := OpenProcess(PROCESS_ALL_ACCESS, false, pid);  
if h = 0 then  
    Exit;  
Gold[0] := $FF;  
Gold[1] := $FF;  
Gold[2] := $00;  
Gold[3] := $00;  
Gas[0] := $FF;  
Gas[1] := $FF;  
Gas[2] := $00;  
Gas[3] := $00;  
GoldA := Gold130;  
GasA := Gas130;  
if (chkMineral.Enabled) and (chkMineral.Checked) then  
begin  
    for i := 0 to 11 do  
    begin  
      WriteProcessMemory(h, ptr(GoldA + i * 4), @Gold, 4, tt);  
    end;  
end;  
if (chkGas.Enabled) and (chkGas.Checked) then  
begin  
    for i := 0 to 11 do  
    begin  
      WriteProcessMemory(h, ptr(GasA + i * 4), @Gas, 4, tt);  
    end;  
end;  
CloseHandle(h);  
end;   

转载于:https://www.cnblogs.com/rogee/archive/2010/09/15/1827438.html

DELPHI实现游戏内存的修改相关推荐

  1. 网络安全学习第15篇 - 游戏内存修改

    请依据实验文档<游戏辅助的实现>中的内容,自行编写一个游戏内存数据修改程序,使其可以对某款游戏的某一项或某几项数值进行修改.有余力的同学可以任选一款游戏尝试修改. 实验报告的最后请简述,作 ...

  2. DELPHI 内存流修改16进制文件, 文件太大时候OutofMemory的问题研究

    DELPHI 内存流修改16进制文件, 文件太大时候OutofMemory的问题研究 问题描述: 需要用内存流打开一个300M大小的文件, 替换文件中固定长度的16进制编码为另一条编码 原始思路 1. ...

  3. 游戏外挂原理解析与制作 - [内存数值修改类 篇四]

    前三篇的博文结合了C#的Demo对内存数据修改一类的挂剖析了原理,利用C#语言调用Windows API,我们其实已经写出了一个简单的内存扫描工具,但是它存在一些缺陷,比如说只能所搜索单一类型数值(整 ...

  4. 【CE】游戏内存修改 植物大战僵尸 太阳数量

    游戏版本:植物大战僵尸中文版( PlantsVsZombies ) https://www.jb51.net/game/73344.html Cheat Engine 版本:Cheat Engine ...

  5. 游戏客户端内存防修改浅析

    游戏客户端内存防修改浅析 但凡现在有点人气的游戏都可能被hack,而且网上有很多方便的工具可以使用,单就手机端还讲,最常见的内存修改器有八门神器.烧饼修改器.最近针对这两种内存修改器做了些防护处理,简 ...

  6. 不要迷恋我,我只是利用Python修改了游戏内存

    前言 大家好,我叫善念. 这次要做的是修改一款单机游戏的数据,学过C语言的朋友肯定经常会看到有些老师讲这个案例,就是<植物大战僵尸>这个课题,不过此文我将带大家利用Python来实现(20 ...

  7. 只需要一点点C++基础,新手也可以制作单机游戏内存修改器

    声明:本文只是为了初学C++的,能够做出一些实用的东西,跳出管理系统的束缚,提升学习的兴趣,在这里选取了单机游戏,请不要尝试在线游戏,违发而已未必可行. 序:首先我们需要一个Qt+VS环境 Qt从ht ...

  8. 【术】游戏内存修改器原理及游戏敏感数值加密建议

    介绍市面上主流游戏内存修改器的原理,对症下药,让游戏从数据加密层面上更好的抵御这类内存修改器. 主流游戏内存修改器有三大内存搜索功能: 1. 基础数值搜索 2. 模糊搜索 3. 反加密搜索 基础数值搜 ...

  9. 街机游戏-FC游戏的hack修改rom

    这个文章算是一个记录,目前没空再去改游戏了,我怕等我有空的时候,把这方面的知识忘了. 还有关于这个文章的一些纠正. 关于修改街机游戏的一些方法 https://blog.csdn.net/oChunC ...

最新文章

  1. JVM自动内存管理:对象判定和回收算法
  2. WCF - 基础介绍
  3. Richardson RazorSQL中文版
  4. Serverless Devs 的官网是如何通过 Serverless Devs 部署的
  5. 如何采用python语言绘制一条_如何使用matplotlib绘制一条线?
  6. 微信小程序-WebSocket应用
  7. 滑块 组件_组件制作:如何使用链接的输入创建滑块
  8. cmake,CMakeLists.txt,make,makefile的关系
  9. hadoop记录topk
  10. [转载] python 闭包和装饰器详解
  11. 【广东大学生网络攻防大赛-WriteUp(非官方)】Reverse | pyre
  12. 华为云文字识别关键技术和特别需要注意的事宜
  13. mysql 限制条数_MySQL LIMIT:限制查询结果的条数
  14. 嵌入式算法19---国家商用密码SM算法
  15. c++语言表白超炫图形_数学公式的超酷表白我爱你
  16. 2022年微信小程序真机调试全流程及10大常见问题处理
  17. 清除WAS的僵死进程
  18. 用gulp实现代码压缩、图片压缩和项目打包
  19. 《OpenCalib: A Multi-sensor Calibration Toolbox for Autonomous Driving》论文解读
  20. android 录制手机视频与生成gif图片

热门文章

  1. 【每周CV论文推荐】 初学深度学习人脸关键点检测必读文章
  2. 跨境出海,Tik Tok商业化营销推广分享
  3. 中国聚氨酯胶粘剂行业现状研究分析及市场前景预测报告(2022年)
  4. VB 字节数组和字符串的转换问题 (StringByte)
  5. 37 反转一个3位整数
  6. ListView优化的代码
  7. hdu 4640(状压dp)
  8. “LM/w3svc/1/root /***” 别名已存在
  9. 产品经理面试中那些不忍直视的奇葩题目,面试官你真是够了!
  10. 阿里用户体验大师教你如何让产品更加触动人心