首页 > 代码库 > Smali汇编语言之HelloWorld

Smali汇编语言之HelloWorld

编写HelloWorld.smali文件:

.class public LHelloWorld;
.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!"
    invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V
    return-void
.end method

然后运行命令:

java -jar smali.jar -o classes.dex HelloWorld.smali

将classes.dex压缩成HelloWorld.zip文件

使用命令上传至Android手机的/sdcard/目录下

adb push HelloWorld.zip /sdcard

使用adb shell命令登陆手机,运行程序

dalvikvm -cp HelloWorld.zip HelloWorld



Smali汇编语言之HelloWorld