大概2年前寫的代碼,今天突然要用到,找了半天,這裡記錄下 用到的庫: https://pan.baidu.com/s/1htuUQX2 ...
大概2年前寫的代碼,今天突然要用到,找了半天,這裡記錄下
用到的庫: https://pan.baidu.com/s/1htuUQX2
#include <jni.h> #include <string> #include <dlfcn.h> typedef int (* pfnMSHookFunction)(void* result, void* a2, void** a3); int Aaaaaa(jint a, jint b) { int bRet = 0; bRet = a/3; return bRet; } extern "C" JNIEXPORT int Java_aaa_aaa_MainActivity_test(jint a,jint b) { FILE *fp = fopen("1.txt", "rb"); if (0 != fp) { printf("111"); } return Aaaaaa(a, b); } typedef FILE* (*pfnmyfopen)(const char *, const char *); pfnmyfopen porg = 0; //fake 函數 FILE *myfopen(const char * name, const char * flag) { FILE* fret = 0; fret = porg(name,flag); return fret; } //這裡用的是substrate void initHook() { void* phandle =dlopen("libhook.so",RTLD_NOW ); pfnMSHookFunction pmsHook=(pfnMSHookFunction)dlsym(phandle,"MSHookFunction"); pmsHook((void*)fopen,(void*)myfopen,(void**)&porg); } jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) { JNIEnv* env = 0; jint result = -1; if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { return -1; } initHook(); result = JNI_VERSION_1_4; return result; }