Repository navigation
feat(firmware): inspect uClinux bFLT flat executables offline - #14663
Conversation
The reader matches the bFLT magic on any filename, records the 64-byte big-endian header, and extracts text.bin (header included), data.bin, and relocations.bin while listing relocations as stored words. gzip and gzdata bodies inflate under artifact_limits.expanded_bytes; revision 2 is always stored, and its relocation words stay unchecked because their layout depends on a CPU the header never names. A missing magic or a header shorter than 64 bytes is the only refusal, other inconsistencies are limitations beside the remaining facts, files above 128 MiB are rejected, and the follow-up probe opens the text image as a raw binary with a caller-chosen architecture and entry.
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
[Medium impact] The PR appears safe to merge; both previous findings are addressed, and no new actionable issue was established. SummaryAdds offline bFLT inspection and extraction, including header facts, stored and inflated segments, relocation listings, and follow-up guidance.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[bFLT magic] --> B[Decode header]
B --> C{Compressed body?}
C -->|No| D[Stored image]
C -->|Yes| E[Inflate under caller budget and fixed ceiling]
E -->|Success| F[Inflated image]
E -->|Failure or limit| G[Header facts and compressed fallback]
D --> H[Text, data and relocation segments]
F --> H
H --> I[Inventory and contained extraction]
G --> I
Reviews (4) · Last reviewed commit: "fix(firmware): cap bFLT in-memory gzip i..." · Reviewed by Greptile |
|
@morluto thanks again for merging the bFLT support. Being able to inspect and extract uClinux flat executables offline beats decoding the 64-byte header by hand. |
Summary
uClinux flat executables (bFLT) are the program format on no-MMU embedded Linux systems such as Cortex-M, ColdFire, Blackfin and RISC-V nommu boards, and they appear inside firmware root filesystems. REA does not recognize the format today, so a bFLT file comes back as an unknown blob. To see where text and data begin, where the program starts, how many relocations it carries, or to get at a gzip-compressed body, an analyst has to decode the 64-byte header by hand or with a separate tool and loses per-segment Evidence.
This adds an offline
bfltartifact format.inspect-artifactandextract-artifact(and the MCPinspect_artifact/extract_artifacttools) recognize thebFLTmagic regardless of filename, report the big-endian header as facts, and serve text (header included), data and the relocation table as extractable segments. gzip and gzdata bodies are inflated in memory under the existingartifact_limits.expanded_bytesbudget. Relocations are listed, not applied, and nothing is executed. No issue exists for this; it is a format-inspection and ordinary-extraction addition within the supported contribution scope.Problem and expected behavior
Use case: given a
busyboxbFLT pulled out of a firmware root filesystem, see its revision, flags, entry offset, segment boundaries, stack size and relocation table, inflate a compressed body, then extracttext.binand open it as a raw binary with an architecture taken from the firmware or kernel configuration.Observable outcome:
bFLTis recognized asbflt. The root is an archive whose architecture is null, because the flat header does not name a CPU.format_metadata(kind: "bflt") reportsrevision,entry,data_start,data_end,bss_end, the derivedtext_size,data_sizeandbss_size,stack_size,reloc_start,reloc_count,flagswithflag_namesandunknown_flags,build_date(revision 4),compression,inflated_bytes, the first 64relocationswithrelocations_truncated, andout_of_range_relocation_count.text.bin([0, data_start), header included, soentryis an offset into it),data.binandrelocations.bin, each withkind: "bflt-segment"metadata. Stored segments keep their file range assource_location; segments that exist only after inflation have no file range and carryimage_offset.gzip, everything after the header is one gzip stream; withgzdata, text is stored and the stream starts atdata_start. Revision 2 loaders ignore these flags, so a revision 2 body is read as stored.artifact_limits.expanded_bytesor cannot be inflated, the header facts are still reported, coverage isunknown, a limitation names the cause, and the stored bytes are served ascompressed-body.gz(plustext.binforgzdata).bss_endbeforedata_end, a relocation table past the image, and more than 64 relocations become limitations beside the facts that still hold. Files over 128 MiB are rejected.inspect-artifactadds oneopen_binarynext probe: extracttext.bin, open it asraw-binarywith a caller-chosen architecture, and set the entry to a chosen load base plus the headerentry.Change and scope
src/domain/bfltExecutable.tsowns parsing: magic and header decoding, flag names, segment ranges, bounded gzip and gzdata inflation, relocation listing and range checks, and limitations.src/domain/bfltExecutable.fixture.tsbuilds synthetic files for the tests.src/artifacts/BfltArtifactReader.tsmaps the decoded executable onto the existingDecodedRegionArtifactReader, passingartifact_limits.expanded_bytesthrough, as the Intel HEX, S-record, UF2 and DfuSe readers already use that base.artifactFormatRecognition.ts, registration inartifactFormats.ts,bfltandbflt-segmentmetadata inartifactFormatMetadata.tsandformatMetadata/firmwareMetadata.ts, the inventory view, artifact graph,targetFormats.ts(archive), the reader format union, and theopen_binarynext probe inartifactInspection.ts.REA_settings:BFLT_MAX_FILE_BYTES= 128 MiB: a whole-file admission ceiling, the same fixed ceiling the DfuSe and Intel HEX readers use, because the decoder holds the file once in memory.BFLT_LISTED_RELOCATIONS= 64: a delivery budget for the inlinerelocationslist in header metadata, not an admission limit. Every entry is still range-checked and counted, andrelocations.binholds the complete table.BFLT_HEADER_SIZE= 64: the size of the format's header as defined byflat.h, not a tunable budget.artifact_limits.expanded_bytes, with that parameter's existing default.docs/bflt-executables.mdwith the docs index and sidebar, a CLI example indocs/getting-started/cli.md, a section indocs/guides/firmware/firmware-analysis.md, bFLT gzip decompression in theexpanded_bytesreader list indocs/reference/limits-and-recovery.md, and a bFLT entry in the skill references under.agents/skills/reverse-engineer-anything/and its.cursor-plugin/mirror.Not included: applying relocations, resolving shared-library references, guessing the CPU, decoding revision 2 relocation words (their bit order and base segment depend on the target CPU), and any execution or loading.
Follow the contribution scope.
Unresolved scope, authority, side effects, or required verification block
integration. Link the required maintainer scope decision for new providers or
capabilities involving target execution, injection, mutation, or protection
recovery; ordinary fixes within existing boundaries may state "not applicable".
Draft PRs may leave the scope decision pending and the Author readiness and
Author checklist unchecked. Maintainers can help resolve open questions.
Contract and boundary impact
bfltExecutable.tsproduces the header facts, segment ranges, inflated image and limitations; the reader, inventory graph, inventory view and inspection next probes consume them without reparsing raw bytes.bflt, andartifact_limits.expanded_bytesnow also bounds bFLT inflation.bflt, classified as an archive target; existing formats unchanged. Recognition requires the 4-bytebFLTmagic at offset 0.bfltandbflt-segmentmetadata shapes; stored segments carry source ranges, inflated segments carryimage_offset, and every segment carries its SHA-256.docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs andskills/; edit authored instructions in.agents/skills/reverse-engineer-anything/and never commit build outputs): none committed; authored skill references updated under.agents/skills/reverse-engineer-anything/and.cursor-plugin/.Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.
Evidence and regression coverage
src/domain/bfltExecutable.test.ts(revision 4 header facts and segment boundaries, gzip body inflation served by image offset only, gzdata text kept at its file offset with data inflated, an over-budget gzip body reported as a limitation with the stored bytes, revision 2 with its stored-entry caveat, a revision 2 body read as stored when gzip flag bits are set,build_dateonly for revision 4, revision 2 relocation words listed without range checks, a short or unmarked header refused, unknown revisions, unknown flags and out-of-range offsets, revision 4 relocations measured from the byte after the header through the end of bss, relocations past the inline budget, a relocation table past the file),src/artifacts/BfltArtifactReader.test.ts(inventory by magic with header facts and segment ranges, extraction of inflated gzip segments),tests/boundary/providers/native/artifactProvider.standaloneFormats.test.ts(theopen_binarynext probe fortext.bin), andsrc/application/binary/TargetFormatVocabularies.test.ts.bfltformat value or reader, so a bFLT file is not recognized there. The CLI output below is executed against this branch.node scripts/rea.mjs inspect-artifact plain.bflt --jsonon a file generated bybfltFile()(256 bytes of text, 8 bytes of data, 3 relocations,ramflag). Excerpt of the inventory substep's rootformat_metadata:{ "kind": "bflt", "revision": 4, "entry": 64, "data_start": 320, "data_end": 328, "bss_end": 344, "stack_size": 4096, "reloc_start": 328, "reloc_count": 3, "flags": 1, "flag_names": ["ram"], "unknown_flags": 0, "build_date": 1764115200, "build_date_iso": "2025-11-26T00:00:00.000Z", "compression": "none", "text_size": 320, "data_size": 8, "bss_size": 16, "inflated_bytes": null, "relocations": [16, 32, 260], "relocations_truncated": false, "out_of_range_relocation_count": 0 }Coverage was
{"scope":"container-entries","status":"complete"}and the members weretext.bin(320 bytes,source_location{"offset":0,"length":320}),data.bin(8 bytes at offset 320) andrelocations.bin(12 bytes at offset 328). The next probe wasopen_binarywith the rationale "Extract text.bin with extract_artifact, then open it with format raw-binary, a caller-chosen architecture (the bFLT header names none) and entry_point set to a chosen load base. The program entry is that base plus 0x40; relocations are not applied."gzip example:
gzip.bflt(flagsramandgzip, 64 KiB of text and 4 KiB of data compressed into a 178-byte file) reported"compression": "gzip","inflated_bytes": 69640,"data_start": 65600,"relocations": [16, 32]and complete coverage. The inflateddata.binoccurrence was:{"logical_path":"data.bin","declared_size":4096,"source_location":null,"format_metadata":{"kind":"bflt-segment","segment":"data","image_offset":65600,"length":4096},"hash_status":"verified"}node scripts/rea.mjs extract-artifact gzip.bflt --output-root "$PWD/xout" --jsonwrotetext.bin(65600 bytes),data.bin(4096 bytes) andrelocations.bin(8 bytes) withcontainment_verified: true. The SHA-256 oftext.bin(abd9b1e0...cdc389) anddata.bin(267e5d2b...c6899d) matched bothshasum -a 256on the written files and an independentgzip.decompressof the stored body. Agzdatacopy kepttext.binat its file range and inflateddata.bin("inflated_bytes": 4100).Limitation examples:
gzip.bfltwith--artifact-limits '{"expanded_bytes":4096}'exited 0 with coverageunknown,inflated_bytesnull, one membercompressed-body.gz(114 bytes at offset 64), and the limitation "The gzip body inflates past the 4096-byte artifact_limits.expanded_bytes budget; only the stored compressed bytes are exposed. Raise artifact_limits.expanded_bytes to inflate it."unknown,text.binanddata.binlisted, norelocations.bin,out_of_range_relocation_countnull, and the limitation "The relocation table [0x144, 0x10e4) runs past the 328-byte file; relocations are not listed."gzipflag and a corrupt stream exited 0 with coverageunknown,compressed-body.gz(50 bytes) served and extractable, and the limitation "The gzip body is not a readable gzip stream; only the stored compressed bytes are exposed."Refusal example: a 32-byte file starting with
bFLTexited 1 with"code":"unsupported_target","failure_kind":"malformed"and the reason "bFLT is malformed: bFLT header is truncated: 32 bytes, expected 64".flat.hheader layout. No toolchain-built bFLT (for example fromelf2flt) was used. The 128 MiB rejection is not exercised by a CLI run. The MCP tools were not exercised directly; they share the inventory and extraction path the CLI uses.For boundary fixes, identify the applicable boundary regressions
and lifecycle regressions
covered by the evidence above, and explain relevant gaps.
Not a boundary fix. The new reader's tests cover a truncated header, a missing magic, segment and relocation ranges past the file, an over-budget compressed body, and an unreadable gzip stream. Cancellation is not separately tested for this format.
For evidence-bearing changes:
Demo
Rendered walkthrough of the CLI inspect output above (simulated terminal, values taken from a real run on generated fixtures).
rea-bflt-demo.mp4
Validation performed
npx vitest run src/application/binary/TargetFormatVocabularies.test.ts src/artifacts/BfltArtifactReader.test.ts src/domain/bfltExecutable.test.ts tests/boundary/providers/native/artifactProvider.standaloneFormats.test.ts: 77 tests passed, 0 failednpm run check:fast(typecheck, lint, architecture guards): passed, "Architecture guards passed across 3135 source files."npm run docs:check: passed, includingtests/conformance/readmeConsistency.test.ts(8 tests)npm run format:check: "All matched files use the correct format."npm run verify:advertised-schemas: passed, 262 distinct schemas and 38 patterns accepted by V8, Go RE2 and Pythonre; the C++ RE2 and Rust engines were not installed locally and were not verifiednpm run compile, thennode scripts/rea.mjs inspect-artifactandextract-artifacton generated files: output as shown aboveCompatibility, safety, and release
open_binarynext probe was not followed with a real provider in this run.bflt.artifact_limits.expanded_bytes, and the whole file is bounded by the fixed 128 MiB ceiling.AI was used for assistance.
Author readiness
Human owner: @mvanhorn
Author checklist (completed by the PR author before requesting review)
type(scope): outcome.REA_runtime setting with a default, floor, and maximum, unless a fixed ceiling has a stated reason. See Adding a runtime setting.