Android Hot patch 技术:Dexposed-来自阿里手机淘宝部门的开源项目
来源:互联网 发布:应用最广的编程语言 编辑:程序博客网 时间:2024/04/29 00:42
开源代码地址:https://github.com/alibaba/dexposed
应用方面:
1. 用于测试、性能监控:Instrumentation (for testing, performance monitoring and etc.)
2. 用于在线热补丁,应急突发事件:Online hot patch to fix critical, emergent or security bugs
3. 用于SDK hooking
What is Dexposed ?Dexposed is a powerful yet non-invasive runtime AOP (Aspect-oriented Programming) framework for Android app development, based on the work of open-source Xposed framework project.
The AOP of Dexposed is implemented purely non-invasive, without any annotation processor, weaver or bytecode rewriter. The integration is as simple as loading a small JNI library in just one line of code at the initialization phase of your app.
Not only the code of your app, but also the code of Android framework that running in your app process can be hooked. This feature is extremely useful in Android development as we developers heavily rely on the fragmented old versions of Android platform (SDK).
Together with dynamic class loading, a small piece of compiled Java AOP code can be loaded into the running app, effectively altering the behavior of the target app without restart.
Typical use-cases
- Classic AOP programming
- Instrumentation (for testing, performance monitoring and etc.)
- Online hot patch to fix critical, emergent or security bugs
- SDK hooking for a better development experience
Integration
Directly add dexposed aar to your project as compile libraries, it contains a jar file "dexposedbridge.jar" two so files "libdexposed.so libdexposed_l.so" from 'dexposed' directory.
Gradle dependency like following:
dependencies { compile 'com.taobao.android:dexposed:0.1.1@aar' }
Insert the following line into the initialization phase of your app, as early as possible:
public class MyApplication extends Application { @Override public void onCreate() { // Check whether current device is supported (also initialize Dexposed framework if not yet) if (DexposedBridge.canDexposed(this)) { // Use Dexposed to kick off AOP stuffs. ... } } ... }
It's done.
Basic usage
There are three injection points for a given method: before, after, replace.
Example 1: Attach a piece of code before and after all occurrences of Activity.onCreate(Bundle)
.
// Target class, method with parameter types, followed by the hook callback (XC_MethodHook). DexposedBridge.findAndHookMethod(Activity.class, "onCreate", Bundle.class, new XC_MethodHook() { // To be invoked before Activity.onCreate(). @Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable { // "thisObject" keeps the reference to the instance of target class. Activity instance = (Activity) param.thisObject; // The array args include all the parameters. Bundle bundle = (Bundle) param.args[0]; Intent intent = new Intent(); // XposedHelpers provide useful utility methods. XposedHelpers.setObjectField(param.thisObject, "mIntent", intent); // Calling setResult() will bypass the original method body use the result as method return value directly. if (bundle.containsKey("return")) param.setResult(null); } // To be invoked after Activity.onCreate() @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { XposedHelpers.callMethod(param.thisObject, "sampleMethod", 2); } });
Example 2: Replace the original body of the target method.
DexposedBridge.findAndHookMethod(Activity.class, "onCreate", Bundle.class, new XC_MethodReplacement() { @Override protected Object replaceHookedMethod(MethodHookParam param) throws Throwable { // Re-writing the method logic outside the original method context is a bit tricky but still viable. ... } });
Checkout the example
project to find out more.
Support
Dexposed support all dalvik runtime arm architecture devices from Android 2.3 to 4.4 (no include 3.0). The stability has been proved in our long term product practice.
Follow is support status.
Contribute
We are open to constructive contributions from the community, especially pull request and quality bug report. Currently, the support for new Android Runtime (ART) is still in early beta stage, we value your help to test or improve the implementation.
Dexposed is aimed to be lightweight, transparent and productive. All improvements with these principal in mind are welcome. At the same time, we are actively exploring more potentially valuable use-cases and building powerful tools based upon Dexposed. We're interested in any ideas expanding the use-cases and grateful for community developed tools on top of Dexposed.
- Android Hot patch 技术:Dexposed-来自阿里手机淘宝部门的开源项目
- Android Hot patch 技术:Dexposed-来自阿里手机淘宝部门的开源项目
- Android热补丁技术—dexposed原理简析(手机淘宝采用方案)
- Android热补丁技术—dexposed原理简析(阿里Hao)
- Android开发之阿里百川OneSDK与手机淘宝技术简介
- 阿里无线11.11:手机淘宝 521 性能优化项目揭秘
- Android,来自google的手机平台
- 技术部门项目管理的几点感想
- 来自Apache的Java开源项目
- 简单集成Dexposed开源框架
- 来自淘宝的架构经验
- 淘宝开源项目TbSchedule的使用
- Android热补丁技术,ClassLoader、dexposed、Andfix、smart app updates补丁技术收集整理
- 阿里开源项目
- 认识Android手机--来自MIUI
- iOS hot-patch框架 -- Rollout
- Amoeba -阿里的开源项目
- weex接收来自Android手机的Broadcast广播消息
- dwr的转换器
- const 应用总结
- latex 字体大小设置
- Android编程规范与常用技巧
- zabbix fping报错
- Android Hot patch 技术:Dexposed-来自阿里手机淘宝部门的开源项目
- 坑你没商量之c#微信回调中核实订单的签名验证
- Java日期循环,Java获取当月的第一天和最后一天
- SVN服务器端安装、配置与管理
- IOS - Lable基础用法
- JavaScript整理知识点一 (网络整理)
- 《海马记忆训练》
- Nutch搜索引擎__Nutch简介及安装
- win7 mysql 集群搭建,自测ok