android user版本如何開啟root許可權

來源:互聯網
上載者:User

標籤:android   http   使用   for   sp   問題   on   cti   代碼   

首先您要確認您是想開啟adbd 的root 許可權,還是讓app 也可以拿到root 許可權。
 
(1). adbd 的root 許可權
我們通常在debug user 版本問題時, 或者進行user 版本的monkey test 時都會這個工作,以便debug.
 
如果你想user 版本adb root 許可權預設關閉, 而在想開啟時, 可以通過工程模式中的設定項開啟, 那麼請USER2ROOT 功能。
此功能預設關閉, 如果開啟, 需要在ProjectConfig.mk 中設定: MTK_USER_ROOT_SWITCH = yes
 
(2). app 的root 許可權
app 的root 許可權通常是通過執行su 命令來擷取。注意的是KK 上, 因為多種限制, 普通的su 難以直接拿到root 許可權, 需要做針對性的改動.
通常我們會內建具有控制端的第三方su, 下面以內建SuperSU, 以及使用Google default su 為例進行說明。
 
(3). 如何內建第三方SuperSU
該方式可以繞過zygote 和 adbd 對Root Capabilities BoundSet 的限制.
3.1. 下載SuperSU
 SuperSU: http://forum.xda-developers.com/showthread.php?t=1538053
 
3.2. 內建Superuser.apk 到 system/app
   將su 複製並改名成: daemonsu
   內建su 到 system/xbin
   內建daemonsu 到 system/xbin
   內建chattr 到 system/xbin
   內建chattr.pie 到 /system/xbin
 
3.3. 內建install-recovery.sh 到system/etc
更新alps/system/core/inlcude/private/android_filesystem_config.h
在android_files 數組的最開始新增.
{ 00755, AID_ROOT,      AID_ROOT,      0, "system/etc/install-recovery.sh" },
 
(4). 如何內建Google default su
4.1 放開Google default su 只准shell/root 使用者使用的限制.
    system/extras/su/su.c 中刪除下面3行代碼
    if (myuid != AID_ROOT && myuid != AID_SHELL) {
        fprintf(stderr,"su: uid %d not allowed to su\n", myuid);
        return 1;
    }
 
4.2 首先將此編譯出的su 內建到system/bin, 然後修改su 的內建許可權,啟用sbit 位.
更新alps/system/core/inlcude/private/android_filesystem_config.h
在android_files 數組中
增加
{ 06755, AID_ROOT,      AID_ROOT,      0, "system/bin/su" },
注意這行要放在
{ 00755, AID_ROOT,      AID_SHELL,     0, "system/bin/*" },
之前
 
4.3 如果是KK 以及以後版本, 需要強行解除zygote 和 adbd 對Root Capabilities BoundSet 的限制
更新kernel/security/commoncap.c 中 cap_prctl_drop 函數為:
static long cap_prctl_drop(struct cred *new, unsigned long cap)
{
  //begin: Let ‘zygote‘ and ‘adbd‘ drop Root Capabilities BoundSet ineffectively
        if (!strncmp(current->comm, "zygote", 16)) {
                return -EINVAL;
        }
        if (!strncmp(current->comm, "adbd", 16)) {
                return -EINVAL;
        }
        // add end
        if (!capable(CAP_SETPCAP))
                return -EPERM;
        if (!cap_valid(cap))
                return -EINVAL;
        cap_lower(new->cap_bset, cap);
        return 0;
}
重新編譯系統, 重新download 後, adb shell 進入後再輸入su 看看是否命令列由$切換到#, 如果切換即成功。

android user版本如何開啟root許可權

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.