当前位置:   article > 正文

写个最简单的植物大战僵尸修改器吧!c和python_python修改植物大战僵尸内存

python修改植物大战僵尸内存

效果图:

C实现:

  1. #include<windows.h>
  2. #include<stdio.h>
  3. void main()
  4. {
  5. //获取游戏窗口句柄
  6. HWND hd = FindWindow(L"MainWindow",L"植物大战僵尸中文版");
  7. DWORD pid;
  8. //通过窗口句柄获取进程ID
  9. GetWindowThreadProcessId(hd, &pid);
  10. //通过进程ID获取进程句柄
  11. HANDLE hprocess = OpenProcess(PROCESS_ALL_ACCESS,false,pid);
  12. DWORD address;
  13. //通过基址和偏移获取阳光的地址 (想得到这些数据需要学点CheatEngine简称CE)
  14. ReadProcessMemory(hprocess, (LPVOID)0x6a9ec0, &address, 4, NULL);
  15. ReadProcessMemory(hprocess, (LPVOID)(address+0x768), &address, 4, NULL);
  16. address += 0x5560;
  17. //printf("阳光地址:%x", address);
  18. int sun;
  19. scanf_s("%d",&sun);
  20. //改阳光数
  21. WriteProcessMemory(hprocess, (LPVOID)address, &sun, 4,NULL);
  22. }

python实现比较麻烦,需要事先安装好PyWin32和ctypes这两个库

python实现:

  1. import win32gui,win32api,win32process,ctypes
  2. #载入kernal32.dll,Windows读写内存的函数在这个dll里面
  3. kernal32=ctypes.windll.LoadLibrary(r"C:\Windows\System32\kernel32.dll")
  4. #用于通过基址获取最终的地址
  5. def GetAddress(handle,BaseAddress,offset=[]):
  6. value=ctypes.c_long()
  7. kernal32.ReadProcessMemory(int(handle),BaseAddress,ctypes.byref(value),4,None)
  8. for i in range(len(offset)-1):
  9. kernal32.ReadProcessMemory(int(handle), value.value+offset[i], ctypes.byref(value), 4, None)
  10. return value.value+offset[len(offset)-1]
  11. #获取窗口句柄
  12. hwnd=win32gui.FindWindow("MainWindow","植物大战僵尸中文版")
  13. #通过窗口句柄获取进程ID,该函数返回一个列表,进程ID是在第二
  14. pid=win32process.GetWindowThreadProcessId(hwnd)[1]
  15. #通过进程ID获取句柄
  16. handle=win32api.OpenProcess(0x1F0FFF,False,pid)
  17. #ctypes.c_long()返回的是一个C语言long类型的变量
  18. showSun=ctypes.c_long()
  19. changeSun=ctypes.c_long()
  20. while 1:
  21. address = GetAddress(handle, 0x6a9ec0, offset=[0x768, 0x5560])
  22. #ctypes.byref(showSun)相当于取showSun的指针
  23. kernal32.ReadProcessMemory(int(handle),address,ctypes.byref(showSun),4,None)
  24. print("{}{}".format("当前阳光:",showSun.value))
  25. changeSun.value = int(input("要修改成多少:"))
  26. kernal32.WriteProcessMemory(int(handle), address, ctypes.byref(changeSun), 4, None)

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/706813
推荐阅读
相关标签
  

闽ICP备14008679号