zoukankan      html  css  js  c++  java
  • android user用户版本提高adb权限【转】

    本文转载自: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 ");  
      44. }  
  • 相关阅读:
    Ubuntu 20.04下EasyConnect兼容性问题临时解决方案
    Ubuntu 20.04 LTS安装搜狗输入法,只需三条命令,还能自动更新
    Java笔记: 继承成员覆盖和隐藏
    Java扫雷游戏: JMine
    Emacs: 设置窗口标题格式
    Java笔记: protected的真正含义
    Java笔记: 初始化块
    Ubuntu跨版本安装软件
    百度编辑器 Ueditor 增加字体
    AspCms 升级百度编辑器
  • 原文地址:https://www.cnblogs.com/zzb-Dream-90Time/p/8167200.html
Copyright © 2011-2022 走看看