|
1 | 1 | package com.example.xposedhookweixin1;
|
2 | 2 |
|
3 | 3 | import android.app.Activity;
|
4 |
| -import android.content.ComponentName; |
| 4 | +import android.content.BroadcastReceiver; |
| 5 | +import android.content.Context; |
5 | 6 | import android.content.Intent;
|
6 |
| -import android.os.Build; |
| 7 | +import android.content.IntentFilter; |
7 | 8 | import android.os.Bundle;
|
8 | 9 | import android.os.Environment;
|
9 |
| -import android.support.annotation.RequiresApi; |
10 | 10 | import android.util.Log;
|
11 |
| -import android.view.View; |
12 | 11 |
|
13 | 12 | import java.io.File;
|
14 | 13 | import java.lang.reflect.Field;
|
|
21 | 20 |
|
22 | 21 | public class XposedHookWeixin implements IXposedHookLoadPackage {
|
23 | 22 |
|
24 |
| - private static final String selfPackageName="com.example.xposedhookweixin1"; |
| 23 | + private static final String selfPackageName = "com.example.xposedhookweixin1"; |
25 | 24 |
|
26 |
| - static final String intentFilterMsg = selfPackageName+".notify_open"; |
| 25 | + static final String intentFilterMsg = selfPackageName + ".notify_open"; |
27 | 26 |
|
28 |
| - private static final String weixinPackageName = "com.tencent.mm"; |
| 27 | + private static final String weixinPackageName = "com.tencent.mm"; |
29 | 28 |
|
30 |
| - private static final String weixinMainActivityClassName = weixinPackageName + ".ui.LauncherUI"; |
| 29 | + private static final String weixinMainActivityClassName = weixinPackageName + ".ui.LauncherUI"; |
31 | 30 |
|
32 |
| - private static final String weixinNearbyClassName = weixinPackageName + ".plugin.nearby.ui.NearbyFriendsUI"; |
| 31 | + private static final String weixinNearbyClassName = weixinPackageName + ".plugin.nearby.ui.NearbyFriendsUI"; |
33 | 32 |
|
34 | 33 | static final String TAG = "xposed";
|
35 | 34 |
|
36 | 35 | @Override
|
37 | 36 | 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"; |
38 | 106 |
|
| 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 | + } |
39 | 134 | }
|
| 135 | + |
40 | 136 | }
|
0 commit comments