Strong best-effort Python .pyc, marshal, and source analyzer/decompiler.
py-cdec is a Python tool designed to analyze and decompile Python bytecode (.pyc) files and marshal payloads into readable Python-like source code.
It uses heuristic-based reconstruction techniques to recover structure, functions, and readable output from compiled Python artifacts.
This tool is useful for:
- Reverse engineering Python bytecode
- Learning how Python compilers structure code
- Inspecting unknown
.pycfiles - Debugging compiled Python modules
- Educational analysis of Python internals
- Automatic detection of
.pyand.pycfiles - Bytecode disassembly support
- Marshal payload extraction and inspection
- Heuristic-based source reconstruction
- Recursive code object analysis
- CLI interface for quick usage
- Lightweight and dependency-free design
Install via pip:
pip install py-cdecOr install locally:
git clone https://github.com/Gisnsl/py-cdec.git
cd py-cdec
pip install .You can use py-cdec directly inside your Python code.
from pathlib import Path
from py_cdec import PycDecompiler
# Automatically handles both .pyc and .py files
pyc_path = Path("myfile.pyc") # or myfile.py
decompiler = PycDecompiler(pyc_path)
# Print the decompiled source code directly
print(decompiler)Run directly from terminal:
py-cdec sample.pycTo view Python bytecode instructions:
py-cdec sample.pyc --show-dispy-cdec internally performs several steps:
-
File Detection
- Detects whether the input is
.pyor.pyc
- Detects whether the input is
-
Header Parsing
- Reads Python bytecode headers safely depending on version
-
Marshal Loading
- Extracts compiled code objects using Python's marshal module
-
Disassembly
- Converts bytecode into readable instructions
-
Reconstruction
- Attempts to rebuild Python-like source using heuristics
-
Output Formatting
- Produces readable structured output
The main goal of py-cdec is not perfect decompilation, but:
- Producing readable reconstructed code
- Helping developers understand compiled Python internals
- Providing a safe inspection tool for bytecode analysis
âڑ ï¸ڈ WARNING:
Never execute unknown .pyc or marshal payloads directly.
They may contain malicious code even if they appear safe.
Always inspect before execution.
Developer: @maho_s9
MIT License