Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/magniff/hacky
Low level CPython tinkering utils.
https://github.com/magniff/hacky
cpython hack
Last synced: 14 days ago
JSON representation
Low level CPython tinkering utils.
- Host: GitHub
- URL: https://github.com/magniff/hacky
- Owner: magniff
- Created: 2016-04-02T18:05:34.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2021-09-19T11:19:23.000Z (about 3 years ago)
- Last Synced: 2024-08-09T06:53:24.790Z (3 months ago)
- Topics: cpython, hack
- Language: C
- Homepage:
- Size: 8.79 KB
- Stars: 18
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# HACKY
Python hacking suite.## INSTALLATION
Tested on CPython 3.4
```bash
python setup.py install (preferred)
```
or
```bash
pip install hacky
```## EXAMPLES
* Class transplantation:
```python
>>> import hacky
>>> hacky.set_class(100, type('MyInt', (int,), {'__repr__': lambda self: "hello from hacky"}))
hello from hacky
>>> 100
hello from hacky
>>>
```* Messing around with tp_flags:
```python
>>> from types import FunctionType
>>> import hacky
>>> hacky.set_flags(
FunctionType,
hacky.get_flags(FunctionType) | (1 << 10)
)# you can now subclass function type
>>> class T(FunctionType): pass
>>>
```* Make your class final:
```python
>>> hacky.set_flags(int, hacky.get_flags(int) ^ (1 << 10))>>> class T(int): pass
TypeError: type 'int' is not an acceptable base type
```* Read process's memory. Lets examine memory around `int` object `100`.
```python
>>> [hacky.read_memory_in(id(100)+shift) for shift in range(20)]
[7, 0, 0, 0, 0, 0, 0, 0, 192, 228, 158, 0, 0, 0, 0, 0, 1, 0, 0, 0]
>>> import struct
>>> [int(item) for item in struct.pack('>> hacky.write_memory_in(id(100)+24, 200)
>>> 100
200
```* Inject attr at type`s dictionary
```python
>>> object_dict = hacky.fetch_dict(object)
>>> object_dict["foo"] = "hello world"
>>> (100).foo
'hello world'
>>> "hello world".foo
'hello world'
>>> (lambda x: x).foo
'hello world'
```* More stuff soon.