A tiny macOS inline hook framework
/*
hook `function` to `destination`, store the original pointer in `origin`
- `origin` can be NULL
*/
int tiny_hook(void *function, void *destination, void **origin);
/*
insert a jump code at `address`
- `link` == true -> bl / call
- `link` == false -> b / jmp
*/
int tiny_insert(void *address, void *destination, bool link);
/*
insert a further jump code at `address`
- `link` == true -> adrp+blr / call [rip]
- `link` == false -> adrp+br / jmp [rip]
*/
int tiny_insert_far(void *address, void *destination, bool link);
/* swap two objc methods */
int ocrt_swap(const char *cls1, const char *sel1, const char *cls2, const char *sel2);
/*
get implemention of an objc method
- available types are: CLASS_METHOD, INSTANCE_METHOD
*/
void *ocrt_impl(const char *cls, const char *sel, bool type);
/* get method struct from name */
Method ocrt_method(const char *cls, const char *sel, bool type);
int read_mem(void *destination, const void *source, size_t len);
int write_mem(void *destination, const void *source, size_t len);
void *sym_solve(uint32_t image_index, const char *symbol_name);
make test
Details are in test.
Thanks to these projects for their inspiring idea and code!