Inspecting an apk
The commands on this page read and write nothing. You can use them on any file without fear of changing it.
Find out what the file is
Always start here. ngr identify looks at the structure of the file, not its extension,
and says which commands accept it:
ngr identify app.apk
file: app.apk
structure: apk with dex in the root (114,280 B)
verbs: info, resource, xml, decode, refactor, protect, align, sign, verify, rotate, lineage, disassemble, dump, list, decompile
caveats:
...
The verbs: line is the one that counts. A bundle (.xapk, .apkm, .apks) is not an apk, and info,
resource, xml and verify do not accept it: you have to “merge it” first.
Package, version and permissions
ngr info with no options gives the essentials:
ngr info app.apk
package="com.example.app"
VersionCode="7"
VersionName="1.2.3"
AppName="Example"
AppIcon="res/mipmap-mdpi-v4/ic_launcher.png"
application-class=".App"
activity-main=".MainActivity"
To see something else, ask for it. Each content option you give replaces the default set:
ngr info --permissions --min-sdk-version --target-sdk-version app.apk
And with --format json the answer can be read by a program:
ngr info --format json --package --version-code app.apk
[
{
"package":"com.example.app",
"VersionCode":7
}
]
The manifest
An apk's AndroidManifest.xml is compiled. ngr xml shows it as a tree, without unpacking
anything:
ngr xml app.apk AndroidManifest.xml
source-path="AndroidManifest.xml"
N: android=http://schemas.android.com/apk/res/android
E: manifest (line=2)
A: android:versionCode(0x0101021b)=(type 0x10)0x7
A: android:versionName(0x0101021c)="1.2.3" (Raw: "1.2.3")
...
It works for any compiled xml in the apk, such as a layout in res/. If you want the manifest as text xml, to read
or edit it, use ngr decode.
The resources
To see which files and resources there are:
ngr info --files app.apk
ngr info --resources --filter-type string app.apk
And to see the value of one, ngr resource, by name or by identifier. With -v it
shows all its configurations, for example each language:
ngr resource -v app.apk @string/app_name
The code
ngr list lists what is in the dex files, one thing per line, ready to filter:
ngr list dex app.apk
ngr list classes app.apk | grep MainActivity
ngr list strings app.apk | grep -i http
To read the code, “decompile it to Java” or disassemble it to smali with
ngr disassemble.
The signature
ngr verify says whether the apk's signatures verify. With -v it gives the verdict for
each scheme, and with --print-certs, who signed it:
ngr verify -v --print-certs app.apk
“Signing and verifying” explains how to read the answer.
A protected apk
If info, resource or xml answer WARN: PROTECTED on stderr and print nothing, the apk has entries under
classes.dex/ or AndroidManifest.xml/, as if those files were folders. ngr does not read those apks
(“Messages and troubleshooting”).
See also
ngr identify,ngr info,ngr resource,ngr xmlandngr list.- “Using ngr in scripts”, to get this data with a program.