(1) Analysis of Smali function call statement in Smali series learning

1. Function call
Functions and member variables in smali are also divided into two types, namely direct and virtual. The difference between the two is as follows:

1.direct method refers to calling the private method.
2.virtual method refers to calling protected and public methods.
3.static method refers to calling a static method.
4.super method refers to calling the parent class method.
5. Of course, there are also invoke-XXX/range commands, which are called when there are more than 4 parameters, which are relatively rare.

So when calling a function, there are invoke-direct, invoke-virtual, and there are several different instructions such as invoke-static, invoke-super, and invoke-interface.

The smali methods of these functions are explained below.

1.invoke-static
is used to call static functions, for example:

        invoke-static {}, Lcom/aaa;->CheckSignature()Z

Note: There is a pair of curly brackets "{}" after invoke-static, which is actually the instance + parameter list of the method that is invoked. Since this method requires neither parameters nor static, the {} is empty.

E.g:

  const-string v0, "NDKLIB"

  invoke-static {v0}, Ljava/lang/System;->loadLibrary(Ljava/lang/String;)V

  This is the method used to call static void System.loadLibrary( String ) to load the so library compiled by NDK

2.invoke-super

The instruction used to call the parent class method is generally used to call onCreate, onDestroy and other methods.

3.invoke-direct

Call the private function:

E.g:

  invoke-direct {p0}, Landroid/app/TabActivity;-><init>()V

  Here init() is a private function defined in TabActivity.

4.invoke-virtual

It is used to call protected or public functions. Also be careful not to use invoke-direct or invoke-static when modifying smali.

5.invoke-xxxxx/range

When the parameters of the method are more than 5 (including 5), the above commands cannot be used directly, but "/range" is added behind, and the range indicates the range, and the usage method is also different.

 

2. The return result of the function

Calling a function and returning the function result in Java code can be done with one statement, but in Smali it needs to be done separately. After using the above command, if the called function returns non-void, then move-result (return basic data types) and move-result-object (return object) instructions:

  const-string v0, "Eric"

  invoke-static {v0}, Lcmb/pbi;->t(Ljava/lang/String;)Ljava/lang/String;

  move-result-object  v2

The v2 register in the above stores the String string returned by calling the t method.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325258316&siteId=291194637