我需要得到一个Android APK的包名。我已经尝试解压缩APK和读取AndroidManifest.xml文件的内容,但它似乎不是一个文本文件。

如何提取APK的包名?


当前回答

一个非常简单的方法是使用apkanalyzer。

apkanalyzer manifest application-id "${_path_to_apk}"

其他回答

对于Windows,以下对我来说是有效的:

:: // Initializing variables
SET adb="C:\Users\<User name>\AppData\Local\Android\Sdk\platform-tools\adb"
SET aapt="C:\Users\<User name>\AppData\Local\Android\Sdk\build-tools\22.0.0\aapt"
SET APKPath=C:\Users\<User name>\Desktop\APK\Instant_Instal\

CD %APKPath%

:: // Searching for apk file and storing it
FOR /F "delims=" %%f IN ('dir /S /B *.apk') DO SET "APKFullPath=%%f"
SET apk=%APKFullPath%

:: // Command adb install apk, run apk
%adb% install %apk%

:: // Fetching package name from apk
%aapt% dump badging %APKFullPath% | FIND "package: name=" > temp.txt
FOR /F "tokens=2 delims='" %%s IN (temp.txt) DO SET pkgName=%%s
del temp.txt

:: // Launching apk
%adb% shell monkey -p %pkgName% -c android.intent.category.LAUNCHER 1

pause

Note

请根据adb、aapt路径和apk在系统中的位置,编辑adb、aapt、APKPath路径。

工作:

Here I have added the apk in a folder on Desktop "\Desktop\APK\Instant_Instal\". The command %adb% install %apk% installs the application if the device is connected. This %aapt% dump badging %APKFullPath% | FIND "package: name=" > temp.txt fetches package name and a few other details like version etc. of the apk and stores in a temp.txt file in same location as that of the apk. FOR /F "tokens=2 delims='" %%s IN (temp.txt) DO SET pkgName=%%sextracts the package name and assigns topkgName` variable Finally %adb% shell monkey -p %pkgName% -c android.intent.category.LAUNCHER 1 launches the app.

从本质上讲,上面的代码将apk从桌面“desktop \ apk \ instant_install \”中的给定位置安装到设备并启动应用程序。

aapt dump badging <path-to-apk> | grep package:\ name

你可以从APK中提取AndroidManifest.xml,删除所有NULL字节,跳过所有内容直到字符串'manifest'之后,然后你就在一个长度字节后面跟着包名(以及它后面的内容)。对于困难的任务,我使用强大的GEMA工具,因此命令看起来像这样:

7z e -so MyApp.apk AndroidManifest.xml | gema '\x00=' | gema -match 'manifest<U1><U>=@substring{0;@char-int{$1};$2}'

当然,您可以使用任何其他工具来进行筛选。

由于我无法用编辑器在.apk文件中找到包名(如上所述),我检查了我已经安装的应用程序“ES Datei资源管理器”/“ES文件资源管理器”(免费版本)中的功能。 在此工具中,包名称将正确显示。 因为我认为手机上不应该缺少一个好的文件资源管理器,我建议使用这个工具(如果你已经在手机上安装了apk,并且必须知道包的名称)。

另一个解决方案是使用aapt列表,并使用sed来解析它:

aapt list -a $PATH_TO_YOUR_APK | sed -n "/^包组[^s]/s/.*name=//p"