|
1 | 1 | package com.example.xposedhookweixin1; |
2 | 2 |
|
| 3 | +import android.app.Activity; |
3 | 4 | import android.content.ContentValues; |
| 5 | +import android.content.Intent; |
| 6 | +import android.os.Bundle; |
4 | 7 | import android.util.Log; |
| 8 | +import android.view.View; |
| 9 | +import android.widget.Button; |
5 | 10 |
|
6 | | -import java.util.Arrays; |
| 11 | +import java.lang.reflect.Field; |
7 | 12 |
|
8 | 13 | import de.robv.android.xposed.IXposedHookLoadPackage; |
9 | 14 | import de.robv.android.xposed.XC_MethodHook; |
10 | 15 | import de.robv.android.xposed.XposedHelpers; |
11 | 16 | import de.robv.android.xposed.callbacks.XC_LoadPackage; |
12 | 17 |
|
| 18 | +import static de.robv.android.xposed.XposedHelpers.findClass; |
| 19 | + |
13 | 20 | public class XposedHookWeixin implements IXposedHookLoadPackage { |
14 | 21 |
|
15 | 22 | private static final String weixinPackageName = "com.tencent.mm"; |
16 | 23 |
|
| 24 | + private static final String weixinLauncherUIName = weixinPackageName + ".ui.LauncherUI"; |
| 25 | + |
| 26 | + private static final String weixinLuchyMoneyUIName = weixinPackageName + ".plugin.luckymoney.ui.LuckyMoneyNotHookReceiveUI"; |
| 27 | + |
| 28 | + private static final String weixinLuchyMoneyDetailsUIName = weixinPackageName + ".plugin.luckymoney.ui.LuckyMoneyDetailUI"; |
| 29 | + |
17 | 30 | private static final String weixinSqlitClassName = "com.tencent.wcdb.database.SQLiteDatabase"; |
18 | 31 |
|
19 | | - private static final String TAG="xposed"; |
| 32 | + private static final String TAG = "xposed"; |
20 | 33 |
|
21 | 34 | @Override |
22 | 35 | public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable { |
23 | | - if(lpparam.packageName.equals(weixinPackageName)) { |
24 | | - addLuckyMoneyListener(lpparam); |
| 36 | + if (lpparam.packageName.equals(weixinPackageName)) { |
| 37 | + initHook(lpparam); |
| 38 | + hookNewMessage(lpparam); |
| 39 | + hookOpenLuckyMoney(lpparam); |
| 40 | + hookCloseLuckyMoneyDetailUI(lpparam); |
25 | 41 | } |
26 | 42 | } |
27 | 43 |
|
28 | | - private void addLuckyMoneyListener(XC_LoadPackage.LoadPackageParam lpparam) { |
29 | | - Class sqlitCls=XposedHelpers.findClassIfExists(weixinSqlitClassName,lpparam.classLoader); |
30 | | - if(sqlitCls!=null) { |
31 | | - XposedHelpers.findAndHookMethod(sqlitCls, "insertWithOnConflict", // |
32 | | - String.class, String.class, ContentValues.class,// |
33 | | - int.class, new XC_MethodHook() { |
34 | | - @Override |
35 | | - protected void afterHookedMethod(MethodHookParam param) throws Throwable { |
36 | | - super.afterHookedMethod(param); |
37 | | - Log.d(TAG,"数据库参数:"+ Arrays.toString(param.args)); |
| 44 | + private String lastTalkerName = ""; |
| 45 | + private String lastNativeUrl = ""; |
| 46 | + private Activity launcherUiActivity; |
| 47 | + |
| 48 | + /** |
| 49 | + * 初始化微信红包勾子 |
| 50 | + */ |
| 51 | + private void initHook(XC_LoadPackage.LoadPackageParam loadPackageParam) { |
| 52 | + XposedHelpers.findAndHookMethod(weixinLauncherUIName, loadPackageParam.classLoader, // |
| 53 | + "onCreate", Bundle.class, new XC_MethodHook() { |
| 54 | + @Override |
| 55 | + protected void afterHookedMethod(MethodHookParam param) throws Throwable { |
| 56 | + launcherUiActivity = (Activity) param.thisObject; |
| 57 | + } |
| 58 | + }); |
| 59 | + } |
38 | 60 |
|
| 61 | + /** |
| 62 | + * 过滤红包消息 |
| 63 | + */ |
| 64 | + private void hookNewMessage(final XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable { |
| 65 | + XposedHelpers.findAndHookMethod(weixinSqlitClassName, loadPackageParam.classLoader, // |
| 66 | + "insertWithOnConflict", String.class, String.class, // |
| 67 | + ContentValues.class, int.class, new XC_MethodHook() { |
| 68 | + @Override |
| 69 | + protected void afterHookedMethod(MethodHookParam param) throws Throwable { |
| 70 | + Log.d(TAG, "table=" + param.args[0] + "\n"); |
| 71 | + ContentValues contentValues = (ContentValues) param.args[2]; |
| 72 | + if ("WalletLuckyMoney".equals(param.args[0])) { |
| 73 | + Log.d(TAG, "mNativeUrl:" + contentValues.getAsString("mNativeUrl")); |
| 74 | + lastNativeUrl = contentValues.getAsString("mNativeUrl"); |
| 75 | + } else if ("message".equals(param.args[0]) // |
| 76 | + && null != contentValues.getAsString("reserved") // |
| 77 | + && contentValues.getAsString("reserved").contains("微信红包")) { |
| 78 | + Log.d(TAG, "talker:" + contentValues.getAsString("talker")); |
| 79 | + lastTalkerName = contentValues.getAsString("talker"); |
| 80 | + Log.d(TAG, "content:" + contentValues.getAsString("content")); |
| 81 | + // 启动红包页面 |
| 82 | + if (launcherUiActivity != null) { |
| 83 | + Intent paramau = new Intent(); |
| 84 | + paramau.putExtra("key_way", 0); |
| 85 | + paramau.putExtra("key_native_url", lastNativeUrl); |
| 86 | + paramau.putExtra("key_username", lastTalkerName); |
| 87 | + paramau.putExtra("key_cropname", (String) null); |
| 88 | + XposedHelpers.callStaticMethod(findClass( |
| 89 | + "com.tencent.mm.bp.d", // |
| 90 | + loadPackageParam.classLoader), "b", launcherUiActivity,// |
| 91 | + "luckymoney", ".ui.LuckyMoneyNotHookReceiveUI", paramau); |
| 92 | + } else { |
| 93 | + Log.d(TAG, "launcherUiActivity == null" + "\n"); |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | + }); |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * 触发开红包动作 |
| 102 | + */ |
| 103 | + private void hookOpenLuckyMoney(final XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable { |
| 104 | + XposedHelpers.findAndHookMethod(weixinLuchyMoneyUIName, loadPackageParam.classLoader, "onResume", new XC_MethodHook() { |
| 105 | + @Override |
| 106 | + protected void afterHookedMethod(MethodHookParam param) throws Throwable { |
| 107 | + Log.d(TAG, "LuckyMoneyNotHookReceiveUI"); |
| 108 | + Field buttonField = XposedHelpers.findField(param.thisObject.getClass(), "nTE"); |
| 109 | + final Button kaiButton = (Button) buttonField.get(param.thisObject); |
| 110 | + if (kaiButton.getVisibility() != View.VISIBLE) { |
| 111 | + ((Activity) param.thisObject).finish(); |
| 112 | + } else { |
| 113 | + kaiButton.postDelayed(new Runnable() { |
| 114 | + @Override |
| 115 | + public void run() { |
| 116 | + kaiButton.performClick(); |
| 117 | + } |
| 118 | + }, 500); |
39 | 119 | } |
40 | | - }); |
41 | | - } |
| 120 | + } |
| 121 | + }); |
| 122 | + } |
| 123 | + |
| 124 | + /** |
| 125 | + * 关闭红包详情页 |
| 126 | + */ |
| 127 | + private void hookCloseLuckyMoneyDetailUI(final XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable { |
| 128 | + XposedHelpers.findAndHookMethod(weixinLuchyMoneyDetailsUIName, loadPackageParam.classLoader, // |
| 129 | + "onCreate", Bundle.class, new XC_MethodHook() { |
| 130 | + @Override |
| 131 | + protected void afterHookedMethod(MethodHookParam param) throws Throwable { |
| 132 | + ((Activity) param.thisObject).finish(); |
| 133 | + } |
| 134 | + }); |
42 | 135 | } |
43 | 136 |
|
44 | 137 | } |
0 commit comments