定位hook点
调研了常用的加水印方式,使用frida工具定位关键API:
- Bitmap.compress - 用于保存图片到磁盘
- Canvas.drawText - 添加文字水印
- Canvas.drawBitmap - 添加图像水印
Frida脚本实现
去除文字水印
通过hook Canvas.drawText方法,检测并替换包含"小红书"或"xhs"的文字内容为空字符串:
Canvas.drawText.overload("java.lang.String", "float", "float", "android.graphics.Paint").implementation = function(text, x, y, paint) {
if (text.toLowerCase().includes("小红书") || text.toLowerCase().includes("xhs")) {
return this.drawText('', x, y, paint);
}
}
去除图片logo水印
定位到drawBitmap的重载方法,通过检测Bitmap尺寸判断是否为水印:
Canvas.drawBitmap.overload("android.graphics.Bitmap", "android.graphics.Rect", "android.graphics.Rect", "android.graphics.Paint").implementation = function(bitmap, src, dst, paint) {
if (bitmap.getWidth() < 400 && bitmap.getHeight() < 150) {
// 替换为透明Bitmap
var transparent = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
return this.drawBitmap(transparent, src, dst, paint);
}
}
Xposed模块实现
将Frida脚本转换为Xposed模块,实现持久化去水印功能:
文字水印处理
private void hookCanvasDrawText() {
for (Method method : Canvas.class.getDeclaredMethods()) {
if (method.getName().equals("drawText") && method.getParameterTypes().length == 4) {
XposedBridge.hookMethod(method, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) {
String text = (String) param.args[0];
if (text != null && (text.toLowerCase().contains("小红书") || text.toLowerCase().contains("xhs"))) {
param.args[0] = "";
}
}
});
}
}
}
图片水印处理
private void hookCanvasDrawBitmap() {
for (Method method : Canvas.class.getDeclaredMethods()) {
if (method.getName().equals("drawBitmap") && method.getParameterTypes().length == 4) {
XposedBridge.hookMethod(method, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) {
Bitmap bmp = (Bitmap) param.args[0];
if (bmp.getWidth() < 400 && bmp.getHeight() < 150) {
Bitmap transparent = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), Bitmap.Config.ARGB_8888);
param.args[0] = transparent;
}
}
});
}
}
}
完整代码和模块下载地址: https://github.com/SimpsonGet/XhsWatermarkRemove
免责声明
1.一般免责声明:本文所提供的技术信息仅供参考,不构成任何专业建议。读者应根据自身情况谨慎使用且应遵守《中华人民共和国网络安全法》,作者及发布平台不对因使用本文信息而导致的任何直接或间接责任或损失负责。
2. 适用性声明:文中技术内容可能不适用于所有情况或系统,在实际应用前请充分测试和评估。若因使用不当造成的任何问题,相关方不承担责任。
3. 更新声明:技术发展迅速,文章内容可能存在滞后性。读者需自行判断信息的时效性,因依据过时内容产生的后果,作者及发布平台不承担责任。
本文为 独立观点,未经授权禁止转载。
如需授权、对文章有疑问或需删除稿件,请联系 FreeBuf
客服小蜜蜂(微信:freebee1024)