FrameworkInjector
是一个Java的AOP框架。它通过json文件配置AOP切点信息,使用Javassist
对Jar包进行插桩实现AOP。
最初,FrameworkInjector
被设计用于对Android framework进行AOP插桩,这是其命名的渊源。
- JSON文件管理AOP插桩切点配置
- 对指定方法进行插桩
- 支持通配符匹配类和方法
- [BUG][TODO] 目前暂时跳过了接口类,对接口类(interface)不执行插桩
source build.sh
执行build.sh
即可编译得到frameworkinjector.jar
,它通过javac
编译,jar
打包。
本工具通过java执行编译得到的jar包,其中需要传递参数:
--pointcuts_json
设置切点配置文件json的路径-i
输入的被插桩的jar包-o
输出的被插桩后的jar包-cplist
Class Path List。作为额外的类加载路径提供给Javassist。当被插桩的类依赖了其他jar包且该jar包不在ClassLoader的默认搜索路径时,通过该参数告知Javassist以使其能够找到并加载类。多个路径使用冒号分隔(详见对应平台的JDK标准)
source build_and_run_sample.sh
build_and_run_sample.sh
集成了一些步骤,它能完成一次编译打包,并运行一个内置的样本。该样本是对本工程编译出来的jar包进行插桩,即自己对自己进行插桩。
对foo.jar进行插桩:
java -jar frameworkinjector.jar -cplist "libs" -pointcuts_json myPointcuts.json -i foo.jar -o injected_foo.jar
当出现Class NotFound时,尝试加入对应类的jar包的路径:
java -Xbootclasspath/a:/path/myPath:<other> <...other cmd parts...>
- Run
build_and_run_sample.sh
, which will perform code weaving configed by sample.json - A new jar that is injected will be produced from step 1. It containes codes injected by this program. In the case of the sample, a new
System.out.println
call is injected which shown as below.
Copyright (C) <2022>
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.