Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 407
Ken Kinder Avatar asked Apr 13 '11 23:04

Ken Kinder


People also ask

How do I read Smali files?

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.

What is Smali?

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.

What is Smali source code?

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


3 Answers

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!

like image 122
Aleadam Avatar answered Sep 28 '22 23:09

Aleadam


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

like image 44
danfuzz Avatar answered Sep 28 '22 21:09

danfuzz


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

like image 21
JesusFreke Avatar answered Sep 28 '22 21:09

JesusFreke