Question

I have been learning how to code smali files, and i had created a certain method which takes a string parameter and puts it in the log.Its java equivalent is something like this:

public void log(String param){
        Log.d(param, param);
    }

And when i smalied it again and signed the apk, i got the following error in the logCat:

10-05 21:52:42.081: W/dalvikvm(32021): VFY: register1 v2 type 0, wanted ref
10-05 21:52:42.081: W/dalvikvm(32021): VFY: bad arg 0 (into Ljava/lang/String;)
10-05 21:52:42.081: W/dalvikvm(32021): VFY:  rejecting call to Landroid/util/Log;.d (Ljava/lang/String;Ljava/lang/String;)I
10-05 21:52:42.081: W/dalvikvm(32021): VFY:  rejecting opcode 0x71 at 0x0000
10-05 21:52:42.081: W/dalvikvm(32021): VFY:  rejected Lcom/shqipe/worthstream/utils/Utils;.log (Ljava/lang/String;)V
10-05 21:52:42.081: W/dalvikvm(32021): Verifier rejected class Lcom/shqipe/worthstream/utils/Utils;
10-05 21:52:42.081: D/AndroidRuntime(32021): Shutting down VM

This is the method in the smali file:

.method public static log(Ljava/lang/String;)V
    .registers 2
    .parameter "paramString"
    .prologue


    invoke-static {p1, p1}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

    .line 63
    return-void
.end method

Can anyone explain it to me how i can debug this error?

Was it helpful?

Solution

p1 is an invalid register in that context. In fact, baksmali should have caught that! :)

With .registers 2 and a single argument, you have registers v0 and v1, with p0 being aliased to v1. p1 would actually be v2, which isn't allowed, per your .registers directive.

What you want is

invoke-static {p0, p0}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

or equivalently

invoke-static {v1, v1}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

With respect to how to debug this sort of error, the best thing you could have done would be to look in the dalvik source code for the VFY error strings that you see, and identify exactly what the error message means (i.e. what error condition is it triggered on), and where in the bytecode the error occurs.

For identifying where it the bytecode the error occurs, look at the error lines

10-05 21:52:42.081: W/dalvikvm(32021): VFY:  rejecting opcode 0x71 at 0x0000
10-05 21:52:42.081: W/dalvikvm(32021): VFY:  rejected Lcom/shqipe/worthstream/utils/Utils;.log (Ljava/lang/String;)V

This shows that the error happened in the Lcom/shqipe/worthstream/utils/Utils;.log (Ljava/lang/String;)V method, at bytecode offset 0 (i.e. the first instruction). However, in case it's not clear which instruction it is referring to, you can use the -f option to baksmali, which will cause it to add the bytecode offset as a comment before each instruction.

OTHER TIPS

Just an addition to JesusFreke's answer, p0 does NOT reference the Java this in the example as the function is static. So the arguments start at p0, as JesusFreke said.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top