Notice
The English translation of this page has not been completed, you are welcome to contribute translations to us.
You can use the Chrome Translation Plugin to translate entire pages for reference.
ReflectionFactory - kt
Change Records
v1.0 first
Function Illustrate
这是自定义
Member和Class相关功能的查找匹配以及invoke的封装类。
MembersType - class
enum class MembersType
Change Records
v1.1.0 added
Function Illustrate
定义一个
Class中的Member类型
ALL - enum
ALL
Change Records
v1.1.0 added
Function Illustrate
全部
Method与Constructor。
METHOD - enum
METHOD
Change Records
v1.1.0 added
Function Illustrate
全部
Method。
CONSTRUCTOR - enum
CONSTRUCTOR
Change Records
v1.1.0 added
Function Illustrate
全部
Constructor。
LazyClass - class
open class LazyClass<T> internal constructor(
    private val instance: Any,
    private val initialize: Boolean,
    private val loader: ClassLoaderInitializer?
)
Change Records
v1.2.0 added
Function Illustrate
懒装载
Class实例。
ClassLoader.listOfClasses - ext-method
fun ClassLoader.listOfClasses(): List<String>
Change Records
v1.1.2 added
Function Illustrate
写出当前
ClassLoader下所有Class名称数组。
ClassLoader.searchClass - ext-method
inline fun ClassLoader.searchClass(name: String, async: Boolean, initiate: ClassConditions): DexClassFinder.Result
Change Records
v1.1.0 added
Function Illustrate
通过当前
ClassLoader按指定条件查找并得到 Dex 中的Class。
Pay Attention
此方法在 Class 数量过多及查找条件复杂时会非常耗时。
建议启用 async 或设置 name 参数,name 参数将在 Hook APP (宿主) 不同版本中自动进行本地缓存以提升效率。
此功能尚在实验阶段,性能与稳定性可能仍然存在问题,使用过程遇到问题请向我们报告并帮助我们改进。
ClassLoader.onLoadClass - ext-method
fun ClassLoader.onLoadClass(result: (Class<*>) -> Unit)
Change Records
v1.1.0 added
Function Illustrate
监听当前
ClassLoader的ClassLoader.loadClass方法装载。
Pay Attention
只有当前 ClassLoader 有主动使用 ClassLoader.loadClass 事件时才能被捕获。
这是一个实验性功能,一般情况下不会用到此方法,不保证不会发生错误。
只能在 (Xposed) 宿主环境使用此功能,其它环境下使用将不生效且会打印警告信息。
Function Example
针对一些使用特定 ClassLoader 装载 Class 的宿主应用,你可以使用此方法来监听 Class 加载情况。
Notice
为了防止发生问题,你需要得到一个存在的 ClassLoader 实例来使用此功能。
比如我们在 PackageParam 中使用 appClassLoader。
The following example
appClassLoader.onLoadClass { clazz ->
    // 得到 clazz 即加载对象
    clazz... // 这里进行你需要的操作
}
或使用你得到的存在的 ClassLoader 实例,可以通过 Hook 获取。
The following example
val customClassLoader: ClassLoader? = ... // 假设这个就是你的 ClassLoader
customClassLoader?.onLoadClass { clazz ->
    // ...
}
在判断到这个 Class 被装载成功时,开始执行你的 Hook 功能。
The following example
val customClassLoader: ClassLoader? = ... // 假设这个就是你的 ClassLoader
customClassLoader?.onLoadClass { clazz ->
    if(clazz.name == /** 你需要的 Class 名称 */) {
        clazz.hook {
            // ...
        }
    }
}
hookClass - field
Change Records
v1.0 first
v1.1.0 removed
HookClass 相关功能不再对外开放
normalClass - field
Change Records
v1.0 first
v1.1.0 removed
HookClass 相关功能不再对外开放
hasClass - field
Change Records
v1.0 first
v1.1.0 removed
请直接使用 hasClass() 无参方法
Class.hasExtends - ext-field
val Class<*>.hasExtends: Boolean
Change Records
v1.0.80 added
Function Illustrate
当前
Class是否有继承关系,父类是Any将被认为没有继承关系。
Class?.extends - ext-method
infix fun Class<*>?.extends(other: Class<*>?): Boolean
Change Records
v1.1.5 added
Function Illustrate
当前
Class是否继承于other。
如果当前 Class 就是 other 也会返回 true。
如果当前 Class 为 null 或 other 为 null 会返回 false。
Function Example
你可以使用此方法来判断两个 Class 是否存在继承关系。
The following example
// 假设下面这两个 Class 就是你需要判断的 Class
val classA: Class<*>?
val classB: Class<*>?
// 判断 A 是否继承于 B
if (classA extends classB) {
    // Your code here.
}
Class?.notExtends - ext-method
infix fun Class<*>?.notExtends(other: Class<*>?): Boolean
Change Records
v1.1.5 added
Function Illustrate
当前
Class是否不继承于other。
此方法相当于 extends 的反向判断。
Function Example
你可以使用此方法来判断两个 Class 是否不存在继承关系。
The following example
// 假设下面这两个 Class 就是你需要判断的 Class
val classA: Class<*>?
val classB: Class<*>?
// 判断 A 是否不继承于 B
if (classA notExtends classB) {
    // Your code here.
}
Class?.implements - ext-method
infix fun Class<*>?.implements(other: Class<*>?): Boolean
Change Records
v1.1.5 added
Function Illustrate
当前
Class是否实现了other接口类。
如果当前 Class 为 null 或 other 为 null 会返回 false。
Function Example
你可以使用此方法来判断两个 Class 是否存在依赖关系。
The following example
// 假设下面这两个 Class 就是你需要判断的 Class
val classA: Class<*>?
val classB: Class<*>?
// 判断 A 是否实现了 B 接口类
if (classA implements classB) {
    // Your code here.
}
Class?.notImplements - ext-method
infix fun Class<*>?.notImplements(other: Class<*>?): Boolean
Change Records
v1.1.5 added
Function Illustrate
当前
Class是否未实现other接口类。
此方法相当于 implements 的反向判断。
Function Example
你可以使用此方法来判断两个 Class 是否不存在依赖关系。
The following example
// 假设下面这两个 Class 就是你需要判断的 Class
val classA: Class<*>?
val classB: Class<*>?
// 判断 A 是否未实现 B 接口类
if (classA notImplements classB) {
    // Your code here.
}
Class.toJavaPrimitiveType - ext-method
fun Class<*>.toJavaPrimitiveType(): Class<*>
Change Records
v1.1.5 added
Function Illustrate
自动转换当前
Class为 Java 原始类型 (Primitive Type)。
如果当前 Class 为 Java 或 Kotlin 基本类型将自动执行类型转换。
当前能够自动转换的基本类型如下。
kotlin.Unitjava.lang.Voidjava.lang.Booleanjava.lang.Integerjava.lang.Floatjava.lang.Doublejava.lang.Longjava.lang.Shortjava.lang.Characterjava.lang.Byte
classOf - method
Change Records
v1.0 first
v1.1.0 deprecated
请转到 toClass(...) 方法
String.toClass - ext-method
fun String.toClass(loader: ClassLoader?, initialize: Boolean): Class<*>
inline fun <reified T> String.toClass(loader: ClassLoader?, initialize: Boolean): Class<T>
Change Records
v1.1.0 added
v1.1.5 modified
新增泛型返回值 Class<T> 方法
新增 initialize 参数
Function Illustrate
通过字符串类名转换为
loader中的实体类。
Function Example
你可以直接填写你要查找的目标 Class,必须在默认 ClassLoader 下存在。
The following example
"com.example.demo.DemoClass".toClass()
你还可以自定义 Class 所在的 ClassLoader。
The following example
val customClassLoader: ClassLoader? = ... // 假设这个就是你的 ClassLoader
"com.example.demo.DemoClass".toClass(customClassLoader)
你还可以指定 Class 的目标类型。
The following example
// 指定的 DemoClass 必须存在或为可访问的 stub
"com.example.demo.DemoClass".toClass<DemoClass>()
你还可以设置在获取到这个 Class 时是否自动执行其默认的静态方法块,默认情况下不会执行。
The following example
// 获取并执行 DemoClass 默认的静态方法块
"com.example.demo.DemoClass".toClass(initialize = true)
默认的静态方法块在 Java 中使用如下方式定义。
The following example
public class DemoClass {
    static {
        // 这里是静态方法块的内容
    }
    public DemoClass() {
        // ...
    }
}
String.toClassOrNull - ext-method
fun String.toClassOrNull(loader: ClassLoader?, initialize: Boolean): Class<*>?
inline fun <reified T> String.toClassOrNull(loader: ClassLoader?, initialize: Boolean): Class<T>?
Change Records
v1.1.0 added
v1.1.5 modified
新增泛型返回值 Class<T> 方法
新增 initialize 参数
Function Illustrate
通过字符串类名转换为
loader中的实体类。
找不到 Class 会返回 null,不会抛出异常。
Function Example
用法请参考 String.toClass 方法。
classOf - method
inline fun <reified T> classOf(loader: ClassLoader?, initialize: Boolean): Class<T>
Change Records
v1.1.0 added
v1.1.5 modified
将返回类型由 Class<*> cast 为 Class<T>
新增 initialize 参数
Function Illustrate
通过
T得到其Class实例并转换为实体类。
Function Example
我们要获取一个 Class 在 Kotlin 下不通过反射时应该这样做。
The following example
DemoClass::class.java
现在,你可以直接 cast 一个实例并获取它的 Class 对象,必须在当前 ClassLoader 下存在。
The following example
classOf<DemoClass>()
若目标存在的 Class 为 stub,通过这种方式,你还可以自定义 Class 所在的 ClassLoader。
The following example
val customClassLoader: ClassLoader? = ... // 假设这个就是你的 ClassLoader
classOf<DemoClass>(customClassLoader)
lazyClass - method
fun lazyClass(name: String, initialize: Boolean, loader: ClassLoaderInitializer?): LazyClass.NonNull<Any>
inline fun <reified T> lazyClass(name: String, initialize: Boolean, loader: ClassLoaderInitializer?): LazyClass.NonNull<T>
fun lazyClass(variousClass: VariousClass, initialize: Boolean, loader: ClassLoaderInitializer?): LazyClass.NonNull<Any>
Change Records
v1.2.0 added
Function Illustrate
懒装载
Class。
lazyClassOrNull - method
fun lazyClassOrNull(name: String, initialize: Boolean, loader: ClassLoaderInitializer?): LazyClass.Nullable<Any>
inline fun <reified T> lazyClassOrNull(name: String, initialize: Boolean, loader: ClassLoaderInitializer?): LazyClass.Nullable<T>
fun lazyClassOrNull(variousClass: VariousClass, initialize: Boolean, loader: ClassLoaderInitializer?): LazyClass.Nullable<Any>
Change Records
v1.2.0 added
Function Illustrate
懒装载
Class。
String.hasClass - ext-method
fun String.hasClass(loader: ClassLoader?): Boolean
Change Records
v1.0 first
v1.1.0 modified
支持直接使用空参数方法使用默认 ClassLoader 进行判断
Function Illustrate
通过字符串类名使用指定的
ClassLoader查找是否存在。
Function Example
你可以轻松的使用此方法判断字符串中的类是否存在,效果等同于直接使用 Class.forName。
The following example
if("com.example.demo.DemoClass".hasClass()) {
    // Your code here.
}
填入方法中的 loader 参数可判断指定的 ClassLoader 中的 Class 是否存在。
The following example
val customClassLoader: ClassLoader? = ... // 假设这个就是你的 ClassLoader
if("com.example.demo.DemoClass".hasClass(customClassLoader)) {
    // Your code here.
}
Class.hasField - ext-method
inline fun Class<*>.hasField(initiate: FieldConditions): Boolean
Change Records
v1.0.4 added
v1.0.67 modified
合并到 FieldFinder
v1.0.80 modified
将方法体进行 inline
Function Illustrate
查找变量是否存在。
Class.hasMethod - ext-method
inline fun Class<*>.hasMethod(initiate: MethodConditions): Boolean
Change Records
v1.0 first
v1.0.1 modified
新增 returnType 参数
v1.0.67 modified
合并到 MethodFinder
v1.0.80 modified
将方法体进行 inline
Function Illustrate
查找方法是否存在。
Class.hasConstructor - ext-method
inline fun Class<*>.hasConstructor(initiate: ConstructorConditions): Boolean
Change Records
v1.0.2 added
v1.0.67 modified
合并到 ConstructorFinder
v1.0.80 modified
将方法体进行 inline
Function Illustrate
查找构造方法是否存在。
Member.hasModifiers - ext-method
inline fun Member.hasModifiers(conditions: ModifierConditions): Boolean
Change Records
v1.0.67 added
v1.0.80 modified
将方法体进行 inline
v1.1.0 modified
合并到 ModifierConditions
Function Illustrate
查找
Member中匹配的描述符。
Class.hasModifiers - ext-method
inline fun Class<*>.hasModifiers(conditions: ModifierConditions): Boolean
Change Records
v1.1.0 added
Function Illustrate
查找
Class中匹配的描述符。
obtainStaticFieldAny - method
Change Records
v1.0 first
v1.0.1 removed
obtainFieldAny - method
Change Records
v1.0 first
v1.0.1 removed
modifyStaticField - method
Change Records
v1.0 first
v1.0.1 removed
modifyField - method
Change Records
v1.0 first
v1.0.1 removed
Class.field - ext-method
inline fun Class<*>.field(initiate: FieldConditions): FieldFinder.Result
Change Records
v1.0.2 added
v1.0.80 modified
将方法体进行 inline
Function Illustrate
查找并得到变量。
Class.method - ext-method
inline fun Class<*>.method(initiate: MethodConditions): MethodFinder.Result
Change Records
v1.0 first
v1.0.1 modified
 更名为 obtainMethodmethod
