正在查看: jsgt v4.8.1 应用的 o0.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: jsgt v4.8.1 应用的 o0.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package qh;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.text.TextUtils;
import com.wind.imlib.db.manager.CommSettingManager;
import com.xiaomi.push.service.g0;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import tv.danmaku.ijk.media.player.IjkMediaMeta;
import tv.danmaku.ijk.media.player.IjkMediaPlayer;
public class o0 {
public static Context h;
public static o0 i;
public static a j;
public static String k;
public final b c;
public final String d;
public static final HashMap g = new HashMap();
public static boolean l = false;
public final HashMap a = new HashMap();
public long e = 0;
public long f = 0;
public final n0 b = new p0();
public interface a {
}
public interface b {
}
public o0(Context context, g0.a aVar, String str, String str2) {
this.d = "0";
this.c = aVar;
this.d = "0";
k = str == null ? context.getPackageName() : str;
if (str2 != null) {
return;
}
try {
h.getPackageManager().getPackageInfo(h.getPackageName(), 16384);
} catch (Exception unused) {
}
}
public static String a() {
NetworkInfo activeNetworkInfo;
Context context = h;
if (context == null) {
return IjkMediaMeta.IJKM_VAL_TYPE__UNKNOWN;
}
try {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
if (connectivityManager == null || (activeNetworkInfo = connectivityManager.getActiveNetworkInfo()) == null) {
return IjkMediaMeta.IJKM_VAL_TYPE__UNKNOWN;
}
if (activeNetworkInfo.getType() == 1) {
return "WIFI-UNKNOWN";
}
return activeNetworkInfo.getTypeName() + "-" + activeNetworkInfo.getSubtypeName();
} catch (Throwable unused) {
return IjkMediaMeta.IJKM_VAL_TYPE__UNKNOWN;
}
}
public static synchronized o0 f() {
o0 o0Var;
synchronized (o0.class) {
o0Var = i;
if (o0Var == null) {
throw new IllegalStateException("the host manager is not initialized yet.");
}
}
return o0Var;
}
public static synchronized void g(Context context, g0.a aVar) {
synchronized (o0.class) {
Context applicationContext = context.getApplicationContext();
h = applicationContext;
if (applicationContext == null) {
h = context;
}
if (i == null) {
if (j == null) {
i = new o0(context, aVar, CommSettingManager.PUSH_KEY, "2.2");
} else {
i = new g0.b(context, aVar);
}
}
}
}
public static synchronized void h(com.xiaomi.push.service.g0 g0Var) {
synchronized (o0.class) {
j = g0Var;
i = null;
}
}
public static void i(String str, String str2) {
HashMap hashMap = g;
k0 k0Var = (k0) hashMap.get(str);
synchronized (hashMap) {
if (k0Var == null) {
k0 k0Var2 = new k0(str);
k0Var2.f(604800000L);
k0Var2.g(str2);
hashMap.put(str, k0Var2);
} else {
k0Var.g(str2);
}
}
}
public static String q() {
Throwable th2;
BufferedInputStream bufferedInputStream;
FileInputStream fileInputStream;
byte[] bArr;
byte[] digest;
try {
File file = new File(h.getFilesDir(), "host_fallbacks");
if (file.isFile()) {
fileInputStream = new FileInputStream(file);
try {
bufferedInputStream = new BufferedInputStream(fileInputStream);
} catch (Throwable th3) {
th2 = th3;
bufferedInputStream = null;
}
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] bArr2 = new byte[8192];
while (true) {
try {
try {
int read = bufferedInputStream.read(bArr2, 0, 8192);
if (read <= 0) {
break;
}
byteArrayOutputStream.write(bArr2, 0, read);
} catch (Exception e) {
e.printStackTrace();
v0.q(bufferedInputStream);
v0.q(byteArrayOutputStream);
bArr = null;
}
} finally {
v0.q(bufferedInputStream);
v0.q(byteArrayOutputStream);
}
}
bArr = byteArrayOutputStream.toByteArray();
String str = h.getPackageName() + "_key_salt";
if (!TextUtils.isEmpty(str)) {
try {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
messageDigest.update(str.getBytes());
digest = messageDigest.digest();
} catch (Exception unused) {
}
String str2 = new String(v0.F(digest, bArr), StandardCharsets.UTF_8);
lh.b.l("load host fallbacks = " + str2);
return str2;
}
digest = null;
String str22 = new String(v0.F(digest, bArr), StandardCharsets.UTF_8);
lh.b.l("load host fallbacks = " + str22);
return str22;
} catch (Throwable th4) {
th2 = th4;
try {
lh.b.d("load host exception " + th2.getMessage());
return null;
} finally {
v0.q(bufferedInputStream);
v0.q(fileInputStream);
}
}
}
} catch (Throwable th5) {
th2 = th5;
bufferedInputStream = null;
fileInputStream = null;
}
return null;
}
public String b(ArrayList arrayList, String str, String str2) {
ArrayList<String> arrayList2 = new ArrayList<>();
ArrayList arrayList3 = new ArrayList();
arrayList3.add(new u("type", str));
if (str.equals("wap")) {
String b2 = x.b(h);
try {
int length = b2.length();
byte[] bytes = b2.getBytes("UTF-8");
for (int i2 = 0; i2 < bytes.length; i2++) {
byte b3 = bytes[i2];
int i3 = b3 & 240;
if (i3 != 240) {
bytes[i2] = (byte) (((b3 & 15) ^ ((byte) (((b3 >> 4) + length) & 15))) | i3);
}
}
b2 = new String(bytes);
} catch (UnsupportedEncodingException unused) {
}
arrayList3.add(new u("conpt", b2));
}
arrayList3.add(new u("reserved", "1"));
arrayList3.add(new u("uuid", str2));
arrayList3.add(new u("list", ne.c.s(arrayList)));
com.xiaomi.push.service.b a2 = com.xiaomi.push.service.b.a(h);
if (TextUtils.isEmpty(a2.d)) {
a2.d = com.xiaomi.push.service.b.c(a2.e, "mipush_country_code", "mipush_country_code.lock", a2.b);
}
arrayList3.add(new u("countrycode", a2.d));
arrayList3.add(new u("push_sdk_vc", String.valueOf(50300)));
k0 o = o("resolver.msg.xiaomi.net");
String format = String.format(Locale.US, "https://%1$s/gslb/?ver=5.0", "resolver.msg.xiaomi.net");
if (o == null) {
arrayList2.add(format);
HashMap hashMap = g;
synchronized (hashMap) {
k0 k0Var = (k0) hashMap.get("resolver.msg.xiaomi.net");
if (k0Var != null) {
Iterator<String> it2 = k0Var.d(true).iterator();
while (it2.hasNext()) {
arrayList2.add(String.format(Locale.US, "https://%1$s/gslb/?ver=5.0", it2.next()));
}
}
}
} else {
arrayList2 = o.c(format);
}
Iterator<String> it3 = arrayList2.iterator();
IOException e = null;
while (it3.hasNext()) {
Uri.Builder buildUpon = Uri.parse(it3.next()).buildUpon();
Iterator it4 = arrayList3.iterator();
while (it4.hasNext()) {
w wVar = (w) it4.next();
buildUpon.appendQueryParameter(wVar.a(), wVar.b());
}
try {
b bVar = this.c;
return bVar == null ? x.c(h, new URL(buildUpon.toString())) : ((g0.a) bVar).a(buildUpon.toString());
} catch (IOException e2) {
e = e2;
}
}
if (e == null) {
return null;
}
lh.b.d("network exception: " + e.getMessage());
throw e;
}
public final ArrayList<k0> c(ArrayList<String> arrayList) {
JSONObject jSONObject;
JSONObject jSONObject2;
r();
synchronized (this.a) {
k();
for (String str : this.a.keySet()) {
if (!arrayList.contains(str)) {
arrayList.add(str);
}
}
}
HashMap hashMap = g;
synchronized (hashMap) {
for (Object obj : hashMap.values().toArray()) {
k0 k0Var = (k0) obj;
if (!k0Var.k()) {
g.remove(k0Var.d);
}
}
}
if (!arrayList.contains("resolver.msg.xiaomi.net")) {
arrayList.add("resolver.msg.xiaomi.net");
}
ArrayList<k0> arrayList2 = new ArrayList<>(arrayList.size());
for (int i2 = 0; i2 < arrayList.size(); i2++) {
arrayList2.add(null);
}
try {
String str2 = x.k(h) ? "wifi" : "wap";
String b2 = b(arrayList, str2, this.d);
if (!TextUtils.isEmpty(b2)) {
JSONObject jSONObject3 = new JSONObject(b2);
lh.b.l(b2);
if ("OK".equalsIgnoreCase(jSONObject3.getString("S"))) {
JSONObject jSONObject4 = jSONObject3.getJSONObject("R");
String string = jSONObject4.getString("province");
String string2 = jSONObject4.getString("city");
String string3 = jSONObject4.getString("isp");
String string4 = jSONObject4.getString(IjkMediaPlayer.OnNativeInvokeListener.ARG_IP);
String string5 = jSONObject4.getString("country");
JSONObject jSONObject5 = jSONObject4.getJSONObject(str2);
lh.b.n("get bucket: net=" + string3 + ", hosts=" + jSONObject5.toString());
int i3 = 0;
while (i3 < arrayList.size()) {
String str3 = arrayList.get(i3);
JSONArray optJSONArray = jSONObject5.optJSONArray(str3);
if (optJSONArray == null) {
lh.b.d("no bucket found for " + str3);
jSONObject = jSONObject5;
} else {
k0 k0Var2 = new k0(str3);
int i4 = 0;
while (i4 < optJSONArray.length()) {
String string6 = optJSONArray.getString(i4);
if (TextUtils.isEmpty(string6)) {
jSONObject2 = jSONObject5;
} else {
jSONObject2 = jSONObject5;
k0Var2.j(new t0(string6, optJSONArray.length() - i4));
}
i4++;
jSONObject5 = jSONObject2;
}
jSONObject = jSONObject5;
arrayList2.set(i3, k0Var2);
k0Var2.i = string5;
k0Var2.e = string;
k0Var2.g = string3;
k0Var2.h = string4;
k0Var2.f = string2;
if (jSONObject4.has("stat-percent")) {
k0Var2.l = jSONObject4.getDouble("stat-percent");
}
if (jSONObject4.has("stat-domain")) {
jSONObject4.getString("stat-domain");
}
if (jSONObject4.has("ttl")) {
k0Var2.f(jSONObject4.getInt("ttl") * 1000);
}
k0Var2.a();
}
i3++;
jSONObject5 = jSONObject;
}
JSONObject optJSONObject = jSONObject4.optJSONObject("reserved");
if (optJSONObject != null) {
long j2 = jSONObject4.has("reserved-ttl") ? jSONObject4.getInt("reserved-ttl") * 1000 : 604800000L;
Iterator<String> keys = optJSONObject.keys();
while (keys.hasNext()) {
String next = keys.next();
JSONArray optJSONArray2 = optJSONObject.optJSONArray(next);
if (optJSONArray2 == null) {
lh.b.d("no bucket found for " + next);
} else {
k0 k0Var3 = new k0(next);
k0Var3.f(j2);
for (int i5 = 0; i5 < optJSONArray2.length(); i5++) {
String string7 = optJSONArray2.getString(i5);
if (!TextUtils.isEmpty(string7)) {
k0Var3.j(new t0(string7, optJSONArray2.length() - i5));
}
}
HashMap hashMap2 = g;
synchronized (hashMap2) {
this.b.getClass();
hashMap2.put(next, k0Var3);
}
}
}
}
}
}
} catch (Exception e) {
lh.b.d("failed to get bucket " + e.getMessage());
}
for (int i6 = 0; i6 < arrayList.size(); i6++) {
k0 k0Var4 = arrayList2.get(i6);
if (k0Var4 != null) {
j(arrayList.get(i6), k0Var4);
}
}
p();
return arrayList2;
}
public final JSONObject d() {
JSONObject jSONObject;
synchronized (this.a) {
jSONObject = new JSONObject();
jSONObject.put("ver", 2);
JSONArray jSONArray = new JSONArray();
Iterator it2 = this.a.values().iterator();
while (it2.hasNext()) {
jSONArray.put(((l0) it2.next()).a());
}
jSONObject.put("data", jSONArray);
JSONArray jSONArray2 = new JSONArray();
Iterator it3 = g.values().iterator();
while (it3.hasNext()) {
jSONArray2.put(((k0) it3.next()).e());
}
jSONObject.put("reserved", jSONArray2);
}
return jSONObject;
}
public final qh.k0 e(java.lang.String r9, boolean r10) {
throw new UnsupportedOperationException("Method not decompiled: qh.o0.e(java.lang.String, boolean):qh.k0");
}
public final void j(String str, k0 k0Var) {
if (TextUtils.isEmpty(str) || k0Var == null) {
throw new IllegalArgumentException("the argument is invalid " + str + ", " + k0Var);
}
this.b.getClass();
synchronized (this.a) {
k();
if (this.a.containsKey(str)) {
((l0) this.a.get(str)).e(k0Var);
} else {
l0 l0Var = new l0(str);
l0Var.e(k0Var);
this.a.put(str, l0Var);
}
}
}
public final void k() {
synchronized (this.a) {
if (l) {
return;
}
l = true;
this.a.clear();
try {
String q = q();
if (!TextUtils.isEmpty(q)) {
m(q);
lh.b.l("loading the new hosts succeed");
}
} catch (Throwable th2) {
lh.b.d("load bucket failure: " + th2.getMessage());
}
}
}
public final void l() {
ArrayList<String> arrayList;
synchronized (this.a) {
k();
arrayList = new ArrayList<>(this.a.keySet());
int size = arrayList.size();
while (true) {
size--;
if (size < 0) {
break;
}
l0 l0Var = (l0) this.a.get(arrayList.get(size));
if (l0Var != null && l0Var.b() != null) {
arrayList.remove(size);
}
}
}
ArrayList<k0> c = c(arrayList);
for (int i2 = 0; i2 < arrayList.size(); i2++) {
if (c.get(i2) != null) {
j(arrayList.get(i2), c.get(i2));
}
}
}
public final void m(String str) {
synchronized (this.a) {
this.a.clear();
JSONObject jSONObject = new JSONObject(str);
if (jSONObject.optInt("ver") != 2) {
throw new JSONException("Bad version");
}
JSONArray optJSONArray = jSONObject.optJSONArray("data");
if (optJSONArray != null) {
for (int i2 = 0; i2 < optJSONArray.length(); i2++) {
l0 l0Var = new l0();
l0Var.d(optJSONArray.getJSONObject(i2));
this.a.put(l0Var.a, l0Var);
}
}
JSONArray optJSONArray2 = jSONObject.optJSONArray("reserved");
if (optJSONArray2 != null) {
for (int i3 = 0; i3 < optJSONArray2.length(); i3++) {
JSONObject jSONObject2 = optJSONArray2.getJSONObject(i3);
String optString = jSONObject2.optString("host");
if (!TextUtils.isEmpty(optString)) {
try {
k0 k0Var = new k0(optString);
k0Var.i(jSONObject2);
g.put(k0Var.d, k0Var);
lh.b.d("load local reserved host for " + k0Var.d);
} catch (JSONException unused) {
lh.b.d("parse reserved host fail.");
}
}
}
}
}
}
public final String n() {
StringBuilder sb = new StringBuilder();
synchronized (this.a) {
for (Map.Entry entry : this.a.entrySet()) {
sb.append((String) entry.getKey());
sb.append(":\n");
sb.append(((l0) entry.getValue()).toString());
sb.append("\n");
}
}
return sb.toString();
}
public final k0 o(String str) {
l0 l0Var;
k0 b2;
synchronized (this.a) {
k();
l0Var = (l0) this.a.get(str);
}
if (l0Var == null || (b2 = l0Var.b()) == null) {
return null;
}
return b2;
}
public final void p() {
Throwable th2;
FileOutputStream fileOutputStream;
BufferedOutputStream bufferedOutputStream;
Exception e;
synchronized (this.a) {
BufferedOutputStream bufferedOutputStream2 = null;
r3 = null;
byte[] digest = null;
bufferedOutputStream2 = null;
BufferedOutputStream bufferedOutputStream3 = null;
try {
String jSONObject = d().toString();
lh.b.l("persist host fallbacks = " + jSONObject);
if (TextUtils.isEmpty(jSONObject)) {
fileOutputStream = null;
} else {
fileOutputStream = h.openFileOutput("host_fallbacks", 0);
try {
bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
try {
try {
String str = h.getPackageName() + "_key_salt";
if (!TextUtils.isEmpty(str)) {
try {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
messageDigest.update(str.getBytes());
digest = messageDigest.digest();
} catch (Exception unused) {
}
}
byte[] bytes = jSONObject.getBytes(StandardCharsets.UTF_8);
SecretKeySpec secretKeySpec = new SecretKeySpec(digest, "AES");
IvParameterSpec ivParameterSpec = new IvParameterSpec(v0.A);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(1, secretKeySpec, ivParameterSpec);
bufferedOutputStream.write(cipher.doFinal(bytes));
bufferedOutputStream.flush();
bufferedOutputStream3 = bufferedOutputStream;
} catch (Exception e2) {
e = e2;
lh.b.d("persist bucket failure: " + e.getMessage());
v0.q(bufferedOutputStream);
v0.q(fileOutputStream);
}
} catch (Throwable th3) {
th2 = th3;
bufferedOutputStream2 = bufferedOutputStream;
v0.q(bufferedOutputStream2);
v0.q(fileOutputStream);
throw th2;
}
} catch (Exception e3) {
bufferedOutputStream = null;
e = e3;
} catch (Throwable th4) {
th2 = th4;
v0.q(bufferedOutputStream2);
v0.q(fileOutputStream);
throw th2;
}
}
v0.q(bufferedOutputStream3);
} catch (Exception e4) {
bufferedOutputStream = null;
e = e4;
fileOutputStream = null;
} catch (Throwable th5) {
th2 = th5;
fileOutputStream = null;
}
v0.q(fileOutputStream);
}
}
public final void r() {
synchronized (this.a) {
Iterator it2 = this.a.values().iterator();
while (it2.hasNext()) {
((l0) it2.next()).c();
}
while (true) {
for (boolean z = false; !z; z = true) {
for (String str : this.a.keySet()) {
if (((l0) this.a.get(str)).b.isEmpty()) {
break;
}
}
}
this.a.remove(str);
}
}
}
}