Android bytecode: value of some variables not defined

109 views Asked by At

I reverse an android application. While reading, I see some methods that used variables such as p1 or p2 ... I don't know where can I reference those variables. For example:

.method public b(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)V
    .locals 1

    invoke-static {}, Lpnf/this/object/does/not/Exist;->a()Z

    move-result v0

    invoke-static {v0}, Lpnf/this/object/does/not/Exist;->b(I)V

    .prologue
    .line 33
    if-eqz p1, :cond_0

    if-eqz p2, :cond_0

    if-eqz p3, :cond_0

    .line 34
    invoke-static {p1, p2, p3}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I

    .line 36
    :cond_0
    return-void
.end method

The thing I don't understand is:

if-eqz p1, :cond_0

if-eqz p2, :cond_0

if-eqz p3, :cond_0

I don't know variables p1 p2 p3 here. Please tell me. Thanks

1

There are 1 answers

1
Antimony On BEST ANSWER

p1, p2, etc. are just syntactic sugar provided by the assembler. In Dex code, the local variables and parameters are a giant array, with parameters passed in the last few slots of the array. The assembler helpfully lets you refer to parameters directly via the pn syntax, rather than having to keep track of how many local variables you have and use the appropriate vn.

In the example posted, you have 1 local variable and 4 parameters, meaning that the registers look like {v0, p0, p1, p2, p3}.

The later 4 are automatically initialized at the start of the method to the values of the parameters passed.