androiddalviksmali

Why one more parameter is passed in a method in smali code


In a piece of smali code that I decoded via apktool, I found a method call passes one more argument than these are declared in then method definition. That extra argument is definitely not used at all. But if I remove it, Error occurs when run, saying "expected two, found three" from "verifier". What's going on here?

# method definition
.method public setLatitude(D)V
    .locals 1
    #(snipped)
.end method

# method call
# v3 is not defined actually
invoke-virtual {v1, v2, v3}, LFoo;->setLongitude(D)V


Solution

  • All non-static methods accept the object that the method is being called on as the first parameter.

    In your example, the method accepts an argument of type D, which is a wide type that takes 2 registers. In this case, v1 is the LFoo; instance that the method is being called on, and [v2, v3] is the register pair that contains the 64-bit wide argument to the method.

    When you say that "v3 is not defined actually", it would be implicitly set when v2 is set, because all wide values are stored using consecutive register pairs.