Skip to main content

Advanced Odoo Protect Python code obfuscator with machine ID binding

Project description

odooprotect

OdooProtect - Advanced Python Code Obfuscator

OdooProtect Logo Python License Buy Me A Coffee

OdooProtect is a comprehensive Python code obfuscation tool with machine ID binding, designed to protect your Python applications from reverse engineering and unauthorized distribution.

๐Ÿš€ Features

Core Obfuscation

  • Variable Name Obfuscation: Transforms readable variable names into obfuscated identifiers
  • String Encryption: Encrypts string literals using base64 encoding
  • AST Transformation: Advanced Abstract Syntax Tree manipulation
  • Import Protection: Secures import statements and module loading

Machine Binding & Licensing

  • Hardware Fingerprinting: Generates unique machine identifiers based on CPU, MAC address, and disk serial
  • License Key Generation: Creates signed license keys with expiration dates
  • Runtime Verification: Validates licenses on every code execution
  • Tamper Detection: Detects attempts to modify or bypass protection

Project Protection

  • Directory Processing: Obfuscates entire Python projects recursively
  • Package Structure Preservation: Maintains original project structure
  • Unified Licensing: Single license file for entire projects
  • Cross-Platform: Works on Linux, Windows, and macOS

Command Line Interface

  • Standalone Executable: Run with odooprotect command after installation
  • Professional CLI: Standard flag-based interface (-i, -o, -m, -c)
  • Easy Installation: One-command setup with ./install.sh
  • System Integration: Available globally after installation

๐Ÿ“‹ Table of Contents

๐Ÿ› ๏ธ Installation

Choose one of the installation methods below based on your needs.

๐Ÿ“‹ Prerequisites

  • Python 3.6 or higher (3.9+ recommended for best performance)
  • pip package manager
  • Git (for cloning the repository)
  • sudo/admin privileges (for system-wide installation)

๐Ÿš€ Quick Install (Recommended)

One-Command Installation

# Clone and install OdooProtect with standalone command
git clone https://github.com/dynaz/OdooProtect.git
cd OdooProtect
./install.sh

Verify Installation

odooprotect --help
# Should display: OdooProtect - Python Obfuscator with Machine ID Binding

๐Ÿ“ฆ Manual Installation

Step 1: Download

# Clone the repository
git clone https://github.com/dynaz/OdooProtect.git
cd OdooProtect

Step 2: Make Executable

# Make the script executable
chmod +x odooprotect.py

Step 3: System Integration (Optional)

# Create global symlink (requires sudo)
sudo ln -sf "$(pwd)/odooprotect.py" /usr/local/bin/odooprotect

# Or add to your PATH
export PATH="$PATH:$(pwd)"

Step 4: Verify

# Test direct execution
./odooprotect.py --help

# Test global command (if symlink created)
odooprotect --help

๐Ÿณ Docker Installation

Build Docker Image

git clone https://github.com/dynaz/OdooProtect.git
cd OdooProtect

# Build the image
docker build -t odooprotect .

# Run OdooProtect in container
docker run -v $(pwd):/workspace odooprotect --help

Use Pre-built Image

# Pull and run
docker run -it dynaz/odooprotect --help

๐Ÿงช Development Installation

For Contributors

# Clone repository
git clone https://github.com/dynaz/OdooProtect.git
cd OdooProtect

# Set up virtual environment
python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install development dependencies
pip install -r requirements-dev.txt

# Run tests
python -m pytest tests/

# Make executable
chmod +x odooprotect.py

๐Ÿ”ง Advanced Installation

Custom Installation Path

