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
相关推荐
一只修仙的猿25 分钟前
再谈性能优化,一次项目优化经历分享
android·性能优化
雮尘2 小时前
Android性能优化之枚举替代
android
2501_915909064 小时前
苹果上架App软件全流程指南:iOS 应用发布步骤、App Store 上架流程、uni-app 打包上传与审核技巧详解
android·ios·小程序·https·uni-app·iphone·webview
2501_915921434 小时前
iOS 文件管理与能耗调试结合实战 如何查看缓存文件、优化电池消耗、分析App使用记录(uni-app开发与性能优化必备指南)
android·ios·缓存·小程序·uni-app·iphone·webview
2501_915918415 小时前
App 苹果 上架全流程解析 iOS 应用发布步骤、App Store 上架流程
android·ios·小程序·https·uni-app·iphone·webview
2501_916007475 小时前
苹果上架全流程详解,iOS 应用发布步骤、App Store 上架流程、uni-app 打包上传与审核要点完整指南
android·ios·小程序·https·uni-app·iphone·webview
PuddingSama6 小时前
Android 高级绘制技巧: BlendMode
android·前端·面试
2501_915921437 小时前
iOS App 性能监控与优化实战 如何监控CPU、GPU、内存、帧率、耗电情况并提升用户体验(uni-app iOS开发调试必备指南)
android·ios·小程序·uni-app·iphone·webview·ux
Digitally7 小时前
如何将视频从安卓手机传输到电脑?
android·智能手机·电脑
CV资深专家7 小时前
Android 相机框架的跨进程通信架构
android