This module can read and write to the memory of any process on Windows.

vsantiago113, updated 🕥 2022-06-27 15:24:37

ReadWriteMemory

PyPI - Status PyPI - Format GitHub GitHub release (latest by date) PyPI - Python Version

Description

The ReadWriteMemory Class is made on Python for reading and writing to the memory of any process. This Class does not depend on any extra modules and only uses standard Python libraries like ctypes.


Documentation


Requirements

Python 3.4+
OS: Windows 7, 8 and 10


Windows API’s in this module:

EnumProcesses
GetProcessImageFileName
OpenProcess
Process Security and Access Rights
CloseHandle
GetLastError
ReadProcessMemory
WriteProcessMemory


Usage

Import and instantiate the Class

```python from ReadWriteMemory import ReadWriteMemory

rwm = ReadWriteMemory() ```

Get a Process by name

```python from ReadWriteMemory import ReadWriteMemory

rwm = ReadWriteMemory()

process = rwm.get_process_by_name('ac_client.exe') ```

Get a Process by ID

```python from ReadWriteMemory import ReadWriteMemory

rwm = ReadWriteMemory()

process = rwm.get_process_by_id(1337) ```

Get the list of running processes ID's from the current system

```python from ReadWriteMemory import ReadWriteMemory

rwm = ReadWriteMemory()

processes_ids = rwm.enumerate_processes() ```

Print the Process information

```python from ReadWriteMemory import ReadWriteMemory

rwm = ReadWriteMemory()

process = rwm.get_process_by_name('ac_client.exe') print(process.dict) ```

Print the Process HELP docs

```python from ReadWriteMemory import ReadWriteMemory

rwm = ReadWriteMemory()

process = rwm.get_process_by_name('ac_client.exe') help(process) ```

Exception: ReadWriteMemoryError

````python from ReadWriteMemory import ReadWriteMemory from ReadWriteMemory import ReadWriteMemoryError

rwm = ReadWriteMemory() try: process = rwm.get_process_by_name('ac_client.exe') except ReadWriteMemoryError as error: print(error) ````

Open the Process

To be able to read or write to the process's memory first you need to call the open() method. ```python from ReadWriteMemory import ReadWriteMemory

rwm = ReadWriteMemory()

process = rwm.get_process_by_name('ac_client.exe') process.open() ```

Set the pointers for example: to get health, ammo and grenades

The offsets must be a list in the correct order, if the address does not have any offsets then just pass the address. You need to pass two arguments, first the process address as hex and a list of offsets as hex. ```python from ReadWriteMemory import ReadWriteMemory

rwm = ReadWriteMemory()

process = rwm.get_process_by_name('ac_client.exe') process.open()

health_pointer = process.get_pointer(0x004e4dbc, offsets=[0xf4]) ammo_pointer = process.get_pointer(0x004df73c, offsets=[0x378, 0x14, 0x0]) grenade_pointer = process.get_pointer(0x004df73c, offsets=[0x35c, 0x14, 0x0]) ```

Read the values for the health, ammo and grenades from the Process's memory

```python from ReadWriteMemory import ReadWriteMemory

rwm = ReadWriteMemory()

process = rwm.get_process_by_name('ac_client.exe') process.open()

health_pointer = process.get_pointer(0x004e4dbc, offsets=[0xf4]) ammo_pointer = process.get_pointer(0x004df73c, offsets=[0x378, 0x14, 0x0]) grenade_pointer = process.get_pointer(0x004df73c, offsets=[0x35c, 0x14, 0x0])

health = process.read(health_pointer) ammo = process.read(ammo_pointer) grenade = process.read(grenade_pointer) ```

Print the health, ammo and grenade values

```python from ReadWriteMemory import ReadWriteMemory

rwm = ReadWriteMemory()

process = rwm.get_process_by_name('ac_client.exe') process.open()

health_pointer = process.get_pointer(0x004e4dbc, offsets=[0xf4]) ammo_pointer = process.get_pointer(0x004df73c, offsets=[0x378, 0x14, 0x0]) grenade_pointer = process.get_pointer(0x004df73c, offsets=[0x35c, 0x14, 0x0])

health = process.read(health_pointer) ammo = process.read(ammo_pointer) grenade = process.read(grenade_pointer)

print({'Health': health, 'Ammo': ammo, 'Grenade': grenade}) ```

Write some random values for health, ammo and grenade to the Process's memory

```python from ReadWriteMemory import ReadWriteMemory from random import randint

rwm = ReadWriteMemory()

process = rwm.get_process_by_name('ac_client.exe') process.open()

health_pointer = process.get_pointer(0x004e4dbc, offsets=[0xf4]) ammo_pointer = process.get_pointer(0x004df73c, offsets=[0x378, 0x14, 0x0]) grenade_pointer = process.get_pointer(0x004df73c, offsets=[0x35c, 0x14, 0x0])

process.write(health_pointer, randint(1, 100)) process.write(ammo_pointer, randint(1, 20)) process.write(grenade_pointer, randint(1, 5)) ```

Close the Process's handle when you are done using it.

```python from ReadWriteMemory import ReadWriteMemory

