Xposed第四課(微信篇) 朋友圈點贊 (1)

Editor發表於2018-05-31

[原創]Xposed第三課(微信篇) 防止好友訊息撤回


上篇文章有些小夥伴問我怎麼去看佈局檔案的,我這裡交代先我分析介面的方法


1、 adb shell dumpsys activity top

Xposed第四課(微信篇) 朋友圈點贊 (1)

2、 as自帶的layout inspector(有些情況無法得到繪製)

Xposed第四課(微信篇) 朋友圈點贊 (1)

但是顯示效果最好

3、 Android Device Monitor 相信以前用eclipse時候adt經常用到的

Xposed第四課(微信篇) 朋友圈點贊 (1)

好了廢話不多說了,以上是我用到的,如果有更好的可以給我留言

首先terminal輸入adb shell dumpsys activity top 如下

Xposed第四課(微信篇) 朋友圈點贊 (1)

往下繼續翻

Xposed第四課(微信篇) 朋友圈點贊 (1)

然後我們們看看分析分析SnsTimeLineUI裡面的程式碼邏輯


public void onCreate(Bundle bundle) {

...省略N多程式碼...

this.skT=this.rUA;

this.slh.a(this.sle, this.jzz,str, str2, this.slf, this.rWo, this.slg);

//這句話是初始化裡面的列表等組建

this.slh.onCreate();

ae.byE().init();

this.mActionBar=getSupportActionBar();

com.tencent.mm.kernel.g.Ea();

com.tencent.mm.kernel.g.DX().fUP.a((int) com.tencent.mm.plugin.appbrand.jsapi.bio.face.c.CTRL_INDEX, (e) this);

com.tencent.mm.kernel.g.Ea();

com.tencent.mm.kernel.g.DX().fUP.a(682, (e) this);

com.tencent.mm.kernel.g.Ea();

com.tencent.mm.kernel.g.DX().fUP.a(218, (e) this);

...省略N多程式碼...

}


通過上面的程式碼可以找到

com.tencent.mm.plugin.sns.ui.bb


在這個檔案裡面就有我們剛才在terminal裡面看到的很多關聯的東西


Xposed第四課(微信篇) 朋友圈點贊 (1)


所以關聯起來可以開始編碼了,裡面註釋的程式碼都是列印的關鍵資訊,可以在一邊除錯一邊看輸出資訊


/**

*hook 朋友圈

*

*@param applicationContext

*@param classLoader

*/

private void hookWxMoments(final Context applicationContext, final ClassLoader classLoader) throws Error {

XposedHelpers.findAndHookMethod("com.tencent.mm.plugin.sns.ui.bb",

classLoader,

"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();

//                       LogUtils.i(mlv.toString(), mlvSuperClass.toString());

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);

//                                                       intposition=(int) param.args[0];

final View view=(View) param.args[1];

//                                                       ViewGroup viewGroup=(ViewGroup) param.args[2];

if(view !=null) {

//fl 第一個view是圖片 第二個view是朋友圈內容

final ViewGroup fl=(ViewGroup) view;

//                                                           StringBuffer sb=new StringBuffer();

//                                                           for(inti=0; i < fl.getChildCount(); i++) {

//                                                               sb.append(fl.getChildAt(i).toString());

//                                                               sb.append("@");

//                                                               sb.append(fl.getChildAt(i).getId());

//                                                               sb.append("@");

//                                                               sb.append(applicationContext.getResources().getResourceName(fl.getChildAt(i).getId()));

//                                                               sb.append("\n");

//                                                           }

//                                                           LogUtils.i(position, view, sb.toString(), viewGroup, JSON.toJSONString(adapter.getItem(position)), adapter.getItem(position).toString());

view.setOnLongClickListener(new View.OnLongClickListener() {

@Override

public boolean onLongClick(View v) {

new AlertDialog.Builder(mActivity)

.setTitle("溫馨提示")

.setMessage("是否對當前訊息進行瘋狂點贊").setNegativeButton("是的", new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog,intwhich) {

mActivity.runOnUiThread(new Runnable() {

@Override

public void run() {

if(fl !=null && fl.getChildCount() >1) {

LinearLayout msgLinear=(LinearLayout) fl.getChildAt(1);

for(inti=0; i < msgLinear.getChildCount(); i++) {

View mc=msgLinear.getChildAt(i);

String resourceName=applicationContext.getResources().getResourceName(mc.getId());

if(mc instanceof TextView) {

//                                                                                               mc.setVisibility(View.VISIBLE);

//                                                                                               ((TextView) mc).append("看雪論壇,看雪論壇++,看雪論壇+++");

//因為有些gettext 得到的是spanned 調toString會引起shutdown 所以用以下方式列印即可

//                                                                                               LogUtils.i(((TextView) mc).getText());

}elseif(mc instanceof ViewStub) {

//                                                                                               ((ViewStub) mc).inflate();

}elseif("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("看雪論壇,看雪論壇++,看雪論壇+++");

LogUtils.i(likeView.getCompoundDrawables());

}else{

TextView tv=new TextView(applicationContext);

tv.setText(",看雪論壇,看雪論壇++,看雪論壇+++");

tv.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

vg.addView(tv);

}

}

//                                                                                           LogUtils.i(mc, resourceName,"com.tencent.mm:id/de_");

}

}

}

});

}

}).setNeutralButton("不是的", null).show();

returnfalse;

}

});

}

}

});

}

});

}

});

}

最終結果 如下圖


去掉上圖程式碼註釋效果圖    
Xposed第四課(微信篇) 朋友圈點贊 (1)

去掉上圖程式碼註釋效果圖
Xposed第四課(微信篇) 朋友圈點贊 (1)

註釋後程式碼的效果
Xposed第四課(微信篇) 朋友圈點贊 (1)

去掉註釋我把所有view都展示出來了,後面過濾註釋無用程式碼後只留下點贊欄目的view即可


這個只是做了ui效果,後面會進行資料庫儲存記錄,保證下次瀏覽到該條資訊能夠直接顯示點贊資料,並且儘可能實現從好友列表選擇點贊人
程式碼已上傳


原文連結:https://bbs.pediy.com/thread-226951.htm

本文由看雪論壇 KingZd 原創

轉載請註明來自看雪社群


相關文章