i new in Rev Eng, i am looking for a way to shield my apps from tampering or reverse engineering therefore i want to add a smali function that closes the app if the certificate was changed.
If anyone has an idea or have a good documentation for the use of PackageManager in smali, i would appreciate the help, thanks.
I tried this generated from ChatGPT, yet the won't open at all:
# Get the PackageManager object
invoke-virtual {v0}, Landroid/content/Context;->getPackageManager()Landroid/content/pm/PackageManager;
move-result-object v1
# Get the PackageInfo object
const-string v2, "my.package.name"
const/high16 v3, 0x0040
invoke-virtual {v1, v2, v3}, Landroid/content/pm/PackageManager;->getPackageInfo(Ljava/lang/String;I)Landroid/content/pm/PackageInfo;
move-result-object v4
# Get the expected signature
const-string v5, "308203a5..."
# Compare the expected signature with the first signature in PackageInfo
invoke-virtual {v4}, Landroid/content/pm/PackageInfo;->signatures()[Landroid/content/pm/Signature;
iget-object v6, v4, [Landroid/content/pm/Signature;->length:I
const/4 v7, 0x0
aget-object v6, v6, v7
invoke-virtual {v6}, Landroid/content/pm/Signature;->toCharsString()Ljava/lang/String;
move-result-object v6
invoke-virtual {v5, v6}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z
if-nez v8
# Quit execution
invoke-static {}, Ljava/lang/System;->exit(I)V