Skip to content

feat(binary-layout): admit ELF32 i386, ARM and MIPS layout profiles - #7052

Merged
morluto merged 4 commits into
morluto:mainfrom
salmanalmutairi1:feat/elf32-binary-layout
Oct 25, 2026
Merged

morluto merged 4 commits into
morluto:mainfrom
salmanalmutairi1:feat/elf32-binary-layout

Conversation

@salmanalmutairi1

@salmanalmutairi1 salmanalmutairi1 commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #6934.

inspect_binary_layout refused every ELF32 object with unsupported_target, so ARM32 and MIPS32 router/IoT firmware got no layout facts. It now admits EXEC/DYN/REL objects in these profiles: ELF64 x86-64 (unchanged), ELF32 i386, ELF32 little-endian ARM and ELF32 little- or big-endian MIPS. Other machines, classes and byte orders still return unsupported_target, and the message names the admitted profiles.

Problem and expected behavior

bridge/pwntools/layout_impl.py accepted only EI_CLASS == ELFCLASS64, EI_DATA == ELFDATA2LSB and e_machine == EM_X86_64, and binaryLayoutSchema pinned architecture to EM_X86_64 / 64 / little. The rest of the adapter already goes through class- and byte-order-aware pyelftools structures (image.structs.Elf_Sym, Elf_Dyn, header sizes), so 32-bit and big-endian layouts need no other parsing change.

Expected: an ELF32 ARM or MIPS executable returns the same layout report as an x86-64 one, with architecture naming its real machine, class and byte order.

Change and scope

  • Bridge. PROFILES maps each admitted (e_machine, class bits, byte order) to the architecture pwntools must also report. The identification fields are read in the declared byte order, ELF32 headers are bounds-checked at 52 bytes, and pwntools' own arch/bits/endian must match the admitted profile after loading.
  • Schema. architecture is a union of the exact admitted combinations, so a report such as EM_386 / 64 or EM_ARM / big still fails validation.
  • Evidence. The subject architecture previously always said x86_64. It now follows the reported machine (x86_64, x86, arm, mips).
  • Verification. verify:binary:layout cross-compiles i386, ARM, MIPS and MIPSel executables and relocatable objects. They are never executed. The verifier compares section names, addresses, offsets and sizes with GNU readelf through both CLI and MCP. It also compares every symbol value/size and every relocation offset, numeric type and symbol table/index reference, retaining table/entry identities and checking the oracle row counts. The real-binary-layout workflow installs the four cross toolchains.

Not included: AArch64, ELF32 big-endian ARM, MIPS64/n32, x32, or any machine outside the list above. GOT/PLT maps and mitigation indicators still come from the unchanged upstream heuristics, and their completeness stays unknown, as before.

Follow the contribution scope. This widens target-format admission of an existing read-only offline operation. It adds no execution, injection or mutation authority. Whether widening architecture needs a maintainer scope decision is asked on #6934 and is still pending.

Contract and boundary impact

  • Semantic owner and earliest changed stage: PwntoolsLayoutProvider's Python adapter (layout_impl.py) owns target admission. binaryLayoutSchema owns the output contract, and BinaryLayoutService composes Evidence. No superseded path remains.
  • Contribution scope fit and linked maintainer decision: existing read-only capability. Question posted on inspect_binary_layout requires ELF64 LE; ELF32 targets get no layout profile and no named alternative #6934, no decision recorded yet.
  • CLI and MCP/tool-catalog contract: input unchanged. The output architecture field widens from one literal combination to five admitted combinations, and the tool description states the new profile.
  • Provider, bridge, target-format, or platform compatibility: same pinned pwntools 4.15.0 / pyelftools 0.33 / Unicorn 2.1.2 on Linux x64. Existing ELF64 x86-64 reports are unchanged.
  • Evidence, artifact, provenance, or reconstruction contract: the Evidence subject architecture now reflects the target instead of a constant x86_64.
  • Target selection, authority, upstream behavior, and cleanup details: unchanged. The target is never launched, and Unicorn PLT emulation is the existing upstream behavior.
  • Generated metadata, package, or installation impact: none committed. The catalog is regenerated by CI.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated:
    • src/domain/native/binaryLayout.test.ts: admits the four new combinations and rejects mismatched class/machine/byte-order combinations. It also accepts 16-byte Elf32_Sym entries for ELF32 relocations while still refusing undersized ELF32 entries and 16-byte entries in ELF64 reports.
    • src/application/binaryDiagnostics/BinaryLayoutService.test.ts: the Evidence subject names the reported machine.
    • scripts/verify-binary-layout.mjs: real ELF32 cases cross-checked against readelf. The existing AArch64 and core unsupported_target cases are kept.
  • Base reproduction or other evidence: on the base revision, layout_impl.py:119-120 refuses any object with EI_CLASS != 2 before parsing, as quoted in inspect_binary_layout requires ELF64 LE; ELF32 targets get no layout profile and no named alternative #6934.
  • User-visible CLI/MCP output: the real lane asserts, through both inspect-binary-layout --json and MCP, that each cross-compiled fixture reports architecture {EM_386, 32, little}, {EM_ARM, 32, little}, {EM_MIPS, 32, big} or {EM_MIPS, 32, little} and the expected image_type, and that every section's name, address, offset and size equals GNU readelf -SW. A verbatim report excerpt was not captured from the CI log.
  • Remaining proof gaps: ELF32 big-endian ARM, AArch64 and MIPS64 remain unsupported and unverified. GOT/PLT completeness on ARM/MIPS is reported as unknown and not asserted.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • Review follow-up at 27dc69f93: npm run check, the pre-push npm run check:fast, Node syntax checking and git diff --check passed on macOS (Node 24.22.1, npm 11.16.0). The new ELF32 symbol/relocation comparisons have not been run against the real provider: isolated Linux x64 setup was stopped after sustained dependency-download throttling, and dispatching the fork's Real offline binary layout workflow was denied with HTTP 403. The successful real-provider run below covers the earlier 1443a20 revision.

  • npx tsc -p . --noEmit (Windows 11, Node 24.18.0): passed.

  • npm run test:local -- <17 binary-diagnostics source test files>: 231 passed, 2 skipped, 1 failed. The failure is ByteEntropyService.test.ts "parent directory moves during streaming", which fails identically on the unchanged base on Windows (rename semantics) and is unrelated.

  • npx oxlint on changed files: no new warnings compared with the base files.

  • npm run verify:module-boundaries: passed.

  • Pre-push hook (typecheck, lint): passed.

  • Real offline binary layout workflow on the fork (ubuntu-24.04, pinned pwntools 4.15.0 / pyelftools 0.33 / Unicorn 2.1.2):

    • Run #3 at 1443a20: passed. The verifier step took 232 s, covering the existing ELF64 cases and the eight ELF32 cases.
    • Run #2 at b8426c9: the 20 existing ELF64 cases passed, then the first i686 report was refused as unreadable_output because the relocation check required 24-byte (Elf64_Sym) symbol entries. This was fixed in 1443a20, with regression cases in binaryLayout.test.ts that fail on b8426c9.
    • Run #1 at ebaf7a4: the 20 existing ELF64 cases passed, then the i686 fixture failed to compile because --no-install-recommends skipped the target libc headers. This was fixed in b8426c9.
  • Not run locally: npm run docs:check and boundary tests (test:focused), because the Windows build needs native Windows artifacts absent from a source checkout.

