Dex file to java

How to decompile Android DEX (VM bytecode) files into corresponding Java source code?

Android platform uses a virtual machine which is known as Dalvik VM which is used to execute the android application code. Dalvik VM executes the code in a format called DEX (Dalvik Executable). DEX files are the compiled version of Android application code written in Java. DEX files are a form of bytecode and can be decompiled into the corresponding Java source code.When we build a project in android studio to generate the APK. The compiler will firstly convert the code to dex and then this generated dex is then converted to the APK. This APK can be installed on the mobile device.

Decompiling is a process in which DEX files are converted back to the Java Source code. The first step of decompiling DEX files is to convert these DEX files into JAR files which is a Java Archive file. There are various tools which can be used for generating this JAR file. This JAR file is easily readable and it contains the resources such as java and other files in which the code for the android application has been written.

Decompiling is generally used to get the source code of any android application from the applications JAR file. This process can be used for the debugging of the application, reverse engineering and understanding the inner logic of the application.

In this article we will take a look at various methods which are used for Decompiling the DEX files into their corresponding Java Source Code which are as follows.

dex2jar

The dex2jar is a programming tool which is designed to convert Android DEX files into corresponding Java Source Code. It is also use to extract the contents of the APK file of the application to view the source code of an android application. For using the dex2jar tool we have to first download and install this tool on our local machine and then we have to run the below command from the command line.

dex2jar [filename].dex

In the file name we have to specify the name for our dex file.

The above command will generate the Java class file for each class in that dex file. This generated class files can then be decompiled through Java Decompiler using tools such as JD-GUI.

APK Tool

APK Tool is a reverse engineering tool which is used to get the JAVA source code from any android application. It is used to decode the resources to nearly original form and rebuild them after making some modifications. APK tool is used to decompile DEX files by first extracting classes.dex file from the APK file of the application. Once it is extracted the classes.dex file can be decompiled using the below command.

Читайте также:  Php this function is deprecated

apktool d fileName.dex

The above command will generate a folder which will contain the decompiled source code. This source code can be viewed and edited in any text or code editor.

JAD

JAD is a Java Decompiler which is also used to decompile DEX files into Java Source code. It is a command line tool which is used to generate Java class files from the DEX file. For using JAD we have to first download and install it on our local machine and then we can use the below command to generate and decompile the DEX file.

jad fileName.dex

Above command will generate a Java class file (.class) which can be opened in any of the text/code editors to view the decompiled source code.

JEB

JEB is a Java Decompiler for android applications which is developed by PNF Software. It is a commercial, cross platform tool which is used to reverse engineer APK packages and decompile the DEX files into Java source code. JEB has a built-in decompiler that can be used to decompile DEX files in a single step. It also has a powerful graphical user interface for navigating and editing the decompiled source code.

Conclusion

Decompiling DEX files into their corresponding Java source code can be a useful tool for debugging, reverse engineering, or for understanding the inner workings of an Android application. In this article, we discussed the various methods of decompiling DEX files, including using dex2jar, Apktool, JAD, and JEB. Each of these tools has its own advantages and disadvantages, so it is important to choose the right one for your needs.

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

License

skylot/jadx

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

jadx — Dex to Java decompiler

Читайте также:  Python хранение настроек программы

Command line and GUI tools for producing Java source code from Android Dex and Apk files

❗ ❗ ❗ Please note that in most cases jadx can’t decompile all 100% of the code, so errors will occur. Check Troubleshooting guide for workarounds

Main features:

  • decompile Dalvik bytecode to java classes from APK, dex, aar, aab and zip files
  • decode AndroidManifest.xml and other resources from resources.arsc
  • deobfuscator included

jadx-gui features:

  • view decompiled code with highlighted syntax
  • jump to declaration
  • find usage
  • full text search
  • smali debugger, check wiki page for setup and usage

Jadx-gui key bindings can be found here

See these features in action here: jadx-gui features overview

After download unpack zip file go to bin directory and run:

On Windows run .bat files with double-click
Note: ensure you have installed Java 11 or later 64-bit version. For Windows, you can download it from oracle.com (select x64 Installer).

flatpak install flathub com.github.skylot.jadx

You can use jadx in your java projects, check details on wiki page

JDK 11 or higher must be installed:

git clone https://github.com/skylot/jadx.git cd jadx ./gradlew dist 

(on Windows, use gradlew.bat instead of ./gradlew )

Scripts for run jadx will be placed in build/jadx/bin and also packed to build/jadx-.zip

