mtk 如何永久性开启adb 的root权限

[Description]
如何永久性开启adb 的root权限

[Keyword]
user debug root adb adbd

[Serious Declaration]
严重声明: 任何在最终user版本上打开root权限的手法都会给用户带来安全风险, 请仔细评估您的需求是否真实需要. MTK 强烈反对此类做法, 由此带来的安全风险,以及造成的损失, MTK 不承担任何的责任。

[Solution]

  • adb 的root 权限是在system/core/adb/adb.c 中控制。主要根据ro.secure 以及 ro.debuggable 等system property 来控制。
    默认即档ro.secure 为0 时,即开启root 权限,为1时再根据ro.debuggable 等选项来确认是否可以用开启root 权限。为此如果要永久性开启adb 的root 权限,有两种修改的方式:
  1. 修改system property ro.secure, 让ro.secure=0。
  2. 修改adb.c 中开启root 权限的判断逻辑。
  • 在L 版本上adb 会受到SELinux 的影响, 所以需要调整SELinux policy 设置.

下面详细说明这两种修改方式:
第一种方法. 修改system property ro.secure, 让ro.secure=0。
(1)修改alps/build/core/main.mk
ifneq (,$(user_variant))

Target is secure in user builds.

ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1

将ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1 改成 ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=0 即可。

