package com.baidu.techain.i; import android.content.Context; import android.os.Build; import android.os.Environment; import android.os.Process; import android.provider.Settings; import android.text.TextUtils; import com.huawei.hms.framework.common.ContainerUtils; import com.huawei.hms.support.hianalytics.HiAnalyticsConstant; import com.meizu.cloud.pushsdk.constants.PushConstants; import java.io.BufferedReader; import java.io.CharArrayWriter; import java.io.File; import java.io.FileReader; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import org.json.JSONObject; /* compiled from: GdUtil */ public final class j { private static final String a = new String(b.a(new byte[]{77, 122, 65, 121, 77, 84, 73, 120, 77, 68, 73, 61})); private static final String b = new String(b.a(new byte[]{90, 71, 108, 106, 100, 87, 82, 112, 89, 87, 73, 61})); private static final String c = (a + b); private static c d; private Context e; private j(Context context) { this.e = context; } private String a(String str) { try { return s.b(this.e) ? Settings.System.getString(this.e.getContentResolver(), str) : ""; } catch (Throwable unused) { c.a(); return null; } } /* JADX WARNING: Code restructure failed: missing block: B:18:?, code lost: com.baidu.techain.i.c.a(); */ /* JADX WARNING: Code restructure failed: missing block: B:19:0x002a, code lost: if (r1 != null) goto L_0x002c; */ /* JADX WARNING: Code restructure failed: missing block: B:21:?, code lost: r1.close(); */ /* JADX WARNING: Code restructure failed: missing block: B:22:0x0030, code lost: com.baidu.techain.i.c.a(); */ /* JADX WARNING: Code restructure failed: missing block: B:24:0x0033, code lost: return null; */ /* JADX WARNING: Code restructure failed: missing block: B:25:0x0034, code lost: r5 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:26:0x0035, code lost: if (r1 != null) goto L_0x0037; */ /* JADX WARNING: Code restructure failed: missing block: B:28:?, code lost: r1.close(); */ /* JADX WARNING: Code restructure failed: missing block: B:29:0x003b, code lost: com.baidu.techain.i.c.a(); */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Missing exception handler attribute for start block: B:17:0x0027 */ private static String a(File file) { FileReader fileReader; try { fileReader = new FileReader(file); char[] cArr = new char[8192]; CharArrayWriter charArrayWriter = new CharArrayWriter(); while (true) { int read = fileReader.read(cArr); if (read <= 0) { break; } charArrayWriter.write(cArr, 0, read); } String charArrayWriter2 = charArrayWriter.toString(); try { fileReader.close(); } catch (Throwable unused) { c.a(); } return charArrayWriter2; } catch (Throwable unused2) { fileReader = null; } throw th; } public static String a(Context context) { try { c b2 = b(context); if (b2 != null) { return b2.a(); } return ""; } catch (Throwable unused) { c.a(); return ""; } } private static synchronized c b(Context context) { c cVar; synchronized (j.class) { if (d == null) { d = new j(context).a(); } cVar = d; } return cVar; } private c a() { c cVar = null; try { File file = new File(this.e.getFilesDir(), c.e("K5j7Snuat7HHCaEg62XaRa41Ukv_4vtSH9Z4FqXi1Fs=")); if (file.exists()) { cVar = c.a(d(a(file))); } if (cVar != null) { return cVar; } c a2 = c.a(d(a(c.e("FLI7RPHK558lhmIMdK5V1-nh-gfSlVAFvUdffcjh8sgAXO2nb2l_YXWA6lX6geWt")))); if (a2 != null) { return a2; } boolean z = this.e.checkPermission("android.permission.READ_EXTERNAL_STORAGE", Process.myPid(), Process.myUid()) == 0; if (z) { a2 = b(); } if (a2 != null) { return a2; } c c2 = c(); if (c2 == null && z) { return b(c("")); } return c2; } catch (Throwable unused) { c.a(); return null; } } private c b() { try { if (!s.c(this.e)) { return null; } File externalStorageDirectory = Environment.getExternalStorageDirectory(); File file = new File(externalStorageDirectory, c.e("_99uIeWLLYgYWnfdVm4xmTNMy58crLVzIq1_1xd6OaXaqNsyUOaKaQPHeL9hMa2J") + "/" + c.e("idzo8hWEQF2c4tBTa5WOlQMU8UU8Wq-86X4X9ljayiU=")); if (file.exists()) { String a2 = a(file); if (!TextUtils.isEmpty(a2)) { try { return c.a(new String(a.a(c, c, b.a(a2.getBytes())))); } catch (Throwable unused) { c.a(); } } } return null; } catch (Throwable unused2) { c.a(); } } private c b(String str) { boolean z = Build.VERSION.SDK_INT < 23; if ((z && TextUtils.isEmpty(str)) || !s.c(this.e)) { return null; } String str2 = ""; File externalStorageDirectory = Environment.getExternalStorageDirectory(); File file = new File(externalStorageDirectory, c.e("u_lhldj5Nkwulw6YvIU2wr_ieZRcYQnQZ7zSlbUYnYY=") + "/" + c.e("u2fjUEpcZJL7IE6RlBqIRmFJW_FjZrNApjdMKDgt7FM=")); if (!file.exists()) { File externalStorageDirectory2 = Environment.getExternalStorageDirectory(); file = new File(externalStorageDirectory2, c.e("_99uIeWLLYgYWnfdVm4xmTNMy58crLVzIq1_1xd6OaXaqNsyUOaKaQPHeL9hMa2J") + "/" + c.e("u2fjUEpcZJL7IE6RlBqIRmFJW_FjZrNApjdMKDgt7FM=")); } try { BufferedReader bufferedReader = new BufferedReader(new FileReader(file)); StringBuilder sb = new StringBuilder(); while (true) { String readLine = bufferedReader.readLine(); if (readLine == null) { break; } sb.append(readLine); sb.append("\r\n"); } bufferedReader.close(); String[] split = new String(a.a(c, c, b.a(sb.toString().getBytes()))).split(ContainerUtils.KEY_VALUE_DELIMITER); if (split != null && split.length == 2) { if (z && str.equals(split[0])) { str2 = split[1]; } else if (!z) { if (TextUtils.isEmpty(str)) { str = split[1]; } str2 = split[1]; } } } catch (Throwable unused) { c.a(); } if (TextUtils.isEmpty(str2)) { return null; } c cVar = new c((byte) 0); cVar.a = str2; cVar.b = str; return cVar; } private c c() { try { String a2 = a(c.e("FLI7RPHK558lhmIMdK5V18TV2libLOeHJlQPRa8lKBaxRs4pujQo1mXKtiCUFVkg")); String a3 = a(c.e("ARQJ8IArCy4jLSUJ6i4PbDdNue2ww1CwfUTDQn8F4ug=")); if (TextUtils.isEmpty(a3)) { a3 = c(""); } if (TextUtils.isEmpty(a2)) { String i = s.i(this.e); a2 = a(d.a((c.e("q6R8gqLUgHDSsH6dbL27xN7Qr9sa0MxMqXTV66AWUUE=") + a3 + i).getBytes())); } if (TextUtils.isEmpty(a2)) { return null; } c cVar = new c((byte) 0); cVar.a = a2; cVar.b = a3; return cVar; } catch (Throwable unused) { c.a(); return null; } } private static String c(String str) { return TextUtils.isEmpty(PushConstants.PUSH_TYPE_NOTIFY) ? str : PushConstants.PUSH_TYPE_NOTIFY; } private static String d(String str) { if (TextUtils.isEmpty(str)) { return null; } try { return new String(a.a(c, c, b.a(str.getBytes()))); } catch (Throwable unused) { c.a(); return ""; } } /* access modifiers changed from: private */ /* compiled from: GdUtil */ public static class c { public String a; public String b; private c() { } /* synthetic */ c(byte b2) { this(); } public static c a(String str) { if (TextUtils.isEmpty(str)) { return null; } try { JSONObject jSONObject = new JSONObject(str); String string = jSONObject.getString("deviceid"); String string2 = jSONObject.getString("imei"); if (!TextUtils.isEmpty(string)) { if (string2 != null) { c cVar = new c(); cVar.a = string; cVar.b = string2; return cVar; } } return null; } catch (Throwable unused) { c.a(); return null; } } public final String a() { try { String str = this.b; if (TextUtils.isEmpty(str)) { str = PushConstants.PUSH_TYPE_NOTIFY; } String stringBuffer = new StringBuffer(str).reverse().toString(); return this.a + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + stringBuffer; } catch (Throwable unused) { c.a(); return null; } } } /* compiled from: GdUtil */ public static class a { public static byte[] a(String str, String str2, byte[] bArr) throws Exception { SecretKeySpec secretKeySpec = new SecretKeySpec(str2.getBytes(), "AES"); Cipher instance = Cipher.getInstance("AES/CBC/PKCS5Padding"); instance.init(2, secretKeySpec, new IvParameterSpec(str.getBytes())); return instance.doFinal(bArr); } } /* compiled from: GdUtil */ public static class b { private static final byte[] a = {65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47}; public static byte[] a(byte[] bArr) { byte b; int i; int length = bArr.length; int i2 = (length / 4) * 3; if (i2 == 0) { return new byte[0]; } byte[] bArr2 = new byte[i2]; int i3 = 0; while (true) { byte b2 = bArr[length - 1]; b = 10; if (!(b2 == 10 || b2 == 13 || b2 == 32 || b2 == 9)) { if (b2 != 61) { break; } i3++; } length--; } int i4 = 0; int i5 = 0; int i6 = 0; int i7 = 0; while (i4 < length) { byte b3 = bArr[i4]; if (!(b3 == b || b3 == 13 || b3 == 32 || b3 == 9)) { if (b3 >= 65 && b3 <= 90) { i = b3 - 65; } else if (b3 >= 97 && b3 <= 122) { i = b3 - 71; } else if (b3 >= 48 && b3 <= 57) { i = b3 + 4; } else if (b3 == 43) { i = 62; } else if (b3 != 47) { return null; } else { i = 63; } i5 = (i5 << 6) | ((byte) i); if (i7 % 4 == 3) { int i8 = i6 + 1; bArr2[i6] = (byte) ((i5 & 16711680) >> 16); int i9 = i8 + 1; bArr2[i8] = (byte) ((i5 & 65280) >> 8); bArr2[i9] = (byte) (i5 & 255); i6 = i9 + 1; } i7++; } i4++; b = 10; } if (i3 > 0) { int i10 = i5 << (i3 * 6); int i11 = i6 + 1; bArr2[i6] = (byte) ((i10 & 16711680) >> 16); if (i3 == 1) { i6 = i11 + 1; bArr2[i11] = (byte) ((i10 & 65280) >> 8); } else { i6 = i11; } } byte[] bArr3 = new byte[i6]; System.arraycopy(bArr2, 0, bArr3, 0, i6); return bArr3; } } /* compiled from: GdUtil */ public static class d { public static String a(byte[] bArr) { try { MessageDigest instance = MessageDigest.getInstance("MD5"); instance.reset(); instance.update(bArr); byte[] digest = instance.digest(); StringBuilder sb = new StringBuilder(); for (byte b : digest) { String upperCase = Integer.toHexString(b & 255).toUpperCase(); if (upperCase.length() == 1) { sb.append(PushConstants.PUSH_TYPE_NOTIFY); } sb.append(upperCase); sb.append(""); } return sb.toString(); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } } } }