Android Permanently Open root Permission of adb

  • 2021-11-24 02:53:36
  • OfStack

root permissions for adb are controlled in system/core/adb/adb. c. It is mainly controlled according to ro. secure and ro. debuggable, etc. system and property.

By default, when the file ro. secure is 0, the root permission is turned on, and when it is 1, it is confirmed whether the root permission can be turned on according to options such as ro. debuggable. For this reason, if you want to permanently open the root permission of adb, there are two ways to modify it:

1. Modify system property ro. secure so that ro. secure = 0.

2. Modify the judgment logic of opening root permission in adb. c.

These two modifications are described in detail below:

Method 1.

Modify system property ro. secure so that ro. secure = 0.

(1) Modification of alps/build/core/main. mk


ifneq (,$(user_variant))
 # Target is secure in user builds.
 ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1

Will

ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1

Change to

ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=0

(2) After android JB version (4.1), google directly removes user version root permission from compilation. For this reason, you need to modify the compilation option ALLOW_ADBD_ROOT in system/core/adb/Android. mk. If this option is not turned on, adb.c will not select root or shell permission according to ro.secure, and return shell permission directly.

So you need line 126 in Android. mk:


ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
===> 
ifneq (,$(filter userdebug user eng,$(TARGET_BUILD_VARIANT)))

Method 2.

Modify the judgment logic of opening root permission in adb. c. There are differences between versions after 4.1 and versions before 4.1.

If it is JB version 4.1 or later, modify the function should_drop_privileges () directly, empty this function and return 0 directly. Returning 0 opens root permission.

[Test and Confirmation]

When the modification is completed, you only need to re-build bootimage, then download, then turn on debug option in setting, and after adb connection, # will be displayed, that is, root succeeded.

Additional knowledge: How does adb determine whether it has root permissions and change system/app contents

1. First determine root permissions:

adb root
Results:
C:\signapp > adb root
restarting adbd as root # indicates root permission, if adbd cannot run as root in production builds indicates no root permission

2. Change the contents of system/app

1 read only will appear in system/app under normal circumstances, so adb remount is needed (this is a command to re-mount your partition, so that system partition can be changed from read-only to read-writable, and root permission can be obtained before running, and adb root can be executed first)

You can modify it at will in system/app, but pay attention to one point.

If you want to preset it for system application, it is not enough to copy apk to the/system/app directory, and you need 777 permissions. Command: chmod 777 target. apk

In general, there are the following codes:

adb root
adb remount
adb push target.apk /system/app

adb shell
cd ../system/app
chomd 777 target.apk

reboot

There are also some places that can be operated by the following commands:


 $ adb push SecureSetting.apk /sdcard/ //  Upload the files to be installed to prepare for installation. 
 $ adb shell $ su //  Switch to  root  User. If you don't get it  Root  Permissions, this 1 Step will not succeed. 
 # mount // Displays the current mount Situation 
 # mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system //  Make partitions writable.  
 # cat /sdcard/SecureSetting.apk > /system/app/SecureSetting.apk //  This 1 Step can be used  cp  Implementation, but 1 This command is not included in the device. If you use  mv  An error occurs: failed on '/sdcard/NetWork.apk' - Cross-device link .  
 chmod 777 chetou.apk
 # mount -o remount,ro -t yaffs2 /dev/block/mtdblock3 /system //  Restores partition properties, read-only.  
 # exit $ exit

Related articles: