smali
Assemble Smali files into Dalvik bytecode
SYNOPSIS
smali [options] <file_or_directory> ...
PARAMETERS
-o <FILE>, --output <FILE>
Specifies the path for the output .dex file. If not provided, it typically defaults to classes.dex in the current directory.
-a <API_LEVEL>, --api <API_LEVEL>
Sets the target Android API level for the generated .dex file. This influences the selection of available opcodes and bytecode verification rules.
-j <THREADS>, --jobs <THREADS>
Utilizes the specified number of threads for parallel assembly, significantly speeding up the process on multi-core processors.
-v, --version
Prints the version information of the smali assembler and then exits.
-h, --help
Displays a comprehensive help message, detailing all available command-line options and their respective usage.
--allow-odex-insns
Allows the processing of ODEX (optimized DEX) instructions in the input .smali files. These are typically found in pre-verified classes on older Android versions and should be used with caution.
DESCRIPTION
smali is the assembler component of the smali/baksmali toolchain, a critical utility for Android development and reverse engineering. It translates human-readable .smali assembly files back into executable Dalvik bytecode, which is encapsulated within a .dex (Dalvik Executable) file.
The Dalvik bytecode forms the instruction set for the Android Runtime (ART) or the older Dalvik Virtual Machine (DVM), enabling the execution of Android applications. While its counterpart, baksmali, disassembles DEX files into .smali source, smali performs the essential reverse operation, allowing developers and security researchers to modify application logic at a low level.
This process is fundamental for tasks such as patching existing applications, injecting custom code, or altering application behavior without access to the original source code. smali fully supports the various Dalvik opcodes and directives, providing granular control over the compiled application's functionality and structure.
CAVEATS
smali typically runs as a Java application (e.g., java -jar smali.jar), requiring a Java Runtime Environment (JRE) to be installed on the system. It is a low-level tool that demands a solid understanding of Dalvik bytecode and Android internals for effective and error-free usage. Assembly errors can be challenging to debug and might result in malformed DEX files or application crashes. The resulting DEX file often needs to be signed and aligned as part of a larger APK recompilation process for proper functionality on an Android device.
COMMON WORKFLOW
smali is most frequently employed in tandem with its disassembler counterpart, baksmali. The typical workflow involves:
1. Using baksmali to disassemble an APK's classes.dex file into a collection of human-readable .smali files.
2. Making necessary modifications or additions to these .smali files.
3. Employing smali to reassemble the modified .smali files back into a new classes.dex file.
4. Re-packaging this new .dex file into the original APK, which then needs to be signed and zip-aligned before it can be successfully installed and run on an Android device.
HISTORY
The smali/baksmali toolchain was conceptualized and developed by JesusFreke (Ben Gruver) around 2010. It rapidly established itself as the authoritative standard for manipulating Dalvik bytecode, filling a critical void in the Android development and reverse engineering landscape. Its precision, extensive support for Dalvik opcodes, and ongoing development propelled its adoption across the Android modding, custom ROM, and security research communities. It remains an indispensable utility for deep-dive analysis and modification of Android applications at the bytecode level, continually evolving to support new Android versions and bytecode formats like ART.


