Skip to content

feat(native): list Mach-O function starts and data-in-code entries offline - #14897

Merged
morluto merged 14 commits into
morluto:mainfrom
mvanhorn:fix/macho-function-starts
Nov 27, 2026
Merged

morluto merged 14 commits into
morluto:mainfrom
mvanhorn:fix/macho-function-starts

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Summary

Most Mach-O images, stripped ones included, carry LC_FUNCTION_STARTS: the linker's ULEB128 delta list of every function start in __TEXT. Many also carry LC_DATA_IN_CODE, which marks jump tables and literal data inside the text section. REA reads neither today, so there is no offline way to list a stripped binary's function boundaries or to tell which bytes inside a function are data and not instructions.

This adds an offline inspect_macho_function_starts tool and the CLI command rea inspect-macho-function-starts. It decodes both tables from one thin Mach-O or one slice of a universal file, reports each start's VM address and section and each data-in-code entry's offset, address, length, kind, section and owning start, and counts every structural problem it meets. The image is not disassembled or executed. No issue exists for this; it is a read-only format-inspection addition within the supported contribution scope.

Problem and expected behavior

Use case: given a stripped program, list the function starts the linker recorded, compare them with a provider's procedure list, and find the jump tables and literal pools so they are not decoded as instructions.

Observable outcome:

  • function_starts and data_in_code report each command's status (present or absent), dataoff, datasize, container file_offset and whether the range sits in __LINKEDIT.
  • starts[] holds absolute VM addresses (the first delta is added to the __TEXT vmaddr; a zero delta ends the list) and the containing section.
  • data_in_code_entries[] holds the file offset, VM address, length, kind (DICE_KIND_DATA, JUMP_TABLE8, JUMP_TABLE16, JUMP_TABLE32, ABS_JUMP_TABLE32, or the raw number), containing section, and owner, the greatest decoded start at or before that address.
  • coverage counts starts and entries plus duplicate and mis-sized commands, tables outside __LINKEDIT, commands past the file, truncated or overflowing ULEB128, wrapped and out-of-text starts, a missing __TEXT anchor, trailing bytes, entries that cross a section, unsorted, unmapped and zero-length entries. Any nonzero counter makes coverage.status partial with a limitation naming it.
  • page selects kind (all, starts, data), offset and limit (limit: 0 returns counts only) and reports the next offset for each table.
  • max_entries (default 2,097,152, at most 16,777,216) bounds starts plus data-in-code entries combined. A larger pair is refused whole with details.limit and the combined count as required_value.

Change and scope

  • src/domain/native/machoFunctionStarts.ts: input and result schemas, limitation text, and the issue predicate.
  • src/native/apple/MachoFunctionStarts.ts: slice selection, command loading, ULEB128 walk, data-in-code decoding and paging. It reuses the shared Mach-O load-command walk and file mappings; readMachoImageFromReader gains an optional visit callback so this reader sees LC_FUNCTION_STARTS and LC_DATA_IN_CODE during the one shared walk, and LoadRegion gains an optional macho_segment (name and declared vmaddr) used to find the __TEXT anchor. Other callers are unchanged.
  • src/native/apple/MachoAddressIndex.ts: interval indexes for the smallest containing section and the file-offset-to-VM translation, built once per call, so each start and entry is one binary search. Overlapping sections resolve as a scan would (smallest wins, first declared breaks a tie), and an offset covered by two different translations is reported unmapped. Section names for starts are computed only for the returned page, and decoding yields and checks cancellation every 4,096 entries.
  • Provider, service, port, composition, capability declarations, CLI command, MCP binding, module-layer entry, and provider lifecycle coverage.
  • Docs: new docs/guides/native/macho-function-starts.md, CLI examples in docs/getting-started/cli.md, docs/reference/limits-and-recovery.md, the docs index and sidebar, and the skill references under .agents/skills/reverse-engineer-anything/ and .cursor-plugin/. The existing fixed-ceiling registry entry for the 4 GiB identity ceiling now names this reader, since dataoff and FAT32 slice offsets are 32-bit.

Not included: disassembly, symbolization of starts, LC_FUNCTION_VARIANTS, and dyld shared cache images.

