Fix SELinuxHelper
May still not work at some devices.............
This commit is contained in:
parent
e905664403
commit
ffa7ced044
|
|
@ -3,6 +3,8 @@ package com.elderdrivers.riru.edxp.proxy;
|
||||||
import com.elderdrivers.riru.edxp.config.ConfigManager;
|
import com.elderdrivers.riru.edxp.config.ConfigManager;
|
||||||
import com.elderdrivers.riru.edxp.deopt.PrebuiltMethodsDeopter;
|
import com.elderdrivers.riru.edxp.deopt.PrebuiltMethodsDeopter;
|
||||||
|
|
||||||
|
import de.robv.android.xposed.SELinuxHelper;
|
||||||
|
|
||||||
import static com.elderdrivers.riru.edxp.util.FileUtils.getDataPathPrefix;
|
import static com.elderdrivers.riru.edxp.util.FileUtils.getDataPathPrefix;
|
||||||
|
|
||||||
public class NormalProxy extends BaseProxy {
|
public class NormalProxy extends BaseProxy {
|
||||||
|
|
@ -18,6 +20,7 @@ public class NormalProxy extends BaseProxy {
|
||||||
String appDataDir) {
|
String appDataDir) {
|
||||||
// mainly for secondary zygote
|
// mainly for secondary zygote
|
||||||
mRouter.onForkStart();
|
mRouter.onForkStart();
|
||||||
|
SELinuxHelper.initOnce();
|
||||||
mRouter.initResourcesHook();
|
mRouter.initResourcesHook();
|
||||||
// call this to ensure the flag is set to false ASAP
|
// call this to ensure the flag is set to false ASAP
|
||||||
mRouter.prepare(false);
|
mRouter.prepare(false);
|
||||||
|
|
@ -36,6 +39,7 @@ public class NormalProxy extends BaseProxy {
|
||||||
public void forkSystemServerPre(int uid, int gid, int[] gids, int debugFlags, int[][] rlimits,
|
public void forkSystemServerPre(int uid, int gid, int[] gids, int debugFlags, int[][] rlimits,
|
||||||
long permittedCapabilities, long effectiveCapabilities) {
|
long permittedCapabilities, long effectiveCapabilities) {
|
||||||
mRouter.onForkStart();
|
mRouter.onForkStart();
|
||||||
|
SELinuxHelper.initOnce();
|
||||||
mRouter.initResourcesHook();
|
mRouter.initResourcesHook();
|
||||||
// set startsSystemServer flag used when loadModules
|
// set startsSystemServer flag used when loadModules
|
||||||
mRouter.prepare(true);
|
mRouter.prepare(true);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,11 @@
|
||||||
package de.robv.android.xposed;
|
package de.robv.android.xposed;
|
||||||
|
|
||||||
import android.os.SELinux;
|
import android.os.SELinux;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import de.robv.android.xposed.services.BaseService;
|
import de.robv.android.xposed.services.BaseService;
|
||||||
import de.robv.android.xposed.services.BinderService;
|
import de.robv.android.xposed.services.BinderService;
|
||||||
|
|
@ -28,7 +33,36 @@ public final class SELinuxHelper {
|
||||||
* @return A boolean indicating whether SELinux is enforcing.
|
* @return A boolean indicating whether SELinux is enforcing.
|
||||||
*/
|
*/
|
||||||
public static boolean isSELinuxEnforced() {
|
public static boolean isSELinuxEnforced() {
|
||||||
return sIsSELinuxEnabled && SELinux.isSELinuxEnforced();
|
if (!sIsSELinuxEnabled) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
boolean result = false;
|
||||||
|
final File SELINUX_STATUS_FILE = new File("/sys/fs/selinux/enforce");
|
||||||
|
if (SELINUX_STATUS_FILE.exists()) {
|
||||||
|
try {
|
||||||
|
FileInputStream fis = new FileInputStream(SELINUX_STATUS_FILE);
|
||||||
|
int status = fis.read();
|
||||||
|
switch (status) {
|
||||||
|
case 49:
|
||||||
|
result = true;
|
||||||
|
break;
|
||||||
|
case 48:
|
||||||
|
result = false;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
XposedBridge.log("Unexpected byte " + status + " in /sys/fs/selinux/enforce");
|
||||||
|
}
|
||||||
|
fis.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
if (e.getMessage().contains("Permission denied")) {
|
||||||
|
result = true;
|
||||||
|
} else {
|
||||||
|
XposedBridge.log("Failed to read SELinux status: " + e.getMessage());
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -56,14 +90,15 @@ public final class SELinuxHelper {
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
// TODO: SELinux status
|
||||||
private static boolean sIsSELinuxEnabled = false;
|
private static boolean sIsSELinuxEnabled = false;
|
||||||
private static BaseService sServiceAppDataFile = new DirectAccessService(); // ed: initialized directly
|
private static BaseService sServiceAppDataFile = new DirectAccessService(); // ed: initialized directly
|
||||||
|
|
||||||
/*package*/ static void initOnce() {
|
/*package*/ public static void initOnce() {
|
||||||
// ed: we assume all selinux policies have been added lively using magiskpolicy
|
// ed: we assume all selinux policies have been added lively using magiskpolicy
|
||||||
// try {
|
try {
|
||||||
// sIsSELinuxEnabled = SELinux.isSELinuxEnabled();
|
sIsSELinuxEnabled = SELinux.isSELinuxEnabled();
|
||||||
// } catch (NoClassDefFoundError ignored) {}
|
} catch (NoClassDefFoundError ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ static void initForProcess(String packageName) {
|
/*package*/ static void initForProcess(String packageName) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue