Giter Club home page Giter Club logo

kxposedhelper's Introduction

KXposedHelper

🔥XposedHlper for Kotlin, provide some awesome utilities for your xposed module development.

GitHub release (latest SemVer)

Setup

Step 1. Add the JitPack repository to your build file Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
      ...
      maven { url 'https://jitpack.io' }
    }
}

Step 2. Add the dependency

dependencies {
    implementation 'com.github.ikws4:KXposedHelper:1.2'
}

Catalogue

  1. How to hook method?
    1. Simple to use
    2. Before and after hook
    3. Replece method
    4. Change return value
    5. Some utilities in hook
  2. How to use KXSharedPreferences?
  3. How to use KXBroadcastReceiver?

How to hook method?

Simple to use
KXposedHelpers.findAndHookMethod(Activity::class, "onCreate", parameterTypes = arrayOf(Bundle::class), methodHook = MethodHook{param->
    // `this` for the Activity instance
    // So you can write code just like in your regular way on Activity
    // For exmaple
    Toast.makeText(this,"onStart",Toast.LENGTH_SHORT).show()
})

Before and after hook

KXposedHelpers.findAndHookMethod(Activity::class, "onStart", methodHook = MethodHook(
    beforeHookedMethod = { param->
    },
    afterHookedMethod = { param->
    })
)

Replece method

KXposedHelpers.findAndHookMethod(Activity::class, "onStart", methodHook = MethodReplecement{param->
})

Change return value

KXposedHelpers.findAndHookMethod(TextView::class, "getText", methodHook = MethodHook{param->
    param.result = "Changed result value"
})

Some utilities in hook

// ActivityHookHelper for Activity lifecycle hook
ActivityHookHelper.onCreate {  }
ActivityHookHelper.onDestroy {  }
...

// ApplicationHookHelper
ApplicationHookHelper.onCreate {  }
ApplicationHookHelper.attach {  }

How to use KXSharedPreferences?

In high Android version, because the security permission, and the XSharedPreferences not working very well, so I created the utility for SharedPreferences called KXSharedPreferences, it's use the ContentProvider to shared preferences across the applications.

Step 1. Add the provider to your AndroidManifest.xml

<provider
    android:authorities="io.ikws4.kxposedhelper.utilities.KXSharedPreferencesProvider"
    android:name="io.ikws4.kxposedhelper.utilities.KXSharedPreferencesProvider"
    android:exported="true"/>

Step 2. Use the KXSharedPreferences object to get SharedPreferences value.

val sp = KXSharedPreferences(contentResolver,"your SharedPreferences name")
sp.getString("key","defValue")

How to use KXBroadcastReceiver?

Sometimes you need to receive some broadcasts from your app, so this can help you easily to receiver broadcasts.

val broadReceiver = KXBroadcastReceiver(
    IntentFilter().apply {
        addAction("Action1")
        addAction("Action2")
    })

broadReceiver.setOnReceiveListener { context, intent ->
    when (intent.action) {
        "Action1" -> {
        }
        "Action2" -> {
        }
    }
}

ActivityHookHelper.onCreate {
    broadReceiver.register(this)
}

ActivityHookHelper.onDestroy {
    broadReceiver.unRegister(this)
}

LICENSE

MIT License

Copyright (c) 2020 zhiping

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

kxposedhelper's People

Contributors

ikws4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.