Contract and boundary impact

  • Semantic owner and earliest changed stage: MachoFunctionStarts.ts decodes both tables from the shared Mach-O walk; the provider and service consume its result without reparsing. The shared walk in machoImage.ts remains the single owner of load-command framing and segment mappings.
  • Contribution scope fit and linked maintainer decision: read-only inspection of a local file; not applicable (no target execution, injection, mutation, or protection recovery).
  • CLI and MCP/tool-catalog contract: one new MCP tool inspect_macho_function_starts and one new CLI command inspect-macho-function-starts with --architecture, --kind, --offset, --limit, --max-entries, --max-file-bytes and --max-structure-bytes. Existing tools are unchanged.
  • Provider, bridge, target-format, or platform compatibility: new offline provider rea-macho-function-starts; no existing provider changes behavior.
  • Evidence, artifact, provenance, or reconstruction contract: new result shape with confidence: observed; evidence locations name the two table ranges.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): a universal file requires architecture; architecture on a thin image is refused.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs and skills/; 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.

  • 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: src/native/apple/MachoFunctionStarts.test.ts (11 tests: starts and entries from fixture images, universal slice selection, absent commands, duplicate and mis-sized commands, tables outside __LINKEDIT, truncated and overflowing ULEB128, wrapped and out-of-text starts, section crossings, unsorted, unmapped and zero-length entries, ambiguous file offsets, paging and the entry budget), src/native/apple/MachoAddressIndex.test.ts (4 tests: the section index matches a linear scan over nested, overlapping, tied and empty sections; conflicting and identical file translations), src/native/apple/MachoFunctionStartsProvider.test.ts (4), src/application/binaryDiagnostics/MachoFunctionStartsService.test.ts (4), src/domain/native/machoFunctionStarts.test.ts (2), tests/acceptance/machoFunctionStartsCli.test.ts, tests/boundary/mcp/machoFunctionStartsMcp.test.ts (3), tests/boundary/filesystem/machoFunctionStartsFinalization.test.ts, plus entries in tests/boundary/mcp/absoluteLocalPathTools.test.ts, tests/acceptance/tools/localToolContracts.test.ts and tests/conformance/providerCapabilityCases.ts. Fixtures are built in src/native/apple/MachoFunctionStarts.fixture.ts.
  • Base reproduction or other evidence: the gate's regression proof ran the new tests against the base revision, where they fail because the tool does not exist. The CLI output below is executed against this branch.
  • User-visible CLI/MCP output (if applicable): executed, rea inspect-macho-function-starts demo --json on an arm64 executable built with clang -O1 from a small C file with four functions. The function-starts payload is the 8 bytes b0 09 20 98 01 2c 00 00. Excerpt of normalized_result:
{
  "function_starts": { "status": "present", "dataoff": 32968, "datasize": 8, "file_offset": 32968, "in_linkedit": true },
  "data_in_code": { "status": "present", "dataoff": 32976, "datasize": 0, "file_offset": 32976, "in_linkedit": true },
  "coverage": { "status": "complete", "total_starts": 4, "total_data_in_code": 0 },
  "starts": [
    { "index": 0, "vmaddr": "0x1000004b0", "section": "__text", "issues": [] },
    { "index": 1, "vmaddr": "0x1000004d0", "section": "__text", "issues": [] },
    { "index": 2, "vmaddr": "0x100000568", "section": "__text", "issues": [] },
    { "index": 3, "vmaddr": "0x100000594", "section": "__text", "issues": [] }
  ]
}

Those four addresses are exactly the nm -n demo addresses of _classify, _dispatch, _checksum and _main (all other coverage counters were 0).

Clang emitted an empty LC_DATA_IN_CODE for that arm64 build, so data-in-code was exercised on a synthetic arm64 image written with the test fixture builder (sample.macho, four starts and four entries, the last placed at the end of __text on purpose):

{"index":0,"offset":4160,"vmaddr":"0x100001040","length":16,"kind":"JUMP_TABLE8","section":"__text","owner":{"index":0,"vmaddr":"0x100001000"},"issues":[]}
{"index":1,"offset":4480,"vmaddr":"0x100001180","length":8,"kind":"DICE_KIND_DATA","section":"__text","owner":{"index":1,"vmaddr":"0x100001100"},"issues":[]}
{"index":2,"offset":4864,"vmaddr":"0x100001300","length":32,"kind":"ABS_JUMP_TABLE32","section":"__text","owner":{"index":2,"vmaddr":"0x100001280"},"issues":[]}
{"index":3,"offset":6136,"vmaddr":"0x1000017f8","length":16,"kind":"JUMP_TABLE32","section":"__text","owner":{"index":3,"vmaddr":"0x100001480"},"issues":["crosses_section"]}

Coverage was partial with section_crossings: 1 (every other counter 0) and the limitation "A data-in-code entry is not contained in one section."

