问题
Prologue
I am trying to learn about DalvikVM instructions using the Smali/Baksmali assembler/disassembler for dex files.
Problem
From this java file
package gd;
class Hello {
public static void main(String[] args)
{
System.out.println("Hello!");
}
}
I have generated the following smali assembly file:
.class Lgd/Hello;
.super Ljava/lang/Object;
.source "Hello.java"
# direct methods
.method constructor <init>()V
.registers 1
.prologue
.line 3
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
return-void
.end method
.method public static main([Ljava/lang/String;)V
.registers 3
.parameter
.prologue
.line 6
sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;
const-string v1, "Hello!"
invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V
.line 7
return-void
.end method
My question is about the following line.
sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;
As I understand this loads the static object PrintStream
of the java.lang.System
class into the v0
register. Now, what does this out:
mean?
回答1:
PrintStream is actually the type of the thing being loaded. The object you're loading might be referred to as java.lang.System.out
, where java.lang
is the package, System
is the class, and out
is the member (a static field) to be loaded.
You can see the same pattern in the invoke-virtual: java.io
is the package, PrintStream
is the class and println
is the member (in this case, an instance method). In both cases, the member is preceded with a ->
. I don't know if this pattern is consistent throughout Smali.
I found http://source.android.com/tech/dalvik/dalvik-bytecode.html invaluable when I was playing with dalvik stuff, although in this case its contribution was just identifying that sget-object only took two arguments. That told me the ->out:
business had to be part of the static field reference.
回答2:
Actually it reads the static field named out
of the class java.Lang.System. The (expected) type of that field is
java.io.PrintStream`.
来源:https://stackoverflow.com/questions/11671545/smali-syntax-for-dalvikvm-opcodes