Skip to content

feat(native): decode Android .note.android.ident ELF notes - #9502

Merged
morluto merged 8 commits into
morluto:mainfrom
saariuslystoned:feat/native-android-ident-elf-note
Nov 9, 2026
Merged

morluto merged 8 commits into
morluto:mainfrom
saariuslystoned:feat/native-android-ident-elf-note

Conversation

@saariuslystoned

@saariuslystoned saariuslystoned commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Decode Android NDK .note.android.ident (owner === "Android", n_type === 1, NT_ANDROID_TYPE_IDENT) ELF notes in inspect_elf_notes / rea inspect-elf-notes so callers receive structured android_api, ndk_version, and ndk_build_number facts instead of falling back to type_name: "unknown" and manual hex slicing. No existing upstream issue is linked; this extends the built-in static ELF note reader alongside GNU and CORE notes.

Problem and expected behavior

Android NDK shared libraries and executables linked with Bionic crtbegin_so.o / crtbrand.S embed a .note.android.ident note (owner: "Android", type: 1):

  • Legacy Android NDK (< r14) and unbranded platform builds emit a 4-byte descriptor storing uint32_t android_api in the ELF image's byte order.
  • Modern Android NDK (r14+) emits a 132-byte (or extended >= 132-byte) descriptor containing uint32_t android_api at 0..4, char ndk_version[64] at 4..68, and char ndk_build_number[64] at 68..132.

Previously, inspect_elf_notes only mapped GNU and CORE note owners, leaving Android type 1 entries as type_name: "unknown" with descriptor.hex: null on 132-byte notes (above the 64-byte preview threshold). Callers inspecting Android native libraries now receive type_name: "android_ident" and a structured android object while truncated or non-ASCII vendor payloads safely degrade android to null and preserve raw descriptor provenance.

Change and scope

Follow the contribution scope.

  • Extend ELF_NOTE_TYPE_NAMES with "android_ident", add androidNoteTypeName(type) for owner === "Android", and add nullable android: { android_api, ndk_version, ndk_build_number } to each note entry in src/domain/native/elfNotes.ts.
  • Add decodeAndroid in src/native/elf/ElfNoteParser.ts following the same endianness and TextBudget (scanned + used) accounting as decodeGnu and decodeCore:
    • descriptor.length === 4: decodes { android_api, ndk_version: null, ndk_build_number: null }.
    • descriptor.length >= 132: caches the 128-byte fixed-slot scan per descriptor slice in TextBudget.scans, validates printable ASCII (0x20..0x7e) before NUL and clean NUL padding across both 64-byte slots (4..68 and 68..132), charges retained string bytes to TextBudget.used, and returns { android_api, ndk_version, ndk_build_number }.
    • Truncated (0..3 or 5..131 bytes), unterminated, control-byte, or non-zero-padded slots return android: null without rejecting valid ELF images.
  • Update the inspect_elf_notes tool contract description, docs/elf-notes.md, and docs/specs/native/android-elf-ident-note/{spec.md,plan.md,tasks.md} (indexed in docs/specs/README.md).
  • Intentionally out of scope: other Android note types (such as NT_ANDROID_TYPE_MEMTAG / NT_ANDROID_TYPE_KUSER), which remain type_name: "unknown" with android: null.

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/domain/native/elfNotes.ts (note entry schema and Android type-name mapping) and src/native/elf/ElfNoteParser.ts (static note-entry projection consumed by ElfNotesProvider, ElfNotesService, inspect-elf-notes, and inspect_elf_notes).
  • Contribution scope fit and linked maintainer decision: not applicable (additive static ELF note decoding within the existing built-in inspect_elf_notes boundary; no target execution, attachment, or external tool invocation).
  • CLI and MCP/tool-catalog contract: inspect_elf_notes / inspect-elf-notes output entries add "android_ident" to type_name and android: { android_api: number, ndk_version: string | null, ndk_build_number: string | null } | null alongside gnu and core.
  • Provider, bridge, target-format, or platform compatibility: portable Node.js static parser across ELF32/ELF64 and little-/big-endian targets.
  • Evidence, artifact, provenance, or reconstruction contract: observed note header/descriptor offsets, SHA-256 digests, and <= 64-byte hex previews remain unchanged; unparsed Android descriptors set android: null rather than fabricating fields.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: CI regenerates ignored catalogs; no build outputs committed.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated (executed):
    • src/domain/native/elfNotes.test.ts: verifies androidNoteTypeName mappings (1 -> "android_ident", other types -> "unknown").
    • src/native/elf/ElfNoteParser.test.ts: covers little-endian (aarch64, x86_64) and big-endian (ELF32, ELF64) .note.android.ident sections with 132-byte, 152-byte extended, and legacy 4-byte descriptors; owner === "Android" with unknown type: 2; 0-, 2-, and 68-byte truncated descriptors; unterminated, control-byte, and non-zero-padded 64-byte slots; and TextBudget scan caching and retained-text limits.
    • tests/boundary/mcp/elfNotesMcp.test.ts: verifies inspect_elf_notes over MCP decodes .note.android.ident and preserves descriptor.hex on short truncated notes without starting a deep provider.
    • tests/acceptance/elfNotesAndroid.test.ts: verifies CLI (inspect-elf-notes --json) and stdio MCP (inspect_elf_notes) parity across little-endian ELF64 and big-endian ELF32 targets.
  • Base reproduction or other evidence: prior to this change, ElfNoteParser.toEntry only checked GNU and CORE owners, emitting type_name: "unknown" with no android field for owner === "Android", type === 1.
  • User-visible CLI/MCP output (representative entries[] item from rea inspect-elf-notes libtarget.so --json / inspect_elf_notes):
    {
      "index": 0,
      "table_kind": "section",
      "table_index": 1,
      "namesz": 8,
      "descsz": 132,
      "type": 1,
      "type_name": "android_ident",
      "owner": "Android",
      "owner_bytes_hex": "416e64726f696400",
      "descriptor": {
        "bytes": 132,
        "sha256": "...",
        "hex": null
      },
      "gnu": null,
      "core": null,
      "android": {
        "android_api": 24,
        "ndk_version": "r27c",
        "ndk_build_number": "12297006"
      }
    }
  • Remaining proof gaps: none for .note.android.ident; other NT_ANDROID_* note types remain raw unknown entries by design.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npx oxfmt . && npx oxfmt --check . — passed (All matched files use the correct format).
  • npm run build:cached — passed (3 successful, 3 total).
  • npm run check:fast — passed (typecheck and lint / module boundaries clean).
  • npx vitest run --project domain src/domain/native/elfNotes.test.ts src/domain/native/elfNoteLayout.test.ts — passed (2 files, 6 tests).
  • npx vitest run --project services src/application/binaryDiagnostics/ElfNotesService.test.ts — passed (1 file, 6 tests).
  • npx vitest run --project adapters src/native/elf/ElfNoteParser.test.ts src/native/elf/ElfNotesProvider.test.ts — passed (2 files, 72 passed, 1 skipped).
  • npx vitest run --project boundary tests/boundary/filesystem/elfNotes.test.ts tests/boundary/filesystem/flutterElfNotes.test.ts — passed (2 files, 15 tests).
  • npx vitest run --project mcp-boundary tests/boundary/mcp/elfNotesMcp.test.ts — passed (1 file, 7 tests).
  • npx vitest run --project acceptance tests/acceptance/elfNotesCli.test.ts tests/acceptance/elfNotesCore.test.ts tests/acceptance/elfNotesAbiEndian.test.ts — passed (3 files, 11 tests).
  • npx vitest run --project acceptance tests/acceptance/elfNotesAndroid.test.ts — passed (1 file, 2 tests).
  • npm run verify:architecture-guards — passed (Architecture guards passed across 2548 source files).
  • npm run verify:test-discovery — passed (Discovered all 3197 test files exactly once).
  • npm run scan:todos — passed (No tech-debt markers found).
  • npm run jscpd — passed (3.46% duplicated lines).
  • npm run knip && npm run knip:production — passed (Knip found no issues).
  • npm run metadata:check && npm run mcp-catalog:check && npm run docs:check && npm run verify:docs:routes — passed (9/9 docs checks and 341 built HTML documentation routes clean).
  • npm run lint:typed — passed (6,676 files, 0 errors).
  • Cross-Node Vitest matrix (v22.23.4, v24.22.1, v26.13.0) across all 12 ELF note suites above — passed (12 files, 119 passed, 1 skipped on each runtime).

