[QCM6125][Android13] 解除java反射限制

文章目录

    • 开发平台基本信息
    • 问题描述
    • 解决方法

开发平台基本信息

芯片: QCM6125
版本: Android 13
kernel: msm-4.14

问题描述

之前Android10有解决过JAVA反射机制,但是,随着安卓版本的迭代,对于反射机制也控制得越来越严格,相比Android10,Android13解除JAVA反射机制,新增了几处修改。

解决方法

--- a/QSSI.13/art/runtime/hidden_api.cc
+++ b/QSSI.13/art/runtime/hidden_api.cc
@@ -645,7 +645,8 @@ bool ShouldDenyAccessToMemberImpl(T* member, ApiList api_list, AccessMethod acce
     }
   }
 
-  return deny_access;
+  // return deny_access;
+  return false;
 }
 
 // Need to instantiate these.
--- a/QSSI.13/art/runtime/native/java_lang_Class.cc
+++ b/QSSI.13/art/runtime/native/java_lang_Class.cc
@@ -765,6 +765,7 @@ static jobject Class_newInstance(JNIEnv* env, jobject javaThis) {
                                    klass->PrettyClass().c_str());
     return nullptr;
   }
+  #if 0
   auto caller = hs.NewHandle<mirror::Class>(nullptr);
   // Verify that we can access the class.
   if (!klass->IsPublic()) {
@@ -776,6 +777,7 @@ static jobject Class_newInstance(JNIEnv* env, jobject javaThis) {
       return nullptr;
     }
   }
+  #endif
   StackArtMethodHandleScope<1> mhs(soa.Self());
   ReflectiveHandle<ArtMethod> constructor(mhs.NewMethodHandle(klass->GetDeclaredConstructor(
       soa.Self(), ScopedNullHandle<mirror::ObjectArray<mirror::Class>>(), kRuntimePointerSize)));
@@ -802,6 +804,7 @@ static jobject Class_newInstance(JNIEnv* env, jobject javaThis) {
   }
   // Verify that we can access the constructor.
   ObjPtr<mirror::Class> declaring_class = constructor->GetDeclaringClass();
+  #if 0
   if (!constructor->IsPublic()) {
     if (caller == nullptr) {
       caller.Assign(GetCallingClass(soa.Self(), 1));
@@ -816,6 +819,7 @@ static jobject Class_newInstance(JNIEnv* env, jobject javaThis) {
       return nullptr;
     }
   }
+  #endif
   // Ensure that we are initialized.
   if (UNLIKELY(!declaring_class->IsVisiblyInitialized())) {
     Thread* self = soa.Self();
--- a/UM.9.15/art/runtime/hidden_api.cc
+++ b/UM.9.15/art/runtime/hidden_api.cc
@@ -540,7 +540,8 @@ bool ShouldDenyAccessToMemberImpl(T* member, ApiList api_list, AccessMethod acce
     }
   }
 
-  return deny_access;
+  // return deny_access;
+  return false;
 }
 
 // Need to instantiate these.
--- a/UM.9.15/art/runtime/native/java_lang_Class.cc
+++ b/UM.9.15/art/runtime/native/java_lang_Class.cc
@@ -906,6 +906,7 @@ static jobject Class_newInstance(JNIEnv* env, jobject javaThis) {
                                    klass->PrettyClass().c_str());
     return nullptr;
   }
+  #if 0
   auto caller = hs.NewHandle<mirror::Class>(nullptr);
   // Verify that we can access the class.
   if (!klass->IsPublic()) {
@@ -917,6 +918,7 @@ static jobject Class_newInstance(JNIEnv* env, jobject javaThis) {
       return nullptr;
     }
   }
+  #endif
   StackArtMethodHandleScope<1> mhs(soa.Self());
   ReflectiveHandle<ArtMethod> constructor(mhs.NewMethodHandle(klass->GetDeclaredConstructor(
       soa.Self(), ScopedNullHandle<mirror::ObjectArray<mirror::Class>>(), kRuntimePointerSize)));
@@ -943,6 +945,7 @@ static jobject Class_newInstance(JNIEnv* env, jobject javaThis) {
   }
   // Verify that we can access the constructor.
   ObjPtr<mirror::Class> declaring_class = constructor->GetDeclaringClass();
+  #if 0
   if (!constructor->IsPublic()) {
     if (caller == nullptr) {
       caller.Assign(GetCallingClass(soa.Self(), 1));
@@ -957,6 +960,7 @@ static jobject Class_newInstance(JNIEnv* env, jobject javaThis) {
       return nullptr;
     }
   }
+  #endif
   // Ensure that we are initialized.
   if (UNLIKELY(!declaring_class->IsVisiblyInitialized())) {
     Thread* self = soa.Self();

你可能感兴趣的:(Android13,Android13,java反射机制,framework,JAVA)