Use pointer deref instead of memcpy
https://github.com/PAGalaxyLab/YAHFA/commit/0976d65
This commit is contained in:
parent
30fa70d43e
commit
27cb8f0efd
|
|
@ -1,5 +1,4 @@
|
||||||
#include "jni.h"
|
#include "jni.h"
|
||||||
#include <string.h>
|
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
@ -29,6 +28,10 @@ static inline void *readAddr(void *addr) {
|
||||||
return *((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) {
|
void Java_lab_galaxy_yahfa_HookMain_init(JNIEnv *env, jclass clazz, jint sdkVersion) {
|
||||||
SDKVersion = sdkVersion;
|
SDKVersion = sdkVersion;
|
||||||
jclass classExecutable;
|
jclass classExecutable;
|
||||||
|
|
@ -142,18 +145,17 @@ static int replaceMethod(void *fromMethod, void *toMethod, int isBackup) {
|
||||||
newEntrypoint
|
newEntrypoint
|
||||||
);
|
);
|
||||||
if (newEntrypoint) {
|
if (newEntrypoint) {
|
||||||
memcpy((char *) fromMethod + OFFSET_entry_point_from_quick_compiled_code_in_ArtMethod,
|
writeAddr((char *) fromMethod + OFFSET_entry_point_from_quick_compiled_code_in_ArtMethod,
|
||||||
&newEntrypoint,
|
newEntrypoint);
|
||||||
pointer_size);
|
|
||||||
} else {
|
} else {
|
||||||
LOGE("failed to allocate space for trampoline of target method");
|
LOGE("failed to allocate space for trampoline of target method");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OFFSET_entry_point_from_interpreter_in_ArtMethod != 0) {
|
if (OFFSET_entry_point_from_interpreter_in_ArtMethod != 0) {
|
||||||
memcpy((char *) fromMethod + OFFSET_entry_point_from_interpreter_in_ArtMethod,
|
void *interpEntrypoint = readAddr((char *) toMethod + OFFSET_entry_point_from_interpreter_in_ArtMethod);
|
||||||
(char *) toMethod + OFFSET_entry_point_from_interpreter_in_ArtMethod,
|
writeAddr((char *) fromMethod + OFFSET_entry_point_from_interpreter_in_ArtMethod,
|
||||||
pointer_size);
|
interpEntrypoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
hookCount += 1;
|
hookCount += 1;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue