Android :user版本赋予su权限

这篇具有很好参考价值的文章主要介绍了Android :user版本赋予su权限。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

1. userdebug和user版本

2. 关闭selinux

system/core

diff --git a/init/selinux.cpp b/init/selinux.cpp
index 5a0255acd..787917274 100644
--- a/init/selinux.cpp
+++ b/init/selinux.cpp
@@ -104,6 +104,8 @@ EnforcingStatus StatusFromCmdline() {
 }
bool IsEnforcing() {
+    return false;    
+
     if (ALLOW_PERMISSIVE_SELINUX) {
         return StatusFromCmdline() == SELINUX_ENFORCING;
     }

3. 修改su.cpp,注释用户组权限检测

system/extras/su/su.cpp

 diff --git a/su/su.cpp b/su/su.cpp
 index 1a1ab6bf..af3d2a68 100644--- a/su/su.cpp
 +++ b/su/su.cpp
 @@ -80,8 +80,8 @@ void extract_uidgids(const char* uidgids, uid_t* uid, gid_t* gid, gid_t* gids, i
 }
 int main(int argc, char** argv) {
-    uid_t current_uid = getuid();
-    if (current_uid != AID_ROOT && current_uid != AID_SHELL) error(1, 0, "not 
allowed");
+    //uid_t current_uid = getuid();
+    //if (current_uid != AID_ROOT && current_uid != AID_SHELL) error(1, 0, "not 
allowed");       
    // Handle -h and --help.
    ++argv;

4. 给 su 文件默认授予 root 权限

system/core/libcutils/fs_config.cpp

diff --git a/libcutils/fs_config.cpp b/libcutils/fs_config.cpp
index 5805a4d19..92e93e76f 100644
--- a/libcutils/fs_config.cpp
+++ b/libcutils/fs_config.cpp
@@ -86,7 +86,7 @@ static const struct fs_path_config android_dirs[] = {
    { 00751, AID_ROOT,    AID_SHELL,    0, "system/bin" },
    { 00755, AID_ROOT,    AID_ROOT,     0, "system/etc/ppp" },
    { 00755, AID_ROOT,    AID_SHELL,    0, "system/vendor" },
-   { 00750, AID_ROOT,    AID_SHELL,    0, "system/xbin" },
+   { 00755, AID_ROOT,    AID_SHELL,    0, "system/xbin" },        
    { 00751, AID_ROOT,    AID_SHELL,    0, "system/apex/*/bin" },   
    { 00751, AID_ROOT,    AID_SHELL,    0, "system_ext/bin" }, 
    { 00751, AID_ROOT,    AID_SHELL,    0, "system_ext/apex/*/bin" },
 
@@ -190,7 +190,7 @@ static const struct fs_path_config android_files[] = {
 // the following two files are INTENTIONALLY set-uid, but they
 // are NOT included on user builds.
    { 06755, AID_ROOT,  AID_ROOT,       0, "system/xbin/procmem" },   
-   { 04750, AID_ROOT,  AID_SHELL,      0, "system/xbin/su" },
+   { 06755, AID_ROOT,  AID_SHELL,      0, "system/xbin/su" }, 
    
  

 

frameworks/base/core/jni/com_android_internal_os_Zygote.cpp

diff --git a/core/jni/com_android_internal_os_Zygote.cpp 
b/core/jni/com_android_internal_os_Zygote.cpp
index 9eede83e21e5..694eec2a40ac 100644
--- a/core/jni/com_android_internal_os_Zygote.cpp
+++ b/core/jni/com_android_internal_os_Zygote.cpp
@@ -656,6 +656,7 @@ static void EnableKeepCapabilities(fail_fn_t fail_fn) {
 }

 static void DropCapabilitiesBoundingSet(fail_fn_t fail_fn) {
+/*
    for (int i = 0; prctl(PR_CAPBSET_READ, i, 0, 0, 0) >= 0; i++) {;
        if (prctl(PR_CAPBSET_DROP, i, 0, 0, 0) == -1) {
            if (errno == EINVAL) {
@@ -666,6 +667,7 @@ static void DropCapabilitiesBoundingSet(fail_fn_t fail_fn) {
            }
        }    
     }
+  */
 }

kernel/security/commoncap.c

diff --git a/security/commoncap.c b/security/commoncap.c
index f86557a8e43f6..19124dd6239a1 100644
--- a/security/commoncap.c
+++ b/security/commoncap.c
@@ -1147,12 +1147,12 @@ int cap_task_setnice(struct task_struct *p, int nice)
 static int cap_prctl_drop(unsigned long cap)
 {
     struct cred *new;
-
+/*
     if (!ns_capable(current_user_ns(), CAP_SETPCAP))
         return -EPERM;
     if (!cap_valid(cap))
         return -EINVAL;
-
+*/
     new = prepare_creds();
     if (!new)
         return -ENOMEM;

5. user版本需要把su编进系统

build/core文章来源地址https://www.toymoban.com/news/detail-783478.html

diff --git a/target/product/base_system.mk b/target/product/base_system.mk
index 4569bceff9..5c8eaaa87c 100644
--- a/target/product/base_system.mk
+++ b/target/product/base_system.mk
@@ -273,6 +273,7 @@ PRODUCT_PACKAGES += \
    wificond \
    wifi.rc \
    wm \
+   su \

# VINTF data for system image
PRODUCT_PACKAGES += \

@@ -378,7 +379,6 @@ PRODUCT_PACKAGES_DEBUG := \
     ss \
     start_with_lockagent \
     strace \
-    su \
     sanitizer-status \
     tracepath \
     tracepath6 \

到了这里,关于Android :user版本赋予su权限的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • [SM6225][Android13]user版本默认允许root和remount

    芯片:  高通SM6225 版本:  Android 13 kernel:  msm-5.15        刚刚从Framework踏入性能的小殿堂,User版本默认是不会开启root权限的,而且一般调试需要设置一下CPU GPU DDR performance模式或者修改一些schedule util等调核调频节点去对比复测,userdebug版本的话本身整机性能就比user卡很多,

    2024年02月09日
    浏览(43)
  • Android 修改 SELinux avc 权限的方法

    系统版本:Android 11.0     平         台:RK3568 在 Android 系统的开发及适配过程中,我们常常需要对 SELinux avc  权限进行修改,以下是我对 SELinux avc  权限修改总结的方法。 一、验证功能是否存在 selinux 权限问题 #进入Android终端 adb shell #获取root权限 su #查看系统当前 s

    2024年02月09日
    浏览(29)
  • MTK Android13 user版本进入engineermode的Bluetooth测试项时闪退

    平台:MT6771 android13 问题描述:进入到工模,点击进入Bluetooth测试项直接闪退 Log如下: 从日志咱们可以看到: 很明显这个服务没有注册,找到编译规则s0_vnd/device/mediatek/vendor/common/device.mk,可以看到以下: 可以看到只有在编译eng,userdebug版本时会编译em_hidl,那在编译规则中加

    2024年02月05日
    浏览(37)
  • Android所有版本的存储权限适配

                 第一步:在Manifest文件添加如下权限          uses-permission android:name=\\\"android.permission.WRITE_EXTERNAL_STORAGE\\\" android:maxSdkVersion=\\\"28\\\" tools:ignore=\\\"ScopedStorage\\\"/              uses-permission android:name=\\\"android.permission.MANAGE_EXTERNAL_STORAGE\\\"/          uses-permission android:name=\\\"android.p

    2024年01月17日
    浏览(27)
  • Android版本实现root权限(本办法适用于所有android平台)

    本方法适用于所有Android版本 userdebug和user版本 关闭selinux system/core 修改su.cpp,注释用户组权限检测 system/extras/su/su.cpp diff --git a/su/su.cpp b/su/su.cpp index 1a1ab6bf..af3d2a68 100644 --- a/su/su.cpp +++ b/su/su.cpp @@ -80,8 +80,8 @@ void extract_uidgids(const char* uidgids, uid_t* uid, gid_t* gid, gid_t* gids, i } int ma

    2024年02月06日
    浏览(30)
  • android 高版本sd卡目录读写权限

    1、从安卓11不允许访问sd目录,官方说明如下: https://developer.android.com/about/versions/11/privacy/storage?hl=zh-cn 2、使用MediaStore方法 一手遮天 Android - 存储: Android 11 通过 MediaStore 管理文件 - webabcd - 博客园 (cnblogs.com)  3、关于权限的文章 (31条消息) Android 10、11分区存储适配踩坑总结_安

    2024年02月15日
    浏览(33)
  • 一篇文章搞定Android权限问题(全版本)

    文章内容如下: 如果你只是想快速的完成你Android权限申请的工作,那么直接上工具PermissionX 如果是想真正的了解Android的权限问题,那么建议你用15分钟通读一下本文。(可以不去实验,收藏以备后用) 首先了解Android版本和SDK的关系,帮助我们分辨后面的权限版本。 其次把最常

    2023年04月20日
    浏览(42)
  • 一篇文章搞定《Android权限问题(全版本)》

    文章内容如下: 如果你只是想快速的完成你Android权限申请的工作,那么直接上工具PermissionX 如果是想真正的了解Android的权限问题,那么建议你用15分钟通读一下本文。(可以不去实验,收藏以备后用) 首先了解Android版本和SDK的关系,帮助我们分辨后面的权限版本。 其次把最常

    2024年02月03日
    浏览(40)
  • Linux系统知识4—Linux的root用户,su 和 exit 命令,sudo 命令,用户和用户组管理,getent,查看权限控制,修改权限控制 -chmod,修改权限控制-chown

    目录 一.Linux的root用户 1.1 root用户(超级管理员) 1.2 su 和 exit 命令 1.3 sudo 命令 1.为普通用户配置 sudo 认证 二.用户和用户组管理 2.1用户,用户组 2.2用户组的管理 2.3用户管理 2.4.getent 三.查看权限控制 3.1认知权限信息 1.序号1,表示文件,文件夹的权限控制信息 2. 序号2,表

    2024年01月17日
    浏览(47)
  • android studio开发——android11版本以上权限动态申请问题,包括文件读写、图片、相机的调用

    用于android手机的升级,现在已经是android13版本了,对于权限问题可能更加敏感了,前段时间开发发现之前的方法已经不再适用于android11以后的版本了 读写权限申请最好是跳转到设置中进行才是最好了,下面我们开始进行 首先是AndroidManifest.xml文件的权限 然后这里讲解一下权

    2024年02月10日
    浏览(47)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包