Compatibility, safety, and release

  • Breaking changes or migration steps: none; additive nullable android property on inspect_elf_notes entries and "android_ident" enum member on type_name.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable; inspect_elf_notes is a portable built-in static ELF reader that does not invoke external disassemblers or debuggers.
  • Package or release metadata impact: none (inspect_elf_notes tool contract schema updates automatically).
  • Security, privacy, process, or containment review: reads bounded slices from an already admitted in-memory Buffer with fixed 128-byte slot scanning and TextBudget accounting; no filesystem mutation, process execution, or unbounded string allocation.

Author readiness

Human owner: @saariuslystoned

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

Decode Android NDK NT_ANDROID_TYPE_IDENT (.note.android.ident, owner Android, type 1) notes in inspect_elf_notes across legacy 4-byte and modern >=132-byte descriptors with bounded TextBudget accounting.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T14:47:52.398153Z 4bfd755 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The reviewed changes appear safe to merge; no new actionable issue was found.

Summary

Adds structured Android ELF note facts to inspect_elf_notes and inspect-elf-notes.

  • ELF note reports now include Android API and NDK details.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[ELF note] --> B{Android owner and type 1?}
  B -->|No| C[android is null]
  B -->|Yes| D{Descriptor length}
  D -->|4 bytes| E[Decode API using ELF byte order]
  D -->|132 bytes or more| F[Check two fixed string slots]
  D -->|Other| C
  F -->|Invalid| C
  F -->|Valid| G[Charge retained text and decode fields]
  E --> H[Return entry with raw descriptor facts]
  G --> H
  C --> H
Loading

Reviews (7) · Last reviewed commit: "Merge remote-tracking branch 'upstream/m..." · Reviewed by Greptile

Comment thread src/native/elf/ElfNoteParser.test.ts Resolved
Comment thread docs/elf-notes.md Resolved
Comment thread tests/boundary/mcp/elfNotesMcp.test.ts Resolved
@morluto
morluto merged commit e5ddbe8 into morluto:main Nov 9, 2026
9 of 10 checks passed
@morluto morluto mentioned this pull request Nov 11, 2026
3 tasks done
@morluto morluto added area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior enhancement New feature or request labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants