本文将主要介绍通过Python脚本检测apk信息的功能,介绍具体的实现之前,首先介绍一个Android SDK中的开发工具aapt。
aapt即Android Asset Packaging Tool,我们可以在Android SDK的platform-tools目录下找到该工具。aapt可以查看、 创建、 更新ZIP格式的文档,也可将资源文件编译成二进制文件,Android IDE编译Android应用程序的时候就是使用aapt对资源进行打包的。当我们需要对apk进行分析的时候,aapt就派上用场了。
下面首先将会介绍如何使用aapt以及aapt的基本功能。
1. 列出apk包的内容
aapt l[ist] [-v] [-a] file.{zip,jar,apk}
-v 以table形式列出来
-a 详细列出内容
例如:aapt l <你的apk文件>,表示查看apk的内容
2. 查看apk一些信息
aapt d[ump] [--values] WHAT file.{apk} [asset [asset ...]]
badging Print the label and icon for the app declared in APK
permissions Print the permissions from the APK.
resources Print the resource table from the APK.
configurations Print the configurations in the APK.
xmltree Print the compiled xmls in the given assets.
xmlstrings Print the strings of the given compiled xml assets.
例如:aapt d permissions <apk文件>,这个就是显示这个apk所具有的权限。
执行aapt d badging mydemo.apk,会得到下面的结果(未截取全部内容)。可以看到其中包含了应用包名、版本号、permission等信息。
3. 编译android资源
aapt p[ackage] [-d][-f][-m][-u][-v][-x][-z][-M AndroidManifest.xml] /
[-0 extension [-0 extension ...]] [-g tolerance] [-j jarfile] /
[--debug-mode] [--min-sdk-version VAL] [--target-sdk-v