日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android7.1增加一个开机自启动的bin应用遇到的权限问题

發(fā)布時間:2025/4/16 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android7.1增加一个开机自启动的bin应用遇到的权限问题 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

android7.1增加一個開機(jī)自啟動的bin應(yīng)用遇到的權(quán)限問題

?

1.????增加開機(jī)自啟動的bin應(yīng)用

1.1??增加的源代碼

新建external\study,編譯生成study,編譯方式有兩種

(1)??mmm external/study

(2)??make systemimage,在 device/qcom/common/base.mk下增加LIBCAMERA += study

?

1.2??增加開機(jī)自啟動study

device/qcom/msm8937_64/init.target.rc的

on boot

service study /system/bin/study

???class main

???user? root

oneshot

第1個study是service名稱,第2個study是可執(zhí)行應(yīng)用名稱。

?

1.3??增加study的權(quán)限

(1)??device/qcom/sepolicy/common/file_contexts下增加study

# System files

stem/bin/study?????????????????????? u:object_r: study_exec:s0

file_contexts文件保存系統(tǒng)中所有文件的安全上下文定義,每行前半部分是文件的路徑,后面是它的安全上下文的定義(study_exec)。

?

安全上下文的格式:USER:ROLE:TYPE[LEVEL],在安全上下文規(guī)則中最主要的定義是type,這里是study_exec。TYPE是定義主體和客體所屬的類型,對于進(jìn)程而言,它的類型也稱為domian。

?

(2)??在device/qcom/sepolicy/common/或是其他sepolicy下增加study.te文件。

Te文件屬于類型強(qiáng)制規(guī)則文件(TypeEnforcement),它主要由類型定義和規(guī)則定義兩部分組成

?

#定義了study和study_exec兩種類型,study用在進(jìn)程的安全上下文中,study_exec用在文件的安全上下文中。屬性domain表示域,屬性是android預(yù)先在system\sepolicy\attributes中定義好,當(dāng)然我們也可以定義,比如在device\qcom\sepolicy\common\attributes中。

?

#無論是主題還是客體的類型定義,都是通過type語句來完成,通常主體的type具有domian屬性,因此,我們也把主體的type稱為domain,將domain設(shè)置為study的屬性,表明zygote是用來描述進(jìn)程的安全上下文的。

type study, domain;

#表明類型study_exec具有屬性exec_type和file_type,即它是用來描述文件的安全上下文的

type study_exec, exec_type, file_type;

?

init_daemon_domain(study)

allow study study:capability dac_override;

allow study rootfs:lnk_file { read getattr};

allow study system_data_file:dir {opengetattr read write add_name};

allow study system_data_file:file {opengetattr create read write};

allow study shell_exec:file {read openexecute execute_no_trans rx_file_perms};

allow study toolbox_exec:file {getattrexecute read open execute_no_trans};

這些內(nèi)容是根據(jù)avc denied的log增加的。

?

1)????init_daemon_domain(study)

程執(zhí)行一個type為zygote_exec的文件時,將該子進(jìn)程的domain設(shè)置為zygote,而不是繼承父進(jìn)程的domain。并且給與zygote這個domain,所有定義在tmpfs_domain宏中的權(quán)限。

# init_daemon_domain(domain) # Set up a transition from init to thedaemon domain # upon executing its binary. define(`init_daemon_domain', ` domain_auto_trans(init, $1_exec, $1) tmpfs_domain($1) ')

init_daemon_domain(study)是一個宏,聲明當(dāng)一個domain為init的進(jìn)程創(chuàng)建一個子進(jìn)程執(zhí)行一個type為study_exec的文件時,將該子進(jìn)程的domain設(shè)置為study,而不是繼承父進(jìn)程的domain。并且給與study這個domain,所有定義在tmpfs_domain宏中的權(quán)限。

?

2)????allow語句

比如allow study system_data_file:file {opengetattr create read write};

rule_name source_type target_type : classperm_set

?

source_type:通常是某種屬性為domain的類型(type),代表主體。

Target_type(目標(biāo)類型):允許訪問的客體的類型,目標(biāo)類型可以同時指定多個,

Class(客體類別):允許訪問的客戶的目標(biāo)類型可能會涵蓋比較廣的范圍,客體類別可以對客體目標(biāo)類型進(jìn)行限制和明確化,例如這里目標(biāo)類型是system_data_file可以代表文件(file)、目錄(dir)及鏈接(lnk_file),通過file對它進(jìn)行了限制,因此,在這條規(guī)則中只代表文件。

?

增加的內(nèi)容需要編譯生成新的boot.img和生成study,其中增加的study.te文件在make bootimage編譯的時候生成在out\target\product\msm8937_64\root\sepolicy中,而file_contexts文件匯總生成為out\target\product\msm8937_64\root\file_contexts.bin,file_contexts.bin文件,file_contexts.bin 和 file_contexts可互轉(zhuǎn),見鏈接:

https://blog.cofface.com/archives/2255.html

?

sepolicy可用二進(jìn)制工具bless查找里面的內(nèi)容。

?

2.????adb方式更新boot.img和study---OK

用fastboot燒錄boot.img和adb push study到/system/bin下驗證正常。

通過ls -z study方式得到結(jié)果:

u:object_r:study_exec:s0system/bin/study

?

3.????升級包update.zip方式更新boot.img和study---權(quán)限問題

更新后提示init: Service study does not have aSELinux domain defined.

通過ls -z study方式得到結(jié)果:

u:object_r:system_file:s0 system/bin/study

可見用adb的方式study的類型是study_exec,升級包的方式是system_file,為什么是system_file呢?見文件system\sepolicy\file.te下面的內(nèi)容

# Default type for anything under /system.

type system_file, file_type;

?

為了解決init: Service study does not have aSELinux domain defined.問題,需要在升級包的META-INF\com\google\android\updater-script文件增加下面的內(nèi)容:

set_metadata("/system/bin/study","uid", 0, "gid", 2000, "mode", 0755,"capabilities", 0x0, "selabel", "u:object_r:study_exec:s0");

總結(jié)

以上是生活随笔為你收集整理的android7.1增加一个开机自启动的bin应用遇到的权限问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。