前言

简单记录一下关闭SELinux的命令或代码。

正文

获取SELinux状态

adb shell getenforce

返回值有两个

Permissive //关闭了SELinux

Enforcing //打开了SELinux

临时方法

前提设备已root了哈

临时的话,就是用adb来改变。

adb shell setenforce 1 或 0
  1. setenforce 0设置为permissive模式;

  2. setenforce 1 设置为enforcing模式;

改变后可以用adb shell getenforce获取状态。

重启后又恢复默认模式

永久方法

这个就是改代码啦。

Android 13

selinux.cpp
system\core\init\selinux.cpp
修改前
bool IsEnforcing() {
    {
        int fd(open("/mboot/selinux", O_RDONLY | O_CLOEXEC | O_BINARY));
        if (fd != -1) {
            char v = 0xff;
            if (read(fd, &v, 1) < 0)
                PLOG(ERROR) << "Failed to read /mboot/selinux";
            close(fd);
            LOG(WARNING) << "/mboot/selinux is " << v;
            return v == '1';
        }
    }
    if (ALLOW_PERMISSIVE_SELINUX) {
        return StatusFromProperty() == SELINUX_ENFORCING;
    }
    return true;
}
修改后
bool IsEnforcing() {
    //biumall.com add start
    return false; 
    //biumall.com add end
    {
        int fd(open("/mboot/selinux", O_RDONLY | O_CLOEXEC | O_BINARY));
        if (fd != -1) {
            char v = 0xff;
            if (read(fd, &v, 1) < 0)
                PLOG(ERROR) << "Failed to read /mboot/selinux";
            close(fd);
            LOG(WARNING) << "/mboot/selinux is " << v;
            return v == '1';
        }
    }
    if (ALLOW_PERMISSIVE_SELINUX) {
        return StatusFromProperty() == SELINUX_ENFORCING;
    }
    return true;
}

这种我验证OK。

参考文章

  1. 查看SELinux状态及关闭SELinux

  2. 代码里永久关闭selinux

相关文章

暂无评论

none
暂无评论...