Paging: --kind data --limit 2 returned returned_data: 2, total_data: 4, next_data_offset: 2 and no starts.

Budget refusal: --max-entries 4 exited 1 with "code":"resource_constraint", "Mach-O function starts and data-in-code entries total 8, above max_entries (4)", and details.limit {"parameter":"max_entries","effective_value":4,"required_value":8,"cli_flag":"--max-entries"}.

  • Remaining proof gaps: no real binary with a nonempty LC_DATA_IN_CODE was available on this arm64 host, so data-in-code decoding is shown on fixture images only. Universal files were exercised by the fixture tests, not by a shipped universal binary.

Not a boundary fix. The new tool's boundary tests cover MCP absolute-path handling, the finalization of the admitted file, and the provider lifecycle registration.

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 vitest run on the ten test files above: 10 files, 42 tests passed.
  • npm run lint: exit 0, including the numeric REA_ limits and fixed-ceilings verification.
  • node scripts/rea.mjs inspect-macho-function-starts on the clang-built and fixture-built images: output as shown above.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. The visit callback and macho_segment field are optional additions to shared types.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable; offline parsing only, run on macOS arm64 with Node 24.
  • Package or release metadata impact: one new MCP tool and CLI command.
  • Security, privacy, process, or containment review: reads a local file only through bounded positional reads. Table ranges are checked against the file size before reading, both tables count toward max_entries before any per-entry work, section and mapping lookups are logarithmic, and decoding yields and honors cancellation.

AI was used for assistance.

Author readiness

Human owner: @mvanhorn

  • 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.

Author checklist (completed by the PR author before requesting review)

  • 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.
  • I ran every test, build, or measurement needed to validate this change, reported a browser, GPU, or environment gap only when that runtime or hardware is unavailable, and reported the checks I ran and their results without presenting inferred correctness or speedups as measured.
  • Comments explain constraints or non-obvious decisions; task history and conversations stay out of code and docs.
  • Documentation is concise and factual, without punchy slogans or promotional language.
  • This change fixes the root cause and follows the engineering rules in AGENTS.md.
  • Formatted input is interpreted once at the owning boundary, and consumers use the owner's parsed facts. See Interpret boundary facts once.
  • Combined failures preserve partial observations, remaining resources, and cleanup facts. See Own the lifecycle.
  • A hardcoded limit is an REA_ runtime setting with a default, floor, and maximum, unless a fixed ceiling has a stated reason. See Adding a runtime setting.

Demo

demo

…fline

The diff adds a static reader for LC_FUNCTION_STARTS and LC_DATA_IN_CODE
on one thin Mach-O or one selected slice of a universal file. Starts are
absolute VM addresses from ULEB128 deltas off the __TEXT vmaddr, and
each data-in-code entry reports offset, length, kind, and the function
start that owns its address, with one offset and limit applied to each
selected table and counts covering every entry.
inspect_macho_function_starts and inspect-macho-function-starts expose
that report, require architecture only for a universal file, and refuse
a combined table above max_entries with no partial result. The shared
load-command walk now yields each command once and stores the Mach-O
segment name and vmaddr on load regions, and the guides and limit docs
record coverage, paging, and the read and entry budgets.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 27, 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-27T20:07:26.864543Z a616791 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 27, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The reviewed changes appear safe to merge, with no new actionable issue found.RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

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

Summary

Adds offline Mach-O function-start and data-in-code inspection through CLI and MCP.

  • Mach-O inspection reports function starts and data-in-code entries.
  • The new Mach-O report is available through the CLI and MCP.

mvanhorn states that no issue was opened because this is read-only format inspection within the supported contribution scope.

Review used source checks; no tests were run. The supersession check could not complete because GitHub access was unavailable.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[CLI or MCP request] --> B[Shared service]
  B --> C[Provider opens identity-checked file]
  C --> D[Select thin image or universal slice]
  D --> E[Shared load-command reader]
  E --> F[Load both tables]
  F --> G[Check entry budget and decode]
  G --> H[Count issues and build requested pages]
  H --> I[Return observed Evidence]
Loading

Reviews (10) · Last reviewed commit: "fix(native): report a non-Mach-O input a..." · Reviewed by Greptile

Comment thread src/native/apple/MachoFunctionStarts.ts Resolved
Comment thread src/native/apple/MachoFunctionStarts.ts Resolved
Comment thread src/native/apple/MachoFunctionStarts.ts Resolved
Comment thread src/native/apple/MachoFunctionStarts.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2fae00a190

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/native/apple/MachoFunctionStarts.ts Resolved
Comment thread src/native/apple/MachoFunctionStarts.ts Resolved
mvanhorn and others added 3 commits November 27, 2026 04:44
- Check each start against an interval index of executable segments, built
  once, instead of scanning every segment per start.
