Giter Site home page Giter Site logo

jaop's Introduction

jaop

jaop 是一个基于javassist和asm的gradle aop插件,可以在特定的方法调用处或方法体内 编程
javassist做简单的代码插入,asm做操作数栈分析和字节码的转录
不会新增任何方法,秒杀aspectj
兼容性更好
不支持instant run

配置

repositories {
  jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:1.5.0' // 需要1.5的plugin
    classpath 'jaop.gradle.plugin:gradle-plugin:1.0.3'
}

apply plugin: 'jaop'

用法

@Jaop  //配置文件的开关
public class JaopDemo {
    @After("demo.jaop.sample.MainActivity.onCreate")  // hook 掉onCreate 方法的方法体
    public void replace1(MethodBodyHook hook) {
        Button button = (Button) ((Activity) hook.getTarget()).findViewById(R.id.button);
        button.setText("text replace by jaop");
    }

    @Replace("android.widget.Toast.makeText") // hook Toast makeText 方法的调用处, 替换toast的文本
    public void replace2(MethodCallHook hook) {
        Object[] args = hook.getArgs();
        hook.setResult(Toast.makeText((Context)args[0], "hook toast", Toast.LENGTH_LONG)); // 设置返回值
    }
}

详情请看sample

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.