android hook native函數,androidnative

來源:互聯網
上載者:User

android hook native函數,androidnative

大概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"JNIEXPORTint  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;}//這裡用的是substratevoid 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;}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.