Skip to content

Scanner/wrapper cleanups: sort spans, anchor struct, quote macro#6

Merged
ko1N merged 3 commits into
mainfrom
scanner-cleanups
Jun 30, 2026
Merged

Scanner/wrapper cleanups: sort spans, anchor struct, quote macro#6
ko1N merged 3 commits into
mainfrom
scanner-cleanups

Conversation

@killerra

Copy link
Copy Markdown
Collaborator

Three remaining review cleanups, each its own commit. All preserve matching semantics —
the matches/finds cross-check proptests and fixture tests are the net.

Commits

  • sort code spansspan_index_for_offset (binary search) and ExecReader::find_span
    assume code spans are ascending and non-overlapping, but the PE/ELF/Mach wrappers emitted
    them in section/segment order. Real binaries are conventionally VA-ascending, but a crafted
    or unusual image with out-of-order executable regions could mis-resolve offsets. Sort
    code_spans by mapped.start at construction in all three wrappers; add a fixture test
    enforcing the invariant.
  • bundle the anchor fields into one struct — the unified scan path threaded the anchor as
    four separate params (bytes/len/offset/jumps), giving 9–11-arg functions. Introduce an
    AnchorPlan struct (the fields of PatternPlan/PreparedPattern) and pass &AnchorPlan
    through the scan strategies instead. Pure refactor.
  • emit macro tokens with quotepattern! built a Rust source string ("&[...]") and
    re-parsed it (and compile_error did the same with manual escaping). Build the output
    TokenStream directly with quote/proc-macro2 (one quoted Atom per atom, integer args
    as suffixed literals). Adds the two standard proc-macro deps to the macros crate only.

Verification

cargo test --workspace --all-targets --all-features, cargo test --workspace --doc,
cargo clippy --workspace --all-targets --all-features -- -D warnings -D clippy::all, and
cargo fmt --all -- --check all pass.

killerra added 3 commits June 29, 2026 13:45
span_index_for_offset (binary search) and ExecReader::find_span assume the code
spans are ascending and non-overlapping, but the PE/ELF/Mach wrappers emitted
them in section/segment order. Real binaries are conventionally VA-ascending, but
a crafted or unusual image with out-of-order executable regions could mis-resolve
offsets. Sort code_spans by mapped.start at construction in all three wrappers;
add a fixture test enforcing the invariant.
The unified scan path threaded the anchor as four separate parameters
(bytes/len/offset/jumps), giving 9-11-arg functions. Introduce an AnchorPlan
struct (already a coherent unit, and the fields of PatternPlan/PreparedPattern)
and pass &AnchorPlan through the scan strategies instead. Pure refactor; the
matches/finds cross-check proptests and fixture tests confirm no behavior change.
pattern! built a Rust source string ("&[...]") and re-parsed it, and compile_error
did the same with manual escaping. Build the output TokenStream directly with
quote/proc-macro2 instead (one quoted Atom expression per atom, integer args as
suffixed literals). Behavior is unchanged; the macro_smoke tests still match the
runtime parser output.
@ko1N ko1N merged commit a896fd1 into main Jun 30, 2026
3 checks passed
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.

2 participants