What's the best way to learn Smali (and how/when to use Dalvik VM opcodes)?

JavaAndroidDalvikSmali

Java Problem Overview


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?

Java Solutions


Solution 1 - Java

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!

Solution 2 - Java

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

Solution 3 - Java

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKen KinderView Question on Stackoverflow
Solution 1 - JavaAleadamView Answer on Stackoverflow
Solution 2 - JavadanfuzzView Answer on Stackoverflow
Solution 3 - JavaJesusFrekeView Answer on Stackoverflow