Python - 植物大战僵尸辅助程序 - 霜冷的秘密基地

Python - 植物大战僵尸辅助程序

目标程序:植物大战僵尸中文版
程序版本:v2.0
作者:霜冷
说明:辅助修改程序的基础属性,目前可修改阳光,僵尸不死,秒杀僵尸,其他的介于自己太懒,所以咕咕。
DLL:C++开发,用于读写内存
意义:复习一下C++读写内存、逆向基础;学习python的GUI编程

import ctypes
import os
import tkinter as tk
from typing_extensions import IntVar


class Ex_dll:
    __ex = 0        # USE THE C++ DLL
    __hProcess = 0  # Game hProcess

    def __init__(self) -> None:
        self.dll()
        self.hProcess()

    def dll(self):
        path = os.path.dirname(__file__)
        ex_path = os.path.join(path, "ex.dll")
        self.__ex = ctypes.WinDLL(ex_path)

    def hProcess(self):
        hProcess = self.__ex.gethProcess()
        self.__hProcess = hProcess
    
    def isRun(self):
        return self.__hProcess

    def MessageBox(self, msg, tit):
        self.__ex.Msg(str(msg), str(tit))

    # DWORD data
    def ReadProcessMemory(self, addr, offset):
        return self.__ex.readMemory(self.__hProcess, addr, offset)

    def WriteProcessMemory(self, addr, value, num=4):
        self.__ex.setAddr(addr)
        return self.__ex.WriteMemory_ex(value, num)


class WINDOWS:
    __window = 0        # Main Window handle

    def CreateWindow(self, title, size):
        self.__window = tk.Tk()
        self.__window.title(title)
        self.__window.geometry(size)

    def addLabel(self, text, rows, col):
        var = tk.StringVar()
        var.set(text)
        label = tk.Label(self.__window, textvariable=var, font=("Arial", 12), width=15, height=1)
        label.grid(row=rows, column=col)

    def getWindow(self):
        return self.__window


# entry input - 阳光设置
def sun_ex():
    try:
        var = int(sun_entry.get())
        ex.WriteProcessMemory(sun_valueAddr, var)
    except:
        print("entry.value is null!")

# btn1 checked - 僵尸不死
def zoombie_unDie():
    if btn1_checked.get():
        if btn2_checked:    # 防止冲突
            checkBtn_zoombie_isKill.deselect()
        print("[Enabled] 僵尸不死")
        ex.WriteProcessMemory(dwrAddr_zoombies_attack, dwrValue_zoombies_attack_unDie)
    else:
        print("[Unable] 僵尸不死")
        ex.WriteProcessMemory(dwrAddr_zoombies_attack, dwrValue_zoombies_attack_old)

# btn2 checked - 秒杀僵尸
def zoombie_oneKill():
    if btn2_checked.get():
        if btn2_checked:    # 防止冲突
            checkBtn_zoombie_unDie.deselect()
        print("[Enabled] 秒杀僵尸")
        ex.WriteProcessMemory(dwrAddr_zoombies_attack, dwrValue_zoombies_attack_oneKill)

    else:
        print("[Unable] 秒杀僵尸")
        ex.WriteProcessMemory(dwrAddr_zoombies_attack, dwrValue_zoombies_attack_old)


# 植物不死
def plant_unDie():
    if btn3_checked.get():
        print("btn3 onChecked!")
    else:
        print("btn3 unChecked!")


# 无CD
def cdNull():
    if btn4_checked.get():
        print("btn4 onChecked!")
    else:
        print("btn4 unChecked!")


if __name__ == "__main__":
    ex = Ex_dll()
    wc = WINDOWS()
    window = wc.getWindow()

    dwSunshineBaseAddress = 0x6A9F38    # sunshine base address
    dwSunshineOffsetFirst = 0x768       # offset one
    dwSunshineOffsetSecond = 0x5560     # offset two
 
    sun_v1 = ex.ReadProcessMemory(dwSunshineBaseAddress, 0)
    sun_v2 = ex.ReadProcessMemory(sun_v1, dwSunshineOffsetFirst)
    sun_v3 = ex.ReadProcessMemory(sun_v2, dwSunshineOffsetSecond)

    sun_valueAddr = int(sun_v2 + dwSunshineOffsetSecond)  # sunshine value address

    if ex.isRun():
        wc.CreateWindow("PanPVZ v1.0 by SmileSL", "310x200")

        # set sun value
        sun_entry = tk.Entry(window)
        btn = tk.Button(window, padx="20p", text="修改阳光", activebackground="#416064", command=sun_ex)
        
        sun_entry.grid(row=2, column=1)
        btn.grid(row=2, column=0)

        # 僵尸不死 - data
        dwrValue_zoombies_attack_old     = 0x20247C2B    # sub edi,dword ptr ss:[esp+0x20]
        dwrValue_zoombies_attack_unDie   = 0x20247C33    # xor edi,dword ptr ss:[esp+0x20]
        dwrValue_zoombies_attack_oneKill = 0x9090FF2B    # sub edi nop nop
        dwrAddr_zoombies_attack          = 0x0053130F    # zoombie.life = edi - attack.value

        btn1_checked = tk.IntVar()
        checkBtn_zoombie_unDie = tk.Checkbutton(window, text="僵尸不死", width=15, height=2, variable=btn1_checked, onvalue=1, offvalue=0, command=zoombie_unDie)
        checkBtn_zoombie_unDie.grid(row=0, column=0)

        # 秒杀僵尸
        btn2_checked = tk.IntVar()
        checkBtn_zoombies_onKill = tk.Checkbutton(window, text="秒杀僵尸", width=15, height=2, variable=btn2_checked, onvalue=1, offvalue=0, command=zoombie_oneKill)
        checkBtn_zoombies_onKill.grid(row=0, column=1)

        # 植物不死
        btn3_checked = tk.IntVar()
        checkBtn_zoombie_isKill = tk.Checkbutton(window, text="植物不死", width=15, height=2, variable=btn3_checked, onvalue=1, offvalue=0, command=plant_unDie)
        checkBtn_zoombie_isKill.grid(row=1, column=0)

        # 无CD
        btn4_checked = tk.IntVar()
        checkBtn_cdNull = tk.Checkbutton(window, text="不废时间", width=15, height=2, variable=btn4_checked, onvalue=1, offvalue=0, command=cdNull)
        checkBtn_cdNull.grid(row=1, column=1)

        # info
        wc.addLabel("Create by SmileSL", 4, 1)
        wc.addLabel("v1.0 beta", 5, 1)

        tk.mainloop() 
    else:
        print("[Warnning] Game not Running!")
        ex.MessageBox("Game not Running!", "WARNNING")

附件列表:
HackPvz.zip [ex.dll, ex.lib, ex.py]

附件下载

汇编应用-OS程序的学习
快来做第一个评论的人吧~
0:00