Skip to content

Instantly share code, notes, and snippets.

@NSExceptional
Last active March 12, 2018 21:17
Show Gist options
  • Save NSExceptional/f0ee69846eca8617609afc590aba58b0 to your computer and use it in GitHub Desktop.
Save NSExceptional/f0ee69846eca8617609afc590aba58b0 to your computer and use it in GitHub Desktop.
Demonstrates how to hook methods with MSHookFunction.
// Typical tweak
%hook UIView
- (UIColor *)backgroundColor {
return [UIColor blackColor];
}
%end
// Hook using MSHookFunction
// return type method name arguments ...
MSHook(UIColor *, backgroundColor, id self, SEL _cmd) {
return [UIColor blackColor];
}
%ctor {
void *backgroundColorImp = (void *)class_getMethodImplementation([UIView class], @selector(backgroundColor));
MSHookFunction(backgroundColorImp, MSHake(backgroundColorImp));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment