Commit 3d7db2a9 authored by swift_gan's avatar swift_gan

fix resolve cache

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