前言
為了讓應(yīng)用程序可以直接調(diào)用su執(zhí)行系統(tǒng)命令和獲取root權(quán)限,本文基于Purple Pi OH主板的Android SDK,介紹如果修改和編譯一個root版本的Android11系統(tǒng),以下為sdk源碼修改方法。
Purple Pi OH作為一款兼容樹莓派的開源主板,采用瑞芯微RK3566 (Cortex-A55) 四核64位超強(qiáng)CPU,主頻最高達(dá)1.8 GHz,算力高達(dá)1Tops,支持INT8/INT16,支持TensorFlow/MXNet/PyTorch/Caffe框架,多路視頻輸出和輸入,支持4K、H.265/H.264視頻解碼,接口豐富。
玩法豐富,支持OpenHarmony、Ubuntu、Debian、Android等多種系統(tǒng),提供豐富開源資料。
產(chǎn)品規(guī)格書:Purple Pi OH 產(chǎn)品手冊
關(guān)閉selinux
device/rockchip/common/BoardConfig.mk
diff --git a/device/rockchip/common/BoardConfig.mkb/device/rockchip/common/BoardConfig.mk
indexe03c54f6a0..4fc6dc9868 100755
--- a/device/rockchip/common/BoardConfig.mk
+++ b/device/rockchip/common/BoardConfig.mk
@@ -59,7+59,7@@ BOARD_BOOT_HEADER_VERSION ?= 2
BOARD_MKBOOTIMG_ARGS :=
BOARD_PREBUILT_DTBOIMAGE ?= $(TARGET_DEVICE_DIR)/dtbo.img
BOARD_ROCKCHIP_VIRTUAL_AB_ENABLE ?= false
-BOARD_SELINUX_ENFORCING ?= true
+BOARD_SELINUX_ENFORCING ?= false
# Use the non-open-sourceparts, ifthey're present
注釋用戶組權(quán)限檢測system/extras/su/su.cpp
diff --git a/system/extras/su/su.cpp b/system/extras/su/su.cpp
index 1a1ab6bf40..af3d2a68c7 100644
--- a/system/extras/su/su.cpp
+++ b/system/extras/su/su.cpp
@@ -80,8+80,8@@ voidextract_uidgids(constchar* uidgids, uid_t* uid, gid_t* gid, gid_t* gids, i
}
intmain(intargc, char** argv){
- uid_tcurrent_uid = getuid();
- if(current_uid != AID_ROOT && current_uid != AID_SHELL) error(1, 0, "not allowed");
+ //uid_t current_uid = getuid();
+ //if (current_uid != AID_ROOT && current_uid != AID_SHELL) error(1, 0, "not allowed");
// Handle -h and --help.
++argv;
給su文件默認(rèn)授予root權(quán)限
system/core/libcutils/fs_config.cpp
diff --git a/system/core/libcutils/fs_config.cpp b/system/core/libcutils/fs_config.cpp
index 5805a4d19b..92e93e76ff 100644
--- a/system/core/libcutils/fs_config.cpp
+++ b/system/core/libcutils/fs_config.cpp
@@ -188,7+188,7@@ staticconststructfs_path_configandroid_files[] = {
// the following two files are INTENTIONALLY set-uid, but they
// are NOT included on user builds.
{ 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/procmem"},
- { 04750, AID_ROOT, AID_SHELL, 0, "system/xbin/su"},
+ { 06755, AID_ROOT, AID_SHELL, 0, "system/xbin/su"},
// the following files have enhanced capabilities and ARE included
// in user builds.
frameworks/base/core/jni/com_android_internal_os_Zygote.cpp
diff --git a/frameworks/base/core/jni/com_android_internal_os_Zygote.cpp b/frameworks/base/core/jni/com_android_internal_os_Zygote.cpp
index 9eede83e21..d161e6fad3 100644
--- a/frameworks/base/core/jni/com_android_internal_os_Zygote.cpp
+++ b/frameworks/base/core/jni/com_android_internal_os_Zygote.cpp
@@ -656,7+656,7@@ staticvoidEnableKeepCapabilities(fail_fn_t fail_fn) {
}
staticvoidDropCapabilitiesBoundingSet(fail_fn_t fail_fn) {
- for(inti = 0; prctl(PR_CAPBSET_READ, i, 0, 0, 0) >= 0; i++) {;
+/* for (int i = 0; prctl(PR_CAPBSET_READ, i, 0, 0, 0) >= 0; i++) {;
if (prctl(PR_CAPBSET_DROP, i, 0, 0, 0) == -1) {
if (errno == EINVAL) {
ALOGE("prctl(PR_CAPBSET_DROP) failed with EINVAL. Please verify "
@@ -665,7 +665,7 @@ static void DropCapabilitiesBoundingSet(fail_fn_t fail_fn) {
fail_fn(CREATE_ERROR("prctl(PR_CAPBSET_DROP, %d) failed: %s", i, strerror(errno)));
}
}
- }
+ }*/
}
kernel/security/commoncap.c
diff --git a/kernel/security/commoncap.c b/kernel/security/commoncap.c
index 876cfe01d9..ce87b1b780 100644
--- a/kernel/security/commoncap.c
+++ b/kernel/security/commoncap.c
@@ -1166,12+1166,12@@ intcap_task_setnice(struct task_struct *p, intnice)
staticintcap_prctl_drop(unsignedlongcap)
{
structcred*new;
-
+/*
if (!ns_capable(current_user_ns(), CAP_SETPCAP))
return -EPERM;
if (!cap_valid(cap))
return -EINVAL;
-
+*/
new= prepare_creds();
if(!new)
return-ENOMEM;
編譯鏡像
修改后需要重新編譯內(nèi)核和AOSP,Android編譯需要選擇rk3566_r-userdebug版本
sourcebuild/envsetup.sh
lunch rk3566_r-userdebug
檢測驗(yàn)證root是否成功
可在應(yīng)用程序中調(diào)用 /system/xbin/su來測試系統(tǒng)是否root成功
publicstaticvoidRootCommand() {
Process process = null;
try{
process = Runtime.getRuntime().exec("/system/xbin/su");
process.waitFor();
} catch(IOException | InterruptedException e) {
e.printStackTrace();
} finally{
if(process != null) {
process.destroy();
}
}
}
root的系統(tǒng)可正常執(zhí)行,而非root的系統(tǒng)會提示沒有權(quán)限
java.io.IOException: Cannot run program "/system/xbin/su": error=13, Permission denied
-
Android
+關(guān)注
關(guān)注
12文章
3935瀏覽量
127339 -
主板
+關(guān)注
關(guān)注
53文章
1875瀏覽量
70764 -
root
+關(guān)注
關(guān)注
1文章
86瀏覽量
21388
發(fā)布評論請先 登錄
相關(guān)推薦
評論