Skip to content

Commit

Permalink
优化代码逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
firesunCN committed Apr 19, 2018
1 parent 3c9abf3 commit 5d64263
Show file tree
Hide file tree
Showing 13 changed files with 324 additions and 371 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ android {
applicationId "me.firesun.wechat.enhancement"
minSdkVersion 17
targetSdkVersion 23
versionCode 39
versionName "1.5.0"
versionCode 40
versionName "1.6.0"
}

buildTypes {
Expand All @@ -42,5 +42,6 @@ dependencies {
compileOnly files('libs/XposedBridgeApi-82.jar')
implementation 'com.android.support:appcompat-v7:23.1.1'
implementation 'net.dongliu:apk-parser:2.4.2'
implementation 'com.google.code.gson:gson:2.8.2'
}

18 changes: 8 additions & 10 deletions app/src/main/java/me/firesun/wechat/enhancement/Main.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package me.firesun.wechat.enhancement;

import android.app.ActivityManager;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.util.Log;

import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
Expand All @@ -17,7 +15,8 @@
import me.firesun.wechat.enhancement.plugin.AutoLogin;
import me.firesun.wechat.enhancement.plugin.HideModule;
import me.firesun.wechat.enhancement.plugin.LuckMoney;
import me.firesun.wechat.enhancement.util.HookClasses;
import me.firesun.wechat.enhancement.util.HookParams;
import me.firesun.wechat.enhancement.util.SearchClasses;

import static de.robv.android.xposed.XposedBridge.log;

Expand All @@ -26,7 +25,7 @@ public class Main implements IXposedHookLoadPackage {

@Override
public void handleLoadPackage(final LoadPackageParam lpparam) {
if (lpparam.packageName.equals(HookClasses.WECHAT_PACKAGE_NAME)) {
if (lpparam.packageName.equals(HookParams.WECHAT_PACKAGE_NAME)) {
try {
XposedHelpers.findAndHookMethod(ContextWrapper.class, "attachBaseContext", Context.class, new XC_MethodHook() {
@Override
Expand All @@ -35,15 +34,15 @@ protected void afterHookedMethod(XC_MethodHook.MethodHookParam param) throws Thr
Context context = (Context) param.args[0];
String processName = lpparam.processName;
//Only hook important process
if (!processName.equals(HookClasses.WECHAT_PACKAGE_NAME) &&
!processName.equals(HookClasses.WECHAT_PACKAGE_NAME + ":tools")
if (!processName.equals(HookParams.WECHAT_PACKAGE_NAME) &&
!processName.equals(HookParams.WECHAT_PACKAGE_NAME + ":tools")
) {
return;
}
String versionName = getVersionName(context, HookClasses.WECHAT_PACKAGE_NAME);
String versionName = getVersionName(context, HookParams.WECHAT_PACKAGE_NAME);
log("Found wechat version:" + versionName);
if (HookClasses.versionName == null) {
HookClasses.init(context, lpparam, versionName);
if (!HookParams.hasInstance()) {
SearchClasses.init(context, lpparam, versionName);
loadPlugins(lpparam);
}
}
Expand All @@ -61,7 +60,6 @@ private String getVersionName(Context context, String packageName) {
PackageInfo packInfo = packageManager.getPackageInfo(packageName, 0);
return packInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.widget.CompoundButton;
import android.widget.Toast;

import java.lang.reflect.Method;

import me.firesun.wechat.enhancement.util.HookClasses;
import me.firesun.wechat.enhancement.util.HookParams;


public class SettingsActivity extends AppCompatActivity {

Expand Down Expand Up @@ -85,7 +84,7 @@ public boolean onPreferenceChange(Preference preference, Object isChecked) {
public boolean onPreferenceClick(Preference pref) {
Context context = getApplication();
if (context != null) {
SharedPreferences.Editor editor = context.getSharedPreferences(HookClasses.WECHAT_ENHANCEMENT_CONFIG_NAME, Context.MODE_WORLD_READABLE).edit();
SharedPreferences.Editor editor = context.getSharedPreferences(HookParams.WECHAT_ENHANCEMENT_CONFIG_NAME, Context.MODE_WORLD_READABLE).edit();
editor.clear();
editor.commit();
Toast toast = Toast.makeText(context, getString(R.string.repair_done), Toast.LENGTH_SHORT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
import me.firesun.wechat.enhancement.PreferencesUtils;
import me.firesun.wechat.enhancement.util.HookClasses;
import me.firesun.wechat.enhancement.util.HookParams;


public class ADBlock {
Expand All @@ -21,7 +21,7 @@ public static ADBlock getInstance() {
}

public void hook(XC_LoadPackage.LoadPackageParam lpparam) {
XposedHelpers.findAndHookMethod(HookClasses.XMLParserClass, HookClasses.XMLParserMethod, String.class, String.class, new XC_MethodHook() {
XposedHelpers.findAndHookMethod(HookParams.getInstance().XMLParserClassName, lpparam.classLoader, HookParams.getInstance().XMLParserMethod, String.class, String.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
import me.firesun.wechat.enhancement.PreferencesUtils;
import me.firesun.wechat.enhancement.R;
import me.firesun.wechat.enhancement.util.HookClasses;

import static net.dongliu.apk.parser.struct.xml.Attribute.AttrIds.getString;
import me.firesun.wechat.enhancement.util.HookParams;


public class AntiRevoke {
Expand All @@ -33,7 +30,7 @@ public static AntiRevoke getInstance() {
}

public static void hook(XC_LoadPackage.LoadPackageParam lpparam) {
XposedHelpers.findAndHookMethod(HookClasses.SQLiteDatabaseClassName, lpparam.classLoader, HookClasses.SQLiteDatabaseUpdateMethod, String.class, ContentValues.class, String.class, String[].class, int.class, new XC_MethodHook() {
XposedHelpers.findAndHookMethod(HookParams.getInstance().SQLiteDatabaseClassName, lpparam.classLoader, HookParams.getInstance().SQLiteDatabaseUpdateMethod, String.class, ContentValues.class, String.class, String[].class, int.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) {
try {
Expand All @@ -56,7 +53,7 @@ protected void beforeHookedMethod(MethodHookParam param) {
}
});

XposedHelpers.findAndHookMethod(HookClasses.SQLiteDatabaseClassName, lpparam.classLoader, HookClasses.SQLiteDatabaseDeleteMethod, String.class, String.class, String[].class, new XC_MethodHook() {
XposedHelpers.findAndHookMethod(HookParams.getInstance().SQLiteDatabaseClassName, lpparam.classLoader, HookParams.getInstance().SQLiteDatabaseDeleteMethod, String.class, String.class, String[].class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) {
try {
Expand Down Expand Up @@ -91,8 +88,8 @@ protected void beforeHookedMethod(MethodHookParam param) {
}
});


XposedHelpers.findAndHookMethod(HookClasses.MsgInfoStorageClass, HookClasses.MsgInfoStorageInsertMethod, HookClasses.MsgInfoClass, boolean.class, new XC_MethodHook() {
Class msgInfoClass = XposedHelpers.findClass(HookParams.getInstance().MsgInfoClassName, lpparam.classLoader);
XposedHelpers.findAndHookMethod(HookParams.getInstance().MsgInfoStorageClassName, lpparam.classLoader, HookParams.getInstance().MsgInfoStorageInsertMethod, msgInfoClass, boolean.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
import me.firesun.wechat.enhancement.PreferencesUtils;
import me.firesun.wechat.enhancement.util.HookClasses;
import me.firesun.wechat.enhancement.util.HookParams;

import static java.util.Arrays.copyOfRange;

Expand All @@ -28,7 +28,7 @@ public static AntiSnsDelete getInstance() {

public void hook(XC_LoadPackage.LoadPackageParam lpparam) {

XposedHelpers.findAndHookMethod(HookClasses.SQLiteDatabaseClassName, lpparam.classLoader, HookClasses.SQLiteDatabaseUpdateMethod, String.class, ContentValues.class, String.class, String[].class, int.class, new XC_MethodHook() {
XposedHelpers.findAndHookMethod(HookParams.getInstance().SQLiteDatabaseClassName, lpparam.classLoader, HookParams.getInstance().SQLiteDatabaseUpdateMethod, String.class, ContentValues.class, String.class, String[].class, int.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
import me.firesun.wechat.enhancement.PreferencesUtils;
import me.firesun.wechat.enhancement.util.HookClasses;
import me.firesun.wechat.enhancement.util.HookParams;


public class AutoLogin {
Expand All @@ -36,7 +36,7 @@ protected void beforeHookedMethod(MethodHookParam param) {
return;
}
Activity activity = (Activity) param.thisObject;
if (activity.getClass().getName().equals(HookClasses.WebWXLoginUIClassName)) {
if (activity.getClass().getName().equals(HookParams.getInstance().WebWXLoginUIClassName)) {
Class clazz = activity.getClass();
Field field = XposedHelpers.findFirstFieldByExactType(clazz, Button.class);
Button button = (Button) field.get(activity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
import me.firesun.wechat.enhancement.util.HookClasses;
import me.firesun.wechat.enhancement.util.HookParams;


public class HideModule {
Expand Down Expand Up @@ -71,7 +71,7 @@ protected void beforeHookedMethod(MethodHookParam param) {
try {
String packageName = (String) param.args[0];
if (packageName.contains("firesun") || packageName.contains("xposed")) {
param.args[0] = HookClasses.WECHAT_PACKAGE_NAME;
param.args[0] = HookParams.WECHAT_PACKAGE_NAME;
}
} catch (Error | Exception e) {
}
Expand All @@ -84,7 +84,7 @@ protected void beforeHookedMethod(MethodHookParam param) {
try {
String packageName = (String) param.args[0];
if (packageName.contains("firesun") || packageName.contains("xposed")) {
param.args[0] = HookClasses.WECHAT_PACKAGE_NAME;
param.args[0] = HookParams.WECHAT_PACKAGE_NAME;
}
} catch (Error | Exception e) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
import me.firesun.wechat.enhancement.PreferencesUtils;
import me.firesun.wechat.enhancement.util.HookClasses;
import me.firesun.wechat.enhancement.util.HookParams;
import me.firesun.wechat.enhancement.util.XmlToJson;

import static android.text.TextUtils.isEmpty;
Expand All @@ -49,7 +49,7 @@ public static LuckMoney getInstance() {
}

public void hook(final XC_LoadPackage.LoadPackageParam lpparam) {
XposedHelpers.findAndHookMethod(HookClasses.SQLiteDatabaseClassName, lpparam.classLoader, HookClasses.SQLiteDatabaseInsertMethod, String.class, String.class, ContentValues.class, new XC_MethodHook() {
XposedHelpers.findAndHookMethod(HookParams.getInstance().SQLiteDatabaseClassName, lpparam.classLoader, HookParams.getInstance().SQLiteDatabaseInsertMethod, String.class, String.class, ContentValues.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) {
try {
Expand All @@ -73,11 +73,11 @@ protected void afterHookedMethod(MethodHookParam param) {
});


XposedHelpers.findAndHookMethod(HookClasses.ReceiveLuckyMoneyRequestClass, HookClasses.ReceiveLuckyMoneyRequestMethod, int.class, String.class, JSONObject.class, new XC_MethodHook() {
XposedHelpers.findAndHookMethod(HookParams.getInstance().ReceiveLuckyMoneyRequestClassName, lpparam.classLoader, HookParams.getInstance().ReceiveLuckyMoneyRequestMethod, int.class, String.class, JSONObject.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) {
try {
if (!HookClasses.hasTimingIdentifier) {
if (!HookParams.getInstance().hasTimingIdentifier) {
return;
}

Expand All @@ -90,17 +90,20 @@ protected void beforeHookedMethod(MethodHookParam param) {
return;
}
LuckyMoneyMessage luckyMoneyMessage = luckyMoneyMessages.get(0);
Object luckyMoneyRequest = newInstance(HookClasses.LuckyMoneyRequestClass,

Class luckyMoneyRequestClass = XposedHelpers.findClass(HookParams.getInstance().LuckyMoneyRequestClassName, lpparam.classLoader);
Object luckyMoneyRequest = newInstance(luckyMoneyRequestClass,
luckyMoneyMessage.getMsgType(), luckyMoneyMessage.getChannelId(), luckyMoneyMessage.getSendId(), luckyMoneyMessage.getNativeUrlString(), "", "", luckyMoneyMessage.getTalker(), "v1.0", timingIdentifier);
callMethod(requestCaller, HookClasses.RequestCallerMethod, luckyMoneyRequest, getDelayTime());
callMethod(requestCaller, HookParams.getInstance().RequestCallerMethod, luckyMoneyRequest, getDelayTime());
luckyMoneyMessages.remove(0);

} catch (Error | Exception e) {
}
}
});

XposedHelpers.findAndHookMethod(HookClasses.LuckyMoneyReceiveUIClassName, lpparam.classLoader, HookClasses.ReceiveUIMethod, int.class, int.class, String.class, HookClasses.ReceiveUIParamNameClass, new XC_MethodHook() {
Class receiveUIParamNameClass = XposedHelpers.findClass(HookParams.getInstance().ReceiveUIParamNameClassName, lpparam.classLoader);
XposedHelpers.findAndHookMethod(HookParams.getInstance().LuckyMoneyReceiveUIClassName, lpparam.classLoader, HookParams.getInstance().ReceiveUIMethod, int.class, int.class, String.class, receiveUIParamNameClass, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) {
try {
Expand All @@ -115,7 +118,7 @@ protected void afterHookedMethod(MethodHookParam param) {
}
});

XposedHelpers.findAndHookMethod(HookClasses.ContactInfoUIClassName, lpparam.classLoader, "onCreate", Bundle.class, new XC_MethodHook() {
XposedHelpers.findAndHookMethod(HookParams.getInstance().ContactInfoUIClassName, lpparam.classLoader, "onCreate", Bundle.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) {
try {
Expand All @@ -131,7 +134,7 @@ protected void afterHookedMethod(MethodHookParam param) {
}
});

XposedHelpers.findAndHookMethod(HookClasses.ChatroomInfoUIClassName, lpparam.classLoader, "onCreate", Bundle.class, new XC_MethodHook() {
XposedHelpers.findAndHookMethod(HookParams.getInstance().ChatroomInfoUIClassName, lpparam.classLoader, "onCreate", Bundle.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) {
try {
Expand Down Expand Up @@ -205,17 +208,22 @@ private void handleLuckyMoney(ContentValues contentValues, XC_LoadPackage.LoadPa
int msgType = Integer.parseInt(nativeUrl.getQueryParameter("msgtype"));
int channelId = Integer.parseInt(nativeUrl.getQueryParameter("channelid"));
String sendId = nativeUrl.getQueryParameter("sendid");
requestCaller = callStaticMethod(HookClasses.NetworkRequestClass, HookClasses.GetNetworkByModelMethod);

if (HookClasses.hasTimingIdentifier) {
callMethod(requestCaller, HookClasses.RequestCallerMethod, newInstance(HookClasses.ReceiveLuckyMoneyRequestClass, channelId, sendId, nativeUrlString, 0, "v1.0"), 0);
Class networkRequestClass = XposedHelpers.findClass(HookParams.getInstance().NetworkRequestClassName, lpparam.classLoader);
requestCaller = callStaticMethod(networkRequestClass, HookParams.getInstance().GetNetworkByModelMethod);

Class receiveLuckyMoneyRequestClass = XposedHelpers.findClass(HookParams.getInstance().ReceiveLuckyMoneyRequestClassName, lpparam.classLoader);
if (HookParams.getInstance().hasTimingIdentifier) {
callMethod(requestCaller, HookParams.getInstance().RequestCallerMethod, newInstance(receiveLuckyMoneyRequestClass, channelId, sendId, nativeUrlString, 0, "v1.0"), 0);
luckyMoneyMessages.add(new LuckyMoneyMessage(msgType, channelId, sendId, nativeUrlString, talker));
return;
}
Object luckyMoneyRequest = newInstance(HookClasses.LuckyMoneyRequestClass,

Class luckyMoneyRequestClass = XposedHelpers.findClass(HookParams.getInstance().LuckyMoneyRequestClassName, lpparam.classLoader);
Object luckyMoneyRequest = newInstance(luckyMoneyRequestClass,
msgType, channelId, sendId, nativeUrlString, "", "", talker, "v1.0");

callMethod(requestCaller, HookClasses.RequestCallerMethod, luckyMoneyRequest, getDelayTime());
callMethod(requestCaller, HookParams.getInstance().RequestCallerMethod, luckyMoneyRequest, getDelayTime());
}

private void handleTransfer(ContentValues contentValues, XC_LoadPackage.LoadPackageParam lpparam) throws IOException, XmlPullParserException, PackageManager.NameNotFoundException, InterruptedException, JSONException {
Expand All @@ -235,11 +243,14 @@ private void handleTransfer(ContentValues contentValues, XC_LoadPackage.LoadPack
int invalidtime = wcpayinfo.getInt("invalidtime");

if (null == requestCaller) {
requestCaller = callStaticMethod(HookClasses.NetworkRequestClass, HookClasses.GetNetworkByModelMethod);
Class networkRequestClass = XposedHelpers.findClass(HookParams.getInstance().NetworkRequestClassName, lpparam.classLoader);
requestCaller = callStaticMethod(networkRequestClass, HookParams.getInstance().GetNetworkByModelMethod);
}

String talker = contentValues.getAsString("talker");
callMethod(requestCaller, HookClasses.RequestCallerMethod, newInstance(HookClasses.GetTransferRequestClass, transactionId, transferId, 0, "confirm", talker, invalidtime), 0);

Class getTransferRequestClass = XposedHelpers.findClass(HookParams.getInstance().GetTransferRequestClassName, lpparam.classLoader);
callMethod(requestCaller, HookParams.getInstance().RequestCallerMethod, newInstance(getTransferRequestClass, transactionId, transferId, 0, "confirm", talker, invalidtime), 0);
}


Expand Down
Loading

0 comments on commit 5d64263

Please sign in to comment.