Skip to content

Commit f6b86c2

Browse files
committed
added LC_DYLD_EXPORTS_TRIE support for symexp_solve()
1 parent 0b6b6fb commit f6b86c2

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

src/symsolve/symexport.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ void *symexp_solve(uint32_t image_index, const char *symbol_name) {
6868
}
6969
struct dyld_info_command *dyldinfo_cmd = NULL;
7070
struct segment_command_64 *linkedit_cmd = NULL;
71+
struct linkedit_data_command *export_trie = NULL;
7172
for (int i = 0; i < mh_header->ncmds; i++) {
7273
if (ld_command->cmd == LC_SEGMENT_64) {
7374
const struct segment_command_64 *segment = (struct segment_command_64 *)ld_command;
@@ -77,24 +78,30 @@ void *symexp_solve(uint32_t image_index, const char *symbol_name) {
7778
}
7879
else if (ld_command->cmd == LC_DYLD_INFO_ONLY || ld_command->cmd == LC_DYLD_INFO) {
7980
dyldinfo_cmd = (struct dyld_info_command *)ld_command;
80-
if (linkedit_cmd != NULL) {
81-
break;
82-
}
81+
if (linkedit_cmd != NULL) break;
82+
}
83+
else if (ld_command->cmd == LC_DYLD_EXPORTS_TRIE) {
84+
export_trie = (struct linkedit_data_command *)ld_command;
85+
if (linkedit_cmd != NULL) break;
8386
}
8487
ld_command = (void *)ld_command + ld_command->cmdsize;
8588
}
86-
if (dyldinfo_cmd == NULL) {
87-
LOG_ERROR("symexp_solve: LC_DYLD_INFO_ONLY segment not found!");
88-
return NULL;
89-
}
9089
if (linkedit_cmd == NULL) {
9190
LOG_ERROR("symexp_solve: __LINKEDIT segment not found!");
9291
return NULL;
9392
}
9493
// stroff and strtbl are in the __LINKEDIT segment
9594
// Its offset will change when loaded into the memory, so we need to add this slide
9695
uint64_t linkedit_base = image_slide + linkedit_cmd->vmaddr - linkedit_cmd->fileoff;
97-
uint8_t *export_offset = (uint8_t *)linkedit_base + dyldinfo_cmd->export_off;
96+
uint8_t *export_offset;
97+
if (dyldinfo_cmd != NULL)
98+
export_offset = (uint8_t *)linkedit_base + dyldinfo_cmd->export_off;
99+
else if (export_trie != NULL)
100+
export_offset = (uint8_t *)linkedit_base + export_trie->dataoff;
101+
else {
102+
LOG_ERROR("symexp_solve: neither LC_DYLD_INFO_ONLY nor LC_DYLD_EXPORTS_TRIE load command found!");
103+
return NULL;
104+
}
98105
symbol_address = trie_query(export_offset, symbol_name);
99106

100107
if (symbol_address != NULL) {

src/tinyhook.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ bool need_far_jump(const void *src, const void *dst) {
6060
#endif
6161
}
6262

63-
static size_t calc_jump(uint8_t *output, void *src, void *dst, bool link) {
63+
static int calc_jump(uint8_t *output, void *src, void *dst, bool link) {
6464
if (need_far_jump(src, dst))
6565
return calc_far_jump(output, src, dst, link);
6666
else
6767
return calc_near_jump(output, src, dst, link);
6868
}
6969

70-
static int save_head(void *src, void *dst, size_t min_len, int *skip_lenp, int *head_lenp) {
70+
static int save_head(void *src, void *dst, int min_len, int *skip_lenp, int *head_lenp) {
7171
int skip_len = 0; // insns(to be overwritten) len from src
7272
int head_len = 0; // rewritten insns len to dst
7373
#ifdef __aarch64__

0 commit comments

Comments
 (0)