Skip to content

rhprincess/XposedKTX

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Xposed KTX

Download

A simple way to use your XposedBridge's api in Kotlin

· Installation

First, you need to implement XposedBridge's api in your build.gradle file PS: You need to use compileOnly instead implementation Second, implement our library to your dependencies

dependencies {
    // ...
    compileOnly 'de.robv.android.xposed:api:82'
    implementation 'io.rhprincess:xposed-ktx:$latest'
    // ...
}

· Current API

Method Description Param Made Available For
String.hook Use class name string as our hook aim init: HookerProxyForString.() -> Unit String
Class<*>.hook Directly use class to hook its method init: HookerProxyForClazz.() -> Unit Class<*>
String.hookConstructor Use class name string to hook a class’s constructor init: ConstructorHookerProxyForString.() -> Unit String
Class<*>.hookConstructor Directly use class to hook its constructor init: ConstructorHookerProxyForClazz.() -> Unit Class<*>
String.resHook Hook a package’s resources with its package name string init: LayoutHookerProxy.() -> Unit String
LayoutInflatedParam.findViewById Extension for LayoutInflatedParam using an id string to find a view instance id: String XC_LayoutInflated.LayoutInflatedParam
InitPackageResourcesParam.replace replace a resource type: String, name: String, replacement: Any XC_InitPackageResources.InitPackageResourcesParam
InitPackageResourcesParam.replace replace a resource pkgName: String, type: String, name: String, replacement: Any XC_InitPackageResources.InitPackageResourcesParam
InitPackageResourcesParam.replace replace a resource p: List< ReplaceProxy > XC_InitPackageResources.InitPackageResourcesParam
InitPackageResourcesParam.replace replace a resource init: ReplaceProxy.() -> Unit XC_InitPackageResources.InitPackageResourcesParam

Examples

  1. Hooking an activity’s onCreate method.
val activity = "xxx.xxx.xxx.MainActivity"
activity.hook {
    classLoader = lpparam.classLoader // Essential
    methodName = "onCreate" // Essential
    parameterTypes = Bundle::class.java // Non-Essential
    after {
        Log.e("Xposed KTX", "I'm successfully been hooked")
        val activity = it.thisObject as Activity
        Toast.makeText(activity, "You had been slain", Toast.LENGTH_LONG).show()
    }
    before {
        // If you don't need this method, you can omit it
    }
}

You can hook method using Class as well.

MainActivity::class.java.hook {
    methodName = "onCreate" // Essential
    parameterTypes = Bundle::class.java // Non-Essential
    after {
        Log.e("Xposed KTX", "I'm successfully been hooked")
        val activity = it.thisObject as Activity
        Toast.makeText(activity, "You had been slain", Toast.LENGTH_LONG).show()
    }
    before {
        // If you don't need this method, you can omit it
    }
}
  1. Hooking resources.
private var MODULE_PATH = ""
   
override fun initZygote(startupParam: IXposedHookZygoteInit.StartupParam?) {
    MODULE_PATH = startupParam!!.modulePath
}
   
override fun handleInitPackageResources(resparam: XC_InitPackageResources.InitPackageResourcesParam?) {
    "com.android.systemui".resHook {
        type = "layout"
        name = "activity_main"
        resp = resparam
        modRes = XModuleResources.createInstance(MODULE_PATH, resparam.res) // create module resource
        replace { type = "drawable"; name = "ic_chart"; replacement = modRes!!.fwd(R.drawable.ic_xp) } //replace a image resource
        layoutLoaded { // handleLayoutInflated
         val clock = it.findViewById("clock") as TextView
            clock.setTextColor(Color.RED);
        }
   }
}