rwm = ReadWriteMemory()

process = rwm.get_process_by_name('ac_client.exe') process.open()

process.close() ```

Examples

Check out the code inside the Test folder on the python file named testing_script.py. The AssaultCube game used for this test is version v1.1.0.4 If you use a different version then you will have to use CheatEngine to find the memory addresses. https://github.com/assaultcube/AC/releases/tag/v1.1.0.4
For more examples check out the AssaultCube game trainer: https://github.com/vsantiago113/ACTrainer ```python from ReadWriteMemory import ReadWriteMemory from random import randint

rwm = ReadWriteMemory() process = rwm.get_process_by_name('ac_client.exe') process.open()

print('\nPrint the Process information.') print(process.dict)

health_pointer = process.get_pointer(0x004e4dbc, offsets=[0xf4]) ammo_pointer = process.get_pointer(0x004df73c, offsets=[0x378, 0x14, 0x0]) grenade_pointer = process.get_pointer(0x004df73c, offsets=[0x35c, 0x14, 0x0]) print(health_pointer)

health = process.read(health_pointer) ammo = process.read(ammo_pointer) grenade = process.read(grenade_pointer)

print('\nPrinting the current values.') print({'Health': health, 'Ammo': ammo, 'Grenade': grenade})

process.write(health_pointer, randint(1, 100)) process.write(ammo_pointer, randint(1, 20)) process.write(grenade_pointer, randint(1, 5))

health = process.read(health_pointer) ammo = process.read(ammo_pointer) grenade = process.read(grenade_pointer)

print('\nPrinting the new modified random values.') print({'Health': health, 'Ammo': ammo, 'Grenade': grenade})

process.close()

```

Issues

My code is as follows. I am attempting to read a pointer location using offsets and than write to them. issue is when process.get_pointer()

opened on 2023-03-05 17:48:19 by evanwheelrr

My code is as follows. I am attempting to read a pointer location using offsets and than write to them. issue is when process.get_pointer() is called. you get the collowing error

ctypes.windll.kernel32.ReadProcessMemory(self.handle, lp_base_address, lp_buffer, ctypes.ArgumentError: argument 2: OverflowError: int too long to convert

`from ReadWriteMemory import ReadWriteMemory

rwm = ReadWriteMemory()

Define the pointer address

7FF7E9c400000

00497DE0

points_pointer_address = 0x19BC7D60160+0x00497DE0

process = rwm.get_process_by_name("PieceByPiece.exe")

process.open()

points_pointer = process.get_pointer(points_pointer_address, offsets=[0xB8, 0x2F8, 0x18, 0x70, 0x20, 0x10, 0x60]) process.write(points_pointer, 500)

while True:

#value = process.read(points_pointer)
#print(value)`

Originally posted by @evanwheelrr in https://github.com/pypi/warehouse/issues/13128

AttributeError: 'Process' object has no attribute 'get_modules'

opened on 2022-08-20 20:06:10 by MeblIkea

Hi, I have the same problem of others people with the get_pointer function who can't find the address because it needs the base address. So I tried base_address = process.get_modules()[0] process.get_pointer(process.get_modules()[0] + address, offsets=offsets) as said @MillhioreBT in issue #12, but I have this error AttributeError: 'Process' object has no attribute 'get_modules'.

I'm it with Python 3.10, and the module version is 0.1.5. Thx!

Add a new and simple method to get the base address

opened on 2022-06-27 15:24:37 by MillhioreBT

After the merged PR #21 We can now obtain the base address of the process very easily: get_modules()[0] but to make it intuitive and easy to understand for everyone it is better to have a method for it: get_base_address()

Process "" not found!

opened on 2021-09-20 15:50:47 by a2py

I found something . if be " "(space) in name of app show this error Example csgo.exe --> ok
Minecraft 1.16.4.exe --> Process "" not found!

Get all memory addresses

opened on 2021-05-16 16:38:04 by toxicrecker

Is there some way i can retrieve all the memory addresses on the process?

Problems Reading string from memory

opened on 2021-03-12 09:47:14 by HyronNotEZ

Hey there, I'm having some problem while trying to read a string from another program. Somehow my output is this:{'name': 'Deezer.exe', 'pid': 1100, 'handle': 456, 'error_code': None} {'Titel': ''}

This is my code ``` from ReadWriteMemory import ReadWriteMemory

rwm = ReadWriteMemory()

process = rwm.get_process_by_name("Deezer.exe") print(process.dict)

process.open()

title_pointer = process.get_pointer(0x04D21E1C, offsets=[0x10C, 0x44, 0x4, 0x30, 0x0])

titel = process.readString(title_pointer, 20)

print({'Titel': titel})

process.close() ```

And this is what i got with CE

image

I hope someone can help me with this.

Releases

v0.1.5 2020-05-18 22:40:49

This is the latest version and it has been updated with some bug fixes.

ReadWriteMemory v0.1.2 2020-04-09 04:45:14

This version has been updated from the one I used on the YouTube Video. This version handles pointers too.

Victor M. Santiago

IT consultant with over ten years of experience in the industry. Skilled in designing and implementing automated solutions for various industries.

GitHub Repository