pyrun-injected
Run python files and scripts in python which has been injected into another process.
Why?
The usual way of running python scripts with an injected python dll wasn't able to be run on python 3.12 and above.
It seems that this was because the PyRun_SimpleString command needs to be run in the same thread as the Py_InitializeFromConfig and Py_FinalizeEx calls. Using the windows API it doesn't seem possible to execute multiple commands in the same thread.
pyrun-injected fixes this by calling all the necessary functions in one function so that we can call this function and have everything run in the same thread.
Finally, because we are writing this from scratch, we can add some extra functionality into the API for added flexibility.
To this end pyrun-injected uses PyRun_String and PyRun_File under the hood instead of PyRun_SimpleString and PyRun_SimpleFile so that we may get back any exception which is raised by calling the code, thus giving us better visibility on what went wrong if something did.
c API
pyrun-injected provides 3 functions which are useful for calling:
int pyrun_injected.dll.run_file(const char* filename):
Run the specified file name in the injected process. This will return 0 on success, and 1 on failure.
int pyrun_injected.dll.run_string(const char* string):
Run the specified string in the injected process. This will return 0 on success, and 1 on failure.
int pyrun_injected.dll.run_data(RunData* data):
Run a sequence of strings and/or files sequentially within a single session.
This will return 0 on success, and 1 on failure.
On failure, RunData->error will have the stacktrace written into it. See below for details.
RunData and associated structs are defined as follows:
typedef struct {
char* error_msg; // The actual error message we get from the traceback.
size_t msg_length; // The length of the error message in bytes.
uint32_t bad_string_idx; // The index of the string that had the issue.
} ErrorData;
typedef struct {
const char* string_value;
uint8_t is_file;
} StringData;
typedef struct {
uint32_t count; // Total size of strings field.
StringData* strings; // The actual string data to be run.
ErrorData* error; // Error data (if an error occurs).
} RunData;
We pass in a struct like this rather than having multiple arguments because the Windows API only allows us to pass in one argument.
python API
The python API provides a single class which simplifies injecting and calling strings and files in python.
pyrun_injected.dllinject.pyRunner(pm: pymem.Pymem):
This function takes an instance of a Pymem class as it's only constructor argument. This is because we use pymem a lot internally.
The running python version and pyrun-injected will both be injected into this process.
Once initialised, this class provides just one method for running code:
def run_data(
self,
strings: list[StringType],
run_in_directory: Optional[str] = None,
inject_sys_path: bool = False,
):
where StringType is a NamedTuple defined as such:
class StringType(NamedTuple):
value: str
is_file: bool
This function allows you to pass in a mix of filepaths and strings to be run in the specified order.
It is strongly recommended that filepaths are provided as absolute paths, unless all are in a specifi directory, in which case that path should be passed in to this function as the run_in_directory argument.
Note: It's important that all python code which is to be run which requires any other piece of code be run together. Once the code finalises after running the strings or files any data will not be persisted.
Example usage
import subprocess
import time
from pyrun_injected.dllinject import pyRunner, StringType
import pymem
import os.path as op
cwd = op.dirname(__file__)
notepad = subprocess.Popen(['notepad.exe'])
time.sleep(1)
print(f"Running on pid {notepad.pid}. Press ctrl + C to stop.")
pm = pymem.Pymem("notepad.exe")
injected = pyRunner(pm)
string = """import platform
with open("output.txt", "w") as f:
f.write(f"hello from {platform.python_version()}")
"""
injected.run_data([StringType(string, False)], run_in_directory=cwd)
notepad.kill()
The above will start notepad, and then inject python and run the string in it. You should see the output.txt file be produced in the same directory as the file with the version of python used.
Metadata
Release files for pyrun-injected 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pyrun_injected-0.2.1.tar.gz | 72.7 kB | With provenance | Details |
Built distributions (wheels)
Total release size: 296.8 kB
Release files / pyrun_injected-0.2.1.tar.gz
| Download URL | pyrun_injected-0.2.1.tar.gz |
|---|---|
| Size | 72.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ccde815fd32c736db1031fb7d32ff9bbd07354c6e1d382320d6046e8efadf01f
|
|
BLAKE2b-256 checksum How to use checksums |
fb0075d8674a29dd19975f8d363697e5bc4cfeb617871b0f2ef1f64e511a536a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 29, 2026.
Transparency logRelease files / pyrun_injected-0.2.1-cp314-cp314-win_amd64.whl
| Download URL | pyrun_injected-0.2.1-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 19.3 kB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
88103d3ef15419e1d3fe3129a81ac7c43d0f990c54aef9f695e8a2bef95ef5e2
|
|
BLAKE2b-256 checksum How to use checksums |
8e610ce6d953acb819984612478043078f2a17beeb05fbd6212b5418aeaca3bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 29, 2026.
Transparency logRelease files / pyrun_injected-0.2.1-cp314-cp314-win32.whl
| Download URL | pyrun_injected-0.2.1-cp314-cp314-win32.whl |
|---|---|
| Size | 18.5 kB |
| Tags | CPython 3.14 Windows x86-32 |
|
SHA-256 checksum How to use checksums |
019d542031251d64685d7cc58f99ab538883fe071d17fb02adc9ad19dae15017
|
|
BLAKE2b-256 checksum How to use checksums |
99d9e788b484e2c6875bd9e02da32f467353ef5d6512f221ecd23a928e7c33f3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 29, 2026.
Transparency logRelease files / pyrun_injected-0.2.1-cp313-cp313-win_amd64.whl
| Download URL | pyrun_injected-0.2.1-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 19.0 kB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
16d3af62eb4404fa4cd739c7e23b88d20e9b902eb496d1a045cf6ce77b068d79
|
|
BLAKE2b-256 checksum How to use checksums |
e965704e4ec0d86562400d94b249adf5cf37045dfe8bce710593c0ed9fbf1476
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 29, 2026.
Transparency logRelease files / pyrun_injected-0.2.1-cp313-cp313-win32.whl
| Download URL | pyrun_injected-0.2.1-cp313-cp313-win32.whl |
|---|---|
| Size | 18.2 kB |
| Tags | CPython 3.13 Windows x86-32 |
|
SHA-256 checksum How to use checksums |
84cc72c1b7d8833cc505de15acb146dc626d3889bc6ac57420cbe09e28e9136d
|
|
BLAKE2b-256 checksum How to use checksums |
77279b2a014472ea69e091d1560db0cf33e74578bc3f2fd3321345c6a7e78d8f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 29, 2026.
Transparency logRelease files / pyrun_injected-0.2.1-cp312-cp312-win_amd64.whl
| Download URL | pyrun_injected-0.2.1-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 19.0 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
19bf2677a37d2c9ac625ed9078507541a1c3513257f7943d2c0634e11be8b116
|
|
BLAKE2b-256 checksum How to use checksums |
11df9e2cc1624ae666dd467eba4aab98e7c11370a21b397b81f7793475696acb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 29, 2026.
Transparency logRelease files / pyrun_injected-0.2.1-cp312-cp312-win32.whl
| Download URL | pyrun_injected-0.2.1-cp312-cp312-win32.whl |
|---|---|
| Size | 18.2 kB |
| Tags | CPython 3.12 Windows x86-32 |
|
SHA-256 checksum How to use checksums |
1120d8e703fc2b18712af81968597b1723a86a21f9cd2fd2aceb49666e21ce8f
|
|
BLAKE2b-256 checksum How to use checksums |
4dd49fa3a92170b59e54dfd6a8bcd441e7265ccd7588f43d668f3e1a870f8957
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 29, 2026.
Transparency logRelease files / pyrun_injected-0.2.1-cp311-cp311-win_amd64.whl
| Download URL | pyrun_injected-0.2.1-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 19.0 kB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
060f3bd8651e243a2519ad91c16c02026ed6e5147947599547aa948f1e26d6b8
|
|
BLAKE2b-256 checksum How to use checksums |
543bc570c6d6b55cad7acc0af192e5fea979bad9fc6b7c926049ca7f450ef4b0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 29, 2026.
Transparency logRelease files / pyrun_injected-0.2.1-cp311-cp311-win32.whl
| Download URL | pyrun_injected-0.2.1-cp311-cp311-win32.whl |
|---|---|
| Size | 18.3 kB |
| Tags | CPython 3.11 Windows x86-32 |
|
SHA-256 checksum How to use checksums |
06067784fb5a763d3f95ea5fe21934f73ed0c4c32c46413f7a8614ff45872185
|
|
BLAKE2b-256 checksum How to use checksums |
1771a21731d15c3e19396f6e327fbebb314c8f2335f2a5720036435abe922684
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 29, 2026.
Transparency logRelease files / pyrun_injected-0.2.1-cp310-cp310-win_amd64.whl
| Download URL | pyrun_injected-0.2.1-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 19.0 kB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
6cb213b5ffbf1e7841726a52edb8bfe2b22a570fc0da368e88e784fe9ebb2df5
|
|
BLAKE2b-256 checksum How to use checksums |
0a6b0d8b205dcbd3fa3ab000c2dea61b077a28ada2ecb4ee34cc95e7f813d52b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 29, 2026.
Transparency logRelease files / pyrun_injected-0.2.1-cp310-cp310-win32.whl
| Download URL | pyrun_injected-0.2.1-cp310-cp310-win32.whl |
|---|---|
| Size | 18.3 kB |
| Tags | CPython 3.10 Windows x86-32 |
|
SHA-256 checksum How to use checksums |
ce5f461ecbf9a7eeef7a850bf0afdc8e27db6431a094d4de27312ed377b5ff4a
|
|
BLAKE2b-256 checksum How to use checksums |
123f247cd5ce36ff8e8df0810f9b4edc2b839205c18550c37a9dafe5ee95a345
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 29, 2026.
Transparency logRelease files / pyrun_injected-0.2.1-cp39-cp39-win_amd64.whl
| Download URL | pyrun_injected-0.2.1-cp39-cp39-win_amd64.whl |
|---|---|
| Size | 19.0 kB |
| Tags | CPython 3.9 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
f6bfce64268dc2210603e31de1a4bab29bbe26ce187bbddd14c4e55ca03d3d39
|
|
BLAKE2b-256 checksum How to use checksums |
f66ede26de2d776f707cab5538df125b869c9f69e3049616ed80b3f41d0d67cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 29, 2026.
Transparency logRelease files / pyrun_injected-0.2.1-cp39-cp39-win32.whl
| Download URL | pyrun_injected-0.2.1-cp39-cp39-win32.whl |
|---|---|
| Size | 18.3 kB |
| Tags | CPython 3.9 Windows x86-32 |
|
SHA-256 checksum How to use checksums |
3d77c0acafe536d8fe4f737129835d2f26eff79551d46ca1c351cb98c6d4cd6a
|
|
BLAKE2b-256 checksum How to use checksums |
2877d2a54581e6095ac84aea2c6f25d2c569d4e61d28c2a925f84c566d1c2a99
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 29, 2026.
Transparency logSecurity for pyrun-injected 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 13 files in this release have been uploaded with provenance metadata.
Attestation for pyrun_injected-0.2.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 29, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.