Commit ea2f1173 authored by swift_gan's avatar swift_gan

try support k

parent 3881352b
......@@ -48,8 +48,18 @@ namespace SandHook {
Size calOffset(JNIEnv *jniEnv, art::mirror::ArtMethod *p) override {
if (SDK_INT >= ANDROID_L2 && SDK_INT <= ANDROID_M)
return getParentSize() - 3 * BYTE_POINT;
else if (SDK_INT <= ANDROID_L)
else if (SDK_INT <= ANDROID_L) {
Size addr = getAddressFromJava(jniEnv, "com/swift/sandhook/SandHookMethodResolver",
"entryPointFromInterpreter");
int offset = 0;
if (addr != 0) {
offset = findOffset(p, getParentSize(), 2, addr);
if (offset >= 0) {
return static_cast<Size>(offset);
}
}
return getParentSize() - 4 * 8 - 4 * 4;
}
else
return getParentSize() + 1;
}
......@@ -60,6 +70,17 @@ namespace SandHook {
Size calOffset(JNIEnv *jniEnv, art::mirror::ArtMethod *p) override {
if (SDK_INT >= ANDROID_M) {
return getParentSize() - BYTE_POINT;
} else if (SDK_INT <= ANDROID_L) {
Size addr = getAddressFromJava(jniEnv, "com/swift/sandhook/SandHookMethodResolver",
"entryPointFromCompiledCode");
int offset = 0;
if (addr != 0) {
offset = findOffset(p, getParentSize(), 2, addr);
if (offset >= 0) {
return static_cast<Size>(offset);
}
}
return getParentSize() - 4 - 2 * BYTE_POINT;
} else {
return getParentSize() - 4 - 2 * BYTE_POINT;
}
......
......@@ -312,7 +312,11 @@ public class SandHook {
if (nativePeerField == null)
return 0;
try {
return (long) nativePeerField.get(Thread.currentThread());
if (nativePeerField.getType() == int.class) {
return nativePeerField.getInt(Thread.currentThread());
} else {
return nativePeerField.getLong(Thread.currentThread());
}
} catch (IllegalAccessException e) {
return 0;
}
......
......@@ -13,6 +13,8 @@ public class SandHookMethodResolver {
public static Field dexCacheField;
public static Field dexMethodIndexField;
public static Field artMethodField;
public static Field fieldEntryPointFromCompiledCode;
public static Field fieldEntryPointFromInterpreter;
public static boolean canResolvedInJava = false;
public static boolean isArtMethod = false;
......@@ -20,6 +22,9 @@ public class SandHookMethodResolver {
public static long resolvedMethodsAddress = 0;
public static int dexMethodIndex = 0;
public static long entryPointFromCompiledCode = 0;
public static long entryPointFromInterpreter = 0;
public static Method testMethod;
public static Object testArtMethod;
......@@ -50,13 +55,37 @@ public class SandHookMethodResolver {
// may 5.0
private static void checkSupportForArtMethod() throws Exception {
try {
dexMethodIndexField = getField(artMethodClass, "dexMethodIndex");
} catch (NoSuchFieldException e) {
//may 4.4
dexMethodIndexField = getField(artMethodClass, "methodDexIndex");
}
dexCacheField = getField(Class.class, "dexCache");
Object dexCache = dexCacheField.get(testMethod.getDeclaringClass());
resolvedMethodsField = getField(dexCache.getClass(), "resolvedMethods");
if (resolvedMethodsField.get(dexCache) instanceof Object[]) {
canResolvedInJava = true;
}
try {
try {
fieldEntryPointFromCompiledCode = getField(artMethodClass, "entryPointFromQuickCompiledCode");
} catch (Exception e) {
fieldEntryPointFromCompiledCode = getField(artMethodClass, "entryPointFromCompiledCode");
}
if (fieldEntryPointFromCompiledCode.getType() == int.class) {
entryPointFromCompiledCode = fieldEntryPointFromCompiledCode.getInt(testArtMethod);
} else if (fieldEntryPointFromCompiledCode.getType() == long.class) {
entryPointFromCompiledCode = fieldEntryPointFromCompiledCode.getLong(testArtMethod);
}
fieldEntryPointFromInterpreter = getField(artMethodClass, "entryPointFromInterpreter");
if (fieldEntryPointFromInterpreter.getType() == int.class) {
entryPointFromInterpreter = fieldEntryPointFromInterpreter.getInt(testArtMethod);
} else if (fieldEntryPointFromCompiledCode.getType() == long.class) {
entryPointFromInterpreter = fieldEntryPointFromInterpreter.getLong(testArtMethod);
}
} catch (Throwable e) {
}
}
// may 6.0
......
......@@ -46,7 +46,10 @@ public class HookWrapper {
}
private static void fillBackupMethod(ClassLoader classLoader,Class<?> clazz, Map<Member, HookEntity> hookEntityMap) {
Field[] fields = clazz.getDeclaredFields();
Field[] fields = null;
try {
fields = clazz.getDeclaredFields();
} catch (Throwable throwable) {}
if (fields == null || fields.length == 0)
return;
if (hookEntityMap.isEmpty())
......
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