jadx[-gui] [command] [options] (.apk, .dex, .jar, .class, .smali, .zip, .aar, .arsc, .aab) commands (use ' --help' for command options): plugins - manage jadx plugins options: -d, --output-dir - output directory options: -d, --output-dir - output directory -ds, --output-dir-src - output directory for sources -dr, --output-dir-res - output directory for resources -r, --no-res - do not decode resources -s, --no-src - do not decompile source code --single-class - decompile a single class, full name, raw or alias --single-class-output - file or dir for write if decompile a single class --output-format - can be 'java' or 'json', default: java -e, --export-gradle - save as android gradle project -j, --threads-count - processing threads count, default: 4 -m, --decompilation-mode - code output mode: 'auto' - trying best options (default) 'restructure' - restore code structure (normal java code) 'simple' - simplified instructions (linear, with goto's) 'fallback' - raw instructions without modifications --show-bad-code - show inconsistent code (incorrectly decompiled) --no-imports - disable use of imports, always write entire package name --no-debug-info - disable debug info parsing and processing --add-debug-lines - add comments with debug line numbers if available --no-inline-anonymous - disable anonymous classes inline --no-inline-methods - disable methods inline --no-move-inner-classes - disable move inner classes into parent --no-inline-kotlin-lambda - disable inline for Kotlin lambdas --no-finally - don't extract finally block --no-replace-consts - don't replace constant value with matching constant field --escape-unicode - escape non latin characters in strings (with \u) --respect-bytecode-access-modifiers - don't change original access modifiers --mappings-path - deobfuscation mappings file or directory. Allowed formats: Tiny and Tiny v2 (both '.tiny'), Enigma (.mapping) or Enigma directory --mappings-mode - set mode for handling the deobfuscation mapping file: 'read' - just read, user can always save manually (default) 'read-and-autosave-every-change' - read and autosave after every change 'read-and-autosave-before-closing' - read and autosave before exiting the app or closing the project 'ignore' - don't read or save (can be used to skip loading mapping files referenced in the project file) --deobf - activate deobfuscation --deobf-min - min length of name, renamed if shorter, default: 3 --deobf-max - max length of name, renamed if longer, default: 64 --deobf-cfg-file - deobfuscation mappings file used for JADX auto-generated names (in the JOBF file format), default: same dir and name as input file with '.jobf' extension --deobf-cfg-file-mode - set mode for handling the JADX auto-generated names' deobfuscation map file: 'read' - read if found, don't save (default) 'read-or-save' - read if found, save otherwise (don't overwrite) 'overwrite' - don't read, always save 'ignore' - don't read and don't save --deobf-use-sourcename - use source file name as class name alias --deobf-res-name-source - better name source for resources: 'auto' - automatically select best name (default) 'resources' - use resources names 'code' - use R class fields names --use-kotlin-methods-for-var-names - use kotlin intrinsic methods to rename variables, values: disable, apply, apply-and-hide, default: apply --rename-flags - fix options (comma-separated list of): 'case' - fix case sensitivity issues (according to --fs-case-sensitive option), 'valid' - rename java identifiers to make them valid, 'printable' - remove non-printable chars from identifiers, or single 'none' - to disable all renames or single 'all' - to enable all (default) --integer-format - how integers are displayed: 'auto' - automatically select (default) 'decimal' - use decimal 'hexadecimal' - use hexadecimal --fs-case-sensitive - treat filesystem as case sensitive, false by default --cfg - save methods control flow graph to dot file --raw-cfg - save methods control flow graph (use raw instructions) -f, --fallback - set '--decompilation-mode' to 'fallback' (deprecated) --use-dx - use dx/d8 to convert java bytecode --comments-level - set code comments level, values: error, warn, info, debug, user-only, none, default: info --log-level - set log level, values: quiet, progress, error, warn, info, debug, default: progress -v, --verbose - verbose output (set --log-level to DEBUG) -q, --quiet - turn off output (set --log-level to QUIET) --version - print jadx version -h, --help - print this help Plugin options (-P=): 1) dex-input: Load .dex and .apk files - dex-input.verify-checksum - verify dex file checksum before load, values: [yes, no], default: yes 2) java-convert: Convert .class, .jar and .aar files to dex - java-convert.mode - convert mode, values: [dx, d8, both], default: both - java-convert.d8-desugar - use desugar in d8, values: [yes, no], default: no 3) kotlin-metadata: Use kotlin.Metadata annotation for code generation - kotlin-metadata.class-alias - rename class alias, values: [yes, no], default: yes - kotlin-metadata.method-args - rename function arguments, values: [yes, no], default: yes - kotlin-metadata.fields - rename fields, values: [yes, no], default: yes - kotlin-metadata.companion - rename companion object, values: [yes, no], default: yes - kotlin-metadata.data-class - add data class modifier, values: [yes, no], default: yes - kotlin-metadata.to-string - rename fields using toString, values: [yes, no], default: yes - kotlin-metadata.getters - rename simple getters to field names, values: [yes, no], default: yes 4) rename-mappings: various mappings support - rename-mappings.format - mapping format, values: [auto, TINY, TINY_2, ENIGMA, ENIGMA_DIR, MCP, SRG, TSRG, TSRG2, PROGUARD], default: auto - rename-mappings.invert - invert mapping, values: [yes, no], default: no Examples: jadx -d out classes.dex jadx --rename-flags "none" classes.dex jadx --rename-flags "valid, printable" classes.dex jadx --log-level ERROR app.apk jadx -Pdex-input.verify-checksum=no app.apk 

These options also worked on jadx-gui running from command line and override options from preferences dialog

Читайте также:  Путь к java разработчику

To support this project you can:

Источник

Оцените статью