
Python-Bytecode (.pyc/.pyo) dekompilieren und disassemblieren, um lesbaren Quellcode zurückzugewinnen. Unterstützt Python 2.0 - 3.15 (CPython, PyPy und andere Implementierungen). Geschrieben in Rust.
Englisch | 简体中文
Dekompiliere und disassembliere Python-Bytecode (.pyc) von Python 2.0 bis 3.15 zurück in lesbaren Quellcode — geschrieben in Rust, zur Laufzeit kein Python erforderlich, mit einem optionalen prozessinternen Durchlauf durch den cure-Simplifier.
pycdc program.pyc # decompile to stdout
pycdc dis program.pyc # disassemble (exception tables, line numbers, nested code)
--cure: leitet die Ausgabe prozessintern durch den cure-Simplifier/Formatter — keine externe Binärdatei, kein Python — und wandelt if cond: return a / return b in return a if cond else b um und kürzt etwa 10 % der Zeilen--opcodesHomebrew (macOS & Linux):
brew install ejfkdev/tap/pycdc
Scoop (Windows):
scoop install https://raw.githubusercontent.com/ejfkdev/scoop-bucket/main/bucket/pycdc.json
Das Manifest wählt automatisch x64 oder arm64 aus und installiert sowohl pycdc
als auch pycdas. Um stattdessen nach Namen zu installieren, fügen Sie den Bucket einmalig hinzu:
scoop bucket add ejfkdev https://github.com/ejfkdev/scoop-bucket
scoop install pycdc
cargo, von crates.io:
cargo install pycdc
Vorkompilierte Binärdateien: rohe ausführbare Dateien (ohne Archiv-Wrapper) auf der Releases-Seite — Linux / Windows x86_64 + arm64, macOS arm64 + x86_64; Linux- und Windows- Builds sind UPX-komprimiert, macOS wird unkomprimiert ausgeliefert.
Aus dem Quellcode:
cargo build --release # -> target/release/pycdc + pycdas
cargo install --path . # or install both binaries from a checkout
Jede Methode bietet sowohl pycdc als auch pycdas.
# single file -> stdout, a file, or a directory
pycdc program.pyc > program.py
pycdc program.pyc -o program.py
pycdc program.pyc -o ./outdir/
# stdin (pipelines): - reads the pyc from stdin
cat program.pyc | pycdc -
# batch: mirror a directory tree (parallel by default, -j N to control,
# -q suppresses the per-file src -> dst lines)
pycdc ./pyc-corpus -o ./src-out
pycdc ./pyc-corpus # -> ./pyc-corpus-decompiled/
pycdc a.pyc b.pyc # -> a.py, b.py next to the inputs
pycdc ./pyc-corpus -o ./src-out -q -j 8
# raw marshal (no pyc header) with an explicit version
pycdc -v 3.8 payload.marshal
# disassembly — same CLI surface (files, dirs, stdin, -o/-j/-q)
pycdc dis program.pyc
pycdc dis ./pyc-corpus -o ./dis-out # -> mirrored .dis files
# the standalone `pycdas` binary is kept as a compatibility alias
# with byte-identical output
pycdas program.pyc
# optional simplification/formatting pass (cure, linked in-process)
pycdc --cure program.pyc
--cure ist optional und rein kosmetisch: pycdc's Ausgabe ist bereits
verifiziert, daher bleibt der Standard unverändert. Damit werden Bedingungen zu
Ternären zusammengefasst, Anführungszeichen auf einfache Anführungszeichen
normalisiert und die Formatierung neu umgebrochen:
# default # --cure
def classify(v): def classify(v):
if v is True: return 1 if v is True else 0
return 1
return 0
Wenn die Eingabe von cure nicht geparst werden kann oder wenn sie Compiler-Introspektionsmetadaten (__annotate__, co_freevars, __conditional_annotations__, __classdict__) enthält, bei denen eine Vereinfachung das Laufzeitverhalten ändern könnte, wird die Datei unverändert ausgegeben und ein Hinweis an stderr gesendet. Die Verhaltensmatrix besteht 754/754 sowohl mit als auch ohne --cure, und alle 528 Corpus-Module kompilieren damit weiterhin unter ihrem eigenen Interpreter. Da der Pass bewusst Anweisungsformen umschreibt (if/else → Ternär), ist die Bytecode-Signatur-Metrik des Corpus für die --cure-Ausgabe nicht aussagekräftig; beurteilen Sie sie anhand der Verhaltensmatrix.
pycdc --help, pycdc dis --help und pycdas --help dokumentieren jedes Flag. Exit-Codes: 0 Erfolg, 1 eine Datei konnte nicht verarbeitet werden, 2 Nutzungsfehler.
Apple Silicon, 526 echte .pyc-Dateien (~9,5 MB, Python 2.6–3.14 stdlib):
| Szenario | Zeit | Spitzen-RSS |
|---|---|---|
| Batch, parallel (Standard) | ≈0,05 s | ≈25 MB |
Batch, seriell (-j 1) | ≈0,34 s | ≈13 MB |
| Größte einzelne Datei (74 KB, inkl. Start) | ≈5,5 ms | ≈4,4 MB |
| Prozessstart | ≈2 ms | — |
tools/fetch_realworld.sh führt einen Sparse-Checkout eines Verzeichnisses aus jedem der sieben Projekte zu seinem neuesten Release-Tag durch, kompiliert jede .py zu .pyc (compileall -b) und legt den Baum in tests/realworld/ ab (git-ignoriert — das Skript ist der Weg, ihn neu zu erstellen):
| Projekt (Tag) | Module | seriell -j 1 | parallel (Standard) | Rekompilierungen | AST-identisch¹ |
|---|---|---|---|---|---|
| yt-dlp (2026.08.19) | 1045 | 0,38 s | 0,08 s | 1045/1045 | 502/1045 |
| matplotlib (v3.11.2) | 253 | 0,28 s | 0,07 s | 253/253 | 60/253 |
| pandas (v3.0.5) | 1420 | 0,87 s | 0,16 s | 1420/1420 | 586/1420 |
| django (6.1.1) | 907 | 0,33 s | 0,12 s | 907/907 | 470/907 |
| sympy (1.14.0) | 1532 | 3,08 s | 1,62 s | 1532/1532 | 482/1532 |
| scikit-learn (1.9.1) | 671 | 0,42 s | 0,07 s | 671/671 | 216/671 |
| ansible (v2.21.4) | 583 | 0,24 s | 0,05 s | 583/583 | 186/583 |
| gesamt | 6411 | 5,60 s | 2,17 s | 6411/6411 (100 %) | 2502/6411 |
¹ strikt: um Docstrings bereinigter AST gleich dem Originalquelltext — äquivalente Normalisierungen (ein if/else statt eines Ternärs, ein redundantes *()/**{} um ein Unpacking, umsortierte Schlüsselwortargumente) zählen als Unterschiede, daher ist dies als Untergrenze der Formtreue zu betrachten, nicht als Fehlerrate. Die Spalte Parse/Rekompilierung ist die Akzeptanzhürde.