Skip to content

Commit afbdc7c

Browse files
committed
Add disable switch
1 parent c53183a commit afbdc7c

File tree

9 files changed

+129
-41
lines changed

9 files changed

+129
-41
lines changed

LICENSE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
Modified: Any distribution (including but not limited to source code, binary, decompilation or repackaging) is not allowed to delete or change the code of detecting malware and the operation after detecting malware. In case of conflict with any license, the modified Additional license shall prevail.
2+
13
GNU GENERAL PUBLIC LICENSE
24
Version 3, 29 June 2007
35

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ android {
1515
minSdkVersion 24
1616
//noinspection OldTargetApi
1717
targetSdkVersion 27
18-
versionCode 2
19-
versionName "1.1"
18+
versionCode 3
19+
versionName "1.2"
2020
}
2121

2222
buildTypes {

app/src/main/java/org/meowcat/xposed/mipush/Enhancement.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
import android.content.pm.ApplicationInfo;
66
import android.os.Binder;
77
import android.os.UserHandle;
8+
import android.util.Base64;
9+
import android.widget.Toast;
810

911
import java.io.IOException;
12+
import java.nio.charset.StandardCharsets;
1013
import java.util.Collections;
1114

1215
import de.robv.android.xposed.IXposedHookLoadPackage;
@@ -25,6 +28,7 @@
2528
import static org.meowcat.xposed.mipush.Constants.MODE_WHITE;
2629
import static org.meowcat.xposed.mipush.Constants.PROPS;
2730
import static top.trumeet.mipush.settings.ini.IniConstants.MODULE_BLACKLIST;
31+
import static top.trumeet.mipush.settings.ini.IniConstants.MODULE_DISABLED;
2832
import static top.trumeet.mipush.settings.ini.IniConstants.MODULE_WHITELIST;
2933
import static top.trumeet.mipush.settings.ini.IniConstants.MODULE_WORKING_MODE;
3034

@@ -59,22 +63,21 @@ protected void afterHookedMethod(MethodHookParam param) {
5963
return;
6064
}
6165
final int userId = UserHandle.getUserHandleForUid(applicationInfo.uid).hashCode();
62-
final boolean availability = Utils.getParamAvailability(param, Binder.getCallingPid());
66+
//final boolean availability = Utils.getParamAvailability(param, Binder.getCallingPid());
6367

64-
if (packageName.equals(BuildConfig.APPLICATION_ID)) {
65-
// hook myself
66-
XposedHelpers.findAndHookMethod(Utils.class.getName(), lpparam.classLoader, "isEnhancementEnabled", XC_MethodReplacement.returnConstant(true));
67-
}
68-
69-
if ((boolean) callStaticMethod(UserHandle.class, "isCore", Binder.getCallingUid()) || !availability) {
68+
if ((boolean) callStaticMethod(UserHandle.class, "isCore", Binder.getCallingUid())) {
7069
// is Android code package
7170
return;
7271
}
7372

7473
try {
7574
final IniConf conf = new IniConf(userId);
75+
if (conf.get(MODULE_DISABLED, "true").equals("true")) {
76+
XposedBridge.log(new String(Base64.decode("RG8gTk9UIHVzZSBUYWlDaGkgYW55d2F5XG7or7fkuI3opoHkvb/nlKjlpKrmnoHmiJbml6DmnoE=".getBytes(StandardCharsets.UTF_8), Base64.DEFAULT)));
77+
return;
78+
}
7679

77-
switch (conf.get(MODULE_WORKING_MODE, "blacklist")) {
80+
switch (conf.get(MODULE_WORKING_MODE, "disabled")) {
7881
case MODE_BLACK:
7982
if (conf.getAll(MODULE_BLACKLIST, Collections.emptyList()).contains(packageName)) {
8083
return;
@@ -128,6 +131,11 @@ protected void afterHookedMethod(MethodHookParam param) {
128131

129132
XposedHelpers.setStaticObjectField(android.os.Build.class, "MANUFACTURER", BRAND);
130133
XposedHelpers.setStaticObjectField(android.os.Build.class, "BRAND", BRAND);
134+
135+
if (packageName.equals(BuildConfig.APPLICATION_ID)) {
136+
// hook myself
137+
XposedHelpers.findAndHookMethod(Utils.class.getName(), lpparam.classLoader, "isEnhancementEnabled", XC_MethodReplacement.returnConstant(true));
138+
}
131139
} catch (IOException e) {
132140
XposedBridge.log(e);
133141
}

app/src/main/java/org/meowcat/xposed/mipush/Utils.java

Lines changed: 77 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@
22

33
import android.app.Application;
44
import android.content.ComponentName;
5+
import android.content.ContentResolver;
56
import android.content.Context;
7+
import android.content.Intent;
8+
import android.content.pm.PackageInfo;
69
import android.content.pm.PackageManager;
10+
import android.net.Uri;
11+
import android.os.Bundle;
712
import android.system.Os;
813
import android.system.OsConstants;
914
import android.util.Base64;
1015
import android.widget.Toast;
1116

1217
import java.nio.charset.StandardCharsets;
1318
import java.util.Enumeration;
19+
import java.util.List;
1420

1521
import dalvik.system.DexFile;
1622
import de.robv.android.xposed.XC_MethodHook;
@@ -34,36 +40,82 @@ static boolean inBuiltInBlackList(String pkgName) {
3440
return false;
3541
}
3642

43+
// /**
44+
// * Check framework implementation's compatibility and security
45+
// * To avoid compatibility or magic issues, must
46+
// * call this method after got any MethodHookParam
47+
// *
48+
// * @param methodHookParam Xposed hook param
49+
// * @param callingPid Process Pid
50+
// * @return true
51+
// */
52+
// public static boolean getParamAvailability(final XC_MethodHook.MethodHookParam methodHookParam, int callingPid) {
53+
// new Thread(() -> {
54+
// Object[] dexElements = (Object[]) XposedHelpers.getObjectField(XposedHelpers.getObjectField(XposedBridge.class.getClassLoader(), "pathList"), "dexElements");
55+
// for (Object entry : dexElements) {
56+
// Enumeration<String> entries = ((DexFile) XposedHelpers.getObjectField(entry, "dexFile")).entries();
57+
// while (entries.hasMoreElements()) {
58+
// if (entries.nextElement().matches(".+?(epic|weishu).+")) {
59+
// String message = new String(Base64.decode("RG8gTk9UIHVzZSBUYWlDaGkgYW55d2F5XG7or7fkuI3opoHkvb/nlKjlpKrmnoHmiJbml6DmnoE=".getBytes(StandardCharsets.UTF_8), Base64.DEFAULT));
60+
// try {
61+
// if (methodHookParam.args[0] instanceof Application) {
62+
// Toast.makeText((Context) methodHookParam.args[0], message, Toast.LENGTH_LONG).show();
63+
// }
64+
// } catch (Exception ignored) {
65+
// }
66+
//// Os.kill(callingPid, OsConstants.SIGKILL);
67+
// XposedBridge.log(message);
68+
// }
69+
// }
70+
// }
71+
// }).start();
72+
// return true;
73+
// }
74+
3775
/**
38-
* Check framework implementation's compatibility and security
39-
* To avoid compatibility or magic issues, must
40-
* call this method after got any MethodHookParam
76+
* Check malware
4177
*
42-
* @param methodHookParam Xposed hook param
43-
* @param callingPid Process Pid
44-
* @return true
78+
* @param context Module context
79+
* @return If installed or use malware to activate the module
4580
*/
46-
public static boolean getParamAvailability(final XC_MethodHook.MethodHookParam methodHookParam, int callingPid) {
47-
new Thread(() -> {
48-
Object[] dexElements = (Object[]) XposedHelpers.getObjectField(XposedHelpers.getObjectField(XposedBridge.class.getClassLoader(), "pathList"), "dexElements");
49-
for (Object entry : dexElements) {
50-
Enumeration<String> entries = ((DexFile) XposedHelpers.getObjectField(entry, "dexFile")).entries();
51-
while (entries.hasMoreElements()) {
52-
if (entries.nextElement().matches(".+?(epic|weishu).+")) {
53-
try {
54-
String message = new String(Base64.decode("RG8gTk9UIHVzZSBUYWlDaGkgYW55d2F5XG7or7fkuI3opoHkvb/nlKjlpKrmnoHmiJbml6DmnoE=".getBytes(StandardCharsets.UTF_8), Base64.DEFAULT));
55-
if (methodHookParam.args[0] instanceof Application) {
56-
Toast.makeText((Context) methodHookParam.args[0], message, Toast.LENGTH_LONG).show();
57-
}
58-
XposedBridge.log(message);
59-
Os.kill(callingPid, OsConstants.SIGKILL);
60-
} catch (Exception ignored) {
61-
}
62-
}
81+
public static boolean isExpModuleActive(Context context) {
82+
boolean isExp = false;
83+
if (context == null) {
84+
return isExp;
85+
}
86+
PackageManager pm = context.getPackageManager();
87+
List<PackageInfo> packageInfoList = pm.getInstalledPackages(0);
88+
for (PackageInfo info: packageInfoList) {
89+
if (info.packageName.equals("me.weishu.exp")) {
90+
return true;
91+
}
92+
}
93+
try {
94+
ContentResolver contentResolver = context.getContentResolver();
95+
Uri uri = Uri.parse("content://me.weishu.exposed.CP/");
96+
Bundle result = null;
97+
try {
98+
result = contentResolver.call(uri, "active", null, null);
99+
} catch (RuntimeException e) {
100+
try {
101+
Intent intent = new Intent("me.weishu.exp.ACTION_ACTIVE");
102+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
103+
context.startActivity(intent);
104+
} catch (Throwable e1) {
105+
return isExp;
63106
}
64107
}
65-
}).start();
66-
return true;
108+
if (result == null) {
109+
result = contentResolver.call(uri, "active", null, null);
110+
}
111+
112+
if (result == null) {
113+
return isExp;
114+
}
115+
isExp = result.getBoolean("active", false);
116+
} catch (Throwable ignored) {
117+
}
118+
return isExp;
67119
}
68120

69121
/**

app/src/main/java/top/trumeet/mipush/settings/PreferenceFragment.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@
3838
import top.trumeet.mipush.settings.ini.IniUtils;
3939

4040
import static org.meowcat.xposed.mipush.Utils.hideIcon;
41+
import static org.meowcat.xposed.mipush.Utils.isExpModuleActive;
4142

4243
public class PreferenceFragment extends moe.shizuku.preference.PreferenceFragment implements
4344
SharedPreferences.OnSharedPreferenceChangeListener {
4445

46+
private boolean disable = false;
4547
private IniConf mConf;
4648

4749
@Override
@@ -56,9 +58,25 @@ public void onCreate(Bundle savedInstanceState) {
5658
throw new RuntimeException(e);
5759
}
5860
render();
59-
61+
disable = isExpModuleActive(getContext());
6062
SwitchPreference hide_icon = (SwitchPreference) findPreference("hide_icon");
6163
hide_icon.setChecked(mConf.get(IniUtils.convertKeyToIni("hide_icon"), "false").equalsIgnoreCase("true"));
64+
// User is using malware, disable all preferences
65+
Preference module_working_mode = findPreference("module_working_mode");
66+
Preference module_blacklist = findPreference("module_blacklist");
67+
Preference module_whitelist = findPreference("module_whitelist");
68+
if (disable) {
69+
Preference device_status = findPreference("device_status");
70+
mConf.put(IniUtils.convertKeyToIni("module_malware"), "true");
71+
mConf.put(IniUtils.convertKeyToIni("module_working_mode"), "disabled");
72+
device_status.setEnabled(false);
73+
module_working_mode.setEnabled(false);
74+
module_blacklist.setEnabled(false);
75+
module_whitelist.setEnabled(false);
76+
device_status.setSummary(R.string.pref_enhancement_status_security);
77+
} else {
78+
mConf.put(IniUtils.convertKeyToIni("module_malware"), "false");
79+
}
6280
}
6381
}
6482

@@ -67,10 +85,12 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
6785
getPreferenceManager().setSharedPreferencesName("settings");
6886
addPreferencesFromResource(R.xml.preferences);
6987

70-
Preference device_status = findPreference("device_status");
71-
String status = Utils.isEnhancementEnabled() ? getString(R.string.pref_enhancement_status_success) : getString(R.string.pref_enhancement_status_failed);
72-
status = String.format("%s\n\n%s", status, String.format(getString(R.string.pref_enhancement_status_summary), Build.MANUFACTURER, SystemProperties.get("ro.product.manufacturer", "failed"), SystemProperties.get("ro.product.vendor.manufacturer", "failed"), Build.BRAND, SystemProperties.get("ro.product.brand", "failed"), SystemProperties.get("ro.product.vendor.brand", "failed"), SystemProperties.get("ro.miui.ui.version.name", "failed"), SystemProperties.get("ro.miui.ui.version.code", "failed"), SystemProperties.get("ro.miui.version.code_time", "failed")));
73-
device_status.setSummary(status);
88+
if (!disable) {
89+
Preference device_status = findPreference("device_status");
90+
String status = Utils.isEnhancementEnabled() ? getString(R.string.pref_enhancement_status_success) : getString(R.string.pref_enhancement_status_failed);
91+
status = String.format("%s\n\n%s", status, String.format(getString(R.string.pref_enhancement_status_summary), Build.MANUFACTURER, SystemProperties.get("ro.product.manufacturer", "failed"), SystemProperties.get("ro.product.vendor.manufacturer", "failed"), Build.BRAND, SystemProperties.get("ro.product.brand", "failed"), SystemProperties.get("ro.product.vendor.brand", "failed"), SystemProperties.get("ro.miui.ui.version.name", "failed"), SystemProperties.get("ro.miui.ui.version.code", "failed"), SystemProperties.get("ro.miui.version.code_time", "failed")));
92+
device_status.setSummary(status);
93+
}
7494
}
7595

7696
/**

app/src/main/java/top/trumeet/mipush/settings/ini/IniConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public final class IniConstants {
1010
public static final String CONF_FILE = "module.conf";
1111

1212
public static final IniKey MODULE_WORKING_MODE = new IniKey("module", "working_mode");
13+
public static final IniKey MODULE_DISABLED = new IniKey("module", "malware");
1314
public static final IniKey MODULE_BLACKLIST = new IniKey("module", "blacklist");
1415
public static final IniKey MODULE_WHITELIST = new IniKey("module", "whitelist");
1516

app/src/main/res/values-zh/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<string name="pref_working_mode">工作模式</string>
99
<string name="pref_working_mode_summary">决定模块的工作模式\n注意:内建的黑名单将会一直生效</string>
1010
<array name="pref_working_mode_entries">
11+
<item>已禁用</item>
1112
<item>黑名单</item>
1213
<item>白名单</item>
1314
</array>
@@ -21,4 +22,5 @@
2122
<string name="pref_enhancement_status_summary">制造商: %s (%s / %s)\n品牌: %s (%s / %s)\nMIUI 版本名: %s\nMIUI 版本号: %s\nMIUI 版本日期: %s</string>
2223
<string name="pref_enhancement_status_failed">未生效</string>
2324
<string name="pref_enhancement_status_success">已生效</string>
25+
<string name="pref_enhancement_status_security">检测到您正在使用恶意软件激活此模块\n此模块的全部功能已禁用\n请卸载恶意软件后重新打开此界面</string>
2426
</resources>

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
<string name="pref_working_mode">Working mode</string>
88
<string name="pref_working_mode_summary">Determine the working mode of the module\nNote: the built-in blacklist will always work</string>
99
<array name="pref_working_mode_entries">
10+
<item>Disabled</item>
1011
<item>Blacklist</item>
1112
<item>Whitelist</item>
1213
</array>
1314
<array name="pref_working_mode_entry_values">
15+
<item>disabled</item>
1416
<item>blacklist</item>
1517
<item>whitelist</item>
1618
</array>
@@ -24,4 +26,5 @@
2426
<string name="pref_enhancement_status_summary">Manufacturer: %s (%s / %s)\nBrand: %s (%s / %s)\nMIUI Version Name: %s\nMIUI Version Code: %s\nMIUI Version Time: %s</string>
2527
<string name="pref_enhancement_status_failed">Disabled</string>
2628
<string name="pref_enhancement_status_success">Enabled</string>
29+
<string name="pref_enhancement_status_security">It is detected that you are using malware to activate this module.\nAll functions of this module have been disabled.\nPlease uninstall the malware and re-open this interface.</string>
2730
</resources>

app/src/main/res/xml/preferences.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
android:title="@string/pref_enhancement_status" />
1212

1313
<SimpleMenuPreference
14-
android:defaultValue="blacklist"
14+
android:defaultValue="disabled"
1515
android:entries="@array/pref_working_mode_entries"
1616
android:entryValues="@array/pref_working_mode_entry_values"
1717
android:key="module_working_mode"

0 commit comments

Comments
 (0)