-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Local Python Code Protector
Welcome to the Local Python Code Protector wiki! This page provides comprehensive documentation and guidance on how to use the Local Python Code Protector Script to protect and secure your Python code through advanced encryption and obfuscation techniques.
Version: 1.2
(c) 2024 ab.net (alphabetanet.com) - Alpha Beta Network. All Rights Reserved.
Introduction
The Local Python Code Protector Script is a powerful command-line tool designed to provide source code protection and secure code sharing for Python scripts. It allows developers to obfuscate their Python code, making it more difficult for others to understand or reverse-engineer. This script supports both Python source files (.py) and compiled Python files (.pyc), offering flexible options for code obfuscation and encryption.
Key features of the script include:
- Code Obfuscation and Encryption: Implements multi-level protection with dynamic encryption and obfuscation techniques.
- Device-Specific Restrictions: Allows restricting code execution to specific devices based on hardware IDs.
- Expiration Date Settings: Enables setting an expiration date after which the code will not run.
- Cross-Platform Compatibility: Works on Windows, macOS, Linux/Unix, and other operating systems where Python 3.6+ is installed.
- No Internet Connection Required: The protected code runs locally without needing an internet connection.
This tool is ideal for developers who need to protect their Python code when sharing it with clients, colleagues, or deploying it on servers, ensuring Python code security best practices are upheld.
This script is part of the Alpha Beta Network's suite of Python code protection tools, designed to facilitate secure code sharing and enhance source code protection. For more information and to download the latest version, visit the Local Python Code Protector page on our official website.
Key Features
- Secure Code Sharing: Utilize advanced encryption and obfuscation methods to protect your Python code during transfer, ensuring secure code sharing.
- Source Code Protection: Prevent unauthorized access to your code with multi-level protection mechanisms, enhancing source code protection.
- Device-Specific Restrictions: Restrict code execution to specific devices using hardware IDs, adding an extra layer of security.
- Expiration Date Settings: Set an expiration date for your code, after which it will no longer execute.
- Cross-Platform Compatibility: Maintain cross-platform functionality; the protected Python scripts can be executed on any operating system (Windows, macOS, Linux/Unix, and others) where Python 3.6+ is installed.
- No Internet Connection Required: Protect and run your code without requiring an internet connection, ensuring Python secure code transfer.
How It Works
The Local Python Code Protector Script provides the following main functionalities:
-
Obfuscate Python Source Files: Protect Python source files (
.py) by applying multi-level encryption and obfuscation techniques. -
Obfuscate Compiled Python Files: Protect previously compiled Python files (
.pyc) using a unique recompilation technology that enhances their security. -
Restrict Code Execution: Limit code execution to specific devices using hardware IDs (HWIDs).
-
Set Expiration Dates: Define an expiration date after which the code will not run.
-
Add Custom Messages: Include custom messages to be displayed when the protected code is executed.
Getting Started
Prerequisites
- Python 3.6+ installed on your system.
Installation
Clone the repository and navigate to the project directory:
cd local-python-code-protector
Alternatively, download the local_python_code_protector.py script directly to your local machine.
Installing Required Packages
The script requires the following Python packages:
- requests
- psutil
- cryptography
- decompyle3
- xdis
- astor
Install them using pip:
Ensure that you are using the correct version of pip associated with your Python 3 installation. If you are using a virtual environment, activate it before installing the packages.
Usage
The Local Python Code Protector Script provides the following main functionalities:
- Obfuscating Python Source Files
- Obfuscating Compiled Python Files
- Restricting Code Execution to Specific Devices
- Setting an Expiration Date
- Adding Custom Messages
Obfuscating Python Source Files
Obfuscate and protect Python source files (.py) by applying multi-level encryption and obfuscation techniques.
Command Syntax
Description of Parameters
-
-f FILE_PATHor--file FILE_PATH: (Required) Specifies the path to the Python source file (.py) to protect. -
-d DEVICESor--device DEVICES: (Optional) A comma-separated list of hardware IDs (HWIDs) to restrict the code execution to specific devices. -
-e DATEor--expiration DATE: (Optional) Sets an expiration date inYYYY-MM-DDformat, after which the code will not run. -
-m MESSAGEor--message MESSAGE: (Optional) A custom message to display when the protected code is executed.
Example
Obfuscating Compiled Python Files
Protect previously compiled Python files (.pyc) using a unique recompilation technology that enhances their security.
Command Syntax
Note: The parameters are the same as for source files.
Example
Additional Features
Restricting Code Execution to Specific Devices
You can restrict the execution of the protected code to specific devices by specifying their hardware IDs (HWIDs). Only devices with the listed HWIDs will be able to run the code.
Parameter
-
-d DEVICESor--device DEVICES: A comma-separated list of HWIDs.
Example
Setting an Expiration Date
Set an expiration date for the protected code. After this date, the code will refuse to run.
Parameter
-
-e DATEor--expiration DATE: The expiration date inYYYY-MM-DDformat.
Example
Adding Custom Messages
Add a custom message that will be displayed when the protected code is executed. This could be a disclaimer or any pertinent information.
Parameter
-
-m MESSAGEor--message MESSAGE: The custom message text.
Example
Usage Examples
Basic Obfuscation of a Source File
Obfuscate a Python source file without any additional restrictions.
Command
Output
- The protected file will be saved in the
Local_Protecteddirectory as a compiled.pycfile.
Obfuscation with Device Restrictions
Restrict the execution of the protected code to specific devices.
Command
Notes
- Replace the numbers with the actual HWIDs of the devices.
- Only the devices with the specified HWIDs can execute the protected code.
Obfuscation with Expiration Date
Set an expiration date for the protected code.
Command
Notes
- After January 1, 2024, the code will not run.
Obfuscation with All Features
Combine device restrictions, expiration date, and a custom message.
Command
Notes
- The code will only run on the device with HWID
123456789012345678and before January 1, 2024. - Upon execution, the message "License valid until 2024-01-01." will be displayed.
Generating Hardware IDs
To restrict code execution to specific devices, you need to obtain the hardware IDs (HWIDs) of those devices. Use the system_hardware_id_generator.py script to generate the HWID.
Usage:
-
Run the script on the target device:
python system_hardware_id_generator.py -
The script will display the HWID:
Your Hardware ID (HWID) is: 123456789012345678 -
Use this HWID with the
-dor--deviceparameter when obfuscating your code.
Recommendations and Best Practices
-
Add Multiple Protection Layers: To enhance security, you can obfuscate the already protected code again using the script.
python local_python_code_protector.py -f Local_Protected/my_script.pyc -
Use Latest Python Versions: If possible, use the latest Python versions for which decompilers are not readily available.
-
Utilize Virtual Environments: Create virtual environments for different Python versions to generate protected versions compatible with various Python installations.
-
Combine with Cloud Protection: For more robust protection, consider using cloud-based solutions like our Secure Python Code Manager and Python Obfuscator Online, which offer advanced capabilities for code obfuscation in Python and Python secure code transfer.
Security and Best Practices
By implementing Python secure code transfer protocols, the Alpha Beta Network strives to keep code better protected during transmission. This commitment to security extends to various aspects of the platform, aiming to improve Python code security best practices.
While no system can guarantee absolute security, the Local Python Code Protector Script represents an effort to empower developers to share their code with increased confidence, significantly enhancing security with new solutions that we implement.
By leveraging our Python code protection tools, you adhere to Python code security best practices, ensuring your code remains secure during Python secure code transfer.
The Local Python Code Protector Script can also be effectively used to further protect licensed source code files created by the Alpha Beta Network cloud platform (more advanced and flexible source code protection solutions such as Python Obfuscator Online and Secure Python Code Manager Script).
Application Areas
The Local Python Code Protector Script can be effectively applied in the following areas:
-
Secure Code Sharing: Safely share Python code with clients or customers by implementing advanced Python code protection tools, facilitating secure code sharing for sales or rentals.
-
Collaborative Development: Share code securely with colleagues or team members without exposing the source code.
-
Testing and Verification: Provide intermediate versions for verification and testing, including fixing bugs and adding new functionality using seamless code updates.
-
Intellectual Property Protection: Maintain control over your code to prevent unauthorized usage or copying, preserving your intellectual property.
-
Server Infrastructure Management: Securely deploy and run protected Python scripts on rented servers (both virtual and physical), ensuring code confidentiality from both datacenter providers and end clients. This enables safe automation and configuration of client servers while protecting your proprietary code and implementation details.
Licensing
This project is currently in Beta Testing and available for free.
License Agreement
(c) 2024 ab.net (alphabetanet.com) - Alpha Beta Network. All Rights Reserved.
For detailed license information, please refer to the LICENSE.md file.
Contact Information
If you experience issues or have questions not covered in this documentation, please contact the Alpha Beta Network Research Team.
-
Website: https://alphabetanet.com | https://ab.net
-
Official Telegram Channel: https://t.me/alphabetanetcom
Stay connected to receive updates, provide feedback, and get early access to extended functionality.
Keywords: secure code sharing, source code protection, python code, code obfuscation in python, python code encryption, share python code securely, python code protection tools, python secure code transfer, code security best practices, cross-platform compatibility, python programming, protect python code, encrypt code before sharing.
Appendix A: Installation of Required Packages
The local_python_code_protector.py script requires the following Python packages:
- requests
- psutil
- cryptography
- decompyle3
- xdis
- astor
Installing Packages with pip
You can install these packages using the following command:
Ensure that you are using the correct version of pip associated with your Python 3 installation. If you are working within a virtual environment, activate it before installing the packages.
Appendix B: Generating Hardware IDs
To restrict code execution to specific devices, you need to obtain the hardware IDs (HWIDs) of those devices. Use the system_hardware_id_generator.py script to generate the HWID.
Usage:
-
Run the script on the target device:
python system_hardware_id_generator.py -
The script will display the HWID:
Your Hardware ID (HWID) is: 123456789012345678 -
**Use this HWID with the
-dor--deviceparameter when obfuscating your code.
Appendix C: Real-World Example - Universal Python Module with Multi-Version Compatibility
In this appendix, we present a real-world example of applying the Local Python Code Protector Script to create a secure, cross-platform, and multi-version compatible Python module.
C.1 Overview
The file system_hardware_id_generator.pyz is a universal Python module that encapsulates multiple protected .pyc files, each corresponding to a different Python version. It is optimized for cross-platform and multi-version compatibility, automatically detecting the current Python interpreter version and executing the appropriate protected module.
Key Features:
- Automatic Python Version Detection: The module determines the current Python interpreter version at runtime.
-
Version-Specific Execution: Executes the protected
.pycfile corresponding to the detected Python version. - Cross-Platform Compatibility: Runs seamlessly on Windows, macOS, Linux/Unix, and other operating systems.
C.2 Construction of the Universal Module
C.2.1 Protected .pyc Files
Eight protected .pyc files were generated for different Python versions using the Local Python Code Protector Script. The protection process was applied twice to each file to strengthen the security.
Protected files:
-
system_hardware_id_generator_python36.pyc(Python 3.6) -
system_hardware_id_generator_python37.pyc(Python 3.7) -
system_hardware_id_generator_python38.pyc(Python 3.8) -
system_hardware_id_generator_python39.pyc(Python 3.9) -
system_hardware_id_generator_python310.pyc(Python 3.10) -
system_hardware_id_generator_python311.pyc(Python 3.11) -
system_hardware_id_generator_python312.pyc(Python 3.12) -
system_hardware_id_generator_python313.pyc(Python 3.13)
C.2.2 Multi-Version PYZ Builder
The integration of these files into a single .pyz archive was achieved using the Multi-Version PYZ Builder, a software solution that leverages Alpha Beta Network technologies.
Key Features:
- Automatic Python Version Detection: The module determines the current Python interpreter version at runtime.
-
Version-Specific Execution: Executes the protected
.pycfile corresponding to the detected Python version. - Cross-Platform Compatibility: Runs seamlessly on Windows, macOS, Linux/Unix, and other operating systems.
C.3 Using the Universal Module
To generate the Hardware ID (HWID) on any supported platform:
-
Execute the
.pyzfile:python system_hardware_id_generator.pyz -
The module will display the HWID:
Your Hardware ID (HWID) is: 123456789012345678
Notes:
- Ensures secure code execution without exposing the original source code.
- Compatible with multiple Python versions, making it an ideal solution for environments with varied Python installations.
C.4 Building Your Own Universal Module
To create a similar universal Python module for your protected scripts:
-
Protect Your Scripts: Use the Local Python Code Protector Script to obfuscate your
.pyfiles for each Python version you wish to support. -
Use Multi-Version PYZ Builder: Integrate the protected
.pycfiles into a single.pyzarchive using the Multi-Version PYZ Builder.
For detailed instructions and to download the tool, visit the Multi-Version PYZ Builder page on our website.
-
Distribute the
.pyzFile: Share the universal.pyzfile with your users, ensuring they can run it on their platform and Python version without additional configurations.
Benefits:
- Combines the strengths of code obfuscation, encryption, and secure code sharing.
- Facilitates cross-platform and multi-version support, enhancing user experience.
- Aligns with Python code security best practices by minimizing exposure of sensitive code.
C.5 Conclusion
The use of a universal .pyz file exemplifies advanced techniques in source code protection and secure code sharing. By leveraging the Local Python Code Protector Script and the Multi-Version PYZ Builder, developers can create robust, secure, and versatile Python modules suitable for distribution across diverse environments.
For more information about our Alpha Beta Network project, please visit ab.net.
For more tools and resources on Python code protection and optimization, explore our Python Code Protection Tools and Python Obfuscator Online services.
(c) 2024 ab.net (alphabetanet.com) - Alpha Beta Network. All Rights Reserved.