<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Dexposed非侵入式運(yùn)行期 AOP 框架

          聯(lián)合創(chuàng)作 · 2023-09-25 03:51

          Dexposed 是阿里巴巴無線事業(yè)部第一個(gè)重量級(jí) Andorid 開源軟件,基于 ROOT 社區(qū)著名開源項(xiàng)目 Xposed 改造剝離了 ROOT 部分,演化為服務(wù)于所在應(yīng)用自身的 AOP 框架。它支撐了阿里大部分 App 的在線分鐘級(jí)客戶端 bugfix 和線上調(diào)試能力。

          Dexposed 的 AOP 是實(shí)現(xiàn)了純非侵入式,沒有任何注釋處理器,weaver 或者字節(jié)碼重寫程序。Dexposed 的集成非常簡單,就像加載一個(gè) JNI 庫一樣,只需要在初始化的時(shí)候插入一行代碼。

          經(jīng)典用例

          • 典型的 AOP 編程

          • 儀表化 (測試,性能監(jiān)控等等)

          • 在線熱修復(fù)(重要,關(guān)鍵,安全漏洞等等)

          • SDK hooking,更好的開發(fā)體驗(yàn)

          Gradle 依賴:

          native_dependencies {
              artifact 'com.taobao.dexposed:dexposed_l:0.2+:armeabi'
              artifact 'com.taobao.dexposed:dexposed:0.2+:armeabi'
          }
          dependencies {
              compile files('libs/dexposedbridge.jar')
          }

          初始化:

          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.
                      ...
                  }
              }
              ...
          }

          基礎(chǔ)使用示例代碼1:

           // 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);
                  }
              });

          基礎(chǔ)使用示例代碼2:

              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.
                      ...
                  }
          
              });
          瀏覽 18
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  亚洲视频在线播放 | 日本有码第1页 | 国产黄色电影网 | 日本一 级 黄 色 片免费 | 特级西西444www大胆高清图片 |