@@ -177,7 +177,8 @@ intptr_t read_sleb128(const uint8_t **pp, const uint8_t *end) {
177
177
178
178
// dyld
179
179
// bool MachOLoaded::findExportedSymbol
180
- uint8_t *walk_exported_trie (const uint8_t *start, const uint8_t *end, const char *symbol) {
180
+ // MachOLoaded::trieWalk
181
+ uint8_t *tail_walk (const uint8_t *start, const uint8_t *end, const char *symbol) {
181
182
uint32_t visitedNodeOffsets[128 ];
182
183
int visitedNodeOffsetCount = 0 ;
183
184
visitedNodeOffsets[visitedNodeOffsetCount++] = 0 ;
@@ -191,9 +192,6 @@ uint8_t *walk_exported_trie(const uint8_t *start, const uint8_t *end, const char
191
192
}
192
193
if ((*symbol == ' \0 ' ) && (terminalSize != 0 )) {
193
194
return (uint8_t *)p;
194
- // skip flag == EXPORT_SYMBOL_FLAGS_REEXPORT
195
- read_uleb128 (&p, end);
196
- return (uint8_t *)read_uleb128 (&p, end);
197
195
}
198
196
const uint8_t *children = p + terminalSize;
199
197
if (children > end) {
@@ -203,6 +201,7 @@ uint8_t *walk_exported_trie(const uint8_t *start, const uint8_t *end, const char
203
201
uint8_t childrenRemaining = *children++;
204
202
p = children;
205
203
uint64_t nodeOffset = 0 ;
204
+
206
205
for (; childrenRemaining > 0 ; --childrenRemaining) {
207
206
const char *ss = symbol;
208
207
bool wrongEdge = false ;
@@ -227,7 +226,7 @@ uint8_t *walk_exported_trie(const uint8_t *start, const uint8_t *end, const char
227
226
++p; // skip over last byte of uleb128
228
227
if (p > end) {
229
228
// diag.error("malformed trie node, child node extends past end of trie\n");
230
- return NULL ;
229
+ return nullptr ;
231
230
}
232
231
} else {
233
232
// the symbol so far matches this edge (child)
@@ -236,12 +235,13 @@ uint8_t *walk_exported_trie(const uint8_t *start, const uint8_t *end, const char
236
235
nodeOffset = read_uleb128 (&p, end);
237
236
if ((nodeOffset == 0 ) || (&start[nodeOffset] > end)) {
238
237
// diag.error("malformed trie child, nodeOffset=0x%llX out of range\n", nodeOffset);
239
- return NULL ;
238
+ return nullptr ;
240
239
}
241
240
symbol = ss;
242
241
break ;
243
242
}
244
243
}
244
+
245
245
if (nodeOffset != 0 ) {
246
246
if (nodeOffset > (uint64_t )(end - start)) {
247
247
// diag.error("malformed trie child, nodeOffset=0x%llX out of range\n", nodeOffset);
@@ -254,10 +254,6 @@ uint8_t *walk_exported_trie(const uint8_t *start, const uint8_t *end, const char
254
254
}
255
255
}
256
256
visitedNodeOffsets[visitedNodeOffsetCount++] = (uint32_t )nodeOffset;
257
- if (visitedNodeOffsetCount >= 128 ) {
258
- // diag.error("malformed trie too deep\n");
259
- return NULL ;
260
- }
261
257
p = &start[nodeOffset];
262
258
} else
263
259
p = end;
@@ -284,16 +280,24 @@ uintptr_t macho_ctx_iterate_exported_symbol(macho_ctx_t *ctx, const char *symbol
284
280
285
281
uint8_t *exports_start = (uint8_t *)exports;
286
282
uint8_t *exports_end = exports_start + trieFileSize;
287
- uint8_t *node = (uint8_t *)walk_exported_trie (exports_start, exports_end, symbol_name);
283
+ uint8_t *node = (uint8_t *)tail_walk (exports_start, exports_end, symbol_name);
288
284
if (node == NULL )
289
285
return 0 ;
290
286
const uint8_t *p = node;
291
287
const uintptr_t flags = read_uleb128 (&p, exports_end);
292
- if (flags & EXPORT_SYMBOL_FLAGS_REEXPORT) {
293
- return 0 ;
294
- }
295
288
if (out_flags)
296
289
*out_flags = flags;
290
+ if (flags & EXPORT_SYMBOL_FLAGS_REEXPORT) {
291
+ const uint64_t ordinal = read_uleb128 (&p, exports_end);
292
+ const char *importedName = (const char *)p;
293
+ if (importedName[0 ] == ' \0 ' ) {
294
+ importedName = symbol_name;
295
+ return 0 ;
296
+ }
297
+ // trick
298
+ printf (" reexported symbol: %s\n " , importedName);
299
+ return (uintptr_t )importedName;
300
+ }
297
301
uint64_t trieValue = read_uleb128 (&p, exports_end);
298
302
return trieValue;
299
303
#if 0
0 commit comments