Xposed kotlin extension.
Step 1. Add the JitPack repository to your build file
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.ikws4:xposed-ktx:latest-version'
}
Use className(String) to hook method.
val className = "android.app.Activity"
className.hookMethod(classLoder, "onCreate", Bundle::class.java,
beforeHookedMethod = { param ->
// Do something
},
afterHookedMethod = { param ->
// Do something
})
// if you just use afterHookedMethod, you can do this
Activity::class.java.hookMethod("onCreate", Bundle::class.java) { param ->
// Do something
}
Use class to hook method, then you can use 'this' to get Activity instance.
Activity::class.java.hookMethod("onCreate", Bundle::class.java,
beforeHookedMethod = { param ->
// for example
Toast.makeText(this, "I'm a toast", Toast.LENGHT_SHORT).show()
},
afterHookedMethod = { param ->
// Do something
})
Activity::class.java.replaceMethod("onCreate", Bundle::class.java){ param ->
// `this` is the Activity instance
}
// or
val className = "android.app.Activity"
className.replaceMethod(classLoder, "onCreate", Bundle::class.java){ param ->
// Do something
}
TextView::class.java.hookConstructor(Context::class.java,
beforeHookedMethod = { param ->
// Do something
// 'this' is the TextView instance
},
afterHookedMethod = { param ->
// Do something
})
// or
val className = "android.widget.TextView"
className.hookConstructor(classLoader,Context::class.java,
beforeHookedMethod = { param ->
// Do something
},
afterHookedMethod = { param ->
// Do something
})
TextView::class.java.replaceConstructor(Context::class.java) { param ->
// 'this' is the TextView instance
// Do something
}
// or
val className = "android.widget.TextView"
className.replaceConstructor(classLoader,Context::class.java) { param ->
// Do something
}