#include "substrate.h"
#include <dlfcn.h>
void resolveSymbol(const void *addr) {
Dl_info info;
if (dladdr(addr, &info)) {
NSLog(@"<hooksubstrate> Resolved symbol at address %p: dli_fname %s, dli_fbase %p, dli_sname %s, dli_saddr %p", addr, info.dli_fname, info.dli_fbase, info.dli_sname, info.dli_saddr);
}
else {
NSLog(@"<hooksubstrate> Can't resolve symbol at address %p", addr);
}
}
void (*oldMSHookFunction)(void *, void *, void **);
void newMSHookFunction(void *symbol, void *hook, void **old) {
NSLog(@"<hooksubstrate> MSHookFunction: symbol %p, new %p, old %p", symbol, hook, old);
resolveSymbol(symbol);
resolveSymbol(hook);
resolveSymbol(old);
oldMSHookFunction(symbol, hook, old);
}
void (*oldMSHookMessageEx)(Class, SEL, IMP, IMP *);
void newMSHookMessageEx(Class c/*lass*/, SEL s/*elector*/, IMP replacement, IMP *result) {
NSLog(@"<hooksubstrate> MSHookMessageEx: class %@, selector %@, new %p, old %p", NSStringFromClass(c/*lass*/), NSStringFromSelector(s/*elector*/), replacement, result);
resolveSymbol((const void *) *replacement);
resolveSymbol((const void *) result);
oldMSHookMessageEx(c/*lass*/, s/*elector*/, replacement, result);
}
__attribute__((constructor))
static void initialize() {
MSHookFunction(MSHookMessageEx, &newMSHookMessageEx, &oldMSHookMessageEx);
MSHookFunction(MSHookFunction, &newMSHookFunction, &oldMSHookFunction);
NSLog(@"<hooksubstrate> Hooked into MSHookFunction & MSHookMessageEx");
}
With sample output (for an old version)
> cat /dev/null > /var/log/syslog
> cat /var/log/syslog | grep "Loading"
Sep 12 17:06:54 iPad Clash of Clans[2372]: MS:Notice: Loading: /Library/MobileSubstrate/DynamicLibraries/HookSubstrate.dylib
Sep 12 17:06:54 iPad Clash of Clans[2372]: MS:Notice: Loading: /Library/MobileSubstrate/DynamicLibraries/xxCOCPlugin.dylib
> cat /var/log/syslog | grep "<cc>"
Sep 12 17:06:54 iPad Clash of Clans[2372]: <cc> Hooked into MSHookFunction & MSHookMessageEx
Sep 12 17:06:54 iPad Clash of Clans[2372]: <cc> MSHookFunction: old 0x845fd, new 0x3af4fd
Sep 12 17:06:54 iPad Clash of Clans[2372]: <cc> Resolved symbol at address 0x845fd: dli_fname /var/mobile/Applications/1A631C27-CE93-4845-B7FB-0637D600E10C/Clash of Clans.app/Clash of Clans, dli_fbase 0x4000, dli_sname (null), dli_saddr 0x0
Sep 12 17:06:54 iPad Clash of Clans[2372]: <cc> Resolved symbol at address 0x3af4fd: dli_fname /Library/MobileSubstrate/DynamicLibraries/xxCOCPlugin.dylib, dli_fbase 0x3a7000, dli_sname _Z20func_hook_new_searchi, dli_saddr 0x3af4fd
Sep 12 17:06:54 iPad Clash of Clans[2372]: <cc> MSHookMessageEx: class AppController, selector application:didFinishLaunchingWithOptions:, new 0x3afdb5
Sep 12 17:06:54 iPad Clash of Clans[2372]: <cc> Resolved symbol at address 0x3afdb5: dli_fname /Library/MobileSubstrate/DynamicLibraries/xxCOCPlugin.dylib, dli_fbase 0x3a7000, dli_sname _Z60hook_AppController_application_didFinishLaunchingWithOptionsP11objc_objectP13objc_selectorS0_S0_, dli_saddr 0x3afdb5
printf
doesn't print to syslog. Still don't know how to fix the first way.