Metadata-Version: 2.1
Name: memhax
Version: 0.0.1
Summary: A Python library for getting access to raw memory and internals
Home-page: UNKNOWN
License: UNKNOWN
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python :: 3.9
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.9,<3.10
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

num_obj = PyLongObject(id(1234))
print(num_obj.struct_str())

# struct PyLongObject {
#     Py_ssize_t      ob_refcnt;
#     PyTypeObject*   ob_type;
#     Py_ssize_t      ob_size;
#     unsigned int[1] 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] = id(new_item)
print(my_tuple)  # => ([(...), b'123'], 'abc', 3.5)
```


