Programing

안드로이드 APK의 패키지 이름을 읽으십시오

lottogame 2020. 5. 16. 10:02
반응형

안드로이드 APK의 패키지 이름을 읽으십시오


Android APK 패키지 이름 을 가져와야합니다. APK의 압축을 풀고의 내용을 읽으려고했지만 AndroidManifest.xml텍스트 파일이 아닌 것 같습니다.

APK의 패키지 이름을 추출하려면 어떻게합니까?


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

휴대 전화에 APK를 설치 한 다음

adb를 사용하여 연결하면 adb 셸을 시작하고 설치된 각 apk의 패키지 이름을 보여주는 pm list packages -f를 실행할 수 있습니다.

텐트를 사용하여 웹에서 마켓 앱을 시작하기 위해 Android 앱의 패키지 이름 찾기 에서 가져 왔습니다.


MS 메모장을 사용하여 AndroidManifest.xml을 열면 구를 검색 package하면 다음을 찾을 수 있습니다.

package manifest $xxx.xxxxxxx.xxxxxxx |

여기서 xxx.xxxxxxx.xxxxxxx는 각 문자 다음에 공백으로 작성된 패키지 이름입니다.

특정 도구가 설치되어 있지 않을 때 유용한 방법입니다.


구글 플레이를보고 패키지 이름을 알고 싶다면 URL 또는 주소 표시 줄을 볼 수 있습니다. 패키지 이름을 얻습니다. com.landshark.yaum패키지 이름은 다음과 같습니다

 https://play.google.com/store/apps/details?id=com.landshark.yaum&feature=search_result#?t=W251bGwsMSwyLDEsImNvbS5sYW5kc2hhcmsueWF1bSJd

다음 bash 스크립트는 패키지 이름과 기본 활동 이름을 표시합니다.

apk_package.sh

package=$(aapt dump badging "$*" | awk '/package/{gsub("name=|'"'"'","");  print $2}')
activity=$(aapt dump badging "$*" | awk '/activity/{gsub("name=|'"'"'","");  print $2}')
echo
echo "   file : $1"
echo "package : $package"
echo "activity: $activity"

다음과 같이 실행하십시오.

apk_package.sh /path/to/my.apk

@hackbod 답변을 기반으로하지만 창과 관련이 있습니다.

aapt명령은에 있습니다 Android\SDK\build-tools\version. appt command(Android Asset Packaging Tool) 에 대한 자세한 정보가 필요 하면 https://stackoverflow.com/a/28234956/812915를 읽으십시오.

dump하위 명령은 aapt패키지의 개별 요소 또는 부분 값을 표시하는 데 사용됩니다.

aapt dump badging <path-to-apk>

package: name정보가 있는 줄만 표시 하려면findstr

aapt dump badging <path-to-apk> | findstr -n "package: name" | findstr "1:"

다른 Windows 사용자를 돕기를 바랍니다!


프로그램 답변

프로그래밍 방식 으로이 작업을 수행 해야하는 경우 뇌에 답을 얻는 것보다 조금 더 복잡합니다. 모든 앱에 서명하는 데 사용하는 스크립트가 있지만 각각 다른 키를 사용합니다. 다음은 패키지 이름 을 출력 으로 가져 와서 변수에 넣거나 필요한 것을 수행 할 수 있는 두 가지 방법 입니다.

출력 예 : com.example.appname(그리고 그 이상은 아닙니다)

요구 사항

aapt-SDK 도구 다운로드의 일부인 Android Asset Packaging Tool

해결책 1

필드 구분 기호로 awk지정 '사용 하여을 사용 하여 행을 검색하고 행 package: name=에서 두 번째 "필드"만 인쇄하십시오.

aapt dump badging /path/to/file.apk | awk -v FS="'" '/package: name=/{print $2}'

이 방법의 약점은 패키지 정보 필드를 동일한 순서로 출력하는 데 적합하다는 것입니다.

package: name='com.example.appname' versionCode='3461' versionName='2.2.4' platformBuildVersionName='4.2.2-1425461'

우리는이 형식을 유지하려는 개발자의 약속이 없습니다.

해결책 2

필드 구분 기호로 awk지정 "사용 하여을 사용 하여 행을 검색하고 행 package=에서 두 번째 "필드"만 인쇄하십시오.

aapt list -a /path/to/file.apk | awk -v FS='"' '/package=/{print $2}'

이 방법의 약점은 출력 섹션 package=에서만 출력에 적합하다는 것 Android Manifest:입니다. 우리는이 형식을 유지하려는 개발자의 약속이 없습니다.

해결책 3

로 apk 파일을 apktool d펼치고 AndroidManifest.xml을 읽으십시오.

