I am trying to logcat the parameters of a function in smali with my own function. I made a new Android studio project and wrote the function then used APKtool to retrieve the Smali file.
This is my function:
.method public userFunction(II)V
.locals 2
.param p1, "a" # I
.param p2, "b" # I
.line 28
invoke-static {p1}, Ljava/lang/Integer;->toString(I)Ljava/lang/String;
move-result-object v0
const-string v1, "Message"
invoke-static {v1, v0}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I
return-void
.end method
As you can see, it takes two integers and then logs one (forget for now that the other integer is unused).
This is the Android studio code I used to write the above function in Java.
public void sendMessage(View view)
{
userFunction(3,2);
}
public void userFunction(int a, int b)
{
Log.d("Message", Integer.toString(a));
}
Now what I can't make sense of, is how to call this function in Smali. My problem may be that I am testing this within a button. The sendMessage is an Onclick method for testing purposes and all it does is perform the userfunction.
My reasoning behind this is that the method call in Smali ends up being
invoke-virtual {p0, v0, v1}, Lcom/example/froggyfresh/MainActivity;->userFunction(II)V
From what I read, I believe the p0 to be the object calling the function. So I'm not sure how to call the function from within another method that is in the project I am trying to debug.
Is there a work around for this, to create some generic function to log the values?
The issue I get when using p0 in the APK I am trying to debug is APKtool gives me this error:
C:\Users\Dell\Desktop>apktool b base
I: Using Apktool 2.4.1
I: Checking whether sources has changed...
I: Smaling smali folder into classes.dex...
base\smali\funproject.smali[5059,1] Invalid register: v29. Must be between v0 and v15, inclusive.
Could not smali file: funproject.smali
I know that the p0 is a parameter register and that the parameters are stored in the final v(insertnumberhere) register. So I can make sense of the error but not sure how to go about fixing the issue.