GithubHelp home page GithubHelp logo

reinjectplugin's Introduction

ReInjectPlugin

ReInjectPlugin is an android build plugin. It uses ASM to modify classes without write duplicate code in many places. Inspired by xposed, the user just define original class and method, and write inject class and method, then the code will be injected to apk.

Sample

use plugin

ReInjectPlugin is already published to mavenCenter, please add mavenCenter in your mvn config update root project's build.gradle

buildscript {
    dependencies {
        classpath 'io.github.nylon009:reinject-plugin:0.0.1'
    }
}

update app/build.gradle

plugins {
    id 'io.github.nylon009.reinject-plugin'
}

Config file

add ReInject.json file in the app project path: Please note the method for static and non static method are different in InjectUtil.java, for non static method, the inject function should use the origin class as the first parameter.

{
  "injects": [
    {
      "className": "com.nylon.app.Utils",
      "methodName": "foobar",
      "methodSignature": "(Ljava/lang/String;)V",
      "injectClassName": "com.nylon.app.InjectUtils",
      "injectEnterMethodName": "foobarEnter",
      "injectExitMethodName": "foobarExit"
    },
    {
      "className": "com.nylon.app.Utils",
      "methodName": "hello",
      "methodSignature": "(Ljava/lang/String;)V",
      "injectClassName": "com.nylon.app.InjectUtils",
      "injectEnterMethodName": "helloEnter",
      "injectExitMethodName": "helloExit"
    }
  ]
}

Inject for static method

original code: com.nylon.app.Utils

public static void foobar(String test) {
    Log.d(TAG, "foobar");
}

after injected:

public static void foobar(String test) {
    InjectUtils.foobarEnter(test); // this is injected by asm
    Log.d(TAG, "foobar");
    InjectUtils.foobarExit(test);  // this is injected by asm
}

Inject for none-static method

origin

public void hello(String msg) {
    Log.d(TAG, "hello " + msg);
}

after injected

public void hello(String msg) {
    InjectUtils.helloEnter(this, msg);
    Log.d(TAG, "hello " + msg);
    InjectUtils.helloExit(this, msg);
}

How to build your own

Update the Plugin module, change to snapshot version, and publish plugin to local repo directory

 ./gradlew :Plugin:assemble :Plugin:publishAllPublicationsToMyRepoRepository

this project already add local repo directory as maven center, so no need to change it. update the app/build.gradle to use snapshot version.

Reference

reinjectplugin's People

Contributors

nylon009 avatar

Watchers

 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.