(2)在android JB 版本(4.1) 以后,google 从编译上直接去除了adbd 的user 版本root 权限, 为此您要修改system/core/adb/Android.mk 中的编译选项ALLOW_ADBD_ROOT, 如果没有打开这个选项,那么adb.c 中将不会根据ro.secure 去选择root 还是shell 权限,直接返回shell 权限。因此您必须需要Android.mk 中的第126行:
ifneq (, ( f i l t e r u s e r d e b u g e n g , (filter userdebug eng, (filteruserdebugeng,(TARGET_BUILD_VARIANT)))
===> ifneq (, ( f i l t e r u s e r d e b u g u s e r e n g , (filter userdebug user eng, (filteruserdebugusereng,(TARGET_BUILD_VARIANT)))

(3)在android L (5.0) 以后, google 默认开启SELinux enforce mode, 需要在user build 上将su label 默认build 进SEPolicy.
放开SELinux 的限制. 更新alps/external/sepolicy/Android.mk 116 行, 将su label 默认编译进入sepolicy.
sepolicy_policy.conf := $(intermediates)/policy.conf
$(sepolicy_policy.conf): PRIVATE_MLS_SENS := $(MLS_SENS)
$(sepolicy_policy.conf): PRIVATE_MLS_CATS := $(MLS_CATS)
$(sepolicy_policy.conf) : $(call build_policy, $(sepolicy_build_files))
@mkdir -p $(dir $@)
( h i d e ) m 4 − D m l s n u m s e n s = (hide) m4 -D mls_num_sens= (hide)m4Dmlsnumsens=(PRIVATE_MLS_SENS) -D mls_num_cats=KaTeX parse error: Undefined control sequence: \ at position 20: …VATE_MLS_CATS) \̲ ̲ -D target_bu…(TARGET_BUILD_VARIANT)
-D force_permissive_to_unconfined=$(FORCE_PERMISSIVE_TO_UNCONFINED)
-s $^ > $@
$(hide) sed ‘/dontaudit/d’ $@ > $@.dontaudit

将-D target_build_variant=$(TARGET_BUILD_VARIANT) 改成 -D target_build_variant=eng

如果是N 版本, selinux policy 已经搬移到 alps/system/sepolicy.

如果是O版本,target_build_variant需要在/system/sepolicy/definitions.mk中修改。同时,需要将

将/system/sepolicy/Android.mk中的两行 exit 1; 注释掉.

( h i d e ) i f [ " (hide) if [ " (hide)if["(TARGET_BUILD_VARIANT)" = “user” -a -s $@.permissivedomains ]; then
echo “==========” 1>&2;
echo “ERROR: permissive domains not allowed in user builds” 1>&2;
echo “List of invalid domains:” 1>&2;
cat $@.permissivedomains 1>&2;
– exit 1; \ //MTK

++ #exit 1; \ //MTK
fi
$(hide) mv $@.tmp $@

即第一种方法在android L(5.0) 以后你需要改(1),(2),(3).

第二种方法. 修改adb.c 中开启root 权限的判断逻辑。这里针对4.1 以后版本 和4.1以前版本有所区别。
(1).如果是JB 4.1 以后版本,直接在/system/core/adb/daemon/main.cpp 修改should_drop_privileges() 函数, 清空这个函数,直接返回 0 即可。返回0 即开启root 权限。

(2).如果是JB 4.1 以前版本,直接修改函数adb_main 函数,在
/* don’t listen on a port (default 5037) if running in secure mode /
/
don’t run as root if we are running in secure mode */
if (secure) {
struct __user_cap_header_struct header;
struct __user_cap_data_struct cap;

    if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) != 0) {
        exit(1);
    }

在这段代码前加一行:

secure = 0;  //mtk71029 add for root forever.

/* don't listen on a port (default 5037) if running in secure mode */
/* don't run as root if we are running in secure mode */
if (secure) {
    struct __user_cap_header_struct header;
    struct __user_cap_data_struct cap;

    if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) != 0) {
        exit(1);
    }

(3)在android L (5.0) 以后, google 默认开启SELinux enforce mode, 需要在user build 上将su label 默认build 进SEPolicy.
放开SELinux 的限制. 更新alps/external/sepolicy/Android.mk 116 行, 将su label 默认编译进入sepolicy.
sepolicy_policy.conf := $(intermediates)/policy.conf
$(sepolicy_policy.conf): PRIVATE_MLS_SENS := $(MLS_SENS)
$(sepolicy_policy.conf): PRIVATE_MLS_CATS := $(MLS_CATS)
$(sepolicy_policy.conf) : $(call build_policy, $(sepolicy_build_files))
@mkdir -p $(dir $@)
( h i d e ) m 4 − D m l s n u m s e n s = (hide) m4 -D mls_num_sens= (hide)m4Dmlsnumsens=(PRIVATE_MLS_SENS) -D mls_num_cats=KaTeX parse error: Undefined control sequence: \ at position 20: …VATE_MLS_CATS) \̲ ̲ -D target_bu…(TARGET_BUILD_VARIANT)
-D force_permissive_to_unconfined=$(FORCE_PERMISSIVE_TO_UNCONFINED)
-s $^ > $@
$(hide) sed ‘/dontaudit/d’ $@ > $@.dontaudit

将-D target_build_variant=$(TARGET_BUILD_VARIANT) 改成 -D target_build_variant=eng

如果是N 版本, selinux policy 已经搬移到 alps/system/sepolicy.

如果是O版本,target_build_variant需要在/system/sepolicy/definitions.mk中修改。同时,需要将

将/system/sepolicy/Android.mk中的两行 exit 1; 注释掉.

( h i d e ) i f [ " (hide) if [ " (hide)if["(TARGET_BUILD_VARIANT)" = “user” -a -s $@.permissivedomains ]; then
echo “==========” 1>&2;
echo “ERROR: permissive domains not allowed in user builds” 1>&2;
echo “List of invalid domains:” 1>&2;
cat $@.permissivedomains 1>&2;
– exit 1; \ //MTK

++ #exit 1; \ //MTK
fi
$(hide) mv $@.tmp $@

即第二种方法在android L(5.0) 以后你需要改(1),(3).

[测试与确认]
当修改完成后,只需要重新build bootimage ,然后download 即可,然后到setting 中开启debug 选项,adb 连接后,会显示 #, 即root 成功。

[相关FAQ]
JB 版本后user build + eng bootimage 无法开机
如何打开user debug选项
JB 4.2 user 版本的开发选项不见了,如何打开adb debug

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值