Skip to content

Commit bee493b

Browse files
Add Disable Injection Hardening Toggle in settings. (ThePedroo#7)
* Add Disable Injection Hardening Toggle in settings. * Fix strings.xml: No need to reboot. To Disable/Re-enable Injection Hardening
1 parent d1571e5 commit bee493b

File tree

8 files changed

+127
-0
lines changed

8 files changed

+127
-0
lines changed

app/src/main/java/org/lsposed/manager/ConfigManager.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,4 +409,23 @@ public static boolean setAutoInclude(String packageName, boolean enable) {
409409
return false;
410410
}
411411
}
412+
413+
public static boolean isInjectionHardeningEnabled() {
414+
try {
415+
return LSPManagerServiceHolder.getService().isInjectionHardeningEnabled();
416+
} catch (RemoteException e) {
417+
Log.e(App.TAG, Log.getStackTraceString(e));
418+
return false;
419+
}
420+
}
421+
422+
public static boolean setInjectionHardening(boolean enabled) {
423+
try {
424+
LSPManagerServiceHolder.getService().setInjectionHardening(enabled);
425+
return true;
426+
} catch (RemoteException e) {
427+
Log.e(App.TAG, Log.getStackTraceString(e));
428+
return false;
429+
}
430+
}
412431
}

app/src/main/java/org/lsposed/manager/ui/fragment/SettingsFragment.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
169169
prefLogWatchDog.setOnPreferenceChangeListener((preference, newValue) -> ConfigManager.setLogWatchdog((boolean) newValue));
170170
}
171171

