Skip to main content

pyptrs

This library provides real pointers (as in languages like C) and some memory access utilites.

Installation

pip install pyptrs

Creating A Pointer

You should never create pointers directly. Instead, use the functions below:

pyptrs.pointer_to_object(obj, c_object = False)

Return a pointer to obj. c_object specifies whether to treat the obj as a python object or a C object. If c_object is True, obj must be an instance of a ctypes C data type. You can learn more information about these data types from here, here and here

pyptrs.pointer_to_address(address, ctype = None)

Return a pointer that points to the given address. If ctype is None, a python object is assumed to be living in that address. Otherwise, ctype must be the ctypes C data type corresponding to the type of the object living in address. You can learn more information about these data types from here, here and here

Pointer Objects

Pointer.get_size()

Return the number of bytes occupied by the pointed object in memory.

Pointer.get_mem()

Return a bytes object representing the pointed object.

Pointer.temp_value(value, force_write = False)

Return a context manager that dereferences and assigns value to the pointed object at __enter__ and reverts this assignment at __exit__. If size of value is bigger than the pointed object, a MemoryError will be raised. In order to prevent this, pass True to force_write.

Simulated Operators

pyptrs.dereference(pointer, *value, force_write = False)

If value is not given, it just dereferences the pointer. If value is given, it must be a single argument and it dereferences the pointed object and assigns value to it then returns a backup_id that can be passed to pyptrs.mem_restore(). If size of value is bigger than the pointed object, a MemoryError will be raised. In order to prevent this, pass True to force_write. Type of value can be anything if the pointed object is a python object. If the type of the pointed object is a C type, type of value must be the corresponding ctypes C data type.

pyptrs.address_of(obj, c_object = False)

Return address of the obj. If c_object is True type of obj must be a ctypes C data type. You can learn more information about these data types from here, here and here. If c_object is True, address of the actual C object is returned, not the address of its ctypes wrapper.

Utils

pyptrs.mem_read(address, amount = 1)

Read amount bytes starting from address and return them as a bytes object.

pyptrs.mem_write(address, data = b"")

Write the bytes represented by data to address and return a backup_id that can be passed to pyptrs.mem_restore().

pyptrs.mem_restore(backup_id)

Revert the changes done to memory by the function that returned backup_id.

pyptrs.mem_restore_last()

Revert the last change done to memory either by pyptrs.dereference() or pyptrs.mem_write().

Metadata

Release files for pyptrs 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyptrs 1.0.3
File Size Uploaded
pyptrs-1.0.3.tar.gz 5.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyptrs 1.0.3
File Interpreter ABI Platform
pyptrs-1.0.3-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 10.0 kB

Release files / pyptrs-1.0.3.tar.gz

Download URL pyptrs-1.0.3.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f119c919dae36f187c58698c8c5896861046453456175d1118be1f79d36e4fa9
BLAKE2b-256 checksum
How to use checksums
1c8a2b23373a4f784f5510673e5d2c5c41c3bb32a666cd640d87ab0731cbe851
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.0

Release files / pyptrs-1.0.3-py2.py3-none-any.whl

Download URL pyptrs-1.0.3-py2.py3-none-any.whl
Size 4.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
d0714857b5f0194b543d7324254bbdab0bf1f69c5d1cea829e0db0ee5daa7937
BLAKE2b-256 checksum
How to use checksums
52855b008a174888f3957ad3f2e74522862c8205f094582d9a2bcd169058e6de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.0
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page