Skip to content

feat(loaders): analyze x86/x64 ELF and COFF objects - #435

Merged
danielplohmann merged 4 commits into
danielplohmann:masterfrom
r0ny123:codex/object-formats
Nov 18, 2026
Merged

danielplohmann merged 4 commits into
danielplohmann:masterfrom
r0ny123:codex/object-formats

Conversation

@r0ny123

@r0ny123 r0ny123 commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

What this changes

Adds analysis of little-endian x86/x64 ELF relocatable objects (.o and uncompressed .ko) and conventional COFF .obj files. Static archives remain unsupported.

The loader assigns deterministic analysis addresses, resolves section-relative symbols and supported relocations, and preserves the original input hash. Optional xmetadata.object_image records the derived layout, aliases, known function sizes and unresolved external references.

NOP padding is distinguished from function bodies using bounded byte inspection and symbol extents. Known object-function extents prevent interior prologues from splitting their owners. Unsupported relocations and object variants are rejected explicitly; allocation and table limits remain bounded. Existing linked-image loaders, CIL support and hash-escape versions are unchanged.

How it was verified

  • Full suite: 2,744 passed, 3 skipped.
  • Final object-format regression suite: 52 passed.
  • Ruff lint/format checks and type checking pass; type checking retains warnings.
  • Ubuntu crc32_generic.ko from linux-modules-6.8.0-31-generic 6.8.0-31.31: all nine distinct bodies match original symbol addresses, extents and independent instruction counts. Module SHA-256: 8dcf24cc22b706cc3ee8d8c3368b0ba42a45441198af5ba44c5de60be1567982.
  • Existing MCRIT 1.16.0 corpus exporter accepts the report: nine function entries and four indexable minhashes, with matching corpus configuration hashes.
  • Linked PE/ELF probe controls retain their PicHashes. Golden fixtures are unchanged.

No analyzed binary was executed or loaded into a kernel. No binary fixture, corpus data or workflow change is included. Supported relocation subsets and limitations are documented in docs/OBJECT_FILES.md.

  • Lint and formatting
  • Full test suite
  • Changelog entry
  • Golden fixtures unchanged

- keep call sites inside sized functions as reference sources
- support R_386_PLT32
- wrap absolute relocation values to the field width
- ignore COFF debug symbols instead of placing them as common storage
- only claim COFF input whose section and symbol tables fit the file
- resolve weak external chains in linear time and drop them from imports
- place unresolved externals after the image instead of past MAX_IMAGE_SIZE
- report a relocation count in xmetadata instead of every record
- read the ELF OS ABI from the header instead of a second parse
@danielplohmann

Copy link
Copy Markdown
Owner

Reviewed the loader and the integration; relocation math and bounds checks look right, and the full suite passes locally (2,744 passed, 3 skipped).

One design question before merging: with this PR, an ELF ET_REL or a COFF-looking file always goes through load_object(), and any ValueError there ends in an error report. Before, such input fell through to the linked-image loaders. That covers non-x86 .o/.ko files, x86 objects with TLS or unsupported relocations, and any file that starts with 4c 01/64 86 and passes _is_coff_object(). It also applies to disassembleUnmappedBuffer, since MemoryFileLoader maps files too.

Explicit rejection matches what the PR describes and is defensible. Was the behaviour change for these inputs intended, or should FileLoader fall back to the previous path when load_object() raises?

@r0ny123

r0ny123 commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Intended. I checked what the previous path did with these inputs on master (2a943f9):

  • ELF ET_REL (x86, x64, ARM, AArch64, with or without TLS): status=ok, 0 functions, 0 instructions. There are no program headers, so nothing gets mapped.
  • COFF objects and anything else starting with 4c 01/64 86: the "Input is not a PE, ELF, Mach-O, DEX or Delphi knowledge base" RuntimeError, from both disassembleFile and disassembleUnmappedBuffer.

So no input that produced a disassembly before fails now. A fallback would only turn "TLS sections are not supported" back into an empty ok report (ELF) or the generic error (COFF), which I think is worse for the caller. Raw code is unaffected: disassembleBuffer never goes through the loader, and a raw file that happens to pass _is_coff_object() was already an error, only the message differs.

If you prefer the fallback anyway it is a small change, say so and I'll add it.

Unrelated to the question: while testing this on system objects I found that a function ending in a call to __stack_chk_fail at the end of its section was dropped (analysis ran into the zero padding). With -ffunction-sections that hit every protected function. Fixed in b0322cf by ending the block at the symbol's declared extent, with a test; 1004/1004 sized symbols recovered over 81 objects from a stock distribution install (996 before).

@danielplohmann
danielplohmann merged commit ab72bf2 into danielplohmann:master Nov 18, 2026
29 checks passed
danielplohmann added a commit that referenced this pull request Nov 18, 2026
…ce (#437)

MAX_OBJECT_SYMBOLS, MAX_OBJECT_RELOCATIONS, MAX_OBJECT_NAME_LENGTH and the
MAX_IMAGE_SIZE of ObjectImage.allocate() were read from the SmdaConfig class,
so values set on the config passed to Disassembler were ignored. FileLoader
and MemoryFileLoader take an optional config and pass it to load_object().

readable_name moves from PeSymbolProvider (private) to
labelprovider/symbol_names.py, so BinaryInfo and ObjectSymbolProvider stop
importing a private helper.

Follow-ups to #435 from danielplohmann/apiscout#55.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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