android user使用者版本提高adb許可權【轉】

來源:互聯網
上載者:User

標籤:value   word   get   frame   kernel   clip   deb   uid   inux   

本文轉載自:http://blog.csdn.net/liyongming1982/article/details/14108111

有的user使用者版本的log 不全,且push/pull某些檔案或者屬性檔案

常常會遇到許可權不夠的情況,給調試帶來很多便:

對於user 版本adb shell 開啟的還是shell 許可權,而不是root 許可權,
如果您需要root 許可權,需要再改一下system/core/adb/adb.c 裡面的should_drop_privileges() 
這個函數,在#ifndef ALLOW_ADBD_ROOT 時return 0; 而不是return 1; 即可。

判斷是否降低許可權:

[cpp] view plain copy 
  1. static int should_drop_privileges() {  
  2. #ifndef ALLOW_ADBD_ROOT  
  3.     return 1;  
  4. #else /* ALLOW_ADBD_ROOT */  
  5.     int secure = 0;  
  6.     char value[PROPERTY_VALUE_MAX];  
  7.   
  8.    /* run adbd in secure mode if ro.secure is set and 
  9.     ** we are not in the emulator 
  10.     */  
  11.     property_get("ro.kernel.qemu", value, "");  
  12.     if (strcmp(value, "1") != 0) {  
  13.         property_get("ro.secure", value, "1");  
  14.         if (strcmp(value, "1") == 0) {  
  15.             // don‘t run as root if ro.secure is set...  
  16.             secure = 1;  
  17.   
  18.             // ... except we allow running as root in userdebug builds if the  
  19.             // service.adb.root property has been set by the "adb root" command  
  20.             property_get("ro.debuggable", value, "");  
  21.             if (strcmp(value, "1") == 0) {  
  22.                 property_get("service.adb.root", value, "");  
  23.                 if (strcmp(value, "1") == 0) {  
  24.                     secure = 0;  
  25.                 }  
  26.             }  
  27.         }  
  28.     }  
  29.     return secure;  
  30. #endif /* ALLOW_ADBD_ROOT */  
  31. }  


具體怎麼降低許可權:

[cpp] view plain copy 
    1. if (should_drop_privileges()) {  
    2.     struct __user_cap_header_struct header;  
    3.     struct __user_cap_data_struct cap;  
    4.   
    5.     if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) != 0) {  
    6.         exit(1);  
    7.     }  
    8.   
    9.     /* add extra groups: 
    10.     ** AID_ADB to access the USB driver 
    11.     ** AID_LOG to read system logs (adb logcat) 
    12.     ** AID_INPUT to diagnose input issues (getevent) 
    13.     ** AID_INET to diagnose network issues (netcfg, ping) 
    14.     ** AID_GRAPHICS to access the frame buffer 
    15.     ** AID_NET_BT and AID_NET_BT_ADMIN to diagnose bluetooth (hcidump) 
    16.     ** AID_SDCARD_R to allow reading from the SD card 
    17.     ** AID_SDCARD_RW to allow writing to the SD card 
    18.     ** AID_MOUNT to allow unmounting the SD card before rebooting 
    19.     ** AID_NET_BW_STATS to read out qtaguid statistics 
    20.     */  
    21.     gid_t groups[] = { AID_ADB, AID_LOG, AID_INPUT, AID_INET, AID_GRAPHICS,  
    22.                        AID_NET_BT, AID_NET_BT_ADMIN, AID_SDCARD_R, AID_SDCARD_RW,  
    23.                        AID_MOUNT, AID_NET_BW_STATS };  
    24.     if (setgroups(sizeof(groups)/sizeof(groups[0]), groups) != 0) {  
    25.         exit(1);  
    26.     }  
    27.   
    28.     /* then switch user and group to "shell" */  
    29.     if (setgid(AID_SHELL) != 0) {  
    30.         exit(1);  
    31.     }  
    32.     if (setuid(AID_SHELL) != 0) {  
    33.         exit(1);  
    34.     }  
    35.   
    36.     /* set CAP_SYS_BOOT capability, so "adb reboot" will succeed */  
    37.     header.version = _LINUX_CAPABILITY_VERSION;  
    38.     header.pid = 0;  
    39.     cap.effective = cap.permitted = (1 << CAP_SYS_BOOT);  
    40.     cap.inheritable = 0;  
    41.     capset(&header, &cap);  
    42.   
    43.     D("Local port disabled\n");  
    44. }  

android user使用者版本提高adb許可權【轉】

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.