Commit 2209c181 authored by swift_gan's avatar swift_gan

Merge branch 'master' into support_k

parents ea2f1173 48916f5a
...@@ -58,53 +58,6 @@ void ensureMethodCached(art::mirror::ArtMethod *hookMethod, art::mirror::ArtMeth ...@@ -58,53 +58,6 @@ void ensureMethodCached(art::mirror::ArtMethod *hookMethod, art::mirror::ArtMeth
} }
} }
void ensureBackupMethod(art::mirror::ArtMethod *origin, art::mirror::ArtMethod *backup) {
if (origin->getDeclaringClassPtr() != backup->getDeclaringClassPtr()) {
LOGW("backup method is out to date due to Moving GC!");
SandHook::HookTrampoline* trampoline = trampolineManager.getHookTrampoline(origin);
if (trampoline == nullptr)
return;
SandHook::StopTheWorld stopTheWorld;
if (trampoline->inlineJump != nullptr) {
origin->backup(backup);
backup->setQuickCodeEntry(trampoline->callOrigin->getCode());
if (SDK_INT >= ANDROID_N) {
backup->disableCompilable();
}
if (SDK_INT >= ANDROID_O) {
backup->disableInterpreterForO();
}
if (!backup->isStatic()) {
backup->setPrivate();
}
backup->tryDisableInline();
} else if (trampoline->replacement != nullptr) {
origin->backup(backup);
if (trampoline->callOrigin != nullptr) {
backup->setQuickCodeEntry(trampoline->callOrigin->getCode());
} else {
backup->setQuickCodeEntry(trampoline->originCode);
}
if (SDK_INT >= ANDROID_N) {
backup->disableCompilable();
}
if (SDK_INT >= ANDROID_O) {
backup->disableInterpreterForO();
}
if (!backup->isStatic()) {
backup->setPrivate();
}
backup->tryDisableInline();
} else {
return;
}
backup->flushCache();
}
}
bool doHookWithReplacement(JNIEnv* env, bool doHookWithReplacement(JNIEnv* env,
art::mirror::ArtMethod *originMethod, art::mirror::ArtMethod *originMethod,
art::mirror::ArtMethod *hookMethod, art::mirror::ArtMethod *hookMethod,
...@@ -264,19 +217,6 @@ Java_com_swift_sandhook_SandHook_ensureMethodCached(JNIEnv *env, jclass type, jo ...@@ -264,19 +217,6 @@ Java_com_swift_sandhook_SandHook_ensureMethodCached(JNIEnv *env, jclass type, jo
ensureMethodCached(hookeMethod, backupMethod); ensureMethodCached(hookeMethod, backupMethod);
} }
extern "C"
JNIEXPORT void JNICALL
Java_com_swift_sandhook_SandHook_ensureBackupMethod(JNIEnv *env, jclass type,
jobject originMethod,
jobject backupMethod) {
if (backupMethod == NULL || originMethod == NULL)
return;
art::mirror::ArtMethod* origin = reinterpret_cast<art::mirror::ArtMethod *>(env->FromReflectedMethod(originMethod));
art::mirror::ArtMethod* backup = reinterpret_cast<art::mirror::ArtMethod *>(env->FromReflectedMethod(backupMethod));
ensureBackupMethod(origin, backup);
}
extern "C" extern "C"
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_com_swift_sandhook_SandHook_compileMethod(JNIEnv *env, jclass type, jobject member) { Java_com_swift_sandhook_SandHook_compileMethod(JNIEnv *env, jclass type, jobject member) {
......
...@@ -14,6 +14,8 @@ namespace SandHook { ...@@ -14,6 +14,8 @@ namespace SandHook {
uint32_t TrampolineManager::sizeOfEntryCode(mirror::ArtMethod *method) { uint32_t TrampolineManager::sizeOfEntryCode(mirror::ArtMethod *method) {
Code codeEntry = getEntryCode(method); Code codeEntry = getEntryCode(method);
if (codeEntry == nullptr || codeEntry <= 0)
return 0;
#if defined(__arm__) #if defined(__arm__)
if (isThumbCode(reinterpret_cast<Size>(codeEntry))) { if (isThumbCode(reinterpret_cast<Size>(codeEntry))) {
codeEntry = getThumbCodeAddress(codeEntry); codeEntry = getThumbCodeAddress(codeEntry);
......
...@@ -172,37 +172,9 @@ public class SandHook { ...@@ -172,37 +172,9 @@ public class SandHook {
} }
} }
public static Object ensureBackupAndCallOriginMethod(Member originMethod, Method backupMethod, Object thiz, Object[] args) throws Throwable {
backupMethod.setAccessible(true);
if (Modifier.isStatic(originMethod.getModifiers())) {
ensureBackupMethod(originMethod, backupMethod);
return backupMethod.invoke(null, args);
} else {
ensureBackupMethod(originMethod, backupMethod);
return backupMethod.invoke(thiz, args);
}
}
public static void ensureBackupMethod(Method backupMethod) { public static void ensureBackupMethod(Method backupMethod) {
if (backupMethod == null)
return;
HookWrapper.HookEntity hookEntity = globalBackupMap.get(backupMethod);
if (hookEntity == null)
return;
ensureBackupMethod(hookEntity.target, backupMethod);
} }
public static void ensureBackupMethodByOrigin(Member originMethod) {
if (originMethod == null)
return;
HookWrapper.HookEntity hookEntity = globalHookEntityMap.get(originMethod);
if (hookEntity == null || hookEntity.backup == null)
return;
ensureBackupMethod(originMethod, hookEntity.backup);
}
public static void resolveStaticMethod(Member method) { public static void resolveStaticMethod(Member method) {
//ignore result, just call to trigger resolve //ignore result, just call to trigger resolve
if (method == null) if (method == null)
...@@ -334,8 +306,6 @@ public class SandHook { ...@@ -334,8 +306,6 @@ public class SandHook {
public static native void ensureMethodCached(Method hook, Method backup); public static native void ensureMethodCached(Method hook, Method backup);
public static native void ensureBackupMethod(Member originMethod, Method backupMethod);
public static native boolean compileMethod(Member member); public static native boolean compileMethod(Member member);
public static native boolean canGetObject(); public static native boolean canGetObject();
......
...@@ -39,7 +39,11 @@ public class HookWrapper { ...@@ -39,7 +39,11 @@ public class HookWrapper {
if (targetHookClass == null) if (targetHookClass == null)
throw new HookErrorException("error hook wrapper class :" + clazz.getName()); throw new HookErrorException("error hook wrapper class :" + clazz.getName());
Map<Member,HookEntity> hookEntityMap = getHookMethods(classLoader, targetHookClass, clazz); Map<Member,HookEntity> hookEntityMap = getHookMethods(classLoader, targetHookClass, clazz);
fillBackupMethod(classLoader, clazz, hookEntityMap); try {
fillBackupMethod(classLoader, clazz, hookEntityMap);
} catch (Throwable throwable) {
throw new HookErrorException("fillBackupMethod error!", throwable);
}
for (HookEntity entity:hookEntityMap.values()) { for (HookEntity entity:hookEntityMap.values()) {
SandHook.hook(entity); SandHook.hook(entity);
} }
...@@ -82,8 +86,12 @@ public class HookWrapper { ...@@ -82,8 +86,12 @@ public class HookWrapper {
private static Map<Member, HookEntity> getHookMethods(ClassLoader classLoader, Class targetHookClass, Class<?> hookWrapperClass) throws HookErrorException { private static Map<Member, HookEntity> getHookMethods(ClassLoader classLoader, Class targetHookClass, Class<?> hookWrapperClass) throws HookErrorException {
Map<Member,HookEntity> hookEntityMap = new HashMap<>(); Map<Member,HookEntity> hookEntityMap = new HashMap<>();
Method[] methods = hookWrapperClass.getDeclaredMethods(); Method[] methods = null;
if (methods == null && methods.length == 0) try {
methods = hookWrapperClass.getDeclaredMethods();
} catch (Throwable throwable) {
}
if (methods == null || methods.length == 0)
throw new HookErrorException("error hook wrapper class :" + targetHookClass.getName()); throw new HookErrorException("error hook wrapper class :" + targetHookClass.getName());
for (Method method:methods) { for (Method method:methods) {
HookMethod hookMethodAnno = method.getAnnotation(HookMethod.class); HookMethod hookMethodAnno = method.getAnnotation(HookMethod.class);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment