最近翻着网页上的例子很多都是拿微信来作为例子,于是我也入乡随俗,来学习学习

先给个将要做的事情的截图 对列表的长按事件进行响应

b0c86eb2dfa58e73b9f9160532a597fd.png

列表的长按事件

首先打开cmd 输入 adb shell dumpsys activity top

你会得看到当前界面布局层级,然后往下翻着看 你会发现一个很熟悉的东西

551181f56715ad8e277d3d45e82316be.png

于是有了目标了 开始编码

/**

* 观察聊天界面的时候发现了 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 implements b

定位过去

public interface b {

void a(int i, m mVar, Object obj);

}

89d41b90016499f12e4c466689fde09a.png

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

3c14609202cfcb7a9c016ea44b789c22.png

通过 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 需要用反射拿到类型

最后于 2019-2-2 10:37

被admin编辑

,原因: 图片本地化

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