void Hook_EDog_i1() { JNIEnv* env = NULL; if(GVM == NULL) { DEXLOG("Hook_EDog_i1 GVM is NULL "); return ; } if($EDog_i1 != NULL)return ; if(GVM->GetEnv((void**)&env, JNI_VERSION_1_4) != JNI_OK){ DEXLOG("Hook_EDog_i1 GetEnv fail!"); return ; } jclass cls_protect = findAppClass(env,"com/edog/ELibrary"); if(cls_protect == NULL){ DEXLOG("Hook_EDog_i1 com/edog/ELibrary no find!"); return ; } jmethodID method_enc = env->GetMethodID(cls_protect,"i1","(Ljava/lang/String;)V"); if(NULL == method_enc) { DEXLOG("Hook_EDog_i1 or method_enc no find!"); return ; } MSJavaHookMethod(env,cls_protect,method_enc,(void*)&new$EDog_i1,(void**)&$EDog_i1); DEXLOG("Hook_EDog_i1 is oVER!"); return ; }
bool ClassMethodHook(HookInfo info){ JNIEnv *jenv = GetEnv(); jclass clazzTarget = jenv->FindClass(info.tClazz); if (ClearException(jenv)) { ALOG("Exception","ClassMethodHook[Can't find class:%s in bootclassloader",info.tClazz); clazzTarget = findAppClass(jenv,info.tClazz); if(clazzTarget == NULL){ ALOG("Exception","%s","Error in findAppClass"); return false; } } jmethodID method = jenv->GetMethodID(clazzTarget,info.tMethod,info.tMeihodSig); if(method==NULL){ ALOG("Exception","ClassMethodHook[Can't find method:%s",info.tMethod); return false; } /* if(isArt()){ HookArtMethod(jenv,method); }else{ HookDalvikMethod(method); } */ HookDalvikMethod(method); JNINativeMethod gMethod[] = { {info.tMethod, info.tMeihodSig, info.handleFunc}, }; //func为NULL时不自行绑定,后面扩展吧 if(info.handleFunc != NULL){ //关键!!将目标方法关联到自定义的native方法 if (jenv->RegisterNatives(clazzTarget, gMethod, 1) < 0) { ALOG("RegisterNatives","err"); return false; } } DetachCurrent(); return true; }