3399 android root,RK3399 android8.1 app获取root权限
這里指的是app能利用Runtime.getRuntime().exec("su")或者ProcessBuilder()等創建一個新的具有root權限的shell終端進程,而不是app本身擁有root權限。使得app自身具有root權限這個我沒有研究過,但使得app自身具有system權限則可以使用簽名,在Android Framework 之HelloWorld(三)里有描述。
我是參考了[九鼎RK3399Pro] Android 8.1 系統定制給用戶root權限這篇文章,對NanoPC-T4開發板進行修改的,不過還要修改system/core/adb/set_verity_enable_state_service.cpp->set_verity_enabled_state_service(),這樣運行adb disable-verity才正常,adb remount后也能讀寫/system和/vendor分區了,有點投機取巧,調試階段應該還有其他辦法直接讓/system和/vendor在系統起來時就掛載成可讀寫分區,畢竟adb disable-verity需要重啟生效:
if (!android::base::GetBoolProperty("ro.secure", false)) {
WriteFdFmt(fd, "verity not enabled - ENG build\n");
//return; //不返回
}
下面是修改后su程序的other用戶權限是x,能夠執行。在root和shell用戶下能臨時修改到其他用戶去,譬如 su u0_a58等。文章中還屏蔽了SElinux,同時把一些工具(如su和adb等)的判斷自身是否具有相應權限的代碼注釋掉了。
su工具修改前
ls -l /system/xbin/su
-rwsr-x--- 1 root shell 11064 2020-08-07 10:42 /system/xbin/su
su工具修改后
ls -l /system/xbin/su
-rwsr-sr-x 1 root root 11064 2020-08-20 13:17 /system/xbin/su
所以,無論當前app運行在哪個用戶(如u0_a58之類的)里,都能在app上運行root權限的命令。
private void rootRun(String cmd)
{
try {
// 申請獲取root權限
Process process = Runtime.getRuntime().exec("su"); //"/system/xbin/su"
// 獲取輸出流
OutputStream outputStream = process.getOutputStream();
InputStream is = process.getInputStream();
InputStream es = process.getErrorStream();
DataOutputStream dataOutputStream = new DataOutputStream(outputStream);
dataOutputStream.writeBytes(cmd);
dataOutputStream.flush();
dataOutputStream.close();
outputStream.close();
int code = process.waitFor();
Log.d("TAG", "Run:\"" + cmd +"\", "+"process.waitFor() = " + code);
String line;
BufferedReader br;
br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
while ((line = br.readLine()) != null) {
Log.d("TAG", line);
}
br = new BufferedReader(new InputStreamReader(es, "UTF-8"));
while ((line = br.readLine()) != null) {
Log.e("TAG", line);
}
} catch (Throwable t) {
Log.e("TAG", "Throwable = " + t.getMessage());
t.printStackTrace();
}
}
...
...
rootRun("reboot"); //運行shell命令,在app里重啟android系統
總結
以上是生活随笔為你收集整理的3399 android root,RK3399 android8.1 app获取root权限的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: RecyclerView加载多类型ite
- 下一篇: 如何面试