I know Java, and learned C but never used it. I do not know any form of assembly, either for a virtual machine or a real one.
What's the best way to learn how to hack Smali?
For reading SMALI files, there is a Smali syntax highlighting addon for Notepad++ distributed by the Android Cracking blog. NOTE: "Smali" stands for assembler in Icelandic. Iceland has a village named Dalvik from which the Dalvik Virtual machine was named. Similarly, "Baksmali" stands for disassembler.
From the official git¹, “smali/baksmali is an assembler/disassembler for the dex format used by dalvik, Android's Java VM implementation”. The smali code, which is what we wish to modify, can be thought of as an equivalent of assembly code of a C program.
smali/baksmali is an assembler/disassembler for the dex format used by dalvik, Android's Java VM implementation. The syntax is loosely based on Jasmin's/dedexer's syntax, and supports the full functionality of the dex format (annotations, debug info, line info, etc.)
UPDATE: As I promised yesterday, I added some more links to the list.
Ufff. Not much documentation around! Best advice? Decompile, and read, and tweak, and see how it did, and start the cycle again and again. But you did not ask for that advice, right? ;)
Now, there are a few places out there that wil lhelp a little bit:
http://androidcracking.blogspot.com/search/label/smali This is the best one. I even asked the guy a question and he answered very quickly, so go and take a look.
http://pallergabor.uw.hu/androidblog/dalvik_opcodes.html Very comprehensive table - good reference!
http://webchat.freenode.net/?channels=smali I never tried it, but it's on the google code page of the baksmali author ( http://code.google.com/p/smali/ )
http://forum.xda-developers.com/showthread.php?t=777707 Lastly, this is a post I made some time ago describing some hacks to the Captivate camera. You can follow the diffs in there as I comment a little bit on what each .diff file is doing. The good stuff starts at the post #20.
http://www.slideshare.net/paller/understanding-the-dalvik-bytecode-with-the-dedexer-tool Interesting slide show with some basic concepts. Good way to start.
http://sites.google.com/site/haynesmathew/home/projects/dalvik-notes Even more low level than the typical .smali. A reference for later, but a good read.
http://jasmin.sourceforge.net/guide.html Smali syntax is based on Jasmin, so this gives good concepts.
http://groups.google.com/group/apktool?pli=1 Some discussions there are worth reading through. Also a good place to search for when you're stuck in something.
And last, but not least, the most helpful trick I used: start coding very basic classes and methods in java, compile them and then baksmali your own code. You know exactly what it does, so it will be a lot easier to follow.
Good luck!
I continue to be surprised that folks don't use the official Dalvik format documents as a primary reference. On older releases, the Dalvik docs are in the Android source under dalvik/docs. The particular file you'll want to look at is called dalvik-bytecode.html. A few releases back the bytecode definition became part of the android.com developer docs:
dalvik-bytecode.html on source.android.com
As an additional convenience, I occasionally mirror these docs on my personal website. In this case:
dalvik-bytecode.html on milk.com
I do have a couple of wiki pages on the smali site with some information:
https://github.com/JesusFreke/smali/wiki/Registers
https://github.com/JesusFreke/smali/wiki/TypesMethodsAndFields
And there are examples of smali code that use every opcode in the integration tests for smali/baksmali:
smali integration tests
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With