ngr xml
Prints a compiled xml from inside an apk, such as AndroidManifest.xml or a layout from res/layout/, without
unpacking the apk. You use it to read the manifest or an xml resource quickly. It reads the apk and writes nothing.
Usage
ngr xml [options] <apk> <path>...
Inputs
| Input | What it is |
|---|---|
<apk> |
An apk file |
<path> |
The path of a compiled xml inside the apk, such as AndroidManifest.xml. You can give several |
ngr info --xml-files lists the compiled xml files an apk has.
Options
| Option | What it does | Default |
|---|---|---|
--strings |
Prints the string pool of the xml instead of its tree | |
--format <text|json|xml> |
Report format | text |
-h, --help |
Shows the help |
What it writes
It writes no files. Each xml goes to stdout, one after the other, with the path on the first line.
The text format is a tree: N: is a namespace, E: an element and A: an attribute, with the line number of
the element. Values that are references to resources come out as numbers, unresolved.
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")
A: package="com.example.app" (Raw: "com.example.app")
E: uses-sdk (line=0)
A: android:minSdkVersion(0x0101020c)=(type 0x10)0x15
A: android:targetSdkVersion(0x01010270)=(type 0x10)0x22
E: uses-permission (line=9)
A: android:name(0x01010003)="android.permission.INTERNET" (Raw: "android.permission.INTERNET")
...
--format xml prints the text xml, with resources by their name (@string/..., @drawable/...):
<?xml version='1.0' encoding='utf-8' ?>
<info>
<document source-path="res/layout/row.xml">
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:id="@id/row_text"
android:background="@drawable/bg_selector"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/styled_nested" />
...
--format json gives the same tree as objects, with source_path and document.
With --strings the string pool of that xml comes out:
ngr xml --strings app.apk res/layout/row.xml
res/layout/row.xml
String pool of 10 unique UTF-8 non-sorted strings, 10 entries and 0 styles using 208 bytes:
String #0: id
String #1: background
String #2: layout_width
...
Examples
Read the manifest:
ngr xml app.apk AndroidManifest.xml
Read the manifest as text xml, with resources by their name:
ngr xml --format xml app.apk AndroidManifest.xml
Read two layouts at once:
ngr xml app.apk res/layout/row.xml res/layout/activity_main.xml
See the strings of a compiled xml:
ngr xml --strings app.apk res/layout/row.xml
Exit codes
| Code | When |
|---|---|
| 0 | The xml was printed. Also with a protected apk, which gives no report |
| 1 | The apk does not exist or cannot be read, the path is not in the apk or the entry is not a compiled xml |
| 2 | The options are wrong: <apk> is missing or <path> is missing |
Things to know
- The path has to exist in the apk. If it is not there, the command ends with 1 and prints nothing:
ngr xml: unable to read 'app.apk': Entry 'res/nope.xml' not found in the APK.
- Only a compiled xml is valid. Asking for
resources.arscorclasses.dexgives a read error and ends with 1:
ngr xml: unable to read 'app.apk': ResXml: no root element found.
- With several paths, the command prints the ones that come first and stops at the first one that fails, with the error for that path and code 1.
- A protected apk gives no report.
xmlwritesWARN: PROTECTEDto stderr and ends with 0.
See also
ngr info, to list the compiled xml files with--xml-files.ngr resource, to read a resource by its name.ngr decode, to extract all the xml files as text.- “Inspecting an apk”.