Repository navigation
feat(firmware): inspect Qualcomm MBN image headers and hash segments offline - #14649
Conversation
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 reviewed changes appear safe to merge, with the previous numbered finding fixed and no new blocking issue found. SummaryAdds offline
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
Input[Local image] --> Recognition[Content recognition]
Recognition --> Legacy[Legacy MBN]
Recognition --> ELF[ELF]
Legacy --> Parser[MBN header and region facts]
ELF --> Hash{Qualcomm hash segment?}
Hash -->|Yes| Parser
Hash -->|No| Plain[ELF inventory]
Parser --> Output[MBN inventory and extraction]
ELF --> Native[Native target remains ELF]
Reviews (10) · Last reviewed commit: "fix(firmware): stop mapping Qualcomm MBN..." · Reviewed by Greptile |
3163b0c to
29ef8b5
Compare
…offline Artifact recognition now accepts a legacy Qualcomm MBN header only for versions 3, 5, and 6, and only after every signature-based format, when the image size matches the region sizes, the signature and certificate-chain pointers follow the code, and the code region lies inside the file. Inventory and extraction list the header, code, signature, certificate-chain, and version 5/6 metadata ranges; a range past the end of the file is reported as a limitation with unknown coverage and is left unlisted. An ELF image whose program-header flags mark a Qualcomm hash segment (bits 24-26 equal 2) is inventoried as qualcomm-mbn, with the hash-segment header, hash size, hash count, and the first 64 segment-hash rows, while binary target resolution keeps the ELF classification and extraction still returns those regions for an ELF input. Signatures and certificates are reported by location and size, and hash bytes are left as stored.
29ef8b5 to
472c535
Compare
…ders # Conflicts: # .agents/skills/reverse-engineer-anything/references/native-and-artifacts.md # .cursor-plugin/skills/reverse-engineer-anything/references/native-and-artifacts.md # docs/getting-started/cli.md # src/domain/formatMetadata/firmwareMetadata.ts
# Conflicts: # .agents/skills/reverse-engineer-anything/references/native-and-artifacts.md # .cursor-plugin/skills/reverse-engineer-anything/references/native-and-artifacts.md # docs/getting-started/cli.md # docs/guides/firmware/firmware-analysis.md # src/domain/analysisView/artifactInventoryView.ts # src/domain/artifactFormatRecognition.ts
Preserve both origin/main (morluto#12469 VSIX, morluto#13245 PE overlay, morluto#14649 Qualcomm MBN) and YARA entries across conflicted skill docs and test-projects, and include qualcomm-mbn in PE_OVERLAY_LEADING_FORMATS to resolve the typecheck regression between morluto#13245 and morluto#14649.
Summary
Android bootloader, TrustZone and modem partitions (
sbl1.mbn,aboot.mbn,tz.mbn,modem.mbn) ship as Qualcomm MBN images. REA does not recognize them today: a legacy MBN has no magic number, so it comes back as an unsupported binary, and an ELF-wrapped modem image is read as plain ELF. An analyst cannot see the header fields, where the signature and certificate chain sit, or which hash in the hash segment belongs to which program header without a separate tool.This adds an offline
qualcomm-mbnartifact format.inspect-artifactandextract-artifact(and the MCPinspect_artifact/extract_artifacttools) decode the 40-byte version 3 and 80-byte version 5/6 headers, report the file range of the code, signature, certificate-chain and metadata regions, and for an ELF image that declares a Qualcomm hash segment, decode that segment's header and list the hash position for each program header. Signatures and certificates are located, not verified. No issue exists for this; it is a format-inspection addition within the contribution scope.Problem and expected behavior
Use case: given
sbl1.mbnormodem.mbn, see the image id, version, image source, sizes and pointers, the byte range of each region, and for the modem image the hash size, hash count and per-segment hash offsets. Then extractsignature.binorcertificate-chain.binfor further analysis.Observable outcome:
image_sizeequals the sum of the region sizes, the signature and certificate-chain pointers follow the code region, and the whole code region lies inside the file. It runs after every signature-based format. A header whose sizes disagree is not claimed, and the file stays unsupported.format_metadatahas kindqualcomm-mbn, layoutlegacyorelf, the declared header words andheader.rangeswith the derived file offset and length of each region. Each region inside the file is a child occurrence (header.bin,code.binorhash-table.bin,signature.bin,certificate-chain.bin,metadata0.bin,metadata1.bin).unknown.p_flagsbits 24-26 equal to 2 is inventoried and extracted asqualcomm-mbn. Binary target resolution still reads it as ELF. An ELF without a hash segment stays ELF.e_phnum65535), a wrong program header entry size, or a table past the file end leaves the hash segment unknown and the file stays ELF. Further hash segments, a hash count that differs from the program header count, and a version 5/6 hash header cut short by the segment size or the file end are limitations withunknowncoverage.Change and scope
src/domain/qualcommMbnImage.tsowns parsing: legacy header recognition and plausibility checks, region ranges, ELF program header scan for the hash segment (reusingelfFixedHeader.ts,elfProgramHeader.tsandelfRawTableDeclarations.ts), hash size selection (SHA-256, SHA-384 or SHA-1 by code size and program header count), per-program-header hash offsets, and inventory coverage.src/artifacts/QualcommMbnLocation.tsreads only the spans the domain owner asks for: the 80-byte prefix, then for ELF the program header table and the hash segment header.QualcommMbnArtifactReader.tslists the stored regions and opens their bytes.artifactFormatRecognition.ts, registration inartifactFormats.ts,qualcomm-mbnmetadata schema informatMetadata/firmwareMetadata.ts, ELF-to-MBN promotion for inventory ininventory/classify.tsandextraction/ArtifactExtraction.ts, plus target format, artifact graph and inventory view entries.docs/guides/firmware/qualcomm-mbn-images.md, a section indocs/guides/firmware/firmware-analysis.md, CLI examples indocs/getting-started/cli.md, sidebar entry, docs index, and an MBN entry in the skill references under.agents/skills/reverse-engineer-anything/and.cursor-plugin/.REA_setting:segment_hasheslists at most 64 rows inline (QUALCOMM_MBN_INLINE_SEGMENT_HASH_LIMIT), withomitted_segment_hashescounting the rest. This is a fixed output ceiling, not an admission limit: every hash position is thehash-tableoffset plus index times hash size, and the whole table stays readable as thehash-table.binregion, so no data becomes unreachable.e_phnumvalue 65535 are format constants, not budgets.Not included: signature or certificate verification, hash recomputation, ELF64 extended numbering via section 0, and MBN formats beyond the legacy header and the ELF hash segment.
Contract and boundary impact
qualcommMbnImage.tsproduces the header, range and hash-segment facts; the reader, inventory classification, extraction and metadata schema consume them without reparsing raw bytes.qualcomm-mbn.qualcomm-mbn. ELF target resolution is unchanged; an ELF image with a hash segment is read asqualcomm-mbnonly for inventory and extraction.qualcomm-mbnformat metadata shape withlayout,header(includingranges) andelf; region children carry their source ranges and SHA-256.docs/public/product-catalog.json), package, or installation impact: none committed; authored skill references updated under.agents/skills/reverse-engineer-anything/and.cursor-plugin/.Expected effects:
Evidence and regression coverage
src/domain/qualcommMbnImage.test.ts(version 3 and version 6 legacy headers, sizes or pointers that disagree, truncated signature range, header-sized files without their code region, ELF with and without a hash segment),src/domain/qualcommMbnImage.boundaries.test.ts(e_phnum65535, wrong entry size, table past the file end, several hash segments, hash count mismatch, version 6 hash header cut short byp_fileszor by the file end),src/artifacts/QualcommMbnArtifactReader.test.ts(inventory by content, region bytes, ranges past the file end, ELF MBN inventory and extraction while resolved as an ELF target, ELF without a hash segment staying ELF, inline hash row ceiling, refusal of non-MBN bytes), andsrc/application/binary/TargetFormatVocabularies.test.ts. Fixtures are built bysrc/domain/qualcommMbnImage.fixture.ts; no vendor bytes.qualcomm-mbnformat value, so a legacy MBN is rejected as an unsupported binary and an ELF MBN is inventoried as ELF. The base revision was not run.rea inspect-artifact ./modem.mbn --json, an ELF32 image built bymbnElfWithHashSegment({ loads: 2 })(848 bytes). Manifestroot_formatisqualcomm-mbn, 5 occurrences (.,header.bin,hash-table.bin,signature.bin,certificate-chain.bin), coveragecomplete. Rootformat_metadata, trimmed:{ "kind": "qualcomm-mbn", "layout": "elf", "header": { "version": 3, "header_bytes": 40, "image_id": 0, "image_source": 3, "image_source_name": "emmc-user", "image_size": 480, "code_size": 128, "signature_size": 256, "certificate_chain_size": 96, "ranges": { "header": { "offset": 192, "length": 40 }, "code": { "offset": 232, "length": 128 }, "signature": { "offset": 360, "length": 256 }, "certificate_chain": { "offset": 616, "length": 96 }, "metadata0": null, "metadata1": null } }, "elf": { "elf_class": 32, "byte_order": "little", "machine": 164, "program_header_count": 4, "hash_segment_program_header": 1, "hash_segment_offset": 192, "hash_segment_file_size": 520, "hash_size": 32, "hash_count": 4, "segment_hashes": [ { "program_header": 0, "segment_type": 7, "file_offset": 0, "file_size": 0, "hash_offset": 232 }, { "program_header": 1, "segment_type": 2, "file_offset": 192, "file_size": 520, "hash_offset": 264 }, { "program_header": 2, "segment_type": 0, "file_offset": 720, "file_size": 64, "hash_offset": 296 }, { "program_header": 3, "segment_type": 0, "file_offset": 784, "file_size": 64, "hash_offset": 328 } ], "omitted_segment_hashes": 0 } }rea inspect-artifact ./sbl1.mbn --json, a raw version 3 header built bymbnLegacyImage(200-byte code, 256-byte signature, 96-byte certificate chain, 592 bytes total):root_formatqualcomm-mbn, layoutlegacy,elf: null,header.rangesofheader0+40,code40+200,signature240+256,certificate_chain496+96, coveragecomplete. A version 6 image with a 16-bytemetadata0region additionally reported an 80-byteheader.binandmetadata0.bin.rea extract-artifact ./sbl1.mbn --output-root "$PWD/ex-sbl1" --jsonwroteheader.bin(40 bytes),code.bin(200),signature.bin(256) andcertificate-chain.bin(96) withcontainment_verified: true. The same command onmodem.mbnwroteheader.bin(40),hash-table.bin(128),signature.bin(256) andcertificate-chain.bin(96).Limitation and refusal examples from the same run:
sbl1.mbncut to its first 400 bytes: stillqualcomm-mbnwith the full declared header, but onlyheader.binandcode.binare listed, coverage isunknown, and the limitations include"signature range 240+256 exceeds the 400-byte file","certificate chain range 496+96 exceeds the 400-byte file"and"image range 0+552 exceeds the 400-byte file".extract-artifactwrote onlyheader.binandcode.bin.sbl1.mbnwithimage_sizeoverwritten to 9999: not claimed.inspect-artifactexits 1 with"code": "target_unavailable","message": "Cannot open artifact: unsupported binary format.","constraint": "file_format_rejected".An ELF32 image with one
PT_LOADand no hash segment (mbnElfImage):root_formatelf, one occurrence, coveragecomplete.Remaining proof gaps: only generated images were used. Vendor
sbl1,tzormodemimages, ELF64 MBNs and big-endian ELF wrappers were not run through the CLI. The MCP adapter was not exercised directly; it shares the artifact readers with the CLI. The fullnpm run checksuite and the acceptance and MCP boundary suites were not run.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-mbn-demo.mp4
Validation performed
npm run test:local -- src/domain/qualcommMbnImage.test.ts src/domain/qualcommMbnImage.boundaries.test.ts src/artifacts/QualcommMbnArtifactReader.test.ts src/application/binary/TargetFormatVocabularies.test.ts: 4 files, 81 tests passednpm run check:fast: typecheck and lint passed (turbo cache hit for these inputs); architecture guards passed across 3136 source filesnpm run docs:check: doc facts check passed;tests/conformance/readmeConsistency.test.ts8 tests passednpm run format:check: all matched files use the correct format (8915 files)npm run verify:test-discovery: all 3919 test and spec files discovered exactly oncenpm run compile, thennode scripts/rea.mjs inspect-artifact <file> --jsonon six generated files andnode scripts/rea.mjs extract-artifact <file> --output-root <dir> --jsonon three: results as shown aboveCompatibility, safety, and release
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.