当前位置:   article > 正文

packages.xml数据来源分析(二)_readdefaultpermissionexceptionslocked

readdefaultpermissionexceptionslocked

零零散散的一些记录点,没有完全贯穿起来,正向逆向推理得出的一些整理思路,仅供参考。

** 权限读取路径1**


systemServer.startBootstrapServices-->SystemServerInitThreadPool.get().submit(SystemConfig::getInstance, TAG_SYSTEM_CONFIG);-->SystemConfig()-->readPermissions

SystemConfig中调用readPermissions读取指定目录中的文件信息,并解析存到maps
/system/etc/sysconfig
/system/etc/permissions

/vendor/etc/sysconfig
/vendor/etc/permissions

/odm/etc/sysconfig
/odm/etc/permissions

/oem/etc/sysconfig
/oem/etc/permissions

/product/etc/sysconfig
/product/etc/permissions
文件内容如下:

  1. <permissions>
  2. <feature name="android.hardware.sensor.light" />
  3. </permissions>

那么 以上路径的数据是哪里来的呢???
frameworks/base/data/etc/android.mk 文件

  1. include $(CLEAR_VARS)
  2. LOCAL_MODULE := framework-sysconfig.xml
  3. LOCAL_MODULE_CLASS := ETC
  4. LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/sysconfig
  5. LOCAL_SRC_FILES := $(LOCAL_MODULE)
  6. include $(BUILD_PREBUILT)

编译时会把framework-sysconfig.xml放到system/etc/sysconfig
同理还有platform.xml等等

platform.xml,这个文件中记录了Android APP权限与gid,uid的对应关系.

  1. <permissions>
  2. <permission name="android.permission.BLUETOOTH_ADMIN" >
  3. <group gid="net_bt_admin" />
  4. </permission>
  5. <permission name="android.permission.BLUETOOTH" >
  6. <group gid="net_bt" />
  7. </permission>
  8. <assign-permission name="android.permission.MODIFY_AUDIO_SETTINGS" uid="media" />
  9. <library name="android.test.base"
  10. file="/system/framework/android.test.base.jar" />
  11. <allow-in-power-save package="com.android.providers.downloads" />
  12. <allow-in-data-usage-save package="com.android.providers.downloads" />
  13. <allow-in-power-save package="com.android.cellbroadcastreceiver" />
  14. <allow-in-power-save package="com.android.shell" />
  15. <!-- Whitelist system providers -->
  16. <allow-in-power-save-except-idle package="com.android.providers.calendar" />
  17. <allow-in-power-save-except-idle package="com.android.providers.contacts" />
  18. <!-- These are the packages that are white-listed to be able to run as system user -->
  19. <system-user-whitelisted-app package="com.android.settings" />
  20. <!-- These are the packages that shouldn't run as system user -->
  21. <system-user-blacklisted-app package="com.android.wallpaper.livepicker" />
  22. </permissions>

将APP framework中的权限和底层的gid映射。当APP获得某个权限之后,会获得这个gid所具备的权限。

将APP framework的权限赋予某个系统级别的进程。这样这个进程就可以获得操作APP framework资源的。

