Commit 3d7db2a9 authored by swift_gan's avatar swift_gan

fix resolve cache

parent 8775fed6
......@@ -91,8 +91,8 @@ namespace SandHook {
//test
art::mirror::ArtMethod** mArray = reinterpret_cast<art::mirror::ArtMethod**>(m1.dex_cache_resolved_methods_);
art::mirror::ArtMethod m1B = *(mArray + 8)[m1.dex_method_index_];
art::mirror::ArtMethod m1C = *(mArray + 8)[m2.dex_method_index_];
art::mirror::ArtMethod m1B = *mArray[m1.dex_method_index_];
art::mirror::ArtMethod m1C = *mArray[m2.dex_method_index_];
}
......
......@@ -57,7 +57,7 @@ public class MainActivity extends AppCompatActivity {
artMethodField.setAccessible(true);
long artMethod = (long) artMethodField.get(method1);
// methods[dexMethodIndex] = artMethod;
methods[dexMethodIndex] = artMethod;
initHook();
// SandHook.init();
......
......@@ -46,11 +46,11 @@ public class SandHookMethodResolver {
}
}
public static void resolveMethod(Method method) {
public static void resolveMethod(Method hook, Method backup) {
if (canResolvedInJava && artMethodField != null) {
// in java
try {
resolveInJava(method);
resolveInJava(hook, backup);
} catch (Exception e) {
// in native
}
......@@ -59,17 +59,16 @@ public class SandHookMethodResolver {
}
}
private static void resolveInJava(Method method) throws Exception {
Object dexCache = dexCacheField.get(method.getDeclaringClass());
resolvedMethodsField.setAccessible(true);
int dexMethodIndex = (int) dexMethodIndexField.get(method);
private static void resolveInJava(Method hook, Method backup) throws Exception {
Object dexCache = dexCacheField.get(hook.getDeclaringClass());
int dexMethodIndex = (int) dexMethodIndexField.get(backup);
Object resolvedMethods = resolvedMethodsField.get(dexCache);
if (resolvedMethods instanceof long[]) {
long artMethod = (long) artMethodField.get(method);
long artMethod = (long) artMethodField.get(backup);
((long[])resolvedMethods)[dexMethodIndex] = artMethod;
} else if (resolvedMethods instanceof Object[]) {
Object artMethod = artMethodField.get(method);
Object artMethod = artMethodField.get(backup);
((Object[])resolvedMethods)[dexMethodIndex] = artMethod;
} else {
throw new UnsupportedOperationException("unsupport");
......
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