- Walk LC_FUNCTION_STARTS once. Count and check every start and
  data-in-code entry, but build result objects only for the requested page,
  and resolve owners for that page during the same walk.
- Keep every declared Mach-O segment in the shared reader (macho_segments),
  so a __TEXT with no file bytes still anchors the deltas, as
  llvm-objdump does. LoadRegion no longer carries macho_segment.
- On 32-bit ARM, clear the Thumb tag (bit 0) from published starts and
  report it as `thumb`, keeping the tagged value for the next delta, as
  ld64 encodes and LLDB decodes. Wrap 32-bit images at 2^32.
- Intersect Evidence file ranges with the selected universal slice.
@morluto

morluto commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Thanks for this reader. I pushed one commit on top of your branch, 2801fc2, to address the six review threads. Your history is unchanged.

  • Bounded work and memory:
    • One walk of LC_FUNCTION_STARTS counts and checks every entry, but builds result objects only for the requested page.
    • Owners for the paged data-in-code entries are resolved during that walk.
    • Executable containment is one interval-index lookup per start.
  • Declared segments: the shared reader now keeps every segment command as macho_segments, so a __TEXT with no file bytes still anchors the deltas. LoadRegion.macho_segment is removed.
  • Thumb: on 32-bit ARM, starts clear bit 0 and report thumb. 32-bit images wrap at 2^32.
  • Evidence ranges: they stay inside the selected universal slice.

The semantics were checked against these references:

  • llvm-objdump PrintFunctionStarts (llvm/tools/llvm-objdump/MachODump.cpp) and MachOObjectFile::ReadULEB128s: deltas start at the first __TEXT segment command's vmaddr, and a zero delta ends the list.
  • ld64 FunctionStartsAtom::encode (src/ld/LinkEdit.hpp): a Thumb start is encoded with bit 0 set, and the next delta is taken from that tagged value.
  • LLDB ObjectFileMachO::ParseSymtab: on ARM, bit 0 is cleared from the code address and the start is marked Thumb.
  • dyld MachOLoaded::forEachFunctionStart and mach_o::DataInCode: the entry layout is offset, length, kind; kinds are 1–5; and offset is relative to the slice's mach_header.

Two places where this reader is stricter than llvm-objdump, which this PR already did:

  • A truncated or overflowing ULEB128 is reported. llvm's DataExtractor treats it as the end of the list.
  • A start outside every executable segment stops decoding and is reported. llvm doesn't check this.

Comment thread src/native/apple/MachoFunctionStarts.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2801fc209f

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

- One table, MACHO_DICE_KIND_NAMES, names data-in-code kinds for the
  reader, the schema and the report check, which each had their own copy.
- Each linkedit command's dataoff/datasize is normalized once against the
  slice (end, 32-bit fit, in-slice bytes) instead of the overflow check and
  the in-slice length being recomputed in three helpers.
- Name CPU_TYPE_ARM, VM_PROT_EXECUTE and UINT32_MAX after their headers.
- Report coverage.text_not_at_header when __TEXT does not map file offset
  0: llvm-objdump anchors the deltas on the __TEXT vmaddr and dyld on the
  mach_header address, and they disagree there.
- Pin the fixture's expected starts to literal addresses.
# Conflicts:
#	docs/reference/limits-and-recovery.md
@morluto

morluto commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Follow-up: a brittleness pass, in aa09348. I also merged main (c721e7f) and refreshed the schema summary (628153d).

Found and fixed:

  • Data-in-code kinds named in three places. The reader, the output schema and the report check each had their own copy. MACHO_DICE_KIND_NAMES in the domain module is now the only table, and machoDataInCodeKind maps a raw value from it.
  • Linkedit range arithmetic repeated. The 32-bit end check and the in-slice length were recomputed in three helpers. Each command's dataoff/datasize is now normalized once against the slice (declaredBlob), and the helpers read that.
  • Unnamed constants. 12, 4 and 0xffffffff are now CPU_TYPE_ARM (<mach/machine.h>), VM_PROT_EXECUTE (<mach/vm_prot.h>) and UINT32_MAX, the width of the linkedit_data_command fields.
  • A disputed delta base, previously settled silently.
    • llvm-objdump adds the first delta to the first __TEXT segment command's vmaddr. dyld's forEachFunctionStart adds it to the mach_header address.
    • The two agree only when __TEXT maps file offset 0. When it doesn't (including a __TEXT with no file bytes), the reader still anchors on vmaddr, but now reports coverage.text_not_at_header: 1, a limitation, and partial coverage.
  • Expectations that mirrored the implementation. The shared expected addresses came from the same delta accumulation the decoder does. A test now pins them to literal values, and the armv7 test uses LLDB's addresses directly.