jar库文件的映射。APP中通过指定链接的jar库名,通过这层映射关系,可以在链接的找到正确的jar库。
总结:
readPermissions方法读取/ect/permissions目录下的xml文件,并为读取的结果生成相应的数据结构
packages.xml数据来源流程
PackageManagerService构造方法:

  1. PackageManagerService(){
  2. 1.PermissionManagerService.create()-->PermissionManagerService()-->SystemConfig.getInstance().getPermissions()-->mPermissions
  3. 2.mSettings = new Settings()
  4. 3.mFirstBoot = !mSettings.readLPw(sUserManager.getUsers(false));
  5. 4.scanDirTracedLI
  6. 5.scanDirLI
  7. 6.scanPackageTracedLI
  8. 7.decompressSystemApplications
  9. 8.updateAllSharedLibrariesLPw
  10. 9.mPermissionManager.updateAllPermissions
  11. 10.mSettings.applyDefaultPreferredAppsLPw(this, user.id);
  12. applyFactoryDefaultBrowserLPw(user.id);
  13. primeDomainVerificationsLPw(user.id);
  14. 11.SystemServerInitThreadPool.get().submit(()
  15. 12.checkDefaultBrowser();
  16. 13.mSettings.writeLPr();
  17. 14.updateInstantAppInstallerLocked(null);
  18. 15.mDexManager.load(userPackages);
  19. }

#mSettings.readLPw
在读取完权限文件之后,PackageManagerService会在其构造函数中调用Settings的readLPw方法,读取应用包的设置文件。

/data/system/packages.xml
/data/system/packages-backup.xml
/data/system/packages.list
/data/system/users/userid/package-restrictions.xml

packages-backup.xml是packages.xml的备份文件。在每次写packages.xml文件的时候,都会将旧的packages.xml文件先备份,这样做是为了防止写文件过程中文件意外损坏,还能从旧的文件中恢复

#scanDirTracedLI、scanDirLI扫描指定路径下的apk文件并解析

  1. /vendor/overlay
  2. /product/overlay
  3. /system/framework
  4. /system/priv-app
  5. /system/app
  6. /vendor/priv-app
  7. /vendor/app
  8. /odm/priv-app
  9. /odm/app
  10. /oem/priv-app
  11. /oem/app
  12. /carrier/itson/app
  13. /data/ptt/
  14. /product/priv-app
  15. /product/app
  16. /data/app
  17. /preload
  18. /data/app-private

scanDirLI中
1、parallelPackageParser.submit(file, parseFlags);-->parsePackage-->parseMonolithicPackage-->parseBaseApk-->parseBaseApkCommon-->
解析AndroidManifest.xml 拿到apk版本信息、mSharedUserId、installLocation、applicationInfo、
application、overlay、key-sets、permission-group、permission、permission-tree、uses-permission、
uses-permission-sdk-m、uses-permission-sdk-23、uses-configuration、uses-feature、feature-group、
uses-sdk、supports-screens、protected-broadcast....

2、scanPackageChildLI-->addForInitLI():
addForInitLI中
2.1、mSettings.getSharedUserLPw(pkg.mSharedUserId,...)把shareuserid加入到setting中

2.2、mPackages.put(pkg.packageName, pkg);把package信息put到mPackages中
2.3、#//获取apk签名信息并验证完整性
addForInitLI()-->collectCertificatesLI()-->PackageParser.collectCertificates(pkg, skipVerify)-->collectCertificatesInternal(pkg, skipVerify)-->collectCertificates()
collectCertificates中{
ApkSignatureVerifier.plsCertsNoVerifyOnlyCerts//系统应用跳过验证
ApkSignatureVerifier.verify//其他应用验证
}
...

#默认权限授予
systemServer.startOtherServices()-->mPackageManagerService.systemReady()
相关类
frameworks/base/services/core/java/com/android/server/pm/permission/DefaultPermissionGrantPolicy.java

  1. -->mDefaultPermissionPolicy.grantDefaultPermissions(userId)
  2. -->grantPermissionsToSysComponentsAndPrivApps(userId);
  3. grantDefaultSystemHandlerPermissions(userId);
  4. grantDefaultPermissionExceptions(userId);
  5. ...
  6. -->mDefaultPermissionPolicy.scheduleReadDefaultPermissionExceptions()-->readDefaultPermissionExceptionsLocked()-->getDefaultPermissionFiles()-->

默认权限读取路径
/system/etc/default-permissions
/vendor/etc/default-permissions
/odm/etc/default-permissions
/oem/etc/default-permissions
/product/etc/default-permissions
默认授予应用一些权限

#动态权限runtime-permissions
/data/system/users/0/runtime-permissions.xml

PackageManagerService-->mPermissionCallback-->onPermissionGranted-->mSettings.writeRuntimePermissionsForUserLPr()-->mRuntimePermissionsPersistence.writePermissionsForUserSyncLPr(userId);-->writePermissionsSync();

#apk签名
与APK签名相关的文件都位于META-INF目录下
MANIFEST.MF 放的是打包在APK中的文件的Message digest(消息摘要)
CERT.SF文件中存放的也是Message Digest
CERT.RSA文件中存放着CERT.SF的数字签名,以及签名证书
查看CERT.RAS文件中存放的证书
openssl pkcs7 -inform DER -in CERT.RSA -noout -print_certs -text
提取证书
openssl pkcs7 -inform DER -print_certs -in CERT.RSA -out cert.pem
打印证书内容
openssl x509 -in cert.pem -noout -text
有效性验证
openssl smime -verify -in CERT.RSA -inform DER -content CERT.SF -CAfile cert.pem

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/261298
推荐阅读
相关标签
  

闽ICP备14008679号