Skip to content

Instantly share code, notes, and snippets.

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

Embed
What would you like to do?
MobileSubstrate hook c++ function
/*
获取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
You can’t perform that action at this time.