android hook native函数

大概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 = ;
bRet = a/;
return bRet;
} extern "C"
JNIEXPORT int Java_aaa_aaa_MainActivity_test(jint a,jint b)
{
FILE *fp = fopen("1.txt", "rb");
if ( != fp)
{
printf("");
} return Aaaaaa(a, b);
} typedef FILE* (*pfnmyfopen)(const char *, const char *);
pfnmyfopen porg = ; //fake 函数
FILE *myfopen(const char * name, const char * flag)
{
FILE* fret = ;
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 = ;
jint result = -; if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK)
{
return -;
} initHook(); result = JNI_VERSION_1_4; return result;
}
上一篇:C# Func与Action


下一篇:SPSS Statistics 多个版本的下载安装激活步骤