adbd源码位于system/core/adb/目录下,可执行文件位于/sbin/adbd。通过adb执行ps命令,结果如下:
USER PID PPID VSIZE RSS WCHAN PC NAME
root 1 0 296 212 c00b0124 0000d9ec S /init
... ...
shell 2183 1 3372 184 ffffffff 0000eca4 S /sbin/adbd
root 2204 1859 832 336 00000000 afe0c7dc R ps
看一下倒数第二行,adbd所在进程的父进程是root,本身的user是shell。对于一个发布状态的产品,这个是最正常不过了。但现在开发中遇到这样一个需求,产品已经处在发布状态(编译模式已经改成user)的情况下,因为BSP需要处理一些内核上的东西,需要在PC上执行adb shell后具有root权限。也就是这种效果:
USER PID PPID VSIZE RSS WCHAN PC NAME
root 1 0 296 212 c00b0124 0000d9ec S /init
... ...
root 1911 1 3376 184 ffffffff 0000eca4 S /sbin/adbd
root 2198 2197 828 332 00000000 afe0c7dc R ps
要达到这个效果,就是要在启动adbd时,以root用户启动。那么,先看一下在Android中怎么启动adbd。
可以看一下Android系统根目录下的/init.rc的片段:
... ...
# adbd is controlled by the persist.service.adb.enable system property
service adbd /sbin/adbd
disabled
# adbd on at boot in emulator
on property:ro.kernel.qemu=1
start adbd
on property:persist.service.adb.enable=1
start adbd
on property:persist.service.adb.enable=0
stop adbd
... ...
这里定义了一个触发器,只要persist.service.adb.enable值被置为1,就会启动/sbin/adbd。
怎么样设置persist.service.adb.enable的值呢?这里涉及到一个属性服务/system/core/init/property_service.c。看下面的东西之前先看一下我之前翻译过来的这篇StevGuo的文档,他对属性服务描述得很仔细,也很有条理。
http://blog.csdn.net/a345017062/archive/2010/12/17/6083026.aspx
今天搜资料的时候才发现网上N多人翻译了这篇文章,有点儿晕晕的。。。
我们继续。。。
通过阅读上面的文档,我们知道了属性服务启动时加载了四个文件,这四个文件里面都可以设置系统属性,还可以通过APK设置系统属性。但我把这些方式都,结果都一样,adbd是启动起来了,用户都是shell,还是没有root权限的。看来差异应该在编译模式上,是改为user编译模式后,系统改变了adbd启动时的权限。在build目录下搜索一下,发现了main.mk中有这样的代码片段
## user/userdebug ##
user_variant := $(filter userdebug user,$(TARGET_BUILD_VARIANT))
enable_target_debugging := true
ifneq (,$(user_variant))
# Target is secure in user builds.
ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1
tags_to_install := user
ifeq ($(user_variant),userdebug)
# Pick up some extra useful tools
tags_to_install += debug
else
# Disable debugging in plain user builds.
enable_target_debugging :=
endif
# TODO: Always set WITH_DEXPREOPT (for user builds) once it works on OSX.
# Also, remove the corresponding block in config/product_config.make.
ifeq ($(HOST_OS)-$(WITH_DEXPREOPT_buildbot),linux-true)
WITH_DEXPREOPT := true
endif
# Disallow mock locations by default for user builds
ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=0
else # !user_variant
# Turn on checkjni for non-user builds.
ADDITIONAL_BUILD_PROPERTIES += ro.kernel.android.checkjni=1
# Set device insecure for non-user builds.
ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=0
# Allow mock locations by default for non user builds
ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=1
endif # !user_variant
ifeq (true,$(strip $(enable_target_debugging)))
# Target is more debuggable and adbd is on by default
ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=1 persist.service.adb.enable=1
# Include the debugging/testing OTA keys in this build.
INCLUDE_TEST_OTA_KEYS := true
else # !enable_target_debugging
# Target is less debuggable and adbd is off by default
ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=0 persist.service.adb.enable=0
endif # !enable_target_debugging
这段代码我大致解释一下:
主要通过判断当前的编译模式来给几个属性赋予不同的值,然后把属性存储在ADDITIONAL_DEFAULT_PROPERTIES这个变量中,这个变量在后面是要写到根目录下的/default.prop中去,在系统启动时被属性服务加载的。也就是说我们在/default.prop中看到的几个属性的值是在这里设置的。
只看两个属性ro.secure,persist.service.adb.enable。当前是user模式的话,编译系统会把ro.secure置为1,把persist.service.adb.enable置为0.也就是说,用user模式编译出来的系统运行在安全模式下,adbd默认关闭。即使通过设置属性的方式打开,adbd进程的用户也是shell,不具有root权限。这样,普通用户或者开发者拿到一个机器后,通过PC运行adb shell时,是以shell用户登录机器的。
好了,现在把ro.secure置为0,再重新编译,只要设置属性persist.service.adb.enable的值为1,adbd进程就会以root用户的身份启动。
adbd源码位于system/core/adb/目录下,可执行文件位于/sbin/adbd。通过adb执行ps命令,结果如下:
USER PID PPID VSIZE RSS WCHAN PC NAME
root 1 0 296 212 c00b0124 0000d9ec S /init
... ...
shell 2183 1 3372 184 ffffffff 0000eca4 S /sbin/adbd
root 2204 1859 832 336 00000000 afe0c7dc R ps
看一下倒数第二行,adbd所在进程的父进程是root,本身的user是shell。对于一个发布状态的产品,这个是最正常不过了。但现在开发中遇到这样一个需求,产品已经处在发布状态(编译模式已经改成user)的情况下,因为BSP需要处理一些内核上的东西,需要在PC上执行adb shell后具有root权限。也就是这种效果:
USER PID PPID VSIZE RSS WCHAN PC NAME
root 1 0 296 212 c00b0124 0000d9ec S /init
... ...
root 1911 1 3376 184 ffffffff 0000eca4 S /sbin/adbd
root 2198 2197 828 332 00000000 afe0c7dc R ps
要达到这个效果,就是要在启动adbd时,以root用户启动。那么,先看一下在Android中怎么启动adbd。
可以看一下Android系统根目录下的/init.rc的片段:
... ...
# adbd is controlled by the persist.service.adb.enable system property
service adbd /sbin/adbd
disabled
# adbd on at boot in emulator
on property:ro.kernel.qemu=1
start adbd
on property:persist.service.adb.enable=1
start adbd
on property:persist.service.adb.enable=0
stop adbd
... ...
这里定义了一个触发器,只要persist.service.adb.enable值被置为1,就会启动/sbin/adbd。
怎么样设置persist.service.adb.enable的值呢?这里涉及到一个属性服务/system/core/init/property_service.c。看下面的东西之前先看一下我之前翻译过来的这篇StevGuo的文档,他对属性服务描述得很仔细,也很有条理。
http://blog.csdn.net/a345017062/archive/2010/12/17/6083026.aspx
今天搜资料的时候才发现网上N多人翻译了这篇文章,有点儿晕晕的。。。
我们继续。。。
通过阅读上面的文档,我们知道了属性服务启动时加载了四个文件,这四个文件里面都可以设置系统属性,还可以通过APK设置系统属性。但我把这些方式都,结果都一样,adbd是启动起来了,用户都是shell,还是没有root权限的。看来差异应该在编译模式上,是改为user编译模式后,系统改变了adbd启动时的权限。在build目录下搜索一下,发现了main.mk中有这样的代码片段
## user/userdebug ##
user_variant := $(filter userdebug user,$(TARGET_BUILD_VARIANT))
enable_target_debugging := true
ifneq (,$(user_variant))
# Target is secure in user builds.
ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1
tags_to_install := user
ifeq ($(user_variant),userdebug)
# Pick up some extra useful tools
tags_to_install += debug
else
# Disable debugging in plain user builds.
enable_target_debugging :=
endif
# TODO: Always set WITH_DEXPREOPT (for user builds) once it works on OSX.
# Also, remove the corresponding block in config/product_config.make.
ifeq ($(HOST_OS)-$(WITH_DEXPREOPT_buildbot),linux-true)
WITH_DEXPREOPT := true
endif
# Disallow mock locations by default for user builds
ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=0
else # !user_variant
# Turn on checkjni for non-user builds.
ADDITIONAL_BUILD_PROPERTIES += ro.kernel.android.checkjni=1
# Set device insecure for non-user builds.
ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=0
# Allow mock locations by default for non user builds
ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=1
endif # !user_variant
ifeq (true,$(strip $(enable_target_debugging)))
# Target is more debuggable and adbd is on by default
ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=1 persist.service.adb.enable=1
# Include the debugging/testing OTA keys in this build.
INCLUDE_TEST_OTA_KEYS := true
else # !enable_target_debugging
# Target is less debuggable and adbd is off by default
ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=0 persist.service.adb.enable=0
endif # !enable_target_debugging
这段代码我大致解释一下:
主要通过判断当前的编译模式来给几个属性赋予不同的值,然后把属性存储在ADDITIONAL_DEFAULT_PROPERTIES这个变量中,这个变量在后面是要写到根目录下的/default.prop中去,在系统启动时被属性服务加载的。也就是说我们在/default.prop中看到的几个属性的值是在这里设置的。
只看两个属性ro.secure,persist.service.adb.enable。当前是user模式的话,编译系统会把ro.secure置为1,把persist.service.adb.enable置为0.也就是说,用user模式编译出来的系统运行在安全模式下,adbd默认关闭。即使通过设置属性的方式打开,adbd进程的用户也是shell,不具有root权限。这样,普通用户或者开发者拿到一个机器后,通过PC运行adb shell时,是以shell用户登录机器的。
好了,现在把ro.secure置为0,再重新编译,只要设置属性persist.service.adb.enable的值为1,adbd进程就会以root用户的身份启动。
分享到:
相关推荐
修改过的adbd的arm的(非amr64), 用来让adb 可以用root的权限启动,方便调试。
用于需要adbd root 权限启动的adbd 修改版本,从android 10 的system.img解压得到
解决使用adb root命令出现 adbd connot run as root in production build错误,
这款应用能让您以“非安全”模式运行adbd,让“adb shell”拥有ROOT权限,允许通过“adb push/pull”直接访问系统文件和目录,并通过运行“adb remount”命令来让您的/system/分区可写。 主要功能: - 通过“patch...
magisk模块,用于解决已经root,但是执行“adb root”仍然提示“adbd cannot run as root in production builds”的问题; 使用说明:下载本模块后pull到设备里,然后在magisk 里安装。安装完成启动后自动生效! ...
有些手机即使root了通过adb root命令也还是无法使adb一直获得root权限,安装adbd后,授予其root权限,并勾选里面的选项后,运行adb root,在手机重启之前,adb可以一直获取root权限。
2.0的adbd 资源 部分手机可以使用 我上传两个 adbd 大家可以选择使用
,验证你的手机是否已经root了 adb shell su ...行命令后,$ 变为 # 即 表示root 成功 ...2,安装adbd-insecure.apk ...打开应用将Enable insecure adbd 和 enable at boot 勾选上,设置好之后重进键入:adb root即可
超级adbd_ChainfireadbdInsecure, 在root机子中可设置adb shell一运行就是root用户
手机打包系统必备,mtk平台自制线刷系统的工具
adbd-Insecure-v2.00.apk ,最新版本的adbd.......................................
用于破解adb的限制,可以用于adb备份整个系统!
03、输入adb root,显示adbd is already running as root; 04、输入adb shell mount -o remount rw system/,挂载system为读写; 05、输入adb push su system/bin/,su发送到手机; 06、输入adb push busybox ...
它不是普通的root(su),而是具有根权限的在手机上运行的adbd守护程序。 adb root允许您“ adb push / pull”到系统目录并运行诸如“ adb remount”或“ adb disable-verify”之类的命令。 这是一个高度不安全的...
ADBD Insecure (Android 2.1+).zip
天猫精灵里面的ADBD可执行程序,具体的可以参见链接: https://blog.csdn.net/leekwen/article/details/79923187
http://blog.csdn.net/yihongyuelan 《Android 5.0 如何正确启用isLoggable(二)__原理分析》脚本包,用于开启隐藏log,需要adbd获得root权限即adb remount
5、可解决Root不完整问题 6、adb命令终端及电源管理 7、备份手机现有系统,并制作卡刷包、线刷包;备份建议使用v2.4.7版本,该版本兼容性好、稳定,可以备份NAND和EMMC字库,并支持最新MTK8389 MTK6589 MTK6577 MTK...
5、可解决Root不完整问题 6、adb命令终端及电源管理 7、备份手机现有系统,并制作卡刷包、线刷包;备份建议使用v2.4.7版本,该版本兼容性好、稳定,可以备份NAND和EMMC字库,并支持最新MTK8389 MTK6589 MTK6577 MTK...