在虚拟引擎内 hook 微信防撤回

1. 导入 epic

dependencies {
  compile 'me.weishu:epic:0.3.6'
}

2. 传入获取的 application

RevokeMsgHook.startHook(mInitialApplication);         // 开始 HOOK 微信

3. 编写防撤回逻辑

public class RevokeMsgHook {
    private static boolean disableRevoke = true;
    private static Map<Long, Object> msgCacheMap = new HashMap<>();
    private static Object storageInsertClazz;

    public static void startHook(Application application) {
        final ClassLoader classLoader = application.getClassLoader();
        try {
            Class clazz = classLoader.loadClass("com.tencent.wcdb.database.SQLiteDatabase");
            DexposedBridge.findAndHookMethod(clazz, "updateWithOnConflict", String.class, ContentValues.class, String.class, String[].class, int.class,
                    new XC_MethodHook() {
                        @Override
                        protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                            if (param.args[0].equals("message")) {
                                ContentValues contentValues = ((ContentValues) param.args[1]);
                                //reload();

                                if (disableRevoke && contentValues.getAsInteger("type") == 10000 &&
                                        !contentValues.getAsString("content").equals("你撤回了一条消息")) {
                                    handleMessageRecall(contentValues);
                                    param.setResult(1);
                                }
                            }
                            super.beforeHookedMethod(param);
                        }
                    });
        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
            Class avClass = classLoader.loadClass("com.tencent.mm.storage.av");
            DexposedBridge.hookAllMethods(avClass, "b",
                    new XC_MethodHook() {
                        @Override
                        protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                            storageInsertClazz = param.thisObject;
                            Object msg = param.args[0];
                            long msgId = XposedHelpers.getLongField(msg, "field_msgId");
                            msgCacheMap.put(msgId, msg);
                            super.afterHookedMethod(param);
                        }
                    });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void handleMessageRecall(ContentValues contentValues) {
        long msgId = contentValues.getAsLong("msgId");
        Object msg = msgCacheMap.get(msgId);

        long createTime = XposedHelpers.getLongField(msg, "field_createTime");
        XposedHelpers.setIntField(msg, "field_type", contentValues.getAsInteger("type"));
        XposedHelpers.setObjectField(msg, "field_content", contentValues.getAsString("content") + "(已被阻止)");
        XposedHelpers.setLongField(msg, "field_createTime", createTime + 1L);
        try {
            av.b(storageInsertClazz, msg, false);    // 使用反射
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

    public static void b(Object so, Object au, Object bo) {
        try {
            Method dMethod = so.getClass().getDeclaredMethod("b", au.getClass(), boolean.class);
            if (dMethod != null) {
                dMethod.setAccessible(true);
                dMethod.invoke(so, au, bo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

4. 逻辑分析

先 hook 掉 av.b 方法,保存接收到的 msg,在更改信息,保存到数据库,修改传入函数的参数

最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 137,256评论 19赞 139
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 47,399评论 6赞 342
  • 用到的组件 1、通过CocoaPods安装 2、第三方类库安装 3、第三方服务 友盟社会化分享组件 友盟用户反馈 ...
    SunnyLeong阅读 15,399评论 1赞 180
  • 自军训以来,我便感受到丝丝恶意,弥漫在空气中,若有若无,时隐时现,我努力想通过众人的目光寻找一丝丝线索,线索却总在...
    KwanChauYee_阅读 639评论 0赞 0
  • 很早就想为他-我的外公,写点什么,却迟迟不敢下笔。因为往往在刚开始想念他的那一刻,心便开始痛,很痛,泪水就已...
    采薇Cherry阅读 539评论 0赞 0

友情链接更多精彩内容