apksmali

Need help disabling a method in smali in an apk file


I need to disable the following method, but I have no idea what to do or what to change. I've tried deleting it completely, but that just crashed the app.

The code:

.method private c()V
    .registers 4

    new-instance v0, Landroid/app/AlertDialog$Builder;

    iget-object v1, p0, Lcom/blah/blah/er;->c:Lcom/blah/blah/AlphaActivity;

    invoke-direct {v0, v1}, Landroid/app/AlertDialog$Builder;-><init>(Landroid/content/Context;)V

    const/4 v1, 0x0

    invoke-virtual {v0, v1}, Landroid/app/AlertDialog$Builder;->setCancelable(Z)Landroid/app/AlertDialog$Builder;

    const-string v1, "Random text"

    invoke-virtual {v0, v1}, Landroid/app/AlertDialog$Builder;->setTitle(Ljava/lang/CharSequence;)Landroid/app/AlertDialog$Builder;

    const v1, 0x1080027

    invoke-virtual {v0, v1}, Landroid/app/AlertDialog$Builder;->setIcon(I)Landroid/app/AlertDialog$Builder;

    const-string v1, "Other random text"

    invoke-virtual {v0, v1}, Landroid/app/AlertDialog$Builder;->setMessage(Ljava/lang/CharSequence;)Landroid/app/AlertDialog$Builder;

    const v1, 0x104000a

    new-instance v2, Lcom/blah/blah/es;

    invoke-direct {v2, p0}, Lcom/blah/blah/es;-><init>(Lcom/blah/blah/er;)V

    invoke-virtual {v0, v1, v2}, Landroid/app/AlertDialog$Builder;->setPositiveButton(ILandroid/content/DialogInterface$OnClickListener;)Landroid/app/AlertDialog$Builder;

    invoke-virtual {v0}, Landroid/app/AlertDialog$Builder;->create()Landroid/app/AlertDialog;

    move-result-object v0

    iput-object v0, p0, Lcom/blah/blah/er;->d:Landroid/app/AlertDialog;

    iget-object v0, p0, Lcom/blah/blah/er;->d:Landroid/app/AlertDialog;

    invoke-virtual {v0}, Landroid/app/AlertDialog;->show()V

    return-void
.end method

Solution

  • If you want to disable the method you can't simply delete the method because what should Android do if some other method wants to call a non-existing method? This is not possible and therefore the app crashes.

    If you want to disable the method you can simply delete all the instructions inside. The shown method luckily does not has a return value (you can see that on the last instruction return-void which means "exit method and return nothing".

    So you can strip down the method to the bare minimum:

    .method private c()V
        return-void
    .end method