Compatibility, safety, and release

  • Breaking changes or migration steps: none for existing callers. ELF64 x86-64 reports are unchanged. Consumers that assumed architecture was always EM_X86_64 / 64 / little will now also see the ELF32 combinations.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable. Real pwntools coverage is the workflow above.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no new authority. Targets are still read from an owned snapshot and never executed.

Author readiness

Human owner: @salmanalmutairi1

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

salmanalmutairi1 and others added 3 commits October 25, 2026 02:28
inspect_binary_layout refused every ELF32 object, so router and IoT
firmware (ARM32, MIPS32) got no layout facts at all.

The pwntools adapter now admits EXEC/DYN/REL objects in these profiles:
ELF64 x86-64, ELF32 i386, ELF32 little-endian ARM and ELF32 little- or
big-endian MIPS. Header fields are read in the declared byte order, the
ELF32 header is bounds-checked at 52 bytes, and pwntools' own reported
architecture, class and byte order must match the admitted profile.
Other machines, classes and byte orders keep an unsupported_target
refusal that names the admitted profiles.

The output schema admits exactly those architecture combinations, and
the Evidence subject now names the reported machine instead of always
claiming x86_64.

verify:binary:layout cross-compiles i386, ARM, MIPS and MIPSel
executables and relocatable objects (never executed) and checks every
section name, address, offset and size against GNU readelf through CLI
and MCP. The real-binary-layout workflow installs those toolchains.

Refs morluto#6934

Co-Authored-By: Claude Opus 5.5 <[email protected]>
--no-install-recommends skips the libc6-dev-*-cross packages the cross
compilers only recommend, so the i686 fixture fell back to the host's
/usr/include and failed to find bits/libc-header-start.h. Install the
four target libc development packages explicitly.

Refs morluto#6934

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The relocation reference check required a 24-byte Elf64_Sym entry, so
every positive symbol reference in an ELF32 report was refused as
unreadable output. Elf32_Sym is 16 bytes; take the minimum from the
reported class. A 64-bit table with 16-byte entries is still refused.

Refs morluto#6934

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-25T01:09:05.334026Z
We couldn’t complete this review. Comment @codex review to try again.
1443a20 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The reviewed changes appear safe to merge, with the previous finding addressed and no new blocking issues found.

Summary

Adds ELF32 i386, little-endian ARM, and little- or big-endian MIPS support to offline binary layout inspection.

  • ELF layout reports now cover i386, ARM, and MIPS files.

Reviews (2) · Last reviewed commit: "test(binary-layout): compare ELF32 symbo..." · Reviewed by Greptile

Comment thread scripts/verify-binary-layout.mjs Resolved
@salmanalmutairi1 salmanalmutairi1 changed the title Feat/elf32 binary layout feat(binary-layout): admit ELF32 i386, ARM and MIPS layout profiles Oct 25, 2026
@salmanalmutairi1
salmanalmutairi1 marked this pull request as draft October 25, 2026 00:46
@salmanalmutairi1
salmanalmutairi1 marked this pull request as ready for review October 25, 2026 01:07
@morluto
morluto merged commit 2c38bec into morluto:main Oct 25, 2026
36 of 40 checks passed
@morluto morluto mentioned this pull request Oct 25, 2026
3 tasks done
@morluto

morluto commented Oct 25, 2026

Copy link
Copy Markdown
Owner

@salmanalmutairi1, thank you for extending offline binary layout inspection to the supported ELF32 i386, ARM and MIPS profiles. Reporting the target’s architecture in Evidence also makes those binary reports easier to interpret. Welcome to REA!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

inspect_binary_layout requires ELF64 LE; ELF32 targets get no layout profile and no named alternative

2 participants