Skip to content

Instantly share code, notes, and snippets.

@zwo zwo/hookcpp.m
Created Feb 9, 2019

What would you like to do?
MobileSubstrate hook c++ function
By 飘云/P.Y.G
#import <substrate.h>
#import <pthread.h>
// 原始函数
signed int (*orig_XxteaDecrypt)(const char *inBuf, size_t bufLen, const char *key, size_t a4, char *outBuf, int a6);
signed int myXxteaDecrypt(const char *inBuf, size_t bufLen, const char *key, size_t a4, char *outBuf, int a6)
signed int ret = orig_XxteaDecrypt(inBuf, bufLen, key, a4, outBuf, a6);
NSString *str = [NSString stringWithCString:outBuf encoding:NSUTF8StringEncoding];
//NSLog(@"[++++]%s", outBuf);
NSLog(@"[++++]%@", str);
return ret;
void *threadFun(void*)
while (true)
void *lpFun = ((void*)MSFindSymbol(NULL, "__Z12XxteaDecryptPKciS0_iPci"));
if (lpFun)
NSLog(@"[++++]lpFun = %p", lpFun);
MSHookFunction(lpFun, (void*)myXxteaDecrypt, (void**)&orig_XxteaDecrypt);
NSLog(@"[++++]orig_XxteaDecrypt = %p", orig_XxteaDecrypt);
return NULL;
static __attribute__((constructor)) void piaoyun()
// 用线程来查找,以免xx的dylib后加载而找不到函数
pthread_t th;
int err = pthread_create(&th, NULL, threadFun, NULL);
if (err != 0)
printf("[++++]pthread_create error: %s\n", strerror(err));
NSLog(@"[++++]inject success!!!!");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.