Skip to content

Instantly share code, notes, and snippets.

@zmrbak
Created June 3, 2018 09:21
Show Gist options
  • Save zmrbak/19472342a366b43a3f7280f1f74a53c2 to your computer and use it in GitHub Desktop.
Save zmrbak/19472342a366b43a3f7280f1f74a53c2 to your computer and use it in GitHub Desktop.
Hook朋友圈点赞。匹配不正确,有待修正......
/**
* 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);
LogUtils.i("hook 朋友圈");
LogUtils.i(param.thisObject.getClass());
Field mat = XposedHelpers.findFieldIfExists(param.thisObject.getClass(), "mActivity");
LogUtils.i(mat.toString());
final Activity mActivity = (Activity) mat.get(param.thisObject);
LogUtils.i(mActivity.toString());
//不再执行,版本有错!
Field odm = XposedHelpers.findFieldIfExists(param.thisObject.getClass(), "odm");
LogUtils.i(odm.toString());
ListView mlv = (ListView) odm.get(param.thisObject);
LogUtils.i(mlv.toString());
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);
for (int i = 0; i <param.args.length ; i++) {
LogUtils.i("param.args["+i+"]:->"+param.args[i]);
}
int position = (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 (int i = 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) {
LogUtils.i("弹出对话框");
new AlertDialog.Builder(mActivity)
.setTitle("温馨提示")
.setMessage("是否对当前消息进行疯狂点赞").setNegativeButton("是的", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
LogUtils.i("处理对话框结果");
mActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
LogUtils.i("开始现场处理结果");
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 = applicationContext.getResources().getResourceName(mc.getId());
LogUtils.i("resourceName:"+resourceName);
if (mc instanceof TextView) {
mc.setVisibility(View.VISIBLE);
((TextView) mc).append("测试!");
// 因为有些gettext 得到的是spanned 调toString会引起shutdown 所以用以下方式打印即可
LogUtils.i(((TextView) mc).getText());
} else if (mc instanceof ViewStub) {
((ViewStub) mc).inflate();
} else 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("测试2!");
LogUtils.i((Object) likeView.getCompoundDrawables());
}else {
TextView tv = new TextView(applicationContext);
tv.setText("测试3");
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();
return false;
}
});
}
}
});
}
});
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment