Search code examples
androiddalviksmali

Dalvik Verifier: register1 v25 type 0, wanted ref


I have the following Smali code:

.method private k(I)V
.registers 27 (original) 29 (after)

...
#@68a
invoke-direct/range {v24 .. v25}, Landroid/widget/LinearLayout;-><init>(Landroid/content/Context;)V
...

This is rejected by the Dalvik verifier. 0x76 is invoke-direct/range.

dalvikvm: VFY: register1 v25 type 0, wanted ref
dalvikvm: VFY: bad arg 1 (into Landroid/content/Context;)
dalvikvm: VFY:  rejecting call to Landroid/widget/LinearLayout;.<init> (Landroid/content/Context;)V
dalvikvm: VFY:  rejecting opcode 0x76 at 0x068a
dalvikvm: VFY:  rejected Lcom/pocketwood/myav/MyAV;.k (I)V
dalvikvm: Verifier rejected class Lcom/pocketwood/myav/MyAV;
dalvikvm: Class init failed in newInstance call (Lcom/pocketwood/myav/MyAV;)

Interestingly v25 is not used in any instruction above 68a! The original APK runs fine, but repacked with smali the verifier rejects class MyAV.


Solution

  • I suspect you have the wrong code location. If you look at the error message, it mentions opcode 0x76, which is invoke-direct/range. The code snippet you provided does not have an invoke-direct/range instruction, so, unless something really screwy is going on, that can't be the code that's causing the issue.

    Also, take a look at the name of the method in the error message: Lcom/pocketwood/myav/MyAV;.k (I)V. There is what looks like a space after the k. The space character itself isn't a valid character in a method name, but maybe it's actually some other space-like unicode character?

    Nevermind. That space appears to be baked into the error message.


    Finally, the offset mentioned in the error message (at 0x068a) should be the code offset of the instruction within the containing method. You can use baksmali's --offsets option when disassembling the dex file, and baksmali will add a comment with the code offset before each instruction. Although, I'm not sure offhand if the offset is in bytes or code units, which are 16 bits, so it may be off by a factor of 2.