為了讓應用程序可以直接調用su執行系統命令和獲取root權限,本文基于Purple Pi OH主板的Android SDK,介紹如果修改和編譯一個root版本的Android11系統,以下為sdk源碼修改方法。
Purple Pi OH作為一款兼容樹莓派的開源主板,采用瑞芯微RK3566 (Cortex-A55) 四核64位超強CPU,主頻最高達1.8 GHz,算力高達1Tops,支持INT8/INT16,支持TensorFlow/MXNet/PyTorch/Caffe框架,多路視頻輸出和輸入,支持4K、H.265/H.264視頻解碼,接口豐富。
玩法豐富,支持OpenHarmony、Ubuntu、Debian、Android等多種系統,提供豐富開源資料。
關閉selinux
device/rockchip/common/BoardConfig.mk
diff --git a/device/rockchip/common/BoardConfig.mkb/device/rockchip/common/BoardConfig.mkindexe03c54f6a0..4fc6dc9868 100755--- a/device/rockchip/common/BoardConfig.mk+++ b/device/rockchip/common/BoardConfig.mk@@ -59,7+59,7@@ BOARD_BOOT_HEADER_VERSION ?= 2BOARD_MKBOOTIMG_ARGS :=BOARD_PREBUILT_DTBOIMAGE ?= $(TARGET_DEVICE_DIR)/dtbo.imgBOARD_ROCKCHIP_VIRTUAL_AB_ENABLE ?= false-BOARD_SELINUX_ENFORCING ?= true+BOARD_SELINUX_ENFORCING ?= false# Use the non-open-sourceparts, ifthey're present
注釋用戶組權限檢測
system/extras/su/su.cpp
diff --git a/system/extras/su/su.cpp b/system/extras/su/su.cppindex 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文件默認授予root權限
system/core/libcutils/fs_config.cpp
diff --git a/system/core/libcutils/fs_config.cpp b/system/core/libcutils/fs_config.cppindex 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.cppindex 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.cindex 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;
編譯鏡像
修改后需要重新編譯內核和AOSP,Android編譯需要選擇rk3566_r-userdebug版本
sourcebuild/envsetup.shlunch rk3566_r-userdebug
檢測驗證root是否成功
可在應用程序中調用 /system/xbin/su來測試系統是否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的系統可正常執行,而非root的系統會提示沒有權限
java.io.IOException: Cannot run program "/system/xbin/su": error=13, Permission denied
-
Android
+關注
關注
12文章
3935瀏覽量
127348 -
主板
+關注
關注
53文章
1875瀏覽量
70772 -
root
+關注
關注
1文章
86瀏覽量
21389 -
Purple
+關注
關注
0文章
8瀏覽量
237
發布評論請先 登錄
相關推薦
評論