前面做了个小玩意,朋友圈点赞,缺点是只能在当前界面临时显示,并且不能选择好友,返回后在进去就没有了,今天准备将联系人与朋友圈点赞功能关联起来。
首先分析布局结构
根据关键名称进行查找
BizContactEntranceView | AlphabetScrollBar |
---|---|
定位到了com.tencent.mm.ui.contact.AddressUI
有人想,你光找到这个有个软用,数据库你不找到怎么去保存到你自己的app里面。 大家接着往下看,可能我代码有自己的想法,皮一下很开心O(∩_∩)O
先上代码
@Override
public void hookContact() {
XposedHelpers.findAndHookMethod("com.tencent.mm.ui.contact.AddressUI.a",
mClassLoader,
"coR",
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
Field oiy = XposedHelpers.findField(param.thisObject.getClass(), "oiy");
oiy.setAccessible(true);
LogUtils.i(oiy);
ListView oiyLv = (ListView) oiy.get(param.thisObject);
Class<?> mlvSuperClass = oiyLv.getClass().getSuperclass();
LogUtils.i(oiyLv);
XposedHelpers.findAndHookMethod(mlvSuperClass,
"setAdapter",
ListAdapter.class,
new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
final ListAdapter adapter = (ListAdapter) param.args[0];
LogUtils.i(adapter.toString());
XposedHelpers.findAndHookMethod(adapter.getClass(),
"getView",
int.class,
View.class,
ViewGroup.class,
new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
int position = (int) param.args[0];
final View view = (View) param.args[1];
final ViewGroup viewGroup = (ViewGroup) param.args[2];
LogUtils.i(position, view, viewGroup, JSON.toJSONString(adapter.getItem(position)), adapter.getItem(position).toString());
}
});
}
});
}
});
}
可以得到以下信息
05-30 08:20:00.685 3223-3223/com.tencent.mm I/ContactImpl:
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ main, com.zed.xposed.demo.action.inter.impl.ContactImpl$1.afterHookedMethod(ContactImpl.java:39)
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ private android.widget.ListView com.tencent.mm.ui.contact.AddressUI$a.oiy
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ main, com.zed.xposed.demo.action.inter.impl.ContactImpl$1.afterHookedMethod(ContactImpl.java:42)
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ android.widget.ListView{10d02036 V.ED..CL ......ID 0,0-768,930 #7f10016e app:id/j8}
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────
05-30 08:20:01.066 3223-3223/com.tencent.mm I/ContactImpl:
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ main, com.zed.xposed.demo.action.inter.impl.ContactImpl$1$1.beforeHookedMethod(ContactImpl.java:51)
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ com.tencent.mm.ui.contact.a@2e2454f8
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────
05-30 08:20:01.102 3223-3223/com.tencent.mm I/ContactImpl:
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ main, com.zed.xposed.demo.action.inter.impl.ContactImpl$1$1$1.beforeHookedMethod(ContactImpl.java:64)
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ args[0] = 0
│ args[1] = null
│ args[2] = android.widget.ListView{10d02036 VFED..CL ......ID 0,0-768,930 #7f10016e app:id/j8}
│ args[3] = {"fNU":49,"field_conRemark":"","field_deleteFlag":0,"field_descWordingId":"","field_nickname":"Aa 黄盖","field_openImAppid":"","field_remarkDesc":"","field_showHead":65,"field_signature":"","field_username":"此处不显示","field_verifyFlag":0,"field_weiboFlag":0,"key":"此处不显示"}
│ args[4] = com.tencent.mm.storage.f@1ac21e2a
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────
05-30 08:20:01.114 3223-3223/com.tencent.mm I/ContactImpl:
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ main, com.zed.xposed.demo.action.inter.impl.ContactImpl$1$1$1.beforeHookedMethod(ContactImpl.java:64)
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ args[0] = 1
│ args[1] = null
│ args[2] = android.widget.ListView{10d02036 VFED..CL ......ID 0,0-768,930 #7f10016e app:id/j8}
│ args[3] = {"fNU":66,"field_conRemark":"","field_deleteFlag":0,"field_descWordingId":"","field_nickname":"aLOL-代练-小客服","field_openImAppid":"","field_remarkDesc":"","field_showHead":65,"field_signature":"想要LOL代练可以私聊","field_username":"此处不显示","field_verifyFlag":0,"field_weiboFlag":0,"key":"此处不显示"}
│ args[4] = com.tencent.mm.storage.f@e76f385
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────
这是部分数据,我接下来要做的就是要一次性加载全部数据保存到自己的app 我们把上面的代码少位改造下
/**
* 直接取得联系人列表数据
*/
@Override
public void hookContact() {
XposedHelpers.findAndHookMethod("com.tencent.mm.ui.contact.AddressUI.a",
mClassLoader,
"coR",
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
Field oiy = XposedHelpers.findField(param.thisObject.getClass(), "oiy");
oiy.setAccessible(true);
LogUtils.i(oiy);
ListView oiyLv = (ListView) oiy.get(param.thisObject);
Class<?> mlvSuperClass = oiyLv.getClass().getSuperclass();
LogUtils.i(oiyLv);
XposedHelpers.findAndHookMethod(mlvSuperClass,
"setAdapter",
ListAdapter.class,
new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
final ListAdapter adapter = (ListAdapter) param.args[0];
LogUtils.i(adapter.toString());
int count = adapter.getCount();
for (int i = 0; i < count; i++) {
WxContact contact = JSON.parseObject(JSON.toJSONString(adapter.getItem(i)), WxContact.class);
WxContact ct = WxContactDB.queryByUsername(mContext, contact.getField_username());
//先判断是否已经存在了 在进行保存
if (ct == null) {
LogUtils.i(JSON.toJSONString(contact));
WxContactDB.insertData(mContext, contact);
}
}
}
});
}
});
}
然后与朋友长按事件关联 弹出一个联系人列表 进行选择
改造后的代碼如下
/**
* hook 朋友圈
*/
@Override
public void hookWxMoments() {
XposedHelpers.findAndHookMethod("com.tencent.mm.plugin.sns.ui.bb",
mClassLoader,
"onCreate",
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
Field mat = XposedHelpers.findFieldIfExists(param.thisObject.getClass(), "mActivity");
final Activity mActivity = (Activity) mat.get(param.thisObject);
Field odm = XposedHelpers.findFieldIfExists(param.thisObject.getClass(), "odm");
ListView mlv = (ListView) odm.get(param.thisObject);
Class<?> mlvSuperClass = mlv.getClass().getSuperclass();
XposedHelpers.findAndHookMethod(mlvSuperClass,
"setAdapter",
ListAdapter.class,
new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
final ListAdapter adapter = (ListAdapter) param.args[0];
XposedHelpers.findAndHookMethod(adapter.getClass(),
"getView",
int.class,
View.class,
ViewGroup.class,
new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
final View view = (View) param.args[1];
if (view != null) {
//fl 第一个view是图片 第二个view是朋友圈内容
final ViewGroup fl = (ViewGroup) view;
view.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
final List<WxContact> wxContacts = WxContactDB.queryAll(mContext);
LogUtils.i(JSON.toJSONString(wxContacts));
Dialog show = WxMomentContactDialog.instance(mActivity).build(wxContacts, new WxMomentContactDialog.CallBack() {
@Override
public void sure() {
final StringBuffer sb = new StringBuffer();
for (int i = 0; i < wxContacts.size(); i++) {
WxContact contact = wxContacts.get(i);
if (contact.isCheck()) {
sb.append(contact.getField_nickname());
sb.append(",");
}
}
mActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
String s = sb.toString();
if (fl != null && fl.getChildCount() > 1) {
LinearLayout msgLinear = (LinearLayout) fl.getChildAt(1);
for (int i = 0; i < msgLinear.getChildCount(); i++) {
View mc = msgLinear.getChildAt(i);
String resourceName = mContext.getResources().getResourceName(mc.getId());
if ("com.tencent.mm:id/de_".equals(resourceName)) {
ViewGroup vg = (ViewGroup) mc;
mc.setVisibility(View.VISIBLE);
if (vg.getChildCount() > 0) {
TextView likeView = (TextView) vg.getChildAt(0);
likeView.append(s);
} else {
TextView tv = new TextView(mContext);
tv.setText("");
tv.append(",");
tv.append(s);
tv.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
vg.addView(tv);
}
}
}
}
}
});
}
});
show.show();
show.getWindow().setLayout(ViewUtil.dp2px(mActivity, 300f), ViewUtil.dp2px(mActivity, 400f));
return false;
}
});
}
}
});
}
});
}
});
}
效果圖如下
效果一 | 效果二 | 效果三 |
---|---|---|
有些不完美的地方,联系人需要点击下通讯录才开始保存数据 这个阶段先做到联系人与点赞关联,下次把点赞的联系人与朋友圈消息关联关系一起保存起来。就可以做到下次在进去朋友圈可以看到上次点赞的。后面还可以进行取消以及其他操作
这次我把我用到的微信版本和genymotion的arm-transfer放进去了 所以体积变大了 哈哈