Skip to content

Commit 7ceefd7

Browse files
committed
commit
1 parent 5c0cfd9 commit 7ceefd7

File tree

3 files changed

+107
-11
lines changed

3 files changed

+107
-11
lines changed

projects/XposedHookWeiXin3/.idea/markdown-navigator/profiles_settings.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

projects/XposedHookWeiXin3/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
**本工程目标——通过本工程 click 事件来打开微信并获取微信附近的人信息**
22

3-
<!--<img src="image/nearby.png" width="280px" height="500px"/>-->
3+
<img src="image/nearby.png" width="280px" height="500px"/>
44

55
**本工程基于[微信7.0.4版本源码](./docs/weixin_7.0.4_source)**
66

Lines changed: 105 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package com.example.xposedhookweixin1;
22

33
import android.app.Activity;
4-
import android.content.ComponentName;
4+
import android.content.BroadcastReceiver;
5+
import android.content.Context;
56
import android.content.Intent;
6-
import android.os.Build;
7+
import android.content.IntentFilter;
78
import android.os.Bundle;
89
import android.os.Environment;
9-
import android.support.annotation.RequiresApi;
1010
import android.util.Log;
11-
import android.view.View;
1211

1312
import java.io.File;
1413
import java.lang.reflect.Field;
@@ -21,20 +20,117 @@
2120

2221
public class XposedHookWeixin implements IXposedHookLoadPackage {
2322

24-
private static final String selfPackageName="com.example.xposedhookweixin1";
23+
private static final String selfPackageName = "com.example.xposedhookweixin1";
2524

26-
static final String intentFilterMsg = selfPackageName+".notify_open";
25+
static final String intentFilterMsg = selfPackageName + ".notify_open";
2726

28-
private static final String weixinPackageName = "com.tencent.mm";
27+
private static final String weixinPackageName = "com.tencent.mm";
2928

30-
private static final String weixinMainActivityClassName = weixinPackageName + ".ui.LauncherUI";
29+
private static final String weixinMainActivityClassName = weixinPackageName + ".ui.LauncherUI";
3130

32-
private static final String weixinNearbyClassName = weixinPackageName + ".plugin.nearby.ui.NearbyFriendsUI";
31+
private static final String weixinNearbyClassName = weixinPackageName + ".plugin.nearby.ui.NearbyFriendsUI";
3332

3433
static final String TAG = "xposed";
3534

3635
@Override
3736
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
37+
if (lpparam.packageName.equals(weixinPackageName)) {
38+
addWeixinBroadcast(lpparam);
39+
getNearbyInfo(lpparam);
40+
}
41+
}
42+
43+
private void addWeixinBroadcast(final XC_LoadPackage.LoadPackageParam lpparam) {
44+
XposedHelpers.findAndHookMethod(weixinMainActivityClassName, //
45+
lpparam.classLoader, //
46+
"onCreate", Bundle.class, new XC_MethodHook() {
47+
@Override
48+
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
49+
super.beforeHookedMethod(param);
50+
}
51+
52+
@Override
53+
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
54+
super.afterHookedMethod(param);
55+
Log.d(TAG, "添加广播");
56+
addBroadcastReceiver(lpparam, param);
57+
}
58+
});
59+
}
60+
61+
62+
private void addBroadcastReceiver(final XC_LoadPackage.LoadPackageParam lpparam, //
63+
XC_MethodHook.MethodHookParam param) {
64+
final Activity activity = (Activity) param.thisObject;
65+
IntentFilter intentFilter = new IntentFilter();
66+
intentFilter.addAction(intentFilterMsg);
67+
activity.registerReceiver(new BroadcastReceiver() {
68+
@Override
69+
public void onReceive(Context context, Intent intent) {
70+
Log.d(TAG, "接收到广播:" + intent.getAction());
71+
Intent intent1 = new Intent();
72+
//自定义状态
73+
intent1.putExtra("auto", true);
74+
intent1.setClass(activity, XposedHelpers.findClass(weixinNearbyClassName, lpparam.classLoader));
75+
activity.startActivity(intent1);
76+
}
77+
}, intentFilter);
78+
}
79+
80+
private void getNearbyInfo(final XC_LoadPackage.LoadPackageParam lpparam) {
81+
XposedHelpers.findAndHookMethod(weixinNearbyClassName, lpparam.classLoader, //
82+
"onSceneEnd", int.class,//
83+
int.class, String.class, //
84+
XposedHelpers.findClassIfExists("com.tencent.mm.ai.m", lpparam.classLoader),//
85+
new XC_MethodHook() {
86+
@Override
87+
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
88+
super.beforeHookedMethod(param);
89+
}
90+
91+
@Override
92+
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
93+
super.afterHookedMethod(param);
94+
Activity activity = (Activity) param.thisObject;
95+
Intent intent = activity.getIntent();
96+
//不是自动不会继续执行
97+
if (!intent.getBooleanExtra("auto", false))
98+
return;
99+
Log.d(TAG, "继续执行");
100+
getNearbyInfo(param, lpparam);
101+
}
102+
});
103+
}
104+
105+
private static final String nearby_info_path = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separatorChar + "weixin_nearby.txt";
38106

107+
private void getNearbyInfo(XC_MethodHook.MethodHookParam param, XC_LoadPackage.LoadPackageParam lpparam) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException {
108+
Field field = lpparam.classLoader.loadClass(weixinNearbyClassName).getDeclaredField("lQs");
109+
field.setAccessible(true);
110+
List list = (List) field.get(param.thisObject);
111+
Log.i(TAG, "打印附近人结果:" + list.size());
112+
Class axv = list.get(0).getClass();
113+
Field[] fields = axv.getDeclaredFields();
114+
StringBuilder builder = new StringBuilder();
115+
String msg = "";
116+
for (int i = 0; i < list.size(); i++) {
117+
msg = "第" + (i + 1) + "人\n";
118+
builder.append(msg);
119+
for (Field field1 : fields) {
120+
try {
121+
field1.setAccessible(true);
122+
msg = "打印附近人详情属性:" + field1.getName() + "===" + field1.getType().toString() + "===" + field1.get(list.get(i)) + "\n";
123+
builder.append(msg);
124+
} catch (Exception e) {
125+
e.printStackTrace();
126+
}
127+
}
128+
}
129+
if (msg.isEmpty()) {
130+
Log.i(TAG, "无好友");
131+
} else {
132+
Log.i(TAG, "写入是否成功:" + FileIOUtils.writeFileFromBytesByStream(nearby_info_path, msg.getBytes()));
133+
}
39134
}
135+
40136
}

0 commit comments

Comments
 (0)