Skip to content

fix(ast): strip stack canary boilerplate from decompiled C output#172

Open
wizardengineer wants to merge 1 commit intomainfrom
fix/strip-stack-canary
Open

fix(ast): strip stack canary boilerplate from decompiled C output#172
wizardengineer wants to merge 1 commit intomainfrom
fix/strip-stack-canary

Conversation

@wizardengineer
Copy link
Copy Markdown
Contributor

Add is_stack_canary_operation() to FunctionBuilder that detects compiler-inserted stack protector patterns by checking:

  • Operations with inputs referencing __stack_chk_guard globals
  • CALL operations targeting __stack_chk_fail

Detected operations are skipped during basic block creation, removing the canary entry load and fail call from the generated C.

This is a temporary solution that handles the straightforward cases (entry guard load and fail call) by pattern-matching on global names and call targets. The exit comparison block (if guard == saved) is not fully removed because the AST structuring engine reorganizes it into an if-else before our filter can catch the individual operations.

A complete solution would require value-level taint tracking — marking values derived from __stack_chk_guard and propagating that taint through copies, comparisons, and branches so the entire canary exit path can be identified and stripped. That approach is more invasive and should be discussed before implementing.

Partial fix for #161

Add is_stack_canary_operation() to FunctionBuilder that detects
compiler-inserted stack protector patterns by checking:
- Operations with inputs referencing __stack_chk_guard globals
- CALL operations targeting __stack_chk_fail

Detected operations are skipped during basic block creation,
removing the canary entry load and fail call from the generated C.

This is a temporary solution that handles the straightforward cases
(entry guard load and fail call) by pattern-matching on global names
and call targets. The exit comparison block (if guard == saved) is
not fully removed because the AST structuring engine reorganizes it
into an if-else before our filter can catch the individual operations.

A complete solution would require value-level taint tracking — marking
values derived from __stack_chk_guard and propagating that taint
through copies, comparisons, and branches so the entire canary exit
path can be identified and stripped. That approach is more invasive
and should be discussed before implementing.

Partial fix for #161

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@wizardengineer wizardengineer changed the title fix(ast): strip stack canary boilerplate from decompiled C output (#161) fix(ast): strip stack canary boilerplate from decompiled C output Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant