PyProtect-v3 3.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyprotect_v3-3.0.0/MANIFEST.in +3 -0
- pyprotect_v3-3.0.0/PKG-INFO +135 -0
- pyprotect_v3-3.0.0/PyProtect_v3.egg-info/PKG-INFO +135 -0
- pyprotect_v3-3.0.0/PyProtect_v3.egg-info/SOURCES.txt +19 -0
- pyprotect_v3-3.0.0/PyProtect_v3.egg-info/dependency_links.txt +1 -0
- pyprotect_v3-3.0.0/PyProtect_v3.egg-info/entry_points.txt +2 -0
- pyprotect_v3-3.0.0/PyProtect_v3.egg-info/requires.txt +9 -0
- pyprotect_v3-3.0.0/PyProtect_v3.egg-info/top_level.txt +1 -0
- pyprotect_v3-3.0.0/README.md +103 -0
- pyprotect_v3-3.0.0/pyproject.toml +47 -0
- pyprotect_v3-3.0.0/pyprotect/__init__.py +16 -0
- pyprotect_v3-3.0.0/pyprotect/__main__.py +117 -0
- pyprotect_v3-3.0.0/pyprotect/_key.py +2 -0
- pyprotect_v3-3.0.0/pyprotect/anti_debug.py +166 -0
- pyprotect_v3-3.0.0/pyprotect/crypto.py +498 -0
- pyprotect_v3-3.0.0/pyprotect/engine.c +570 -0
- pyprotect_v3-3.0.0/pyprotect/engine.py +68 -0
- pyprotect_v3-3.0.0/pyprotect/hooks.py +89 -0
- pyprotect_v3-3.0.0/pyprotect/obfuscator.py +502 -0
- pyprotect_v3-3.0.0/setup.cfg +4 -0
- pyprotect_v3-3.0.0/setup.py +98 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: PyProtect-v3
|
|
3
|
+
Version: 3.0.0
|
|
4
|
+
Summary: Python script obfuscation library with AES-256-GCM encryption and C extension acceleration
|
|
5
|
+
Author-email: NguyenNgocNam <c.nam020213@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/PyProtect/PyProtect
|
|
8
|
+
Project-URL: Repository, https://github.com/PyProtect/PyProtect
|
|
9
|
+
Keywords: obfuscation,security,cryptography,anti-debug,protection
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
13
|
+
Classifier: Topic :: Security :: Cryptography
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: C
|
|
21
|
+
Classifier: Operating System :: OS Independent
|
|
22
|
+
Classifier: Environment :: Console
|
|
23
|
+
Requires-Python: >=3.8
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
Requires-Dist: setuptools>=42.0.0
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
28
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
29
|
+
Provides-Extra: build
|
|
30
|
+
Requires-Dist: wheel>=0.27.0; extra == "build"
|
|
31
|
+
Requires-Dist: build>=0.7.0; extra == "build"
|
|
32
|
+
|
|
33
|
+
# pyprotect-v3
|
|
34
|
+
|
|
35
|
+
A production-ready Python script obfuscation library with AES-256-GCM encryption,
|
|
36
|
+
multi-platform C extension acceleration, and graceful pure-Python fallback.
|
|
37
|
+
|
|
38
|
+
## Features
|
|
39
|
+
|
|
40
|
+
- **AES-256-GCM Encryption** — Industry-standard authenticated encryption
|
|
41
|
+
- **C Extension Acceleration** — Native code for decryption, anti-debug, and execution
|
|
42
|
+
- **Multi-Platform** — Windows, macOS, Linux with platform-specific anti-debug
|
|
43
|
+
- **Pure Python Fallback** — Graceful degradation if C extension fails to build
|
|
44
|
+
- **Import Hook Support** — Protect entire packages with transparent decryption
|
|
45
|
+
- **CLI Tool** — Simple command-line interface for obfuscating scripts
|
|
46
|
+
- **PyPI Ready** — Upload to PyPI with `pip install pyprotect-v3`
|
|
47
|
+
|
|
48
|
+
## Quick Start
|
|
49
|
+
|
|
50
|
+
### Install
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install pyprotect-v3
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Obfuscate a Script
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
# Encrypt a single file
|
|
60
|
+
python -m pyprotect encrypt my_script.py -o dist/
|
|
61
|
+
|
|
62
|
+
# Encrypt an entire package
|
|
63
|
+
python -m pyprotect encrypt-dir mypackage/ -o dist/
|
|
64
|
+
|
|
65
|
+
# Build C extension only
|
|
66
|
+
python -m pyprotect build-engine
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Programmatic Usage
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from pyprotect import Obfuscator
|
|
73
|
+
|
|
74
|
+
obf = Obfuscator()
|
|
75
|
+
obf.encrypt_file("my_script.py")
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Run an Obfuscated Script
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
python my_script_protected.py
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The script will automatically:
|
|
85
|
+
1. Try to load the C extension for native decryption
|
|
86
|
+
2. Fall back to pure Python if C extension unavailable
|
|
87
|
+
3. Decrypt and execute the original code
|
|
88
|
+
|
|
89
|
+
### Protect a Package with Import Hook
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from pyprotect.hooks import install_hook
|
|
93
|
+
|
|
94
|
+
hook = install_hook(key=b"your-32-byte-key-here!!!!!!")
|
|
95
|
+
import my_protected_module
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Architecture
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
pyprotect-v3/
|
|
102
|
+
├── pyprotect/
|
|
103
|
+
│ ├── __init__.py # Package init, version info
|
|
104
|
+
│ ├── __main__.py # CLI: python -m pyprotect
|
|
105
|
+
│ ├── obfuscator.py # Main obfuscation tool
|
|
106
|
+
│ ├── engine.c # Cross-platform C extension
|
|
107
|
+
│ ├── engine.py # Pure Python fallback engine
|
|
108
|
+
│ ├── crypto.py # AES-GCM encryption (ctypes + pure Python)
|
|
109
|
+
│ ├── anti_debug.py # Anti-debug checks (Python fallback)
|
|
110
|
+
│ └── hooks.py # Import hook for multi-module protection
|
|
111
|
+
├── setup.py # PyPI-ready setup
|
|
112
|
+
├── pyproject.toml # Build configuration
|
|
113
|
+
└── README.md # This file
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Anti-Debug Features
|
|
117
|
+
|
|
118
|
+
| Platform | Techniques |
|
|
119
|
+
|----------|------------|
|
|
120
|
+
| **Linux** | `/proc/self/status` TracerPid, `ptrace(PTRACE_TRACEME)` |
|
|
121
|
+
| **Windows** | `IsDebuggerPresent()`, `CheckRemoteDebuggerPresent()`, `NtQueryInformationProcess()` |
|
|
122
|
+
| **macOS** | `ptrace(PT_DENY_ATTACH)`, `sysctl` `KERN_PROC` |
|
|
123
|
+
|
|
124
|
+
## C Extension Fallback
|
|
125
|
+
|
|
126
|
+
If the C extension fails to build (no C compiler, missing OpenSSL, etc.),
|
|
127
|
+
pyprotect-v3 automatically uses a pure Python fallback that:
|
|
128
|
+
|
|
129
|
+
- Uses `ctypes` to call OpenSSL for AES-GCM decryption if available
|
|
130
|
+
- Falls back to a built-in pure Python AES-256-GCM implementation
|
|
131
|
+
- Performs anti-debug checks via `os`, `sys`, and `ctypes`
|
|
132
|
+
|
|
133
|
+
## License
|
|
134
|
+
|
|
135
|
+
MIT
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: PyProtect-v3
|
|
3
|
+
Version: 3.0.0
|
|
4
|
+
Summary: Python script obfuscation library with AES-256-GCM encryption and C extension acceleration
|
|
5
|
+
Author-email: NguyenNgocNam <c.nam020213@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/PyProtect/PyProtect
|
|
8
|
+
Project-URL: Repository, https://github.com/PyProtect/PyProtect
|
|
9
|
+
Keywords: obfuscation,security,cryptography,anti-debug,protection
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
13
|
+
Classifier: Topic :: Security :: Cryptography
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: C
|
|
21
|
+
Classifier: Operating System :: OS Independent
|
|
22
|
+
Classifier: Environment :: Console
|
|
23
|
+
Requires-Python: >=3.8
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
Requires-Dist: setuptools>=42.0.0
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
28
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
29
|
+
Provides-Extra: build
|
|
30
|
+
Requires-Dist: wheel>=0.27.0; extra == "build"
|
|
31
|
+
Requires-Dist: build>=0.7.0; extra == "build"
|
|
32
|
+
|
|
33
|
+
# pyprotect-v3
|
|
34
|
+
|
|
35
|
+
A production-ready Python script obfuscation library with AES-256-GCM encryption,
|
|
36
|
+
multi-platform C extension acceleration, and graceful pure-Python fallback.
|
|
37
|
+
|
|
38
|
+
## Features
|
|
39
|
+
|
|
40
|
+
- **AES-256-GCM Encryption** — Industry-standard authenticated encryption
|
|
41
|
+
- **C Extension Acceleration** — Native code for decryption, anti-debug, and execution
|
|
42
|
+
- **Multi-Platform** — Windows, macOS, Linux with platform-specific anti-debug
|
|
43
|
+
- **Pure Python Fallback** — Graceful degradation if C extension fails to build
|
|
44
|
+
- **Import Hook Support** — Protect entire packages with transparent decryption
|
|
45
|
+
- **CLI Tool** — Simple command-line interface for obfuscating scripts
|
|
46
|
+
- **PyPI Ready** — Upload to PyPI with `pip install pyprotect-v3`
|
|
47
|
+
|
|
48
|
+
## Quick Start
|
|
49
|
+
|
|
50
|
+
### Install
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install pyprotect-v3
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Obfuscate a Script
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
# Encrypt a single file
|
|
60
|
+
python -m pyprotect encrypt my_script.py -o dist/
|
|
61
|
+
|
|
62
|
+
# Encrypt an entire package
|
|
63
|
+
python -m pyprotect encrypt-dir mypackage/ -o dist/
|
|
64
|
+
|
|
65
|
+
# Build C extension only
|
|
66
|
+
python -m pyprotect build-engine
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Programmatic Usage
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from pyprotect import Obfuscator
|
|
73
|
+
|
|
74
|
+
obf = Obfuscator()
|
|
75
|
+
obf.encrypt_file("my_script.py")
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Run an Obfuscated Script
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
python my_script_protected.py
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The script will automatically:
|
|
85
|
+
1. Try to load the C extension for native decryption
|
|
86
|
+
2. Fall back to pure Python if C extension unavailable
|
|
87
|
+
3. Decrypt and execute the original code
|
|
88
|
+
|
|
89
|
+
### Protect a Package with Import Hook
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from pyprotect.hooks import install_hook
|
|
93
|
+
|
|
94
|
+
hook = install_hook(key=b"your-32-byte-key-here!!!!!!")
|
|
95
|
+
import my_protected_module
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Architecture
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
pyprotect-v3/
|
|
102
|
+
├── pyprotect/
|
|
103
|
+
│ ├── __init__.py # Package init, version info
|
|
104
|
+
│ ├── __main__.py # CLI: python -m pyprotect
|
|
105
|
+
│ ├── obfuscator.py # Main obfuscation tool
|
|
106
|
+
│ ├── engine.c # Cross-platform C extension
|
|
107
|
+
│ ├── engine.py # Pure Python fallback engine
|
|
108
|
+
│ ├── crypto.py # AES-GCM encryption (ctypes + pure Python)
|
|
109
|
+
│ ├── anti_debug.py # Anti-debug checks (Python fallback)
|
|
110
|
+
│ └── hooks.py # Import hook for multi-module protection
|
|
111
|
+
├── setup.py # PyPI-ready setup
|
|
112
|
+
├── pyproject.toml # Build configuration
|
|
113
|
+
└── README.md # This file
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Anti-Debug Features
|
|
117
|
+
|
|
118
|
+
| Platform | Techniques |
|
|
119
|
+
|----------|------------|
|
|
120
|
+
| **Linux** | `/proc/self/status` TracerPid, `ptrace(PTRACE_TRACEME)` |
|
|
121
|
+
| **Windows** | `IsDebuggerPresent()`, `CheckRemoteDebuggerPresent()`, `NtQueryInformationProcess()` |
|
|
122
|
+
| **macOS** | `ptrace(PT_DENY_ATTACH)`, `sysctl` `KERN_PROC` |
|
|
123
|
+
|
|
124
|
+
## C Extension Fallback
|
|
125
|
+
|
|
126
|
+
If the C extension fails to build (no C compiler, missing OpenSSL, etc.),
|
|
127
|
+
pyprotect-v3 automatically uses a pure Python fallback that:
|
|
128
|
+
|
|
129
|
+
- Uses `ctypes` to call OpenSSL for AES-GCM decryption if available
|
|
130
|
+
- Falls back to a built-in pure Python AES-256-GCM implementation
|
|
131
|
+
- Performs anti-debug checks via `os`, `sys`, and `ctypes`
|
|
132
|
+
|
|
133
|
+
## License
|
|
134
|
+
|
|
135
|
+
MIT
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
MANIFEST.in
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
setup.py
|
|
5
|
+
PyProtect_v3.egg-info/PKG-INFO
|
|
6
|
+
PyProtect_v3.egg-info/SOURCES.txt
|
|
7
|
+
PyProtect_v3.egg-info/dependency_links.txt
|
|
8
|
+
PyProtect_v3.egg-info/entry_points.txt
|
|
9
|
+
PyProtect_v3.egg-info/requires.txt
|
|
10
|
+
PyProtect_v3.egg-info/top_level.txt
|
|
11
|
+
pyprotect/__init__.py
|
|
12
|
+
pyprotect/__main__.py
|
|
13
|
+
pyprotect/_key.py
|
|
14
|
+
pyprotect/anti_debug.py
|
|
15
|
+
pyprotect/crypto.py
|
|
16
|
+
pyprotect/engine.c
|
|
17
|
+
pyprotect/engine.py
|
|
18
|
+
pyprotect/hooks.py
|
|
19
|
+
pyprotect/obfuscator.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pyprotect
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# pyprotect-v3
|
|
2
|
+
|
|
3
|
+
A production-ready Python script obfuscation library with AES-256-GCM encryption,
|
|
4
|
+
multi-platform C extension acceleration, and graceful pure-Python fallback.
|
|
5
|
+
|
|
6
|
+
## Features
|
|
7
|
+
|
|
8
|
+
- **AES-256-GCM Encryption** — Industry-standard authenticated encryption
|
|
9
|
+
- **C Extension Acceleration** — Native code for decryption, anti-debug, and execution
|
|
10
|
+
- **Multi-Platform** — Windows, macOS, Linux with platform-specific anti-debug
|
|
11
|
+
- **Pure Python Fallback** — Graceful degradation if C extension fails to build
|
|
12
|
+
- **Import Hook Support** — Protect entire packages with transparent decryption
|
|
13
|
+
- **CLI Tool** — Simple command-line interface for obfuscating scripts
|
|
14
|
+
- **PyPI Ready** — Upload to PyPI with `pip install pyprotect-v3`
|
|
15
|
+
|
|
16
|
+
## Quick Start
|
|
17
|
+
|
|
18
|
+
### Install
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install pyprotect-v3
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Obfuscate a Script
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# Encrypt a single file
|
|
28
|
+
python -m pyprotect encrypt my_script.py -o dist/
|
|
29
|
+
|
|
30
|
+
# Encrypt an entire package
|
|
31
|
+
python -m pyprotect encrypt-dir mypackage/ -o dist/
|
|
32
|
+
|
|
33
|
+
# Build C extension only
|
|
34
|
+
python -m pyprotect build-engine
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Programmatic Usage
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from pyprotect import Obfuscator
|
|
41
|
+
|
|
42
|
+
obf = Obfuscator()
|
|
43
|
+
obf.encrypt_file("my_script.py")
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Run an Obfuscated Script
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
python my_script_protected.py
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The script will automatically:
|
|
53
|
+
1. Try to load the C extension for native decryption
|
|
54
|
+
2. Fall back to pure Python if C extension unavailable
|
|
55
|
+
3. Decrypt and execute the original code
|
|
56
|
+
|
|
57
|
+
### Protect a Package with Import Hook
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from pyprotect.hooks import install_hook
|
|
61
|
+
|
|
62
|
+
hook = install_hook(key=b"your-32-byte-key-here!!!!!!")
|
|
63
|
+
import my_protected_module
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Architecture
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
pyprotect-v3/
|
|
70
|
+
├── pyprotect/
|
|
71
|
+
│ ├── __init__.py # Package init, version info
|
|
72
|
+
│ ├── __main__.py # CLI: python -m pyprotect
|
|
73
|
+
│ ├── obfuscator.py # Main obfuscation tool
|
|
74
|
+
│ ├── engine.c # Cross-platform C extension
|
|
75
|
+
│ ├── engine.py # Pure Python fallback engine
|
|
76
|
+
│ ├── crypto.py # AES-GCM encryption (ctypes + pure Python)
|
|
77
|
+
│ ├── anti_debug.py # Anti-debug checks (Python fallback)
|
|
78
|
+
│ └── hooks.py # Import hook for multi-module protection
|
|
79
|
+
├── setup.py # PyPI-ready setup
|
|
80
|
+
├── pyproject.toml # Build configuration
|
|
81
|
+
└── README.md # This file
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Anti-Debug Features
|
|
85
|
+
|
|
86
|
+
| Platform | Techniques |
|
|
87
|
+
|----------|------------|
|
|
88
|
+
| **Linux** | `/proc/self/status` TracerPid, `ptrace(PTRACE_TRACEME)` |
|
|
89
|
+
| **Windows** | `IsDebuggerPresent()`, `CheckRemoteDebuggerPresent()`, `NtQueryInformationProcess()` |
|
|
90
|
+
| **macOS** | `ptrace(PT_DENY_ATTACH)`, `sysctl` `KERN_PROC` |
|
|
91
|
+
|
|
92
|
+
## C Extension Fallback
|
|
93
|
+
|
|
94
|
+
If the C extension fails to build (no C compiler, missing OpenSSL, etc.),
|
|
95
|
+
pyprotect-v3 automatically uses a pure Python fallback that:
|
|
96
|
+
|
|
97
|
+
- Uses `ctypes` to call OpenSSL for AES-GCM decryption if available
|
|
98
|
+
- Falls back to a built-in pure Python AES-256-GCM implementation
|
|
99
|
+
- Performs anti-debug checks via `os`, `sys`, and `ctypes`
|
|
100
|
+
|
|
101
|
+
## License
|
|
102
|
+
|
|
103
|
+
MIT
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=42.0.0", "wheel>=0.37.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "PyProtect-v3"
|
|
7
|
+
version = "3.0.0"
|
|
8
|
+
description = "Python script obfuscation library with AES-256-GCM encryption and C extension acceleration"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
keywords = ["obfuscation", "security", "cryptography", "anti-debug", "protection"]
|
|
13
|
+
authors = [
|
|
14
|
+
{name = "NguyenNgocNam", email = "c.nam020213@gmail.com"},
|
|
15
|
+
]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Topic :: Software Development :: Build Tools",
|
|
20
|
+
"Topic :: Security :: Cryptography",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3.8",
|
|
23
|
+
"Programming Language :: Python :: 3.9",
|
|
24
|
+
"Programming Language :: Python :: 3.10",
|
|
25
|
+
"Programming Language :: Python :: 3.11",
|
|
26
|
+
"Programming Language :: Python :: 3.12",
|
|
27
|
+
"Programming Language :: C",
|
|
28
|
+
"Operating System :: OS Independent",
|
|
29
|
+
"Environment :: Console",
|
|
30
|
+
]
|
|
31
|
+
dependencies = ["setuptools>=42.0.0"]
|
|
32
|
+
|
|
33
|
+
[project.urls]
|
|
34
|
+
Homepage = "https://github.com/PyProtect/PyProtect"
|
|
35
|
+
Repository = "https://github.com/PyProtect/PyProtect"
|
|
36
|
+
|
|
37
|
+
[project.scripts]
|
|
38
|
+
pyprotect = "pyprotect.__main__:main"
|
|
39
|
+
|
|
40
|
+
[project.optional-dependencies]
|
|
41
|
+
dev = ["pytest>=7.0", "pytest-cov>=4.0"]
|
|
42
|
+
build = ["wheel>=0.27.0", "build>=0.7.0"]
|
|
43
|
+
|
|
44
|
+
[tool.setuptools.packages.find]
|
|
45
|
+
include = ["pyprotect*"]
|
|
46
|
+
|
|
47
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""pyprotect-v3: Python script obfuscation library with C extension acceleration."""
|
|
2
|
+
|
|
3
|
+
__version__ = "3.0.0"
|
|
4
|
+
__author__ = "pyprotect"
|
|
5
|
+
|
|
6
|
+
from . import anti_debug, crypto
|
|
7
|
+
|
|
8
|
+
try:
|
|
9
|
+
from . import engine_c as _engine
|
|
10
|
+
HAS_C_EXTENSION = True
|
|
11
|
+
except (ImportError, ModuleNotFoundError):
|
|
12
|
+
from . import engine as _engine
|
|
13
|
+
HAS_C_EXTENSION = False
|
|
14
|
+
|
|
15
|
+
from .obfuscator import Obfuscator
|
|
16
|
+
from .hooks import ProtectedImportHook
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"""CLI entry point for pyprotect-v3."""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
import os
|
|
5
|
+
import argparse
|
|
6
|
+
import subprocess
|
|
7
|
+
import shutil
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def cmd_encrypt(args):
|
|
11
|
+
from pyprotect.obfuscator import Obfuscator
|
|
12
|
+
obf = Obfuscator(
|
|
13
|
+
compress=not args.no_compress,
|
|
14
|
+
output_dir=args.output_dir,
|
|
15
|
+
)
|
|
16
|
+
out_path = obf.encrypt_file(args.input)
|
|
17
|
+
print(f"[+] Encrypted: {args.input} -> {out_path}")
|
|
18
|
+
_copy_engine(args.output_dir)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def cmd_encrypt_dir(args):
|
|
22
|
+
from pyprotect.obfuscator import Obfuscator
|
|
23
|
+
obf = Obfuscator(
|
|
24
|
+
compress=not args.no_compress,
|
|
25
|
+
multi=True,
|
|
26
|
+
output_dir=args.output_dir,
|
|
27
|
+
)
|
|
28
|
+
out_files = obf.encrypt_directory(args.input)
|
|
29
|
+
print(f"[+] Encrypted {len(out_files)} files from {args.input}")
|
|
30
|
+
for f in out_files:
|
|
31
|
+
print(f" -> {f}")
|
|
32
|
+
_copy_engine(args.output_dir)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def cmd_build_engine(args):
|
|
36
|
+
_do_build_engine()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _do_build_engine():
|
|
40
|
+
src_dir = os.path.dirname(os.path.abspath(__file__))
|
|
41
|
+
engine_c = os.path.join(src_dir, "engine.c")
|
|
42
|
+
if not os.path.exists(engine_c):
|
|
43
|
+
print("[-] engine.c not found in pyprotect package directory")
|
|
44
|
+
sys.exit(1)
|
|
45
|
+
build_dir = os.path.join(src_dir, "..", "build_engine")
|
|
46
|
+
os.makedirs(build_dir, exist_ok=True)
|
|
47
|
+
try:
|
|
48
|
+
subprocess.check_call([
|
|
49
|
+
sys.executable, "-c", f"""
|
|
50
|
+
import sys
|
|
51
|
+
sys.path.insert(0, {os.path.dirname(src_dir)!r})
|
|
52
|
+
from setuptools import setup, Extension
|
|
53
|
+
import sysconfig
|
|
54
|
+
ext = Extension(
|
|
55
|
+
'pyprotect.engine_c',
|
|
56
|
+
sources=[{engine_c!r}],
|
|
57
|
+
libraries=['crypto', 'z'],
|
|
58
|
+
extra_compile_args=['-std=c99', '-Wall', '-O2'],
|
|
59
|
+
)
|
|
60
|
+
setup(
|
|
61
|
+
name='pyprotect-engine',
|
|
62
|
+
ext_modules=[ext],
|
|
63
|
+
script_args=['build_ext', '--build-temp={build_dir!r}', '--build-lib={src_dir!r}'],
|
|
64
|
+
)
|
|
65
|
+
""",
|
|
66
|
+
])
|
|
67
|
+
print(f"[+] C extension built successfully")
|
|
68
|
+
except subprocess.CalledProcessError as e:
|
|
69
|
+
print(f"[-] Failed to build C extension: {e}")
|
|
70
|
+
print("[*] Pure Python fallback will be used")
|
|
71
|
+
sys.exit(1)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _copy_engine(output_dir):
|
|
75
|
+
if output_dir is None:
|
|
76
|
+
return
|
|
77
|
+
os.makedirs(output_dir, exist_ok=True)
|
|
78
|
+
engine_dir = os.path.dirname(os.path.abspath(__file__))
|
|
79
|
+
for fname in os.listdir(engine_dir):
|
|
80
|
+
if fname.startswith("engine_c") and (fname.endswith(".so") or fname.endswith(".pyd") or fname.endswith(".dll")):
|
|
81
|
+
shutil.copy2(os.path.join(engine_dir, fname), os.path.join(output_dir, fname))
|
|
82
|
+
print(f"[+] Copied engine: {fname}")
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def main():
|
|
86
|
+
parser = argparse.ArgumentParser(
|
|
87
|
+
description="pyprotect-v3: Python script obfuscation tool",
|
|
88
|
+
)
|
|
89
|
+
sub = parser.add_subparsers(dest="command")
|
|
90
|
+
|
|
91
|
+
p_encrypt = sub.add_parser("encrypt", help="Encrypt a single .py file")
|
|
92
|
+
p_encrypt.add_argument("input", help="Input .py file")
|
|
93
|
+
p_encrypt.add_argument("-o", "--output-dir", default=None, help="Output directory")
|
|
94
|
+
p_encrypt.add_argument("--no-compress", action="store_true", help="Skip zlib compression")
|
|
95
|
+
|
|
96
|
+
p_encdir = sub.add_parser("encrypt-dir", help="Encrypt all .py files in a directory")
|
|
97
|
+
p_encdir.add_argument("input", help="Input directory")
|
|
98
|
+
p_encdir.add_argument("-o", "--output-dir", default=None, help="Output directory")
|
|
99
|
+
p_encdir.add_argument("--no-compress", action="store_true", help="Skip zlib compression")
|
|
100
|
+
|
|
101
|
+
p_build = sub.add_parser("build-engine", help="Build C extension only")
|
|
102
|
+
|
|
103
|
+
args = parser.parse_args()
|
|
104
|
+
if not args.command:
|
|
105
|
+
parser.print_help()
|
|
106
|
+
sys.exit(1)
|
|
107
|
+
|
|
108
|
+
if args.command == "encrypt":
|
|
109
|
+
cmd_encrypt(args)
|
|
110
|
+
elif args.command == "encrypt-dir":
|
|
111
|
+
cmd_encrypt_dir(args)
|
|
112
|
+
elif args.command == "build-engine":
|
|
113
|
+
cmd_build_engine(args)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
if __name__ == "__main__":
|
|
117
|
+
main()
|