JesusFreke / smali

smali/baksmali
6.26k stars 1.07k forks source link

Wrong error Invalid register: v16 #858

Closed nimamoradi closed 1 year ago

nimamoradi commented 1 year ago

Platform: Mac os arm

hi, I am injecting a piece of code and subverting the program fellow to my own code through smali modification.

Original code


.locals 12  
...
invoke-static {p2}, Ljava/lang/System;->loadLibrary(Ljava/lang/String;)V

modified code


.locals 13
...
const-class v12, Lclass/code/main;

invoke-static {v12, p2}, Lcom/mypackage/myclass;->mymethod(Ljava/lang/Class;Ljava/lang/String;)V

the new register here 'v12' which is clearly lower than 16 and there is no registers with 16 or more in the file but got this error when I try to build it.

Invalid register: v16. Must be between v0 and v15, inclusive more oddly at places where I made no changes(in the same class file) I used this injection at many apps and they seem to work fine just going this is the only error I got by this sort

here is the gist file for complete code the modification is at line 95

auermich93 commented 1 year ago

The method in which you made the modification says:

.method private b(Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;)V
    .locals 13

Hence the method has 13 local variables (v0-v12) and 4 param registers (p0-p3). I think the problem is not v12 but rather p3, which is the 17th register (v16 if you convert param registers to local register). For instance, in line 111 you use p3 in the following instruction: aput-object p3, v4, v2 However, according to the docs (https://source.android.com/docs/core/runtime/dalvik-bytecode), aput-object can only handle registers v0 to v15 as parameters, hence above error message makes sense.