Repository navigation
perf(viv): optimize elf symbol resolution - #3182
tryhard-26 wants to merge 1 commit into
Conversation
b974f17 to
0232db1
Compare
| STT_FUNC = 0x2 | ||
| if sym_value == fh.address and sym_info & STT_FUNC != 0: | ||
| yield FunctionName(sym_name), fh.address | ||
| funcs = get_elf_symbol_functions(fh.ctx["cache"], fh.inner.vw.parsedbin) |
There was a problem hiding this comment.
i'd prefer to split fetching the items from setting the cache, otherwise looks good!
0232db1 to
8e88e01
Compare
|
btw @williballenthin heads up, this will trip the |
|
good point, thanks for calling that out. would you please open that PR @tryhard-26? |
8e88e01 to
122f201
Compare
mandiant/capa#3182 checks elf symbol types with (st_info & 0xf) in (STT_FUNC, STT_GNU_IFUNC) instead of st_info & 0x2, which wrongly let unnamed STT_SECTION (type 3) symbols through. this drops 5 empty-name false positives from the snapshot: api("") at 0x4088e0 and function-name("") at 0x4016d8, 0x4016f0, 0x401c50 and 0x408988. no other features change.
122f201 to
5fd2901
Compare
|
hey @williballenthin any updates? |
in vivisect elf feature extraction (
viv/function.pyandviv/insn.py), symbol types were checked usingsym_info & 0x2 != 0in a linear loop over all symbols on every call instruction and function. because elf encodes symbol types in the lower 4 bits ofst_infoas an enum not a bitmask, testing bit 1 falsely treated section headers (0x3) and thread-local storage variables (0x6) as callable functions and apis, since both have bit 1 set. repeatedly re-scanning the entire symbol table and callingget_name()on every instruction also created a quadratic bottleneck, causing over 2.3 million redundant string decodings across small test binaries.this pr adds
get_elf_symbol_functionsinviv.helpersto validate symbol types using(symbol.info & 0xf) in (2, 10)and pre-indexes callable symbols by address into the workspace cache. this converts instruction and function symbol lookups into o(1) dictionary lookups, safely skips malformed symbol names instead of crashing, and stops non-function symbols from leaking into extracted features.benchmarked against 5 elf fixtures already in
tests/data:call counts and false positive counts above are deterministic, timings are single-run on my machine [macbook air m4 16gigs] and will vary by environment.
all tests pass, new unit tests covering symbol type filtering, corrupt symbol recovery, and caching have been added
ruff check,ruff format, anddeptryall pass cleanly.no linked gh issue as such
used gemini a bit to help debug the type masking logic
idk whether changelog update is needed or not
checklist