I have an APK file and decompile it using APKtool and get all the source code as smali files, I want to modify the bytecode to show the user a message when he tries to open the camera and take a pic
Below the code I added to the smali file, wrote it in java an convert it to bytecode using java2smali
.prologue
.line 13
new-instance v0, Landroidx/appcompat/app/AlertDialog$Builder;
invoke-direct {v0, p0}, Landroidx/appcompat/app/AlertDialog$Builder;-><init>(Landroid/content/Context;)V
.line 14
.local v0, "dlgAlert":Landroidx/appcompat/app/AlertDialog$Builder;
const-string v1, "This is an alert with no consequence"
invoke-virtual {v0, v1}, Landroidx/appcompat/app/AlertDialog$Builder;->setMessage(Ljava/lang/CharSequence;)Landroidx/appcompat/app/AlertDialog$Builder;
.line 15
const-string v1, "App Title"
invoke-virtual {v0, v1}, Landroidx/appcompat/app/AlertDialog$Builder;->setTitle(Ljava/lang/CharSequence;)Landroidx/appcompat/app/AlertDialog$Builder;
.line 16
const-string v1, "Ok"
new-instance v2, Lbrut/example/install_file/Method2$1;
invoke-direct {v2, p0}, Lbrut/example/install_file/Method2$1;-><init>(Lbrut/example/install_file/Method2;)V
invoke-virtual {v0, v1, v2}, Landroidx/appcompat/app/AlertDialog$Builder;->setPositiveButton(Ljava/lang/CharSequence;Landroid/content/DialogInterface$OnClickListener;)Landroidx/appcompat/app/AlertDialog$Builder;
.line 22
const/4 v1, 0x1
invoke-virtual {v0, v1}, Landroidx/appcompat/app/AlertDialog$Builder;->setCancelable(Z)Landroidx/appcompat/app/AlertDialog$Builder;
.line 23
invoke-virtual {v0}, Landroidx/appcompat/app/AlertDialog$Builder;->create()Landroidx/appcompat/app/AlertDialog;
move-result-object v1
invoke-virtual {v1}, Landroidx/appcompat/app/AlertDialog;->show()V
.line 24
return-void
I added them directly to smali files before every
takePicture() method or Intent(MediaStore.ACTION_IMAGE_CAPTURE)
but the code is not working and the message is not displayed when user take a picture so, is there another method that can be used to take a picture in Android application that I need to insert this bytecode before it or maybe there is something wrong in the bytecode I'm using?