277 lines
9.6 KiB
Java
277 lines
9.6 KiB
Java
package com.unity3d.ads.misc;
|
|
|
|
import android.os.Handler;
|
|
import android.os.Looper;
|
|
import com.ubt.jimu.base.util.FileUtil;
|
|
import com.unity3d.ads.log.DeviceLog;
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.security.MessageDigest;
|
|
import java.security.NoSuchAlgorithmException;
|
|
import java.util.Iterator;
|
|
import org.json.JSONException;
|
|
import org.json.JSONObject;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class Utilities {
|
|
public static String Sha256(String str) {
|
|
return Sha256(str.getBytes());
|
|
}
|
|
|
|
public static JSONObject mergeJsonObjects(JSONObject jSONObject, JSONObject jSONObject2) throws JSONException {
|
|
if (jSONObject == null) {
|
|
return jSONObject2;
|
|
}
|
|
if (jSONObject2 == null) {
|
|
return jSONObject;
|
|
}
|
|
JSONObject jSONObject3 = new JSONObject();
|
|
Iterator<String> keys = jSONObject2.keys();
|
|
while (keys.hasNext()) {
|
|
String next = keys.next();
|
|
jSONObject3.put(next, jSONObject2.get(next));
|
|
}
|
|
Iterator<String> keys2 = jSONObject.keys();
|
|
while (keys2.hasNext()) {
|
|
String next2 = keys2.next();
|
|
if (jSONObject3.has(next2) && (jSONObject3.get(next2) instanceof JSONObject) && (jSONObject.get(next2) instanceof JSONObject)) {
|
|
jSONObject3.put(next2, mergeJsonObjects(jSONObject.getJSONObject(next2), jSONObject3.getJSONObject(next2)));
|
|
} else {
|
|
jSONObject3.put(next2, jSONObject.get(next2));
|
|
}
|
|
}
|
|
return jSONObject3;
|
|
}
|
|
|
|
/* JADX WARN: Removed duplicated region for block: B:24:0x0044 A[EXC_TOP_SPLITTER, SYNTHETIC] */
|
|
/* JADX WARN: Removed duplicated region for block: B:29:0x0038 A[EXC_TOP_SPLITTER, SYNTHETIC] */
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
To view partially-correct code enable 'Show inconsistent code' option in preferences
|
|
*/
|
|
public static java.lang.String readFile(java.io.File r4) {
|
|
/*
|
|
r0 = 0
|
|
if (r4 != 0) goto L4
|
|
return r0
|
|
L4:
|
|
boolean r1 = r4.exists()
|
|
if (r1 == 0) goto L4f
|
|
boolean r1 = r4.canRead()
|
|
if (r1 == 0) goto L4f
|
|
java.io.FileReader r1 = new java.io.FileReader // Catch: java.lang.Exception -> L2e
|
|
r1.<init>(r4) // Catch: java.lang.Exception -> L2e
|
|
java.io.BufferedReader r4 = new java.io.BufferedReader // Catch: java.lang.Exception -> L2b
|
|
r4.<init>(r1) // Catch: java.lang.Exception -> L2b
|
|
java.lang.String r2 = ""
|
|
L1c:
|
|
java.lang.String r3 = r4.readLine() // Catch: java.lang.Exception -> L29
|
|
if (r3 == 0) goto L27
|
|
java.lang.String r2 = r2.concat(r3) // Catch: java.lang.Exception -> L29
|
|
goto L1c
|
|
L27:
|
|
r0 = r2
|
|
goto L36
|
|
L29:
|
|
r2 = move-exception
|
|
goto L31
|
|
L2b:
|
|
r2 = move-exception
|
|
r4 = r0
|
|
goto L31
|
|
L2e:
|
|
r2 = move-exception
|
|
r4 = r0
|
|
r1 = r4
|
|
L31:
|
|
java.lang.String r3 = "Problem reading file"
|
|
com.unity3d.ads.log.DeviceLog.exception(r3, r2)
|
|
L36:
|
|
if (r4 == 0) goto L42
|
|
r4.close() // Catch: java.lang.Exception -> L3c
|
|
goto L42
|
|
L3c:
|
|
r4 = move-exception
|
|
java.lang.String r2 = "Couldn't close BufferedReader"
|
|
com.unity3d.ads.log.DeviceLog.exception(r2, r4)
|
|
L42:
|
|
if (r1 == 0) goto L4e
|
|
r1.close() // Catch: java.lang.Exception -> L48
|
|
goto L4e
|
|
L48:
|
|
r4 = move-exception
|
|
java.lang.String r1 = "Couldn't close FileReader"
|
|
com.unity3d.ads.log.DeviceLog.exception(r1, r4)
|
|
L4e:
|
|
return r0
|
|
L4f:
|
|
java.lang.String r4 = "File did not exist or couldn't be read"
|
|
com.unity3d.ads.log.DeviceLog.error(r4)
|
|
return r0
|
|
*/
|
|
throw new UnsupportedOperationException("Method not decompiled: com.unity3d.ads.misc.Utilities.readFile(java.io.File):java.lang.String");
|
|
}
|
|
|
|
public static byte[] readFileBytes(File file) throws IOException {
|
|
if (file == null) {
|
|
return null;
|
|
}
|
|
FileInputStream fileInputStream = new FileInputStream(file);
|
|
byte[] bArr = new byte[(int) file.length()];
|
|
int i = 0;
|
|
int i2 = FileUtil.ZIP_BUFFER_SIZE;
|
|
long length = file.length();
|
|
long j = FileUtil.ZIP_BUFFER_SIZE;
|
|
if (length < j) {
|
|
i2 = (int) file.length();
|
|
}
|
|
while (true) {
|
|
int read = fileInputStream.read(bArr, i, i2);
|
|
if (read <= 0) {
|
|
fileInputStream.close();
|
|
return bArr;
|
|
}
|
|
i += read;
|
|
if (file.length() - i < j) {
|
|
i2 = ((int) file.length()) - i;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void runOnUiThread(Runnable runnable) {
|
|
runOnUiThread(runnable, 0L);
|
|
}
|
|
|
|
public static String toHexString(byte[] bArr) {
|
|
String str = "";
|
|
for (byte b : bArr) {
|
|
int i = b & 255;
|
|
if (i <= 15) {
|
|
str = str + "0";
|
|
}
|
|
str = str + Integer.toHexString(i);
|
|
}
|
|
return str;
|
|
}
|
|
|
|
/* JADX WARN: Removed duplicated region for block: B:15:0x003b */
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
To view partially-correct code enable 'Show inconsistent code' option in preferences
|
|
*/
|
|
public static boolean writeFile(java.io.File r5, java.lang.String r6) {
|
|
/*
|
|
java.lang.String r0 = "Error closing FileOutputStream"
|
|
r1 = 0
|
|
if (r5 != 0) goto L6
|
|
return r1
|
|
L6:
|
|
r2 = 0
|
|
r3 = 1
|
|
java.io.FileOutputStream r4 = new java.io.FileOutputStream // Catch: java.lang.Throwable -> L27 java.lang.Exception -> L29
|
|
r4.<init>(r5) // Catch: java.lang.Throwable -> L27 java.lang.Exception -> L29
|
|
byte[] r6 = r6.getBytes() // Catch: java.lang.Throwable -> L21 java.lang.Exception -> L24
|
|
r4.write(r6) // Catch: java.lang.Throwable -> L21 java.lang.Exception -> L24
|
|
r4.flush() // Catch: java.lang.Throwable -> L21 java.lang.Exception -> L24
|
|
r4.close() // Catch: java.lang.Exception -> L1b
|
|
goto L1f
|
|
L1b:
|
|
r6 = move-exception
|
|
com.unity3d.ads.log.DeviceLog.exception(r0, r6)
|
|
L1f:
|
|
r1 = 1
|
|
goto L39
|
|
L21:
|
|
r5 = move-exception
|
|
r2 = r4
|
|
goto L54
|
|
L24:
|
|
r6 = move-exception
|
|
r2 = r4
|
|
goto L2a
|
|
L27:
|
|
r5 = move-exception
|
|
goto L54
|
|
L29:
|
|
r6 = move-exception
|
|
L2a:
|
|
java.lang.String r3 = "Could not write file"
|
|
com.unity3d.ads.log.DeviceLog.exception(r3, r6) // Catch: java.lang.Throwable -> L27
|
|
if (r2 == 0) goto L39
|
|
r2.close() // Catch: java.lang.Exception -> L35
|
|
goto L39
|
|
L35:
|
|
r6 = move-exception
|
|
com.unity3d.ads.log.DeviceLog.exception(r0, r6)
|
|
L39:
|
|
if (r1 == 0) goto L53
|
|
java.lang.StringBuilder r6 = new java.lang.StringBuilder
|
|
r6.<init>()
|
|
java.lang.String r0 = "Wrote file: "
|
|
r6.append(r0)
|
|
java.lang.String r5 = r5.getAbsolutePath()
|
|
r6.append(r5)
|
|
java.lang.String r5 = r6.toString()
|
|
com.unity3d.ads.log.DeviceLog.debug(r5)
|
|
L53:
|
|
return r1
|
|
L54:
|
|
if (r2 == 0) goto L5e
|
|
r2.close() // Catch: java.lang.Exception -> L5a
|
|
goto L5e
|
|
L5a:
|
|
r6 = move-exception
|
|
com.unity3d.ads.log.DeviceLog.exception(r0, r6)
|
|
L5e:
|
|
throw r5
|
|
*/
|
|
throw new UnsupportedOperationException("Method not decompiled: com.unity3d.ads.misc.Utilities.writeFile(java.io.File, java.lang.String):boolean");
|
|
}
|
|
|
|
public static String Sha256(byte[] bArr) {
|
|
if (bArr == null) {
|
|
return null;
|
|
}
|
|
try {
|
|
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
|
|
messageDigest.update(bArr, 0, bArr.length);
|
|
return toHexString(messageDigest.digest());
|
|
} catch (NoSuchAlgorithmException e) {
|
|
DeviceLog.exception("SHA-256 algorithm not found", e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static void runOnUiThread(Runnable runnable, long j) {
|
|
Handler handler = new Handler(Looper.getMainLooper());
|
|
if (j > 0) {
|
|
handler.postDelayed(runnable, j);
|
|
} else {
|
|
handler.post(runnable);
|
|
}
|
|
}
|
|
|
|
public static String Sha256(InputStream inputStream) throws IOException {
|
|
if (inputStream == null) {
|
|
return null;
|
|
}
|
|
try {
|
|
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
|
|
byte[] bArr = new byte[FileUtil.ZIP_BUFFER_SIZE];
|
|
while (true) {
|
|
int read = inputStream.read(bArr);
|
|
if (read != -1) {
|
|
messageDigest.update(bArr, 0, read);
|
|
} else {
|
|
return toHexString(messageDigest.digest());
|
|
}
|
|
}
|
|
} catch (NoSuchAlgorithmException e) {
|
|
DeviceLog.exception("SHA-256 algorithm not found", e);
|
|
return null;
|
|
}
|
|
}
|
|
}
|