Commit 3235b9da authored by swift_gan's avatar swift_gan

add compile method

parent 6637f8ed
......@@ -282,18 +282,29 @@ Java_com_swift_sandhook_SandHook_ensureMethodDeclaringClass(JNIEnv *env, jclass
}
extern "C"
JNIEXPORT void JNICALL
JNIEXPORT jboolean JNICALL
Java_com_swift_sandhook_SandHook_compileMethod(JNIEnv *env, jclass type, jobject member) {
if (member == NULL)
return;
return JNI_FALSE;
art::mirror::ArtMethod* method = reinterpret_cast<art::mirror::ArtMethod *>(env->FromReflectedMethod(member));
if (method != nullptr && !method->isCompiled()) {
if (method == nullptr)
return JNI_FALSE;
if (!method->isCompiled()) {
SandHook::StopTheWorld stopTheWorld;
if (!method->compile(env) && SDK_INT >= ANDROID_N) {
method->disableCompilable();
if (!method->compile(env)) {
if (SDK_INT >= ANDROID_N) {
method->disableCompilable();
method->flushCache();
}
return JNI_FALSE;
} else {
return JNI_TRUE;
}
} else {
return JNI_TRUE;
}
}
......
......@@ -304,7 +304,7 @@ public class SandHook {
public static native void ensureMethodDeclaringClass(Member originMethod, Method backupMethod);
public static native void compileMethod(Member member);
public static native boolean compileMethod(Member member);
public static native boolean canGetObject();
public static native Object getObjectNative(long thread, long address);
......
package com.swift.sandhook.xposedcompat.hookstub;
import com.swift.sandhook.SandHook;
import com.swift.sandhook.SandHookMethodResolver;
import com.swift.sandhook.utils.ParamWrapper;
import java.lang.reflect.Constructor;
......@@ -93,8 +94,11 @@ public class HookStubManager {
int id = getMethodId(stubMethodInfo.args, stubMethodInfo.index);
originMethods[id] = origin;
hookMethodEntities[id] = entity;
tryCompileCallOriginMethod(stubMethodInfo.args, stubMethodInfo.index);
return entity;
if (tryCompileAndResolveCallOriginMethod(entity.backup, stubMethodInfo.args, stubMethodInfo.index)) {
return entity;
} else {
return null;
}
}
}
......@@ -174,10 +178,13 @@ public class HookStubManager {
}
}
public static void tryCompileCallOriginMethod(int args, int index) {
public static boolean tryCompileAndResolveCallOriginMethod(Method backupMethod, int args, int index) {
Method method = getCallOriginMethod(args, index);
if (method != null) {
SandHook.compileMethod(method);
SandHookMethodResolver.resolveMethod(method, backupMethod);
return SandHook.compileMethod(method);
} else {
return false;
}
}
......
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