Skip to content

Commit c482ae7

Browse files
committed
fix CI: Limit GitHub Actions' Python matrix to 3.10+, since using match syntax
1 parent 7bcda60 commit c482ae7

9 files changed

Lines changed: 61 additions & 49 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
16+
python-version: ['3.10', '3.11', '3.12']
1717

1818
steps:
1919
- uses: actions/checkout@v4
@@ -26,7 +26,7 @@ jobs:
2626
- name: Install dependencies
2727
run: |
2828
python -m pip install --upgrade pip
29-
pip install -e .[test]
29+
pip install -e .[dev]
3030
3131
- name: Lint with flake8
3232
run: |

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
## [0.1.0] - 2026-01-08
1111

1212
### Added
13+
1314
- Python code obfuscation with AST-based transformation
1415
- Variable, function, and class name obfuscation
1516
- Docstring obfuscation
1617
- Smart identifier classification (preserves imports and built-ins)
1718
- **Lossless restoration** via embedded source chunks
1819
- Embedded metadata support for key-free restoration
19-
20+
2021
- C code obfuscation with regex-based tokenization
2122
- Identifier renaming (variables, functions, structs)
2223
- Comment scrambling
@@ -43,6 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4344
- Support for both Python 3.8+ and C code
4445

4546
### Technical Details
47+
4648
- Lossless restoration uses zlib compression + base64 encoding
4749
- Source chunks distributed as comments (`#@mistode:chunk:` for Python, `// @mistode:chunk:` for C)
4850
- Metadata embedded as `#@mistode:metadata:` or `/* @mistode:metadata: */`

CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@ Thank you for your interest in the Mistode project! We welcome contributions of
55
## Development Environment Setup
66

77
1. Clone the project:
8+
89
```shell
910
git clone https://github.com/for13to1/mistode.git
1011
cd mistode
1112
```
1213

1314
2. Install development dependencies:
15+
1416
```shell
1517
pip install -e ".[dev]"
1618
```
1719

1820
3. Run tests:
21+
1922
```shell
2023
pytest tests/ -v
2124
```

CONTRIBUTING_ZH.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@
55
## 开发环境设置
66

77
1. 克隆项目:
8+
89
```shell
910
git clone https://github.com/for13to1/mistode.git
1011
cd mistode
1112
```
1213

1314
2. 安装开发依赖:
15+
1416
```shell
1517
pip install -e ".[dev]"
1618
```
1719

1820
3. 运行测试:
21+
1922
```shell
2023
pytest tests/ -v
2124
```
@@ -48,4 +51,4 @@
4851
1. 确保所有测试通过
4952
2. 添加新功能的测试用例
5053
3. 更新文档
51-
4. 遵循现有的代码风格
54+
4. 遵循现有的代码风格

README.md

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,24 @@ Mistode (Mist Code, pronounced like "Miss Told") is a lightweight code obfuscati
1111
## Features
1212

