more smali syntax and running smali files

there are some examples of smali syntax written by the author of smali/baksmali JesusFreke here: http://code.google.com/p/smali/source/browse/trunk/examples/. most are rather technical, but still illuminating.

here's one that i modified slightly that shows a basic hello world app with a standard main method. also, in the comments you will see a way to quickly compile and run a smali file. this is sometimes quite useful in testing your code:
.class public LHelloWorld;  # Ye olde hello world application # To assemble and run this on a phone or emulator: # # java -jar smali.jar -o classes.dex HelloWorld.smali # zip HelloWorld.zip classes.dex # adb push HelloWorld.zip /data/local # adb shell dalvikvm -cp /data/local/HelloWorld.zip HelloWorld # # if you get out of memory type errors when running smali.jar # give java more memory with -Xmx512m, like this: # java -Xmx512m -jar smali.jar HelloWorld.smali  .super Ljava/lang/Object;  .method public static main([Ljava/lang/String;)V     .registers 2      sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;      const-string v1, "hello,world!"      # combine executing with adb shell commands and console output     # and you have a very quick way to test code     invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V      return-void .end method

Komentar