正在查看: Clean Center v0.5.5 应用的 NetworkUtils.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Clean Center v0.5.5 应用的 NetworkUtils.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.trustlook.sdk.cloudscan;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
import com.tom_roush.fontbox.ttf.NamingTable;
import com.tom_roush.fontbox.ttf.OpenTypeScript;
import com.trustlook.sdk.Constants;
import com.trustlook.sdk.Utility;
import com.trustlook.sdk.data.AppInfo;
import com.trustlook.sdk.data.DataUtils;
import com.trustlook.sdk.data.PkgInfo;
import com.trustlook.sdk.data.VirusDesc;
import com.trustlook.sdk.database.DBHelper;
import com.trustlook.sdk.database.DBManager;
import com.trustlook.sdk.ngsescan.FileUtils;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class NetworkUtils {
int a;
int b;
Context c;
public NetworkUtils(Context context, int i, int i2) {
this.a = i;
this.b = i2;
this.c = context;
}
private String b(String str, int i, int i2) throws IOException {
HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(str).openConnection();
httpURLConnection.setConnectTimeout(i);
httpURLConnection.setReadTimeout(i2);
httpURLConnection.setRequestProperty("X-TL-APIKEY", CloudUtil.getTrustlookApiKey(this.c));
if (httpURLConnection.getResponseCode() != 200) {
return null;
}
InputStream inputStream = httpURLConnection.getInputStream();
StringBuffer stringBuffer = new StringBuffer();
if (inputStream == null) {
return null;
}
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
while (true) {
String readLine = bufferedReader.readLine();
if (readLine == null) {
break;
}
stringBuffer.append(readLine + "\n");
}
if (stringBuffer.length() == 0) {
inputStream.close();
bufferedReader.close();
return null;
}
String stringBuffer2 = stringBuffer.toString();
inputStream.close();
bufferedReader.close();
return stringBuffer2;
}
private String c(String str, int i, int i2) throws IOException, b {
?? url = new URL(str);
String str2 = null;
int i3 = 0;
try {
try {
url = (HttpURLConnection) url.openConnection();
try {
url.setConnectTimeout(i);
url.setReadTimeout(i2);
url.setRequestProperty("X-TL-APIKEY", CloudUtil.getTrustlookApiKey(this.c));
i3 = url.getResponseCode();
if (i3 == 200) {
if (url.getHeaderField("Cache-Control").contains("=")) {
DataUtils.saveLongValue(this.c, Constants.SDK_INFO_EXPIRE, Long.valueOf(Long.valueOf(System.currentTimeMillis() / 1000).longValue() + Long.valueOf(Integer.valueOf(r12.split("=")[1]).intValue()).longValue()).longValue());
}
InputStream inputStream = url.getInputStream();
StringBuffer stringBuffer = new StringBuffer();
if (inputStream != null) {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
while (true) {
String readLine = bufferedReader.readLine();
if (readLine == null) {
break;
}
stringBuffer.append(readLine + "\n");
}
String stringBuffer2 = stringBuffer.length() == 0 ? null : stringBuffer.toString();
inputStream.close();
bufferedReader.close();
str2 = stringBuffer2;
}
}
url.disconnect();
if (i3 != 200) {
Log.e("TL", "getSdkInfo throw HttpRequestException " + i3);
throw new b(i3);
}
} catch (IOException e) {
e = e;
e.getMessage();
if (url != 0) {
url.disconnect();
}
if (i3 != 200) {
Log.e("TL", "getSdkInfo throw HttpRequestException " + i3);
throw new b(i3);
}
return str2;
} catch (Throwable th) {
th = th;
th.getMessage();
if (url != 0) {
url.disconnect();
}
if (i3 != 200) {
Log.e("TL", "getSdkInfo throw HttpRequestException " + i3);
throw new b(i3);
}
return str2;
}
} catch (Throwable th2) {
if (url != 0) {
url.disconnect();
}
if (i3 == 200) {
throw th2;
}
Log.e("TL", "getSdkInfo throw HttpRequestException " + i3);
throw new b(i3);
}
} catch (IOException e2) {
e = e2;
url = 0;
} catch (Throwable th3) {
th = th3;
url = 0;
}
return str2;
}
public static List<PkgInfo> getPkgInfo(String str, List<PkgInfo> list) {
ArrayList arrayList = new ArrayList();
for (PkgInfo pkgInfo : list) {
if ((pkgInfo.getMd5().substring(0, 3) + pkgInfo.getMd5().substring(15, 17) + pkgInfo.getMd5().substring(29, 32)).equalsIgnoreCase(str)) {
pkgInfo.toString();
arrayList.add(pkgInfo);
}
}
return arrayList;
}
public static boolean isNetworkAvailable(Context context) {
NetworkInfo activeNetworkInfo;
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
return connectivityManager != null && (activeNetworkInfo = connectivityManager.getActiveNetworkInfo()) != null && activeNetworkInfo.isConnected() && activeNetworkInfo.getState() == NetworkInfo.State.CONNECTED;
}
List<AppInfo> a(String str, String str2, List<PkgInfo> list) throws IOException, JSONException, b {
String str3;
int i;
String str4;
String str5;
int i2;
String str6;
String str7;
Iterator<PkgInfo> it;
int i3;
JSONArray optJSONArray;
String str8;
int i4;
int i5;
URL url;
HttpURLConnection httpURLConnection;
int responseCode;
int i6;
BufferedReader bufferedReader;
String str9 = "paymentrisk";
String str10 = "score";
String str11 = "application/json";
String str12 = NamingTable.TAG;
ArrayList arrayList = new ArrayList();
int i7 = this.a;
int i8 = this.b;
URL url2 = new URL(str);
int i9 = 3;
HttpURLConnection httpURLConnection2 = null;
int i10 = 0;
boolean z = false;
while (true) {
if (i9 <= 0) {
str3 = null;
i = i10;
break;
}
int i11 = i9 - 1;
try {
url = url2;
try {
httpURLConnection = (HttpURLConnection) url2.openConnection();
try {
httpURLConnection.setDoOutput(true);
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setRequestProperty("Content-Type", str11);
httpURLConnection.setRequestProperty("Accept", str11);
httpURLConnection.setRequestProperty("X-TL-APIKEY", CloudUtil.getTrustlookApiKey(this.c));
httpURLConnection.setConnectTimeout(i7);
httpURLConnection.setReadTimeout(i8);
str8 = str11;
} catch (IOException e) {
e = e;
str8 = str11;
}
} catch (IOException e2) {
e = e2;
str8 = str11;
i4 = i7;
i5 = i8;
}
try {
i4 = i7;
} catch (IOException e3) {
e = e3;
i4 = i7;
i5 = i8;
httpURLConnection2 = httpURLConnection;
e.getMessage();
i9 = i11;
url2 = url;
str11 = str8;
i7 = i4;
i8 = i5;
z = true;
}
try {
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(httpURLConnection.getOutputStream(), "UTF-8"));
bufferedWriter.write(str2);
bufferedWriter.close();
responseCode = httpURLConnection.getResponseCode();
try {
httpURLConnection.getResponseCode();
httpURLConnection.getResponseMessage();
} catch (IOException e4) {
e = e4;
i6 = responseCode;
}
} catch (IOException e5) {
e = e5;
i5 = i8;
httpURLConnection2 = httpURLConnection;
e.getMessage();
i9 = i11;
url2 = url;
str11 = str8;
i7 = i4;
i8 = i5;
z = true;
}
} catch (IOException e6) {
e = e6;
str8 = str11;
i4 = i7;
i5 = i8;
url = url2;
}
if (responseCode == 200) {
InputStream inputStream = httpURLConnection.getInputStream();
StringBuffer stringBuffer = new StringBuffer();
if (inputStream != null) {
i6 = responseCode;
try {
bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
} catch (IOException e7) {
e = e7;
i5 = i8;
i10 = i6;
httpURLConnection2 = httpURLConnection;
e.getMessage();
i9 = i11;
url2 = url;
str11 = str8;
i7 = i4;
i8 = i5;
z = true;
}
while (true) {
String readLine = bufferedReader.readLine();
if (readLine == null) {
break;
}
i5 = i8;
try {
stringBuffer.append(readLine + "\n");
i8 = i5;
} catch (IOException e8) {
e = e8;
}
e = e8;
i10 = i6;
httpURLConnection2 = httpURLConnection;
e.getMessage();
i9 = i11;
url2 = url;
str11 = str8;
i7 = i4;
i8 = i5;
z = true;
}
i5 = i8;
str3 = stringBuffer.length() == 0 ? null : stringBuffer.toString();
inputStream.close();
bufferedReader.close();
i = i6;
httpURLConnection2 = httpURLConnection;
break;
}
}
i10 = responseCode;
i9 = i11;
str11 = str8;
i7 = i4;
i8 = i8;
httpURLConnection2 = httpURLConnection;
url2 = url;
}
if (httpURLConnection2 != null) {
httpURLConnection2.disconnect();
}
String str13 = "TL";
if (i != 200) {
if (z) {
Log.e("TL", "_postJson2TrustLook timeout " + i);
i = 502;
}
Log.e("TL", "_postJson2TrustLook throw HttpRequestException " + i);
throw new b(i);
}
if (str3 == null) {
return arrayList;
}
Context context = this.c;
HashMap hashMap = new HashMap();
String stringValue = DataUtils.getStringValue(context, Constants.DESC_CONTENT, "");
if (stringValue.equals("")) {
stringValue = FileUtils.getJson(context, "0.json");
}
try {
JSONObject optJSONObject = new JSONObject(stringValue).optJSONObject("desc");
Iterator<String> keys = optJSONObject.keys();
while (keys.hasNext()) {
String next = keys.next();
Iterator<String> it2 = keys;
if (optJSONObject.get(next) instanceof JSONObject) {
JSONObject jSONObject = (JSONObject) optJSONObject.get(next);
if (!jSONObject.isNull(str12)) {
JSONObject jSONObject2 = optJSONObject;
String str14 = str12;
VirusDesc virusDesc = new VirusDesc(jSONObject.isNull(str12) ? OpenTypeScript.UNKNOWN : jSONObject.getString(str12));
virusDesc.setScore(jSONObject.isNull(str10) ? -1 : jSONObject.getInt(str10));
JSONObject jSONObject3 = jSONObject.getJSONObject("desc");
String str15 = str10;
virusDesc.setDescZh(jSONObject3.getString("zh"));
virusDesc.setDescEn(jSONObject3.getString("en"));
JSONObject jSONObject4 = jSONObject.getJSONObject("cat");
virusDesc.setCategoryZh(jSONObject4.getString("zh"));
virusDesc.setCategoryEn(jSONObject4.getString("en"));
hashMap.put(next, virusDesc);
keys = it2;
str12 = str14;
optJSONObject = jSONObject2;
str10 = str15;
}
}
keys = it2;
}
} catch (JSONException e9) {
Log.e("TL", trustlook_cloudscan.c.a("loadDescMap JSONException: ").append(e9.getMessage()).toString());
}
ArrayList arrayList2 = new ArrayList();
ArrayList arrayList3 = new ArrayList();
JSONObject jSONObject5 = new JSONObject(str3);
if (jSONObject5.optInt("cc") == 1) {
DBManager.getInstance(this.c).getDataSource().clearAppInfoCache();
}
JSONArray optJSONArray2 = jSONObject5.optJSONArray("pks");
int i12 = 0;
while (i12 < optJSONArray2.length()) {
JSONObject jSONObject6 = optJSONArray2.getJSONObject(i12);
String string = jSONObject6.getString(DBHelper.COLUMN_MD5);
List<PkgInfo> pkgInfo = getPkgInfo(string, list);
if (pkgInfo != null) {
Iterator<PkgInfo> it3 = pkgInfo.iterator();
while (it3.hasNext()) {
PkgInfo next2 = it3.next();
try {
it = it3;
try {
?? appInfo = new AppInfo(next2.getPkgName(), next2.getMd5());
appInfo.setApkPath(next2.getPkgPath());
str7 = str13;
i3 = i12;
try {
appInfo.setSizeInBytes(next2.getPkgSize());
appInfo.setSystemApp(next2.isSystemApp());
appInfo.setCertSha1(next2.getCertSha1());
appInfo.setAppName(next2.getAppName());
VirusDesc virusDesc2 = (VirusDesc) hashMap.get(Integer.toString(jSONObject6.isNull("vid") ? -1 : jSONObject6.getInt("vid")));
optJSONArray2.length();
next2.getPkgPath();
virusDesc2.getName();
appInfo.setScore(virusDesc2.getScore());
appInfo.setVirusName(virusDesc2.getName());
appInfo.setSummary(new String[]{virusDesc2.getDescZh(), virusDesc2.getDescEn()});
appInfo.setCategory(new String[]{virusDesc2.getCategoryZh(), virusDesc2.getCategoryEn()});
ArrayList arrayList4 = new ArrayList();
if (jSONObject6.isNull(str9) || (optJSONArray = jSONObject6.optJSONArray(str9)) == null) {
str6 = str9;
} else {
str6 = str9;
for (int i13 = 0; i13 < optJSONArray.length(); i13++) {
try {
arrayList4.add(optJSONArray.get(i13).toString());
} catch (Exception e10) {
e = e10;
trustlook_cloudscan.a.a(e, new StringBuilder("parseQueryResult exception for ").append(string).append(" "), str7);
str13 = str7;
i12 = i3;
str9 = str6;
it3 = it;
}
}
}
appInfo.setUpload(!jSONObject6.isNull("up") ? jSONObject6.getBoolean("up") : 0);
appInfo.setDeepScan(!jSONObject6.isNull("dp") ? jSONObject6.getBoolean("dp") : 0);
if (jSONObject6.isNull("mi")) {
arrayList3.add(appInfo);
}
arrayList2.add(appInfo);
} catch (Exception e11) {
e = e11;
str6 = str9;
}
} catch (Exception e12) {
e = e12;
str6 = str9;
str7 = str13;
i3 = i12;
trustlook_cloudscan.a.a(e, new StringBuilder("parseQueryResult exception for ").append(string).append(" "), str7);
str13 = str7;
i12 = i3;
str9 = str6;
it3 = it;
}
} catch (Exception e13) {
e = e13;
str6 = str9;
str7 = str13;
it = it3;
}
str13 = str7;
i12 = i3;
str9 = str6;
it3 = it;
}
str4 = str9;
str5 = str13;
i2 = i12;
} else {
str4 = str9;
str5 = str13;
i2 = i12;
Log.e(str5, "package name not found by md5 =" + string);
}
i12 = i2 + 1;
str13 = str5;
str9 = str4;
}
String str16 = str13;
for (PkgInfo pkgInfo2 : list) {
if (pkgInfo2.isCache()) {
AppInfo appInfo2 = pkgInfo2.toAppInfo();
appInfo2.setScore(1);
appInfo2.setVirusNameCategorySummaryByScore(1);
arrayList2.add(appInfo2);
}
}
for (PkgInfo pkgInfo3 : list) {
String md5 = pkgInfo3.getMd5();
Iterator it4 = arrayList2.iterator();
while (true) {
if (!it4.hasNext()) {
AppInfo appInfo3 = pkgInfo3.toAppInfo();
appInfo3.setScore(1);
appInfo3.setVirusNameCategorySummaryByScore(1);
arrayList2.add(appInfo3);
arrayList3.add(appInfo3);
break;
}
if (((AppInfo) it4.next()).getMd5().equalsIgnoreCase(md5)) {
break;
}
}
}
try {
if (!arrayList3.isEmpty()) {
arrayList3.size();
try {
DBManager.getInstance(this.c).getDataSource().batchInsertCloudScanResult(arrayList3);
} catch (Exception e14) {
e = e14;
Log.w(str16, trustlook_cloudscan.c.a("batchUpdateCloudScanResult exception:").append(e.getMessage()).toString());
return arrayList2;
}
}
} catch (Exception e15) {
e = e15;
}
return arrayList2;
}
public boolean checkSdkInfo(String str) throws b {
if (Long.valueOf(System.currentTimeMillis() / 1000).longValue() < Long.valueOf(DataUtils.getLongValue(this.c, Constants.SDK_INFO_EXPIRE, 0L)).longValue()) {
return true;
}
try {
String c = c(str, this.a, this.b);
if (c == null) {
return false;
}
a(c);
new OfflineDbUtils().updateLocalDb(this.c, c);
c(c);
return true;
} catch (IOException e) {
e.printStackTrace();
trustlook_cloudscan.b.a(e, new StringBuilder().append("checkSdkInfo IOException: "), "TL");
return false;
} catch (JSONException e2) {
Log.e("TL", trustlook_cloudscan.c.a("checkSdkInfo JSONException: ").append(e2.getMessage()).toString());
return false;
}
}
public boolean checkServerHealth(String str) {
for (int i = 3; i > 0; i--) {
try {
} catch (Exception e) {
e.getMessage();
}
if (200 == a(str, this.a, this.b)) {
return true;
}
}
return false;
}
public StringBuffer getRequestData(Map<String, Object> map, String str) throws UnsupportedEncodingException {
StringBuffer stringBuffer = new StringBuffer();
for (Map.Entry<String, Object> entry : map.entrySet()) {
stringBuffer.append(entry.getKey()).append("=").append(URLEncoder.encode(entry.getValue().toString(), str)).append("&");
}
stringBuffer.deleteCharAt(stringBuffer.length() - 1);
return stringBuffer;
}
public boolean missing(String str) throws IOException {
return 200 == a(str, this.a, this.b);
}
public java.util.List<com.trustlook.sdk.urlscan.UrlInfo> queryURL(java.lang.String r6, byte[] r7) throws java.io.IOException, org.json.JSONException, com.trustlook.sdk.cloudscan.a, com.trustlook.sdk.cloudscan.f, com.trustlook.sdk.cloudscan.g, com.trustlook.sdk.cloudscan.c, com.trustlook.sdk.cloudscan.d {
throw new UnsupportedOperationException("Method not decompiled: com.trustlook.sdk.cloudscan.NetworkUtils.queryURL(java.lang.String, byte[]):java.util.List");
}
public int upload2Trustlook(Map<String, String> map, String str, File file, String str2) throws IOException {
if (str == null || str.trim().equals("")) {
str = file.getName();
}
StringBuilder sb = new StringBuilder();
for (String str3 : map.keySet()) {
sb.append("------WebKitFormBoundaryT1HoybnYeFOGFlBR\r\n");
sb.append("Content-Disposition: form-data; name=\"" + str3 + "\"\r\n");
sb.append("\r\n");
sb.append(map.get(str3) + "\r\n");
}
sb.append("------WebKitFormBoundaryT1HoybnYeFOGFlBR\r\n");
sb.append("Content-Disposition: form-data; name=\"file\"; filename=\"" + str + "\"\r\n");
sb.append("Content-Type: application/json\r\n\r\n");
System.out.println(sb.toString());
byte[] bytes = sb.toString().getBytes("UTF-8");
byte[] bytes2 = "\r\n------WebKitFormBoundaryT1HoybnYeFOGFlBR--\r\n".getBytes("UTF-8");
HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(str2).openConnection();
httpURLConnection.setFixedLengthStreamingMode(file.length() + bytes.length + bytes2.length);
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setRequestProperty("Content-Type", "multipart/form-data; boundary=----WebKitFormBoundaryT1HoybnYeFOGFlBR");
httpURLConnection.setRequestProperty("Content-Length", String.valueOf(file.length() + bytes.length + bytes2.length));
httpURLConnection.setRequestProperty("X-TL-APIKEY", CloudUtil.getTrustlookApiKey(this.c));
httpURLConnection.setDoOutput(true);
OutputStream outputStream = httpURLConnection.getOutputStream();
FileInputStream fileInputStream = new FileInputStream(file);
outputStream.write(bytes);
byte[] bArr = new byte[1024];
while (true) {
int read = fileInputStream.read(bArr);
if (read == -1) {
outputStream.write(bytes2);
fileInputStream.close();
outputStream.close();
return httpURLConnection.getResponseCode();
}
outputStream.write(bArr, 0, read);
}
}
private void b(String str) {
if (Utility.isNullOrEmpty(str)) {
return;
}
try {
DataUtils.saveStringValue(this.c, Constants.DESC_VERSION, new JSONObject(str).optString("ver"));
DataUtils.saveStringValue(this.c, Constants.DESC_CONTENT, str);
} catch (JSONException e) {
Log.e("TL", trustlook_cloudscan.c.a("saveDescResult JSONException: ").append(e.getMessage()).toString());
}
}
private void c(String str) throws JSONException {
JSONObject jSONObject;
JSONObject jSONObject2 = new JSONObject(str);
if (jSONObject2.isNull("desc") || (jSONObject = jSONObject2.getJSONObject("desc")) == null) {
return;
}
try {
b(b(jSONObject.getString("url"), this.a, this.b));
} catch (IOException unused) {
}
}
private void a(String str) throws JSONException {
JSONObject jSONObject = new JSONObject(str);
DataUtils.saveStringValue(this.c, Constants.SDK_INFO_API_VERSION, jSONObject.optString("api_version"));
JSONArray jSONArray = new JSONArray();
if (!jSONObject.isNull("stat")) {
jSONArray = jSONObject.optJSONArray("stat");
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < jSONArray.length(); i++) {
sb.append(jSONArray.get(i)).append(",");
}
DataUtils.saveStringValue(this.c, Constants.EXTRA_INFO_FIELD, sb.toString());
DataUtils.saveBooleanValue(this.c, Constants.EXTRA_INFO_SENT, false);
}
private int a(String str, int i, int i2) throws IOException {
HttpURLConnection httpURLConnection;
Throwable th;
try {
httpURLConnection = (HttpURLConnection) new URL(str).openConnection();
try {
httpURLConnection.setConnectTimeout(i);
httpURLConnection.setReadTimeout(i2);
httpURLConnection.setRequestProperty("X-TL-APIKEY", CloudUtil.getTrustlookApiKey(this.c));
int responseCode = httpURLConnection.getResponseCode();
httpURLConnection.disconnect();
return responseCode;
} catch (Throwable th2) {
th = th2;
if (httpURLConnection != null) {
httpURLConnection.disconnect();
}
throw th;
}
} catch (Throwable th3) {
httpURLConnection = null;
th = th3;
}
}
}