Metadata-Version: 2.1
Name: memhax
Version: 0.1.0
Summary: A Python library for getting access to raw memory and internals
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Operating System :: Unix
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Typing :: Typed
Requires-Python: >=3.11,<3.12
Description-Content-Type: text/markdown
License-File: LICENSE

# Memhax

A python library for accessing raw python objects and other regions in memory.

## Installation

```bash
$ pip install memhax
```

## Usage

### Read/Write raw memory
```python
from memhax.constants import memory

# Read 4 bytes from address 0x12345678
with memory(0x12345678) as mem:
    data = mem.read(4)
```

### Dump an object's struct
```python
from memhax.cpython.primitives import PyLongObject

print(PyLongObject)

# struct PyLongObject {
#     Py_ssize_t    ob_refcnt;
#     PyTypeObject* ob_type;
#     Py_ssize_t    ob_size;
#     uint32_t[]    ob_digit;
# }
```


### Read/modify python objects
```python
from memhax.cpython.collections import PyTupleObject

my_tuple = (1, "abc", 3.5)
tuple_obj = PyTupleObject(id(my_tuple))

# Get the tuple's length
print(tuple_obj.ob_size())  # => 3

# Replace an item in the tuple
new_item = [my_tuple, b"123"]
tuple_obj.ob_item[0].raw(id(new_item))
print(my_tuple)  # => ([(...), b'123'], 'abc', 3.5)
```
