[AUTOMATED] fix(cli): zero-function-sizes-make — a sectionless ELF reports a real extent per function - #452
Merged
Merged
Conversation
…ports a real extent per function
Zero an ELF's three section-header fields and every function kuna finds
reports size 0, so `--min-size 1` discards the whole binary:
$ kuna functions ./noshdr --min-size 1 --json | jq '{count, total, error}'
{ "count": 0, "total": 11, "error": null }
`funcextent` clips each entry against the loader's CODE sections, and an
image with no section table publishes none, so every entry took the
"outside every CODE section" answer that exists for import pointer slots.
When the section table yields no CODE span at all the clip now runs
against the executable load segments instead, which the loader reports
through a new `LoadImage::get_segments` — separate from the section walk,
so which entries whole-binary decompilation selects is unchanged. The
fallback is whole-table, never per-entry: an entry that misses the CODE
spans an image does publish is a pointer slot, and choosing a segment for
it would hand a body to exactly those.
On the filed witness the summary goes from code_bytes 0 to 4821 and
`largest` ranks the VM interpreter first at 4101 bytes. Sweeping 135
fixture images and 29 system binaries, exactly two change — both
sectionless, both from 0 to a real extent.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
On a binary with no ELF section table, every function kuna finds reports a size
of
0, so size-based triage throws the whole binary away. Take any ELF and zeroits three section-header fields — nothing else changes, every mapped byte is
identical:
--min-size 1is documented triage, and it discards all eleven with no error todistinguish that from a binary that really holds nothing.
--summaryreportscode_bytes 0and alargestlist of zeroes, so the "which function is the bigone" question a stripped binary is opened with cannot be asked at all.
The fix
funcextentclips each entry against the loader's CODE sections; an imagewith no section table publishes none, so every entry took the "outside every
CODE section" answer that exists for import pointer slots. When the section
table yields no CODE span at all, the clip now runs against the executable
load segments instead — still an upper bound clipped at the next entry,
just a coarser container for the last entry of a segment.
PT_LOADs through a newLoadImage::get_segments,separate from the section walk. Teaching the loader to synthesize sections
from segments instead would have silently changed which entries
whole-binary decompilation selects.
spans an image does publish is a pointer slot or an undefined external, and
choosing a segment for it would hand a body to exactly those.
The tests
tests/cli/zero-function-sizes-make.jsonand a four-case console gate run onnoshdr_x86_64, a new 304-byte ELF64 PIE with no section table whose twofunctions report
0and0before the change and16and6after — theneighbour clip and the segment-end clip. Two loader unit tests cover the
permission-to-flag translation. Sweeping 135 fixture images and 29 system
binaries through
kuna functions --json, exactly two change, both sectionless,both from
0to a real extent;kuna functions /bin/bashstays at a 0.32 smedian.
🤖 Generated with Claude Code