Knight-ZXW / LancetX

🔥🔥饿了么开源的 字节码插桩框架 lancet的增强版本,修复了一些Bug,并基于ByteX提高编译速度。支持以下特性:1.插桩功能分组,独立开关配置 2.更多字节码修改能力
Apache License 2.0
285 stars 44 forks source link

hook 原生方法疑问 #28

Open 529523346 opened 1 month ago

529523346 commented 1 month ago

在hook textview的settext方法时发现有时候获取到的原text为null,不知道是啥原因,望大佬指点 @Proxy() @TargetClass(value = "android.widget.TextView", scope = Scope.ALL) @TargetMethod(methodName = "setText") public void aroundSetText(CharSequence text) { Logger.e("TextViewSetTextAspect:CharSequence=>TextView被hook=>" + "原字符串为:" + text); // 获取原始参数 String stringKey = text == null ? null : ResourceMapper.getNameForValue(text.toString()); // 修改参数 if (stringKey != null && !stringKey.equals("")) { String configValues = CacheUtil.INSTANCE.getAppConfig().getLanguage_package().get(stringKey); if (configValues != null && configValues.length() > 0) { Logger.e("TextViewSetTextAspect:CharSequence=>修改前的字符串=>" + text + ",Key=>" + stringKey + ",匹配到的字符串=>" + configValues); text = configValues; } else { Logger.e("TextViewSetTextAspect:CharSequence=>未匹配到value:" + "原字符串为=>" + text + ",Key为=>" + stringKey); } } else { Logger.e("TextViewSetTextAspect:CharSequence=>未匹配到key:" + "原字符串为=>" + text + ",Key为=>" + stringKey); } Origin.callVoid(); } 发现原字符串有还时候输出为空串,但是实际textview是有值的

529523346 commented 1 month ago
image