之前写的基于内存修改的扫雷程序,现在分享一下,有疑问可以互相交流,代码注释也很清晰
由于win10没有扫雷,先要下载安装扫雷,winmine.exe,可以在网上搜
打开运行扫雷后,再运行python程序就可以自动扫雷了
# 一键扫雷import win32guiimport win32processimport win32APIimport ctypesimport win32conimport time# 获取窗口句柄window_handle = win32gui.FinDWindow(None, "扫雷")# 获取窗口坐标left, top, right, bottom = win32gui.GetwindowRect(window_handle)#print("窗口坐标:")#print(str(left)+' '+str(right)+' '+str(top)+' '+str(bottom))# 点击窗口函数def click(x,y): win32API.SetCursorPos([x, y]) win32API.mouse_event(win32con.MOUSEEVENTF_leftDOWN, 0, 0, 0, 0) win32API.mouse_event(win32con.MOUSEEVENTF_leftUP, 0, 0, 0, 0) win32API.mouse_event(win32con.MOUSEEVENTF_leftDOWN, 0, 0, 0, 0) win32API.mouse_event(win32con.MOUSEEVENTF_leftUP, 0, 0, 0, 0) #time.sleep(0.5)left = left + 6top = top + 107# 获取进程IDprocess_ID = win32process.GetwindowThreadProcessID(window_handle)[1]# 获取进程句柄process_handle = win32API.OpenProcess(0x1F0FFF, False, process_ID)# 调用系统内核kernel32 = ctypes.windll.Loadlibrary(r"C:\windows\System32\kernel32.dll")# 读取内存# 获取区域高度height = ctypes.c_long()kernel32.ReadProcessMemory(int(process_handle), 0x01005338, ctypes.byref(height), 4, None)#print(height)# 获取区域宽度wIDth = ctypes.c_long()kernel32.ReadProcessMemory(int(process_handle), 0x01005334, ctypes.byref(wIDth), 4, None)#print(wIDth)# 打印每个格子的地址def print_address(List): print('格子内存地址如下:') for i in List: print(i)# 起始地址s = 16798561 #Ox1005361n = 0lei = 0List = []for y in range(0,height.value): a = [] for x in range(1,wIDth.value+1): # 获取当前内存的值 m = s + (x-1) + y*32 n += 1 #print("0x0%02x" % m) data = ctypes.c_long() kernel32.ReadProcessMemory(int(process_handle), m, ctypes.byref(data), 4, None) #print(hex(data.value)) #print(hex(data.value)[-2:]) a.append(hex(data.value)) # 点击不是雷的 if(hex(data.value)[-2:] != '8f' and hex(data.value)[-2:] != '8a' and hex(data.value)[-2:] != '71'): pass #print(hex(data.value)) click(left + x*16, top + y*16) #print('点击了第{}行{}列'.format(y+1,x),hex(data.value)) else: lei += 1 List.append(a)print_address(List)print('扫雷结束')print('共有{}个块,{}个雷'.format(n,lei))
总结
以上是内存溢出为你收集整理的Python修改内存(扫雷)全部内容,希望文章能够帮你解决Python修改内存(扫雷)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)