Commit 1842108
committed
feat: Enable sibling discovery and offset handling in cross-function analysis
This commit significantly enhances the robustness of structure reconstruction by improving how the analyzer traverses the call graph, specifically handling pointer arithmetic and identifying related "sibling" functions.
- include/structor/cross_function_analyzer.hpp, src/cross_function_analyzer.cpp:
- Implemented sibling discovery: when tracing backward to a caller, the analyzer now also traces forward to find other callees receiving the same variable. This ensures that analyzing `init_obj(ptr)` also discovers `process_obj(ptr)` via their common caller.
- Updated `CallerFinder` to extract pointer offsets (deltas) from call arguments (e.g., `func((char*)ptr + 0x10)`).
- Modified `trace_backward` to normalize field access offsets based on these deltas, allowing correct reconstruction of substructures.
- include/structor/type_propagator.hpp:
- Added forward propagation logic to ensure synthesized types are applied to sibling functions.
- Enhanced `find_base_var` to robustly identify base variables through complex expressions (casts, refs, pointer arithmetic).
- src/z3/layout_constraints.cpp, src/z3/field_candidates.cpp:
- Added `add_type_preference_constraints` to favor typed fields over raw bytes when overlapping candidates exist.
- Implemented `fill_gaps_with_padding` to insert explicit padding fields in the final structure.
- Added comprehensive logging to the Z3 constraint building and solving phases for better debugging.
- include/structor/access_collector.hpp:
- Added `is_zero_initialization` to detect and flag writes that set fields to zero/NULL.
- integration_tests/:
- Added comprehensive test suite (Python scripts and C source) verifying propagation across linked-list operations and substructure passing.
Impact:
Users will see more complete structure definitions when analyzing code where pointers are passed between multiple functions. The tool can now correctly infer full structures even when functions only access specific substructures (offsets), and types are propagated more reliably across the entire usage graph.1 parent fa17365 commit 1842108
File tree
42 files changed
+3346
-224
lines changed- .github/workflows
- include/structor
- z3
- integration_tests
- src
- z3
- test
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
42 files changed
+3346
-224
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| 24 | + | |
| 25 | + | |
23 | 26 | | |
24 | 27 | | |
25 | 28 | | |
| 29 | + | |
| 30 | + | |
26 | 31 | | |
27 | 32 | | |
| 33 | + | |
| 34 | + | |
28 | 35 | | |
29 | 36 | | |
30 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
31 | 60 | | |
32 | 61 | | |
33 | | - | |
| 62 | + | |
34 | 63 | | |
35 | 64 | | |
36 | 65 | | |
37 | 66 | | |
38 | 67 | | |
39 | 68 | | |
40 | 69 | | |
41 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
42 | 79 | | |
43 | 80 | | |
44 | 81 | | |
| 82 | + | |
45 | 83 | | |
46 | 84 | | |
47 | 85 | | |
| |||
56 | 94 | | |
57 | 95 | | |
58 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
59 | 166 | | |
60 | 167 | | |
61 | 168 | | |
| |||
64 | 171 | | |
65 | 172 | | |
66 | 173 | | |
67 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
68 | 178 | | |
69 | 179 | | |
70 | 180 | | |
| |||
73 | 183 | | |
74 | 184 | | |
75 | 185 | | |
76 | | - | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
77 | 190 | | |
78 | 191 | | |
79 | 192 | | |
| 193 | + | |
80 | 194 | | |
81 | 195 | | |
82 | 196 | | |
83 | | - | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
84 | 202 | | |
85 | 203 | | |
86 | 204 | | |
| |||
99 | 217 | | |
100 | 218 | | |
101 | 219 | | |
102 | | - | |
| 220 | + | |
103 | 221 | | |
104 | 222 | | |
105 | | - | |
| 223 | + | |
106 | 224 | | |
107 | 225 | | |
108 | 226 | | |
| |||
121 | 239 | | |
122 | 240 | | |
123 | 241 | | |
124 | | - | |
| 242 | + | |
125 | 243 | | |
126 | 244 | | |
127 | 245 | | |
| |||
131 | 249 | | |
132 | 250 | | |
133 | 251 | | |
134 | | - | |
135 | | - | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
136 | 262 | | |
137 | 263 | | |
138 | | - | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
139 | 267 | | |
140 | 268 | | |
141 | 269 | | |
142 | 270 | | |
143 | 271 | | |
144 | 272 | | |
145 | | - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
146 | 276 | | |
147 | 277 | | |
148 | 278 | | |
149 | 279 | | |
150 | | - | |
| 280 | + | |
151 | 281 | | |
152 | 282 | | |
153 | 283 | | |
| |||
167 | 297 | | |
168 | 298 | | |
169 | 299 | | |
| 300 | + | |
170 | 301 | | |
171 | 302 | | |
172 | 303 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| 97 | + | |
| 98 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
18 | 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 | + | |
19 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
20 | 69 | | |
21 | 70 | | |
22 | 71 | | |
| |||
38 | 87 | | |
39 | 88 | | |
40 | 89 | | |
41 | | - | |
42 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
43 | 94 | | |
44 | 95 | | |
45 | 96 | | |
| |||
240 | 291 | | |
241 | 292 | | |
242 | 293 | | |
243 | | - | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
244 | 297 | | |
245 | 298 | | |
246 | 299 | | |
| |||
254 | 307 | | |
255 | 308 | | |
256 | 309 | | |
257 | | - | |
| 310 | + | |
258 | 311 | | |
259 | 312 | | |
260 | 313 | | |
| |||
0 commit comments