172+
MaterialSwitchPreference prefInjectionHardening = findPreference("disable_injection_hardening");
173+
if (prefInjectionHardening != null) {
174+
prefInjectionHardening.setChecked(!installed || ConfigManager.isInjectionHardeningEnabled());
175+
prefInjectionHardening.setOnPreferenceChangeListener((preference, newValue) -> ConfigManager.setInjectionHardening((boolean) newValue));
176+
}
177+
172178
MaterialSwitchPreference prefDexObfuscate = findPreference("enable_dex_obfuscate");
173179
if (prefDexObfuscate != null) {
174180
prefDexObfuscate.setEnabled(installed);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!--
2+
~ This file is part of LSPosed.
3+
~
4+
~ LSPosed is free software: you can redistribute it and/or modify
5+
~ it under the terms of the GNU General Public License as published by
6+
~ the Free Software Foundation, either version 3 of the License, or
7+
~ (at your option) any later version.
8+
~
9+
~ LSPosed is distributed in the hope that it will be useful,
10+
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
~ GNU General Public License for more details.
13+
~
14+
~ You should have received a copy of the GNU General Public License
15+
~ along with LSPosed. If not, see <https://www.gnu.org/licenses/>.
16+
~
17+
~ Copyright (C) 2022 LSPosed Contributors
18+
-->
19+
20+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
21+
android:width="24dp"
22+
android:height="24dp"
23+
android:viewportWidth="24"
24+
android:viewportHeight="24"
25+
android:tint="?attr/colorControlNormal">
26+
<path
27+
android:fillColor="@android:color/white"
28+
android:pathData="M12 2L4 5v6.09c0 5.05 3.41 9.76 8 10.91c4.59-1.15 8-5.86 8-10.91V5l-8-3zm6 9.09c0 4-2.55 7.7-6 8.83c-3.45-1.13-6-4.82-6-8.83v-4.7l6-2.25l6 2.25v4.7z" />
29+
30+
<path
31+
android:fillColor="@android:color/white"
32+
android:pathData="M4.22676 4.22676C4.5291 3.92441 5.01929 3.92441 5.32163 4.22676L12 10.9051L18.6784 4.22676C18.9807 3.92441 19.4709 3.92441 19.7732 4.22676C20.0756 4.5291 20.0756 5.01929 19.7732 5.32163L13.0949 12L19.7732 18.6784C20.0756 18.9807 20.0756 19.4709 19.7732 19.7732C19.4709 20.0756 18.9807 20.0756 18.6784 19.7732L12 13.0949L5.32163 19.7732C5.01929 20.0756 4.5291 20.0756 4.22676 19.7732C3.92441 19.4709 3.92441 18.9807 4.22676 18.6784L10.9051 12L4.22676 5.32163C3.92441 5.01929 3.92441 4.5291 4.22676 4.22676Z" />
33+
</vector>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@
172172
<string name="settings_group_framework">Framework</string>
173173
<string name="settings_disable_verbose_log">Disable verbose logs</string>
174174
<string name="settings_disable_verbose_log_summary">Verbose logs are required to report issues</string>
175+
<string name="settings_disable_injection_hardening">Disable Injection Hardening</string>
176+
<string name="settings_disable_injection_hardening_summary">Target Apps and Modules need not be removed from denylist / umount list for LSPosed but lose benefit of hardening. No need to reboot.</string>
175177
<string name="settings_enable_log_watchdog">Enable log watchdog</string>
176178
<string name="settings_enable_log_watchdog_summary">Log watchdog of LSPosed modifies system properties, which could be exploited to detect LSPosed</string>
177179
<string name="pure_black_dark_theme">Black dark theme</string>

app/src/main/res/xml/prefs.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@
121121
android:shouldDisableView="false"
122122
android:summary="@string/settings_enable_status_notification_summary"
123123
android:title="@string/settings_enable_status_notification" />
124+
125+
<rikka.material.preference.MaterialSwitchPreference
126+
android:defaultValue="false"
127+
android:icon="@drawable/ic_outline_shield_x_24"
128+
android:key="disable_injection_hardening"
129+
android:persistent="false"
130+
android:summary="@string/settings_disable_injection_hardening_summary"
131+
android:title="@string/settings_disable_injection_hardening" />
124132
</PreferenceCategory>
125133

126134
<PreferenceCategory android:title="@string/settings_group_repo">

daemon/src/main/java/org/lsposed/lspd/service/ConfigManager.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,12 @@ public class ConfigManager {
9595

9696
private final SQLiteDatabase db = openDb();
9797

98+
static final Path basePath = Paths.get("/data/adb/lspd");
99+
98100
private boolean verboseLog = true;
99101
private boolean logWatchdog = true;
100102
private boolean dexObfuscate = true;
103+
private boolean injectionHardening = true;
101104
private boolean enableStatusNotification = true;
102105
private Path miscPath = null;
103106

@@ -272,6 +275,9 @@ private synchronized void updateConfig() {
272275

273276
bool = config.get("enable_log_watchdog");
274277
logWatchdog = bool == null || (boolean) bool;
278+
279+
bool = config.get("disable_injection_hardening");
280+
injectionHardening = bool == null || (boolean) bool;
275281

276282
bool = config.get("enable_dex_obfuscate");
277283
dexObfuscate = bool == null || (boolean) bool;
@@ -1035,6 +1041,45 @@ public boolean isLogWatchdogEnabled() {
10351041
return logWatchdog;
10361042
}
10371043

1044+
public void setInjectionHardening(boolean on) {
1045+
File configFile = new File("/data/adb/disable_injection_hardening");
1046+
if (on) {
1047+
try {
1048+
if(!configFile.exists()) {
1049+
configFile.createNewFile();
1050+
}
1051+
Os.chmod(configFile.getAbsolutePath(), 0644);
1052+
Log.d(TAG, "injection hardening enabled");
1053+
updateModulePrefs("lspd", 0, "config", "disable_injection_hardening", on);
1054+
injectionHardening = on;
1055+
}
1056+
catch (Throwable e) {
1057+
Log.e(TAG, "failed to create config file for injection hardening", e);
1058+
return;
1059+
}
1060+
} else {
1061+
try {
1062+
if(configFile.exists()) {
1063+
configFile.delete();
1064+
}
1065+
Log.d(TAG, "injection hardening disabled");
1066+
updateModulePrefs("lspd", 0, "config", "disable_injection_hardening", on);
1067+
injectionHardening = on;
1068+
}
1069+
catch (Throwable e) {
1070+
Log.e(TAG, "failed to delete config file for injection hardening", e);
1071+
return;
1072+
}
1073+
}
1074+
}
1075+
1076+
public boolean isInjectionHardeningEnabled() {
1077+
File configFile = new File("/data/adb/disable_injection_hardening");
1078+
injectionHardening = configFile.exists();
1079+
updateModulePrefs("lspd", 0, "config", "disable_injection_hardening", injectionHardening);
1080+
return injectionHardening;
1081+
}
1082+
10381083
public void setDexObfuscate(boolean on) {
10391084
updateModulePrefs("lspd", 0, "config", "enable_dex_obfuscate", on);
10401085
}

daemon/src/main/java/org/lsposed/lspd/service/LSPManagerService.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,16 @@ public void setLogWatchdog(boolean enabled) {
556556
public boolean isLogWatchdogEnabled() {
557557
return ConfigManager.getInstance().isLogWatchdogEnabled();
558558
}
559+
560+
@Override
561+
public void setInjectionHardening(boolean enabled) {
562+
ConfigManager.getInstance().setInjectionHardening(enabled);
563+
}
564+
565+
@Override
566+
public boolean isInjectionHardeningEnabled() {
567+
return ConfigManager.getInstance().isInjectionHardeningEnabled();
568+
}
559569

560570
@Override
561571
public boolean setAutoInclude(String packageName, boolean enabled) {

services/manager-service/src/main/aidl/org/lsposed/lspd/ILSPManagerService.aidl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,8 @@ interface ILSPManagerService {
9595
boolean getAutoInclude(String packageName) = 51;
9696

9797
boolean setAutoInclude(String packageName, boolean enable) = 52;
98+
99+
void setInjectionHardening(boolean enable) = 53;
100+
101+
boolean isInjectionHardeningEnabled() = 54;
98102
}

0 commit comments

Comments
 (0)