Wrapcode

Baksmali / Smali Android's dex files (using command line tool)

| 2 min read

Dalvik Virtual Machine does not use java bytecode. Instead, it uses it's own file format called dex (Dalvik Executable Format). It holds definition of multiple classes and relative data.

Smali /Baksmali is an assembler / disassembler for for dex file format.

Input and Output

Since Smali and Baksmali is used to work on dex file format, input is obviously .dex file. .dex file is packed (you can say zipped) under android apk or .jar file. Generally named as "classes.dex".

When you baksmali (disassemble) it, the tool will disassemble and extract all the classes present in the dex file. Practically you will not get files under .class extension. Rather you will get .smali files, in which you will get code in form of dalvik opcodes or smali syntax.

Learning smali syntax can be time consuming but it can be a bliss for android developers.

Smali-Me! - Custom made Smali / Baksmali batch tool.

I have coded a tiny tool that automatically baksmali .dex files and later smali them.

[scbutton link="http://www.mediafire.com/?s1cb90m8cf9x9hi" target="blank" variation="green" size="large" ]Download Smali-Me v1.0[/scbutton]

How to disassemble or baksmali?

Baksmali

  1. Download Smali-Me! tool. Extract it somewhere (say C:/Smali-Me-1.0)
  2. Place .dex file in that folder.
  3. Run baksmali.bat
  4. You will get disassembled files in folder called "Decompiled"
  5. Make your edits carefully.

How to reassemble or smali?

  1. Copy all the content from folder "Decompiled"
  2. Paste it in folder called "Smali-Me" (if folder does not exist, create a new one)
  3. Run smali.bat
  4. If no errors found, you will find a file called "modded-classes.dex" in root folder. Caution : Make sure there is ONLY ONE .dex file present in root folder. If there are more than one .dex files are present, this tool won't work.

I hope this tool will make your development easier. Good luck with your development..

Regards,

Rahul