Skip to content

Instantly share code, notes, and snippets.

@t4kemyh4nd
Created October 15, 2023 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t4kemyh4nd/849b009a0f7863ab1f5d637197b7b513 to your computer and use it in GitHub Desktop.
Save t4kemyh4nd/849b009a0f7863ab1f5d637197b7b513 to your computer and use it in GitHub Desktop.
package p000;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Parcel;
import android.os.RemoteException;
import android.os.StrictMode;
import android.util.Log;
import com.google.android.gms.common.GoogleCertificatesLookupQuery;
import com.google.android.gms.common.GoogleCertificatesLookupResponse;
import com.google.android.gms.dynamite.DynamiteModule$LoadingException;
import java.util.Set;
/* compiled from: PG */
/* renamed from: aiae */
public final class signatureVerifier {
/* renamed from: a */
private static signatureVerifier verifier;
/* renamed from: b */
private static volatile Set f25705b;
/* renamed from: c */
private final Context context;
/* renamed from: d */
private volatile String f25707d;
public signatureVerifier(Context context) {
this.context = context.getApplicationContext();
}
/* renamed from: b */
public static signatureVerifier create(Context context) {
ahxq.m49410m(context);
synchronized (signatureVerifier.class) {
if (verifier == null) {
ahzz.m49334a(context);
verifier = new signatureVerifier(context);
}
}
return verifier;
}
/* renamed from: f */
static final SignatureArray packageContainsSignature(PackageInfo packageInfo, SignatureArray... signatureArrayArr) {
if (packageInfo.signatures == null) {
return null;
}
if (packageInfo.signatures.length != 1) {
Log.w("GoogleSignatureVerifier", "Package has more than one signature.");
return null;
}
SignatureBytes signatureBytes = new SignatureBytes(packageInfo.signatures[0].toByteArray());
for (int i = 0; i < signatureArrayArr.length; i++) {
if (signatureArrayArr[i].equals(signatureBytes)) {
return signatureArrayArr[i];
}
}
return null;
}
/* renamed from: g */
public static final boolean checkGoogleSignature(PackageInfo packageInfo, boolean isPackagePlay) {
SignatureArray packageContainsSignature;
if (isPackagePlay && packageInfo != null && ("com.android.vending".equals(packageInfo.packageName) || "com.google.android.gms".equals(packageInfo.packageName))) {
ApplicationInfo applicationInfo = packageInfo.applicationInfo;
if (applicationInfo == null || (applicationInfo.flags & 129) == 0) {
isPackagePlay = false;
} else {
isPackagePlay = true;
}
}
if (packageInfo != null && packageInfo.signatures != null) {
if (isPackagePlay) {
packageContainsSignature = packageContainsSignature(packageInfo, ahzy.signatures);
} else {
packageContainsSignature = packageContainsSignature(packageInfo, ahzy.signatures[0]);
}
if (packageContainsSignature != null) {
return true;
}
}
return false;
}
/* JADX WARN: Removed duplicated region for block: B:64:0x013b */
/* JADX WARN: Removed duplicated region for block: B:65:0x013d */
/* JADX WARN: Type inference failed for: r10v0, types: [android.os.IBinder, aihr] */
/* renamed from: a */
/*
Code decompiled incorrectly, please refer to instructions dump.
*/
public final GoogleCertificatesResult checkSignature(String packageName) {
GoogleCertificatesResult m49326b;
boolean googleCertApi;
if (packageName == null) {
return GoogleCertificatesResult.m49326b("null pkg");
}
if (packageName.equals(this.f25707d)) {
return GoogleCertificatesResult.certificateResultTrue;
}
StrictMode.ThreadPolicy allowThreadDiskReads = StrictMode.allowThreadDiskReads();
try {
try {
ahzz.m49333b();
IGoogleCertificatesApiBinder iGoogleCertificatesApiBinder = ahzz.f25690d;
Parcel transactAndReadException = iGoogleCertificatesApiBinder.transactAndReadException(7, iGoogleCertificatesApiBinder.obtainAndWriteInterfaceToken());
googleCertApi = parcelOperator.parcel_IntNotZero(transactAndReadException);
transactAndReadException.recycle();
} catch (RemoteException | DynamiteModule$LoadingException e) {
Log.e("GoogleCertificates", "Failed to get Google certificates from remote", e);
}
try {
if (googleCertApi) {
boolean isPlayPackage = aiad.isPlayPackage(this.context);
allowThreadDiskReads = StrictMode.allowThreadDiskReads();
try {
ahxq.m49410m(ahzz.context);
try {
ahzz.m49333b();
GoogleCertificatesLookupQuery googleCertificatesLookupQuery = new GoogleCertificatesLookupQuery(packageName, isPlayPackage, false, IObjectWrapper.gmsBinder(ahzz.context), false, true);
try {
IGoogleCertificatesApiBinder iGoogleCertificatesApiBinder2 = ahzz.f25690d;
Parcel obtainAndWriteInterfaceToken = iGoogleCertificatesApiBinder2.obtainAndWriteInterfaceToken();
parcelOperator.writeToParcel(obtainAndWriteInterfaceToken, googleCertificatesLookupQuery);
Parcel transactAndReadException2 = iGoogleCertificatesApiBinder2.transactAndReadException(6, obtainAndWriteInterfaceToken);
GoogleCertificatesLookupResponse googleCertificatesLookupResponse = (GoogleCertificatesLookupResponse) parcelOperator.createParcel(transactAndReadException2, GoogleCertificatesLookupResponse.CREATOR);
transactAndReadException2.recycle();
PackageManager.NameNotFoundException nameNotFoundException = null;
if (googleCertificatesLookupResponse.successOrFail) {
googleCertificatesLookupResponse.something();
m49326b = new GoogleCertificatesResult(true, null, null);
} else {
String str = googleCertificatesLookupResponse.responseString;
if (googleCertificatesLookupResponse.getInt() == 4) {
nameNotFoundException = new PackageManager.NameNotFoundException();
}
if (str == null) {
str = "error checking package certificate";
}
googleCertificatesLookupResponse.something();
googleCertificatesLookupResponse.getInt();
m49326b = new GoogleCertificatesResult(false, str, nameNotFoundException);
}
} catch (RemoteException e2) {
Log.e("GoogleCertificates", "Failed to get Google certificates from remote", e2);
m49326b = GoogleCertificatesResult.fail("module call", e2);
}
} catch (DynamiteModule$LoadingException e3) {
Log.e("GoogleCertificates", "Failed to get Google certificates from remote", e3);
m49326b = GoogleCertificatesResult.fail("module init: ".concat(String.valueOf(e3.getMessage())), e3);
}
if (m49326b.resultBool) {
return m49326b;
}
this.f25707d = packageName;
return m49326b;
} finally {
}
}
PackageInfo packageInfo = this.context.getPackageManager().getPackageInfo(packageName, 64);
boolean isPlayPackage2 = aiad.isPlayPackage(this.context);
if (packageInfo == null) {
m49326b = GoogleCertificatesResult.m49326b("null pkg");
} else if (packageInfo.signatures != null && packageInfo.signatures.length == 1) {
SignatureBytes signature = new SignatureBytes(packageInfo.signatures[0].toByteArray());
String pkgName = packageInfo.packageName;
GoogleCertificatesResult m49332c = ahzz.m49332c(pkgName, signature, isPlayPackage2, false); // check apps signature
if (m49332c.resultBool && packageInfo.applicationInfo != null && (packageInfo.applicationInfo.flags & 2) != 0 && ahzz.m49332c(pkgName, signature, false, true).resultBool) {
m49326b = GoogleCertificatesResult.m49326b("debuggable release cert app rejected"); // the checks are for debug build APKs
} else {
m49326b = m49332c;
}
} else {
m49326b = GoogleCertificatesResult.m49326b("single cert required");
}
if (m49326b.resultBool) {
}
} catch (PackageManager.NameNotFoundException e4) {
return GoogleCertificatesResult.fail("no pkg ".concat(packageName), e4);
}
} finally {
}
}
/* renamed from: c */
public final boolean checkPlayOrGoogle(PackageInfo packageInfo) {
if (packageInfo == null) {
return false;
}
if (checkGoogleSignature(packageInfo, false)) { // check for playstore
return true;
}
if (checkGoogleSignature(packageInfo, true)) { // check for other app
if (aiad.isPlayPackage(this.context)) {
return true;
}
Log.w("GoogleSignatureVerifier", "Test-keys aren't accepted on this build.");
}
return false;
}
/* renamed from: d */
public final boolean m49310d(String str) {
GoogleCertificatesResult checkSignature = checkSignature(str);
checkSignature.log();
return checkSignature.resultBool;
}
/* renamed from: e */
public final boolean m49309e(int i) {
GoogleCertificatesResult m49326b;
int length;
String[] packagesForUid = this.context.getPackageManager().getPackagesForUid(i);
if (packagesForUid != null && (length = packagesForUid.length) != 0) {
int i2 = 0;
m49326b = null;
while (true) {
if (i2 < length) {
m49326b = checkSignature(packagesForUid[i2]);
if (m49326b.resultBool) {
break;
}
i2++;
} else {
ahxq.m49410m(m49326b);
break;
}
}
} else {
m49326b = GoogleCertificatesResult.m49326b("no pkgs");
}
m49326b.log();
return m49326b.resultBool;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment