Skip to content

Commit 219d2df

Browse files
Parse KSU allowlist and fix getDenylist function (ThePedroo#8)
Use isInDenylist JNI method to get denylist packages and Refactor related codes.
1 parent bee493b commit 219d2df

File tree

7 files changed

+447
-399
lines changed

7 files changed

+447
-399
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ public class ConfigFileManager {
8686
static final Path modulePath = basePath.resolve("modules");
8787
static final Path daemonApkPath = Paths.get(System.getProperty("java.class.path", null));
8888
static final Path managerApkPath = daemonApkPath.getParent().resolve("manager.apk");
89-
static final File magiskDbPath = new File("/data/adb/magisk.db");
9089
private static final Path lockPath = basePath.resolve("lock");
9190
private static final Path configDirPath = basePath.resolve("config");
9291
static final File dbPath = configDirPath.resolve("modules_config.db").toFile();

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

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,25 +1217,18 @@ private void removeModulePrefs(int uid, String packageName) throws IOException {
12171217

12181218
public List<String> getDenyListPackages() {
12191219
List<String> result = new ArrayList<>();
1220-
if (!getApi().equals("Zygisk")) return result;
1221-
if (!ConfigFileManager.magiskDbPath.exists()) return result;
1222-
try (final SQLiteDatabase magiskDb =
1223-
SQLiteDatabase.openDatabase(ConfigFileManager.magiskDbPath, new SQLiteDatabase.OpenParams.Builder().addOpenFlags(SQLiteDatabase.OPEN_READONLY).build())) {
1224-
try (Cursor cursor = magiskDb.query("settings", new String[]{"value"}, "`key`=?", new String[]{"denylist"}, null, null, null)) {
1225-
if (!cursor.moveToNext()) return result;
1226-
int valueIndex = cursor.getColumnIndex("value");
1227-
if (valueIndex >= 0 && cursor.getInt(valueIndex) == 0) return result;
1220+
if(!isInjectionHardeningEnabled())
1221+
{
1222+
try
1223+
{
1224+
List<PackageInfo> infos = PackageService.getInstalledPackagesFromAllUsers(PackageService.MATCH_ALL_FLAGS, false).getList();
1225+
return infos.parallelStream()
1226+
.filter(info -> DenylistManager.isInDenylist(info.packageName))
1227+
.map(info -> info.packageName)
1228+
.collect(Collectors.toList());
1229+
} catch (Throwable e) {
1230+
Log.e(TAG, "get denylist", e);
12281231
}
1229-
try (Cursor cursor = magiskDb.query(true, "denylist", new String[]{"package_name"}, null, null, null, null, null, null, null)) {
1230-
if (cursor == null) return result;
1231-
int packageNameIdx = cursor.getColumnIndex("package_name");
1232-
while (cursor.moveToNext()) {
1233-
result.add(cursor.getString(packageNameIdx));
1234-
}
1235-
return result;
1236-
}
1237-
} catch (Throwable e) {
1238-
Log.e(TAG, "get denylist", e);
12391232
}
12401233
return result;
12411234
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* This file is part of ReLSPosed.
3+
*
4+
* ReLSPosed 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+
* ReLSPosed 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 ReLSPosed. If not, see <https://www.gnu.org/licenses/>.
16+
*
17+
* Copyright (C) 2023 The PerformanC Organization Contributors
18+
*/
19+
// ------------------------------------------------------------------------------------------------------------------------------------------------
20+
/* INFO: Code below contains parts of the code of the ReZygisk's Daemon. It is protected by its AGPL 3.0.0 license by The PerformanC Organization.
21+
See https://github.com/PerformanC/ReZygisk repository for more details. */
22+
// ------------------------------------------------------------------------------------------------------------------------------------------------
23+
24+
package org.lsposed.lspd.service;
25+
26+
public class DenylistManager {
27+
native static boolean isInDenylist(String processName);
28+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import static org.lsposed.lspd.ILSPManagerService.DEX2OAT_SELINUX_PERMISSIVE;
2626
import static org.lsposed.lspd.ILSPManagerService.DEX2OAT_SEPOLICY_INCORRECT;
2727

28+
import static org.lsposed.lspd.service.DenylistManager.isInDenylist;
29+
2830
import android.net.LocalServerSocket;
2931
import android.os.Build;
3032
import android.os.FileObserver;
@@ -346,6 +348,4 @@ private native void doMountNative(boolean enabled,
346348
private static native boolean setSockCreateContext(String context);
347349

348350
private native String getSockPath();
349-
350-
private native boolean isInDenylist(String processName);
351351
}

daemon/src/main/jni/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ add_subdirectory(${EXTERNAL_ROOT} external)
55

66
set(SOURCES
77
dex2oat.cpp
8+
denylist.cpp
89
logcat.cpp
910
obfuscation.cpp
1011
)

0 commit comments

Comments
 (0)