1313
- **Encrypted Token Generator**: Highly customizable encrypted token generation supporting various configurations:
14-
- **Random Seed**: Supports setting a random seed to ensure reproducibility.
15-
- **Length Control**: Custom token length, range [8, 32] characters.
16-
- **Style Configuration**: Supports two obfuscation styles:
17-
- **Similar Character Style**: Uses visually similar character groups to enhance obfuscation (e.g., `Oo0`, `iIlL1`, `b6B8`, `Zz2`, `Ss5`).
18-
- **Random Character Style**: Uses random alphanumeric combinations.
19-
- **Smart Deduplication**: Automatically maintains a set of generated tokens to avoid duplicates.
20-
- **Safe First Character**: Ensures the first character is not a digit, complying with naming conventions.
14+
- **Random Seed**: Supports setting a random seed to ensure reproducibility.
15+
- **Length Control**: Custom token length, range [8, 32] characters.
16+
- **Style Configuration**: Supports two obfuscation styles:
17+
- **Similar Character Style**: Uses visually similar character groups to enhance obfuscation (e.g., `Oo0`, `iIlL1`, `b6B8`, `Zz2`, `Ss5`).
18+
- **Random Character Style**: Uses random alphanumeric combinations.
19+
- **Smart Deduplication**: Automatically maintains a set of generated tokens to avoid duplicates.
20+
- **Safe First Character**: Ensures the first character is not a digit, complying with naming conventions.
2121
- **Python Support**:
22-
- **AST Parsing**: Accurate obfuscation based on Abstract Syntax Trees, ensuring complete preservation of code format.
23-
- **Smart Identifier Classification**: Automatically identifies and preserves imported modules, functions, and built-in methods.
24-
- **Docstring Obfuscation**: Replaces docstrings with hash values.
25-
- **Fully Reversible**: Supports full restoration using generated key files or embedded metadata.
26-
- **Lossless Restoration**: Achieves lossless consistency with the original file (preserving all comments and formatting) via distributed annotated injection of source chunks.
22+
- **AST Parsing**: Accurate obfuscation based on Abstract Syntax Trees, ensuring complete preservation of code format.
23+
- **Smart Identifier Classification**: Automatically identifies and preserves imported modules, functions, and built-in methods.
24+
- **Docstring Obfuscation**: Replaces docstrings with hash values.
25+
- **Fully Reversible**: Supports full restoration using generated key files or embedded metadata.
26+
- **Lossless Restoration**: Achieves lossless consistency with the original file (preserving all comments and formatting) via distributed annotated injection of source chunks.
2727
- **C Support**:
28-
- **Fast Tokenization**: Uses robust regular expression tokenizers.
29-
- **Comment Obfuscation**: Obfuscates `//` and `/* */` comment content.
30-
- **Compilation Safety**: Preserves keywords, preprocessor directives, and string literals (ensuring safety).
31-
- **Lossless Restoration**: Achieves lossless consistency with the original file via distributed annotated injection of source chunks.
28+
- **Fast Tokenization**: Uses robust regular expression tokenizers.
29+
- **Comment Obfuscation**: Obfuscates `//` and `/* */` comment content.
30+
- **Compilation Safety**: Preserves keywords, preprocessor directives, and string literals (ensuring safety).
31+
- **Lossless Restoration**: Achieves lossless consistency with the original file via distributed annotated injection of source chunks.
3232

3333
## Installation
3434

@@ -73,6 +73,7 @@ Mistode intelligently identifies and avoids obfuscating the following types of i
7373
### Example
7474

7575
**Original Code**:
76+
7677
```python
7778
import re
7879
from openpyxl.utils import get_column_letter, column_index_from_string
@@ -85,6 +86,7 @@ def shift_column_letter(base_column, offset):
8586
```
8687

8788
**Obfuscated Code**:
89+
8890
```python
8991
import re
9092
from openpyxl.utils import get_column_letter, column_index_from_string
@@ -103,8 +105,8 @@ def Oo0iIlL1b6B8Zz2Ss5(Oo0iIlL1b6B8Zz2Ss6, Oo0iIlL1b6B8Zz2Ss7):
103105

104106
Mistode uses a two-layer restoration mechanism:
105107

106-
1. **Distributed Source Chunks (`#@mistode:chunk:` or `// @mistode:chunk:`)**: The original source code is compressed, encoded, and injected as chunks before each line of the obfuscated code. Restoration prioritizes these chunks to reconstruct the original code, achieving **lossless restoration** (including all comments, empty lines, and formatting).
107-
2. **Embedded Metadata (`#@mistode:metadata:`)**: Contains the identifier mapping table as a backup restoration method.
108+
1. **Distributed Source Chunks (`#@mistode:chunk:` or `// @mistode:chunk:`)**: The original source code is compressed, encoded, and injected as chunks before each line of the obfuscated code. Restoration prioritizes these chunks to reconstruct the original code, achieving **lossless restoration** (including all comments, empty lines, and formatting).
109+
2. **Embedded Metadata (`#@mistode:metadata:`)**: Contains the identifier mapping table as a backup restoration method.
108110

