Xposed 替换Textview文案
这篇主要写下替换Textview的文案,主要实现比如脱敏。
``
public class TextViewHook {
private static final String TAG = "TextViewHook";
public static void hook(XC_LoadPackage.LoadPackageParam lpparam) {
Log.i(TAG, "hook: start");
try {
final Class clazz = XposedHelpers.findClass("android.widget.TextView", lpparam.classLoader);
XposedHelpers.findAndHookMethod(clazz, "setText", CharSequence.class, TextView.BufferType.class, new XC_MethodReplacement() {
@Override
protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
Object[] args = param.args;
CharSequence arg = (CharSequence) args[0];
TextView.BufferType arg1 = (TextView.BufferType) args[1];
Log.e(TAG, "replaceHookedMethod: arg=" + arg + ";arg1=" + arg1);
// TODO: 23-9-28 替换textview的文本,
if (!TextUtils.isEmpty(arg)){
args[0] = "替换成功";
}
return XposedBridge.invokeOriginalMethod(param.method,param.thisObject,args);
}
});
} catch (Throwable e) {
Log.e(TAG, "hook: ", e);
}
Log.i(TAG, "hook: end");
}
}
如上述代码,只要textview中设置的文本不为空,我们就将其替换成"替换成功".
我测试时主要用的微信测试,可以看下效果:
1:微信小程序入口,文本全部被替换成了替换成功。
2: