From cf847c2c93253d01052b24f22da6a637fc65498b Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Tue, 20 Aug 2019 08:45:41 -0700 Subject: [PATCH] If hooking in __DATA_CONST, make writable before trying to write iOS 13 seems to have thrown us off. Apparently, __DATA_CONST is set read-only after dyld runs. --- fishhook.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fishhook.c b/fishhook.c index a4df70b..a048442 100644 --- a/fishhook.c +++ b/fishhook.c @@ -24,8 +24,10 @@ #include "fishhook.h" #include +#include #include #include +#include #include #include #include @@ -82,8 +84,12 @@ static void perform_rebinding_with_section(struct rebindings_entry *rebindings, nlist_t *symtab, char *strtab, uint32_t *indirect_symtab) { + const bool isDataConst = strcmp(section->segname, "__DATA_CONST") == 0; uint32_t *indirect_symbol_indices = indirect_symtab + section->reserved1; void **indirect_symbol_bindings = (void **)((uintptr_t)slide + section->addr); + if (isDataConst) { + mprotect(indirect_symbol_bindings, section->size, PROT_READ | PROT_WRITE); + } for (uint i = 0; i < section->size / sizeof(void *); i++) { uint32_t symtab_index = indirect_symbol_indices[i]; if (symtab_index == INDIRECT_SYMBOL_ABS || symtab_index == INDIRECT_SYMBOL_LOCAL || @@ -110,6 +116,9 @@ static void perform_rebinding_with_section(struct rebindings_entry *rebindings, } symbol_loop:; } + if (isDataConst) { + mprotect(indirect_symbol_bindings, section->size, PROT_READ); + } } static void rebind_symbols_for_image(struct rebindings_entry *rebindings,