Repository navigation
feat(firmware): decode ESP-IDF Non-Volatile Storage (NVS) flash partitions - #14436
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; no blocking issue remains. SummaryAdds read-only ESP-IDF NVS decoding through CLI and MCP, with checksum checks, blob reconstruction, retained Evidence, and paged views.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[CLI or MCP request] --> B[Check caller inputs]
B --> C[Read stable file and digest]
C --> D[Check selected partition bounds]
D --> E[Decode pages and check checksums]
E --> F[Reassemble blobs and derive coverage]
E --> G{Decoded size fits budget?}
F --> G
G -->|No| H[Return typed resource refusal]
G -->|Yes| I[Create complete Evidence]
I --> J[Complete inline result]
I --> K[Retained Evidence with summary or paging]
Reviews (9) · Last reviewed commit: "fix(firmware): bound decoded NVS represe..." · Reviewed by Greptile |
735976c to
944cd20
Compare
…tions Add offline ESP-IDF v1/v2 NVS partition decoding via `inspect_esp_nvs` (`rea inspect-esp-nvs`) with complete retained Evidence, `detail: "summary"` and `inspect_analysis_view` (`kind: "esp-nvs"`) paging, linear O(N+M) v2 multi-chunk blob reassembly, slot-by-slot CRC recovery past damaged item headers, fail-closed `partition_offset`/`partition_bytes` bounds validation, and full capability conformance and provider lifecycle coverage.
445fee6 to
2fe372e
Compare
…ption layout Page states now follow ESP-IDF's PageState constants (corrupt 0xfffffff0, invalid 0, unknown otherwise), with the header CRC and whether entries were walked reported separately. NVS encryption keeps page headers in plaintext, so an encrypted page is reported as a valid page whose item headers are all unreadable instead of as a header CRC failure. Item headers follow Item::checkHeaderConsistency: span per type, BLOB_IDX and BLOB_DATA chunk-index rules, and a variable item's span matching its length. An inconsistent header is not trusted and the walk advances one slot. Unrecognized types are no longer entries with unknown values, and namespace index 0 items that are not definitions are reported instead of skipped silently. Adds float (0x24) and double (0x28) items, keeps the bytes of non-UTF-8 strings and keys, and marks older copies of a key superseded by a higher page sequence number or a later slot. Spec constants are named once and v2 blob reassembly moves to its own module.
|
Maintainer review of the NVS decoder, checked against ESP-IDF's own sources. Fixes are in commit 0e7a656 on this branch. Heads-up: commit 445fee6 was dropped when this branch was force-pushed. I reapplied it on top of your rebased head, so please pull before your next push. Defects fixed
Brittleness fixed
Left as is
TestsThere are six new domain regressions: float/double, page states, an encrypted-layout page, inconsistent headers, supersession, and non-UTF-8 bytes. The existing tests are updated. These pass:
Sources
|
…map span checks and artifact handoff
…n page versions and -0
… dropping them An interrupted page move leaves an older copy of a BLOB_DATA chunk next to the copy a recovered blob used. a2e8fc1 stopped reporting it as an orphan by skipping every chunk with a claimed index, which also dropped the older copy silently, including one whose bytes differ. It is now reported as blob_data_copy, superseded, with its own CRC-based completeness, and does not make coverage partial.
…S blob chunks superseded
Head branch was pushed to by a user without write access
Summary
Advances #3615 (Acceptance Criterion 3: Non-Volatile Storage key-value decoding) and #7955 by adding
inspect_esp_nvs(rea inspect-esp-nvs), a portable, read-only static decoder for ESP-IDF v1 and v2 Non-Volatile Storage (data/nvs) flash partitions and 4096-byte aligned ESP32/ESP8266 flash dump slices.Problem and expected behavior
inspect_artifacton anesp-flash-imagedump locates and carvespartitions/nvs.binas raw bytes, leaving analysts to invoke external Pythonnvs_partition_gen.pyor custom scripts to inspect persisted device configuration, namespace tables, calibration values, and multi-chunk blobs.With
inspect_esp_nvs:empty,active,full,freeing, orcorrupt_or_encrypted), sequence numbers, v1 (0xff) / v2 (0xfe) format markers, and 2-bit entry-state bitmaps (empty,written,erased).esp_rom_crc32_le(0xFFFFFFFF, ...)checksums across page headers ([4..28)), 32-byte item headers ([0..4) || [8..32)), and variable-length payloads, advancing slot-by-slot across damaged item headers so subsequent intact keys remain decoded.ns_index = 0), primitive integers (u8..u64,i8..i64), UTF-8 strings (sz), v1 single-page blobs, and v2 multi-pageBLOB_IDX+BLOB_DATApayloads in linear time with streaming SHA-256 digests, bounded 128-byte hex previews, and explicitblob_data_orphan/missing_chunksreporting.detail: "summary", bounded inlinemax_entries,--evidence_output, andinspect_analysis_view(kind: "esp-nvs"andkind: "evidence-json").partition_offset/partition_bytesselections that extend past EOF rather than silently truncating, preserves caller-selected local values verbatim without guessing secrecy from key names, and reports XTS-AES encrypted or corrupt pages explicitly ascorrupt_or_encrypted(coverage.status: "partial").Change and scope
Follow the contribution scope.
Read-only static byte inspection over a caller-selected local file (
not applicablefor execution, injection, mutation, or protection recovery). Encrypted NVS (nvs_keysXTS-AES) is not decrypted.Contract and boundary impact
src/domain/firmware/espNvs.ts,src/domain/firmware/espNvsItemDecoder.ts,src/domain/firmware/espNvsParser.ts, andsrc/domain/analysisView/espNvsView.tsown page/bitmap/CRC32 validation, linear v2 blob reassembly, and retained-Evidence view paging.inspect_esp_nvs(rea inspect-esp-nvs <path> [--partition-offset N] [--partition-bytes N] [--max-entries N] [--max-file-bytes N] [--detail complete|summary] [--evidence_output PATH]) andinspect_analysis_viewkind: "esp-nvs".ESP_NVS_PROVIDERinsrc/firmware/espNvs/EspNvsProvider.ts), registered in capability conformance and provider lifecycle coverage.file-offset-rangepartition bounds, retained parentevidence_linkswhen inlinemax_entriesordetail: "summary"bounds delivery, and explicitcompleteness("complete" | "missing_chunks" | "crc_mismatch").ArtifactResourceScopeandreadStableArtifact;max_file_bytesrefusals report typeddetails.limit(control_kind: "parameter"), and out-of-boundspartition_offset/partition_bytesfail closed withAnalysisInputError.docs/public/product-catalog.json), package, or installation impact: Authored guide added atdocs/guides/firmware/esp-nvs.md, skill guidance updated in.agents/skills/reverse-engineer-anything/references/native-and-artifacts.md(synced to.cursor-plugin/), and advertised schema summary added atscripts/verify/advertised-schemas/tools/inspect_esp_nvs.json. Ignored generated outputs remain uncommitted.Expected effects:
Evidence and regression coverage
src/domain/firmware/espNvs.test.ts(executed): namespace registration,u32,sz, and multi-page v2BLOB_IDX+BLOB_DATAreassembly, 7,812-itemchunkCount=255linear-time regression, damagedspanbyte slot-by-slot recovery of following intact keys, out-of-boundspartitionBytesrefusal, and encrypted/corrupt page handling.src/application/binaryDiagnostics/EspNvsService.test.ts(executed): digest-bound Evidence,callerAnalysisParametersfiltering, inlinemax_entrieswith retained parent Evidence,max_file_bytescontrol_kind: "parameter"recovery, and mid-runAbortControllercancellation.tests/boundary/mcp/espNvsMcpCli.test.ts(executed): end-to-end advertised MCP and public CLI parity over a non-zeropartition_offsetflash slice, retained Evidence recovery viainspect_analysis_view(kind: "esp-nvs"andkind: "evidence-json"),detail: "summary", CLI--evidence_output, and out-of-boundspartition_bytesfailure.tests/conformance/providerCapabilityCases.ts&tests/support/providerLifecycleCoverage.ts(executed): registeredespNvsand"rea-esp-nvs".nvs.binas opaque bytes without decoding ESP-IDF NVS pages or records ([Feature] Hardware and Embedded Reverse Engineering: ESP32 firmware extraction, NVS decoding, raw flash mapping, and bus capture analysis #3615).nvs_keysis intentionally out of scope.For evidence-bearing changes:
Validation performed
node scripts/run-typescript.mjs --noEmit && node scripts/run-typescript.mjs --noEmit -p tsconfig.scripts.json— passednpx oxlint -c .oxlintrc.json --quiet <changed-files> && npx oxfmt --check <changed-files>— passednode scripts/verify-module-boundaries.mjs && node scripts/verify/rea-numeric-limits.mjs && node scripts/verify/fixed-ceilings.mjs && node scripts/verify/architecture-guards.mjs— passednpx vitest run src/domain/firmware/espNvs.test.ts src/application/binaryDiagnostics/EspNvsService.test.ts src/contracts/analysisDetail.test.ts tests/boundary/mcp/espNvsMcpCli.test.ts tests/boundary/mcp/advertisedDialect.test.ts tests/conformance/providerCapabilityConformance.test.ts tests/evaluation/providerLifecycleCoverage.test.ts tests/evaluation/fixedCeilingGuard.test.ts tests/evaluation/moduleReExportGuard.test.ts tests/boundary/cli/cliContractCommandParity.test.ts tests/boundary/mcp/enhancedTools.01-lists-the-complete-target-open.test.ts— passed (11 files, 1,144 tests)Compatibility, safety, and release
.cursor-pluginskill mirror andscripts/verify/advertised-schemas/tools/inspect_esp_nvs.json.span, andArtifactResourceScopehandle cleanup.Author readiness
Human owner: @liziye627-design