好友
阅读权限20
听众
最后登录1970-1-1
|
本帖最后由 liyitong 于 2021-12-29 14:36 编辑
解释性语言操作内存真的不太友好,还是推荐编译型语言。
听说IDA有个模块是用Python写的。。。。嗯,特别厉害的人,不属于“一般人”这个被讨论对象。
目前看到的获取句柄都是通过findwindows(查找进程的窗口名)进行,这篇笔记主要记录通过进程名获取句柄。
首先画一个界面,用pyqt5的qtdesinger拖曳出来,然后用py2ui,把ui文件直接转成py文件即可。
界面代码:[Python] 纯文本查看 复制代码 # -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'klkd.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(338, 271)
font = QtGui.QFont()
font.setFamily("宋体")
font.setPointSize(16)
MainWindow.setFont(font)
MainWindow.setToolTipDuration(-3)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(60, 30, 111, 21))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(60, 80, 131, 21))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(60, 130, 131, 21))
self.label_3.setObjectName("label_3")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(60, 170, 131, 41))
self.label_4.setObjectName("label_4")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(200, 24, 71, 31))
self.lineEdit.setAlignment(QtCore.Qt.AlignCenter)
self.lineEdit.setObjectName("lineEdit")
self.label_5 = QtWidgets.QLabel(self.centralwidget)
self.label_5.setGeometry(QtCore.QRect(110, 230, 211, 21))
self.label_5.setObjectName("label_5")
#MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "恐龙快打全屏攻击"))
self.label.setText(_translate("MainWindow", "F1 攻击力"))
self.label_2.setText(_translate("MainWindow", "F2 全屏攻击"))
self.label_3.setText(_translate("MainWindow", "F3 连击刷分"))
self.label_4.setText(_translate("MainWindow", "F4 取消连击"))
self.lineEdit.setText(_translate("MainWindow", "0x40"))
self.label_5.setText(_translate("MainWindow", "liyitong@52pojie.cn"))
然后创建一个主程序代码,使用界面代码的窗口类,新建一个窗口,这样修改ui到py文件的时候,就不用重新写逻辑代码了。
就是说,把界面代码和功能代码分开到2个文件中来写。
功能代码(jiemian.py):[Python] 纯文本查看 复制代码 from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtCore import pyqtSignal,Qt
import sys,win32api
from win32con import PROCESS_ALL_ACCESS #Opencress 权限
import ctypes #内存读写的数据类型
from ctypes import *
from ctypes.wintypes import *
import win32ui #申请程序权限
import psutil #遍历进程
#from tkinter import * #注意模块导入方式,否则代码会有差别,另见:import tkinter.messagebox 方法
#from tkinter import messagebox
from jiemian import Ui_MainWindow #创建一个界面副本,使界面代码独立于功能代码
from system_hotkey import SystemHotkey #用来注册全局热键,即F1,F2等快捷键
kernel32 = windll.LoadLibrary("kernel32.dll")
ReadProcessMemory = kernel32.ReadProcessMemory #读取内存值函数
WriteProcessMemory = kernel32.WriteProcessMemory #写入内存值函数
jincheng=r'X-Zone.exe' #要修改的程序的进程名
#root = Tk()
#root.withdraw()
for proc in psutil.process_iter(): #遍历每一个进程
if proc.name() == jincheng: #找到目标进程
process = ctypes.windll.kernel32.OpenProcess(PROCESS_ALL_ACCESS , False, proc.pid) #获取目标进程的pid
print(process)
break #找到后立即结束for循环,不再继续查找下一个进程
def rpm(address,bufflength=4): #读取地址,用于操作偏移地址量
date= ctypes.c_int32()
ReadProcessMemory(int(process), address, ctypes.byref(date), bufflength,None)
return date.value
def wpm1(address:int, zhi=0x40): #模块地址1,不影响代码理解
buf = ctypes.c_int32(zhi)
try:
ret = ctypes.windll.kernel32.WriteProcessMemory(int(process),address+rpm(rpm(0xe990c0)+0xFCDDD0),ctypes.byref(buf),1,1,None)
except BaseException:
print('遇到了不完全权限')
def wpm2(address:int, zhi=0x40): #模块地址2,游戏修改需要,不影响代码理解
buf = ctypes.c_int32(zhi)
try:
ret = ctypes.windll.kernel32.WriteProcessMemory(int(process),address+rpm(rpm(0xe990c0)+0xFCDDD0-0x240),ctypes.byref(buf),1,1,None)
except BaseException:
print('遇到了权限失败')
class zhuchuangkou(QWidget, Ui_MainWindow):
def __init__(self):
super(zhuchuangkou,self).__init__()
self.setupUi(self) #产生界面副本
def gongjili(gongneng=1): #f1的功能
baoji=self.lineEdit.text() #获取输入框的内容
wpm1(0xb33b,int(baoji))
def quanpinggongji(gongneng=2): #F2的功能
wpm2(0x109c6,0x60)
wpm2(0x109c7,0x02)
def lianjishuafen(gongneng=3): #f3
wpm2(0x109c6,0x60)
wpm2(0x109c7,0x64)
def quxiaolianji(gongneng=4): #f4
wpm2(0x109c6, 0x00)
wpm2(0x109c7, 0x00)
hk = SystemHotkey() #启用全局热键
hk.register(('f1',),callback=gongjili) #注册f1
hk.register(('f2',), callback=quanpinggongji)#注册f2
hk.register(('f3',), callback=lianjishuafen)#注册f3
hk.register(('f4',), callback=quxiaolianji)#注册f4
app = QtWidgets.QApplication(sys.argv)
window = zhuchuangkou()
window.show()
sys.exit(app.exec_())
程序打包文件下载:https://liyitong.lanzout.com/igUlRy3eo6b
对应游戏平台下载:游聚游戏平台0.6.60 https://liyitong.lanzout.com/ikrVGy3epcd全屏攻击没有设置关闭,只能炸房重开。
使用连击刷分功能时候,场景内最好不要超过3个敌兵,不然会把游戏卡死。
主要讨论代码,不做游戏辅助,所以不要问我添加什么新功能,我也不会。代码都是抄 的。
|
免费评分
-
查看全部评分
|