diff --git a/edxp-core/src/main/cpp/external/yahfa/src/HookMain.c b/edxp-core/src/main/cpp/external/yahfa/src/HookMain.c index a7d647e82..c5e852081 100644 --- a/edxp-core/src/main/cpp/external/yahfa/src/HookMain.c +++ b/edxp-core/src/main/cpp/external/yahfa/src/HookMain.c @@ -1,5 +1,4 @@ #include "jni.h" -#include #include #include #include @@ -29,6 +28,10 @@ static inline void *readAddr(void *addr) { return *((void **) addr); } +static inline void writeAddr(void *addr, void *value) { + *((void **)addr) = value; +} + void Java_lab_galaxy_yahfa_HookMain_init(JNIEnv *env, jclass clazz, jint sdkVersion) { SDKVersion = sdkVersion; jclass classExecutable; @@ -142,18 +145,17 @@ static int replaceMethod(void *fromMethod, void *toMethod, int isBackup) { newEntrypoint ); if (newEntrypoint) { - memcpy((char *) fromMethod + OFFSET_entry_point_from_quick_compiled_code_in_ArtMethod, - &newEntrypoint, - pointer_size); + writeAddr((char *) fromMethod + OFFSET_entry_point_from_quick_compiled_code_in_ArtMethod, + newEntrypoint); } else { LOGE("failed to allocate space for trampoline of target method"); return 1; } if (OFFSET_entry_point_from_interpreter_in_ArtMethod != 0) { - memcpy((char *) fromMethod + OFFSET_entry_point_from_interpreter_in_ArtMethod, - (char *) toMethod + OFFSET_entry_point_from_interpreter_in_ArtMethod, - pointer_size); + void *interpEntrypoint = readAddr((char *) toMethod + OFFSET_entry_point_from_interpreter_in_ArtMethod); + writeAddr((char *) fromMethod + OFFSET_entry_point_from_interpreter_in_ArtMethod, + interpEntrypoint); } hookCount += 1;