Skip to content

Instantly share code, notes, and snippets.

@jakeajames
Created March 29, 2019 21:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jakeajames/44bbac643a4351b0169528568fff92dd to your computer and use it in GitHub Desktop.
Save jakeajames/44bbac643a4351b0169528568fff92dd to your computer and use it in GitHub Desktop.
struct substitute_function_hook {
void *function;
void *replacement;
void *old_ptr;
int options;
};
extern void *MSGetImageByName(const char *filename) __asm__("_MSGetImageByName");;
void *SubGetImageByName(const char *filename) {
return MSGetImageByName(filename);
}
extern void *MSFindSymbol(void *image, const char *name) __asm__("_MSFindSymbol");
void *SubFindSymbol(void *image, const char *name) {
return MSFindSymbol(image, name);
}
extern void MSHookFunction(void *symbol, void *replace, void **result) __asm__("_MSHookFunction");
void SubHookFunction(void *symbol, void *replace, void **result) {
MSHookFunction(symbol, replace, result);
}
extern void MSHookMessageEx(Class _class, SEL sel, IMP imp, IMP *result) __asm__("_MSHookMessageEx");
void SubHookMessageEx(Class _class, SEL sel, IMP imp, IMP *result) {
MSHookMessageEx(_class, sel, imp, result);
}
int substitute_hook_functions(const struct substitute_function_hook *hooks, size_t nhooks, void **recordp, int options) {
for (int i = 0; i < nhooks; i++) {
MSHookFunction(hooks[i].function, (void*)hooks[i].replacement, (void*)hooks[i].old_ptr);
}
return 0;
}
int substitute_hook_objc_message(Class klass, SEL selector, void *replacement, void *old_ptr, bool *created_imp_ptr) {
MSHookMessageEx(klass, selector, replacement, old_ptr);
return 0;
}
@FranzGeringer
Copy link

Thigt

@Winston-Lin-9527
Copy link

lmao that easy? why didn't coolstar do it? :)

@pixelomer
Copy link

The whole point for using libsubstitute is to make it not work on unc0ver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment