https://github.com/kmaork/hypno
Inject python code into a running python process
https://github.com/kmaork/hypno
injection linux python windows
Last synced: 16 days ago
JSON representation
Inject python code into a running python process
- Host: GitHub
- URL: https://github.com/kmaork/hypno
- Owner: kmaork
- License: mit
- Created: 2020-07-11T20:40:06.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-09-04T19:05:41.000Z (8 months ago)
- Last Synced: 2025-03-31T09:05:51.350Z (24 days ago)
- Topics: injection, linux, python, windows
- Language: Python
- Homepage:
- Size: 50.8 KB
- Stars: 90
- Watchers: 3
- Forks: 13
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-python-re - hypno - A cross-platform tool/library allowing to inject python code into a running python process. Can be installed through `pip`. (Bytecode / Manual analysis)
README
# Hypno
[](https://badge.fury.io/py/hypno)
[](https://pypi.python.org/pypi/hypno/)
[](https://github.com/kmaork/hypno/blob/master/LICENSE.txt)
[](https://github.com/kmaork/hypno)
[](https://discord.gg/P3mN92eM2X)A cross-platform tool/library allowing to inject python code into a running python process.
Based on [kmaork/pyinjector](https://github.com/kmaork/pyinjector).If you are trying to debug a python process, check out [kmaork/madbg](https://github.com/kmaork/madbg).
### Installation
```shell script
pip install hypno
```
Both source distributions, manylinux, musslinux, mac and windows wheels are uploaded to pypi for every release.### Usage
#### CLI
```shell script
hypno
```#### API
```python
from hypno import inject_pyinject_py(pid, python_code)
```#### Example
This example runs a python program that prints its pid, and then attaches to the newly created process and
injects it with another print statement using hypno. Mac users will need to use `sudo` for the second command.
```shell script
python -c "import os, time; print('Hello from', os.getpid()); time.sleep(0.5)" &\
hypno $! "import os; print('Hello again from', os.getpid())"
```### Security
Hypno briefly generates a temporary file containing the requested python code.
This file is given 644 permissions by default, which means all users can read it.
To use custom permissions, you can pass the `permissions` argument to `inject_py()`.