PAGalaxyLab / YAHFA

Yet Another Hook Framework for ART
GNU General Public License v3.0
1.56k stars 350 forks source link

support android 12 better. #163

Closed WindySha closed 2 years ago

WindySha commented 2 years ago

OFFSET_classlinker_in_Runtime should be 472 + 8 in the newest android 12 version.

yearsyan commented 2 years ago

I think the better way to get classlinker address is the relative offset of JavaVMExt address which is easy to get by JNI. In an art::Runtime instance, whether android 11 or android 12, the offset is 3 pointer size.

ClassLinker* class_linker_;

SignalCatcher* signal_catcher_;

std::unique_ptr<jni::JniIdManager> jni_id_manager_;

std::unique_ptr<JavaVMExt> java_vm_;
rk700 commented 2 years ago

I think the better way to get classlinker address is the relative offset of JavaVMExt address which is easy to get by JNI. In an art::Runtime instance, whether android 11 or android 12, the offset is 3 pointer size.

ClassLinker* class_linker_;

SignalCatcher* signal_catcher_;

std::unique_ptr<jni::JniIdManager> jni_id_manager_;

std::unique_ptr<JavaVMExt> java_vm_;

Thanks! That's a good idea. I just pushed a new commit for it: 9cea98bd749164c011ac44d35c32c2a0e4b146c6

yujincheng08 commented 2 years ago

@rk700 Not actually true: https://android.googlesource.com/platform/art/+/4dcac3629ea5925e47b522073f3c49420e998911

diff --git [a/runtime/runtime.h](https://android.googlesource.com/platform/art/+/48fb9f43a81fa0cab09ed4a4f3d478c1a0ecbe9e/runtime/runtime.h) [b/runtime/runtime.h](https://android.googlesource.com/platform/art/+/4dcac3629ea5925e47b522073f3c49420e998911/runtime/runtime.h)
index 2dd022e..0c99cf9 100644
--- a/runtime/runtime.h
+++ b/runtime/runtime.h
@@ -107,6 +107,7 @@
 struct RuntimeArgumentMap;
 class RuntimeCallbacks;
 class SignalCatcher;
+class SmallIrtAllocator;
 class StackOverflowHandler;
 class SuspensionHandler;
 class ThreadList;
@@ -324,6 +325,10 @@
     return class_linker_;
   }

+  SmallIrtAllocator* GetSmallIrtAllocator() const {
+    return small_irt_allocator_;
+  }
+
   jni::JniIdManager* GetJniIdManager() const {
     return jni_id_manager_.get();
   }
@@ -1198,6 +1203,8 @@

   SignalCatcher* signal_catcher_;

+  SmallIrtAllocator* small_irt_allocator_;
+
   std::unique_ptr<jni::JniIdManager> jni_id_manager_;

   std::unique_ptr<JavaVMExt> java_vm_;
yearsyan commented 2 years ago

@rk700 Not actually true: https://android.googlesource.com/platform/art/+/4dcac3629ea5925e47b522073f3c49420e998911

diff --git [a/runtime/runtime.h](https://android.googlesource.com/platform/art/+/48fb9f43a81fa0cab09ed4a4f3d478c1a0ecbe9e/runtime/runtime.h) [b/runtime/runtime.h](https://android.googlesource.com/platform/art/+/4dcac3629ea5925e47b522073f3c49420e998911/runtime/runtime.h)
index 2dd022e..0c99cf9 100644
--- a/runtime/runtime.h
+++ b/runtime/runtime.h
@@ -107,6 +107,7 @@
 struct RuntimeArgumentMap;
 class RuntimeCallbacks;
 class SignalCatcher;
+class SmallIrtAllocator;
 class StackOverflowHandler;
 class SuspensionHandler;
 class ThreadList;
@@ -324,6 +325,10 @@
     return class_linker_;
   }

+  SmallIrtAllocator* GetSmallIrtAllocator() const {
+    return small_irt_allocator_;
+  }
+
   jni::JniIdManager* GetJniIdManager() const {
     return jni_id_manager_.get();
   }
@@ -1198,6 +1203,8 @@

   SignalCatcher* signal_catcher_;

+  SmallIrtAllocator* small_irt_allocator_;
+
   std::unique_ptr<jni::JniIdManager> jni_id_manager_;

   std::unique_ptr<JavaVMExt> java_vm_;

Excuse my ignorance, when will this change take effect, in Android 13 or with Android12 update?

rk700 commented 2 years ago

So the distance between classlinker and javavm is increased by 1 pointer right?

canyie commented 2 years ago

I think you are right. And I think we can try to dlsym some symbols added in this commit (just like https://github.com/canyie/pine/commit/34dc23e34f600f6c44092a2c2a7c66e9fa30b994) to detect if the rom merged this commit.

shuajinanhai commented 2 years ago

是的,我用小米6刷过12系统测试过,获取到的是错误的值。不过也有其他12系统刷机包,获取到的是正确的值。另外安卓13测试过,也是错误的

shuajinanhai commented 2 years ago

另外安卓13也保留32位环境

yearsyan commented 2 years ago

是的,我用小米6刷过12系统测试过,获取到的是错误的值。不过也有其他12系统刷机包,获取到的是正确的值。另外安卓13测试过,也是错误的

安卓12L与13已经合并此修改。安卓12除主分支外我没有发现合并修改,不知道是否有遗漏。这可能是第三方系统直接使用master分支构建的原因。