Xposed移植点
一、背景
前段时间,对xposed感兴趣,想移植一下xposed到本地代码。移植成功后,做了以下对照。该移植在于art虚拟机的移植。下面就分别介绍移植点
二、移植位置
红色的是新增加的代码。可以用compare软件,来进行移植工作,比较方便
1、art\runtime\base\logging.h
增加log属性
2、 art\runtime\base\logging.c
实现一个xposed的log
3、art\runtime\entrypoints\entrypoint_utils.h
art\runtime\entrypoints\entrypoint_utils.cc
操作hook后的方法
上面的方法,详细的解释了,如果是xposed hook的方法被检测到时,如何去调用的过程。
4、art\runtime\art_method.h
art\runtime\art_method.cc
art\runtime\art_method-in.h
增加一个用于hook的结构体
这个结构体是xposed能进行hook的一个关键
判断方法时,增加xposed方法的判断
Quick入口设置时,还有一定的要求
增加一些与xposed相关的数据结构调用方法及字段
下面StackReplaceMethod的方法,用于更换
这一段代码在ArtMethod.cc中,是进行方法替换的核心逻辑。
Xposed就是改造了art的artmethod这一类,该类其实就是art虚拟机在运行时的方法对象。
最后生成hook_info 通过SetEntryPointFromJni 来设置到对方法区。需要用的时候再通过soa.DecodeMethod(method)->GetXposedHookInfo();来获取,进而调用。
5、art\runtime\class_linker.cc
因为method->IsProxyMethod(true)变了,导致的改变。
6、art\runtime\debugger.cc
7、art\runtime\instrumentation.cc
8、art\runtime\jni_internal.cc
9、art\runtime\modifiers.h
增加xposed的constant变量
10、art\runtime\oat.h
art\runtime\oat.cc
一些xposed版本的信息,其实这里可以不要,然后下下面oat_file_assist中检查的时候忽略。
11、art\runtime\oat_file_assistant.cc
11、art\runtime\reflection.cc
art\runtime\runtime.h
art\runtime\thread.cc
art\runtime\utils.cc
没有太多难懂的方法
12、art\runtime\stack.h
增加一个方法设置
三、总结
Xposed 在art虚拟机的源代码的runtime中做了一些修改。给artmethod增加了一个功能。最后实现了hook功能。
文笔不好,请见谅。