Fix Java Primitive Type Class not found problem in Android 5.0.2 (API 21) or latest

This commit is contained in:
2022-12-30 20:47:58 +08:00
parent 2dc4ea9d45
commit 903f55db06
2 changed files with 21 additions and 21 deletions

View File

@@ -39,8 +39,7 @@ import com.highcapable.yukihookapi.hook.core.finder.members.FieldFinder
import com.highcapable.yukihookapi.hook.core.finder.members.MethodFinder import com.highcapable.yukihookapi.hook.core.finder.members.MethodFinder
import com.highcapable.yukihookapi.hook.core.finder.tools.ReflectionTool import com.highcapable.yukihookapi.hook.core.finder.tools.ReflectionTool
import com.highcapable.yukihookapi.hook.core.finder.type.factory.* import com.highcapable.yukihookapi.hook.core.finder.type.factory.*
import com.highcapable.yukihookapi.hook.type.java.AnyClass import com.highcapable.yukihookapi.hook.type.java.*
import com.highcapable.yukihookapi.hook.type.java.UnitType
import com.highcapable.yukihookapi.hook.xposed.bridge.status.YukiHookModuleStatus import com.highcapable.yukihookapi.hook.xposed.bridge.status.YukiHookModuleStatus
import com.highcapable.yukihookapi.hook.xposed.parasitic.AppParasitics import com.highcapable.yukihookapi.hook.xposed.parasitic.AppParasitics
import dalvik.system.BaseDexClassLoader import dalvik.system.BaseDexClassLoader
@@ -180,17 +179,18 @@ infix fun Class<*>?.notImplements(other: Class<*>?) = implements(other).not()
* - [java.lang.Byte] * - [java.lang.Byte]
* @return [Class] * @return [Class]
*/ */
fun Class<*>.toJavaPrimitiveType() = fun Class<*>.toJavaPrimitiveType() = when (this) {
if (name != Unit.toString() && name != "java.lang.Void" && name != "void") classOf<Unit>(), UnitClass, UnitType -> UnitType
(name.replace("java.lang.Boolean", "boolean") BooleanClass, BooleanType -> BooleanType
.replace("java.lang.Integer", "int") IntClass, IntType -> IntType
.replace("java.lang.Float", "float") FloatClass, FloatType -> FloatType
.replace("java.lang.Double", "double") DoubleClass, DoubleType -> DoubleType
.replace("java.lang.Long", "long") LongClass, LongType -> LongType
.replace("java.lang.Short", "short") ShortClass, ShortType -> ShortType
.replace("java.lang.Character", "char") CharClass, CharType -> CharType
.replace("java.lang.Byte", "byte")).toClass() ByteClass, ByteType -> ByteType
else UnitType else -> this
}
/** /**
* 通过字符串类名转换为 [loader] 中的实体类 * 通过字符串类名转换为 [loader] 中的实体类

View File

@@ -84,7 +84,7 @@ val AnyType get() = AnyClass
* 这是 Java 原始类型 (Primitive Type) - 它在字节码中的关键字为 "boolean" * 这是 Java 原始类型 (Primitive Type) - 它在字节码中的关键字为 "boolean"
* @return [Class] * @return [Class]
*/ */
val BooleanType get() = "boolean".toClass() val BooleanType get() = Boolean::class.javaPrimitiveType ?: "boolean".toClass()
/** /**
* 获得 [Char] 类型 * 获得 [Char] 类型
@@ -92,7 +92,7 @@ val BooleanType get() = "boolean".toClass()
* 这是 Java 原始类型 (Primitive Type) - 它在字节码中的关键字为 "char" * 这是 Java 原始类型 (Primitive Type) - 它在字节码中的关键字为 "char"
* @return [Class] * @return [Class]
*/ */
val CharType get() = "char".toClass() val CharType get() = Char::class.javaPrimitiveType ?: "char".toClass()
/** /**
* 获得 [Byte] 类型 * 获得 [Byte] 类型
@@ -100,7 +100,7 @@ val CharType get() = "char".toClass()
* 这是 Java 原始类型 (Primitive Type) - 它在字节码中的关键字为 "byte" * 这是 Java 原始类型 (Primitive Type) - 它在字节码中的关键字为 "byte"
* @return [Class] * @return [Class]
*/ */
val ByteType get() = "byte".toClass() val ByteType get() = Byte::class.javaPrimitiveType ?: "byte".toClass()
/** /**
* 获得 [Short] 类型 * 获得 [Short] 类型
@@ -108,7 +108,7 @@ val ByteType get() = "byte".toClass()
* 这是 Java 原始类型 (Primitive Type) - 它在字节码中的关键字为 "short" * 这是 Java 原始类型 (Primitive Type) - 它在字节码中的关键字为 "short"
* @return [Class] * @return [Class]
*/ */
val ShortType get() = "short".toClass() val ShortType get() = Short::class.javaPrimitiveType ?: "short".toClass()
/** /**
* 获得 [Int] 类型 * 获得 [Int] 类型
@@ -116,7 +116,7 @@ val ShortType get() = "short".toClass()
* 这是 Java 原始类型 (Primitive Type) - 它在字节码中的关键字为 "int" * 这是 Java 原始类型 (Primitive Type) - 它在字节码中的关键字为 "int"
* @return [Class] * @return [Class]
*/ */
val IntType get() = "int".toClass() val IntType get() = Int::class.javaPrimitiveType ?: "int".toClass()
/** /**
* 获得 [Float] 类型 * 获得 [Float] 类型
@@ -124,7 +124,7 @@ val IntType get() = "int".toClass()
* 这是 Java 原始类型 (Primitive Type) - 它在字节码中的关键字为 "float" * 这是 Java 原始类型 (Primitive Type) - 它在字节码中的关键字为 "float"
* @return [Class] * @return [Class]
*/ */
val FloatType get() = "float".toClass() val FloatType get() = Float::class.javaPrimitiveType ?: "float".toClass()
/** /**
* 获得 [Long] 类型 * 获得 [Long] 类型
@@ -132,7 +132,7 @@ val FloatType get() = "float".toClass()
* 这是 Java 原始类型 (Primitive Type) - 它在字节码中的关键字为 "long" * 这是 Java 原始类型 (Primitive Type) - 它在字节码中的关键字为 "long"
* @return [Class] * @return [Class]
*/ */
val LongType get() = "long".toClass() val LongType get() = Long::class.javaPrimitiveType ?: "long".toClass()
/** /**
* 获得 [Double] 类型 * 获得 [Double] 类型
@@ -140,7 +140,7 @@ val LongType get() = "long".toClass()
* 这是 Java 原始类型 (Primitive Type) - 它在字节码中的关键字为 "double" * 这是 Java 原始类型 (Primitive Type) - 它在字节码中的关键字为 "double"
* @return [Class] * @return [Class]
*/ */
val DoubleType get() = "double".toClass() val DoubleType get() = Double::class.javaPrimitiveType ?: "double".toClass()
/** /**
* 获得 [Unit] 类型 * 获得 [Unit] 类型