Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others


0 votes
in Technique[技术] by (71.8m points)

java - Smali toast show code injection error - register v1 type Reference mismatch?

I injected the following piece of code to show toast message in an existing method myMethod into a decompiled app:

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

    const/4 v0, 0x1

    const-string v1, "Welcome to myMethod"

    invoke-static {p0, v1, v0}, Landroid/widget/Toast;->makeText(Landroid/content/Context;Ljava/lang/CharSequence;I)Landroid/widget/Toast;

    move-result-object v0

    invoke-virtual {v0}, Landroid/widget/Toast;->show()V

.end method

The app compiles fine but when this method is called app crashes, error details logcat logs:

java.lang.VerifyError: Verifier rejected class com.XXX: void com.XXX.myMethod(java.lang.String) failed to verify: void com.XXX.myMethod(java.lang.String): [0x3] register v1 has type Precise Reference: java.lang.String but expected Reference: android.content.Context (declaration of 'com.XXX' appears in /data/app/com.XXX/base.apk)

Did I miss something?

Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The first argument of makeText accepts a Context object. However, you are passing in p0, which contains a String object (the string value being passed into your method).

Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share