Welcome to Qi-U Community for programmer and developer-Open, Learning and Share

Categories

0 votes
545 views
in Technique[技术] by (31.9m 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

    return-void
.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

Please log in or register to answer this question.

1 Answer

0 votes
by (31.9m 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 Qi-U Community for programmer and developer-Open, Learning and Share
...