package cn.jiguang.al; import android.content.Context; import android.text.TextUtils; import cn.jiguang.am.a; import cn.jiguang.ao.e; import cn.jiguang.ao.g; import cn.jiguang.ao.j; import cn.jiguang.dy.c; import java.io.Closeable; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import javax.crypto.Cipher; import javax.crypto.CipherOutputStream; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; public class b { public static File a(Context context, File file, int i, int i2) { Throwable th; FileInputStream fileInputStream; FileOutputStream fileOutputStream; Throwable th2; try { String d = j.d(g.a(context)); if (TextUtils.isEmpty(d)) { cn.jiguang.an.b.g("PIU", "process name to md5 failed"); c.a().a(context, i, i2, a.d, 2, "process name to md5 failed"); cn.jiguang.ao.c.a((Closeable) null); cn.jiguang.ao.c.a((Closeable) null); return null; } String d2 = j.d(d + file.getName()); if (TextUtils.isEmpty(d2)) { cn.jiguang.an.b.g("PIU", "process + fileName to md5 failed"); c.a().a(context, i, i2, a.d, 2, "process + fileName to md5 failed"); cn.jiguang.ao.c.a((Closeable) null); cn.jiguang.ao.c.a((Closeable) null); return null; } File file2 = new File(file.getParentFile(), d + File.separator + d2 + ".d"); if (file2.exists()) { file2.delete(); } file2.getParentFile().mkdirs(); file2.createNewFile(); fileOutputStream = new FileOutputStream(file2); try { fileInputStream = new FileInputStream(file); try { byte[] bArr = new byte[32]; fileInputStream.read(bArr); String str = new String(bArr, "utf-8"); cn.jiguang.an.b.b("PIU", "get md5:" + str); Cipher instance = Cipher.getInstance("AES/CBC/PKCS5Padding"); instance.init(2, new SecretKeySpec(str.getBytes("utf-8"), "AES"), new IvParameterSpec(e.a.getBytes("utf-8"))); CipherOutputStream cipherOutputStream = new CipherOutputStream(fileOutputStream, instance); byte[] bArr2 = new byte[8192]; while (true) { int read = fileInputStream.read(bArr2, 0, bArr2.length); if (read == -1) { break; } cipherOutputStream.write(bArr2, 0, read); } cn.jiguang.ao.c.a(cipherOutputStream); String a = cn.jiguang.ao.c.a(file2.getAbsolutePath()); cn.jiguang.an.b.b("PIU", "dd f md:" + a); if (!str.equals(a)) { c.a().a(context, i, i2, a.d, 2, "file MD5 not match"); cn.jiguang.ao.c.a(fileOutputStream); cn.jiguang.ao.c.a(fileInputStream); return null; } cn.jiguang.an.b.b("PIU", "d d success"); if (!file2.exists()) { c.a().a(context, i, i2, a.d, 2, "create dex file failed "); } cn.jiguang.ao.c.a(fileOutputStream); cn.jiguang.ao.c.a(fileInputStream); return file2; } catch (Throwable th3) { th2 = th3; try { cn.jiguang.an.b.e("PIU", "decode failed:" + th2.getMessage()); c.a().a(context, i, i2, a.d, 2, "decode failed " + th2.getMessage()); cn.jiguang.ao.c.a(fileOutputStream); cn.jiguang.ao.c.a(fileInputStream); return null; } catch (Throwable th4) { th = th4; cn.jiguang.ao.c.a(fileOutputStream); cn.jiguang.ao.c.a(fileInputStream); throw th; } } } catch (Throwable th5) { th = th5; fileInputStream = null; cn.jiguang.ao.c.a(fileOutputStream); cn.jiguang.ao.c.a(fileInputStream); throw th; } } catch (Throwable th6) { th = th6; fileOutputStream = null; fileInputStream = null; cn.jiguang.ao.c.a(fileOutputStream); cn.jiguang.ao.c.a(fileInputStream); throw th; } } public static File a(Context context, String str, int i, int i2) { String a = a(str, i + "", i2); return new File(context.getFilesDir() + File.separator + ".p", a); } private static String a(String str, String str2, int i) { if (TextUtils.isEmpty(str)) { str = str2 + i; } return "." + str; } public static boolean a(File file, cn.jiguang.am.c cVar, boolean z) { if (!file.exists() || !file.canRead()) { cn.jiguang.an.b.b("PIU", "p :" + file.getAbsolutePath() + " not."); return false; } else if (!z) { return true; } else { if (TextUtils.isEmpty(cVar.s)) { cn.jiguang.an.b.g("PIU", "p M error."); return false; } String a = cn.jiguang.ao.c.a(file.getAbsolutePath()); if (TextUtils.isEmpty(a)) { cn.jiguang.an.b.g("PIU", "g p M f."); return false; } else if (cVar.s.equalsIgnoreCase(a)) { return true; } else { file.delete(); cn.jiguang.an.b.g("PIU", "p M not m, c m: " + cVar.s + ", b f m:" + a); return false; } } } public static File b(Context context, String str, int i, int i2) { if (context == null) { return null; } String str2 = context.getFilesDir() + File.separator + ".p"; File file = new File(str2, a(str, i + "", i2) + "o"); cn.jiguang.an.b.b("PIU", "getLibPath mkdirs:" + file.mkdirs()); return file; } public static File c(Context context, String str, int i, int i2) { String str2 = context.getFilesDir() + File.separator + ".p"; File file = new File(str2, a(str, i + "", i2) + "ox"); cn.jiguang.an.b.b("PIU", "getOptimizedDexPath mkdirs:" + file.mkdirs()); return file; } }