CyMod is a Python tool that enhances code security by compiling Python code into binary files using Cython. This tool helps protect confidential code when sharing with clients or distributing in production environments by converting Python scripts (.py files) into compiled binaries (.so or .dll files).
- Secure Code Sharing: Compile Python scripts to binaries, making it more challenging to access the source code directly.
- Compatibility: Supports both Windows and Linux systems.
- Easy to Use: Command-line interface for flexible, straightforward usage.
- Optimized Performance: Compiled binaries may offer slight performance improvements over standard Python scripts.
- Python: Python 2.x or 3.x (recommended Python 3.x)
- Cython: You can install it via pip if not already installed.
pip install cython
- C++ Compiler: Ensure a compatible C++ compiler is installed for binary compilation. Compatibility details:
- Python 2.6 to 3.2: Microsoft Visual C++ Compiler for Python
- Python 3.3 and 3.4: Microsoft Visual Studio 2010
- Python 3.5 and later: Visual Studio 2015+
Clone the CyMod repository and navigate to its directory:
git clone https://github.com/username/CyMod.git
cd CyMod
1.Fork the code into your local directory
2.Decide which python version you want to use and check if corresponding support of c++ compiler is with you or not
In case of Windows, Following support is needed for different python versions:
While installing, Keep in mind to select this:
-
Make a Copy of your folder which you want to convert into compiled binary
-
Pass the path of your copied project like this:
python cyMOD.py <path_of_package>
Download samp_proj folder, and you can use it for a sample run
1. python cyMOD.py C:\Users\BIG1KOR\Desktop\samp_proj
2. python cyMOD.py C:\Users\BIG1KOR\Desktop\samp_proj -K=True
3. python cyMOD.py C:\Users\BIG1KOR\Desktop\samp_proj -K=True -A=__init__.py,main.py
python cyMOD.py -h
CyMod follows these basic steps:
- Identify Files: Scans the specified folder for
.py
files. - Filter Files: Excludes specified files, such as
__init__.py
ormain.py
. - Generate Setup File: Creates a
setup.py
file required for Cython compilation. - Compile to Binary: Compiles Python files to binary using the C++ compiler.
sample_project/
├── main.py
├── __init__.py
├── module1.py
└── module2.py
Running CyMod will produce the following structure (if keep
is set to False
):
sample_project/
├── main.c
├── __init__.pyc/.so
├── module1.pyc/.so
└── module2.pyc/.so
CyMod increases code security by obfuscating Python scripts, but please note:
- Platform-Specific Binaries: The compiled binaries are tailored to the specific Python version and operating system.
- Reverse Engineering: While binaries provide code obfuscation, they are not entirely immune to reverse engineering.
- Enhanced Code Security: Obfuscates code by compiling to binaries.
- Cross-Platform: Works on both Windows and Linux systems.
- Slight Performance Boost: Executing compiled code may be faster than raw
.py
files.
- Platform-Specific: Binaries are specific to the operating system and Python version.
- C++ Compiler Required: Compilation requires the setup of a compatible C++ compiler.
- Not Completely Secure: Binaries may still be reverse-engineered.
Common Issues and Solutions:
- C++ Compiler Error: Ensure the correct C++ compiler version is installed and configured.
- File Not Found Error: Verify the folder path and ensure
.py
files are in place. - Setup File Issues: If
setup.py
fails to generate, check folder permissions and confirm Cython is installed.
We welcome contributions to improve CyMod! Feel free to open an issue or submit a pull request.
This project is licensed under the GNU General Public License v3.0. See the LICENSE file for details.