当前位置:   article > 正文

python修改植物大战僵尸阳光值_python 植物大战僵尸 锁死阳光

python 植物大战僵尸 锁死阳光

逆向第一课,找个单机游戏,改数据玩玩。 

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # File : 植物大战僵尸修改器.py
  4. # Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
  5. # Date : 2019/12/28
  6. import win32gui
  7. import win32process
  8. import win32api
  9. import ctypes
  10. handle = win32gui.FindWindow(None,"植物大战僵尸中文版")
  11. print(handle)
  12. pid = win32process.GetWindowThreadProcessId(handle)[1]
  13. print(pid)
  14. phwnd = win32api.OpenProcess(0x1F0FFF,False,pid)
  15. print(phwnd)
  16. kernerl32 = ctypes.windll.LoadLibrary(r"C:\Windows\System32\kernel32.dll")
  17. print(kernerl32)
  18. data1 = ctypes.c_long()
  19. kernerl32.ReadProcessMemory(int(phwnd),0x006A9EC0,ctypes.byref(data1),4,None)
  20. print(hex(data1.value))
  21. data2 = ctypes.c_long()
  22. kernerl32.ReadProcessMemory(int(phwnd),data1.value+0x768,ctypes.byref(data2),4,None)
  23. print(hex(data2.value))
  24. data3 = ctypes.c_long()
  25. kernerl32.ReadProcessMemory(int(phwnd),data2.value+0x5560,ctypes.byref(data3),4,None)
  26. print(data3.value)
  27. sun = int(input("请输入你要的阳光值:"))
  28. kernerl32.WriteProcessMemory(int(phwnd),data2.value+0x5560,ctypes.byref(ctypes.c_long(sun)),4,None)

 

