Skip to content

A tiny macOS hook framework, inlcuded inline hook, objc runtime hook, symbol resolver..

License

Notifications You must be signed in to change notification settings

Antibioticss/tinyhook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tinyhook

A tiny macOS inline hook framework

Functions

Inline hook

/*
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);

Objective-C runtime hook

/* 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);

Read and write memory

int read_mem(void *destination, const void *source, size_t len);

int write_mem(void *destination, const void *source, size_t len);

Get function address from name

void *sym_solve(uint32_t image_index, const char *symbol_name);

Examples

make test

Details are in test.

References

Thanks to these projects for their inspiring idea and code!