이것이 가장 좋은 방법이지만 AndroidManifest.xml은 이진 파일이며 텍스트로 변환하는 데 표시되는 모든 SO 답변이 작동하지 않습니다. ( apktool d간단한 대신 사용하면 unzip이 작업을 수행해야하지만 그렇지 않습니다.) 이 문제에 대한 해결책이 있으면 의견을 말하십시오


A simple solution would be Open Android Studio -> Build -> Analyze Apk... browse and select the APK now you can find the package name and pretty much you can read.


If you just want to know package name, run adb logcat, launch the activity you want , you will get a hint on the package name.


Another solution is to use aapt list and use sed to parse through that:

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


There's a very simple way if you got your APK allready on your Smartphone. Just use one of these APPs:

Package Name Viewer Apps


I think the best and simplest way to extract only the package name in Linux is

aapt dump badging <APK_path> | grep package | sed -r "s/package: name='([a-z0-9.]*)'.*/\1/"

Explanation:

  1. AAPT extracts the APK information
  2. Grep "package" to keep only the line about the package information
  3. Make sed replace the whole line with the package name only using the following regex: package: name='([a-z0-9.]*)'.* and replacing with the first (and only) matching group.

You can extract AndroidManifest.xml from the APK, remove all NULL bytes, skip everything until after the string 'manifest', and then you are at a length byte followed by the package name (and what comes after it). For the difficult task I use the great GEMA tool, so the command looks like this:

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

Of course, you can use any other tool to do the filtering.


you can instal Package_Name_Viewer.apk on your emulator and next you can see package name of all instaled app on your emulator.


I also tried the de-compilation thing, it works but recently I found the easiest way:

  1. Download and install Appium from Appium website

  2. Open Appium->Android setting, choose the target apk file. And then you get everything you want, the package info, activity info.


To use this in batch scripting it's handy to have the script return just the package name (e.g. for uninstalling an app when you have the APK).

Here's the script I use:

# extract the android package id from a built apk file
# usage ./getPackageName.sh <path-to-apk>
line=`aapt dump badging "$1" | grep package:\ name`

# above returns:
# package: name='com.calvium.myapp' versionCode='1' versionName='1.0'
if [[ $line =~ name=\'(.+)\'\ versionCode ]]; then
    echo ${BASH_REMATCH[1]}
else
    echo "Failed to find package name"
    exit 1
fi

available on gist

So you could write:

adb uninstall `./getPackageName.sh file.apk`


For Windows following worked for me:

:: // 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

Please edit the paths of adb, aapt, APKPath according to the paths of adb, aapt, and the apk location in your system.

Working:

  • 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.

In essence the above code installs the apk from given location in desktop "Desktop\APK\Instant_Instal\" to the device and launches the application.


As I don't was able to find the package name in the .apk file with editor (like suggested above), I have checked the functions in the App "ES Datei Explorer" / "ES File Explorer" (free version) that I had installed already. In this tool, the package name is showed properly.
As I think a good file explorer should not be missing on a phone, I suggest to use this tool (if you already have installed the apk on an mobile and have to know the package name).


Since its mentioned in Android documentation that AAPT has been deprecated, getting the package name using AAPT2 command in Linux is as follows:

./aapt2 dump packagename <path_to_apk>

Since I am using an older version of Gradle build, I had to download a newer version of AAPT2 as mentioned here :

Download AAPT2 from Google Maven

Using the build-tools in my sdk - 25.0.3, 26.0.1 and 27.0.3, executing the aapt2 command shows an error: Unable to open 'packagename': No such file or directory. That's why I went for the newer versions of AAPT2.

I used 3.3.0-5013011 for linux.


If you don't have the Android SDK installed, like in some test scenarios, you can get the package name using the following bash method:

getAppIdFromApk() {
  local apk_path="$1"

  # regular expression (required)
  local re="^\"L.*/MainActivity;"
  # sed substitute expression
  local se="s:^\"L\(.*\)/MainActivity;:\1:p"
  # tr expression
  local te=' / .';

  local app_id="$(unzip -p $apk_path classes.dex | strings | grep -Eo $re | sed -n -e $se | tr $te)"

  echo "$app_id"
}

Tested on a mac. 'strings' and 'unzip' are standard on most linux's, so should work on linux too.


A very simple method is to use apkanalyzer.

apkanalyzer manifest application-id "${_path_to_apk}"

aapt list -a "path_to_apk"

I recommend you save it in a .txt, because it can be very long. So:

aapt list -a "path_to_apk" > file.txt

Then see the file.txt in your current directory.

참고URL : https://stackoverflow.com/questions/6289149/read-the-package-name-of-an-android-apk

반응형