public void checkSignature(final Context context) {
try {
Signature[] signatures = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES).signatures;
if (signatures[0].toCharsString() != <YOUR CERTIFICATE STRING GOES HERE>) {
// Kill the process without warning. If someone changed the certificate
// is better not to give a hint about why the app stopped working android.os.Process.killProcess(android.os.Process.myPid());
}
}
catch (NameNotFoundException ex) {
// Must never fail, so if it does, means someone played with the apk, so kill the process android.os.Process.killProcess(android.os.Process.myPid());
}
}
Once this code is written, one needs to find out which one is their certificate. In order to do so, you must create or produce an APK in the release mode. This is because the release certificate is different from the debug certificate. Following which, please output your certificate into your Logcat:
signatures[0].toCharsString();
Always note, that once you go back to the debug mode, the certificate also changes and to avoid this, use the following line in order to ignore the verification process.
if ((context.getApplicationContext().getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE) != 0) return;
After this, in order to check the lucky patcher checker, one can decompile all the Lucky Patcher versions and the creator utilized the double package names between the releases. Please note, that you must be aware of the new versions and the addition of the including future package names.
private boolean checkLuckyPatcher() {
if (packageExists("com.dimonvideo.luckypatcher")) return true;
if (packageExists("com.chelpus.lackypatch")) return true;
if (packageExists("com.android.vending.billing.InAppBillingService.LACK")) return true; return false;
}
private boolean packageExists(final String packageName) {
try {
ApplicationInfo info = this.getPackageManager().getApplicationInfo(packageName, 0);
if (info == null) {
// No need really to test for null, if the package does not
// exist it will really rise an exception. but in case Google
// changes the API in the future lets be safe and test it
return false;
}
return true;
}
catch (Exception ex) {
// If we get here only means the Package does not exist
}
return false;
}