Files each command writes
This page gathers in one place what each ngr command leaves on disk: what it writes, what it is called by
default, what -o changes and what -f does. The general rules are in
“How ngr works”; here is the detail per command.
The table
| Command | What it writes | Default name | -o |
-f |
Other files |
|---|---|---|---|---|---|
identify |
Nothing | ||||
info |
Nothing | ||||
resource |
Nothing | ||||
xml |
Nothing | ||||
decode |
A folder | <name>/ next to the apk |
The folder | Deletes the whole folder and writes it again | Inside: .cache/ (without --dex) |
build |
An apk | <folder>_built.apk next to the folder |
The apk | Overwrites the apk | Rewrites .cache/ inside the tree |
merge |
An apk | <name>_merged.apk next to the bundle |
The apk | Overwrites the apk | |
refactor |
An apk | <name>_refactored.apk |
The apk | Overwrites the apk | |
protect |
An apk | <name>_protected.apk |
The apk | Overwrites the apk | |
align |
A zip or an apk | <name>_aligned<ext> |
The file | Overwrites the file | With --check, nothing |
sign |
An apk and its v4 signature | <name>_signed<ext> |
The apk | Overwrites the apk and its .idsig |
<output>.idsig, except with --no-v4 |
verify |
Nothing | ||||
rotate |
A lineage file | None: -o is required |
The lineage | Overwrites the lineage | |
lineage |
A lineage file, only if something changes | None: -o is needed to write |
The lineage | Overwrites the lineage | |
disassemble |
A smali folder | <name>_smali/ next to the input |
The folder | Writes inside the folder without emptying it | |
assemble |
A dex | <input>.dex next to the input |
The dex | Overwrites the dex | |
dump |
Nothing | ||||
list |
Nothing | ||||
decompile |
A Java folder | <name>_java/ next to the input |
The folder | Writes inside the folder without emptying it, and overwrites the --report file |
--report <file>; nogar-stubs/ with --stubs |
The commands that write no files print their result to stdout. Which they are and how to redirect them is in “Output and exit codes”.
Three commands write something more than the name column says:
signleaves two files: the apk and the v4 signature,<output>.idsig, with the full name of the apk before it (app_signed.apk.idsig). If<output>does not exist but its.idsigdoes,signstill refuses and says which one it is.decompilecan leave three things: the Java folder; the JSON report, if you pass--report; and thenogar-stubs/folder inside the Java folder, if you pass--stubs.buildwrites inside the input tree. It reassembles the smali that changed and leaves the result in.cache/for next time (“The decode tree”).
What -f does in each command
-f means “yes, I know it exists”, but what happens next depends on the command:
| Command | With -f |
|---|---|
decode |
Deletes the whole folder before decoding. Whatever was inside that does not come from the apk disappears |
disassemble, decompile |
Writes inside the folder that already exists, without emptying it. Files that do not match a new one stay |
build, merge, refactor, protect, align, assemble, rotate, lineage |
Overwrites the output file |
sign |
Overwrites the apk and its .idsig |
With decompile, -f also applies to the --report file: without -f, a report that already exists is an error
even if the folder is new.
The commands that write a folder (decode, disassemble, decompile) also create the parent folders of the path
you give them. Those that write a file do not: with -o new/app.apk, the new/ folder must already exist, or the
command ends with 1. It happens in build, merge, refactor, protect, align, sign, assemble and
rotate:
ngr sign: unable to write 'out/a.apk': Could not find a part of the path '/home/you/work/out/a.apk'.
If -o and the input are the same file, -f overwrites it: ngr align app.apk -o app.apk -f replaces app.apk
with its aligned version. Without -f, the command refuses.
How the default name is formed
The name comes from the input's, and the output goes next to the input, not in the current folder:
cd /tmp
ngr align work/app.apk
wrote work/app_aligned.apk
The rule has three parts:
- The last extension of the input name is removed (
app.apkbecomesapp,my.app.v2.apkbecomesmy.app.v2). - The command's suffix is added.
- The extension of the output is added.
The suffixes are these:
| Command | Suffix |
|---|---|
build |
_built |
merge |
_merged |
refactor |
_refactored |
protect |
_protected |
align |
_aligned |
sign |
_signed |
disassemble |
_smali |
decompile |
_java |
decode and assemble have no suffix: decode uses the name without extension (app.apk gives app/) and
assemble adds .dex (classes_smali gives classes_smali.dex, and One.smali gives One.dex).
The extension of the output depends on the command:
| Command | Output extension | Example |
|---|---|---|
align, sign |
The input's | data.zip gives data_aligned.zip; app.apk gives app_signed.apk |
build, merge, refactor, protect |
Always .apk |
app.xapk gives app_merged.apk; data.zip gives data_protected.apk |
Without an extension, the name stays as it is and the suffix goes at the end:
ngr align noext
wrote noext_aligned
An input without an extension causes a problem only in decode: the default folder would be named the same as the
file, and ngr does not create it. Not even with -f:
ngr decode: unable to decode 'noext': The file '/home/you/work/noext' already exists.
Pass -o with another name, or give the file the .apk extension. The file is not touched.
What happens when the destination already exists
No command overwrites an output unless you ask it to. If the destination exists, the command writes nothing, prints a line to stderr and ends with exit code 1. The message says which option allows it:
ngr build: 'app_built.apk' already exists (pass -f to overwrite).
ngr decode: 'app' already exists (pass -f to overwrite).
ngr disassemble: 'handles_smali' already exists (pass -f to write into it).
ngr decompile: 'handles_java' already exists (pass -f to write into it).
ngr sign: 's.apk.idsig' already exists (pass -f to overwrite).
The text changes according to what -f does in that command: “overwrite” for those that overwrite or delete and
“write into it” for disassemble and decompile, which write inside without emptying. The rest of the commands
that write (merge, refactor, protect, align, assemble, rotate, lineage) use the first.
In lineage, the refusal only comes if the lineage changes and you pass -o: without changes, the command writes
nothing. If it changes and you do not pass -o, the message is different, also with exit code 1:
ngr lineage: the lineage changed but no -o was given; nothing was written.
The wrote line on stderr
Every command that writes ends with a line that starts with wrote, on stderr. It says what it wrote and where.
The paths are the ones you gave, or the ones ngr formed from them:
| Command | Line |
|---|---|
decode |
wrote 134 file(s) to app |
build |
wrote app_built.apk |
merge |
wrote app_merged.apk |
refactor |
wrote app_refactored.apk |
protect |
wrote app_protected.apk |
align |
wrote app_aligned.apk |
sign |
wrote app_signed.apk and app_signed.apk.idsig (with --no-v4, only the apk) |
rotate |
wrote lin.bin |
lineage |
wrote lin2.bin, only if it wrote |
disassemble |
wrote 25 file(s) to shapes_smali |
assemble |
wrote shapes_smali.dex |
decompile |
wrote 25 file(s) to shapes_java; with --report, wrote 17 file(s) to app_java and r.json; with --stubs, it also counts the files of nogar-stubs/ |
The commands that do not write print no wrote line. decompile prints another summary line first
(ngr decompile: 25 classes, 49 methods: ...) and several WARN: lines; “Output and exit codes”
explains what each thing is.
A protected apk is not decoded, refactored or protected again: decode, refactor and protect write its path and
PROTECTED to stderr, write nothing and end with 0.
Where the debug key is
ngr sign --debug-key signs with a key that ngr creates the first time. It is stored in your user folder, depending on the system:
| System | Path |
|---|---|
| macOS | ~/Library/Application Support/NOGAR/debug.p12 |
| Linux | $XDG_CONFIG_HOME/NOGAR/debug.p12, or ~/.config/NOGAR/debug.p12 if XDG_CONFIG_HOME is not defined |
| Windows | %APPDATA%\NOGAR\debug.p12 |
nogar does not back up that file. Keep a copy if you sign apps with it: an Android device only accepts an update with the same signature as the installed app (“The debug key”).
See also
- “How ngr works”, the common rules.
- “Output and exit codes”.
- “The decode tree”.
ngr sign.