Oct 17th

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

android dex full Baksmali / Smali Androids dex files (using command line tool)

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.

Download Smali-Me v1.0

How to disassemble or baksmali?

baksmali Baksmali / Smali Androids dex files (using command line tool)

  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?

smali Baksmali / Smali Androids dex files (using command line tool)

  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

About Rahul

Rahul Patil is 22 year old Software Developer from India. He loves to work on web technologies.You can find me on Facebook : https://www.facebook.com/rahulrulez Google + : https://plus.google.com/108232101755970804303

17 thoughts on “Baksmali / Smali Android’s dex files (using command line tool)

    1. Rahul Post author

      Sir, Apktool decompiles apk and framework. You need smali, baksmali tool in order to disassemble (decompile) .dex file structure if you want to work on classes. :-) Apktool helps to extract .dex files though. :D

      Appreciate your reply though!

      Reply
  1. crap

    :D I am a rom dev mate i know how it works.
    Decompile any apk or jar with apktool and the output will be and has always been a smali folder (decoded dex).
    So enlighten me ;)

    Reply
    1. Rahul Post author

      Same here sir, I am also a ROM developer.

      Well, you can definitely decompile jar and get .smali with apktool. But I would recommend using smali / baksmali.

      I used to decompile jar files with apktool. It decompiles jar files very well but compilation is still buggy with apktool. Smali files got corrupted during compilation and it broke the jar file.. Any way which version of apktool do you use?

      I am developing a GUI tool that ease the process of apk and framework engineering. Right now I am using apktool 1.5.0 which is stable enough! :D

      Thanks for your reply sir, appreciate your participation :-) This article is served to teach how to work with .dex files so I believe this tool is good enough to teach beginners. I prefer working with AOSP and CM10 sources though.

      Reply
  2. crap

    Using own compiled apktool.
    And have no clue what u mean by corrupting the files.man :D
    Been working for 30 months like this via terminal command and never had issues and probably never will.
    Apktool was restructured a year ago or something to work with classes.dex.

    Dont want to downgrade ur work but its a bit obscelete :)

    Reply
    1. Rahul Post author

      Many .smali files were of size 0kb. Probably they were corrupt. :-) Which was creating issues while recompiling it again. May be there was a issue with apktool version I was using. I stopped building my own apktool way back :-)

      Anyway, I will check that stuff and update this article with apktool method as well :-)

      Thank you for your response.

      Reply
    1. Rahul Post author

      Was working on Linux before, then I shifted to Windows, Lots of Visual Studio work needs to be done here :-)

      Anyway, which ROM do you cook?

      Reply
    1. Rahul Post author

      Robbie my friend.. You remember me right? I am “Rahulrulez” / “Rahul++” from XDA, DarkyROM forums :D Nice to see you again. Thanks for visiting my site :D I appreciate your comments. Keep in touch.. Good luck with your development. I am out of SGS development. I am getting a new phone very soon. Will kick start my development on my future phone ;-)

      Reply
      1. Trixie

        FllashYou must be sure to copy the framework-res.apk from the ROM you will be woikrng with into the same directory as APKTool.Then issue the command: apktool if framework-res.apkAfter this, you should be free to decompile any apk coming from the ROM you are woikrng with and not encounter any issues.

        Reply
  3. Siddesh

    Hi Rahul,

    Thanks for sharing this info. I am trying to edit one of the java file inside apk and recompile back to apk. I was able to decompile apk properly and create project of it. But when i import it into eclipse it shows many errors and after looking into java file, i realized the resource (R file) reference is replaced with constant number and few variable names had changed. So i couldn’t able to edit required java file.
    Is this possible to edit those java file without any error and recompile back to apk or i need to edit the smali file itself. Please help me on this and let me know which will be best approach to process it.

    Thanks.

    Reply

Leave a Reply