Left as is, on purpose:

  • First __TEXT and first __LINKEDIT only. That matches llvm-objdump, which stops at the first __TEXT, and the PR already reports duplicates as a limitation.
  • Stricter than llvm on malformed tables. The reader reports a truncated or overflowing ULEB128, and a start outside every executable segment. llvm's DataExtractor simply stops at the first.

Sources:

  • llvm-objdump PrintFunctionStarts and MachOObjectFile::ReadULEB128s, read from llvm-project main.
  • ld64 FunctionStartsAtom::encode and dyld MachOLoaded::forEachFunctionStart / mach_o::DataInCode, both via DeepWiki.
  • LLDB ObjectFileMachO::ParseSymtab, via DeepWiki.
  • blacktop/go-macho GetFunctions, via DeepWiki, as a second decoder for the base and terminator.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 628153ddd8

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/native/apple/MachoFunctionStarts.ts Resolved
The architecture help for four commands said "as lipo -thin does", which
the CLI option-alias check reads as a registered short flag `-thin`.
Describe the lipo behavior without spelling its flag.
Comment thread src/native/apple/MachoFunctionStarts.ts Resolved
Comment thread src/native/apple/MachoFunctionStarts.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b89c576b63

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/native/apple/MachoFunctionStarts.ts Resolved
…the header

- Refuse a data table above max_entries from its byte count, and stop the
  start walk at the remaining allowance, so the allowance bounds decoding
  work. The refusal no longer claims a required_value it did not measure.
- Map each data-in-code offset as the mach_header's VM address plus the
  offset, the way ld64 encodes it and dyld documents it. MH_OBJECT does not
  map its header, so its base is 0. The shared container now carries
  mach_header.filetype.
- Use the same header address for text_not_at_header, which also catches a
  header shifted by SG_HIGHVM.
- Report a list that ends without its zero terminator as
  unterminated_starts.
- Accept an observed empty section name in both result schemas.
@morluto

morluto commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Second follow-up, in b6a68c3, covering the six new review threads.

  • The entry budget bounds the work again. A data table larger than max_entries is refused from its byte count before any entry is read. The start walk stops at whatever allowance remains. The refusal no longer reports a required_value: decoding stops before the full total is known, so the number would only be a lower bound.
  • Data-in-code offsets are now header-relative. Each address is the mach_header address plus the offset, which is how ld64's DataInCodeAtom::encode writes it and dyld documents it. An MH_OBJECT doesn't map its header, so its base is 0. The shared container now carries mach_header.filetype.
  • text_not_at_header uses the same header address. That check now also catches a header that SG_HIGHVM shifts.
  • A list without its zero terminator is reported as unterminated_starts.
  • Empty section names are now accepted by both result schemas.

Two sources were added for the data-in-code semantics: ld64 DataInCodeAtom::encode in src/ld/LinkEdit.hpp, and dyld mach_o::DataInCode, both read through DeepWiki.

Comment thread src/native/apple/MachoFunctionStarts.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b6a68c3604

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/native/apple/MachoFunctionStarts.ts Resolved
…ry total

- Count LC_FUNCTION_STARTS and LC_DATA_IN_CODE commands during the shared
  load-command walk into a compact tally (two 32-bit words per command)
  instead of retaining a view and an object for each one. The shared
  visitor now hands over the image's byte order.
- When the image has no starts to decode, a data table above max_entries is
  refused with its exact count as required_value.
@morluto
morluto enabled auto-merge (squash) November 27, 2026 18:50

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d57b7eefee

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/native/apple/MachoFunctionStarts.ts Resolved
@morluto
morluto disabled auto-merge November 27, 2026 18:56
Ask the shared Mach-O header recognizer before the thin reader. An ELF or
PE file passed without `architecture` has no Mach-O magic, so it is an
unrecognized target for this operation. A recognized Mach-O with a broken
or cut-off header still fails as malformed or truncated.
@morluto
morluto enabled auto-merge (squash) November 27, 2026 20:03

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a61679120e

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/native/apple/MachoFunctionStarts.ts Resolved
@morluto
morluto merged commit 61fb6cf into morluto:main Nov 27, 2026
58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants