ngr list
Prints to stdout one of the tables of a dex, one item per line; or, with dex, the dex files inside an apk. From an
apk or an xapk it gives the union of all its dex files, with each item once. It is the quick way to find out what is
in an app's code, and the output can be filtered with grep.
Usage
ngr list [options] <kind> <file>
Inputs
| Input | What it is |
|---|---|
<kind> |
What to list: classes, strings, fields, methods, types or dex |
<file> |
A dex, an apk or an xapk, or a dex inside an apk (app.apk/classes2.dex) |
Options
| Option | What it does | Default |
|---|---|---|
-h, --help |
Shows the help |
What it writes
It writes no files. To stdout, one item per line in alphabetical order. What comes out depends on <kind>:
| Kind | What comes out |
|---|---|
classes |
The classes the dex defines, as descriptors |
strings |
The strings of the dex, in quotes |
fields |
The fields the dex refers to, as class->name:type |
methods |
The methods the dex refers to, as class->name(parameters)return |
types |
The types the dex refers to, primitives included |
dex |
The paths of the dex files of an apk or an xapk, in order. For a bare dex, its path |
$ ngr list classes classes.dex
Lcom/example/app/BootReceiver;
Lcom/example/app/Box$Function;
Lcom/example/app/Box;
...
$ ngr list strings classes.dex
"$SwitchMap$com$example$app$Mode"
"$VALUES"
"$default$greetAll"
...
$ ngr list fields classes.dex
Lcom/example/app/Box;->value:Ljava/lang/Object;
Lcom/example/app/Counter;->LIMIT:I
Lcom/example/app/Counter;->TABLE:[J
...
$ ngr list methods classes.dex
Landroid/app/Activity;-><init>()V
Landroid/app/Activity;->onCreate(Landroid/os/Bundle;)V
Landroid/app/Application;-><init>()V
...
$ ngr list types classes.dex
C
D
F
...
$ ngr list dex app.apk
classes.dex
classes2.dex
fields, methods and types also include the members and types of other classes that the code refers to, such
as Landroid/app/Activity;->onCreate(Landroid/os/Bundle;)V, not just the ones the dex defines. classes gives
only the ones it defines.
Examples
List the classes of a dex:
ngr list classes classes.dex
List the classes of all the dex files of an apk, each one once:
ngr list classes app.apk
List the dex files of an apk:
ngr list dex app.apk
List only the classes of the second dex:
ngr list classes app.apk/classes2.dex
Search with grep for the methods of a class:
ngr list methods app.apk | grep 'Counter;->'
Lcom/example/app/Counter;-><clinit>()V
Lcom/example/app/Counter;-><init>()V
Lcom/example/app/Counter;->add(I)V
Lcom/example/app/Counter;->fib(I)J
Lcom/example/app/Counter;->increment()V
Lcom/example/app/Counter;->ratio()D
Lcom/example/app/Counter;->value()I
Count the classes of an apk:
ngr list classes app.apk | wc -l
Exit codes
| Code | When |
|---|---|
| 0 | The list was printed |
| 1 | The input does not exist or cannot be read, or the dex you name is not in the apk |
| 2 | The options or inputs are wrong: <kind> or <file> is missing, <kind> is not one of the six, or there is an extra input |
A kind that does not exist gives code 2 and says which ones are valid:
ngr list: 'foo' is not a valid kind; use one of: classes, strings, fields, methods, types, dex. See 'ngr help list'.
Things to know
- From an apk you get the union. If an item is in two dex files, it comes out once. In the sample apk, one dex
has 41 classes and the other 2, and
ngr list classes app.apkgives 43; with methods, 161 and 16 give 168. list dexof an xapk gives paths that include the inner entry, such asbase.apk/classes.dex.list dexdoes not accept a dex named inside an apk:ngr list dex app.apk/classes2.dexsays it does not exist. Give it the apk.- Strings come out in quotes, so you can see where they start and end.
See also
ngr disassemble, to see the code of a class as smali.ngr dump, the same tables as annotated bytes.ngr identify, to find out what structure a file has.