360手机助手 v3.3.0版本的 MD5 值为:127c345ad16bbebee6e347381328afd0
以下内容为反编译后的 RootMan.java 源代码,内容仅作参考
package com.qihoo.permmgr;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Process;
import android.os.SystemProperties;
import android.text.TextUtils;
import android.util.Log;
import com.qihoo.permmgr.util.AESUtils;
import com.qihoo.rtservice.TempRoot;
import com.qihoo.speedometer.Config;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class RootMan {
private static Context f4660b;
private static RootMan c;
String f4661a;
private boolean d = false;
private RootMan() {
}
private int a(SharedPreferences sharedPreferences) {
j[] b2 = b(sharedPreferences);
int i = TempRoot.ROOT_FAILED_OTHER;
int i2 = 0;
while (true) {
if (i2 >= b2.length) {
sharedPreferences.edit().putInt("fail_donum", sharedPreferences.getInt("fail_donum", 0) + 1).commit();
com.qihoo.permmgr.util.e.a("num----" + sharedPreferences.getInt("fail_donum", 0));
break;
}
j jVar = b2[i2];
String trim = sharedPreferences.getString("crashList", Config.INVALID_IP).trim();
if (!TextUtils.isEmpty(trim)) {
trim.split(";");
}
if (trim.contains(jVar.c())) {
i = TempRoot.ROOT_FAILED_SOLUTION_CRASH_BEFORE_SO_IGNORE;
} else {
sharedPreferences.edit().putString("currentSolutionId", jVar.c()).commit();
i = a(b2[i2]);
if (i == 3000) {
sharedPreferences.edit().putString("successSolution", jVar.c()).commit();
break;
}
}
i2++;
}
return i;
}
private int a(j jVar) {
String str;
String str2 = String.valueOf(PermService.mPermmgrRootDir) + System.currentTimeMillis() + ".so";
StringBuilder sb = new StringBuilder(String.valueOf(PermService.mPermmgrRootDir));
str = jVar.d;
com.qihoo.permmgr.util.c.a(sb.append(str).toString(), str2);
int a2 = a(str2, jVar);
File file = new File(str2);
if (file.exists()) {
file.delete();
}
return a2;
}
public static RootMan a(Context context) {
f4660b = context;
if (c == null) {
c = new RootMan();
}
return c;
}
private File a(String str, InputStream inputStream) {
FileOutputStream fileOutputStream = null;
try {
File file = new File(str);
try {
file.createNewFile();
} catch (Exception e) {
if (b.f4664a) {
e.printStackTrace();
}
}
FileOutputStream fileOutputStream2 = new FileOutputStream(file);
try {
byte[] bArr = new byte[4096];
while (true) {
int read = inputStream.read(bArr);
if (read == -1) {
break;
}
fileOutputStream2.write(bArr, 0, read);
}
fileOutputStream2.flush();
try {
fileOutputStream2.close();
} catch (Exception e2) {
if (b.f4664a) {
e2.printStackTrace();
}
}
return file;
} catch (Throwable th) {
th = th;
fileOutputStream = fileOutputStream2;
try {
fileOutputStream.close();
} catch (Exception e3) {
if (b.f4664a) {
e3.printStackTrace();
}
}
throw th;
}
} catch (Throwable th2) {
th = th2;
fileOutputStream.close();
throw th;
}
}
private int b() {
SharedPreferences sharedPreferences = f4660b.getSharedPreferences("permmgr", 0);
com.qihoo.permmgr.util.e.a("retryFailSolution----" + sharedPreferences.getString("fail_solutions", Config.INVALID_IP));
if (sharedPreferences.getInt("fail_donum", 0) < 2) {
return a(sharedPreferences);
}
if (System.currentTimeMillis() - sharedPreferences.getLong("last3016time", 0L) <= 3600000) {
return TempRoot.ROOT_FAILED_SOLUTION_IS_OLD;
}
if (sharedPreferences.getLong("last3016time", 0L) != 0) {
sharedPreferences.edit().putInt("fail_donum", 0).commit();
}
sharedPreferences.edit().putLong("last3016time", System.currentTimeMillis()).commit();
return a(sharedPreferences);
}
private boolean b(c cVar) {
if (cVar == null) {
return false;
}
for (int i = 0; i < 10; i++) {
try {
if (cVar.onCheckRootServerExist()) {
return true;
}
} catch (Exception e) {
if (b.f4664a) {
e.printStackTrace();
}
}
try {
try {
Thread.sleep(1000L);
} catch (InterruptedException e2) {
}
} catch (Exception e3) {
return false;
}
}
return false;
}
private j[] b(SharedPreferences sharedPreferences) {
String string = sharedPreferences.getString("fail_solutions", Config.INVALID_IP);
return TextUtils.isEmpty(string) ? new j[0] : c(string);
}
private j[] b(String str) {
j[] jVarArr = null;
if (b.f4664a) {
Log.d("MyLog", "start download url:" + str);
}
HttpGet httpGet = new HttpGet(str);
DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
defaultHttpClient.getParams().setParameter("http.connection.timeout", 10000);
defaultHttpClient.getParams().setParameter("http.socket.timeout", 10000);
HttpResponse execute = defaultHttpClient.execute(httpGet);
String b2 = AESUtils.b(200 == execute.getStatusLine().getStatusCode() ? EntityUtils.toString(execute.getEntity()) : null);
if (b.f4664a) {
Log.d("MyLog", "download url result:" + b2);
}
if (!TextUtils.isEmpty(b2)) {
SharedPreferences sharedPreferences = f4660b.getSharedPreferences("permmgr", 0);
this.f4661a = sharedPreferences.getString("solutions_md5", Config.INVALID_IP);
String a2 = com.qihoo.permmgr.util.f.a(b2);
if (TextUtils.isEmpty(this.f4661a)) {
this.f4661a = a2;
} else {
if (this.f4661a.equals(a2)) {
throw new k();
}
this.f4661a = a2;
}
jVarArr = c(b2);
sharedPreferences.edit().putString("fail_solutions", b2).commit();
if (b.f4664a) {
Log.d(b.f4665b, "end download file");
}
}
return jVarArr;
}
private void c() {
for (j jVar : b(f4660b.getSharedPreferences("permmgr", 0))) {
File file = new File(String.valueOf(PermService.mPermmgrRootDir) + jVar.c());
if (file.exists()) {
file.delete();
}
}
}
private j[] c(String str) {
if (TextUtils.isEmpty(str)) {
return null;
}
JSONArray jSONArray = new JSONArray(str);
j[] jVarArr = new j[jSONArray.length()];
int i = 0;
while (true) {
int i2 = i;
if (i2 >= jSONArray.length()) {
return jVarArr;
}
JSONObject jSONObject = jSONArray.getJSONObject(i2);
jVarArr[i2] = new j(this, jSONObject.getString("solution"), jSONObject.getString("solution_md5"), jSONObject.getString("planid"), jSONObject.getString("note"));
i = i2 + 1;
}
}
private String d() {
String str;
String str2 = SystemProperties.get("ro.build.version.release");
if (TextUtils.isEmpty(str2)) {
str2 = "unknow";
}
String str3 = Build.MODEL;
if (TextUtils.isEmpty(str3)) {
str3 = "unknow";
}
if (TextUtils.isEmpty(SystemProperties.get("ro.product.manufacturer"))) {
}
if (TextUtils.isEmpty(SystemProperties.get("ro.mtk.hardware"))) {
str = SystemProperties.get("ro.board.platform");
if (TextUtils.isEmpty(str)) {
str = SystemProperties.get("ro.hardware");
}
} else {
str = "mtk";
}
if (TextUtils.isEmpty(str)) {
str = "unknow";
}
str.trim();
String a2 = com.qihoo.permmgr.util.k.a(f4660b);
String a3 = com.qihoo.permmgr.util.f.a(a2);
if (TextUtils.isEmpty(a2)) {
a3 = "unknow";
}
String str4 = "unknow";
try {
str4 = com.qihoo.permmgr.util.b.a(new File("/"), "cat", "/proc/version").split(" ")[2];
} catch (Exception e) {
}
SharedPreferences sharedPreferences = f4660b.getSharedPreferences("permmgr", 0);
boolean z = sharedPreferences.getBoolean("isNew", true);
if (z) {
sharedPreferences.edit().putBoolean("isNew", false).commit();
}
int i = z ? 1 : 0;
String str5 = "model=" + URLEncoder.encode(str3) + "&target=1&buildno=" + URLEncoder.encode(str4) + "&version=" + URLEncoder.encode(str2) + "&platform=" + URLEncoder.encode(str);
if (b.f4664a) {
Log.d(b.f4665b, "url :" + str5);
}
return "http://api.shuaji.360.cn/c/getSolution?" + str5 + "&pkg=" + a.e + "&mid=" + URLEncoder.encode(a3) + "&new=" + i + "&src=1";
}
private native int jmain(int i);
private native void junmain(Class cls);
public int a(c cVar) {
String str;
boolean z;
int i = TempRoot.ROOT_FAILED_DOWNLOAD_URL_ERROR;
int i2 = 0;
this.d = true;
if (b.f4664a) {
Log.d(b.f4665b, "start do root : online");
}
try {
j[] b2 = b(d());
c();
if (b2 != null && b2.length != 0) {
SharedPreferences sharedPreferences = f4660b.getSharedPreferences("permmgr", 0);
String trim = sharedPreferences.getString("crashList", Config.INVALID_IP).trim();
if (b.f4664a) {
Log.d(b.f4665b, "crash list " + trim);
}
String[] split = TextUtils.isEmpty(trim) ? null : trim.split(";");
ArrayList arrayList = new ArrayList();
int i3 = 3008;
int i4 = 0;
while (true) {
if (i4 >= b2.length) {
i = i3;
break;
}
if (split != null) {
int length = split.length;
int i5 = 0;
while (true) {
if (i5 >= length) {
z = false;
break;
}
if (split[i5].equals(b2[i4].c())) {
i3 = TempRoot.ROOT_FAILED_SOLUTION_CRASH_BEFORE_SO_IGNORE;
com.qihoo.permmgr.util.e.b("3__" + TempRoot.ROOT_FAILED_SOLUTION_CRASH_BEFORE_SO_IGNORE + "_" + b2[i4].c(), new File(PermManager.logFilePath));
z = true;
break;
}
i5++;
}
if (z) {
HashMap hashMap = new HashMap();
hashMap.put("plainId", b2[i4].c());
hashMap.put("returnCode", Integer.valueOf(i3));
arrayList.add(hashMap);
i4++;
}
}
if (TextUtils.isEmpty(b2[i4].a()) || b2[i4].a().endsWith(".so")) {
String c2 = b2[i4].c();
String str2 = String.valueOf(f4660b.getFilesDir().getAbsolutePath()) + "/permmgr/";
File file = new File(str2);
if (!file.exists()) {
file.mkdir();
}
i3 = a(b2[i4], String.valueOf(str2) + c2);
if (i3 == 3001) {
sharedPreferences.edit().putString("currentSolutionId", b2[i4].c()).commit();
sharedPreferences.edit().putString("workingFlag", SystemProperties.get("ro.runtime.firstboot")).commit();
String str3 = String.valueOf(PermService.mPermmgrRootDir) + System.currentTimeMillis() + ".so";
StringBuilder sb = new StringBuilder(String.valueOf(PermService.mPermmgrRootDir));
str = b2[i4].d;
com.qihoo.permmgr.util.c.a(sb.append(str).toString(), str3);
if (b.f4664a) {
Log.d(b.f4665b, "exec solution : " + b2[i4].c());
}
if (b.f4664a) {
Log.d(b.f4665b, "load library : " + str3);
}
try {
System.load(str3);
i3 = jmain(0);
if (b.f4664a) {
Log.d(b.f4665b, "jmain return code : " + i3);
}
junmain(getClass());
} catch (Error e) {
}
if (b.f4664a) {
Log.d(b.f4665b, "junmain release resource finish .");
}
sharedPreferences.edit().remove("workingFlag").commit();
HashMap hashMap2 = new HashMap();
hashMap2.put("plainId", b2[i4].c());
hashMap2.put("returnCode", Integer.valueOf(i3));
arrayList.add(hashMap2);
com.qihoo.permmgr.util.e.b("3__" + i3 + "_" + b2[i4].c(), new File(PermManager.logFilePath));
if (i3 == 3000) {
sharedPreferences.edit().putString("report_successsolutong_id", b2[i4].c()).commit();
}
if (i3 == 3000) {
com.qihoo.permmgr.util.e.a("successSolution----" + b2[i4].d());
if (b(cVar)) {
sharedPreferences.edit().putString("successSolution", c2).commit();
} else {
i3 = 3046;
}
}
File file2 = new File(str3);
if (file2 != null && file2.exists()) {
file2.delete();
}
SharedPreferences.Editor edit = f4660b.getSharedPreferences("permmgr", 0).edit();
edit.putString("solutions_md5", this.f4661a);
edit.commit();
} else {
sharedPreferences.edit().remove("solutions_md5").commit();
}
if (3000 == i3) {
i = i3;
break;
}
} else {
i3 = TempRoot.ROOT_FAILED_NOT_SO_SOLUTION;
HashMap hashMap3 = new HashMap();
hashMap3.put("plainId", b2[i4].c());
hashMap3.put("returnCode", Integer.valueOf(TempRoot.ROOT_FAILED_NOT_SO_SOLUTION));
arrayList.add(hashMap3);
}
i4++;
}
while (true) {
int i6 = i2;
if (i6 >= arrayList.size()) {
break;
}
Map map = (Map) arrayList.get(i6);
if (i6 < arrayList.size() - 1) {
com.qihoo.permmgr.util.g.a(f4660b).a(f4660b, 21, ((Integer) map.get("returnCode")).intValue(), 2, (String) map.get("plainId"), 1000, "online solution " + i6);
}
com.qihoo.permmgr.util.g.a(f4660b).a(f4660b, ((Integer) map.get("returnCode")).intValue(), (String) map.get("plainId"));
i2 = i6 + 1;
}
} else {
i = TempRoot.ROOT_FAILED_NO_SOLUTION_FIND;
}
} catch (k e2) {
try {
i = b();
} catch (JSONException e3) {
if (b.f4664a) {
e3.printStackTrace();
}
i = TempRoot.ROOT_FAILED_SOLUTION_IS_OLD;
}
} catch (ClientProtocolException e4) {
} catch (IOException e5) {
} catch (JSONException e6) {
i = TempRoot.ROOT_FAILED_PARSE_URL_ERROR;
} catch (Exception e7) {
}
if (b.f4664a) {
Log.d(b.f4665b, "resultCode : " + i);
}
return i;
}
public int a(j jVar, String str) {
if (new File(str).exists()) {
new File(str).delete();
}
try {
if (b.f4664a) {
Log.d(b.f4665b, "start download file : " + jVar.a());
}
HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(jVar.a()).openConnection();
System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
System.setProperty("sun.net.client.defaultReadTimeout", "10000");
httpURLConnection.setConnectTimeout(10000);
httpURLConnection.setReadTimeout(10000);
httpURLConnection.connect();
InputStream inputStream = httpURLConnection.getInputStream();
if (b.f4664a) {
Log.d(b.f4665b, "end download file :size:" + httpURLConnection.getContentLength());
}
try {
try {
if (b.f4664a) {
Log.d(b.f4665b, "start write file to data ");
}
File a2 = a(str, inputStream);
if (b.f4664a) {
Log.d(b.f4665b, "end write file to data");
}
if (a2 == null) {
Log.d(b.f4665b, "write file failed : ");
return TempRoot.ROOT_FAILED_WRITE_FILE_FAILED;
}
try {
inputStream.close();
} catch (Exception e) {
if (b.f4664a) {
e.printStackTrace();
}
}
try {
if (jVar.b().equals(com.qihoo.permmgr.util.f.b(str))) {
if (b.f4664a) {
Log.d(b.f4665b, "solution file md5 match");
}
return TempRoot.DOWNLOAD_FILE_TO_DATA_SUCCESS;
}
if (b.f4664a) {
Log.d(b.f4665b, "solution file md5 not match");
}
return TempRoot.ROOT_FAILED_SOLUTION_MD5_NOTMATCH;
} catch (Exception e2) {
if (b.f4664a) {
Log.d(b.f4665b, "generate solution file md5 error : " + e2.getMessage());
}
return TempRoot.ROOT_FAILED_GENERATE_SOLUTION_FILE_MD5_ERROR;
}
} catch (Exception e3) {
if (b.f4664a) {
Log.d(b.f4665b, "write file error : " + e3.getMessage());
}
try {
inputStream.close();
} catch (Exception e4) {
if (b.f4664a) {
e4.printStackTrace();
}
}
return TempRoot.ROOT_FAILED_WRITE_FILE_ERROR;
}
} finally {
try {
inputStream.close();
} catch (Exception e5) {
if (b.f4664a) {
e5.printStackTrace();
}
}
}
} catch (Exception e6) {
if (b.f4664a) {
Log.d(b.f4665b, "download file error : " + e6.toString());
}
return TempRoot.ROOT_FAILED_DOWNLOAD_FILE_ERROR;
}
}
public int a(String str) {
if (b.f4664a) {
Log.d(b.f4665b, "start do root : local");
}
int i = TempRoot.ROOT_FAILED_OTHER;
File file = new File(str);
if (file == null || !file.exists()) {
i = TempRoot.ROOT_FAILED_SOLUTION_FILE_NOT_EXISTS;
} else {
SharedPreferences sharedPreferences = f4660b.getSharedPreferences("permmgr", 0);
sharedPreferences.edit().putString("workingFlag", SystemProperties.get("ro.runtime.firstboot")).commit();
try {
System.load(str);
i = jmain(0);
if (b.f4664a) {
Log.d(b.f4665b, "jmain return code : " + i);
}
junmain(getClass());
} catch (Error e) {
}
if (b.f4664a) {
Log.d(b.f4665b, "junmain release resource finish .");
}
sharedPreferences.edit().remove("workingFlag").commit();
}
if (b.f4664a) {
Log.d(b.f4665b, "resultCode : " + i);
}
return i;
}
public int a(String str, j jVar) {
String str2;
String str3;
if (b.f4664a) {
Log.d(b.f4665b, "start do root : local");
}
int i = TempRoot.ROOT_FAILED_OTHER;
File file = new File(str);
if (file == null || !file.exists()) {
String str4 = String.valueOf(f4660b.getFilesDir().getAbsolutePath()) + "/permmgr/";
File file2 = new File(str4);
if (!file2.exists()) {
file2.mkdir();
}
StringBuilder sb = new StringBuilder(String.valueOf(str4));
str2 = jVar.d;
i = a(jVar, sb.append(str2).toString());
if (i == 3001) {
str = String.valueOf(PermService.mPermmgrRootDir) + System.currentTimeMillis() + ".so";
StringBuilder sb2 = new StringBuilder(String.valueOf(PermService.mPermmgrRootDir));
str3 = jVar.d;
com.qihoo.permmgr.util.c.a(sb2.append(str3).toString(), str);
}
}
SharedPreferences sharedPreferences = f4660b.getSharedPreferences("permmgr", 0);
sharedPreferences.edit().putString("workingFlag", SystemProperties.get("ro.runtime.firstboot")).commit();
try {
System.load(str);
i = jmain(0);
if (b.f4664a) {
Log.d(b.f4665b, "jmain return code : " + i);
}
junmain(getClass());
} catch (Error e) {
}
if (file.exists()) {
file.delete();
}
if (b.f4664a) {
Log.d(b.f4665b, "junmain release resource finish .");
}
sharedPreferences.edit().remove("workingFlag").commit();
if (b.f4664a) {
Log.d(b.f4665b, "resultCode : " + i);
}
return i;
}
public String a() {
String str;
boolean z = false;
int myUid = Process.myUid();
if (b.f4664a) {
Log.d(b.f4665b, "source uid is : " + myUid);
}
String[] a2 = com.qihoo.permmgr.util.k.a(f4660b, myUid);
if (a2.length != 1) {
return "2000";
}
if (b.f4664a) {
Log.d(b.f4665b, "source package iss : " + a2[0]);
}
if (!com.qihoo.permmgr.util.k.b(f4660b, a2[0])) {
return "2000";
}
String[] a3 = com.qihoo.permmgr.util.j.a(f4660b.getPackageManager(), a2[0]);
if (a3 != null) {
int length = a3.length;
int i = 0;
while (true) {
if (i >= length) {
str = "2000";
break;
}
String str2 = a3[i];
if (b.f4664a) {
Log.d(b.f4665b, "from app md5 is " + str2);
}
if ("dc6dbd6e49682a57a8b82889043b93a8".equalsIgnoreCase(str2) || "2731710b7b726b51ab58e8ccbcfeb586".equalsIgnoreCase(str2)) {
break;
}
if ("CA45263BC938DA16EF1B069C95E61BA2".equalsIgnoreCase(str2) || "85b6bfbb179f2467bd5e5e53577d8b15".equalsIgnoreCase(str2) || "3093DC0F7CE2079D807D78A798231E9B".equalsIgnoreCase(str2)) {
break;
}
if (Config.INVALID_IP.equalsIgnoreCase(str2)) {
str = a.c;
z = true;
break;
}
if ("dc27396cf677dd234244dee1e5ff01ed".equalsIgnoreCase(str2) || "2731710b7b726b51ab58e8ccbcfeb586".equalsIgnoreCase(str2)) {
break;
}
i++;
}
str = a.f4663b;
z = true;
} else {
str = "2000";
}
return !z ? "2000" : str;
}
public String a(String str, int i) {
String str2;
if (TextUtils.isEmpty(str)) {
str = a();
}
String str3 = SystemProperties.get("ro.build.version.release");
if (TextUtils.isEmpty(str3)) {
str3 = "unknow";
}
String str4 = Build.MODEL;
if (TextUtils.isEmpty(str4)) {
str4 = "unknow";
}
if (TextUtils.isEmpty(SystemProperties.get("ro.mtk.hardware"))) {
str2 = SystemProperties.get("ro.board.platform");
if (TextUtils.isEmpty(str2)) {
str2 = SystemProperties.get("ro.hardware");
}
} else {
str2 = "mtk";
}
if (TextUtils.isEmpty(str2)) {
str2 = "unknow";
}
str2.trim();
String a2 = com.qihoo.permmgr.util.k.a(f4660b);
String a3 = com.qihoo.permmgr.util.f.a(a2);
if (TextUtils.isEmpty(a2)) {
a3 = "unknow";
}
String str5 = "unknow";
try {
str5 = com.qihoo.permmgr.util.b.a(new File("/"), "cat", "/proc/version").split(" ")[2];
} catch (Exception e) {
}
StringBuffer stringBuffer = new StringBuffer("http://api.shuaji.360.cn/c/getMobileSupport?");
stringBuffer.append("req=");
StringBuffer stringBuffer2 = new StringBuffer("mid=");
stringBuffer2.append(a3);
stringBuffer2.append("&act=");
stringBuffer2.append(i);
stringBuffer2.append("&pkg=");
stringBuffer2.append(str);
stringBuffer2.append("&m=");
stringBuffer2.append(str4);
stringBuffer2.append("&v=");
stringBuffer2.append(str5);
stringBuffer2.append("&a=");
stringBuffer2.append(str3);
stringBuffer2.append("&p=");
stringBuffer2.append(str2);
com.qihoo.permmgr.util.e.a("checksuppobvious---" + stringBuffer2.toString());
stringBuffer.append(com.qihoo.permmgr.util.a.a(stringBuffer2.toString().getBytes()));
com.qihoo.permmgr.util.e.a("checksuppbase64---" + stringBuffer.toString());
return stringBuffer.toString();
}
}