Skip to content

Commit

Permalink
优化加载方式,防止插件之间相互影响
Browse files Browse the repository at this point in the history
  • Loading branch information
firesunCN committed Apr 20, 2018
1 parent 5d64263 commit 95c7513
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 85 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
android:name="xposedminversion"
android:value="30" />

<receiver android:name=".util.Receiver" android:enabled="true">
<receiver android:name=".util.ConfigReceiver" android:enabled="true">
<intent-filter>
<action android:name="wechat.intent.action.SAVE_WECHAT_ENHANCEMENT_CONFIG" />
</intent-filter>
Expand Down
29 changes: 20 additions & 9 deletions app/src/main/java/me/firesun/wechat/enhancement/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import java.util.List;

import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedHelpers;
Expand All @@ -14,6 +16,7 @@
import me.firesun.wechat.enhancement.plugin.AntiSnsDelete;
import me.firesun.wechat.enhancement.plugin.AutoLogin;
import me.firesun.wechat.enhancement.plugin.HideModule;
import me.firesun.wechat.enhancement.plugin.IPlugin;
import me.firesun.wechat.enhancement.plugin.LuckMoney;
import me.firesun.wechat.enhancement.util.HookParams;
import me.firesun.wechat.enhancement.util.SearchClasses;
Expand All @@ -23,6 +26,15 @@

public class Main implements IXposedHookLoadPackage {

private static IPlugin[] plugins={
new ADBlock(),
new AntiRevoke(),
new AntiSnsDelete(),
new AutoLogin(),
new HideModule(),
new LuckMoney(),
};

@Override
public void handleLoadPackage(final LoadPackageParam lpparam) {
if (lpparam.packageName.equals(HookParams.WECHAT_PACKAGE_NAME)) {
Expand Down Expand Up @@ -64,17 +76,16 @@ private String getVersionName(Context context, String packageName) {
return "";
}


private void loadPlugins(LoadPackageParam lpparam) {
try {
ADBlock.getInstance().hook(lpparam);
AntiRevoke.getInstance().hook(lpparam);
AntiSnsDelete.getInstance().hook(lpparam);
LuckMoney.getInstance().hook(lpparam);
AutoLogin.getInstance().hook(lpparam);
HideModule.getInstance().hook(lpparam);
} catch (Error | Exception e) {
log("loadPlugins error" + e);
for (IPlugin plugin:plugins) {
try {
plugin.hook(lpparam);
} catch (Error | Exception e) {
log("loadPlugins error" + e);
}
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,8 @@
import me.firesun.wechat.enhancement.util.HookParams;


public class ADBlock {
private static ADBlock instance = null;

private ADBlock() {
}

public static ADBlock getInstance() {
if (instance == null)
instance = new ADBlock();
return instance;
}

public class ADBlock implements IPlugin {
@Override
public void hook(XC_LoadPackage.LoadPackageParam lpparam) {
XposedHelpers.findAndHookMethod(HookParams.getInstance().XMLParserClassName, lpparam.classLoader, HookParams.getInstance().XMLParserMethod, String.class, String.class, new XC_MethodHook() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,12 @@
import me.firesun.wechat.enhancement.util.HookParams;


public class AntiRevoke {
private static AntiRevoke instance = null;
public class AntiRevoke implements IPlugin {
private static Map<Long, Object> msgCacheMap = new HashMap<>();
private static Object storageInsertClazz;

private AntiRevoke() {
}

public static AntiRevoke getInstance() {
if (instance == null)
instance = new AntiRevoke();
return instance;
}

public static void hook(XC_LoadPackage.LoadPackageParam lpparam) {
@Override
public void hook(XC_LoadPackage.LoadPackageParam lpparam) {
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) {
Expand Down Expand Up @@ -108,7 +99,7 @@ protected void afterHookedMethod(MethodHookParam param) {
});
}

private static void handleMessageRecall(ContentValues contentValues) {
private void handleMessageRecall(ContentValues contentValues) {
long msgId = contentValues.getAsLong("msgId");
Object msg = msgCacheMap.get(msgId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,8 @@
import static java.util.Arrays.copyOfRange;


public class AntiSnsDelete {
private static AntiSnsDelete instance = null;

private AntiSnsDelete() {
}

public static AntiSnsDelete getInstance() {
if (instance == null)
instance = new AntiSnsDelete();
return instance;
}


public class AntiSnsDelete implements IPlugin {
@Override
public void hook(XC_LoadPackage.LoadPackageParam lpparam) {

XposedHelpers.findAndHookMethod(HookParams.getInstance().SQLiteDatabaseClassName, lpparam.classLoader, HookParams.getInstance().SQLiteDatabaseUpdateMethod, String.class, ContentValues.class, String.class, String[].class, int.class, new XC_MethodHook() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,8 @@
import me.firesun.wechat.enhancement.util.HookParams;


public class AutoLogin {
private static AutoLogin instance = null;

private AutoLogin() {
}

public static AutoLogin getInstance() {
if (instance == null)
instance = new AutoLogin();
return instance;
}

public class AutoLogin implements IPlugin {
@Override
public void hook(XC_LoadPackage.LoadPackageParam lpparam) {
XposedHelpers.findAndHookMethod(android.app.Activity.class, "onStart", new XC_MethodHook() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,8 @@
import me.firesun.wechat.enhancement.util.HookParams;


public class HideModule {
private static HideModule instance = null;

private HideModule() {
}

public static HideModule getInstance() {
if (instance == null)
instance = new HideModule();
return instance;
}

public class HideModule implements IPlugin {
@Override
public void hook(XC_LoadPackage.LoadPackageParam lpparam) {
XposedHelpers.findAndHookMethod("android.app.ApplicationPackageManager", lpparam.classLoader, "getInstalledApplications", int.class, new XC_MethodHook() {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package me.firesun.wechat.enhancement.plugin;

import de.robv.android.xposed.callbacks.XC_LoadPackage;

public interface IPlugin {
public void hook(XC_LoadPackage.LoadPackageParam lpparam);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,11 @@
import static de.robv.android.xposed.XposedHelpers.newInstance;


public class LuckMoney {
private static LuckMoney instance = null;
public class LuckMoney implements IPlugin {
private static Object requestCaller;
private static List<LuckyMoneyMessage> luckyMoneyMessages = new ArrayList<>();

private LuckMoney() {
}

public static LuckMoney getInstance() {
if (instance == null)
instance = new LuckMoney();
return instance;
}

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


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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import android.os.Bundle;


public class Receiver extends BroadcastReceiver {
public class ConfigReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
Expand Down

0 comments on commit 95c7513

Please sign in to comment.