首页
社区
课程
招聘
[原创]Xposed第一课(微信篇) hook含有多个参数的方法
发表于: 2018-4-24 01:35 14140

[原创]Xposed第一课(微信篇) hook含有多个参数的方法

2018-4-24 01:35
14140

最近翻着网页上的例子很多都是拿微信来作为例子,于是我也入乡随俗,来学习学习
先给个将要做的事情的截图 对列表的长按事件进行响应

列表的长按事件

 

首先打开cmd 输入 adb shell dumpsys activity top
你会得看到当前界面布局层级,然后往下翻着看 你会发现一个很熟悉的东西

 

于是有了目标了 开始编码

/**
     * 观察聊天界面的时候发现了 ConversationWithAppBrandListView 组建
     * 得到了 item data为com.tencent.mm.storage.ae
     * adapter address-> com.tencent.mm.ui.conversation.g
     * @param applicationContext
     * @param classLoader
     */
    private void hookConversationWithAppBrandListView(final Context applicationContext, final ClassLoader classLoader) {
        XposedBridge.log("Demo: hookListView");
        XposedHelpers.findAndHookMethod("com.tencent.mm.ui.conversation.ConversationWithAppBrandListView",
                classLoader,
                "setAdapter",
                ListAdapter.class,
                new XC_MethodHook() {
                    @Override
                    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                        super.beforeHookedMethod(param);
                        ListAdapter adapter = (ListAdapter) param.args[0];
                        XposedBridge.log("Demo: hookListView adapter address-> " + adapter.toString());
                        Log.e("Demo: hookListView", " adapter address-> " + adapter.toString());
                        int count = adapter.getCount();
                        Log.e("Demo: hookListView->", "ConversationWithAppBrandListView has " + count + " child");
                        for (int i = 0; i < count; i++) {
                            Object s = adapter.getItem(i);
                            Log.e("Demo: hookListView->", "item data -> " + JSONObject.toJSONString(s));
                        }
                    }
                });
    }

以上log日志你可以看到列表的数据 和 adapter所在的位置com.tencent.mm.ui.conversation.g 这个是关键点

 

定位到 com.tencent.mm.ui.conversation.g 发现它还有一个实现类

public final class g extends f<String, ae> implements b

定位过去

public interface b {
        void a(int i, m mVar, Object obj);
    }

 

看到没有关联字样 Conversation 我猜想他们之间是有关联的 直接搜索关键字onItemLongClick

 

 

通过 BizChatConversationUI$a$17 关联到了 com.tencent.mm.ui.widget.i 类下的

public final void a(View view, int i, long j, OnCreateContextMenuListener onCreateContextMenuListener, p$d p_d, int i2, int i3) {
        this.snI = p_d;
        this.zew = view;
        cAT();
        this.snJ.clear();
        ContextMenuInfo adapterContextMenuInfo = new AdapterContextMenuInfo(view, i, j);
        onCreateContextMenuListener.onCreateContextMenu(this.snJ, view, adapterContextMenuInfo);
        for (MenuItem menuItem : this.snJ.yAS) {
            ((o) menuItem).yAV = adapterContextMenuInfo;
        }
        if (i2 == 0 && i3 == 0) {
            bS(0, 0);
        } else {
            bS(i2, i3);
        }
    }

抱着试试的心态 写了下面的代码

/**
     * 微信列表界面长按点击事件
     * 引用地址 com.tencent.mm.ui.bizchat.BizChatConversationUI$a$17
     *
     * @param applicationContext
     * @param classLoader
     */
    private void hookWxItemLongClick(final Context applicationContext, ClassLoader classLoader) {
        Class<?> classIfExists = XposedHelpers.findClassIfExists("com.tencent.mm.ui.base.p$d", classLoader);
        if (classIfExists == null) return;
        XposedHelpers.findAndHookMethod("com.tencent.mm.ui.widget.i",
                classLoader,
                "a",
                View.class,
                int.class,
                long.class,
                View.OnCreateContextMenuListener.class,
                classIfExists,
                int.class,
                int.class,
                new XC_MethodHook() {
                    @Override
                    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                        super.beforeHookedMethod(param);

                        Log.e("Demo: hookWxItemLongClick->", param.args[1].toString() + "-" + param.args[5].toString() + "-" + param.args[6].toString());
                    }
                });
    }

功夫不负有心人,

04-23 12:35:45.287 9142-9142/com.tencent.mm E/Demo: hookWxItemLongClick->: 16-332-611

看到了这个log


 

其中在对com.tencent.mm.ui.widget.i进行hook的时候遇到了一些小问题,就是我标题所述的参数问题

 

第一是数据类型:
应为在做安卓应用层的时候 int.class 这样的写法是不被允许的 一般都是使用他们的包装类型Integer.class 所以我直接参数类型写的Integer.class 会导致hook找不到对应的方法 需要更换为 int.class 做到与目标方法参数对应才行 Long类型也是同理

 

第二是内部方法:
在对com.tencent.mm.ui.widget.i进行hook的时候有个内部方法com.tencent.mm.ui.base.p$d 需要用反射拿到类型

 

希望能帮助遇到同样情况的小伙伴
Xposed第二课(微信篇) 聊天界面修改文字


[培训]《安卓高级研修班(网课)》月薪三万计划,掌握调试、分析还原ollvm、vmp的方法,定制art虚拟机自动化脱壳的方法

最后于 2019-2-2 10:37 被admin编辑 ,原因: 图片本地化
收藏
免费 1
支持
分享
最新回复 (11)
雪    币: 144
活跃值: (335)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
谢谢分享
2018-4-24 09:17
0
雪    币: 392
活跃值: (205)
能力值: ( LV4,RANK:40 )
在线值:
发帖
回帖
粉丝
3
人在塔在 谢谢分享
感谢,一起学习
2018-4-24 18:07
0
雪    币: 1366
活跃值: (5584)
能力值: ( LV3,RANK:25 )
在线值:
发帖
回帖
粉丝
4
支持。
2018-4-25 10:35
0
雪    币: 392
活跃值: (205)
能力值: ( LV4,RANK:40 )
在线值:
发帖
回帖
粉丝
5
supperlitt 支持。
谢谢谢谢  一起学习
2018-4-25 11:31
0
雪    币: 4
活跃值: (11)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
谢谢分享
2018-4-25 23:56
0
雪    币: 2694
活跃值: (80)
能力值: ( LV2,RANK:15 )
在线值:
发帖
回帖
粉丝
7
学习了
2018-4-26 00:02
0
雪    币: 4
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
8
好东西啊
2018-5-7 15:13
0
雪    币: 2689
活跃值: (1581)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
9
谢谢分享
2018-5-14 10:07
0
雪    币: 1
活跃值: (16)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
10
请问下 楼主大大用的是什么工具看的源代码呀?
2018-9-19 09:34
0
雪    币: 214
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
11
看雪老会员,隔好多年回来重新学习
2019-4-17 08:54
0
游客
登录 | 注册 方可回帖
返回
//