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

  • crap

    Apktool does this automatically 😉

    • 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. 😀

      Appreciate your reply though!

      • Good to find an expert who knows what he’s tiaklng about!

  • crap

    😀 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 😉

    • 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! 😀

      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.

  • crap

    Using own compiled apktool.
    And have no clue what u mean by corrupting the files.man 😀
    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 🙂

    • 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.

  • crap

    Strange issue there….
    Working in windows ?

    • 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?

  • Robbie Hood

    AllianceROM 😛

  • Robbie Hood

    Anyhow its a good iniative you have here , will keep checking in how your site will develop itself 🙂

    • Robbie my friend.. You remember me right? I am “Rahulrulez” / “Rahul++” from XDA, DarkyROM forums 😀 Nice to see you again. Thanks for visiting my site 😀 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 😉

      • Robbie Hood

        Yeah i remember you 🙂

        what phone are you planning to get ?

        • Rahul

          Umm, haven’t thought of it so far! May be I will get SGS3 in next month 🙂

      • 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.

  • 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.

    • Can you please share the apk file? I will look in to it.

  • Hafez

    i get errors like this
    VRListActivity$34.smali[0,-1] no viable alternative at input ”
    any help?

  • Omid

    hi,
    I made smali dex with no errors but when I copy it into the apk and try to install on my G2 phone, it can’t be installed.
    Where is the problem? I have tested many tools , apktools (diffrent version) . no way. please help me

    thank you

    • Reuven

      Occasionally – I have LG G2 also. This time the “GmsCore.apk” was changed. It is about 15Mb.
      All was fluent and smooth. Check your new file permissions – should be similar to permissions of other files in the destination folder. Also check, if your file browser has administrator permissions to write to this folder.

  • Reuven

    Thank you very for this application.
    One thing only I had to decide is about decompiled classes.dex editor.
    Usual Notepad was good enough. 🙂
    All sequence worked great!
    My question is – when I download your application file, jar1.4 version of Smali / BakSmali is found.
    Is it OK simply to replace it with files of newer 2.3 version from original repository? Will it work?

  • Hello,

    I added a file named ‘Sign.bat’ to sign apk but I want the signed apk be redirected to a folder and not to the root.

    Can you help me plz?

    Thanks for your awesome tool 😀

  • Given

    Hi Rahul can you give me a guide on how to covert .java files to smali?