Repository navigation
feat(go): recover bounded Go string literals from (ptr, len) headers - #9206
Conversation
[Medium impact] The PR appears safe to merge; no new actionable issues were found. SummaryAdds opt-in recovery of bounded Go string literals from static
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[CLI or MCP request] --> B[Read selected image]
B --> C[Parse native mappings and section flags]
C --> D{String literals requested?}
D -->|No| E[Existing build information]
D -->|Yes| F[Bounded static header scan]
F --> G[Inferred strings with file ranges and limits]
E --> H[Complete Evidence]
G --> H
H --> I[Summary or retained string pages]
Reviews (8) · Last reviewed commit: "test(go): cover Mach-O region-index canc..." · Reviewed by Greptile |
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. |
There was a problem hiding this comment.
TL;DR: This is a code read. I ran nothing from the PR, and CI has not run on this head yet. Default calls stay the same and the scan has firm limits. I have one small point about which characters the text filter drops.
Edit (7 Nov): I ran the tests for this PR in a VM, at head 21636ae, which adds the author's ZWJ and ZWNJ change. Results here.
I read the PR head 578114c against its merge base 48f5f30. Main is now 99db80a, and none of main's new commits touch these files.
Nit
- The filter also drops joiners.
DISALLOWED_GO_STRING_CODE_POINTrejects all of\p{Cf}(GoStringLiterals.tslines 28 and 29). That keeps bidi controls like U+202E and the BOM out, which is good. But U+200C and U+200D areCftoo. Emoji sequences use U+200D, and Persian or Hindi text often uses U+200C. Go strings with those would be dropped. Allowing those two and still rejecting the rest ofCfwould keep that text.
Looks good
- Default calls don't change. Both new inputs are
exactOptionalwith no default (goBinary.tslines 83 to 93). The service puts the parsed input straight into Evidence parameters (GoBinaryService.tsline 76). So an option you leave out stays out. The CLI only forwards each option when it is set (goCommands.tslines 67 and 73), and--max-string-literalsalready usescliDecimalField. The report'sstring_literalsisexactOptionaltoo (goBinary.tsline 142). - The scan is bounded. It has a 64 MiB header scan budget, a 4,096-byte cap per string and a 512 KiB cap on total output (
goBinary.tslines 23 to 25). It tracks at most 100,000 candidates (GoStringLiterals.tsline 19) and checks the cancel signal every 65,536 steps (line 97). - No overflow. Pointer and length are
BigIntuntil the length passes the 4,096 check (lines 103 to 115). So 64-bit addresses above 2^53 can't lose precision, and a slice can't run past the end of its section. - Chained fixups are named. A Mach-O with
LC_DYLD_CHAINED_FIXUPSgets a limitation saying the scan can miss headers there.
Not run
- No build, no typecheck, no tests. Each point comes from reading the code.
- I did not run it on a real Go binary, so I can't say how many literals it finds or how often it misses.
- I did not check how PE sections whose virtual size is larger than their raw size are handled.
🤖 Written with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊
|
TL;DR: I tested head 21636ae, which adds the author's ZWJ and ZWNJ change after my code read. All 7 changed test files pass on Node 22, 24 and 26, and the change keeps both joiners and still drops U+202E. On a real Go binary the new flags work, and a call without them matches REA 6.8.0 apart from one field that main added since. Edit (7 Nov): I ran this PR at head 95c5da6 in a VM, and the results are here. This is the run results only. My code read above was of the older head 578114c. I ran it all in a Fedora 44 VM: 210 tests in the 7 changed test files, and one real Go binary. That binary is fzf 0.74.5 (MIT), Fedora's package build. REA only read fzf. I never ran it. The joiner fix worksI wrote a scratch test (not PR code) with the PR's own fixture builder. It feeds four strings through
Real Go binaryfzf is an ELF amd64 file of 5,062,184 bytes. Each run exited 0.
Still not run
Test setup
CommandsAll in the VM, exit 0 unless noted. Times are wall clock from the VM.
🤖 Written and tested with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊 |
…ng-headers # Conflicts: # .agents/skills/reverse-engineer-anything/SKILL.md
|
TL;DR: I ran head 95c5da6 in a VM. All 7 changed test files pass on Node 22, 24 and 26 (211 tests), and fzf gives the same numbers as my earlier run. In scratch runs, a data section that spans two touching readable regions is now read. A read-only section that is not fully readable is now skipped. Edit (8 Nov): I ran the new head, a06b979, in a VM, and the results are here. This is the run results only. My review above covers the older heads: 578114c (code read) and 21636ae (tests). Since then, 0eacab3 merges main. Then 95c5da6 adds three things. It adds the Mach-O region index and a schema check for the MCP tool. It also adds a test with 25,000 sections. On this head only Greptile Review and Validate author declaration ran in CI. No test workflow ran. Tests
That is 211 tests, one more than the 210 in my last run, because The 500 ms limitThe new test fails if the 25,000-section build takes more than 500 ms. Vitest does not print that time. So I rebuilt the same container in a scratch script and timed three calls in a fresh process on each Node. This is a stand-in, not the test's own number.
The slowest was 88.3 ms, with nothing else running in the VM. I did not test a busy machine. Mach-O sections that span two load regionsI built small Mach-O containers by hand. They are not real Mach-O files. I ran each one through the head and through 21636ae. In each one the
So the merge of touching readable regions works as the code says. One side effect shows up when I do the same for the read-only The cancellation testThe cancellation test never fires inside the region index. I ran the 25,000-section container with a scratch copy of the test's cancel hook. The region index calls the cancel check 49 times. The test's hook ignores all 49, because it throws only after the first section is read. The throw then lands in the section loop in Real Go binary and MCPfzf 0.74.5 (MIT), Fedora's package build, same file as before (same sha256). REA only read it. The three CLI runs below exited 0, and the MCP calls give these counts.
I also called Still not run
Test setupCommandsAll in the VM, exit 0 unless noted. Times are wall clock from the VM.
🤖 Written and tested with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊 |
|
TL;DR: At a06b979, the PR's 7 changed test files pass on Node 22, 24 and 26 (221 tests). The cancellation test now fires inside the region index, which my review above said it didn't. A new table test also expects the __rodata drop I found, so the drop looks intended.
Not run
Test setupCommandsnpm ci --offline
npm run test:prepare
xvfb-run -a npm run test:focused -- src/application/go/GoBinaryService.test.ts src/domain/analysisView/goBinaryView.test.ts src/go/GoStringLiterals.test.ts tests/acceptance/goBinaryCli.test.ts tests/boundary/cli/cliIntegerArguments.test.ts tests/boundary/go/goBinaryProvider.test.ts tests/boundary/mcp/goBinaryViews.test.ts🤖 Written and tested with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊 |
|
Welcome to the project, @saariuslystoned! Thanks for adding opt-in recovery of Go string literals from pointer-and-length headers. Exposing individual inferred strings with their limitations gives analysts a useful way to examine packed data. |
Stoked to be here brother; big things coming for us all; i appreciate you and your humbleness; |
Summary
Go compilers pack static string literals contiguously in read-only data sections (
.rodatain ELF,__TEXT,__rodata/__TEXT,__constin Mach-O,.rdatain PE) without NUL terminators, causing generic C-string scanners (search_strings) to concatenate adjacent literals into unusable multi-kilobyte runs (for exampleListResourceProvidersgenaihttps://example.invalid/v1).This PR adds opt-in, bounded static
(ptr, len)reflect.StringHeaderliteral recovery toinspect_go_binary(MCP) andinspect-go-binary(CLI) viainclude_string_literals/--include-string-literalsandmax_string_literals/--max-string-literals, along with retainedgostring_literalsview projection and filtering.Problem and expected behavior
When triaging stripped or unstripped Go binaries (ELF, PE, thin Mach-O, and architecture-selected universal Mach-O slices), callers need individual static Go string literals at their exact byte boundaries rather than NUL-delimited runs across packed
.rodatablobs.Expected behavior:
inspect_go_binary/inspect-go-binarycalls ({ path }) remain unchanged in schema output andevidence_id.include_string_literals: true(--include-string-literals, optionalmax_string_literals/--max-string-literalsin1..10000, default2000) scans non-executable initialized data and read-only sections in normalized ascending file-offset order (merging overlapping same-phase spans so each physical header is visited at most once) for word-aligned 2-word(ptr, len)pairs (uint32on 32-bit targets,uint64on 64-bit targets, honoring container endianness) targeting file-backed read-only spans.1 <= len <= 4096, stay strictly within a single read-only mapped section/span without crossing section boundaries or zero-fill tails, and decode as printable UTF-8 text (\t,\n,\r, joinersU+200CZWNJ /U+200DZWJ, and printable Unicode scalar values; rejecting NUL/control\p{Cc}, other format\p{Cf}, surrogate\p{Cs}, private-use\p{Co}, and unassigned/noncharacter\p{Cn}code points).(offset, bytes)target slices are deduplicated withreference_countand earliestfirst_header_offset, sorted deterministically by(offset, bytes), and bounded bymax_string_literals,512 KiBaggregate UTF-8 bytes,64 MiBheader scan budget,100,000accepted candidates, and a4,096-entry bounded negative slice cache, settingtruncated: truerather than failing when capped.string_literalscarriesevidence_kind: "inferred"and explicitlimitationsnoting that static(ptr, len)recovery excludes compiler-inlined stack/immediate strings and does not establish runtime reachability.Change and scope
Follow the contribution scope.
src/native/metadata/): Exposes parsed ELFsh_flags(bigint) and Mach-O sectionflags(number) onImageSectionalongside existing PEcharacteristicssoGoStringLiteralsclassifies executable vs read-only vs writable data sections directly from container metadata (with sectionless and unreadable-.shstrtabELFPT_LOADfallbacks).src/domain/go/goBinary.ts,src/go/GoStringLiterals.ts,src/go/GoBinaryImage.ts,src/go/GoBinaryProvider.ts): Adds opt-in input controls (include_string_literals,max_string_literalsrequiringinclude_string_literals: true),goStringLiteralsSchema(including universal Mach-Oselected_slicerange invariants for bothlocationandfirst_header_offset), normalized non-overlapping file-ordered header-span traversal, bounded word-aligned(ptr, len)recovery on bothbuild_info !== nullandbuild_info === nullGo/native images, universal slice file-offset rebasing, and epistemic/truncation/chained-fixup limitations.src/domain/analysisView/goBinaryView.ts): Extendsgosummary views withsource_coverage.string_literals("not-requested" | "complete" | "truncated") andsummary.string_literals, and addscollection: "string_literals"supportingvalues,contains,indices,fields,offset, andlimit(refusing uncollected queries wheninclude_string_literalswas not requested on the parent call).src/cli/goCommands.ts,src/contracts/go/goToolContracts.ts,docs/guides/native/go-binaries.md,docs/specs/native/go-string-literals/,.agents/skills/reverse-engineer-anything/,scripts/verify-go-binary.mjs): Wires--include-string-literalsand--max-string-literals(cliDecimalField), updates owning documentation, feature specification/plan/tasks, and skill references, and extendsverify:go:binary(artifactMcpCall) to verify advertised MCP output schemas and contiguous non-NUL-terminated string literal recovery across real compiler-produced ELF, PE, and Mach-O targets.gopclntab/typelink).inspect_go_binarywithout target execution, process attachment, instrumentation, or network access.Contract and boundary impact
src/native/metadata/ElfImage.tsandsrc/native/metadata/MachoImage.tsretain section flags onImageSection;src/go/GoStringLiterals.tsproduces bounded inferredGoStringLiteralsinsidereadGoBinaryImage(src/go/GoBinaryImage.ts), consumed byGoBinaryProvider,goBinaryView, CLIinspect-go-binary, and MCPinspect_go_binary.inspect_go_binaryboundary).include_string_literals?: booleanandmax_string_literals?: number(1..10000, valid only wheninclude_string_literals: true) oninspect_go_binary/inspect-go-binary(--include-string-literals,--max-string-literals); additivecollection: "string_literals"oninspect_analysis_view(kind: "go").PT_LOAD), PE (PE32/PE32+), and Mach-O (32/64-bit thin and universal slice-selected); warns explicitly when Mach-OLC_DYLD_CHAINED_FIXUPS/LC_DYLD_CHAINED_FIXUPS_FILESETis present.Evidence.confidenceremains"observed"for container andruntime/debugbuild-info spans whilenormalized_result.string_literals.evidence_kindexplicitly marks(ptr, len)string candidates as"inferred", preserving exact filelocation({ offset, bytes }) and minimalfirst_header_offsetprovenance pluslimitationsand viewunknowns.pathonly; read-only file access; periodiccheckActivecancellation checks during header scanning.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): Authored skill instructions updated in.agents/skills/reverse-engineer-anything/SKILL.mdand.agents/skills/reverse-engineer-anything/references/native-and-artifacts.md;npm run metadata:check,npm run mcp-catalog:check, andnpm run docs:checkpass with no committed build outputs.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/go/GoStringLiterals.test.tsandtests/fixtures/go/rodataStringImage.ts: Synthetic ELF (32/64, little/big-endian, sectionless, corrupted.shstrtab, reversed section-table order + overlapping writablePT_LOAD), PE (PE32/PE32+), and Mach-O (32/64-bit,LC_DYLD_CHAINED_FIXUPS) binaries with contiguous non-NUL-terminated.rodata/.rdata/__rodatastrings ("ListResourceProviders","genai","https://example.invalid/v1"), verifying exact slice recovery,U+200C(ZWNJ) andU+200D(ZWJ) preservation, deduplicated single-visitreference_countand minimalfirst_header_offset, rejection of cross-sectionptr + len, BSS/unbacked tails, executable.texttargets, NUL/control/other format (\p{Cf}:U+200B,U+202E,U+FEFF,U+00AD)/non-UTF-8 bytes, unaligned pairs, bounded negative-cache behavior across thousands of distinct NUL slices, count and512 KiBaggregate byte caps (truncated: true), and cancellation.src/domain/analysisView/goBinaryView.test.tsandtests/boundary/mcp/goBinaryViews.test.ts: Domain and MCP boundary coverage forsource_coverage.string_literals,summary.string_literals,collection: "string_literals"filtering/paging (values,contains,indices,fields), truncation unknowns, and refusal whenstring_literalswas not requested on the parent Evidence.src/application/go/GoBinaryService.test.ts,tests/boundary/go/goBinaryProvider.test.ts,tests/boundary/cli/cliIntegerArguments.test.ts,tests/acceptance/goBinaryCli.test.ts: Service option forwarding, universal Mach-O slice file-offset adjustment and schema invariants, CLI--max-string-literalsinteger/coupling validation, and end-to-end CLI--include-string-literalsoutput.scripts/verify-go-binary.mjs: Real Go compiler conformance across 15 stripped/unstripped/PIE/sectionless binaries (linux/amd64,linux/386,linux/arm64,linux/ppc64,linux/mips,windows/amd64,windows/386,darwin/amd64,darwin/arm64), verifying CLI/MCP parity and exact file-slice recovery of"ListResourceProviders","genai", and"https://example.invalid/v1".(ptr, len)header recovery, contiguous Go.rodataliterals lack NUL separators and coalesce into a single run under C-string scanning.{ "string_literals": { "evidence_kind": "inferred", "discovered_count": 3, "aggregate_bytes": 52, "max_items": 2000, "truncated": false, "items": [ { "value": "ListResourceProviders", "location": { "offset": 4096, "bytes": 21 }, "first_header_offset": 8192, "reference_count": 2 }, { "value": "genai", "location": { "offset": 4117, "bytes": 5 }, "first_header_offset": 8208, "reference_count": 1 }, { "value": "https://example.invalid/v1", "location": { "offset": 4122, "bytes": 26 }, "first_header_offset": 8224, "reference_count": 1 } ] } }(ptr, len)header scanning intentionally does not decode Mach-OLC_DYLD_CHAINED_FIXUPSencoded pointer slots or compiler-inlined stack/instruction-immediate strings; both limitations are surfaced explicitly inEvidence.limitations.For evidence-bearing changes:
Validation performed
npx vitest run src/go/GoStringLiterals.test.ts src/go/GoBinaryImage.mapping.test.ts src/go/GoMachoImage.alignment.test.ts src/domain/analysisView/goBinaryView.test.ts src/domain/absoluteAnalysisInputPaths.test.ts src/application/go/GoBinaryService.test.ts tests/boundary/go/goBinaryProvider.test.ts tests/boundary/rust/rustBinaryImage.test.ts tests/boundary/mcp/goBinaryViews.test.ts tests/boundary/mcp/goBinaryMcp.test.ts tests/boundary/mcp/lateAbortApplicationEvidenceMcp.test.ts tests/boundary/cli/cliIntegerArguments.test.ts tests/acceptance/goBinaryCli.test.ts— passed (13 passed,272 passed)npm run check:fast— passed (typecheckandlint/ module boundaries passed with 0 errors)npx oxfmt . && npx oxfmt --check .— passed (All matched files use the correct formatacross 7121 files)npm run verify:architecture-guards && npm run verify:test-discovery && npm run scan:todos && npm run jscpd && npm run knip && npm run knip:production && npm run lint:typed && npm run metadata:check— passed (2520 source files guard-clean, 3158 test files discovered once, 0 tech-debt markers, Knip 0 issues, typed lint 0 errors, metadata check clean)npm run mcp-catalog:check && npm run docs:check— passed (mcp-catalog:check:built,docs:check:built,licenses:check, andtests/conformance/readmeConsistency.test.ts9 passed)REA_VERIFY_GO_COMMAND=/path/to/go1.24.0/bin/go npm run verify:go:binary— passed (status: "passed",go1.24.0 darwin/arm64, 15 cross-compiled ELF/PE/Mach-O binaries,30/30public CLI +artifactMcpCallcases verified for both defaultbuild_infoand--include-string-literals/include_string_literals: true)main(08637b0c2) + multi-Node matrix (v22.23.4,v24.22.2,v26.13.0): clean merge (0conflicts),npm run check:fastpassed, and all7changed test files (221/221tests, including the 25,000-section Mach-O case in111-136 ms) passed across Nodev22.23.4,v24.22.2, andv26.13.0.darwin/arm64Mach-O Go1.24.0binaries (CGO_ENABLED=0unstripped,-ldflags="-s -w"stripped, andCGO_ENABLED=1 -ldflags="-linkmode=external"): verified identical defaultevidence_idvsmain(08637b0c2) on all 3 binaries,1,139recovered literals (25,086bytes, preservingU+200C/U+200Dand rejectingU+202E) on both unstripped and-s -wstrippedLC_DYLD_INFO_ONLYMach-O builds, CLI/MCP--detail summaryparity (full and--max-string-literals 50), and0false positives with explicitLC_DYLD_CHAINED_FIXUPSlimitation reporting on external Appleldbuilds.Compatibility, safety, and release
inspect_go_binary/inspect-go-binarycalls omitstring_literalsand preserve existingGoBinarypayloads andevidence_iddigests.darwin/arm64) across Nodev22.23.4,v24.22.2, andv26.13.0with realgo1.24.0cross-compilation (linux/{amd64,386,arm64,ppc64,mips},windows/{amd64,386},darwin/{amd64,arm64}) vianpm run verify:go:binaryplus unstripped,-s -wstripped, and-linkmode=externalMach-Oarm64CLI/MCP probes. Hopper/Ghidra/browser providers are not touched.inspect_go_binary/inspect-go-binaryandinspect_analysis_view(kind: "go"). No new runtime dependencies or package file-list changes.4096bytes), item count (max_string_literals <= 10000, default2000), aggregate UTF-8 output (512 KiB), accepted candidate (100,000), negative slice cache (4,096), and section-scan (64 MiB) budgets plus periodic cancellation checks; no target execution or external process spawning.Author readiness
Human owner: @saariuslystoned
Before merge
type(scope): outcome.