109111
This means you can perfectly restore the original code even without keeping the key file.
110112

@@ -119,7 +121,7 @@ If no key file is provided, the restore command automatically detects and uses t
119121

120122
## Project Structure
121123

122-
```
124+
```shell
123125
mistode/
124126
├── src/
125127
│ └── mistode/

README_ZH.md

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,24 @@ Mistode (Mist Code, pronounced like "Miss Told") 是一个轻量级的代码混
1111
## 特性
1212

1313
- **加密token生成器**: 高度可定制的加密token生成,支持多种配置:
14-
- **随机种子**:支持设置随机种子,确保生成结果的可重现性
15-
- **长度控制**:自定义token长度,范围[8,32]字符
16-
- **风格配置**:支持两种混淆风格
17-
- **近似字符风格**:使用易混淆字符组增强混淆效果(如:`Oo0`, `iIlL1`, `b6B8`, `Zz2`, `Ss5`
18-
- **随机字符风格**:使用随机字母数字组合
19-
- **智能去重机制**:自动维护已生成token集合,避免重复
20-
- **首字符安全**:确保首字符不是数字,符合编程规范
14+
- **随机种子**:支持设置随机种子,确保生成结果的可重现性
15+
- **长度控制**:自定义token长度,范围[8,32]字符
16+
- **风格配置**:支持两种混淆风格
17+
- **近似字符风格**:使用易混淆字符组增强混淆效果(如:`Oo0`, `iIlL1`, `b6B8`, `Zz2`, `Ss5`
18+
- **随机字符风格**:使用随机字母数字组合
19+
- **智能去重机制**:自动维护已生成token集合,避免重复
20+
- **首字符安全**:确保首字符不是数字,符合编程规范
2121
- **Python 支持**:
22-
- **AST 解析**: 基于抽象语法树的精确混淆,确保代码格式完全保留
23-
- **智能标识符分类**: 自动识别并保留导入的模块、函数和内置方法
24-
- **文档字符串混淆**: 将文档字符串替换为哈希值
25-
- **完全可逆**: 支持使用生成的密钥文件或嵌入的元数据完全恢复
26-
- **无损还原 (Lossless Restoration)**: 通过分布式注释注入原始源代码,实现与原文件一致的无损还原(保留所有注释和格式)
22+
- **AST 解析**: 基于抽象语法树的精确混淆,确保代码格式完全保留
23+
- **智能标识符分类**: 自动识别并保留导入的模块、函数和内置方法
24+
- **文档字符串混淆**: 将文档字符串替换为哈希值
25+
- **完全可逆**: 支持使用生成的密钥文件或嵌入的元数据完全恢复
26+
- **无损还原 (Lossless Restoration)**: 通过分布式注释注入原始源代码,实现与原文件一致的无损还原(保留所有注释和格式)
2727
- **C 支持**:
28-
- **快速分词**: 使用健壮的正则表达式分词器
29-
- **注释混淆**: 混淆 `//``/* */` 注释内容
30-
- **编译安全**: 保留关键字、预处理指令和字符串字面量(确保安全)
31-
- **无损还原 (Lossless Restoration)**: 通过分布式注释注入原始源代码,实现与原文件一致的无损还原
28+
- **快速分词**: 使用健壮的正则表达式分词器
29+
- **注释混淆**: 混淆 `//``/* */` 注释内容
30+
- **编译安全**: 保留关键字、预处理指令和字符串字面量(确保安全)
31+
- **无损还原 (Lossless Restoration)**: 通过分布式注释注入原始源代码,实现与原文件一致的无损还原
3232

3333
## 安装
3434

@@ -66,13 +66,14 @@ mistode restore output.py --out restored.py --key mapping.json
6666
Mistode 能够智能识别以下类型的标识符并避免混淆:
6767

6868
- **内置模块**: `re`, `os`, `sys`, `json`, `math`
69-
- **内置函数**: `print`, `len`, `range`, `str`, `int`
69+
- **内置函数**: `print`, `len`, `range`, `str`, `int`
7070
- **导入的函数**: 从 `import``from ... import` 语句中导入的函数
7171
- **内置方法**: `re.sub`, `str.strip`, `list.append`
7272

7373
### 示例
7474

7575
**原始代码**:
76+
7677
```python
7778
import re
7879
from openpyxl.utils import get_column_letter, column_index_from_string
@@ -85,6 +86,7 @@ def shift_column_letter(base_column, offset):
8586
```
8687

8788
**混淆后的代码**:
89+
8890
```python
8991
import re
9092
from openpyxl.utils import get_column_letter, column_index_from_string
@@ -103,10 +105,11 @@ def Oo0iIlL1b6B8Zz2Ss5(Oo0iIlL1b6B8Zz2Ss6, Oo0iIlL1b6B8Zz2Ss7):
103105

104106
Mistode 采用两层恢复机制:
105107

106-
1. **分布式源码块 (`#@mistode:chunk:``// @mistode:chunk:`)**: 将原始源代码压缩、编码并分块注入到混淆代码的每一行之前。恢复时优先使用这些块重组原始代码,实现**无损还原**(包括所有注释、空行和格式)。
107-
2. **嵌入式元数据 (`#@mistode:metadata:`)**: 包含标识符映射表,作为备用恢复手段。
108+
1. **分布式源码块 (`#@mistode:chunk:``// @mistode:chunk:`)**: 将原始源代码压缩、编码并分块注入到混淆代码的每一行之前。恢复时优先使用这些块重组原始代码,实现**无损还原**(包括所有注释、空行和格式)。
109+
2. **嵌入式元数据 (`#@mistode:metadata:`)**: 包含标识符映射表,作为备用恢复手段。
108110

109111
这意味着即使不保留密钥文件,您也可以完美恢复原始代码。
112+
110113
```python
111114
# ... 混淆后的代码 ...
112115
#@mistode:chunk:eJzjSk... (分布式源码块)
@@ -118,7 +121,7 @@ Mistode 采用两层恢复机制:
118121

119122
## 项目结构
120123

121-
```
124+
```shell
122125
mistode/
123126
├── src/
124127
│ └── mistode/

SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
If you discover a security vulnerability, please report it via the following methods:
66

77
- **Do NOT** report security issues in public Issues.
8-
- Please contact the maintainer via email: for13to1@outlook.com
8+
- Please contact the maintainer via email: <for13to1@outlook.com>
99

1010
## Response Time
1111

SECURITY_ZH.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
如果您发现安全漏洞,请通过以下方式报告:
66

77
- **不要**在公开的 Issues 中报告安全问题
8-
- 请通过电子邮件联系维护者:for13to1@outlook.com
8+
- 请通过电子邮件联系维护者:<for13to1@outlook.com>
99

1010
## 响应时间
1111

@@ -35,4 +35,4 @@
3535
1. **生产环境使用**:在部署到生产环境前充分测试混淆后的代码
3636
2. **备份原始代码**:始终保留原始代码的备份
3737
3. **版本控制**:将混淆后的代码和映射文件纳入版本控制
38-
4. **安全审计**:定期审计混淆后的代码以确保安全性
38+
4. **安全审计**:定期审计混淆后的代码以确保安全性

src/mistode/c.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,8 @@ def obfuscate(self, source_code: str) -> str:
440440
"encryption_key": self.mm.encryption_key,
441441
"string_quote_types": self.mm.string_quote_types,
442442
}
443-
encoded = base64.b64encode(
444-
json.dumps(mapping_info).encode("utf-8")
445-
).decode("utf-8")
443+
json_bytes = json.dumps(mapping_info).encode("utf-8")
444+
encoded = base64.b64encode(json_bytes).decode("utf-8")
446445

447446
# 4. Inject Original Source (Lossless restoration)
448447
obfuscated_text = "".join(output)

0 commit comments

Comments
 (0)