Android hook native function, androidnative

Source: Internet
Author: User

Android hook native function, androidnative

The code I wrote about two years ago suddenly needs to be used today. I searched for it for half a day and recorded it here.

Library used: 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; // The fake function 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 "); pmsHoo K (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 ;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.