Xposed第四課(微信篇) 朋友圈點贊(2)之好友列表

weixin_33782386發表於2018-06-02

前面做了個小玩意,朋友圈點贊,缺點是隻能在當前介面臨時顯示,並且不能選擇好友,返回後在進去就沒有了,今天準備將聯絡人與朋友圈點贊功能關聯起來。

首先分析佈局結構


5223850-14864b096ef8309e.png
QQ截圖20180530204254.png

根據關鍵名稱進行查詢

BizContactEntranceView AlphabetScrollBar
5223850-50348364f91c261c.png
QQ截圖20180530203817.png
5223850-171dbb6323a6fbb6.png
QQ截圖20180530204400.png

定位到了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;
                                                                }
                                                            });
                                                        }
                                                    }
                                                });
                                    }
                                });
                    }
                });
    }

效果圖如下

效果一 效果二 效果三
5223850-d10cbb2ea9a56df3.png
微信截圖_20180601222733.png
5223850-f48d8a875eb603ad.png
微信截圖_20180601222659.png
5223850-1293c020c50e30d7.png
微信截圖_20180601222713.png

有些不完美的地方,聯絡人需要點選下通訊錄才開始儲存資料 這個階段先做到聯絡人與點贊關聯,下次把點讚的聯絡人與朋友圈訊息關聯關係一起儲存起來。就可以做到下次在進去朋友圈可以看到上次點讚的。後面還可以進行取消以及其他操作

垃圾程式碼已上傳

這次我把我用到的微信版本和genymotion的arm-transfer放進去了 所以體積變大了 哈哈

相關文章