优化增强版功能,支持热键启用,无限阳光,无cd;

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # File : 植物大战僵尸无敌.py
  4. # Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
  5. # Date : 2019/12/28
  6. import win32gui
  7. import win32process
  8. import win32api
  9. import ctypes
  10. from time import sleep
  11. import ctypes.wintypes
  12. from threading import Thread,activeCount, enumerate
  13. import win32con
  14. kernerl32 = ctypes.windll.LoadLibrary(r"C:\Windows\System32\kernel32.dll")
  15. flag_lock = {
  16. "sun_lock":False,
  17. "cd_lock":False
  18. }
  19. h_ids = [i for i in range(2)] # 创建两个热键序列
  20. h_keys = {i: False for i in h_ids} # 初始化所有热键序列的标志符为False
  21. h_dict = {} # 初始化一个空的字典,记录id与func
  22. def thread_it(func, *args):
  23. t = Thread(target=func, args=args)
  24. t.setDaemon(True)
  25. t.start()
  26. class Hotkey(Thread): # 创建一个Thread的扩展类
  27. user32 = ctypes.windll.user32 # 加载user32.dll
  28. def regiskey(self, hwnd=None, flagid=0, fnkey=win32con.MOD_ALT, vkey=win32con.VK_F9): # 注册热键,默认一个alt+F9
  29. return self.user32.RegisterHotKey(hwnd, flagid, fnkey, vkey)
  30. def callback(self, id, func):
  31. h_dict[id] = func # 这个id对应这个func,没有就是新增,有就是修改
  32. def inner():
  33. for key, value in h_dict.items():
  34. print(f'总的热键池:{h_ids},当前热键序号:{key}, 当前热键功能:{value},当前热键状态:{h_keys[h_ids[key]]}')
  35. while True:
  36. for key, value in h_dict.items():
  37. if h_keys[h_ids[key]]:
  38. thread_it(value) # 另外开线程执行value
  39. h_keys[h_ids[key]] = False
  40. return inner
  41. def run(self):
  42. if not self.regiskey(None, h_ids[0], win32con.MOD_ALT, win32con.VK_F9): # 注册快捷键alt+F9并判断是否成功,该热键用于执行一次需要执行的内容。
  43. print(f"热键注册失败! id{h_ids[0]}") # 返回一个错误信息
  44. if not self.regiskey(None, h_ids[1], 0, win32con.VK_F10): # 注册快捷键F10并判断是否成功,该热键用于结束程序,且最好这么结束,否则影响下一次注册热键。
  45. print(f"热键注册失败! id{h_ids[1]}")
  46. # 以下为检测热键是否被按下,并在最后释放快捷键
  47. try:
  48. msg = ctypes.wintypes.MSG()
  49. while True:
  50. if self.user32.GetMessageA(ctypes.byref(msg), None, 0, 0) != 0:
  51. if msg.message == win32con.WM_HOTKEY:
  52. if msg.wParam in h_ids:
  53. h_keys[msg.wParam] = True
  54. self.user32.TranslateMessage(ctypes.byref(msg))
  55. self.user32.DispatchMessageA(ctypes.byref(msg))
  56. finally:
  57. for i in h_ids:
  58. self.user32.UnregisterHotKey(None, i)
  59. # 必须得释放热键,否则下次就会注册失败,所以当程序异常退出,没有释放热键,
  60. # 那么下次很可能就没办法注册成功了,这时可以换一个热键测试
  61. def modSwitch(flag,msg):
  62. global flag_lock
  63. if flag_lock[flag] == True:
  64. flag_lock[flag] = False
  65. print(f"{msg}已关闭")
  66. else:
  67. flag_lock[flag] = True
  68. print(f"{msg}已开启")
  69. def sunSwith():
  70. modSwitch("sun_lock","锁阳光")
  71. def cdSwith():
  72. modSwitch("cd_lock","无CD")
  73. def hotkey_init():
  74. hotkey = Hotkey()
  75. hotkey.start()
  76. hotkey.callback(0, sunSwith)
  77. fn = hotkey.callback(1, cdSwith)
  78. thread_it(fn)
  79. sleep(0.5)
  80. count = activeCount()
  81. print(f"当前总线程数量:{count}")
  82. print('当前线程列表:', enumerate())
  83. print('热键注册初始化完毕,组合键alt+F9 无限阳光开关 F10 无CD开关')
  84. def main():
  85. hotkey_init()
  86. while True:
  87. handle = win32gui.FindWindow(None,"植物大战僵尸中文版") #找到窗口句柄
  88. if handle:
  89. pid = win32process.GetWindowThreadProcessId(handle)[1] #找到进程id
  90. phwnd = win32api.OpenProcess(0x1F0FFF,False,pid) #找到进程句柄
  91. if flag_lock["sun_lock"]:
  92. sunMod(phwnd)
  93. if flag_lock["cd_lock"]:
  94. cdMod(phwnd)
  95. sleep(0.1)
  96. def sunMod(phwnd,sun_num=9999):
  97. data1 = ctypes.c_long()
  98. kernerl32.ReadProcessMemory(int(phwnd), 0x006A9EC0, ctypes.byref(data1), 4, None)
  99. data2 = ctypes.c_long()
  100. kernerl32.ReadProcessMemory(int(phwnd), data1.value + 0x768, ctypes.byref(data2), 4, None)
  101. data3 = ctypes.c_long()
  102. kernerl32.ReadProcessMemory(int(phwnd), data2.value + 0x5560, ctypes.byref(data3), 4, None)
  103. print(f"\r阳光值:{data3.value}",end="")
  104. kernerl32.WriteProcessMemory(int(phwnd), data2.value + 0x5560, ctypes.byref(ctypes.c_long(int(sun_num))), 4, None)
  105. def cdMod(phwnd):
  106. data1 = ctypes.c_long()
  107. kernerl32.ReadProcessMemory(int(phwnd), 0x6A9EC0, ctypes.byref(data1), 4, None)
  108. data2 = ctypes.c_long()
  109. kernerl32.ReadProcessMemory(int(phwnd), data1.value + 0x768, ctypes.byref(data2), 4, None)
  110. data3 = ctypes.c_long()
  111. kernerl32.ReadProcessMemory(int(phwnd), data2.value + 0x144, ctypes.byref(data3), 4, None)
  112. for i in range(10):
  113. #0到10格,全部冷却改为1
  114. kernerl32.WriteProcessMemory(int(phwnd), data3.value + 0x70+0X50*i, ctypes.byref(ctypes.c_long(1)), 2, None)
  115. if __name__ == '__main__':
  116. main()

 

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

闽ICP备14008679号