Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to modify Game memory by Python

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to modify the game memory in Python. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Installation of games

About this piece of installation. I used to download it on the website, but now I can go to Baidu to download one. I'll use my previous one here.

Link: https://pan.baidu.com/s/1Ydiy1Q9QqKNxoyAkIlzp7Q

Extraction code: 1234

Be sure to avoid clicking on some ads after installation and download, and cancel the lock check of some browsers. Entering the game is full screen, which is not convenient for us to observe the effect and write programs. You can uncheck full screen in the options.

Summary of train of thought in one sentence

My understanding is that the essence of all programs is a collection of variables and values.

For example, the game we play is also a program. Whether the character health and blue bar of the game are all stored in a variable, then if we find the variable that stores this value (which can also be called the address) and modify the value of this variable, then we can do a series of operations to increase the amount of health of our characters and modify the level of characters.

A general idea

First determine which game's data to modify, then determine which game's data to modify, then find the address of the data in the game, and then modify the data.

Sounds a little roundabout. Well, it's my poor Chinese study.

The actual combat determines which game's data can be modified.

Here you need to use a handle to view the tool here I have downloaded for you.

Link: https://pan.baidu.com/s/1ubpe7bmIsojbcX3z_24CxA

Extraction code: 1234

Drag the magnifying glass to the title of the game and you can see all the information in this window.

You can see if the process ID in our task manager is also 39156.

Code import win32process# process module import win32gui# interface # IDwindow_handle of the class name window of the none window (None, "plants vs. Zombies Chinese version") # Pyspy++ window handle win32gui.print (window_handle) process_id = win32process.GetWindowThreadProcessId (window_handle) [1] # fetch process IDprint (process_id) process_handle = win32api.OpenProcess (0x1F0FFF, False Process_id) # process handle # whether the process handle can be inherited by child processes Generally choose false (non-inheritable) # # this is the default security attribute of the thread kernel object. The child process cannot inherit the handle of the parent process, so the child process cannot access the modified kernel object through the handle. Print (process_handle)

About this code I will explain how to determine a game is judged by the process handle, and we manually get the game window ID and class name, we can get the process ID, by the process ID can get the game handle.

Search for an address

The total value of sunshine is 150, and it takes 100 to grow a pea, which is not enough. What we need to achieve now is unlimited sunshine to achieve the effect of unlimited planting peas. CE software is needed here, and I will provide it to you.

Link: https://pan.baidu.com/s/1mkEmVUonDBS6zBjJjYDFSQ

Extraction code: 1234

Video tutorial

Python forever god, actual combat development game memory assistance!

Modify data

Since we are using the programming language Python, we need to use Python to call C and use dynamic link libraries, so we need to configure the kernel module (dynamic link library kernel32.dll). C:\ Windows\ System32\ kernel32.dll is placed in this directory, and I will download it for you here.

Link: https://pan.baidu.com/s/1kAwg7PE_zZP_sqkaluD4QA

Extraction code: 1234

Code import win32api# system module import win32process# process module import win32gui# interface import ctypes# C language call type # python the ctypes module can be directly called in python. The first step is to compile Calgary + into a dynamic library # (.dl or .so), and then call it in python. # C type calling convention # kernel32.WriteProcessMemory (int (process_handle), 0x1C0A4F98 kernel32 byref (c_int (1000)), 4author byref (c_int (0)) kernel32 = ctypes.windll.LoadLibrary (r "C:\ Windows\ System32\ kernel32.dll") # load kernel module dynamic link library date1 = ctypes.c_long () kernel32.ReadProcessMemory (int (process_handle), 0x006A9EC0dctypes.byref (date1), 4 None) # size and length of a data read by None # buffer Text requirements vary from language to language. For compatibility, a custom text # address will change, but the data stored in it will not change. Print (date1.value) date2 = ctypes.c_long () kernel32.ReadProcessMemory (int (process_handle), date1.value+0x768,ctypes.byref (date2), 4PowerNone) print (date2.value) date3 = ctypes.c_long () kernel32.ReadProcessMemory (int (process_handle), date2.value+0x5560,ctypes.byref (date3), 4PowerNone) print (date3.value) sun = input ("Please enter the sunshine value you want to change:") # kernel32.WriteProcessMemory (int (process_handle), date2.value+0x5560 Ctypes.byref (ctypes.c_long (int (sun)), 4MagneNone) kernel32.WriteProcessMemory (int (process_handle), date2.value+0x5560,ctypes.byref (ctypes.c_long (int (sun)), 4MaginNone) # shuts down the process kernel32.CloseHandle (int (process_handle)) effect

Complete source code #! / usr/bin/python3#-*-coding: utf-8-*-# @ Time: 2019-4-30 16 Author import win32api# system module import win32process# process module import win32gui# interface import ctypes# C language call type # python can be directly used in python to call CCompact +. The first step is to compile Calgary + into a dynamic library # (.dl or .so), and then call it in python. # none window IDwindow_handle = win32gui.FindWindow (None, "plants vs. Zombies Chinese version") # Pyspy++ window handle win32gui.print (window_handle) process_id = win32process.GetWindowThreadProcessId (window_handle) [1] # fetch process IDprint (process_id) process_handle = win32api.OpenProcess (0x1F0FFF, False, process_id) # process handle # whether the process handle can be inherited by child processes Generally choose false (non-inheritable) # # this is the default security attribute of the thread kernel object. The child process cannot inherit the handle of the parent process, so the child process cannot access the modified kernel object through the handle. Print (process_handle) # C type calling convention # kernel32.WriteProcessMemory (int (process_handle), 0x1C0A4F98 kernel32 byref (c_int (1000)), 4 kernel32 = ctypes.windll.LoadLibrary (r "C:\ Windows\ System32\ kernel32.dll") # load kernel module dynamic link library date1 = ctypes.c_long () kernel32.ReadProcessMemory (int (process_handle), 0x006A9EC0dctypes.byref (date1), 4 None) # size and length of a data read by None # buffer Text requirements vary from language to language. For compatibility, a custom text # address will change, but the data stored in it will not change. Print (date1.value) date2 = ctypes.c_long () kernel32.ReadProcessMemory (int (process_handle), date1.value+0x768,ctypes.byref (date2), 4PowerNone) print (date2.value) date3 = ctypes.c_long () kernel32.ReadProcessMemory (int (process_handle), date2.value+0x5560,ctypes.byref (date3), 4PowerNone) print (date3.value) sun = input ("Please enter the sunshine value you want to change:") # kernel32.WriteProcessMemory (int (process_handle), date2.value+0x5560 Ctypes.byref (ctypes.c_long (int (sun)), 4Magne) kernel32.WriteProcessMemory (int (process_handle), date2.value+0x5560,ctypes.byref (ctypes.c_long (int (sun), 4Maginone) kernel32.CloseHandle (int (process_handle)) # shuts down the process on "how Python modifies game memory" ends here Hope that the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report