Compile and protect Python scripts from decompilation
Project description
CodexShield
Compile and protect Python scripts from decompilation — works like Nuitka, protects better.
Install
pip install CodexShield
Or from source:
git clone https://github.com/yourname/CodexShield
cd CodexShield
pip install -e ".[all]"
Dependencies:
| Package | Purpose |
|---|---|
cython |
Compile Python → native machine code |
pyinstaller |
Bundle into standalone EXE |
psutil (optional) |
Process-name anti-debug check |
| UPX (optional binary) | Compress the EXE — upx.github.io |
A C compiler is also required: MSVC on Windows, GCC/Clang on Linux/macOS.
Usage
Command line (like Nuitka)
# Basic — produces dist/myscript.exe
python -m CodexShield myscript.py
# or after pip install:
CodexShield myscript.py
# Custom name + icon, hide console window
CodexShield myscript.py --output-filename=MyApp --icon=app.ico --windows-disable-console
# Output to a specific folder
CodexShield myscript.py --output-dir=build
# Compile to .pyd/.so only (no EXE)
CodexShield myscript.py --module
# Just print obfuscated source (no compile)
CodexShield myscript.py --obfuscate-only
# Directory bundle instead of single file
CodexShield myscript.py --onedir
# Disable specific protection layers
CodexShield myscript.py --no-flatten --no-junk
# Show version
CodexShield --version
Python API
import CodexShield
# Full pipeline — returns path to EXE
exe = CodexShield.compile("myscript.py")
# With options
exe = CodexShield.compile(
"myscript.py",
output_dir="build",
output_filename="MyApp",
windows_disable_console=True,
icon="app.ico",
enable_upx=True,
)
Advanced — use CompileOptions directly
from CodexShield.core.options import CompileOptions
from CodexShield.core.pipeline import Pipeline
opts = CompileOptions(
source="myscript.py",
output_dir="build",
output_filename="MyApp",
onefile=True,
windows_disable_console=True,
rename_symbols=True,
encrypt_strings=True,
flatten_flow=True,
inject_opaques=True,
inject_junk=True,
)
exe = Pipeline(opts).run()
print(f"Built: {exe}")
Add anti-debug to your script
Put this at the very top of myscript.py:
from CodexShield.antidbg import guard
guard() # silently exits if a debugger or RE tool is detected
def main():
print("Hello, protected world!")
Protection layers
| Layer | What it defeats |
|---|---|
| Symbol renaming | All function/class/variable names → random gibberish |
| String encryption | Every string XOR-encrypted with a per-file random key |
| Control flow flattening | Function bodies → while True dispatch loops with random state IDs |
| Opaque predicates | Always-false dead branches injected everywhere |
| Junk code injection | Harmless noise statements scattered throughout |
| Cython native compile | Real .pyd/.so machine code — zero Python bytecode in the binary |
| Symbol stripping | All debug symbols removed |
| UPX compression | Binary packed and compressed |
| Anti-debug runtime | Detects x64dbg, IDA, OllyDbg, GDB, Cheat Engine, Frida, etc. |
How it compares
| PyInstaller | Nuitka | CodexShield | |
|---|---|---|---|
| Python bytecode in EXE | ✅ yes | partial | ❌ none |
pyinstxtractor works |
✅ yes | ❌ no | ❌ no |
uncompyle6 works |
✅ yes | partial | ❌ no |
| Symbol names visible | ✅ yes | ✅ yes | ❌ no |
| Strings visible in binary | ✅ yes | ✅ yes | ❌ no |
| Control flow readable | ✅ yes | partial | ❌ no |
| Anti-debug | ❌ no | ❌ no | ✅ yes |
CLI reference
usage: CodexShield [options] source.py
positional:
source Python source file
output:
--output-dir DIR Output directory (default: dist)
--output-filename NAME Override binary name
build mode:
--standalone Bundle all deps into EXE (default)
--module Compile to .pyd/.so only
--obfuscate-only Print obfuscated source, no compile
exe options:
--onefile Single EXE (default)
--onedir Directory bundle
--windows-disable-console Hide console window
--icon FILE .ico / .icns icon path
--no-upx Disable UPX compression
obfuscation:
--no-rename Disable symbol renaming
--no-encrypt Disable string encryption
--no-flatten Disable control flow flattening
--no-opaques Disable opaque predicates
--no-junk Disable junk code
misc:
--keep-temp Keep intermediate build files
--quiet / -q Suppress output
--version / -V Show version
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
codexshield-1.0.2.tar.gz
(15.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file codexshield-1.0.2.tar.gz.
File metadata
- Download URL: codexshield-1.0.2.tar.gz
- Upload date:
- Size: 15.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
daea22e77c5b6b5bf93c75493276c46ac791ed2830a7bc4332d526a30e63407a
|
|
| MD5 |
1ca95da4dcd9db5dc92d09de9ea7f788
|
|
| BLAKE2b-256 |
55e15bedb2bafe409e65864be54ee4b976346d1ed8e8348c9feb5fdb0e56f5c3
|
File details
Details for the file codexshield-1.0.2-py3-none-any.whl.
File metadata
- Download URL: codexshield-1.0.2-py3-none-any.whl
- Upload date:
- Size: 18.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad896791dca3efd85f4ab3c6173058825fc01e8b120e15d319a05fa180e317bb
|
|
| MD5 |
0921b4c50a33fcf58f5ecb695621c084
|
|
| BLAKE2b-256 |
c6c765e2e0651a4a3eb51d7153aaf79fd241d5791b3863f01a8492aacabe7cea
|