Skip to content

Instantly share code, notes, and snippets.

@rweichler
Last active September 27, 2017 23:53
Show Gist options
  • Select an option

  • Save rweichler/bac0cffe6757a553cfd190ca94ca6506 to your computer and use it in GitHub Desktop.

Select an option

Save rweichler/bac0cffe6757a553cfd190ca94ca6506 to your computer and use it in GitHub Desktop.
AW YISS
#import <Foundation/Foundation.h>
#import <substrate.h>
#import <objc/objc.h>
#import <objc/runtime.h>
#define Log(format, ...) NSLog(@"mobilevim: %@", [NSString stringWithFormat: format, ## __VA_ARGS__])
// CONVENIENCE SHIT
static void * ivar(id self, const char *name)
{
Ivar i = class_getInstanceVariable([self class], name);
return (uint8_t *)self + ivar_getOffset(i);
}
// HOOKS
// -[SpringBoard _revealSpotlight]
void (*orig_revealSpotlight)(id, SEL);
void hook_revealSpotlight(id self, SEL _cmd)
{
orig_revealSpotlight(self, _cmd);
Log(@"call stack:\n%@", [NSThread callStackSymbols]);
}
// -[BKHIDEvent _fillWithHIDEvent:descriptor:senderInfo:]
void (*orig_fillWithHIDEvent)(id, SEL, id, id, id);
void hook_fillWithHIDEvent(id self, SEL _cmd, id event, id descriptor, id arg3)
{
int type = *(int *)ivar(descriptor, "_hidEventType");
if(type == 3) { // keyboard
unsigned int usage = *(unsigned int *)ivar(descriptor, "_usage");
Log(@"KEYBOARD LOL: %u", usage);
}
orig_fillWithHIDEvent(self, _cmd, event, descriptor, arg3);
}
MSInitialize {
Log(@"hooking");
MSHookMessageEx(objc_getClass("SpringBoard"), @selector(_revealSpotlight), (IMP)&hook_revealSpotlight, (IMP *)&orig_revealSpotlight);
MSHookMessageEx(objc_getClass("BKHIDEvent"), @selector(_fillWithHIDEvent:descriptor:senderInfo:), (IMP)&hook_fillWithHIDEvent, (IMP *)&orig_fillWithHIDEvent);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment