jimu-decompiled/sources/com/tencent/bugly/proguard/z.java
2025-05-13 19:24:51 +02:00

1121 lines
41 KiB
Java

package com.tencent.bugly.proguard;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.os.Looper;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Process;
import com.ijm.dataencryption.de.DataDecryptTool;
import com.tencent.bugly.crashreport.common.info.AppInfo;
import com.tencent.bugly.crashreport.common.info.PlugInBean;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyFactory;
import java.security.MessageDigest;
import java.security.PublicKey;
import java.security.spec.X509EncodedKeySpec;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import javax.crypto.Cipher;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
/* compiled from: BUGLY */
/* loaded from: classes.dex */
public class z {
private static Map<String, String> a = null;
private static boolean b = false;
public static String a(Throwable th) {
if (th == null) {
return "";
}
try {
StringWriter stringWriter = new StringWriter();
th.printStackTrace(new PrintWriter(stringWriter));
return stringWriter.getBuffer().toString();
} catch (Throwable th2) {
if (x.a(th2)) {
return "fail";
}
th2.printStackTrace();
return "fail";
}
}
private static byte[] b(byte[] bArr, int i, String str) {
if (bArr == null || i == -1) {
return bArr;
}
try {
aj a2 = a.a(i);
if (a2 == null) {
return null;
}
a2.a(str);
return a2.a(bArr);
} catch (Throwable th) {
if (!x.a(th)) {
th.printStackTrace();
}
x.d("encrytype %d %s", Integer.valueOf(i), str);
return null;
}
}
private static ArrayList<String> c(Context context, String str) {
BufferedReader bufferedReader;
BufferedReader bufferedReader2;
if (AppInfo.f(context)) {
return new ArrayList<>(Arrays.asList("unknown(low memory)"));
}
ArrayList<String> arrayList = new ArrayList<>();
try {
ArrayList arrayList2 = new ArrayList(Arrays.asList((new File("/system/bin/sh").exists() && new File("/system/bin/sh").canExecute()) ? "/system/bin/sh" : "sh", "-c"));
arrayList2.add(str);
Process exec = Runtime.getRuntime().exec((String[]) arrayList2.toArray(new String[3]));
bufferedReader = new BufferedReader(new InputStreamReader(exec.getInputStream()));
while (true) {
try {
String readLine = bufferedReader.readLine();
if (readLine == null) {
break;
}
arrayList.add(readLine);
} catch (Throwable th) {
th = th;
bufferedReader2 = null;
}
}
bufferedReader2 = new BufferedReader(new InputStreamReader(exec.getErrorStream()));
while (true) {
try {
String readLine2 = bufferedReader2.readLine();
if (readLine2 != null) {
arrayList.add(readLine2);
} else {
try {
break;
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (Throwable th2) {
th = th2;
try {
if (!x.a(th)) {
th.printStackTrace();
}
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e2) {
e2.printStackTrace();
}
}
if (bufferedReader2 != null) {
try {
bufferedReader2.close();
} catch (IOException e3) {
e3.printStackTrace();
}
}
return null;
} finally {
}
}
}
bufferedReader.close();
try {
bufferedReader2.close();
} catch (IOException e4) {
e4.printStackTrace();
}
return arrayList;
} catch (Throwable th3) {
th = th3;
bufferedReader = null;
bufferedReader2 = null;
}
}
public static String a() {
return a(System.currentTimeMillis());
}
public static String a(long j) {
try {
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US).format(new Date(j));
} catch (Exception unused) {
return new Date().toString();
}
}
public static byte[] b(byte[] bArr, int i) {
if (bArr == null || i == -1) {
return bArr;
}
Object[] objArr = new Object[2];
objArr[0] = Integer.valueOf(bArr.length);
objArr[1] = i == 2 ? "Gzip" : "zip";
x.c("[Util] Unzip %d bytes data with type %s", objArr);
try {
ae a2 = ad.a(i);
if (a2 == null) {
return null;
}
return a2.b(bArr);
} catch (Throwable th) {
if (!x.a(th)) {
th.printStackTrace();
}
return null;
}
}
public static String a(Date date) {
if (date == null) {
return null;
}
try {
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US).format(date);
} catch (Exception unused) {
return new Date().toString();
}
}
public static byte[] b(byte[] bArr, int i, int i2, String str) {
try {
return b(b(bArr, 1, str), 2);
} catch (Exception e) {
if (x.a(e)) {
return null;
}
e.printStackTrace();
return null;
}
}
private static byte[] a(byte[] bArr, int i, String str) {
if (bArr == null || i == -1) {
return bArr;
}
x.c("rqdp{ enD:} %d %d", Integer.valueOf(bArr.length), Integer.valueOf(i));
try {
aj a2 = a.a(i);
if (a2 == null) {
return null;
}
a2.a(str);
return a2.b(bArr);
} catch (Throwable th) {
if (!x.a(th)) {
th.printStackTrace();
}
return null;
}
}
public static long b() {
try {
return (((System.currentTimeMillis() + TimeZone.getDefault().getRawOffset()) / 86400000) * 86400000) - TimeZone.getDefault().getRawOffset();
} catch (Throwable th) {
if (x.a(th)) {
return -1L;
}
th.printStackTrace();
return -1L;
}
}
public static byte[] a(File file, String str, String str2) {
ZipOutputStream zipOutputStream;
ByteArrayInputStream byteArrayInputStream;
ByteArrayOutputStream byteArrayOutputStream;
if (str == null || str.length() == 0) {
return null;
}
x.c("rqdp{ ZF start}", new Object[0]);
try {
byteArrayInputStream = new ByteArrayInputStream(str.getBytes("UTF-8"));
byteArrayOutputStream = new ByteArrayOutputStream();
zipOutputStream = new ZipOutputStream(byteArrayOutputStream);
} catch (Throwable th) {
th = th;
zipOutputStream = null;
}
try {
zipOutputStream.setMethod(8);
zipOutputStream.putNextEntry(new ZipEntry(str2));
byte[] bArr = new byte[DataDecryptTool.DECRYPT_SP_FILE];
while (true) {
int read = byteArrayInputStream.read(bArr);
if (read <= 0) {
break;
}
zipOutputStream.write(bArr, 0, read);
}
zipOutputStream.closeEntry();
zipOutputStream.flush();
zipOutputStream.finish();
byte[] byteArray = byteArrayOutputStream.toByteArray();
try {
zipOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
x.c("rqdp{ ZF end}", new Object[0]);
return byteArray;
} catch (Throwable th2) {
th = th2;
try {
if (!x.a(th)) {
th.printStackTrace();
}
if (zipOutputStream != null) {
try {
zipOutputStream.close();
} catch (IOException e2) {
e2.printStackTrace();
}
}
x.c("rqdp{ ZF end}", new Object[0]);
return null;
} catch (Throwable th3) {
if (zipOutputStream != null) {
try {
zipOutputStream.close();
} catch (IOException e3) {
e3.printStackTrace();
}
}
x.c("rqdp{ ZF end}", new Object[0]);
throw th3;
}
}
}
public static String b(byte[] bArr) {
if (bArr == null || bArr.length == 0) {
return "NULL";
}
try {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
messageDigest.update(bArr);
return a(messageDigest.digest());
} catch (Throwable th) {
if (x.a(th)) {
return null;
}
th.printStackTrace();
return null;
}
}
public static void b(long j) {
try {
Thread.sleep(j);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public static void b(String str) {
if (str == null) {
return;
}
File file = new File(str);
if (file.isFile() && file.exists() && file.canWrite()) {
file.delete();
}
}
public static byte[] c(long j) {
try {
StringBuilder sb = new StringBuilder();
sb.append(j);
return sb.toString().getBytes("utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return null;
}
}
public static String b(Throwable th) {
if (th == null) {
return "";
}
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
th.printStackTrace(printWriter);
printWriter.flush();
return stringWriter.toString();
}
public static long c(byte[] bArr) {
if (bArr == null) {
return -1L;
}
try {
return Long.parseLong(new String(bArr, "utf-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return -1L;
}
}
public static boolean c(String str) {
if (str == null || str.trim().length() <= 0) {
return false;
}
if (str.length() > 255) {
x.a("URL(%s)'s length is larger than 255.", str);
return false;
}
if (str.toLowerCase().startsWith("http")) {
return true;
}
x.a("URL(%s) is not start with \"http\".", str);
return false;
}
public static void b(Parcel parcel, Map<String, String> map) {
if (map != null && map.size() > 0) {
int size = map.size();
ArrayList<String> arrayList = new ArrayList<>(size);
ArrayList<String> arrayList2 = new ArrayList<>(size);
for (Map.Entry<String, String> entry : map.entrySet()) {
arrayList.add(entry.getKey());
arrayList2.add(entry.getValue());
}
Bundle bundle = new Bundle();
bundle.putStringArrayList("keys", arrayList);
bundle.putStringArrayList("values", arrayList2);
parcel.writeBundle(bundle);
return;
}
parcel.writeBundle(null);
}
public static byte[] a(byte[] bArr, int i) {
if (bArr == null || i == -1) {
return bArr;
}
Object[] objArr = new Object[2];
objArr[0] = Integer.valueOf(bArr.length);
objArr[1] = i == 2 ? "Gzip" : "zip";
x.c("[Util] Zip %d bytes data with type %s", objArr);
try {
ae a2 = ad.a(i);
if (a2 == null) {
return null;
}
return a2.a(bArr);
} catch (Throwable th) {
if (!x.a(th)) {
th.printStackTrace();
}
return null;
}
}
public static Map<String, String> b(Parcel parcel) {
Bundle readBundle = parcel.readBundle();
HashMap hashMap = null;
if (readBundle == null) {
return null;
}
ArrayList<String> stringArrayList = readBundle.getStringArrayList("keys");
ArrayList<String> stringArrayList2 = readBundle.getStringArrayList("values");
if (stringArrayList != null && stringArrayList2 != null && stringArrayList.size() == stringArrayList2.size()) {
hashMap = new HashMap(stringArrayList.size());
for (int i = 0; i < stringArrayList.size(); i++) {
hashMap.put(stringArrayList.get(i), stringArrayList2.get(i));
}
} else {
x.e("map parcel error!", new Object[0]);
}
return hashMap;
}
public static byte[] a(byte[] bArr, int i, int i2, String str) {
if (bArr == null) {
return null;
}
try {
return a(a(bArr, 2), 1, str);
} catch (Throwable th) {
if (!x.a(th)) {
th.printStackTrace();
}
return null;
}
}
public static String a(byte[] bArr) {
if (bArr == null) {
return "";
}
StringBuffer stringBuffer = new StringBuffer();
for (byte b2 : bArr) {
String hexString = Integer.toHexString(b2 & 255);
if (hexString.length() == 1) {
stringBuffer.append("0");
}
stringBuffer.append(hexString);
}
return stringBuffer.toString().toUpperCase();
}
public static byte[] b(int i, byte[] bArr, byte[] bArr2) {
try {
PublicKey generatePublic = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(bArr2));
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(1, generatePublic);
return cipher.doFinal(bArr);
} catch (Exception e) {
if (x.b(e)) {
return null;
}
e.printStackTrace();
return null;
}
}
public static boolean a(File file, File file2, int i) {
FileInputStream fileInputStream;
ZipOutputStream zipOutputStream;
x.c("rqdp{ ZF start}", new Object[0]);
if (file != null && file2 != null && !file.equals(file2)) {
if (file.exists() && file.canRead()) {
try {
if (file2.getParentFile() != null && !file2.getParentFile().exists()) {
file2.getParentFile().mkdirs();
}
if (!file2.exists()) {
file2.createNewFile();
}
} catch (Throwable th) {
if (!x.a(th)) {
th.printStackTrace();
}
}
if (!file2.exists() || !file2.canRead()) {
return false;
}
try {
fileInputStream = new FileInputStream(file);
try {
zipOutputStream = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(file2)));
try {
zipOutputStream.setMethod(8);
zipOutputStream.putNextEntry(new ZipEntry(file.getName()));
byte[] bArr = new byte[5000];
while (true) {
int read = fileInputStream.read(bArr);
if (read <= 0) {
break;
}
zipOutputStream.write(bArr, 0, read);
}
zipOutputStream.flush();
zipOutputStream.closeEntry();
try {
fileInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
zipOutputStream.close();
} catch (IOException e2) {
e2.printStackTrace();
}
x.c("rqdp{ ZF end}", new Object[0]);
return true;
} catch (Throwable th2) {
th = th2;
try {
if (!x.a(th)) {
th.printStackTrace();
}
if (fileInputStream != null) {
try {
fileInputStream.close();
} catch (IOException e3) {
e3.printStackTrace();
}
}
if (zipOutputStream != null) {
try {
zipOutputStream.close();
} catch (IOException e4) {
e4.printStackTrace();
}
}
x.c("rqdp{ ZF end}", new Object[0]);
return false;
} catch (Throwable th3) {
if (fileInputStream != null) {
try {
fileInputStream.close();
} catch (IOException e5) {
e5.printStackTrace();
}
}
if (zipOutputStream != null) {
try {
zipOutputStream.close();
} catch (IOException e6) {
e6.printStackTrace();
}
}
x.c("rqdp{ ZF end}", new Object[0]);
throw th3;
}
}
} catch (Throwable th4) {
th = th4;
zipOutputStream = null;
}
} catch (Throwable th5) {
th = th5;
fileInputStream = null;
zipOutputStream = null;
}
} else {
x.d("rqdp{ !sFile.exists() || !sFile.canRead(),pls check ,return!}", new Object[0]);
return false;
}
} else {
x.d("rqdp{ err ZF 1R!}", new Object[0]);
return false;
}
}
public static boolean b(Context context, String str) {
x.c("[Util] Try to unlock file: %s (pid=%d | tid=%d)", str, Integer.valueOf(Process.myPid()), Integer.valueOf(Process.myTid()));
try {
File file = new File(context.getFilesDir() + File.separator + str);
if (!file.exists()) {
return true;
}
if (!file.delete()) {
return false;
}
x.c("[Util] Successfully unlocked file: %s (pid=%d | tid=%d)", str, Integer.valueOf(Process.myPid()), Integer.valueOf(Process.myTid()));
return true;
} catch (Throwable th) {
x.a(th);
return false;
}
}
public static String b(String str, String str2) {
return (com.tencent.bugly.crashreport.common.info.a.b() == null || com.tencent.bugly.crashreport.common.info.a.b().E == null) ? "" : com.tencent.bugly.crashreport.common.info.a.b().E.getString(str, str2);
}
public static String a(Context context, String str) {
if (str == null || str.trim().equals("")) {
return "";
}
if (a == null) {
a = new HashMap();
ArrayList<String> c = c(context, "getprop");
if (c != null && c.size() > 0) {
x.b(z.class, "Successfully get 'getprop' list.", new Object[0]);
Pattern compile = Pattern.compile("\\[(.+)\\]: \\[(.*)\\]");
Iterator<String> it = c.iterator();
while (it.hasNext()) {
Matcher matcher = compile.matcher(it.next());
if (matcher.find()) {
a.put(matcher.group(1), matcher.group(2));
}
}
x.b(z.class, "System properties number: %d.", Integer.valueOf(a.size()));
}
}
return a.containsKey(str) ? a.get(str) : "fail";
}
public static boolean a(String str) {
return str == null || str.trim().length() <= 0;
}
public static Context a(Context context) {
Context applicationContext;
return (context == null || (applicationContext = context.getApplicationContext()) == null) ? context : applicationContext;
}
public static void a(Class<?> cls, String str, Object obj, Object obj2) {
try {
Field declaredField = cls.getDeclaredField(str);
declaredField.setAccessible(true);
declaredField.set(null, obj);
} catch (Exception unused) {
}
}
public static Object a(String str, String str2, Object obj, Class<?>[] clsArr, Object[] objArr) {
try {
Method declaredMethod = Class.forName(str).getDeclaredMethod(str2, clsArr);
declaredMethod.setAccessible(true);
return declaredMethod.invoke(null, objArr);
} catch (Exception unused) {
return null;
}
}
public static void a(Parcel parcel, Map<String, PlugInBean> map) {
if (map != null && map.size() > 0) {
int size = map.size();
ArrayList arrayList = new ArrayList(size);
ArrayList arrayList2 = new ArrayList(size);
for (Map.Entry<String, PlugInBean> entry : map.entrySet()) {
arrayList.add(entry.getKey());
arrayList2.add(entry.getValue());
}
Bundle bundle = new Bundle();
bundle.putInt("pluginNum", arrayList.size());
for (int i = 0; i < arrayList.size(); i++) {
bundle.putString("pluginKey" + i, (String) arrayList.get(i));
}
for (int i2 = 0; i2 < arrayList.size(); i2++) {
bundle.putString("pluginVal" + i2 + "plugInId", ((PlugInBean) arrayList2.get(i2)).a);
bundle.putString("pluginVal" + i2 + "plugInUUID", ((PlugInBean) arrayList2.get(i2)).c);
bundle.putString("pluginVal" + i2 + "plugInVersion", ((PlugInBean) arrayList2.get(i2)).b);
}
parcel.writeBundle(bundle);
return;
}
parcel.writeBundle(null);
}
public static Map<String, PlugInBean> a(Parcel parcel) {
Bundle readBundle = parcel.readBundle();
HashMap hashMap = null;
if (readBundle == null) {
return null;
}
ArrayList arrayList = new ArrayList();
ArrayList arrayList2 = new ArrayList();
int intValue = ((Integer) readBundle.get("pluginNum")).intValue();
for (int i = 0; i < intValue; i++) {
arrayList.add(readBundle.getString("pluginKey" + i));
}
for (int i2 = 0; i2 < intValue; i2++) {
arrayList2.add(new PlugInBean(readBundle.getString("pluginVal" + i2 + "plugInId"), readBundle.getString("pluginVal" + i2 + "plugInVersion"), readBundle.getString("pluginVal" + i2 + "plugInUUID")));
}
if (arrayList.size() == arrayList2.size()) {
hashMap = new HashMap(arrayList.size());
for (int i3 = 0; i3 < arrayList.size(); i3++) {
hashMap.put(arrayList.get(i3), PlugInBean.class.cast(arrayList2.get(i3)));
}
} else {
x.e("map plugin parcel error!", new Object[0]);
}
return hashMap;
}
public static byte[] a(Parcelable parcelable) {
Parcel obtain = Parcel.obtain();
parcelable.writeToParcel(obtain, 0);
byte[] marshall = obtain.marshall();
obtain.recycle();
return marshall;
}
public static <T> T a(byte[] bArr, Parcelable.Creator<T> creator) {
Parcel obtain = Parcel.obtain();
obtain.unmarshall(bArr, 0, bArr.length);
obtain.setDataPosition(0);
try {
return creator.createFromParcel(obtain);
} catch (Throwable th) {
try {
th.printStackTrace();
if (obtain == null) {
return null;
}
obtain.recycle();
return null;
} finally {
if (obtain != null) {
obtain.recycle();
}
}
}
}
public static String a(Context context, int i, String str) {
Process process = null;
if (!AppInfo.a(context, "android.permission.READ_LOGS")) {
x.d("no read_log permission!", new Object[0]);
return null;
}
String[] strArr = str == null ? new String[]{"logcat", "-d", "-v", "threadtime"} : new String[]{"logcat", "-d", "-v", "threadtime", "-s", str};
StringBuilder sb = new StringBuilder();
try {
process = Runtime.getRuntime().exec(strArr);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
while (true) {
String readLine = bufferedReader.readLine();
if (readLine == null) {
break;
}
sb.append(readLine);
sb.append("\n");
if (i > 0 && sb.length() > i) {
sb.delete(0, sb.length() - i);
}
}
return sb.toString();
} catch (Throwable th) {
try {
if (!x.a(th)) {
th.printStackTrace();
}
sb.append("\n[error:" + th.toString() + "]");
String sb2 = sb.toString();
if (process != null) {
try {
process.getOutputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
try {
process.getInputStream().close();
} catch (IOException e2) {
e2.printStackTrace();
}
try {
process.getErrorStream().close();
} catch (IOException e3) {
e3.printStackTrace();
}
}
return sb2;
} finally {
if (process != null) {
try {
process.getOutputStream().close();
} catch (IOException e4) {
e4.printStackTrace();
}
try {
process.getInputStream().close();
} catch (IOException e5) {
e5.printStackTrace();
}
try {
process.getErrorStream().close();
} catch (IOException e6) {
e6.printStackTrace();
}
}
}
}
}
public static Map<String, String> a(int i, boolean z) {
HashMap hashMap = new HashMap(12);
Map<Thread, StackTraceElement[]> allStackTraces = Thread.getAllStackTraces();
if (allStackTraces == null) {
return null;
}
Thread thread = Looper.getMainLooper().getThread();
if (!allStackTraces.containsKey(thread)) {
allStackTraces.put(thread, thread.getStackTrace());
}
Thread.currentThread().getId();
StringBuilder sb = new StringBuilder();
for (Map.Entry<Thread, StackTraceElement[]> entry : allStackTraces.entrySet()) {
int i2 = 0;
sb.setLength(0);
if (entry.getValue() != null && entry.getValue().length != 0) {
StackTraceElement[] value = entry.getValue();
int length = value.length;
while (true) {
if (i2 >= length) {
break;
}
StackTraceElement stackTraceElement = value[i2];
if (i > 0 && sb.length() >= i) {
sb.append("\n[Stack over limit size :" + i + " , has been cut!]");
break;
}
sb.append(stackTraceElement.toString());
sb.append("\n");
i2++;
}
hashMap.put(entry.getKey().getName() + "(" + entry.getKey().getId() + ")", sb.toString());
}
}
return hashMap;
}
/* JADX WARN: Removed duplicated region for block: B:24:0x0055 A[Catch: all -> 0x0059, Exception -> 0x005b, TRY_ENTER, TryCatch #2 {Exception -> 0x005b, blocks: (B:9:0x001c, B:17:0x0035, B:18:0x0038, B:24:0x0055, B:25:0x0058), top: B:4:0x0006, outer: #3 }] */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct code enable 'Show inconsistent code' option in preferences
*/
public static synchronized byte[] a(int r6) {
/*
java.lang.Class<com.tencent.bugly.proguard.z> r6 = com.tencent.bugly.proguard.z.class
monitor-enter(r6)
r0 = 16
r1 = 0
byte[] r0 = new byte[r0] // Catch: java.lang.Throwable -> L23 java.lang.Exception -> L26
java.io.DataInputStream r2 = new java.io.DataInputStream // Catch: java.lang.Throwable -> L23 java.lang.Exception -> L26
java.io.FileInputStream r3 = new java.io.FileInputStream // Catch: java.lang.Throwable -> L23 java.lang.Exception -> L26
java.io.File r4 = new java.io.File // Catch: java.lang.Throwable -> L23 java.lang.Exception -> L26
java.lang.String r5 = "/dev/urandom"
r4.<init>(r5) // Catch: java.lang.Throwable -> L23 java.lang.Exception -> L26
r3.<init>(r4) // Catch: java.lang.Throwable -> L23 java.lang.Exception -> L26
r2.<init>(r3) // Catch: java.lang.Throwable -> L23 java.lang.Exception -> L26
r2.readFully(r0) // Catch: java.lang.Exception -> L21 java.lang.Throwable -> L52
r2.close() // Catch: java.lang.Throwable -> L59 java.lang.Exception -> L5b
monitor-exit(r6)
return r0
L21:
r0 = move-exception
goto L28
L23:
r0 = move-exception
r2 = r1
goto L53
L26:
r0 = move-exception
r2 = r1
L28:
java.lang.String r3 = "Failed to read from /dev/urandom : %s"
r4 = 1
java.lang.Object[] r4 = new java.lang.Object[r4] // Catch: java.lang.Throwable -> L52
r5 = 0
r4[r5] = r0 // Catch: java.lang.Throwable -> L52
com.tencent.bugly.proguard.x.e(r3, r4) // Catch: java.lang.Throwable -> L52
if (r2 == 0) goto L38
r2.close() // Catch: java.lang.Throwable -> L59 java.lang.Exception -> L5b
L38:
java.lang.String r0 = "AES"
javax.crypto.KeyGenerator r0 = javax.crypto.KeyGenerator.getInstance(r0) // Catch: java.lang.Throwable -> L59 java.lang.Exception -> L5b
r2 = 128(0x80, float:1.8E-43)
java.security.SecureRandom r3 = new java.security.SecureRandom // Catch: java.lang.Throwable -> L59 java.lang.Exception -> L5b
r3.<init>() // Catch: java.lang.Throwable -> L59 java.lang.Exception -> L5b
r0.init(r2, r3) // Catch: java.lang.Throwable -> L59 java.lang.Exception -> L5b
javax.crypto.SecretKey r0 = r0.generateKey() // Catch: java.lang.Throwable -> L59 java.lang.Exception -> L5b
byte[] r0 = r0.getEncoded() // Catch: java.lang.Throwable -> L59 java.lang.Exception -> L5b
monitor-exit(r6)
return r0
L52:
r0 = move-exception
L53:
if (r2 == 0) goto L58
r2.close() // Catch: java.lang.Throwable -> L59 java.lang.Exception -> L5b
L58:
throw r0 // Catch: java.lang.Throwable -> L59 java.lang.Exception -> L5b
L59:
r0 = move-exception
goto L67
L5b:
r0 = move-exception
boolean r2 = com.tencent.bugly.proguard.x.b(r0) // Catch: java.lang.Throwable -> L59
if (r2 != 0) goto L65
r0.printStackTrace() // Catch: java.lang.Throwable -> L59
L65:
monitor-exit(r6)
return r1
L67:
monitor-exit(r6)
throw r0
*/
throw new UnsupportedOperationException("Method not decompiled: com.tencent.bugly.proguard.z.a(int):byte[]");
}
@TargetApi(19)
public static byte[] a(int i, byte[] bArr, byte[] bArr2) {
try {
SecretKeySpec secretKeySpec = new SecretKeySpec(bArr2, "AES");
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
if (Build.VERSION.SDK_INT >= 21 && !b) {
try {
cipher.init(i, secretKeySpec, new GCMParameterSpec(cipher.getBlockSize() << 3, bArr2));
return cipher.doFinal(bArr);
} catch (InvalidAlgorithmParameterException e) {
b = true;
throw e;
}
}
cipher.init(i, secretKeySpec, new IvParameterSpec(bArr2));
return cipher.doFinal(bArr);
} catch (Exception e2) {
if (x.b(e2)) {
return null;
}
e2.printStackTrace();
return null;
}
}
public static boolean a(Context context, String str, long j) {
x.c("[Util] Try to lock file:%s (pid=%d | tid=%d)", str, Integer.valueOf(Process.myPid()), Integer.valueOf(Process.myTid()));
try {
File file = new File(context.getFilesDir() + File.separator + str);
if (file.exists()) {
if (System.currentTimeMillis() - file.lastModified() < j) {
return false;
}
x.c("[Util] Lock file (%s) is expired, unlock it.", str);
b(context, str);
}
if (file.createNewFile()) {
x.c("[Util] Successfully locked file: %s (pid=%d | tid=%d)", str, Integer.valueOf(Process.myPid()), Integer.valueOf(Process.myTid()));
return true;
}
x.c("[Util] Failed to locked file: %s (pid=%d | tid=%d)", str, Integer.valueOf(Process.myPid()), Integer.valueOf(Process.myTid()));
return false;
} catch (Throwable th) {
x.a(th);
return false;
}
}
public static String a(File file, int i, boolean z) {
BufferedReader bufferedReader;
if (file == null || !file.exists() || !file.canRead()) {
return null;
}
try {
StringBuilder sb = new StringBuilder();
bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8"));
while (true) {
try {
String readLine = bufferedReader.readLine();
if (readLine == null) {
break;
}
sb.append(readLine);
sb.append("\n");
if (i > 0 && sb.length() > i) {
if (z) {
sb.delete(i, sb.length());
break;
}
sb.delete(0, sb.length() - i);
}
} catch (Throwable th) {
th = th;
try {
x.a(th);
return null;
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (Exception e) {
x.a(e);
}
}
}
}
}
String sb2 = sb.toString();
try {
bufferedReader.close();
} catch (Exception e2) {
x.a(e2);
}
return sb2;
} catch (Throwable th2) {
th = th2;
bufferedReader = null;
}
}
private static BufferedReader a(File file) {
if (file != null && file.exists() && file.canRead()) {
try {
return new BufferedReader(new InputStreamReader(new FileInputStream(file), "utf-8"));
} catch (Throwable th) {
x.a(th);
}
}
return null;
}
public static BufferedReader a(String str, String str2) {
if (str == null) {
return null;
}
try {
File file = new File(str, str2);
if (file.exists() && file.canRead()) {
return a(file);
}
return null;
} catch (NullPointerException e) {
x.a(e);
return null;
}
}
public static Thread a(Runnable runnable, String str) {
try {
Thread thread = new Thread(runnable);
thread.setName(str);
thread.start();
return thread;
} catch (Throwable th) {
x.e("[Util] Failed to start a thread to execute task with message: %s", th.getMessage());
return null;
}
}
public static boolean a(Runnable runnable) {
if (runnable == null) {
return false;
}
w a2 = w.a();
if (a2 != null) {
return a2.a(runnable);
}
String[] split = runnable.getClass().getName().split("\\.");
return a(runnable, split[split.length - 1]) != null;
}
public static SharedPreferences a(String str, Context context) {
if (context != null) {
return context.getSharedPreferences(str, 0);
}
return null;
}
}