Add audit manifests and CI · bikini/patchwork@432df66 · GitHub
Skip to content

Commit 432df66

Browse files
committed
Add audit manifests and CI
1 parent ef1cd60 commit 432df66

9 files changed

Lines changed: 463 additions & 51 deletions

File tree

.gitattributes

Lines changed: 6 additions & 0 deletions

.github/workflows/ci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: actions/setup-python@v5
16+
with:
17+
python-version: ${{ matrix.python-version }}
18+
- name: Install package
19+
run: python -m pip install -e .
20+
- name: Run tests
21+
run: |
22+
python tests/test_audit.py
23+
python tests/test_obfuscator.py

.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
__pycache__/
2+
*.pyc
3+
*.pyo
4+
*.pyd
5+
*.egg-info/
6+
build/
7+
dist/
8+
.eggs/
9+
.pytest_cache/
10+
.mypy_cache/
11+
.ruff_cache/
12+
.venv/
13+
venv/
14+
env/
15+
.env
16+
*.swp
17+
*.swo
18+
.DS_Store
19+
Thumbs.db
20+
.idea/
21+
.vscode/
22+
examples/*_obf.py
23+
examples/*_test_*.py

README.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Python source obfuscator. Give it a `.py` file, get back a single self-contained
44

55
Each build is unique by default. Pass `--seed N` if you want a reproducible one.
66

7+
Version 0.2 adds accountability features for legitimate software-protection
8+
workflows: static source audits, build manifests, and strict audit refusal for
9+
inputs that use sensitive APIs.
10+
711
## What it actually does
812

913
Source-level rewrites first:
@@ -39,7 +43,7 @@ git clone https://github.com/bikini/patchwork.git
3943
cd patchwork
4044
```
4145

42-
If you want the `patchwork` console script on your `PATH`:
46+
That's it. If you want the `patchwork` console script on your `PATH`:
4347

4448
```sh
4549
pip install -e .
@@ -87,9 +91,37 @@ python -m patchwork INPUT [-o OUTPUT] [options]
8791
--no-junk turn off junk dead-branch injection
8892
--no-lazy turn off lazy per-function encryption
8993
--no-anti-debug turn off runtime anti-debug probes
94+
--audit-only analyze the input and exit without writing output
95+
--audit-json PATH write static audit metadata as JSON
96+
--manifest PATH write build manifest with hashes/options/audit data
97+
--strict-audit refuse inputs that contain sensitive API indicators
9098
-q, --quiet quiet mode
9199
```
92100

101+
## Audit and Manifest Workflow
102+
103+
Audit a file without generating an obfuscated output:
104+
105+
```sh
106+
python -m patchwork app.py --audit-only --audit-json evidence/app.audit.json
107+
```
108+
109+
Generate a manifest alongside a reproducible build:
110+
111+
```sh
112+
python -m patchwork app.py --seed 12345 --manifest evidence/app.manifest.json
113+
```
114+
115+
Refuse to transform files that contain review indicators such as dynamic
116+
execution, process spawning, or sensitive standard-library imports:
117+
118+
```sh
119+
python -m patchwork app.py --strict-audit
120+
```
121+
122+
The manifest records the input and output SHA-256 hashes, Python version,
123+
Patchwork version, build seed, selected options, and static audit metadata.
124+
93125
## Python API
94126

95127
```python
@@ -145,6 +177,7 @@ python examples/hello_obf.py
145177

146178
```sh
147179
python tests/test_obfuscator.py
180+
python tests/test_audit.py
148181
```
149182

150183
Runs every example through the obfuscator at multiple seeds, executes original and obfuscated versions, and checks stdout matches byte-for-byte. Also confirms different seeds produce different output and the same seed produces stable output.
@@ -184,4 +217,3 @@ patchwork/
184217
```
185218

186219
MIT.
187-

patchwork/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
from .core import Obfuscator, obfuscate, obfuscate_file
2-
__version__ = '0.1.0'
3-
__all__ = ['Obfuscator', 'obfuscate', 'obfuscate_file']
1+
from .core import Obfuscator, obfuscate, obfuscate_file
2+
from .audit import analyze_source, build_manifest
3+
__version__ = '0.2.0'
4+
__all__ = ['Obfuscator', 'analyze_source', 'build_manifest', 'obfuscate', 'obfuscate_file']

patchwork/audit.py

Lines changed: 214 additions & 0 deletions

0 commit comments

Comments
 (0)