# Install to custom location
PYPROTECT_HOME="$HOME/.local/odooprotect"
mkdir -p "$PYPROTECT_HOME"
cp -r OdooProtect/* "$PYPROTECT_HOME/"
chmod +x "$PYPROTECT_HOME/odooprotect.py"

# Add to PATH in your shell profile
echo "export PATH=\"\$PATH:$PYPROTECT_HOME\"" >> ~/.bashrc
source ~/.bashrc

Portable Installation (USB/External Drive)

# Copy to external drive
EXTERNAL_DRIVE="/mnt/external"
cp -r OdooProtect "$EXTERNAL_DRIVE/"
cd "$EXTERNAL_DRIVE/OdooProtect"

# Run directly
python3 odooprotect.py --help

โœ… Post-Installation

Test Your Installation

# Basic functionality test
odooprotect -m  # Should show your machine ID

# Obfuscation test
odooprotect -i examples/demo.py  # Should create /dist/demo.py

# License check test
odooprotect -c  # Should scan for license files

Troubleshooting Installation

# If odooprotect command not found
which odooprotect  # Check if in PATH
ls -la /usr/local/bin/odooprotect  # Check symlink

# Test direct execution
./odooprotect.py --help

# Check permissions
ls -la odooprotect.py

Upgrade OdooProtect

cd OdooProtect
git pull origin main
./install.sh  # Re-run installer

๐Ÿš€ Quick Start

โœ… NEW: OdooProtect now supports Odoo and framework obfuscation! Public API names (functions and classes that don't start with _) are automatically preserved, allowing cross-module imports to work correctly.

Protect a Single File

odooprotect -i my_script.py -b
# Output: /dist/my_script.py (machine-bound)

Protect an Entire Project

odooprotect -i my_project/ -b -e 365
# Output: /dist/my_project/ (entire project protected)
# Note: Only use for self-contained projects without explicit cross-module imports

Test Protection

# Test a protected script (after running odooprotect on it)
python3 -c "import sys; sys.path.insert(0, '.'); import my_protected_script"
# Should work on licensed machine, fail on others

# Or test the examples in this repository:
cd examples
python3 -c "import demo_bound; result = demo_bound.secret_function('super_secret_key_12345'); print('Protected script result:', result)"

# Test protected project modules:
cd protected_project
python3 -c "from models.user import User; u = User('Test', 25); print('User:', u.name)"

๐Ÿ“– Usage

Basic Syntax

odooprotect -i INPUT [-o OUTPUT] [OPTIONS]

Note: After installation with ./install.sh, you can use odooprotect from anywhere. Alternatively, use python3 odooprotect.py if running directly.

โœ… Recommended Use Cases

  • Odoo Addons: Custom Odoo modules and addons (โœ… NEW: Fully supported!)
  • Django/Flask Apps: Web applications with multiple modules (โœ… NEW: Cross-module imports work!)
  • Standalone Scripts: Single-file Python applications
  • Final Applications: Complete apps with public APIs
  • Closed Systems: Scripts running in controlled environments
  • CLI Tools: Command-line utilities
  • Custom Business Logic: Proprietary algorithms and business rules
  • Framework Plugins: Plugins and extensions for existing frameworks

โš ๏ธ Use With Caution For

  • Open-source Contributions: Code that others need to read and maintain
  • Debugging Required: Code still in active development (harder to debug obfuscated code)
  • Python Libraries: Public packages on PyPI (users expect readable source code)

Input Types

  • Single File: script.py
  • Directory: myproject/ (processes all .py files recursively)

Output Types

  • Single File: protected.py (default: /dist/filename.py)
  • Directory: protected/ (default: /dist/inputname/, maintains input structure)

โš™๏ธ Command Line Options

Option Description Default
-i, --input INPUT Input file or directory Required
-o, --output OUTPUT Output file or directory /dist/
-m, --machine-id Display current machine ID -
-c, --check-license DIR Check license validity in directory Current dir
-b Bind code to current machine hardware Disabled
-e DAYS License expiration in days 365
--no-preserve-api โœจ NEW: Obfuscate all names including public API Disabled (API preserved)

๐Ÿ†• Public API Preservation (Default)

By default, OdooProtect preserves public API names to allow cross-module imports:

  • Preserved: Public functions/classes (no leading _)
  • Obfuscated: Private functions/classes (leading _)
  • Preserved: Odoo-specific attributes (_name, _inherit, create, etc.)
  • Compatible: Works with Odoo, Django, Flask, and other frameworks

Example:

# Default: Preserves public API (Odoo/Framework compatible)
odooprotect -i my_odoo_addon/

# Full obfuscation: May break imports
odooprotect -i standalone_script.py --no-preserve-api

๐Ÿ’ก Examples

Example 1: Basic File Protection

# Protect a single Python file (output to /dist/filename.py)
odooprotect -i sensitive_code.py

# Or specify custom output
odooprotect -i sensitive_code.py -o protected.py

Example 2: Machine-Bound Protection

# Protect and bind to current machine for 1 year
odooprotect -i app.py -o app_protected.py -b -e 365

Example 3: Project Protection

# Protect entire Django/Flask project (output to /dist/)
odooprotect -i my_django_project/ -b

# Or specify custom output directory
odooprotect -i my_django_project/ -o protected_project/ -b

Example 4: Check Machine ID

# Display current machine ID for licensing
odooprotect -m
# Output: Machine ID: 0a3a756bffd5fe563cb9b9ec3e5e17fb

Example 5: Check License Status

# Check license validity in current directory
odooprotect -c

# Check license in specific directory
odooprotect -c /path/to/protected/app
# Shows: โœ… VALID - License valid, โœ… Machine ID matches

Example 6: Trial Version (30 days)

# Create time-limited trial version
odooprotect -i software.py -o trial_version.py -b -e 30

Example 7: Obfuscating Odoo Addons (โœ… Now Supported!)

# โœ… NEW: Obfuscating Odoo addons now works correctly!
# Public API names are preserved, allowing cross-module imports

# Obfuscate a custom Odoo addon
odooprotect -i /path/to/custom_addon/ -o /dist/custom_addon/ -b

# Obfuscate entire Odoo server (if needed)
odooprotect -i /odoo18/odoo18-server/addons/my_custom_addon/ -b

# What gets preserved:
# โœ… Public functions: def my_function() โ†’ preserved
# โœ… Public classes: class MyClass โ†’ preserved  
# โœ… Public methods: def method() โ†’ preserved
# โœ… Odoo model attributes: _name, _inherit, create, write, etc.
# โš™๏ธ Private functions: def _helper() โ†’ obfuscated to _fn_0
# โš™๏ธ Variables: user_input โ†’ obfuscated to _obf_0

# Test after obfuscation:
cd /dist/custom_addon
python3 -m odoo  # Should work! โœ…

๐Ÿ”’ Security Features

Variable Obfuscation

# Original
def process_data(user_input, api_key="secret123"):
    secret_token = "token_abc123"
    return user_input + secret_token

# Protected
def _obf_0(_obf_1, _obf_2=_decrypt_str('0')):
    _obf_3 = _decrypt_str('1')
    return _obf_1 + _obf_3

String Encryption

# Original strings are base64 encoded
_STRINGS = ['c2VjcmV0MTIz', 'dG9rZW5fYWJjMTIz']  # Encrypted strings

Hardware Binding

  • Machine ID Generation: Combines CPU, MAC, and disk serial
  • License Validation: Runtime checks ensure code only runs on authorized machines
  • Expiration Control: Time-based license expiration

Runtime Protection

# Automatic license check on import
_check_license()  # Validates machine and expiration

๐Ÿ—๏ธ Architecture

Core Components

  1. AST Processor (Obfuscator class)

    • Parses Python code into Abstract Syntax Tree
    • Transforms variable names and string literals
    • Applies obfuscation rules
  2. License Manager

    • Generates hardware fingerprints
    • Creates signed license keys
    • Validates licenses at runtime
  3. Runtime Engine

    • Decrypts strings on-demand
    • Verifies machine authorization
    • Handles tamper detection

File Structure

OdooProtect/
โ”œโ”€โ”€ odooprotect.py          # Main obfuscation tool
โ”œโ”€โ”€ README.md            # This documentation
โ”œโ”€โ”€ examples/            # Sample projects
โ”‚   โ”œโ”€โ”€ basic_script.py
โ”‚   โ””โ”€โ”€ sample_project/
โ””โ”€โ”€ tests/               # Test cases
    โ”œโ”€โ”€ test_obfuscation.py
    โ””โ”€โ”€ test_licensing.py

โš ๏ธ Limitations

Current Limitations

  • Complex Metaclasses: Advanced Python patterns may need adjustment
  • Dynamic Imports: importlib and dynamic imports may require special handling
  • Third-party Libraries: Some libraries may not work with obfuscated code

Public API Preservation (Default Behavior)

  • โœ… Framework Compatible: By default, OdooProtect preserves public API names (functions/classes not starting with _)
  • โœ… Cross-Module Imports: from module import function_name works correctly after obfuscation
  • โœ… Odoo Compatible: Tested and working with Odoo's module system
  • Option: Use --no-preserve-api flag for full obfuscation (may break imports)

Known Issues

  • Very large files (>10MB) may be slow to process
  • Some debugging tools may not work with obfuscated code

๐Ÿ”ง Troubleshooting

Common Issues

"ImportError: cannot import name 'function_name' from 'module'" (FIXED!)

Status: โœ… RESOLVED - This issue is now fixed in the latest version!

Solution: OdooProtect now automatically preserves public API names (functions and classes that don't start with _), so cross-module imports work correctly by default.

How it works:

# Public functions (no leading _) are preserved:
def strftime_format_to_spreadsheet_date_format(fmt):  # Name preserved โœ…
    return _internal_helper(fmt)  # Private function obfuscated โœ…

# After obfuscation, you can still import:
from module import strftime_format_to_spreadsheet_date_format  # Works! โœ…

Advanced Option: If you need full obfuscation (which may break imports), use:

odooprotect -i mycode.py --no-preserve-api

Best Practice: Keep default behavior for Odoo/framework code. Only use --no-preserve-api for standalone scripts where no imports are needed.

"SyntaxError: invalid syntax"

Cause: F-strings or advanced Python syntax not supported Solution: Convert f-strings to .format() or string concatenation

"ModuleNotFoundError"

Cause: Import paths changed after obfuscation Solution: Use absolute imports or adjust PYTHONPATH

"Unauthorized use of script"

Cause: License validation failed Solutions:

  • Verify you're on the licensed machine
  • Check license hasn't expired
  • Regenerate license if hardware changed

"ast.Unparse not available"

Cause: Python version < 3.9 Solution: Upgrade Python or use string fallback mode

Debug Mode

# Enable verbose output
odooprotect -i input.py -o output.py --verbose

Recovery

# If obfuscation fails, restore from backup
cp original_file.py obfuscated_file.py.backup

๐Ÿค Contributing

We welcome contributions! Please see our contributing guidelines:

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new features
  4. Submit a pull request

Development Setup

git clone https://github.com/dynaz/OdooProtect
cd odooprotect
python3 -m pip install -r requirements-dev.txt
python3 -m pytest tests/

Code Standards

  • Follow PEP 8 style guidelines
  • Add docstrings to all functions
  • Include unit tests for new features
  • Update documentation for changes

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

Commercial Use

For commercial applications requiring advanced features:

  • Enterprise licensing available
  • Priority support
  • Custom feature development
  • Professional services

๐Ÿ“ž Support

Documentation

Community

  • GitHub Issues: Report bugs and request features
  • Discussions: Ask questions and share experiences
  • Wiki: Community guides and tutorials

Professional Support

For enterprise deployments and custom requirements:

Support the Project

If you find OdooProtect helpful, consider supporting the development:

Buy Me A Coffee

Your support helps maintain and improve this open-source project! โ˜•


๐ŸŽฏ Quick Reference

Most Common Commands

# Quick protection (output to /dist/)
odooprotect -i file.py -b

# Project protection (output to /dist/)
odooprotect -i project/ -b

# Trial version (30 days)
odooprotect -i app.py -o trial.py -b -e 30

# Check machine ID
odooprotect -m

# Check license status
odooprotect -c

Verification

# Test protected file
python3 protected.py

# Test protected module (after creating one)
python3 -c "import my_protected_module; print('Module works!')"

# View machine ID (alternative method)
odooprotect -m

# Check license validity in current directory
odooprotect -c

# Check license in protected project
odooprotect -c /dist/base

# Test example protected scripts
cd examples
python3 -c "import demo_bound; result = demo_bound.secret_function('super_secret_key_12345'); print('Demo result:', result)"
python3 -c "import test_protected; result = test_protected.secret_function('super_secret_key_12345'); print('Test result:', result)"

OdooProtect - Secure your Python code with advanced obfuscation and hardware binding! ๐Ÿ”โœจ

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

odooprotect-1.0.1.tar.gz (26.4 kB view details)

Uploaded Source

Built Distribution

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

odooprotect-1.0.1-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file odooprotect-1.0.1.tar.gz.

File metadata

  • Download URL: odooprotect-1.0.1.tar.gz
  • Upload date:
  • Size: 26.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.4

File hashes

Hashes for odooprotect-1.0.1.tar.gz
Algorithm Hash digest
SHA256 b46f8aaebc328ce16b84443a9865585f29b209ff142da68d892def54355d7e1a
MD5 6e2287ea86e9efa139de100c64e00fc4
BLAKE2b-256 74e6ee807dabbc9bd6e2e82a6958211d8c96344e001fb051be7017e3194c9f2d

See more details on using hashes here.

File details

Details for the file odooprotect-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: odooprotect-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.4

File hashes

Hashes for odooprotect-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 41ecc975d81311601773b5f7161e074fa792e0b6616eed676d85abe2fcaca770
MD5 f6baa16b0e4e0e97a9f5e3f19300fcbe
BLAKE2b-256 9c0072691beb9e2c8a5962306ec4ff505a83e3ed220f079131c427411c6bdbf2

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