In this section, we introduce inner classes. For each inner class in the Java file, a separate smali file is generated, such as ActivityThread$1.smali. The naming convention of these files is that if it is an anonymous inner class, the naming rule is the outer class + $ + number, otherwise it is the outer class + $ + the name of the inner class.
When a private method of an outer class is called in an inner class, the compiler automatically synthesizes a static function. For example this class:
public class Hello {
public class A {
void func () {
setup ();
}
}
private void setup() {
}
}
We call the setup method of the outer class in the func method of the inner class A, and the final compiled smali code is:
Hello$A.smali file Code snippet:
# virtual methods
.method func()V
.locals 1
.prologue
.line 5
iget-object v0, p0, LHello$A;->this$0:LHello;
#calls: LHello;->setup()V
invoke-static {v0}, LHello;->access$000(LHello;)V
.line 6
return-void
.end method
Hello.smali Code snippet:
.method static synthetic access$000(LHello;)V
.locals 0
.parameter
.prologue
.line 1
invoke-direct {p0}, LHello;->setup()V
return- void.end
method
It can be seen that the compiler automatically synthesizes an access$000 method. If we add a call to a private method of an external class to a more complex inner class, although it only results in a new method being synthesized, these synthesized methods The name may change. The result is that the smali files are quite different. At this time, careful analysis is required to find the private method to be called. Then choose an unused name for the synthesized method.