feat(apple): inspect Image4 (IMG4, IM4P, IM4M) firmware containers offline #14907
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #14907"
general
weight: 0.35
mvanhorn
Summary
Apple ships boot chain components, kernel caches and coprocessor firmware wrapped in Image4: a DER
IM4Ppayload, anIM4Msigned manifest, and anIMG4that bundles both with optionalIM4Rrestore info. REA does not recognize these files today, soinspect-artifactreports a.im4por.img4as unknown bytes and there is no offline way to see the payload type, whether it is encrypted, or what the manifest declares.This adds an
apple-img4artifact format.inspect-artifactandextract-artifactrecognize the container from its content (a DER SEQUENCE whose first element is the IA5StringIMG4,IM4PorIM4M), report its structure, and expose the payload, manifest and restore info as entries. Nothing is decrypted, decompressed, executed or signature-checked. Discussed in #14934. It is a read-only format-inspection addition within the supported contribution scope.Problem and expected behavior
Use case: given
kernelcache.im4por a personalized.img4from a restore bundle, find out what the payload is, whether it is encrypted or compressed, and which chip, board and objects the manifest names, then pull the stored payload out for the Mach-O tools.Observable outcome:
format_metadatahas kindapple-img4andmagic(IMG4,IM4PorIM4M).payloadreportstype(such askrnl,ibot),description, the storedoffsetandlength,compression(none, an LZFSE block magic, orcomplzss),uncompressed_size,payload_magic,encrypted,keybag_countandkeybag_types. Keybag IVs and keys are never copied into metadata, limitations or errors.manifestreportsversion, body properties (CHIP,BORD,ECID,CPRO,SDOMand others), per-object properties withDGSTas hex,signature_sizeandcertificate_chain_size.restore_infolistsproperties_presentwithvalues: "redacted".payload,manifest.der(the IM4M SEQUENCE without the[0]wrapper) andrestore-info.der. An encrypted payload is listed andopenrefuses it. Compressed payloads are returned as stored withcompressedSizeequal to the stored length.unknownwhenever one is present. A truncated value fails the read.Change and scope
src/domain/apple/image4.ts: the Image4 parser. It walks DER by header, loads nested values up to 256 KiB and walks wider ones by header so a large payload is ranged, not read. It decodes IM4P, IM4M and IM4R, keybags, compression and the four allowances.src/artifacts/Image4ArtifactReader.ts: the positional reader that serves the three entries and refuses an encrypted payload on open.src/domain/asn1Ber.ts: the shared BER header decoding moves into an exportedreadAsn1BerHeader, which also decodes high-tag-number form (needed for the PRIVATE-classMANB,MANPandBNCNtags) with a 5-octet cap and rejects non-minimal forms.Asn1BerFailuregains atruncatedflag set by every failure that means the input ended early. Image4 uses that flag to fail truncated reads instead of matching message text.artifactFormats.ts,artifactFormatRecognition.ts,artifactFormatMetadata.ts,firmwareMetadata.ts,targetFormats.ts,artifactGraph.ts,artifactInventoryView.ts,ArtifactReader.tsand the PE overlay format list.docs/guides/apple/image4-containers.md, CLI examples indocs/getting-started/cli.md,docs/reference/limits-and-recovery.md,docs/reference/supported-targets.md, the docs index and sidebar, and the skill references under.agents/skills/reverse-engineer-anything/and.cursor-plugin/. The four allowances are registered inscripts/verify/fixed-ceiling-registry.json, andscripts/ci/scopes.mjsmaps the new files.Not included: decryption, LZFSE or LZSS expansion, signature or certificate validation, and decoding IM4R values.
Contract and boundary impact
image4.tsinterprets the DER once at recognition; the reader, metadata and inventory view consume its parsed facts.inspect-artifactandextract-artifactgain one format,apple-img4.apple-img4metadata and entry metadata (decoded: false,unpacked: false).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/apple/image4.test.ts(21 tests: IM4P, IM4M and IMG4 structure, keybags with and without a decodable layout, compression agreement and disagreement,complzssheaders, oversize octet strings and integers, tag-name mismatches, indefinite and non-minimal lengths, trailing bytes, truncation, the four allowances),src/artifacts/Image4ArtifactReader.test.tsandsrc/artifacts/Image4ArtifactReader.boundaries.test.ts(the three entries per container type, encrypted refusal on open, stored LZFSE and LZVN bytes returned undecoded, truncation, a malformed high tag, each of the four allowances, and indefinite values that are not bounded),src/domain/asn1Ber.test.ts(5 tests: low and high tags, header lengths, malformed high tags, thetruncatedflag), plus entries inartifactFormatRecognition.test.ts,TargetFormatVocabularies.test.tsandtests/boundary/providers/native/artifactProvider.standaloneFormats.test.ts. Fixtures are built insrc/domain/apple/image4.fixture.ts.inspect-artifactdoes not recognize these files. The CLI output below is executed against this branch.rea inspect-artifact sample.img4 --jsonon an IMG4 holding an LZFSEkrnlIM4P, an IM4M and an IM4R:rea extract-artifact sample.img4 --jsonwrotemanifest.der(247 bytes),payload(32) andrestore-info.der(51) withcontainment_verified: trueand coverage complete.rea inspect-artifact encrypted.im4p --jsonon anibotIM4P with two keybags reportedencrypted: true,keybag_count: 2,keybag_types: [1, 2]. The JSON contains none of the fixture IV or key bytes.rea extract-artifact encrypted.im4p --jsonrefused withunsupported_target: "Archive entry payload is encrypted; REA does not decrypt archive entries, so the archive cannot be extracted completely".rea inspect-artifact deep.im4m --jsonon an IM4M with 40 nested SEQUENCEs refused with "Image4 DER nesting exceeds 32 levels. This release has no runtime override." and{ allowance: "The Image4 DER depth allowance", limit: 32, unit: "levels" }.complzsshandling is shown on synthetic headers.Not a boundary fix. The new reader's boundary tests cover truncation, a malformed high tag, the four allowances, and indefinite or trailing data kept as limitations.
For evidence-bearing changes:
Validation performed
npx vitest runon the seven test files above: 7 files, 143 tests passed.npm run lint: exit 0, including the fixed-ceilings verification.node scripts/rea.mjs inspect-artifactandextract-artifacton the fixture-built files: output as shown above.Compatibility, safety, and release
readAsn1BerHeaderand thetruncatedflag are additions. In the shared reader, a high-tag-number form is now decoded instead of refused; existing callers match on low tags and are unaffected.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.Demo
!demo
<video src="https://mvanhorn.github.io/pr-demo-assets/rea/2026-11-27-802-feat-apple-image4-containers/out.mp4" controls width="720"></video>