The decompiler output
ngr decompile says how it wrote each method, and for each change it makes with
respect to the dex, what it is and why. This page is the reference for those marks.
The three categories
Each method comes out in one of three categories. The header of each file counts them:
/* nogar: 3 methods: 1 natural, 0 dispatcher, 2 smali */
| Category | What it is | Does javac compile it? |
|---|---|---|
natural |
Normal Java, with its if, loops, try and switch |
Yes |
dispatcher |
Java with a marked loop where the control flow cannot be structured | Yes |
smali |
The method, or a part of it, stays in smali after a comment with the reason | No |
dispatcher
Some code has a control flow that does not fit the structures of Java: a loop with two entries, for example.
Instead of inventing Java that looks clean and does not do the same thing, ngr writes that part as a state
machine: a switch inside a while (true), with a variable that says which block is next. The comment gives the
reason. This example is abbreviated:
// nogar: dispatcher: irreducible loop
int nogarState = 0;
nogarDispatch: while (true) {
switch (nogarState) {
case 0: {
str = obj2.toString();
if (i <= 0) {
nogarState = 2;
continue nogarDispatch;
}
nogarState = 1;
continue nogarDispatch;
}
...
}
}
It is ugly, but it is Java: javac compiles it and it does what the dex does. With --unstructured smali, that part
comes out as smali instead of as a dispatcher.
smali
When a method cannot be written as Java, its code stays in smali inside the body, after a /* NOGAR ERROR: */
comment with the reason. The lines that start with # say which register is each parameter:
private void init(String str, String str2) {
/* NOGAR ERROR: incompatible register types */
# p0 = this
# p1 = str
# p2 = str2
invoke-direct {p0, p2}, Ljava/lang/RuntimeException;-><init>(Ljava/lang/String;)V
iput-object p1, p0, Lcom/example/Limit;->reason:Ljava/lang/String;
return-void
}
javac rejects the class on purpose: that way a missing method is not compiled by oversight. If a method comes out
as smali, ngr decompile ends with exit code 3.
There are three reasons why a method ends up in smali:
- Java cannot express it. The dex does something the language does not allow you to write. These are the reasons in the “catalog”, a closed list.
- You asked for it with
--unstructured smali. - Its translation is not supported yet or it failed. The reason starts with
unsupported:or withinternal:. It is a limit ofngr, not of the language, and we want to know about it (“Messages and troubleshooting”).
The --report report separates the first case from the others: the catalog reasons carry "catalog": true.
The catalog of what Java cannot express
These are constructs that Dalvik bytecode allows and the Java language does not. They are produced mostly by
optimizers and obfuscators, and by the Kotlin compiler. Some depend on --java-version: what Java 8 cannot write,
Java 17 or 25 sometimes can.
| Reason | What happens in the dex |
|---|---|
monitor without block form |
Takes and releases monitors in a way that does not fit synchronized blocks |
code before super()/this() |
A constructor runs code before calling super(...) or this(...). With --java-version 25, only in some cases |
invoke-super to a non-direct supertype |
Calls with super a method that neither super.m() nor I.super.m() can name |
invoke-direct to a private method of another class |
Calls a private method of a class that is not in its own nest |
invoke-custom without a Java form |
An invoke-custom that is not a lambda, a string concatenation, a record method or a pattern switch |
method handle constant |
Uses const-method-handle or const-method-type |
incompatible register types |
A register has types that no conversion reconciles and that ART rejects, or this is initialized outside a constructor |
constructor of another class |
Creates an object, or chains a constructor, with the <init> of another class |
invoke-super on another object |
An invoke-super on an object that Java cannot write as this |
code that is not valid dalvik bytecode |
The code does not pass the checks of the ART verifier |
new-instance without a constructor call |
Allocates an object and never calls its constructor |
interface static initializer that R8 replaced by a throw |
The static initializer of an interface is just a throw left by R8 |
private interface method below java 9 |
A private interface method, with --java-version 8 |
interface method with a body below java 8 |
An interface method with a body, with --java-version 7 |
constructor that calls itself |
The this(...) chain of a constructor goes back to it |
reference stored as an interface its final class does not implement |
Passes, stores or returns an object as an interface that its class does not implement |
invoke-super to an abstract method |
Calls with super a method that no superclass implements |
read of a private field of another class |
Reads a private field of a class that is written in another file |
interface static initializer with statements that are not field initializers |
The static initializer of an interface does something more than give values to its fields |
enum constants interleaved with coverage probes |
The constants of an enum are mixed with the probes of a coverage tool |
call to a member the dex does not declare |
Uses a method, a field or a constructor of an application class that the class neither declares nor inherits |
enum constants wrapped in method trace calls |
The constants of an enum are wrapped in trace calls |
class without a constructor its superclass accepts |
The class declares no constructor and its superclass has none that works. It is a reason of the class, not of a method |
instance-of of a package-private class of another package |
Does an instanceof of a class it has no access to |
constructor whose whole body is throw (R8) |
A constructor that is only a throw, with no call to super, with --java-version 25 |
method that differs from another only in its return type |
Two methods with the same name and the same parameters, which differ only in what they return |
Some reasons carry a detail, which the report gives in "smaliDetail": initializes this outside a constructor,
for example.
Class warnings
A class warning says that ngr wrote the class in a way worth knowing about. It does not change the category of
its methods. They go to stderr, counted by type, and the report gives them class by class. Some of them:
| Warning | What it means |
|---|---|
no constructor |
The dex declares no constructor. javac adds a default one |
added constructor |
The dex declares no constructor, and one was added so that javac accepts the class |
not nested |
An anonymous or local class is written in its own file, with its binary name, because it could not be proven that writing it in place would be equivalent |
renamed |
Some declaration is written with another name, because javac would reject the dex one |
switch map kept |
The synthetic class that translates the constants of an enum to the keys of a switch is kept |
abstract stubs |
The class does not implement an abstract method. One that throws AbstractMethodError is written |
annotation not written |
An annotation has a value that Java cannot write, and it is not written |
throws not declared |
A method throws a checked exception that the dex does not declare |
declared synchronized |
A method declared synchronized does not lock its whole body as Java does. It is written without synchronized, with the locks its code takes |
The text of each WARN: line explains the warning, so one that is not in this table is understood just as well.
Declared deviations
A declared deviation is a point where the Java that ngr writes differs from the dex only in metadata, or on a
path that does not occur. Each one is applied only when its condition is met, never changes the category of a
method, and is always noted in the report: those of a method, in its "deviations" list; those of a field or a
class, in "modifiersChanged", with what was removed, what was added and the reason.
On fields and modifiers:
| Deviation | What changes |
|---|---|
final removed |
A field loses final because javac would reject how the code assigns it |
constant value removed |
A static final field with a constant value that the code assigns again loses final and the value |
record component field made private |
The field of a record component goes from public final to private final |
class made public for a signature in another package |
A class is written public because a signature in another package names it |
private removed from a nested class used outside its nest |
A private nested class loses private because a class in another file uses it |
override widened to the access of the method it overrides |
A method that overrides another takes the access of that one, when its own is lower |
nested class written wider outside its nest |
A nested class that is written in its own file takes a wider access |
abstract added to a class with an abstract method |
A class with an abstract method, and that nobody instantiates, is written abstract |
functional interface removed from an interface without an abstract method |
@FunctionalInterface is removed from an interface that has no abstract method |
documented added to a repeatable container |
@Documented is added to the container of a repeatable annotation |
On bridge methods and twins:
| Deviation | What changes |
|---|---|
bridge regenerated with the target's access |
A synthetic bridge that javac generates again from the method it forwards to is omitted |
bridge the superclass already declares |
A bridge that the superclass already declares is omitted |
twin written as a bridge |
Of several methods with the same name and the same parameters, one is written and the others stay as bridges |
synthetic twin written as a method |
Synthetic twins with the same code are written as one method |
On enums:
| Deviation | What changes |
|---|---|
enum constructor parameters reordered |
The parameters of an enum constructor are written in the order Java requires |
null check removed from an enum valueOf |
The null check that the Kotlin compiler adds to valueOf is removed |
enum constant field written public static final |
The field of a constant is written public static final even though in the dex it is not |
enum constant field written with the enum type |
The field of a constant is written with the type of the enum, not that of its anonymous body |
constructor added to an enum constant body |
A constructor is added to the body of a constant that declares none |
dead enum constructor omitted |
An enum constructor that only throws and that nobody calls is omitted |
On constructors and synchronized blocks:
| Deviation | What changes |
|---|---|
forwarding constructor added for a superclass constructor |
A constructor that the dex calls and the class does not declare is added to a class |
platform class treated as initialized |
A new-instance and its constructor are written as a single new, even though there is code between the two that can fail |
inline marker does not throw |
Calls to Kotlin's InlineMarker are assumed not to throw |
inline marker arguments are interchangeable |
Calls to InlineMarker with a different number are treated as equal |
instruction outside the monitor handler written inside synchronized |
An instruction that the dex leaves outside the handler of a monitor is written inside the synchronized block |
monitor lock is not null |
The object of a synchronized block is assumed not to be null when it is released |
The JSON report
--report <file> writes a JSON with all of the above, to read with a program. Its schema may change between 0.x
versions.
At the top go the options of the run:
{
"tool": "ngr",
"version": "0.1.0",
"input": "app.apk",
"javaVersion": 8,
"androidApi": 36,
"unstructured": "dispatcher",
"summary": { ... },
"classes": [ ... ]
}
summary has the counts for the whole input. The main ones:
| Field | What it counts |
|---|---|
classes, files, methods |
Classes of the dex, files written and methods |
natural, dispatcher, smali |
Methods of each category |
smaliFields |
Fields written as smali |
reasons |
How many times each dispatcher or smali reason appears |
classWarnings, warnings |
Class warnings: the total and by type |
finalsRemoved, constantValuesRemoved, modifiersChanged |
Deviations on fields and modifiers |
renames |
Declarations that changed name, by reason and by type |
classes has one object per class of the dex, with the file where it is written, its warnings and its methods:
{
"class": "Lcom/example/Limit;",
"file": "com/example/Limit.java",
"warnings": [],
"methods": [
{ "method": "check(Ljava/lang/String;)V", "category": "natural" },
{
"method": "init(Ljava/lang/String;Ljava/lang/String;)V",
"category": "smali",
"reasons": ["incompatible register types"],
"regions": [
{
"kind": "smali",
"reason": "incompatible register types",
"detail": "initializes this outside a constructor",
"start": "0x0000",
"end": "0x0006",
"blocks": 1,
"whole": false,
"catalog": true
}
],
"catalog": true,
"smaliDetail": "initializes this outside a constructor"
}
]
}
A natural method carries only its name and its category. A dispatcher or smali one carries its reasons and its
regions, with the code addresses where they start and end. A class can also carry "renames",
"modifiersChanged" and "writtenAs", when it is written with another name.
To know whether a decompilation is clean without reading the report, the exit code is enough: 0 is all Java, 3 is something in smali.
See also
ngr decompile, the options.- “Decompiling to Java”, the task.