Skip to main content

A Python library to edit and track memory of Windows and Linux processes (32 bits and 64 bits).

Project description

PyMemoryEditor

A Python library developed with ctypes to manipulate Windows and Linux processes (32 bits and 64 bits),
reading and writing values in the process memory.

Python Package Pypi License Platforms Python Version Downloads

Installing PyMemoryEditor:

pip3 install PyMemoryEditor

Basic Usage:

Import PyMemoryEditor and open a process using the OpenProcess class, passing a window title, process name
or PID as an argument. You can use the context manager to do this.

from PyMemoryEditor import OpenProcess

with OpenProcess(process_name = "example.exe") as process:
    # Do something...

After that, use the methods read_process_memory and write_process_memory to manipulate the process
memory, passing in the function call the memory address, data type and its size. See the example below:

from PyMemoryEditor import OpenProcess

title = "Window title of an example program"
address = 0x0005000C

with OpenProcess(window_title = title) as process:

    # Getting value from the process memory.
    value = process.read_process_memory(address, int, 4)

    # Writing to the process memory.
    process.write_process_memory(address, int, 4, value + 7)

Getting memory addresses by a target value:

You can look up a value in memory and get the address of all matches, like this:

for address in process.search_by_value(int, 4, target_value):
    print("Found address:", address)

Choosing the comparison method used for scanning:

There are many options to scan the memory. Check all available options in ScanTypesEnum.

The default option is EXACT_VALUE, but you can change it at scan_type parameter:

for address in process.search_by_value(int, 4, target_value, scan_type = ScanTypesEnum.BIGGER_THAN):
    print("Found address:", address)

Note: The scan types EXACT_VALUE and NOT_EXACT_VALUE uses KMP (Knuth–Morris–Pratt) Algorithm, that has completixy O(n + m) — n is the size of the memory page and m is the value length — to speed up the search process. The other scan types use the brute force algorithm, which is O(n * m), so the search may be slower depending on the length of the target value.

You can also search for a value within a range:

for address in process.search_by_value_between(int, 4, min_value, max_value, ...):
    print("Found address:", address)

All methods described above work even for strings, including the method search_by_value_between — however, bytes comparison may work differently than str comparison, depending on the byteorder of your system.

Progress information on searching:

These methods has the progress_information parameter that returns a dictionary containing the search progress information.

for address, info process.search_by_value(..., progress_information = True):
    template = "Address: 0x{:<10X} | Progress: {:.1f}%"
    progress = info["progress"] * 100
    
    print(template.format(address, progress))

Getting memory regions:

Use the method get_memory_regions() to get the base address, size and more information of all memory regions used by the process.

for memory_region in process.get_memory_regions():
    base_address = memory_region["address"]
    size = memory_region["size"]
    information = memory_region["struct"]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymemoryeditor-1.5.6.tar.gz (28.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pymemoryeditor-1.5.6-py3-none-any.whl (28.7 kB view details)

Uploaded Python 3

File details

Details for the file pymemoryeditor-1.5.6.tar.gz.

File metadata

  • Download URL: pymemoryeditor-1.5.6.tar.gz
  • Upload date:
  • Size: 28.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for pymemoryeditor-1.5.6.tar.gz
Algorithm Hash digest
SHA256 033f2b3eaa1c4822993d7cb89e9384198580c0b9a106d5b37fa378731a771bcd
MD5 b074e78de78ae16a3d86a73e8a09364e
BLAKE2b-256 d6507d3bceafc179d2e903a331c9ad8880846f4c36ab9439c9c2aeb9c7a51907

See more details on using hashes here.

File details

Details for the file pymemoryeditor-1.5.6-py3-none-any.whl.

File metadata

  • Download URL: pymemoryeditor-1.5.6-py3-none-any.whl
  • Upload date:
  • Size: 28.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for pymemoryeditor-1.5.6-py3-none-any.whl
Algorithm Hash digest
SHA256 b2f7cada3ddae11435eabb187e5970f5a104e48868e04a2d9326e252e032c2a7
MD5 209ad08e76721c123e7f6a44a4522988
BLAKE2b-256 ae29dba3dce1c2dc89a1d029a1071f8cc18a1ddb13fe2f33e70cdfec1df30335

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page