Skip to content

Commit df03793

Browse files
committed
release v0.1.1: Add CLI improvements and configuration support
- Add --version and --stats flags - Add pyproject.toml configuration file support - Add examples directory with Python/C samples - Enhance error messages with helpful hints - Update documentation
1 parent 3320811 commit df03793

10 files changed

Lines changed: 817 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,43 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.1.1] - 2026-01-08
11+
12+
### Added
13+
14+
- **CLI Improvements**:
15+
- `--version` flag to display version and Python version information
16+
- `--stats` flag for detailed obfuscation statistics
17+
- Shows identifier counts (obfuscated vs preserved)
18+
- Displays file size changes
19+
- Indicates restoration method (key file vs embedded metadata)
20+
- Configuration file support via `pyproject.toml`
21+
- Set default values for `style`, `length`, `seed`, and `stats`
22+
- Uses `[tool.mistode]` section
23+
- Automatically searches current and parent directories
24+
25+
- **Examples Directory**:
26+
- Added `examples/` with comprehensive sample code
27+
- Python calculator example (`calculator.py`)
28+
- C calculator example (`calculator.c`)
29+
- Detailed usage documentation in `examples/README.md`
30+
31+
- **Documentation**:
32+
- Created comprehensive example usage guide
33+
- Added configuration file documentation
34+
35+
### Changed
36+
37+
- **Enhanced Error Messages**:
38+
- User-friendly error formatting with emoji icons (❌ for errors, 💡 for hints)
39+
- Specific troubleshooting hints for common issues
40+
- Better handling of file not found, permission denied, and encoding errors
41+
- Improved key file error messages with suggestions
42+
43+
### Fixed
44+
45+
- Fixed installation command in `README_ZH.md` (changed from `pip install .` to `pip install mistode`)
46+
1047
## [0.1.0] - 2026-01-08
1148

1249
### Added

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,37 @@ mistode obfuscate input.py --out output.py --key mapping.json
6262
mistode restore output.py --out restored.py --key mapping.json
6363
```
6464

65+
### Configuration File
66+
67+
You can set default options in `pyproject.toml` to avoid repeating the same arguments:
68+
69+
```toml
70+
[tool.mistode]
71+
style = "similar" # Default obfuscation style ("similar" or "random")
72+
length = 16 # Default token length (8-32)
73+
stats = true # Always show statistics
74+
# seed = 42 # Optional: set a default seed for reproducibility
75+
```
76+
77+
**How it works**:
78+
79+
- Mistode automatically searches for `pyproject.toml` in the current directory and parent directories
80+
- If found, settings from `[tool.mistode]` are used as defaults
81+
- Command-line arguments always override configuration file settings
82+
83+
**Example**:
84+
85+
```bash
86+
# With the config above, these are equivalent:
87+
mistode o input.py
88+
mistode o input.py --style similar --length 16 --stats
89+
90+
# Override config with command-line args:
91+
mistode o input.py --style random --length 20
92+
```
93+
94+
For a complete guide, see [`examples/CONFIG_GUIDE.md`](examples/CONFIG_GUIDE.md).
95+
6596
## Advanced Features
6697

6798
### Smart Identifier Recognition for Python Obfuscation

README_ZH.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Mistode (Mist Code, pronounced like "Miss Told") 是一个轻量级的代码混
3636
## 安装
3737

3838
```shell
39-
pip install .
39+
pip install mistode
4040
```
4141

4242
## 使用方法
@@ -62,6 +62,37 @@ mistode obfuscate input.py --out output.py --key mapping.json
6262
mistode restore output.py --out restored.py --key mapping.json
6363
```
6464

