Created
February 9, 2019 15:13
-
-
Save zwo/4753ab7fbe0a743dd1e64240321ac51d to your computer and use it in GitHub Desktop.
MobileSubstrate hook c++ function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
获取xx助手lua脚本 | |
By 飘云/P.Y.G | |
2015-04-29 | |
https://www.chinapyg.com | |
*/ | |
#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); | |
break; | |
} | |
} | |
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