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

如何提取APK的包名?


当前回答

你可以从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}'

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

其他回答

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

在Android设备上安装apk。然后

您可以启动adb shell并执行PM list packages -f,这将显示每个已安装apk的包名称。

这是从 找到包名称为Android应用程序使用意图启动市场应用程序从网络。

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

apkanalyzer manifest application-id "${_path_to_apk}"

有一个非常简单的方法,如果你的智能手机上已经准备好了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 \”中的给定位置安装到设备并启动应用程序。