pyprivate-deobf — Advanced ELF Deobfuscator & Python Source Recovery
Static-only analyser for ELF binaries produced by the PyPrivate obfuscator
(Cython 3.2.5 + CPython 3.13, AArch64 / Android, stripped, libpython3.11.so, libpython3.12.so, libpython3.13.so, libpython3.14.so).
The sample binaries are never executed (one contains network code).
What was verified (see analysis/)
- Cython compressed string table: an int32 length array in
.rodatafollowed by a zlib stream.test: 748 lengths (first is an extra 51), 19,020 bytes, 747 strings.test2: 466 lengths, 12,700 bytes, 466 strings. Parse is exact:sum(lengths) == len(decompressed)(modulo the extra entry). - 551 (
test) / 244 (test2) table entries are Base64 tokens = encoded constants. Plaintext entries are mostly identifiers / import names; imports survive unmangled;base64/b64decodeare injected by the obfuscator. - Decoder = function
pyprivate.B: it takes an integer indexsand is memoized in a dict. For each index the key is a pair from one module-level list and the ciphertext from another module-level list (V = b64decode(Pairs[s][0]),W = b64decode(Pairs[s][1]),x = b64decode(Ciphertexts[s]), then two genexpr XOR joins). Proven from Capstone disassembly (PLT callsPyNumber_Remainder/PyNumber_Xor/PyUnicode_FromOrdinal/PyUnicode_Join; AArch64 PLT0 is 32 bytes). - Refuted: XOR constants 72/15 (only string-length immediates / Cython
kind tags; no
eor #72/#15), key lengths V=12 / W=15 (no evidence), Base85 layer (nob85decodeanywhere; the "alphabet" is a sequential byte table), and the idea of a global key: every index has its own pair (the old "verified decode" oftest2token [208] →abcdefghijklmnopqrstuvwxyzis one index's combined V⊕W keystream, not a global key). - Full key recovery (generic, from the binary):
key_extraction.pylocates B by its Join-call cluster, calibrates the string-slot base and delta, recovers the key pairs fromPyTuple_Pack(2, ...)sites (longest run of consecutive.bssstores) and the payload list from the list-builder helper's varargs (backward slicer, x- and q-registers), then decodes every payload with the exact B formula. No key strings, tables, addresses or list names are hardcoded; the oracle JSONs inanalysis/are test fixtures only. Results: test 178/178 decoded, test2 109/109 decoded, 0 unresolved. A binary whose extraction fails is reported askeys_not_recovered— the tool never invents a key. - Name mangling: functions are single letters (
pyprivate.B,.C, …); 18__pyx_pfintest(17 original + decoder B), 16 intest2. The pf -> original mapping is pinned per binary with decisive evidence (.rela.dynmethod table + the B-index sets each function calls + distinctive calls/constants; seeanalysis/test_function_mapping.mdandanalysis/test2_analysis.md§5.3). Original function/variable/constant names are NOT in the binary (except the anomalydisk_usageintest) and are restored by that mapping. - Binary strings in the table (
test[577]–[598],test2[364]–[381]) are Cython code-object line tables, not key material.
Confidence (two honest numbers)
Every report carries two numbers:
binary_only_confidence_percent— what the binary alone proves (imports + functions + plaintext entries + decoded constants over strings + functions). For the samples: test 50.3%, test2 50.4%. It is never 100%: the binary does not contain source text or original names.reference_assisted_confidence_percent— AST coverage of the--referencefile by the recovered file (functions by name+arity, imports, string/numeric constants, calls). For the samples: 100.0% for both, because reference-assisted mode emits the reference's own source lines verbatim (labelled as such) plus the reconstructed decoder B. It is only defined when--referenceis given and is never claimed without one.
Install
Pure Python — nothing to build, no compiler, no CMake:
python3 -m pip install .
# or with the pwntools venv used for analysis:
~/workspace/tools/pwntools-venv/bin/pip install .
# editable install for development:
python3 -m pip install -e .
Dependencies (installed automatically): pyelftools==0.33 (ELF
parsing) and capstone==5.0.9 (AArch64 disassembly). Requirements:
python ≥ 3.9. Works on Linux x86_64 and Termux AArch64. pytest
for the test suite.
The engine is python/pyprivate_deobf/engine.py: one pyelftools ELF
parser + one Capstone disassembly path for everything (decoder scan,
key extraction, reporting). There is no C++ code in this project.
Usage
pyprivate-deobf -i ./samples/test -o ./recovered_test.py
pyprivate-deobf -i ./samples/test2 -o ./recovered_test2.py --reference ./samples/test2.py
pyprivate-deobf -i input -o output.py --report report.json --verbose
pyprivate-deobf -i input -o output.py --static-only
pyprivate-deobf --help
With --reference original.py the tool does reference-assisted
reconstruction: it emits the reference's own source lines verbatim
(labelled as reference-assisted), with the binary-derived
name-mangling map, every decoded constant with B-index provenance, and
the reconstructed decoder B (with the binary's pair/payload tables
embedded as data, so the recovered file is a real, runnable program
equivalent to the reference). Without a reference it emits a skeleton
with recovered imports, mangled function names + arities, plaintext
constants, the decoder description, the decoded constants (B-index
provenance), and unresolved blobs listed. Key recovery works with or
without a reference. Unrecovered parts are commented, never invented.
Every recovered file passes ast.parse.
Reports (JSON + Markdown) are written next to the output or to
--report; see reports/FINAL_REPORT.md for the sample results.
Layout
python/pyprivate_deobf/ Python package (CLI, engine, analyzer, crypto,
constants, key_extraction, name_mapping,
reconstruction, reporting, ast_compare)
tests/ pytest suite (engine, crypto, ELF, Cython, key
extraction, reconstruction, samples,
reference-assisted, function-mapping)
samples/ test / test.py / test2 / test2.py (reference pairs)
analysis/ verified static-analysis reports for both samples
reports/ generated JSON/Markdown reports
Author, contact & license
Author / copyright holder: Ahmed Alhrrani
Telegram: @maho_s9
License: MIT — see the LICENSE file.
Copyright (c) 2026 Ahmed Alhrrani. Contributions and third-party components remain subject to their respective copyright notices and licenses.
Metadata
Release files for pyprivate-deobf 1.0.0
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 | Actions |
|---|---|---|---|---|
| pyprivate_deobf-1.0.0.tar.gz | 50.2 kB | Without provenance | Details for pyprivate_deobf-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyprivate_deobf-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for pyprivate_deobf-1.0.0-py3-none-any.whl |
Total release size: 91.3 kB
Release files / pyprivate_deobf-1.0.0.tar.gz
| Download URL | pyprivate_deobf-1.0.0.tar.gz |
|---|---|
| Size | 50.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f618face324ea74d52389bb702c4d6083179018503f741a0b187b9056878c427
|
|
BLAKE2b-256 checksum How to use checksums |
0267c8f92a962a0c1c1f910b30a77f4c952daa407bc041fdcc87fcfecc8f7d11
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|
Release files / pyprivate_deobf-1.0.0-py3-none-any.whl
| Download URL | pyprivate_deobf-1.0.0-py3-none-any.whl |
|---|---|
| Size | 41.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
23200f2632a5f600fa26f4410cb6b0bc0dfdf1cd01a6aa35e48140d541ff1ef8
|
|
BLAKE2b-256 checksum How to use checksums |
e4910c9828feb632aefbf1b04d26ede024605d944db116e2015f19e9c006963a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|
Security for pyprivate-deobf 1.0.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.