Skip to content

Commit 61a769e

Browse files
committed
fix(cli): rollback section state on strategy failure
1 parent e8cd5d8 commit 61a769e

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

cli/README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,19 @@ Without `--seed`, every run uses a fresh unseeded RNG (non-deterministic).
139139
ln -s function_body_tmp100.pkl strategies/data/function_body.pkl
140140
```
141141

142-
Strategies could work correctly when applied individually.
143-
144-
Known issues:
145-
146-
- `function_body_cloning` + `function_insertion` — cloned proxy calls break when new functions shift indices
147-
- `data_encryption` — injected decryption function may have mismatched signatures on certain modules
148-
149-
Use `--validate` to catch failures, and `-e` to exclude problematic strategies:
142+
> [!TIP]
143+
> The CLI takes a snapshot of the section before each strategy. If a strategy crashes mid-execution, the section is automatically rolled back to its pre-strategy state, so partial modifications never corrupt the output.
144+
145+
> [!WARNING]
146+
> **There are known issue on specific combos**
147+
>
148+
> - `function_insertion* + function_body_cloning`
149+
> - `function_insertion` creates functions with `header=''` (empty string) instead of the expected `[[line, tag], ...]` list (`structural_perturbation.py:113`). When `function_body_cloning` runs next on the same section, it tries to access `header[0][0]` on one of those functions (`structural_perturbation.py:184-185`), which crashes because you can't index into an empty string. The CLI rolls back the section on failure, so the output stays valid — but `function_body_cloning` is effectively skipped.
150+
> - `data_encryption` — injected decryption function may have mismatched signatures on certain modules
151+
152+
> ? NOTE: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla et euismod
153+
> nulla. Curabitur feugiat, tortor non consequat finibus, justo purus auctor
154+
> massa, nec semper lorem quam in massa.
150155
151156
```bash
152157
swamped obfuscate input.wasm -o out.wasm -s structural -e data_encryption function_body_cloning --validate

cli/swamped_cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ def cmd_obfuscate(args):
345345
for name in strategy_names:
346346
entry = STRATEGIES[name]
347347
logger.info(" -> %s", name)
348+
snapshot = copy.deepcopy(section)
348349
t0 = time.monotonic()
349350
try:
350351
if name == "stack_op_insertion":
@@ -358,11 +359,12 @@ def cmd_obfuscate(args):
358359
except Exception as e:
359360
elapsed = time.monotonic() - t0
360361
timings.append((name, elapsed, False))
362+
section = snapshot # rollback to avoid corrupted state
361363
if args.strict:
362364
logger.error(" [error] %s failed: %s", name, e)
363365
sys.exit(1)
364366
else:
365-
logger.warning(" [warning] %s failed: %s", name, e)
367+
logger.warning(" [warning] %s failed (rolled back): %s", name, e)
366368

367369
if args.timing and len(timings) > 1:
368370
total = sum(t for _, t, _ in timings)

0 commit comments

Comments
 (0)