Android7.1 ROOT权限的获取

修改文件:

system/extras/su/su.c

system/core/include/private/android_filesystem_config.h

system/core/libcutils/fs_config.c

frameworks/base/core/jni/com_android_internal_os_Zygote.cpp

frameworks/base/cmds/app_process/app_main.cpp

device/qcom/msm8909/BoardConfig.mk

目的:为了在应用层App中可以通过调用su来获取root权限,进而执行一些命令。

system/extras/su/su.c

在"main"函数中,注释掉uid的验证条件:

    //uid_t current_uid = getuid();
    //if (current_uid != AID_ROOT && current_uid != AID_SHELL) error(1, 0, "not allowed");

system/core/libcutils/fs_config.c

修改su程序的权限配置相关的内容:

    /* the following two files are INTENTIONALLY set-uid, but they
     * are NOT included on user builds. */
    { 06755, AID_ROOT,      AID_SHELL,     0, "system/xbin/su" },

frameworks/base/core/jni/com_android_internal_os_Zygote.cpp

注释掉如下内容:

static void DropCapabilitiesBoundingSet(JNIEnv* env) {
/*
  for (int i = 0; prctl(PR_CAPBSET_READ, i, 0, 0, 0) >= 0; i++) {
    int rc = prctl(PR_CAPBSET_DROP, i, 0, 0, 0);
    if (rc == -1) {
      if (errno == EINVAL) {
        ALOGE("prctl(PR_CAPBSET_DROP) failed with EINVAL. Please verify "
              "your kernel is compiled with file capabilities support");
      } else {
        RuntimeAbort(env, __LINE__, "prctl(PR_CAPBSET_DROP) failed");
      }
    }
  }
*/
}

frameworks/base/cmds/app_process/app_main.cpp

注释"main"函数中的如下内容:

/*  
    if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) < 0) {
        // Older kernels don't understand PR_SET_NO_NEW_PRIVS and return
        // EINVAL. Don't die on such kernels.
        if (errno != EINVAL) {
            LOG_ALWAYS_FATAL("PR_SET_NO_NEW_PRIVS failed: %s", strerror(errno));
            return 12;
        }
    }
*/

device/qcom/msm8909/BoardConfig.mk

在启动参数"BOARD_KERNEL_CMDLINE"中加入对SELinux的设置"androidboot.selinux=permissive",放宽权限:

BOARD_KERNEL_CMDLINE := console=ttyHSL0,115200,n8 androidboot.selinux=permissive androidboot.console=ttyHSL0 androidboot.hardware=qcom msm_rtb.filter=0x237 ehci-hcd.park=3 androidboot.bootdevice=7824900.sdhci lpm_levels.sleep_disabled=1 earlyprintk

或者

BOARD_KERNEL_CMDLINE := androidboot.selinux=permissive
相关推荐
程序员的世界你不懂10 分钟前
移动Android和IOS自动化中常见问题
android·运维·自动化
前期后期2 小时前
Android Compose是如何使用什么架构,多个Activity?还是Fragment?compose的ui又是如何卸载和挂载的呢?
android·ui·架构·kotlin
云深不知处㊣10 小时前
【社交+陪玩服务】全场景陪玩系统源码 小程序+H5双端 社群互动+即时点单+搭建教程
android·小程序·社交源码·找搭子系统源码·陪玩系统源码
casual_clover10 小时前
Kotlin 中实现静态方法的几种方式
android·kotlin
yzpyzp10 小时前
kotlin的?: 操作符(Elvis操作符)
android·kotlin
buleideli10 小时前
Android项目优化同步速度
android·gradle
tangweiguo0305198712 小时前
Android 蓝牙工具类封装:支持经典蓝牙与 BLE,兼容高版本权限
android·gitee
cheese-liang13 小时前
Excel中使用VBA自动生成排班表
android·excel
程序员正茂13 小时前
Unity安卓Android从StreamingAssets加载AssetBundle
android·unity·assetbundle·streamingassets
tmacfrank15 小时前
Compose 实践与探索一 —— 关键知识与概念详解
android·ui·kotlin·android jetpack