ngr decode
Decodes an apk into a folder: the resources and the manifest as text, the code as smali and everything else as is.
It is the first step to change an app. ngr build turns the folder back into an apk.
Usage
ngr decode [options] <apk>
Inputs
| Input | What it is |
|---|---|
<apk> |
An apk file |
Options
| Option | What it does | Default |
|---|---|---|
-o, --output <dir> |
The folder to write | <name>/ next to the apk |
-f, --force |
If the folder exists, deletes it entirely before decoding | |
--type <xml|raw> |
xml decodes the resources. raw copies each entry untouched, and needs --dex |
xml |
--dex |
Copies the dex files to dex/ instead of disassembling them to smali/ |
|
--no-debug-info |
Removes the debug information (.line and the others) from the smali |
|
-h, --help |
Shows the help |
What it writes
A folder with this shape:
app/
AndroidManifest.xml the manifest, as text xml
resources/package_1/ the resource table: package.json and res/ with the xml files and the files
smali/classes/ one .smali per class of classes.dex
smali/classes2/ and one folder for each additional dex
root/ the other entries of the apk: assets/, lib/, META-INF/...
signatures/ the signature blocks of the original apk
.cache/ the original dex files, which build reuses if the smali has not changed
archive-info.json data about the original zip
path-map.json the entries whose name is not valid as a file name
uncompressed-files.json the entries that were stored uncompressed
With --dex, instead of smali/ and .cache/ there is a dex/ folder with the dex files as they are. With
--type raw, the resources are not decoded either: resources.arsc and AndroidManifest.xml.bin stay as they
were. “The decode tree” describes each part.
A final line with the number of files and the folder goes to stderr:
wrote 134 file(s) to app
Examples
Decode an apk into the default folder:
ngr decode app.apk
Decode into another folder, deleting it if it already exists:
ngr decode -f -o work app.apk
Decode only the resources and leave the code as dex, which is faster if you are not going to touch the code:
ngr decode --dex app.apk
Extract all the entries without decoding anything:
ngr decode --type raw --dex app.apk
Exit codes
| Code | When |
|---|---|
| 0 | The tree was written. Also with a protected apk, which is not decoded |
| 1 | The apk does not exist or cannot be read, or the folder already exists and you did not pass -f |
| 2 | The options are wrong: for example, --type raw without --dex |
Things to know
-fdeletes the whole folder, including files you may have added yourself. It is not like the-fofdisassemble, which writes over the folder without emptying it.- Names that differ only in case. On a file system that does not distinguish case (usual on macOS and Windows),
two entries such as
assets/Case.txtandassets/case.txtend up in the same file.decodewarns how many collided:
WARN: 1 entry name(s) collided case-insensitively and overwrote each other on this filesystem
If the warning appears, the apk you build from that tree will not have all the entries of the original. Decode on a case-sensitive volume.
- A protected apk is not decoded.
ngrcalls an apk protected when it has entries underclasses.dex/orAndroidManifest.xml/, as if those files were folders.decodewrites its path andPROTECTEDto stderr, writes no folder and ends with 0. - The apk that comes out of
buildis not identical to the original:ngr buildsays what changes.
See also
ngr build, the opposite step.ngr disassemble, if you only want the smali of a dex.- “Modifying and rebuilding an apk”, the complete walkthrough.
- “The decode tree”.