Commit a7876d0
committed
feat: Enable sibling callee discovery and nested struct synthesis
This commit significantly expands the scope of structure reconstruction by improving how related functions are discovered and how complex data layouts are represented.
The primary change addresses a limitation in `CrossFunctionAnalyzer` where analysis starting from a callee would find the caller but fail to discover *other* callees of that same caller ("siblings").
Key changes by component:
docs/CROSS_FUNCTION_SIBLING_DISCOVERY.md (added):
- Added documentation explaining the sibling discovery logic and its impact on struct reconstruction coverage.
include/structor/cross_function_analyzer.hpp, src/cross_function_analyzer.cpp:
- Updated `trace_backward` to trigger `trace_forward` from discovered callers, ensuring sibling callees are analyzed.
- Added `CalleeCallInfo` and `CallerCallInfo` structs to carry rich metadata (delta, by-ref status, function pointer types) instead of simple tuples.
- Implemented `resolve_indirect_callees` to trace flow through function pointers when `include_indirect_calls` is enabled.
- Added `by_ref` tracking to correctly handle pointer indirection levels when variables are passed by reference.
include/structor/layout_synthesizer.hpp:
- Added `detect_subobjects` to identify clusters of fields that should be extracted into nested structures.
- Added `apply_bitfield_recovery` to convert bitwise access patterns into formal bitfield members.
- Added `emit_substructs` configuration option.
include/structor/structure_persistence.hpp:
- Added `find_reuse_candidate` to search the IDB for existing structures that match the synthesized layout (based on field offsets and semantics) to prevent duplicate type creation.
- Implemented `create_struct_with_substructs` to handle the recursive creation of nested types.
- Added logic to persist bitfield members to IDA.
include/structor/access_collector.hpp:
- Updated `AccessPatternVisitor` to detect bitwise AND/SHIFT operations for bitfield inference.
- Added `stride_hint` extraction from array indexing to aid the Z3 solver in detecting array patterns.
include/structor/z3/array_constraints.cpp:
- Updated array detection to utilize `stride_hint` from the access collector, improving accuracy for arrays of structures.
Impact:
- Struct reconstruction is now much more complete; analyzing a leaf function will now pull in data from all functions that share the same structure instance via a common caller.
- Generated structures are more semantic: bitfields are correctly typed, and distinct field groups are extracted into nested sub-structures.
- Reduced IDB clutter: The plugin now attempts to reuse existing compatible structs rather than always creating new ones.1 parent f9c91f1 commit a7876d0
File tree
17 files changed
+1695
-131
lines changed- docs
- include/structor
- z3
- src
- z3
17 files changed
+1695
-131
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
701 | 701 | | |
702 | 702 | | |
703 | 703 | | |
704 | | - | |
705 | | - | |
706 | | - | |
| 704 | + | |
| 705 | + | |
707 | 706 | | |
708 | 707 | | |
709 | 708 | | |
| |||
716 | 715 | | |
717 | 716 | | |
718 | 717 | | |
719 | | - | |
| 718 | + | |
| 719 | + | |
720 | 720 | | |
721 | 721 | | |
722 | 722 | | |
| |||
0 commit comments