Skip to main content

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.4.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

codexshield-1.0.4-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file codexshield-1.0.4.tar.gz.

File metadata

  • Download URL: codexshield-1.0.4.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for codexshield-1.0.4.tar.gz
Algorithm Hash digest
SHA256 600859973a235801d1de60fd015754b7fe58c858fc985c650182ccfb6165b1cc
MD5 489a4268177e2fa76e93e85d2321dfe7
BLAKE2b-256 7b0b454a906b6ef9ef7a6b797cfb11cf0f007927a4a8af9bde705147ad5cdc94

See more details on using hashes here.

File details

Details for the file codexshield-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: codexshield-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 18.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for codexshield-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8aceacc6bb636cf21c391415f973ab71470f514195eaf9177cc5953d04a38555
MD5 6e58b43f10c0074f1fdbb3d136e8654d
BLAKE2b-256 a975fece5809ceabf2565e1cb7d1d8748ecbde458594e3f0805052d0148f450b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page