AutoCython-zhang 2.3.1__tar.gz → 2.3.2__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.
- {autocython_zhang-2.3.1 → autocython_zhang-2.3.2}/AutoCython/_version.py +1 -1
- {autocython_zhang-2.3.1 → autocython_zhang-2.3.2}/AutoCython/obfuscate.py +12 -1
- autocython_zhang-2.3.2/AutoCython_zhang.egg-info/PKG-INFO +147 -0
- autocython_zhang-2.3.2/PKG-INFO +147 -0
- autocython_zhang-2.3.2/README.md +127 -0
- autocython_zhang-2.3.1/AutoCython_zhang.egg-info/PKG-INFO +0 -280
- autocython_zhang-2.3.1/PKG-INFO +0 -280
- autocython_zhang-2.3.1/README.md +0 -260
- {autocython_zhang-2.3.1 → autocython_zhang-2.3.2}/AutoCython/AutoCython.py +0 -0
- {autocython_zhang-2.3.1 → autocython_zhang-2.3.2}/AutoCython/__init__.py +0 -0
- {autocython_zhang-2.3.1 → autocython_zhang-2.3.2}/AutoCython/compile.py +0 -0
- {autocython_zhang-2.3.1 → autocython_zhang-2.3.2}/AutoCython/run_tasks.py +0 -0
- {autocython_zhang-2.3.1 → autocython_zhang-2.3.2}/AutoCython/tools.py +0 -0
- {autocython_zhang-2.3.1 → autocython_zhang-2.3.2}/AutoCython_zhang.egg-info/SOURCES.txt +0 -0
- {autocython_zhang-2.3.1 → autocython_zhang-2.3.2}/AutoCython_zhang.egg-info/dependency_links.txt +0 -0
- {autocython_zhang-2.3.1 → autocython_zhang-2.3.2}/AutoCython_zhang.egg-info/entry_points.txt +0 -0
- {autocython_zhang-2.3.1 → autocython_zhang-2.3.2}/AutoCython_zhang.egg-info/requires.txt +0 -0
- {autocython_zhang-2.3.1 → autocython_zhang-2.3.2}/AutoCython_zhang.egg-info/top_level.txt +0 -0
- {autocython_zhang-2.3.1 → autocython_zhang-2.3.2}/LICENSE +0 -0
- {autocython_zhang-2.3.1 → autocython_zhang-2.3.2}/MANIFEST.in +0 -0
- {autocython_zhang-2.3.1 → autocython_zhang-2.3.2}/pyproject.toml +0 -0
- {autocython_zhang-2.3.1 → autocython_zhang-2.3.2}/setup.cfg +0 -0
|
@@ -75,10 +75,16 @@ class _DocstringRemover(ast.NodeTransformer):
|
|
|
75
75
|
|
|
76
76
|
|
|
77
77
|
class _AnnotationRemover(ast.NodeTransformer):
|
|
78
|
-
"""
|
|
78
|
+
"""清除函数参数和返回值的类型注解,以及非类体内的变量注解。
|
|
79
|
+
保留类体内的注解赋值,因为 Pydantic/dataclass/attrs 等框架依赖 __annotations__。"""
|
|
80
|
+
|
|
81
|
+
def __init__(self):
|
|
82
|
+
self._scope_stack = ['module']
|
|
79
83
|
|
|
80
84
|
def visit_FunctionDef(self, node):
|
|
85
|
+
self._scope_stack.append('function')
|
|
81
86
|
self.generic_visit(node)
|
|
87
|
+
self._scope_stack.pop()
|
|
82
88
|
node.returns = None
|
|
83
89
|
for arg in node.args.args + node.args.posonlyargs + node.args.kwonlyargs:
|
|
84
90
|
arg.annotation = None
|
|
@@ -91,13 +97,18 @@ class _AnnotationRemover(ast.NodeTransformer):
|
|
|
91
97
|
visit_AsyncFunctionDef = visit_FunctionDef
|
|
92
98
|
|
|
93
99
|
def visit_ClassDef(self, node):
|
|
100
|
+
self._scope_stack.append('class')
|
|
94
101
|
self.generic_visit(node)
|
|
102
|
+
self._scope_stack.pop()
|
|
95
103
|
if not node.body:
|
|
96
104
|
node.body.append(ast.Pass())
|
|
97
105
|
return node
|
|
98
106
|
|
|
99
107
|
def visit_AnnAssign(self, node):
|
|
100
108
|
self.generic_visit(node)
|
|
109
|
+
# 类体内的注解赋值必须保留(Pydantic/dataclass 等框架依赖 __annotations__)
|
|
110
|
+
if self._scope_stack[-1] == 'class':
|
|
111
|
+
return node
|
|
101
112
|
if node.value is not None:
|
|
102
113
|
return ast.Assign(targets=[node.target], value=node.value,
|
|
103
114
|
lineno=node.lineno, col_offset=node.col_offset)
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: AutoCython-zhang
|
|
3
|
+
Version: 2.3.2
|
|
4
|
+
Summary: 自动Cython,使用Cython批量编译.py文件为.pyd文件!
|
|
5
|
+
Author-email: zhang_gavin <qq814608@163.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: homepage, https://github.com/zhang0281/AutoCython
|
|
8
|
+
Project-URL: repository, https://github.com/zhang0281/AutoCython
|
|
9
|
+
Project-URL: documentation, https://github.com/zhang0281/AutoCython#readme
|
|
10
|
+
Keywords: cython,compile,pyd,pyc,python,autopyd
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Requires-Python: >=3.9
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: setuptools
|
|
17
|
+
Requires-Dist: cython
|
|
18
|
+
Requires-Dist: rich
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# AutoCython
|
|
22
|
+
|
|
23
|
+
> 自动将 Python 源码编译为 Cython 二进制扩展(`.so`/`.pyd`),支持七重 AST 混淆、并发编译、跨平台运行。
|
|
24
|
+
|
|
25
|
+
[](https://pypi.org/project/AutoCython-zhang/)
|
|
26
|
+
[](https://pypi.org/project/AutoCython-zhang/)
|
|
27
|
+
[](LICENSE)
|
|
28
|
+
|
|
29
|
+
## 概述
|
|
30
|
+
|
|
31
|
+
AutoCython 是一个 Python 源码保护工具,通过 Cython 编译 + AST 混淆双重手段,将 `.py` 文件转换为不可逆的二进制扩展模块。适用于商业项目源码保护、SDK 分发、知识产权保护等场景。
|
|
32
|
+
|
|
33
|
+
## 特性
|
|
34
|
+
|
|
35
|
+
- **一键编译** — 单文件 (`-f`) 或整目录 (`-p`) 批量编译为 `.so`/`.pyd`
|
|
36
|
+
- **七重 AST 混淆** — docstring 移除、注解清除、局部变量重命名、字符串 XOR 加密、常量折叠、控制流平坦化、虚假分支注入
|
|
37
|
+
- **并发编译** — 基于 `ThreadPoolExecutor` 的多线程并行编译,可配置并发数
|
|
38
|
+
- **实时进度面板** — 基于 Rich 的实时任务状态表格、进度条、耗时统计
|
|
39
|
+
- **跨平台** — 支持 Linux、macOS、Windows,自动适配 `.so`/`.pyd` 扩展名
|
|
40
|
+
- **可复现构建** — 通过 `--seed` 参数固定混淆随机种子
|
|
41
|
+
- **智能排除** — 自动跳过 `__init__.py`、虚拟环境、构建目录;支持 `# AutoCython No Compile` 标记豁免
|
|
42
|
+
- **中英双语** — CLI 帮助信息和进度面板自动适配系统语言
|
|
43
|
+
|
|
44
|
+
## 安装
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install AutoCython-zhang
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 依赖
|
|
51
|
+
|
|
52
|
+
| 包 | 用途 |
|
|
53
|
+
|---|------|
|
|
54
|
+
| `cython` | Python → C 编译核心 |
|
|
55
|
+
| `setuptools` | 构建扩展模块 |
|
|
56
|
+
| `rich` | 终端实时进度面板 |
|
|
57
|
+
|
|
58
|
+
## 使用方法
|
|
59
|
+
|
|
60
|
+
### 编译单文件
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
AutoCython -f demo.py
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 编译整个目录
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
AutoCython -p ./my_project
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 常用选项
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
AutoCython -p ./src -c 4 # 4 线程并发编译
|
|
76
|
+
AutoCython -f main.py -d # 编译后删除源文件
|
|
77
|
+
AutoCython -p ./src --seed 42 # 固定混淆种子(可复现)
|
|
78
|
+
AutoCython -v # 查看版本
|
|
79
|
+
AutoCython -h # 查看帮助
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### 排除文件
|
|
83
|
+
|
|
84
|
+
在文件头两行内添加注释即可跳过编译:
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
# AutoCython No Compile
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### 作为库调用
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from AutoCython.compile import compile_to_binary
|
|
94
|
+
|
|
95
|
+
# 编译单文件
|
|
96
|
+
output = compile_to_binary("demo.py", del_source=False, obfuscate=True, obfuscate_seed=42)
|
|
97
|
+
print(f"生成: {output}")
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## API 概览
|
|
101
|
+
|
|
102
|
+
### 核心函数
|
|
103
|
+
|
|
104
|
+
| 函数 | 模块 | 描述 |
|
|
105
|
+
|------|------|------|
|
|
106
|
+
| `compile()` | `AutoCython.AutoCython` | 主入口:解析参数并调度编译任务 |
|
|
107
|
+
| `compile_to_binary()` | `AutoCython.compile` | 将单个 `.py` 文件编译为二进制扩展 |
|
|
108
|
+
| `obfuscate_source()` | `AutoCython.obfuscate` | 对源码执行七重 AST 混淆变换 |
|
|
109
|
+
| `run_tasks()` | `AutoCython.run_tasks` | 并发任务执行引擎(含实时进度面板) |
|
|
110
|
+
| `find_python_files()` | `AutoCython.tools` | 递归扫描目录下的可编译 `.py` 文件 |
|
|
111
|
+
| `parse_arguments()` | `AutoCython.tools` | CLI 参数解析(中英双语) |
|
|
112
|
+
| `get_platform_extension()` | `AutoCython.compile` | 返回当前平台的二进制扩展名 |
|
|
113
|
+
| `get_system_language()` | `AutoCython.tools` | 检测系统语言(`zh`/`en`) |
|
|
114
|
+
|
|
115
|
+
## 目录结构
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
AutoCython/
|
|
119
|
+
├── AutoCython/
|
|
120
|
+
│ ├── __init__.py # 包入口,导出 compile() 和 main()
|
|
121
|
+
│ ├── _version.py # 单一版本号来源
|
|
122
|
+
│ ├── AutoCython.py # 主编译调度逻辑
|
|
123
|
+
│ ├── compile.py # Cython 编译核心(临时目录隔离)
|
|
124
|
+
│ ├── obfuscate.py # 七重 AST 混淆引擎
|
|
125
|
+
│ ├── run_tasks.py # 并发任务执行 + Rich 实时面板
|
|
126
|
+
│ └── tools.py # CLI 参数解析、文件扫描、国际化
|
|
127
|
+
├── tests/
|
|
128
|
+
│ ├── test_autocython.py # 主入口集成测试
|
|
129
|
+
│ ├── test_compile.py # 编译功能单元测试
|
|
130
|
+
│ ├── test_obfuscate.py # 混淆引擎单元测试
|
|
131
|
+
│ ├── test_obfuscate_advanced.py # 混淆高级场景测试
|
|
132
|
+
│ ├── test_obfuscate_anti.py # 混淆反模式/边界测试
|
|
133
|
+
│ ├── test_compile_anti.py # 编译反模式测试
|
|
134
|
+
│ ├── test_run_tasks.py # 任务执行器测试
|
|
135
|
+
│ ├── test_tools.py # 工具函数测试
|
|
136
|
+
│ └── kd_dist/ # 知识蒸馏测试集(编译矩阵 + 行为等价)
|
|
137
|
+
├── pyproject.toml # 项目配置与构建定义
|
|
138
|
+
├── requirements.txt # 依赖清单
|
|
139
|
+
├── LICENSE # MIT 许可证
|
|
140
|
+
└── DESIGN.md # 设计文档
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## 相关文档
|
|
144
|
+
|
|
145
|
+
- [设计文档](DESIGN.md)
|
|
146
|
+
- [PyPI 主页](https://pypi.org/project/AutoCython-zhang/)
|
|
147
|
+
- [GitHub 仓库](https://github.com/zhang0281/AutoCython)
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: AutoCython-zhang
|
|
3
|
+
Version: 2.3.2
|
|
4
|
+
Summary: 自动Cython,使用Cython批量编译.py文件为.pyd文件!
|
|
5
|
+
Author-email: zhang_gavin <qq814608@163.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: homepage, https://github.com/zhang0281/AutoCython
|
|
8
|
+
Project-URL: repository, https://github.com/zhang0281/AutoCython
|
|
9
|
+
Project-URL: documentation, https://github.com/zhang0281/AutoCython#readme
|
|
10
|
+
Keywords: cython,compile,pyd,pyc,python,autopyd
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Requires-Python: >=3.9
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: setuptools
|
|
17
|
+
Requires-Dist: cython
|
|
18
|
+
Requires-Dist: rich
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# AutoCython
|
|
22
|
+
|
|
23
|
+
> 自动将 Python 源码编译为 Cython 二进制扩展(`.so`/`.pyd`),支持七重 AST 混淆、并发编译、跨平台运行。
|
|
24
|
+
|
|
25
|
+
[](https://pypi.org/project/AutoCython-zhang/)
|
|
26
|
+
[](https://pypi.org/project/AutoCython-zhang/)
|
|
27
|
+
[](LICENSE)
|
|
28
|
+
|
|
29
|
+
## 概述
|
|
30
|
+
|
|
31
|
+
AutoCython 是一个 Python 源码保护工具,通过 Cython 编译 + AST 混淆双重手段,将 `.py` 文件转换为不可逆的二进制扩展模块。适用于商业项目源码保护、SDK 分发、知识产权保护等场景。
|
|
32
|
+
|
|
33
|
+
## 特性
|
|
34
|
+
|
|
35
|
+
- **一键编译** — 单文件 (`-f`) 或整目录 (`-p`) 批量编译为 `.so`/`.pyd`
|
|
36
|
+
- **七重 AST 混淆** — docstring 移除、注解清除、局部变量重命名、字符串 XOR 加密、常量折叠、控制流平坦化、虚假分支注入
|
|
37
|
+
- **并发编译** — 基于 `ThreadPoolExecutor` 的多线程并行编译,可配置并发数
|
|
38
|
+
- **实时进度面板** — 基于 Rich 的实时任务状态表格、进度条、耗时统计
|
|
39
|
+
- **跨平台** — 支持 Linux、macOS、Windows,自动适配 `.so`/`.pyd` 扩展名
|
|
40
|
+
- **可复现构建** — 通过 `--seed` 参数固定混淆随机种子
|
|
41
|
+
- **智能排除** — 自动跳过 `__init__.py`、虚拟环境、构建目录;支持 `# AutoCython No Compile` 标记豁免
|
|
42
|
+
- **中英双语** — CLI 帮助信息和进度面板自动适配系统语言
|
|
43
|
+
|
|
44
|
+
## 安装
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install AutoCython-zhang
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 依赖
|
|
51
|
+
|
|
52
|
+
| 包 | 用途 |
|
|
53
|
+
|---|------|
|
|
54
|
+
| `cython` | Python → C 编译核心 |
|
|
55
|
+
| `setuptools` | 构建扩展模块 |
|
|
56
|
+
| `rich` | 终端实时进度面板 |
|
|
57
|
+
|
|
58
|
+
## 使用方法
|
|
59
|
+
|
|
60
|
+
### 编译单文件
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
AutoCython -f demo.py
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 编译整个目录
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
AutoCython -p ./my_project
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 常用选项
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
AutoCython -p ./src -c 4 # 4 线程并发编译
|
|
76
|
+
AutoCython -f main.py -d # 编译后删除源文件
|
|
77
|
+
AutoCython -p ./src --seed 42 # 固定混淆种子(可复现)
|
|
78
|
+
AutoCython -v # 查看版本
|
|
79
|
+
AutoCython -h # 查看帮助
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### 排除文件
|
|
83
|
+
|
|
84
|
+
在文件头两行内添加注释即可跳过编译:
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
# AutoCython No Compile
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### 作为库调用
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from AutoCython.compile import compile_to_binary
|
|
94
|
+
|
|
95
|
+
# 编译单文件
|
|
96
|
+
output = compile_to_binary("demo.py", del_source=False, obfuscate=True, obfuscate_seed=42)
|
|
97
|
+
print(f"生成: {output}")
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## API 概览
|
|
101
|
+
|
|
102
|
+
### 核心函数
|
|
103
|
+
|
|
104
|
+
| 函数 | 模块 | 描述 |
|
|
105
|
+
|------|------|------|
|
|
106
|
+
| `compile()` | `AutoCython.AutoCython` | 主入口:解析参数并调度编译任务 |
|
|
107
|
+
| `compile_to_binary()` | `AutoCython.compile` | 将单个 `.py` 文件编译为二进制扩展 |
|
|
108
|
+
| `obfuscate_source()` | `AutoCython.obfuscate` | 对源码执行七重 AST 混淆变换 |
|
|
109
|
+
| `run_tasks()` | `AutoCython.run_tasks` | 并发任务执行引擎(含实时进度面板) |
|
|
110
|
+
| `find_python_files()` | `AutoCython.tools` | 递归扫描目录下的可编译 `.py` 文件 |
|
|
111
|
+
| `parse_arguments()` | `AutoCython.tools` | CLI 参数解析(中英双语) |
|
|
112
|
+
| `get_platform_extension()` | `AutoCython.compile` | 返回当前平台的二进制扩展名 |
|
|
113
|
+
| `get_system_language()` | `AutoCython.tools` | 检测系统语言(`zh`/`en`) |
|
|
114
|
+
|
|
115
|
+
## 目录结构
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
AutoCython/
|
|
119
|
+
├── AutoCython/
|
|
120
|
+
│ ├── __init__.py # 包入口,导出 compile() 和 main()
|
|
121
|
+
│ ├── _version.py # 单一版本号来源
|
|
122
|
+
│ ├── AutoCython.py # 主编译调度逻辑
|
|
123
|
+
│ ├── compile.py # Cython 编译核心(临时目录隔离)
|
|
124
|
+
│ ├── obfuscate.py # 七重 AST 混淆引擎
|
|
125
|
+
│ ├── run_tasks.py # 并发任务执行 + Rich 实时面板
|
|
126
|
+
│ └── tools.py # CLI 参数解析、文件扫描、国际化
|
|
127
|
+
├── tests/
|
|
128
|
+
│ ├── test_autocython.py # 主入口集成测试
|
|
129
|
+
│ ├── test_compile.py # 编译功能单元测试
|
|
130
|
+
│ ├── test_obfuscate.py # 混淆引擎单元测试
|
|
131
|
+
│ ├── test_obfuscate_advanced.py # 混淆高级场景测试
|
|
132
|
+
│ ├── test_obfuscate_anti.py # 混淆反模式/边界测试
|
|
133
|
+
│ ├── test_compile_anti.py # 编译反模式测试
|
|
134
|
+
│ ├── test_run_tasks.py # 任务执行器测试
|
|
135
|
+
│ ├── test_tools.py # 工具函数测试
|
|
136
|
+
│ └── kd_dist/ # 知识蒸馏测试集(编译矩阵 + 行为等价)
|
|
137
|
+
├── pyproject.toml # 项目配置与构建定义
|
|
138
|
+
├── requirements.txt # 依赖清单
|
|
139
|
+
├── LICENSE # MIT 许可证
|
|
140
|
+
└── DESIGN.md # 设计文档
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## 相关文档
|
|
144
|
+
|
|
145
|
+
- [设计文档](DESIGN.md)
|
|
146
|
+
- [PyPI 主页](https://pypi.org/project/AutoCython-zhang/)
|
|
147
|
+
- [GitHub 仓库](https://github.com/zhang0281/AutoCython)
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# AutoCython
|
|
2
|
+
|
|
3
|
+
> 自动将 Python 源码编译为 Cython 二进制扩展(`.so`/`.pyd`),支持七重 AST 混淆、并发编译、跨平台运行。
|
|
4
|
+
|
|
5
|
+
[](https://pypi.org/project/AutoCython-zhang/)
|
|
6
|
+
[](https://pypi.org/project/AutoCython-zhang/)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
|
|
9
|
+
## 概述
|
|
10
|
+
|
|
11
|
+
AutoCython 是一个 Python 源码保护工具,通过 Cython 编译 + AST 混淆双重手段,将 `.py` 文件转换为不可逆的二进制扩展模块。适用于商业项目源码保护、SDK 分发、知识产权保护等场景。
|
|
12
|
+
|
|
13
|
+
## 特性
|
|
14
|
+
|
|
15
|
+
- **一键编译** — 单文件 (`-f`) 或整目录 (`-p`) 批量编译为 `.so`/`.pyd`
|
|
16
|
+
- **七重 AST 混淆** — docstring 移除、注解清除、局部变量重命名、字符串 XOR 加密、常量折叠、控制流平坦化、虚假分支注入
|
|
17
|
+
- **并发编译** — 基于 `ThreadPoolExecutor` 的多线程并行编译,可配置并发数
|
|
18
|
+
- **实时进度面板** — 基于 Rich 的实时任务状态表格、进度条、耗时统计
|
|
19
|
+
- **跨平台** — 支持 Linux、macOS、Windows,自动适配 `.so`/`.pyd` 扩展名
|
|
20
|
+
- **可复现构建** — 通过 `--seed` 参数固定混淆随机种子
|
|
21
|
+
- **智能排除** — 自动跳过 `__init__.py`、虚拟环境、构建目录;支持 `# AutoCython No Compile` 标记豁免
|
|
22
|
+
- **中英双语** — CLI 帮助信息和进度面板自动适配系统语言
|
|
23
|
+
|
|
24
|
+
## 安装
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install AutoCython-zhang
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### 依赖
|
|
31
|
+
|
|
32
|
+
| 包 | 用途 |
|
|
33
|
+
|---|------|
|
|
34
|
+
| `cython` | Python → C 编译核心 |
|
|
35
|
+
| `setuptools` | 构建扩展模块 |
|
|
36
|
+
| `rich` | 终端实时进度面板 |
|
|
37
|
+
|
|
38
|
+
## 使用方法
|
|
39
|
+
|
|
40
|
+
### 编译单文件
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
AutoCython -f demo.py
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### 编译整个目录
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
AutoCython -p ./my_project
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 常用选项
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
AutoCython -p ./src -c 4 # 4 线程并发编译
|
|
56
|
+
AutoCython -f main.py -d # 编译后删除源文件
|
|
57
|
+
AutoCython -p ./src --seed 42 # 固定混淆种子(可复现)
|
|
58
|
+
AutoCython -v # 查看版本
|
|
59
|
+
AutoCython -h # 查看帮助
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### 排除文件
|
|
63
|
+
|
|
64
|
+
在文件头两行内添加注释即可跳过编译:
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
# AutoCython No Compile
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### 作为库调用
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from AutoCython.compile import compile_to_binary
|
|
74
|
+
|
|
75
|
+
# 编译单文件
|
|
76
|
+
output = compile_to_binary("demo.py", del_source=False, obfuscate=True, obfuscate_seed=42)
|
|
77
|
+
print(f"生成: {output}")
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## API 概览
|
|
81
|
+
|
|
82
|
+
### 核心函数
|
|
83
|
+
|
|
84
|
+
| 函数 | 模块 | 描述 |
|
|
85
|
+
|------|------|------|
|
|
86
|
+
| `compile()` | `AutoCython.AutoCython` | 主入口:解析参数并调度编译任务 |
|
|
87
|
+
| `compile_to_binary()` | `AutoCython.compile` | 将单个 `.py` 文件编译为二进制扩展 |
|
|
88
|
+
| `obfuscate_source()` | `AutoCython.obfuscate` | 对源码执行七重 AST 混淆变换 |
|
|
89
|
+
| `run_tasks()` | `AutoCython.run_tasks` | 并发任务执行引擎(含实时进度面板) |
|
|
90
|
+
| `find_python_files()` | `AutoCython.tools` | 递归扫描目录下的可编译 `.py` 文件 |
|
|
91
|
+
| `parse_arguments()` | `AutoCython.tools` | CLI 参数解析(中英双语) |
|
|
92
|
+
| `get_platform_extension()` | `AutoCython.compile` | 返回当前平台的二进制扩展名 |
|
|
93
|
+
| `get_system_language()` | `AutoCython.tools` | 检测系统语言(`zh`/`en`) |
|
|
94
|
+
|
|
95
|
+
## 目录结构
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
AutoCython/
|
|
99
|
+
├── AutoCython/
|
|
100
|
+
│ ├── __init__.py # 包入口,导出 compile() 和 main()
|
|
101
|
+
│ ├── _version.py # 单一版本号来源
|
|
102
|
+
│ ├── AutoCython.py # 主编译调度逻辑
|
|
103
|
+
│ ├── compile.py # Cython 编译核心(临时目录隔离)
|
|
104
|
+
│ ├── obfuscate.py # 七重 AST 混淆引擎
|
|
105
|
+
│ ├── run_tasks.py # 并发任务执行 + Rich 实时面板
|
|
106
|
+
│ └── tools.py # CLI 参数解析、文件扫描、国际化
|
|
107
|
+
├── tests/
|
|
108
|
+
│ ├── test_autocython.py # 主入口集成测试
|
|
109
|
+
│ ├── test_compile.py # 编译功能单元测试
|
|
110
|
+
│ ├── test_obfuscate.py # 混淆引擎单元测试
|
|
111
|
+
│ ├── test_obfuscate_advanced.py # 混淆高级场景测试
|
|
112
|
+
│ ├── test_obfuscate_anti.py # 混淆反模式/边界测试
|
|
113
|
+
│ ├── test_compile_anti.py # 编译反模式测试
|
|
114
|
+
│ ├── test_run_tasks.py # 任务执行器测试
|
|
115
|
+
│ ├── test_tools.py # 工具函数测试
|
|
116
|
+
│ └── kd_dist/ # 知识蒸馏测试集(编译矩阵 + 行为等价)
|
|
117
|
+
├── pyproject.toml # 项目配置与构建定义
|
|
118
|
+
├── requirements.txt # 依赖清单
|
|
119
|
+
├── LICENSE # MIT 许可证
|
|
120
|
+
└── DESIGN.md # 设计文档
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## 相关文档
|
|
124
|
+
|
|
125
|
+
- [设计文档](DESIGN.md)
|
|
126
|
+
- [PyPI 主页](https://pypi.org/project/AutoCython-zhang/)
|
|
127
|
+
- [GitHub 仓库](https://github.com/zhang0281/AutoCython)
|
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: AutoCython-zhang
|
|
3
|
-
Version: 2.3.1
|
|
4
|
-
Summary: 自动Cython,使用Cython批量编译.py文件为.pyd文件!
|
|
5
|
-
Author-email: zhang_gavin <qq814608@163.com>
|
|
6
|
-
License-Expression: MIT
|
|
7
|
-
Project-URL: homepage, https://github.com/zhang0281/AutoCython
|
|
8
|
-
Project-URL: repository, https://github.com/zhang0281/AutoCython
|
|
9
|
-
Project-URL: documentation, https://github.com/zhang0281/AutoCython#readme
|
|
10
|
-
Keywords: cython,compile,pyd,pyc,python,autopyd
|
|
11
|
-
Classifier: Programming Language :: Python :: 3
|
|
12
|
-
Classifier: Operating System :: OS Independent
|
|
13
|
-
Requires-Python: >=3.9
|
|
14
|
-
Description-Content-Type: text/markdown
|
|
15
|
-
License-File: LICENSE
|
|
16
|
-
Requires-Dist: setuptools
|
|
17
|
-
Requires-Dist: cython
|
|
18
|
-
Requires-Dist: rich
|
|
19
|
-
Dynamic: license-file
|
|
20
|
-
|
|
21
|
-
# AutoCython V2
|
|
22
|
-
|
|
23
|
-
**自动 Cython:一键将 Python 文件批量编译为 `PYD / SO` 二进制文件,内置 AST 七重混淆引擎**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
## ✨ 特性
|
|
27
|
-
|
|
28
|
-
- 单文件 / 目录批量编译
|
|
29
|
-
- 跨平台支持(Windows / Linux / macOS)
|
|
30
|
-
- AST 七重混淆引擎(可复现)
|
|
31
|
-
- Rich 实时进度 UI,中英文自动切换
|
|
32
|
-
- 编译后可选删除源码
|
|
33
|
-
- 自动 strip 符号表(Linux / macOS)
|
|
34
|
-
|
|
35
|
-
## 📦 安装
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
pip install -U AutoCython-zhang
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
要求 Python ≥ 3.9。
|
|
42
|
-
|
|
43
|
-
## ⚙️ 依赖环境
|
|
44
|
-
|
|
45
|
-
### C/C++ 编译器
|
|
46
|
-
|
|
47
|
-
| 平台 | 编译器 |
|
|
48
|
-
|------|--------|
|
|
49
|
-
| Windows | Visual Studio(MSVC) |
|
|
50
|
-
| Linux | gcc & g++ |
|
|
51
|
-
| macOS | clang(Xcode Command Line Tools) |
|
|
52
|
-
|
|
53
|
-
**重要提示**:编译器架构必须与 Python 解释器一致(64 位 Python 需 64 位编译器)
|
|
54
|
-
|
|
55
|
-
> 其他编译器配置请参考 [Cython](https://github.com/cython/cython) 项目
|
|
56
|
-
|
|
57
|
-
## 🚀 使用指南
|
|
58
|
-
|
|
59
|
-
### 命令行参数
|
|
60
|
-
|
|
61
|
-
| 参数 | 说明 | 默认值 |
|
|
62
|
-
|------|------|--------|
|
|
63
|
-
| `-f, --file` | 编译单个文件 | — |
|
|
64
|
-
| `-p, --path` | 编译目录下所有 `.py` 文件 | — |
|
|
65
|
-
| `-c, --conc` | 并发编译线程数 | 2 |
|
|
66
|
-
| `-d, --del` | 编译后删除源代码 | False |
|
|
67
|
-
| `--seed` | 混淆随机种子(可复现构建) | None |
|
|
68
|
-
| `-v, --version` | 显示版本号 | — |
|
|
69
|
-
| `-h, --help` | 显示帮助信息 | — |
|
|
70
|
-
|
|
71
|
-
> `-f` 和 `-p` 互斥,不可同时使用。
|
|
72
|
-
|
|
73
|
-
### 命令行示例
|
|
74
|
-
|
|
75
|
-
```bash
|
|
76
|
-
# 编译单个文件
|
|
77
|
-
AutoCython -f test.py
|
|
78
|
-
|
|
79
|
-
# 编译整个目录
|
|
80
|
-
AutoCython -p /path/to/project
|
|
81
|
-
|
|
82
|
-
# 编译后删除源代码
|
|
83
|
-
AutoCython -d -f test.py
|
|
84
|
-
AutoCython -d -p /path/to/project
|
|
85
|
-
|
|
86
|
-
# 4 线程并发编译
|
|
87
|
-
AutoCython -c 4 -p /path/to/project
|
|
88
|
-
|
|
89
|
-
# 指定混淆随机种子(可复现构建)
|
|
90
|
-
AutoCython --seed 2025 -f test.py
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
### 手动排除文件不编译
|
|
94
|
-
|
|
95
|
-
在文件 **前两行任意一行** 包含以下标记即可跳过编译:
|
|
96
|
-
|
|
97
|
-
```python
|
|
98
|
-
# AutoCython No Compile
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
> 兼容旧版拼写 `# AucoCython No Compile`
|
|
102
|
-
|
|
103
|
-
### 自动排除规则
|
|
104
|
-
|
|
105
|
-
以下文件和目录会被自动跳过:
|
|
106
|
-
|
|
107
|
-
- `__init__.py` 文件
|
|
108
|
-
- `__pycache__`、`venv`、`.venv`、`build`、`dist`、`node_modules`、`.git`、`.eggs` 目录
|
|
109
|
-
- `*.egg-info` 目录
|
|
110
|
-
|
|
111
|
-
## 🔐 AST 混淆引擎
|
|
112
|
-
|
|
113
|
-
编译前自动执行七重 AST 变换(按执行顺序),大幅提升逆向难度:
|
|
114
|
-
|
|
115
|
-
| 序号 | 变换 | 说明 | 安全跳过条件 |
|
|
116
|
-
|------|------|------|-------------|
|
|
117
|
-
| 1 | Docstring 移除 | 清除 module / class / function 的文档字符串 | 无 |
|
|
118
|
-
| 2 | Annotation 移除 | 清除函数参数、返回值、变量的类型注解 | 无 |
|
|
119
|
-
| 3 | 局部变量重命名 | 基于 hash 的标识符替换,保护闭包变量 | 含 `globals()`/`locals()`/`eval()`/`exec()`/`vars()` 调用 |
|
|
120
|
-
| 4 | 控制流平坦化 | 函数体转换为 `while True` + 状态机调度 | async 函数、yield/yield from、nonlocal/global 声明、comprehension、函数体 < 3 条语句、含不安全调用 |
|
|
121
|
-
| 5 | 虚假分支插入 | 30% 概率插入永真/永假不透明谓词 | 含不安全调用 |
|
|
122
|
-
| 6 | 字符串加密 | 字符串常量替换为 XOR 解密表达式 | 长度 ≤ 1 的字符串、f-string、`match/case` pattern 常量 |
|
|
123
|
-
| 7 | 常量折叠混淆 | 整数常量拆分为算术表达式 | 0、1、负数、> 10000 的整数、布尔值、`match/case` pattern 常量 |
|
|
124
|
-
|
|
125
|
-
> `ast.unparse()` 天然丢弃所有注释,无需额外处理。
|
|
126
|
-
|
|
127
|
-
使用 `--seed` 参数可固定随机种子,实现可复现混淆。
|
|
128
|
-
|
|
129
|
-
## 📚 Python API
|
|
130
|
-
|
|
131
|
-
```python
|
|
132
|
-
from AutoCython import compile # CLI 入口
|
|
133
|
-
from AutoCython.compile import compile_to_binary, get_platform_extension
|
|
134
|
-
from AutoCython.obfuscate import obfuscate_source
|
|
135
|
-
from AutoCython.run_tasks import run_tasks
|
|
136
|
-
from AutoCython.tools import find_python_files, get_system_language
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
### `compile_to_binary(file_path, del_source=False, obfuscate=True, obfuscate_seed=None)`
|
|
140
|
-
|
|
141
|
-
将单个 `.py` 文件编译为二进制扩展(`.pyd` / `.so`)。当 `obfuscate=True` 且混淆失败时,会抛出 `RuntimeError`,避免静默回退到原始源码。
|
|
142
|
-
|
|
143
|
-
```python
|
|
144
|
-
from AutoCython.compile import compile_to_binary
|
|
145
|
-
|
|
146
|
-
output = compile_to_binary("example.py")
|
|
147
|
-
print(output) # example.cpython-312-x86_64-linux-gnu.so
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
### `obfuscate_source(source_code, seed=None)`
|
|
151
|
-
|
|
152
|
-
对源码执行七重 AST 混淆变换,返回混淆后的源码字符串。
|
|
153
|
-
|
|
154
|
-
```python
|
|
155
|
-
from AutoCython.obfuscate import obfuscate_source
|
|
156
|
-
|
|
157
|
-
code = open("example.py").read()
|
|
158
|
-
obfuscated = obfuscate_source(code, seed=42)
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
### `run_tasks(task_list, max_workers=2, language=None, raise_on_failure=False)`
|
|
162
|
-
|
|
163
|
-
并发执行任务列表,实时显示 Rich 进度 UI。`task_list` 中每个元素为四元组 `(函数, 显示名称, 位置参数元组, 关键字参数字典)`。
|
|
164
|
-
|
|
165
|
-
```python
|
|
166
|
-
from AutoCython.run_tasks import run_tasks
|
|
167
|
-
|
|
168
|
-
tasks = [
|
|
169
|
-
(func, display_name, (arg1, arg2), {}),
|
|
170
|
-
]
|
|
171
|
-
summary = run_tasks(tasks, max_workers=4)
|
|
172
|
-
# summary = {"total": N, "succeeded": N, "failed": N, "elapsed": float, "tasks": [...]}
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
### `find_python_files(path)`
|
|
176
|
-
|
|
177
|
-
递归查找目录下所有可编译的 `.py` 文件(排除 `__init__.py` 和标记文件)。
|
|
178
|
-
|
|
179
|
-
```python
|
|
180
|
-
from AutoCython.tools import find_python_files
|
|
181
|
-
|
|
182
|
-
files = find_python_files("/path/to/project")
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
## 🧪 测试
|
|
186
|
-
|
|
187
|
-
```bash
|
|
188
|
-
# 运行全部测试
|
|
189
|
-
pytest
|
|
190
|
-
|
|
191
|
-
# 只运行单元测试
|
|
192
|
-
pytest -m unit
|
|
193
|
-
|
|
194
|
-
# 只运行集成测试 (kd_dist)
|
|
195
|
-
pytest -m integ
|
|
196
|
-
|
|
197
|
-
# 排除集成测试(快速验证)
|
|
198
|
-
pytest -m "not integ"
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
### kd-dist 集成测试
|
|
202
|
-
|
|
203
|
-
kd-dist 集成测试框架用于验证真实项目的编译兼容性和行为等价性。
|
|
204
|
-
|
|
205
|
-
```bash
|
|
206
|
-
# 指定真实项目根目录(未设置则自动探测)
|
|
207
|
-
export KD_DIST_ROOT=/path/to/kd-dist
|
|
208
|
-
|
|
209
|
-
# 开启严格文件计数阈值校验(默认关闭)
|
|
210
|
-
export KD_DIST_STRICT_COUNTS=1
|
|
211
|
-
|
|
212
|
-
# 输出 kd-dist 分层测试 JSON 报告
|
|
213
|
-
export KD_DIST_REPORT_PATH=.pytest_cache/kd_dist_report.json
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
| 测试标记 | 说明 |
|
|
217
|
-
|----------|------|
|
|
218
|
-
| `kd_compile_plain` | 纯编译矩阵测试 |
|
|
219
|
-
| `kd_compile_obfuscate` | 混淆编译矩阵测试 |
|
|
220
|
-
| `kd_behavior` | 行为等价性验证 |
|
|
221
|
-
|
|
222
|
-
配置文件:
|
|
223
|
-
- `tests/kd_dist/manifest.json` — import policy 与行为等价用例
|
|
224
|
-
- `tests/kd_dist/known_failures.json` — 已知 Cython 不兼容文件(xfail 治理)
|
|
225
|
-
|
|
226
|
-
## 📁 项目结构
|
|
227
|
-
|
|
228
|
-
```
|
|
229
|
-
AutoCython/
|
|
230
|
-
├── AutoCython/
|
|
231
|
-
│ ├── __init__.py # 版本导入 + main() 入口
|
|
232
|
-
│ ├── _version.py # 版本号定义
|
|
233
|
-
│ ├── AutoCython.py # CLI 编译入口
|
|
234
|
-
│ ├── compile.py # Cython 编译核心逻辑
|
|
235
|
-
│ ├── obfuscate.py # AST 七重混淆引擎
|
|
236
|
-
│ ├── run_tasks.py # 并发任务执行 + Rich UI
|
|
237
|
-
│ └── tools.py # 工具函数(参数解析、文件查找、国际化)
|
|
238
|
-
├── tests/
|
|
239
|
-
│ ├── test_autocython.py # CLI 入口测试
|
|
240
|
-
│ ├── test_compile.py # 编译模块测试
|
|
241
|
-
│ ├── test_obfuscate.py # 混淆模块测试
|
|
242
|
-
│ ├── test_run_tasks.py # 并发任务测试
|
|
243
|
-
│ ├── test_tools.py # 工具函数测试
|
|
244
|
-
│ └── kd_dist/ # kd-dist 集成测试框架
|
|
245
|
-
├── pyproject.toml # 项目配置
|
|
246
|
-
├── requirements.txt # 依赖清单
|
|
247
|
-
├── LICENSE # MIT 许可证
|
|
248
|
-
└── README.md
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
## ⚠️ 常见问题
|
|
252
|
-
|
|
253
|
-
| 问题 | 原因 | 解决方案 |
|
|
254
|
-
|------|------|----------|
|
|
255
|
-
| 编译失败 | 源码含 Cython 不支持的语法 | 查阅 [Cython Wiki](https://github.com/cython/cython/wiki) |
|
|
256
|
-
| 文件名不支持 | 含连字符等特殊字符 | 自动转下划线,或手动重命名 |
|
|
257
|
-
| 编译超时 | 单文件编译超过 300 秒 | 拆分大文件或检查死循环 |
|
|
258
|
-
| 混淆后运行异常 | 触发了不安全变换 | 使用 `# AutoCython No Compile` 排除该文件 |
|
|
259
|
-
|
|
260
|
-
## 📅 更新记录
|
|
261
|
-
|
|
262
|
-
### V2 版本
|
|
263
|
-
|
|
264
|
-
| 版本 | 日期 | 说明 |
|
|
265
|
-
|------|------|------|
|
|
266
|
-
| V2.3.0 | 2025 | 混淆测试集成 known failure 机制,更新构建和项目配置 |
|
|
267
|
-
| V2.1.0 | 2025-06-23 | 禁用激进性能优化选项,显示系统信息 |
|
|
268
|
-
| V2.0.0 | 2025-06-09 | 完全重构代码,使用新 UI |
|
|
269
|
-
|
|
270
|
-
### V1 版本
|
|
271
|
-
|
|
272
|
-
1. 20220613 — 新增 Linux 支持,需配置 gcc & g++
|
|
273
|
-
2. 20221123 — 支持文件头标记排除编译
|
|
274
|
-
3. 20230306 — 支持指定命令行头(如 `Python310`)以兼容非 Windows 编译
|
|
275
|
-
4. 20230324 — 文档更新
|
|
276
|
-
5. 20240506 — 修复编译失败时遗漏复原 `__init__.py` 的问题
|
|
277
|
-
|
|
278
|
-
## 📄 许可证
|
|
279
|
-
|
|
280
|
-
[MIT License](LICENSE)
|
autocython_zhang-2.3.1/PKG-INFO
DELETED
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: AutoCython-zhang
|
|
3
|
-
Version: 2.3.1
|
|
4
|
-
Summary: 自动Cython,使用Cython批量编译.py文件为.pyd文件!
|
|
5
|
-
Author-email: zhang_gavin <qq814608@163.com>
|
|
6
|
-
License-Expression: MIT
|
|
7
|
-
Project-URL: homepage, https://github.com/zhang0281/AutoCython
|
|
8
|
-
Project-URL: repository, https://github.com/zhang0281/AutoCython
|
|
9
|
-
Project-URL: documentation, https://github.com/zhang0281/AutoCython#readme
|
|
10
|
-
Keywords: cython,compile,pyd,pyc,python,autopyd
|
|
11
|
-
Classifier: Programming Language :: Python :: 3
|
|
12
|
-
Classifier: Operating System :: OS Independent
|
|
13
|
-
Requires-Python: >=3.9
|
|
14
|
-
Description-Content-Type: text/markdown
|
|
15
|
-
License-File: LICENSE
|
|
16
|
-
Requires-Dist: setuptools
|
|
17
|
-
Requires-Dist: cython
|
|
18
|
-
Requires-Dist: rich
|
|
19
|
-
Dynamic: license-file
|
|
20
|
-
|
|
21
|
-
# AutoCython V2
|
|
22
|
-
|
|
23
|
-
**自动 Cython:一键将 Python 文件批量编译为 `PYD / SO` 二进制文件,内置 AST 七重混淆引擎**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
## ✨ 特性
|
|
27
|
-
|
|
28
|
-
- 单文件 / 目录批量编译
|
|
29
|
-
- 跨平台支持(Windows / Linux / macOS)
|
|
30
|
-
- AST 七重混淆引擎(可复现)
|
|
31
|
-
- Rich 实时进度 UI,中英文自动切换
|
|
32
|
-
- 编译后可选删除源码
|
|
33
|
-
- 自动 strip 符号表(Linux / macOS)
|
|
34
|
-
|
|
35
|
-
## 📦 安装
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
pip install -U AutoCython-zhang
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
要求 Python ≥ 3.9。
|
|
42
|
-
|
|
43
|
-
## ⚙️ 依赖环境
|
|
44
|
-
|
|
45
|
-
### C/C++ 编译器
|
|
46
|
-
|
|
47
|
-
| 平台 | 编译器 |
|
|
48
|
-
|------|--------|
|
|
49
|
-
| Windows | Visual Studio(MSVC) |
|
|
50
|
-
| Linux | gcc & g++ |
|
|
51
|
-
| macOS | clang(Xcode Command Line Tools) |
|
|
52
|
-
|
|
53
|
-
**重要提示**:编译器架构必须与 Python 解释器一致(64 位 Python 需 64 位编译器)
|
|
54
|
-
|
|
55
|
-
> 其他编译器配置请参考 [Cython](https://github.com/cython/cython) 项目
|
|
56
|
-
|
|
57
|
-
## 🚀 使用指南
|
|
58
|
-
|
|
59
|
-
### 命令行参数
|
|
60
|
-
|
|
61
|
-
| 参数 | 说明 | 默认值 |
|
|
62
|
-
|------|------|--------|
|
|
63
|
-
| `-f, --file` | 编译单个文件 | — |
|
|
64
|
-
| `-p, --path` | 编译目录下所有 `.py` 文件 | — |
|
|
65
|
-
| `-c, --conc` | 并发编译线程数 | 2 |
|
|
66
|
-
| `-d, --del` | 编译后删除源代码 | False |
|
|
67
|
-
| `--seed` | 混淆随机种子(可复现构建) | None |
|
|
68
|
-
| `-v, --version` | 显示版本号 | — |
|
|
69
|
-
| `-h, --help` | 显示帮助信息 | — |
|
|
70
|
-
|
|
71
|
-
> `-f` 和 `-p` 互斥,不可同时使用。
|
|
72
|
-
|
|
73
|
-
### 命令行示例
|
|
74
|
-
|
|
75
|
-
```bash
|
|
76
|
-
# 编译单个文件
|
|
77
|
-
AutoCython -f test.py
|
|
78
|
-
|
|
79
|
-
# 编译整个目录
|
|
80
|
-
AutoCython -p /path/to/project
|
|
81
|
-
|
|
82
|
-
# 编译后删除源代码
|
|
83
|
-
AutoCython -d -f test.py
|
|
84
|
-
AutoCython -d -p /path/to/project
|
|
85
|
-
|
|
86
|
-
# 4 线程并发编译
|
|
87
|
-
AutoCython -c 4 -p /path/to/project
|
|
88
|
-
|
|
89
|
-
# 指定混淆随机种子(可复现构建)
|
|
90
|
-
AutoCython --seed 2025 -f test.py
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
### 手动排除文件不编译
|
|
94
|
-
|
|
95
|
-
在文件 **前两行任意一行** 包含以下标记即可跳过编译:
|
|
96
|
-
|
|
97
|
-
```python
|
|
98
|
-
# AutoCython No Compile
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
> 兼容旧版拼写 `# AucoCython No Compile`
|
|
102
|
-
|
|
103
|
-
### 自动排除规则
|
|
104
|
-
|
|
105
|
-
以下文件和目录会被自动跳过:
|
|
106
|
-
|
|
107
|
-
- `__init__.py` 文件
|
|
108
|
-
- `__pycache__`、`venv`、`.venv`、`build`、`dist`、`node_modules`、`.git`、`.eggs` 目录
|
|
109
|
-
- `*.egg-info` 目录
|
|
110
|
-
|
|
111
|
-
## 🔐 AST 混淆引擎
|
|
112
|
-
|
|
113
|
-
编译前自动执行七重 AST 变换(按执行顺序),大幅提升逆向难度:
|
|
114
|
-
|
|
115
|
-
| 序号 | 变换 | 说明 | 安全跳过条件 |
|
|
116
|
-
|------|------|------|-------------|
|
|
117
|
-
| 1 | Docstring 移除 | 清除 module / class / function 的文档字符串 | 无 |
|
|
118
|
-
| 2 | Annotation 移除 | 清除函数参数、返回值、变量的类型注解 | 无 |
|
|
119
|
-
| 3 | 局部变量重命名 | 基于 hash 的标识符替换,保护闭包变量 | 含 `globals()`/`locals()`/`eval()`/`exec()`/`vars()` 调用 |
|
|
120
|
-
| 4 | 控制流平坦化 | 函数体转换为 `while True` + 状态机调度 | async 函数、yield/yield from、nonlocal/global 声明、comprehension、函数体 < 3 条语句、含不安全调用 |
|
|
121
|
-
| 5 | 虚假分支插入 | 30% 概率插入永真/永假不透明谓词 | 含不安全调用 |
|
|
122
|
-
| 6 | 字符串加密 | 字符串常量替换为 XOR 解密表达式 | 长度 ≤ 1 的字符串、f-string、`match/case` pattern 常量 |
|
|
123
|
-
| 7 | 常量折叠混淆 | 整数常量拆分为算术表达式 | 0、1、负数、> 10000 的整数、布尔值、`match/case` pattern 常量 |
|
|
124
|
-
|
|
125
|
-
> `ast.unparse()` 天然丢弃所有注释,无需额外处理。
|
|
126
|
-
|
|
127
|
-
使用 `--seed` 参数可固定随机种子,实现可复现混淆。
|
|
128
|
-
|
|
129
|
-
## 📚 Python API
|
|
130
|
-
|
|
131
|
-
```python
|
|
132
|
-
from AutoCython import compile # CLI 入口
|
|
133
|
-
from AutoCython.compile import compile_to_binary, get_platform_extension
|
|
134
|
-
from AutoCython.obfuscate import obfuscate_source
|
|
135
|
-
from AutoCython.run_tasks import run_tasks
|
|
136
|
-
from AutoCython.tools import find_python_files, get_system_language
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
### `compile_to_binary(file_path, del_source=False, obfuscate=True, obfuscate_seed=None)`
|
|
140
|
-
|
|
141
|
-
将单个 `.py` 文件编译为二进制扩展(`.pyd` / `.so`)。当 `obfuscate=True` 且混淆失败时,会抛出 `RuntimeError`,避免静默回退到原始源码。
|
|
142
|
-
|
|
143
|
-
```python
|
|
144
|
-
from AutoCython.compile import compile_to_binary
|
|
145
|
-
|
|
146
|
-
output = compile_to_binary("example.py")
|
|
147
|
-
print(output) # example.cpython-312-x86_64-linux-gnu.so
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
### `obfuscate_source(source_code, seed=None)`
|
|
151
|
-
|
|
152
|
-
对源码执行七重 AST 混淆变换,返回混淆后的源码字符串。
|
|
153
|
-
|
|
154
|
-
```python
|
|
155
|
-
from AutoCython.obfuscate import obfuscate_source
|
|
156
|
-
|
|
157
|
-
code = open("example.py").read()
|
|
158
|
-
obfuscated = obfuscate_source(code, seed=42)
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
### `run_tasks(task_list, max_workers=2, language=None, raise_on_failure=False)`
|
|
162
|
-
|
|
163
|
-
并发执行任务列表,实时显示 Rich 进度 UI。`task_list` 中每个元素为四元组 `(函数, 显示名称, 位置参数元组, 关键字参数字典)`。
|
|
164
|
-
|
|
165
|
-
```python
|
|
166
|
-
from AutoCython.run_tasks import run_tasks
|
|
167
|
-
|
|
168
|
-
tasks = [
|
|
169
|
-
(func, display_name, (arg1, arg2), {}),
|
|
170
|
-
]
|
|
171
|
-
summary = run_tasks(tasks, max_workers=4)
|
|
172
|
-
# summary = {"total": N, "succeeded": N, "failed": N, "elapsed": float, "tasks": [...]}
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
### `find_python_files(path)`
|
|
176
|
-
|
|
177
|
-
递归查找目录下所有可编译的 `.py` 文件(排除 `__init__.py` 和标记文件)。
|
|
178
|
-
|
|
179
|
-
```python
|
|
180
|
-
from AutoCython.tools import find_python_files
|
|
181
|
-
|
|
182
|
-
files = find_python_files("/path/to/project")
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
## 🧪 测试
|
|
186
|
-
|
|
187
|
-
```bash
|
|
188
|
-
# 运行全部测试
|
|
189
|
-
pytest
|
|
190
|
-
|
|
191
|
-
# 只运行单元测试
|
|
192
|
-
pytest -m unit
|
|
193
|
-
|
|
194
|
-
# 只运行集成测试 (kd_dist)
|
|
195
|
-
pytest -m integ
|
|
196
|
-
|
|
197
|
-
# 排除集成测试(快速验证)
|
|
198
|
-
pytest -m "not integ"
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
### kd-dist 集成测试
|
|
202
|
-
|
|
203
|
-
kd-dist 集成测试框架用于验证真实项目的编译兼容性和行为等价性。
|
|
204
|
-
|
|
205
|
-
```bash
|
|
206
|
-
# 指定真实项目根目录(未设置则自动探测)
|
|
207
|
-
export KD_DIST_ROOT=/path/to/kd-dist
|
|
208
|
-
|
|
209
|
-
# 开启严格文件计数阈值校验(默认关闭)
|
|
210
|
-
export KD_DIST_STRICT_COUNTS=1
|
|
211
|
-
|
|
212
|
-
# 输出 kd-dist 分层测试 JSON 报告
|
|
213
|
-
export KD_DIST_REPORT_PATH=.pytest_cache/kd_dist_report.json
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
| 测试标记 | 说明 |
|
|
217
|
-
|----------|------|
|
|
218
|
-
| `kd_compile_plain` | 纯编译矩阵测试 |
|
|
219
|
-
| `kd_compile_obfuscate` | 混淆编译矩阵测试 |
|
|
220
|
-
| `kd_behavior` | 行为等价性验证 |
|
|
221
|
-
|
|
222
|
-
配置文件:
|
|
223
|
-
- `tests/kd_dist/manifest.json` — import policy 与行为等价用例
|
|
224
|
-
- `tests/kd_dist/known_failures.json` — 已知 Cython 不兼容文件(xfail 治理)
|
|
225
|
-
|
|
226
|
-
## 📁 项目结构
|
|
227
|
-
|
|
228
|
-
```
|
|
229
|
-
AutoCython/
|
|
230
|
-
├── AutoCython/
|
|
231
|
-
│ ├── __init__.py # 版本导入 + main() 入口
|
|
232
|
-
│ ├── _version.py # 版本号定义
|
|
233
|
-
│ ├── AutoCython.py # CLI 编译入口
|
|
234
|
-
│ ├── compile.py # Cython 编译核心逻辑
|
|
235
|
-
│ ├── obfuscate.py # AST 七重混淆引擎
|
|
236
|
-
│ ├── run_tasks.py # 并发任务执行 + Rich UI
|
|
237
|
-
│ └── tools.py # 工具函数(参数解析、文件查找、国际化)
|
|
238
|
-
├── tests/
|
|
239
|
-
│ ├── test_autocython.py # CLI 入口测试
|
|
240
|
-
│ ├── test_compile.py # 编译模块测试
|
|
241
|
-
│ ├── test_obfuscate.py # 混淆模块测试
|
|
242
|
-
│ ├── test_run_tasks.py # 并发任务测试
|
|
243
|
-
│ ├── test_tools.py # 工具函数测试
|
|
244
|
-
│ └── kd_dist/ # kd-dist 集成测试框架
|
|
245
|
-
├── pyproject.toml # 项目配置
|
|
246
|
-
├── requirements.txt # 依赖清单
|
|
247
|
-
├── LICENSE # MIT 许可证
|
|
248
|
-
└── README.md
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
## ⚠️ 常见问题
|
|
252
|
-
|
|
253
|
-
| 问题 | 原因 | 解决方案 |
|
|
254
|
-
|------|------|----------|
|
|
255
|
-
| 编译失败 | 源码含 Cython 不支持的语法 | 查阅 [Cython Wiki](https://github.com/cython/cython/wiki) |
|
|
256
|
-
| 文件名不支持 | 含连字符等特殊字符 | 自动转下划线,或手动重命名 |
|
|
257
|
-
| 编译超时 | 单文件编译超过 300 秒 | 拆分大文件或检查死循环 |
|
|
258
|
-
| 混淆后运行异常 | 触发了不安全变换 | 使用 `# AutoCython No Compile` 排除该文件 |
|
|
259
|
-
|
|
260
|
-
## 📅 更新记录
|
|
261
|
-
|
|
262
|
-
### V2 版本
|
|
263
|
-
|
|
264
|
-
| 版本 | 日期 | 说明 |
|
|
265
|
-
|------|------|------|
|
|
266
|
-
| V2.3.0 | 2025 | 混淆测试集成 known failure 机制,更新构建和项目配置 |
|
|
267
|
-
| V2.1.0 | 2025-06-23 | 禁用激进性能优化选项,显示系统信息 |
|
|
268
|
-
| V2.0.0 | 2025-06-09 | 完全重构代码,使用新 UI |
|
|
269
|
-
|
|
270
|
-
### V1 版本
|
|
271
|
-
|
|
272
|
-
1. 20220613 — 新增 Linux 支持,需配置 gcc & g++
|
|
273
|
-
2. 20221123 — 支持文件头标记排除编译
|
|
274
|
-
3. 20230306 — 支持指定命令行头(如 `Python310`)以兼容非 Windows 编译
|
|
275
|
-
4. 20230324 — 文档更新
|
|
276
|
-
5. 20240506 — 修复编译失败时遗漏复原 `__init__.py` 的问题
|
|
277
|
-
|
|
278
|
-
## 📄 许可证
|
|
279
|
-
|
|
280
|
-
[MIT License](LICENSE)
|
autocython_zhang-2.3.1/README.md
DELETED
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
# AutoCython V2
|
|
2
|
-
|
|
3
|
-
**自动 Cython:一键将 Python 文件批量编译为 `PYD / SO` 二进制文件,内置 AST 七重混淆引擎**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
## ✨ 特性
|
|
7
|
-
|
|
8
|
-
- 单文件 / 目录批量编译
|
|
9
|
-
- 跨平台支持(Windows / Linux / macOS)
|
|
10
|
-
- AST 七重混淆引擎(可复现)
|
|
11
|
-
- Rich 实时进度 UI,中英文自动切换
|
|
12
|
-
- 编译后可选删除源码
|
|
13
|
-
- 自动 strip 符号表(Linux / macOS)
|
|
14
|
-
|
|
15
|
-
## 📦 安装
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
pip install -U AutoCython-zhang
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
要求 Python ≥ 3.9。
|
|
22
|
-
|
|
23
|
-
## ⚙️ 依赖环境
|
|
24
|
-
|
|
25
|
-
### C/C++ 编译器
|
|
26
|
-
|
|
27
|
-
| 平台 | 编译器 |
|
|
28
|
-
|------|--------|
|
|
29
|
-
| Windows | Visual Studio(MSVC) |
|
|
30
|
-
| Linux | gcc & g++ |
|
|
31
|
-
| macOS | clang(Xcode Command Line Tools) |
|
|
32
|
-
|
|
33
|
-
**重要提示**:编译器架构必须与 Python 解释器一致(64 位 Python 需 64 位编译器)
|
|
34
|
-
|
|
35
|
-
> 其他编译器配置请参考 [Cython](https://github.com/cython/cython) 项目
|
|
36
|
-
|
|
37
|
-
## 🚀 使用指南
|
|
38
|
-
|
|
39
|
-
### 命令行参数
|
|
40
|
-
|
|
41
|
-
| 参数 | 说明 | 默认值 |
|
|
42
|
-
|------|------|--------|
|
|
43
|
-
| `-f, --file` | 编译单个文件 | — |
|
|
44
|
-
| `-p, --path` | 编译目录下所有 `.py` 文件 | — |
|
|
45
|
-
| `-c, --conc` | 并发编译线程数 | 2 |
|
|
46
|
-
| `-d, --del` | 编译后删除源代码 | False |
|
|
47
|
-
| `--seed` | 混淆随机种子(可复现构建) | None |
|
|
48
|
-
| `-v, --version` | 显示版本号 | — |
|
|
49
|
-
| `-h, --help` | 显示帮助信息 | — |
|
|
50
|
-
|
|
51
|
-
> `-f` 和 `-p` 互斥,不可同时使用。
|
|
52
|
-
|
|
53
|
-
### 命令行示例
|
|
54
|
-
|
|
55
|
-
```bash
|
|
56
|
-
# 编译单个文件
|
|
57
|
-
AutoCython -f test.py
|
|
58
|
-
|
|
59
|
-
# 编译整个目录
|
|
60
|
-
AutoCython -p /path/to/project
|
|
61
|
-
|
|
62
|
-
# 编译后删除源代码
|
|
63
|
-
AutoCython -d -f test.py
|
|
64
|
-
AutoCython -d -p /path/to/project
|
|
65
|
-
|
|
66
|
-
# 4 线程并发编译
|
|
67
|
-
AutoCython -c 4 -p /path/to/project
|
|
68
|
-
|
|
69
|
-
# 指定混淆随机种子(可复现构建)
|
|
70
|
-
AutoCython --seed 2025 -f test.py
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
### 手动排除文件不编译
|
|
74
|
-
|
|
75
|
-
在文件 **前两行任意一行** 包含以下标记即可跳过编译:
|
|
76
|
-
|
|
77
|
-
```python
|
|
78
|
-
# AutoCython No Compile
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
> 兼容旧版拼写 `# AucoCython No Compile`
|
|
82
|
-
|
|
83
|
-
### 自动排除规则
|
|
84
|
-
|
|
85
|
-
以下文件和目录会被自动跳过:
|
|
86
|
-
|
|
87
|
-
- `__init__.py` 文件
|
|
88
|
-
- `__pycache__`、`venv`、`.venv`、`build`、`dist`、`node_modules`、`.git`、`.eggs` 目录
|
|
89
|
-
- `*.egg-info` 目录
|
|
90
|
-
|
|
91
|
-
## 🔐 AST 混淆引擎
|
|
92
|
-
|
|
93
|
-
编译前自动执行七重 AST 变换(按执行顺序),大幅提升逆向难度:
|
|
94
|
-
|
|
95
|
-
| 序号 | 变换 | 说明 | 安全跳过条件 |
|
|
96
|
-
|------|------|------|-------------|
|
|
97
|
-
| 1 | Docstring 移除 | 清除 module / class / function 的文档字符串 | 无 |
|
|
98
|
-
| 2 | Annotation 移除 | 清除函数参数、返回值、变量的类型注解 | 无 |
|
|
99
|
-
| 3 | 局部变量重命名 | 基于 hash 的标识符替换,保护闭包变量 | 含 `globals()`/`locals()`/`eval()`/`exec()`/`vars()` 调用 |
|
|
100
|
-
| 4 | 控制流平坦化 | 函数体转换为 `while True` + 状态机调度 | async 函数、yield/yield from、nonlocal/global 声明、comprehension、函数体 < 3 条语句、含不安全调用 |
|
|
101
|
-
| 5 | 虚假分支插入 | 30% 概率插入永真/永假不透明谓词 | 含不安全调用 |
|
|
102
|
-
| 6 | 字符串加密 | 字符串常量替换为 XOR 解密表达式 | 长度 ≤ 1 的字符串、f-string、`match/case` pattern 常量 |
|
|
103
|
-
| 7 | 常量折叠混淆 | 整数常量拆分为算术表达式 | 0、1、负数、> 10000 的整数、布尔值、`match/case` pattern 常量 |
|
|
104
|
-
|
|
105
|
-
> `ast.unparse()` 天然丢弃所有注释,无需额外处理。
|
|
106
|
-
|
|
107
|
-
使用 `--seed` 参数可固定随机种子,实现可复现混淆。
|
|
108
|
-
|
|
109
|
-
## 📚 Python API
|
|
110
|
-
|
|
111
|
-
```python
|
|
112
|
-
from AutoCython import compile # CLI 入口
|
|
113
|
-
from AutoCython.compile import compile_to_binary, get_platform_extension
|
|
114
|
-
from AutoCython.obfuscate import obfuscate_source
|
|
115
|
-
from AutoCython.run_tasks import run_tasks
|
|
116
|
-
from AutoCython.tools import find_python_files, get_system_language
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
### `compile_to_binary(file_path, del_source=False, obfuscate=True, obfuscate_seed=None)`
|
|
120
|
-
|
|
121
|
-
将单个 `.py` 文件编译为二进制扩展(`.pyd` / `.so`)。当 `obfuscate=True` 且混淆失败时,会抛出 `RuntimeError`,避免静默回退到原始源码。
|
|
122
|
-
|
|
123
|
-
```python
|
|
124
|
-
from AutoCython.compile import compile_to_binary
|
|
125
|
-
|
|
126
|
-
output = compile_to_binary("example.py")
|
|
127
|
-
print(output) # example.cpython-312-x86_64-linux-gnu.so
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
### `obfuscate_source(source_code, seed=None)`
|
|
131
|
-
|
|
132
|
-
对源码执行七重 AST 混淆变换,返回混淆后的源码字符串。
|
|
133
|
-
|
|
134
|
-
```python
|
|
135
|
-
from AutoCython.obfuscate import obfuscate_source
|
|
136
|
-
|
|
137
|
-
code = open("example.py").read()
|
|
138
|
-
obfuscated = obfuscate_source(code, seed=42)
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
### `run_tasks(task_list, max_workers=2, language=None, raise_on_failure=False)`
|
|
142
|
-
|
|
143
|
-
并发执行任务列表,实时显示 Rich 进度 UI。`task_list` 中每个元素为四元组 `(函数, 显示名称, 位置参数元组, 关键字参数字典)`。
|
|
144
|
-
|
|
145
|
-
```python
|
|
146
|
-
from AutoCython.run_tasks import run_tasks
|
|
147
|
-
|
|
148
|
-
tasks = [
|
|
149
|
-
(func, display_name, (arg1, arg2), {}),
|
|
150
|
-
]
|
|
151
|
-
summary = run_tasks(tasks, max_workers=4)
|
|
152
|
-
# summary = {"total": N, "succeeded": N, "failed": N, "elapsed": float, "tasks": [...]}
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
### `find_python_files(path)`
|
|
156
|
-
|
|
157
|
-
递归查找目录下所有可编译的 `.py` 文件(排除 `__init__.py` 和标记文件)。
|
|
158
|
-
|
|
159
|
-
```python
|
|
160
|
-
from AutoCython.tools import find_python_files
|
|
161
|
-
|
|
162
|
-
files = find_python_files("/path/to/project")
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
## 🧪 测试
|
|
166
|
-
|
|
167
|
-
```bash
|
|
168
|
-
# 运行全部测试
|
|
169
|
-
pytest
|
|
170
|
-
|
|
171
|
-
# 只运行单元测试
|
|
172
|
-
pytest -m unit
|
|
173
|
-
|
|
174
|
-
# 只运行集成测试 (kd_dist)
|
|
175
|
-
pytest -m integ
|
|
176
|
-
|
|
177
|
-
# 排除集成测试(快速验证)
|
|
178
|
-
pytest -m "not integ"
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
### kd-dist 集成测试
|
|
182
|
-
|
|
183
|
-
kd-dist 集成测试框架用于验证真实项目的编译兼容性和行为等价性。
|
|
184
|
-
|
|
185
|
-
```bash
|
|
186
|
-
# 指定真实项目根目录(未设置则自动探测)
|
|
187
|
-
export KD_DIST_ROOT=/path/to/kd-dist
|
|
188
|
-
|
|
189
|
-
# 开启严格文件计数阈值校验(默认关闭)
|
|
190
|
-
export KD_DIST_STRICT_COUNTS=1
|
|
191
|
-
|
|
192
|
-
# 输出 kd-dist 分层测试 JSON 报告
|
|
193
|
-
export KD_DIST_REPORT_PATH=.pytest_cache/kd_dist_report.json
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
| 测试标记 | 说明 |
|
|
197
|
-
|----------|------|
|
|
198
|
-
| `kd_compile_plain` | 纯编译矩阵测试 |
|
|
199
|
-
| `kd_compile_obfuscate` | 混淆编译矩阵测试 |
|
|
200
|
-
| `kd_behavior` | 行为等价性验证 |
|
|
201
|
-
|
|
202
|
-
配置文件:
|
|
203
|
-
- `tests/kd_dist/manifest.json` — import policy 与行为等价用例
|
|
204
|
-
- `tests/kd_dist/known_failures.json` — 已知 Cython 不兼容文件(xfail 治理)
|
|
205
|
-
|
|
206
|
-
## 📁 项目结构
|
|
207
|
-
|
|
208
|
-
```
|
|
209
|
-
AutoCython/
|
|
210
|
-
├── AutoCython/
|
|
211
|
-
│ ├── __init__.py # 版本导入 + main() 入口
|
|
212
|
-
│ ├── _version.py # 版本号定义
|
|
213
|
-
│ ├── AutoCython.py # CLI 编译入口
|
|
214
|
-
│ ├── compile.py # Cython 编译核心逻辑
|
|
215
|
-
│ ├── obfuscate.py # AST 七重混淆引擎
|
|
216
|
-
│ ├── run_tasks.py # 并发任务执行 + Rich UI
|
|
217
|
-
│ └── tools.py # 工具函数(参数解析、文件查找、国际化)
|
|
218
|
-
├── tests/
|
|
219
|
-
│ ├── test_autocython.py # CLI 入口测试
|
|
220
|
-
│ ├── test_compile.py # 编译模块测试
|
|
221
|
-
│ ├── test_obfuscate.py # 混淆模块测试
|
|
222
|
-
│ ├── test_run_tasks.py # 并发任务测试
|
|
223
|
-
│ ├── test_tools.py # 工具函数测试
|
|
224
|
-
│ └── kd_dist/ # kd-dist 集成测试框架
|
|
225
|
-
├── pyproject.toml # 项目配置
|
|
226
|
-
├── requirements.txt # 依赖清单
|
|
227
|
-
├── LICENSE # MIT 许可证
|
|
228
|
-
└── README.md
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
## ⚠️ 常见问题
|
|
232
|
-
|
|
233
|
-
| 问题 | 原因 | 解决方案 |
|
|
234
|
-
|------|------|----------|
|
|
235
|
-
| 编译失败 | 源码含 Cython 不支持的语法 | 查阅 [Cython Wiki](https://github.com/cython/cython/wiki) |
|
|
236
|
-
| 文件名不支持 | 含连字符等特殊字符 | 自动转下划线,或手动重命名 |
|
|
237
|
-
| 编译超时 | 单文件编译超过 300 秒 | 拆分大文件或检查死循环 |
|
|
238
|
-
| 混淆后运行异常 | 触发了不安全变换 | 使用 `# AutoCython No Compile` 排除该文件 |
|
|
239
|
-
|
|
240
|
-
## 📅 更新记录
|
|
241
|
-
|
|
242
|
-
### V2 版本
|
|
243
|
-
|
|
244
|
-
| 版本 | 日期 | 说明 |
|
|
245
|
-
|------|------|------|
|
|
246
|
-
| V2.3.0 | 2025 | 混淆测试集成 known failure 机制,更新构建和项目配置 |
|
|
247
|
-
| V2.1.0 | 2025-06-23 | 禁用激进性能优化选项,显示系统信息 |
|
|
248
|
-
| V2.0.0 | 2025-06-09 | 完全重构代码,使用新 UI |
|
|
249
|
-
|
|
250
|
-
### V1 版本
|
|
251
|
-
|
|
252
|
-
1. 20220613 — 新增 Linux 支持,需配置 gcc & g++
|
|
253
|
-
2. 20221123 — 支持文件头标记排除编译
|
|
254
|
-
3. 20230306 — 支持指定命令行头(如 `Python310`)以兼容非 Windows 编译
|
|
255
|
-
4. 20230324 — 文档更新
|
|
256
|
-
5. 20240506 — 修复编译失败时遗漏复原 `__init__.py` 的问题
|
|
257
|
-
|
|
258
|
-
## 📄 许可证
|
|
259
|
-
|
|
260
|
-
[MIT License](LICENSE)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{autocython_zhang-2.3.1 → autocython_zhang-2.3.2}/AutoCython_zhang.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{autocython_zhang-2.3.1 → autocython_zhang-2.3.2}/AutoCython_zhang.egg-info/entry_points.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|