65+
### 配置文件
66+
67+
您可以在 `pyproject.toml` 中设置默认选项,避免重复输入相同的参数:
68+
69+
```toml
70+
[tool.mistode]
71+
style = "similar" # 默认混淆风格("similar" 或 "random")
72+
length = 16 # 默认 token 长度(8-32)
73+
stats = true # 总是显示统计信息
74+
# seed = 42 # 可选:设置默认随机种子以获得可重现结果
75+
```
76+
77+
**工作原理**
78+
79+
- Mistode 自动在当前目录和父目录中搜索 `pyproject.toml`
80+
- 如果找到,`[tool.mistode]` 中的设置将作为默认值使用
81+
- 命令行参数始终会覆盖配置文件设置
82+
83+
**示例**
84+
85+
```bash
86+
# 使用上述配置,以下两个命令等效:
87+
mistode o input.py
88+
mistode o input.py --style similar --length 16 --stats
89+
90+
# 使用命令行参数覆盖配置:
91+
mistode o input.py --style random --length 20
92+
```
93+
94+
完整指南请参阅 [`examples/CONFIG_GUIDE.md`](examples/CONFIG_GUIDE.md)
95+
6596
## 高级特性
6697

6798
### Python 混淆的智能标识符识别

examples/CONFIG_GUIDE.md

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
# Mistode 配置文件使用指南
2+
3+
## 📖 工作原理
4+
5+
是的,你的理解完全正确!配置文件的工作方式如下:
6+
7+
### 1. 自动发现
8+
9+
`mistode` 会自动在以下位置搜索 `pyproject.toml`
10+
11+
- 当前执行目录
12+
- 当前目录的所有父目录(向上递归)
13+
14+
### 2. 自动加载
15+
16+
如果找到 `pyproject.toml` 且包含 `[tool.mistode]` 部分,会自动读取这些配置作为默认值。
17+
18+
### 3. 优先级规则
19+
20+
**命令行参数 > 配置文件 > 内置默认值**
21+
22+
---
23+
24+
## 🎯 实际演示
25+
26+
### 配置文件内容
27+
28+
`pyproject.toml` 中添加:
29+
30+
```toml
31+
[tool.mistode]
32+
style = "random" # 使用随机字符风格
33+
length = 20 # token 长度 20 字符
34+
stats = true # 总是显示统计信息
35+
```
36+
37+
### 演示 1: 不使用配置文件
38+
39+
```bash
40+
$ mistode o demo_simple.py
41+
OK Obfuscated demo_simple.py -> demo_simple.obf.py
42+
```
43+
44+
生成的函数名(16字符,similar风格):
45+
46+
```python
47+
def Vbz585ziiZ5O21S5(ab065bO1bOS2zOsO): # 易混淆字符
48+
```
49+
50+
### 演示 2: 使用配置文件(自动应用)
51+
52+
启用上面的配置后:
53+
54+
```bash
55+
$ mistode o demo_simple.py
56+
OK Obfuscated demo_simple.py -> demo_simple.obf.py
57+
58+
=== Obfuscation Statistics === # 自动显示!
59+
Identifiers obfuscated: 0
60+
Original size: 0.23 KB
61+
Obfuscated size: 1.08 KB
62+
...
63+
```
64+
65+
生成的函数名(20字符,random风格):
66+
67+
```python
68+
def Ui12Zz158sOO8Ss0(yB1sZI0BS6SZ6bSi): # 随机字符,更长
69+
```
70+
71+
### 演示 3: 命令行参数覆盖配置
72+
73+
即使配置文件设置了 `length = 20`,命令行参数依然优先:
74+
75+
```bash
76+
$ mistode o demo_simple.py --length 12 --style similar
77+
# 会使用 12 字符的 similar 风格,而不是配置文件的 20 字符 random
78+
```
79+
80+
---
81+
82+
## 💡 使用场景
83+
84+
### 场景 1: 团队统一配置
85+
86+
在项目根目录的 `pyproject.toml` 中设置,整个团队使用相同的混淆设置:
87+
88+
```toml
89+
[tool.mistode]
90+
style = "similar"
91+
length = 16
92+
stats = true
93+
```
94+
95+
### 场景 2: 不同项目不同配置
96+
97+
- 项目 A 需要短名称快速混淆
98+
- 项目 B 需要长名称高安全性
99+
100+
每个项目配置自己的 `pyproject.toml`
101+
102+
### 场景 3: 临时覆盖
103+
104+
日常使用配置文件的默认设置,但偶尔需要特殊处理:
105+
106+
```bash
107+
# 平时:使用配置文件的设置
108+
mistode o file.py
109+
110+
# 特殊情况:临时使用不同设置
111+
mistode o file.py --length 24 --seed 123
112+
```
113+
114+
---
115+
116+
## ⚙️ 支持的配置项
117+
118+
| 配置项 | 类型 | 默认值 | 说明 |
119+
| :--- | :--- | :--- | :--- |
120+
| `style` | string | `"similar"` | 混淆风格:`"similar"``"random"` |
121+
| `length` | integer | `16` | Token 长度,范围 8-32 |
122+
| `stats` | boolean | `false` | 是否默认显示统计信息 |
123+
| `seed` | integer || 可选的随机种子 |
124+
125+
---
126+
127+
## 📋 完整示例
128+
129+
### pyproject.toml
130+
131+
```toml
132+
[build-system]
133+
requires = ["hatchling"]
134+
build-backend = "hatchling.build"
135+
136+
[project]
137+
name = "my-project"
138+
version = "1.0.0"
139+
140+
# ... 其他配置 ...
141+
142+
# Mistode 配置
143+
[tool.mistode]
144+
style = "similar" # 使用易混淆字符
145+
length = 18 # 18 字符长度
146+
stats = true # 总是显示统计
147+
seed = 42 # 固定随机种子(可重现)
148+
```
149+
150+
### 使用效果
151+
152+
```bash
153+
# 在项目目录下任何位置执行,都会自动应用这些配置
154+
$ cd /path/to/my-project/src
155+
$ mistode o module.py
156+
157+
# 等同于:
158+
$ mistode o module.py --style similar --length 18 --stats --seed 42
159+
```
160+
161+
---
162+
163+
## ❓ 常见问题
164+
165+
### Q1: 配置文件必须在项目根目录吗?
166+
167+
**A**: 不必须。`mistode` 会向上递归搜索父目录,直到找到包含 `[tool.mistode]``pyproject.toml`
168+
169+
### Q2: 如何知道当前使用了哪些配置?
170+
171+
**A**: 暂时没有专门的命令显示。可以通过观察生成的token长度来判断,或使用 `--stats` 查看效果。
172+
173+
### Q3: 配置文件会影响所有子目录吗?
174+
175+
**A**: 是的。如果在父目录找到配置文件,所有子目录执行 `mistode` 都会使用该配置(除非子目录有自己的 `pyproject.toml`)。
176+
177+
### Q4: 不想使用配置文件怎么办?
178+
179+
**A**: 两种方法:
180+
181+
1. 删除或注释掉 `[tool.mistode]` 部分
182+
2. 使用命令行参数覆盖所有配置项
183+
184+
### Q5: 配置文件加载失败会报错吗?
185+
186+
**A**: 不会。如果:
187+
188+
- 找不到 `pyproject.toml`
189+
- 文件格式错误
190+
- 缺少 `[tool.mistode]` 部分
191+
192+
`mistode` 会静默使用内置默认值,不会报错。
193+
194+
---
195+
196+
## ✅ 总结
197+
198+
配置文件的核心优势:
199+
200+
1. **方便**: 不用每次都输入相同的参数
201+
2. **统一**: 团队或项目使用一致的混淆设置
202+
3. **灵活**: 仍然可以用命令行参数临时覆盖
203+
4. **自动**: 无需手动指定配置文件路径
204+
205+
**是的,只要执行目录下(或父目录)有 `pyproject.toml` 文件,并且包含 `[tool.mistode]` 配置,mistode 执行时就会自动应用这些配置!**

0 commit comments

Comments
 (0)