当前位置:   article > 正文

Android 让adb以root的身份来运行_magiskpolicy allow

magiskpolicy allow

1. 首先安装自己手机对应的root的image, 如twrp.img

  1. //上传supersu 到
  2. adb push SuperSU-v2.79-20161211114519.zip /mnt/sdcard/supersu.zip
  3.    adb reboot fastboot
  4. //等重启好
  5.   fastboot  flash recovery twrp-3.3.1-0-shamu.img

  fastboot  flash recovery twrp-3.3.1-0-shamu.img

   进入twrp的菜单,安装SuperSU-v2.79-20161211114519.zip

2. 这样可以通过su命令来取得root权限 , 但是不能adb root这样,

以下命令会提示出错,

  1. adb root
  2. adbd cannot run as root in production builds
  1. adb remount
  2. Not running as root. Try "adb root" first.

需要再替换一下adbd, 安装个termux

  找个修改版的adbd,如adbd.21.png , 下载 https://download.csdn.net/download/aerror/14122036

adb push adbd.21.png /mnt/sdcard/

 

  1. su
  2. stop adbd
  3. mount -o rw,remount / /
  4. cat /sbin/adbd > /sbin/adbd.original
  5. chown 0.0 /sbin/adbd.original
  6. chmod 644 /sbin/adbd.original
  7. rm /sbin/adbd
  8. cat /sdcard/adbd.21.png > /sbin/adbd
  9. chown 0.0 /sbin/adbd
  10. chmod 0750 /sbin/adbd
  11. cat /system/bin/sh > /sbin/adbsh
  12. chown 0.0 /sbin/adbdsh
  13. chmod 0750 /sbin/adbdsh
  14. supolicy --live "permissive init_shell" \
  15. "allow adbd adbd process setcurrent" \
  16. "allow adbd init process dyntransition" \
  17. "allow servicemanager { init_shell zygote } dir search" \
  18. "allow servicemanager { init_shell zygote } file { read open }" \
  19. "allow servicemanager { init_shell zygote } process getattr" \
  20. "allow system_server init_shell binder { transfer call }" \
  21. "allow zygote { servicemanager system_server } binder call"
  22. start adbd

成功之后:

  1. shamu:/ # whoami
  2. root
  3. shamu:/ # ps | grep adbd
  4. root 9296 1 8628 224 poll_sched 000204f4 S /sbin/adbd
  5. $ adb root
  6. adbd is already running as root
  7. $ adb remount
  8. remount succeeded

发现重启之后不行,于是写了一个脚本adbroot放到/system/bin下面,每次重启之后在termux里执行一下:

  1. shamu:/ # cat /system/bin/adbroot
  2. stop adbd
  3. mount -o rw,remount /
  4. rm /sbin/adbd
  5. ln -s /data/local/adbd.21.png /sbin/adbd
  6. supolicy --live "permissive init_shell" \
  7. "allow adbd adbd process setcurrent" \
  8. "allow adbd init process dyntransition" \
  9. "allow servicemanager { init_shell zygote } dir search" \
  10. "allow servicemanager { init_shell zygote } file { read open }" \
  11. "allow servicemanager { init_shell zygote } process getattr" \
  12. "allow system_server init_shell binder { transfer call }" \
  13. "allow zygote { servicemanager system_server } binder call"
  14. start adbd
  15. 在termux每次重启后执行:
  16. su
  17. adbroot

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/949473
推荐阅读
相关标签
  

闽ICP备14008679号