新增 returnType 参数
v1.0.2 modified
合并到 MethodFinder 方法体
v1.0.80 modified
将方法体进行 inline
Function Illustrate
查找并得到方法。
Class.constructor - ext-method
inline fun Class<*>.constructor(initiate: ConstructorConditions): ConstructorFinder.Result
Change Records
v1.0 first
v1.0.1 modified
 更名为 obtainConstructorconstructor
v1.0.2 modified
合并到 ConstructorFinder 方法体
v1.0.80 modified
将方法体进行 inline
Function Illustrate
查找并得到构造方法。
callStatic - method
Change Records
v1.0 first
v1.0.1 modified
 更名为 invokeStaticcallStatic
v1.0.2 removed
call - method
Change Records
v1.0 first
v1.0.1 modified
 更名为 invokeAnycall
v1.0.2 removed
Class.generic - ext-method
fun Class<*>.generic(): GenericClass?
Change Records
v1.1.0 added
Function Illustrate
获得当前
Class的泛型父类。
如果当前实例不存在泛型将返回 null。
Class.generic - ext-method
inline fun Class<*>.generic(initiate: GenericClass.() -> Unit): GenericClass?
Change Records
v1.1.0 added
Function Illustrate
获得当前
Class的泛型父类。
如果当前实例不存在泛型将返回 null。
Any.current - ext-method
inline fun <reified T : Any> T.current(ignored: Boolean): CurrentClass
inline fun <reified T : Any> T.current(ignored: Boolean, initiate: CurrentClass.() -> Unit): T
Change Records
v1.0.70 added
v1.1.0 added
新增 ignored 参数,可以忽略在 CurrentClass 中出现的异常
新增不使用 current { ... } 调用域直接使用 current() 得到实例的类操作对象
Function Illustrate
获得当前实例的类操作对象。
Class.buildOfAny - ext-method
Change Records
v1.0.70 added
v1.0.80 modified
将方法体进行 inline
v1.1.0 deprecated
请迁移到 buildOf 方法
Class.buildOf - ext-method
inline fun Class<*>.buildOf(vararg args: Any?, initiate: ConstructorConditions): Any?
inline fun <T> Class<*>.buildOf(vararg args: Any?, initiate: ConstructorConditions): T?
Change Records
v1.0.70 added
v1.0.80 modified
将方法体进行 inline
v1.1.0 modified
加入无泛型方法 buildOf
v1.1.6 modified
修改参数命名 param 为 args
Function Illustrate
通过构造方法创建新实例,指定类型
T或任意类型Any。
Class.allMethods - ext-method
inline fun Class<*>.allMethods(isAccessible: Boolean, result: (index: Int, method: Method) -> Unit)
Change Records
v1.0.70 added
v1.0.80 modified
将方法体进行 inline
v1.1.5 modified
新增 isAccessible 参数
Function Illustrate
遍历当前类中的所有方法。
Class.allConstructors - ext-method
inline fun Class<*>.allConstructors(isAccessible: Boolean, result: (index: Int, constructor: Constructor<*>) -> Unit)
Change Records
v1.0.70 added
v1.0.80 modified
将方法体进行 inline
v1.1.5 modified
新增 isAccessible 参数
Function Illustrate
遍历当前类中的所有构造方法。
Class.allFields - ext-method
inline fun Class<*>.allFields(isAccessible: Boolean, result: (index: Int, field: Field) -> Unit)
Change Records
v1.0.70 added
v1.0.80 modified
将方法体进行 inline
v1.1.5 modified
新增 isAccessible 参数
Function Illustrate
遍历当前类中的所有变量。
