Skip to content

Commit 4b7968b

Browse files
committed
added origin arg for tiny_interpose
1 parent d61de82 commit 4b7968b

3 files changed

Lines changed: 5 additions & 3 deletions

File tree

include/tinyhook.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ TH_VIS int tiny_unhook_ex(const th_bak_t *bak);
3030
TH_VIS int tiny_insert(void *address, void *destination);
3131

3232
/* interpose */
33-
TH_VIS int tiny_interpose(uint32_t image_index, const char *symbol_name, void *replacement);
33+
TH_VIS int tiny_interpose(uint32_t image_index, const char *symbol_name, void *replacement, void **origin);
3434

3535
/* objective-c runtime */
3636
TH_VIS int ocrt_hook(const char *cls, const char *sel, void *destination, void **origin);

src/interpose.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <mach/mach_error.h> // mach_error_string()
1111
#endif
1212

13-
int tiny_interpose(uint32_t image_index, const char *symbol_name, void *replacement) {
13+
int tiny_interpose(uint32_t image_index, const char *symbol_name, void *replacement, void **origin) {
1414
intptr_t image_slide = _dyld_get_image_vmaddr_slide(image_index);
1515
struct mach_header_64 *mh_header = (struct mach_header_64 *)_dyld_get_image_header(image_index);
1616
struct load_command *ld_command = (void *)mh_header + sizeof(struct mach_header_64);
@@ -84,6 +84,8 @@ int tiny_interpose(uint32_t image_index, const char *symbol_name, void *replacem
8484
break;
8585
}
8686
}
87+
if (origin != NULL)
88+
*origin = sym_ptrs[j];
8789
sym_ptrs[j] = replacement;
8890
break;
8991
}

test/hook/example.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ __attribute__((constructor(0))) int load() {
6464

6565
// or use interpose to hook it!
6666
fprintf(stderr, "=== Now interposing printf\n");
67-
tiny_interpose(0, "_printf", printf_interpose);
67+
tiny_interpose(0, "_printf", printf_interpose, NULL);
6868
return 0;
6969
}
7070

0 commit comments

Comments
 (0)