I want to write an android app which can analyse the APK file and output the permissions this application required? I saw some app achieve this and can anyone tell me which method they might used? thanks
我想写一个Android应用程序,可以分析APK文件并输出此应用程序所需的权限?我看到一些应用程序实现了这一点,谁能告诉我他们可能使用哪种方法?谢谢
1 个解决方案
#1
The best way of doing it with external apk files, not the installed ones:
使用外部apk文件执行此操作的最佳方法,而不是已安装的文件:
The .apk
file is a casual .zip
with changed extension. The permissions are located in AndroidManifest.xml
file, so your job is to load it into memory, parse with some XML parser and search for uses-permission
tag.
It looks like this <uses-permission android:name="android.permission.XXX"/>
.
.apk文件是一个随意的.zip,扩展名已更改。权限位于AndroidManifest.xml文件中,因此您的工作是将其加载到内存中,使用某些XML解析器进行解析并搜索uses-permission标记。它看起来像
To unzip the xml from Archive i would recommend This SO post You should modify it to grab only the .xml file, and Documentation of ZipEntry is telling that it has a .getName()
method. I will leave the xml-parsing research for you (that tutorial is not bad), and yes, its obviously possible.
要从Archive解压缩xml,我建议使用这个SO帖子你应该修改它以仅获取.xml文件,而ZipEntry的文档告诉它有一个.getName()方法。我将为您留下xml解析研究(该教程也不错),是的,它显然是可能的。
EDIT: I found one library that could possibly do it - APK-Parser Github, but it was not tested on android. Some users are reporting some issues on android L
编辑:我找到了一个可以做到的库 - APK-Parser Github,但它没有在android上测试过。一些用户报告了一些关于android L的问题
try(ApkParser apkParser = new ApkParser(new File(filePath))) {
for (String permission: apkMeta.getUsesPermissions()) {
Log.d("APK PERM",permission);
}
}
#1
The best way of doing it with external apk files, not the installed ones:
使用外部apk文件执行此操作的最佳方法,而不是已安装的文件:
The .apk
file is a casual .zip
with changed extension. The permissions are located in AndroidManifest.xml
file, so your job is to load it into memory, parse with some XML parser and search for uses-permission
tag.
It looks like this <uses-permission android:name="android.permission.XXX"/>
.
.apk文件是一个随意的.zip,扩展名已更改。权限位于AndroidManifest.xml文件中,因此您的工作是将其加载到内存中,使用某些XML解析器进行解析并搜索uses-permission标记。它看起来像
To unzip the xml from Archive i would recommend This SO post You should modify it to grab only the .xml file, and Documentation of ZipEntry is telling that it has a .getName()
method. I will leave the xml-parsing research for you (that tutorial is not bad), and yes, its obviously possible.
要从Archive解压缩xml,我建议使用这个SO帖子你应该修改它以仅获取.xml文件,而ZipEntry的文档告诉它有一个.getName()方法。我将为您留下xml解析研究(该教程也不错),是的,它显然是可能的。
EDIT: I found one library that could possibly do it - APK-Parser Github, but it was not tested on android. Some users are reporting some issues on android L
编辑:我找到了一个可以做到的库 - APK-Parser Github,但它没有在android上测试过。一些用户报告了一些关于android L的问题
try(ApkParser apkParser = new ApkParser(new File(filePath))) {
for (String permission: apkMeta.getUsesPermissions()) {
Log.d("APK PERM",permission);
}
}