package com.tencent.mm.platformtools;

import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.a.c;
import com.tencent.mm.a.g;
import com.tencent.mm.a.r;
import com.tencent.mm.pointers.PByteArray;
import com.tencent.mm.sdk.g.d;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.ah;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.ytcommon.BuildConfig;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.client.DefaultHttpClient;

public final class ad {
    public static boolean a(String str, String str2, boolean z, boolean z2, int i) {
        AppMethodBeat.i(72654);
        if (z2) {
            d.f(new 1(str, str2, z, i), "StackReportUploader_uploadFileDirect");
            AppMethodBeat.o(72654);
            return true;
        }
        boolean a = a(str, str2, z, i);
        AppMethodBeat.o(72654);
        return a;
    }

    public static boolean a(String str, String str2, boolean z, boolean z2) {
        AppMethodBeat.i(72655);
        boolean a = a(str, str2, z, z2, 20003);
        AppMethodBeat.o(72655);
        return a;
    }

    /* JADX WARNING: Removed duplicated region for block: B:49:0x017a A:{SYNTHETIC, Splitter:B:49:0x017a} */
    /* JADX WARNING: Removed duplicated region for block: B:55:0x018a A:{SYNTHETIC, Splitter:B:55:0x018a} */
    static boolean a(java.lang.String r15, java.lang.String r16, boolean r17, int r18) {
        /*
        r2 = 72656; // 0x11bd0 float:1.01813E-40 double:3.5897E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.i(r2);
        r2 = com.tencent.mm.sdk.platformtools.bo.isNullOrNil(r15);
        if (r2 != 0) goto L_0x0012;
    L_0x000c:
        r2 = com.tencent.mm.sdk.platformtools.bo.isNullOrNil(r16);
        if (r2 == 0) goto L_0x002c;
    L_0x0012:
        r2 = "MicroMsg.StackReportUploader";
        r3 = "uploadFile param err file:%s  user:%s";
        r4 = 2;
        r4 = new java.lang.Object[r4];
        r5 = 0;
        r4[r5] = r15;
        r5 = 1;
        r4[r5] = r16;
        com.tencent.mm.sdk.platformtools.ab.e(r2, r3, r4);
        r2 = 0;
        r3 = 72656; // 0x11bd0 float:1.01813E-40 double:3.5897E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r3);
    L_0x002b:
        return r2;
    L_0x002c:
        r5 = com.tencent.mm.a.e.cs(r15);
        if (r5 > 0) goto L_0x0050;
    L_0x0032:
        r2 = "MicroMsg.StackReportUploader";
        r3 = "uploadFile err len file:%s len:%d";
        r4 = 2;
        r4 = new java.lang.Object[r4];
        r6 = 0;
        r4[r6] = r15;
        r6 = 1;
        r5 = java.lang.Integer.valueOf(r5);
        r4[r6] = r5;
        com.tencent.mm.sdk.platformtools.ab.e(r2, r3, r4);
        r2 = 0;
        r3 = 72656; // 0x11bd0 float:1.01813E-40 double:3.5897E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r3);
        goto L_0x002b;
    L_0x0050:
        r2 = 128000; // 0x1f400 float:1.79366E-40 double:6.32404E-319;
        if (r5 > r2) goto L_0x0099;
    L_0x0055:
        r2 = 0;
        r3 = -1;
        r2 = com.tencent.mm.a.e.f(r15, r2, r3);
        r0 = r16;
        r1 = r18;
        r3 = a(r2, r15, r0, r1);
        r4 = "MicroMsg.StackReportUploader";
        r5 = "uploadFile ret:%b size:%d file:%s";
        r6 = 3;
        r6 = new java.lang.Object[r6];
        r7 = 0;
        r8 = java.lang.Boolean.valueOf(r3);
        r6[r7] = r8;
        r7 = 1;
        if (r2 == 0) goto L_0x0097;
    L_0x0076:
        r2 = r2.length;
    L_0x0077:
        r2 = java.lang.Integer.valueOf(r2);
        r6[r7] = r2;
        r2 = 2;
        r6[r2] = r15;
        com.tencent.mm.sdk.platformtools.ab.d(r4, r5, r6);
        if (r3 == 0) goto L_0x008f;
    L_0x0085:
        if (r17 == 0) goto L_0x008f;
    L_0x0087:
        r2 = new java.io.File;
        r2.<init>(r15);
        com.tencent.mm.a.e.t(r2);
    L_0x008f:
        r2 = 72656; // 0x11bd0 float:1.01813E-40 double:3.5897E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r2);
        r2 = r3;
        goto L_0x002b;
    L_0x0097:
        r2 = -1;
        goto L_0x0077;
    L_0x0099:
        r2 = 127988; // 0x1f3f4 float:1.7935E-40 double:6.32345E-319;
        r2 = r5 / r2;
        r6 = r2 + 1;
        r2 = 128000; // 0x1f400 float:1.79366E-40 double:6.32404E-319;
        r7 = new byte[r2];
        r2 = com.tencent.mm.sdk.platformtools.bo.anU();
        r8 = (int) r2;
        r4 = 0;
        r3 = new java.io.FileInputStream;	 Catch:{ Exception -> 0x0154, all -> 0x0186 }
        r3.<init>(r15);	 Catch:{ Exception -> 0x0154, all -> 0x0186 }
        r2 = 0;
        r4 = r2;
    L_0x00b2:
        if (r4 >= r6) goto L_0x013e;
    L_0x00b4:
        r2 = 12;
        r9 = 127988; // 0x1f3f4 float:1.7935E-40 double:6.32345E-319;
        r9 = r3.read(r7, r2, r9);	 Catch:{ Exception -> 0x019f }
        if (r9 >= 0) goto L_0x00da;
    L_0x00bf:
        r2 = "MicroMsg.StackReportUploader";
        r4 = "uploadFile read failed file:%s";
        r5 = 1;
        r5 = new java.lang.Object[r5];	 Catch:{ Exception -> 0x019f }
        r6 = 0;
        r5[r6] = r15;	 Catch:{ Exception -> 0x019f }
        com.tencent.mm.sdk.platformtools.ab.e(r2, r4, r5);	 Catch:{ Exception -> 0x019f }
        r3.close();	 Catch:{ Exception -> 0x0194 }
    L_0x00d1:
        r2 = 0;
        r3 = 72656; // 0x11bd0 float:1.01813E-40 double:3.5897E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r3);
        goto L_0x002b;
    L_0x00da:
        r2 = 0;
        d(r8, r7, r2);	 Catch:{ Exception -> 0x019f }
        r2 = 4;
        d(r4, r7, r2);	 Catch:{ Exception -> 0x019f }
        r2 = 8;
        d(r9, r7, r2);	 Catch:{ Exception -> 0x019f }
        r2 = 127988; // 0x1f3f4 float:1.7935E-40 double:6.32345E-319;
        if (r9 >= r2) goto L_0x0135;
    L_0x00ec:
        r2 = r9 + 12;
        r2 = new byte[r2];	 Catch:{ Exception -> 0x019f }
        r10 = 0;
        r11 = 0;
        r12 = r2.length;	 Catch:{ Exception -> 0x019f }
        java.lang.System.arraycopy(r7, r10, r2, r11, r12);	 Catch:{ Exception -> 0x019f }
        r0 = r16;
        r1 = r18;
        r2 = a(r2, r15, r0, r1);	 Catch:{ Exception -> 0x019f }
    L_0x00fe:
        r10 = "MicroMsg.StackReportUploader";
        r11 = "uploadFile idx:%d(%d) read:%d ret:%b size:%d file:%s";
        r12 = 6;
        r12 = new java.lang.Object[r12];	 Catch:{ Exception -> 0x019f }
        r13 = 0;
        r14 = java.lang.Integer.valueOf(r4);	 Catch:{ Exception -> 0x019f }
        r12[r13] = r14;	 Catch:{ Exception -> 0x019f }
        r13 = 1;
        r14 = java.lang.Integer.valueOf(r6);	 Catch:{ Exception -> 0x019f }
        r12[r13] = r14;	 Catch:{ Exception -> 0x019f }
        r13 = 2;
        r9 = java.lang.Integer.valueOf(r9);	 Catch:{ Exception -> 0x019f }
        r12[r13] = r9;	 Catch:{ Exception -> 0x019f }
        r9 = 3;
        r2 = java.lang.Boolean.valueOf(r2);	 Catch:{ Exception -> 0x019f }
        r12[r9] = r2;	 Catch:{ Exception -> 0x019f }
        r2 = 4;
        r9 = java.lang.Integer.valueOf(r5);	 Catch:{ Exception -> 0x019f }
        r12[r2] = r9;	 Catch:{ Exception -> 0x019f }
        r2 = 5;
        r12[r2] = r15;	 Catch:{ Exception -> 0x019f }
        com.tencent.mm.sdk.platformtools.ab.d(r10, r11, r12);	 Catch:{ Exception -> 0x019f }
        r2 = r4 + 1;
        r4 = r2;
        goto L_0x00b2;
    L_0x0135:
        r0 = r16;
        r1 = r18;
        r2 = a(r7, r15, r0, r1);	 Catch:{ Exception -> 0x019f }
        goto L_0x00fe;
    L_0x013e:
        if (r17 == 0) goto L_0x0148;
    L_0x0140:
        r2 = new java.io.File;	 Catch:{ Exception -> 0x019f }
        r2.<init>(r15);	 Catch:{ Exception -> 0x019f }
        com.tencent.mm.a.e.t(r2);	 Catch:{ Exception -> 0x019f }
    L_0x0148:
        r3.close();	 Catch:{ Exception -> 0x0197 }
    L_0x014b:
        r2 = 1;
        r3 = 72656; // 0x11bd0 float:1.01813E-40 double:3.5897E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r3);
        goto L_0x002b;
    L_0x0154:
        r2 = move-exception;
        r3 = r4;
    L_0x0156:
        r4 = "MicroMsg.StackReportUploader";
        r5 = "exception:%s";
        r6 = 1;
        r6 = new java.lang.Object[r6];	 Catch:{ all -> 0x019d }
        r7 = 0;
        r2 = com.tencent.mm.sdk.platformtools.bo.l(r2);	 Catch:{ all -> 0x019d }
        r6[r7] = r2;	 Catch:{ all -> 0x019d }
        com.tencent.mm.sdk.platformtools.ab.e(r4, r5, r6);	 Catch:{ all -> 0x019d }
        r2 = "MicroMsg.StackReportUploader";
        r4 = "uploadFile read except file:%s";
        r5 = 1;
        r5 = new java.lang.Object[r5];	 Catch:{ all -> 0x019d }
        r6 = 0;
        r5[r6] = r15;	 Catch:{ all -> 0x019d }
        com.tencent.mm.sdk.platformtools.ab.e(r2, r4, r5);	 Catch:{ all -> 0x019d }
        if (r3 == 0) goto L_0x017d;
    L_0x017a:
        r3.close();	 Catch:{ Exception -> 0x0199 }
    L_0x017d:
        r2 = 0;
        r3 = 72656; // 0x11bd0 float:1.01813E-40 double:3.5897E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r3);
        goto L_0x002b;
    L_0x0186:
        r2 = move-exception;
        r3 = r4;
    L_0x0188:
        if (r3 == 0) goto L_0x018d;
    L_0x018a:
        r3.close();	 Catch:{ Exception -> 0x019b }
    L_0x018d:
        r3 = 72656; // 0x11bd0 float:1.01813E-40 double:3.5897E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r3);
        throw r2;
    L_0x0194:
        r2 = move-exception;
        goto L_0x00d1;
    L_0x0197:
        r2 = move-exception;
        goto L_0x014b;
    L_0x0199:
        r2 = move-exception;
        goto L_0x017d;
    L_0x019b:
        r3 = move-exception;
        goto L_0x018d;
    L_0x019d:
        r2 = move-exception;
        goto L_0x0188;
    L_0x019f:
        r2 = move-exception;
        goto L_0x0156;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.tencent.mm.platformtools.ad.a(java.lang.String, java.lang.String, boolean, int):boolean");
    }

    private static boolean d(int i, byte[] bArr, int i2) {
        if (128000 < i2 + 4) {
            return false;
        }
        bArr[i2] = (byte) ((i >> 24) & 255);
        bArr[i2 + 1] = (byte) ((i >> 16) & 255);
        bArr[i2 + 2] = (byte) ((i >> 8) & 255);
        bArr[i2 + 3] = (byte) (i & 255);
        return true;
    }

    private static boolean a(byte[] bArr, String str, String str2, int i) {
        AppMethodBeat.i(72657);
        if (bo.cb(bArr)) {
            ab.e("MicroMsg.StackReportUploader", "read file failed:%s", new Object[]{str});
            AppMethodBeat.o(72657);
            return false;
        } else if (bArr.length > 128000) {
            ab.e("MicroMsg.StackReportUploader", "file :%s data len error:%d", new Object[]{str, Integer.valueOf(bArr.length)});
            AppMethodBeat.o(72657);
            return false;
        } else {
            String toLowerCase = g.x(String.format("weixin#$()%d%d", new Object[]{Integer.valueOf(com.tencent.mm.protocal.d.vxo), Integer.valueOf(bArr.length)}).getBytes()).toLowerCase();
            byte[] compress = r.compress(bArr);
            if (bo.cb(compress)) {
                ab.e("MicroMsg.StackReportUploader", "zip data failed file:%s", new Object[]{str});
                AppMethodBeat.o(72657);
                return false;
            }
            PByteArray pByteArray = new PByteArray();
            c.a(pByteArray, compress, toLowerCase.getBytes());
            compress = pByteArray.value;
            if (bo.cb(compress)) {
                ab.e("MicroMsg.StackReportUploader", "encrypt data failed file:%s", new Object[]{str});
            }
            String str3 = "http://" + ah.getContext().getSharedPreferences("system_config_prefs", 0).getString("support.weixin.qq.com", "support.weixin.qq.com");
            StringBuffer stringBuffer = new StringBuffer();
            stringBuffer.append(str3 + "/cgi-bin/mmsupport-bin/stackreport?version=");
            stringBuffer.append(Integer.toHexString(com.tencent.mm.protocal.d.vxo));
            stringBuffer.append("&devicetype=");
            stringBuffer.append(com.tencent.mm.protocal.d.eSg);
            stringBuffer.append("&filelength=");
            stringBuffer.append(r2);
            stringBuffer.append("&sum=");
            stringBuffer.append(toLowerCase);
            stringBuffer.append("&reporttype=");
            stringBuffer.append(i);
            stringBuffer.append("&reportvalue=");
            stringBuffer.append(bo.anU() + ".0.1");
            if (!(str2 == null || str2.equals(BuildConfig.FLAVOR))) {
                stringBuffer.append("&username=");
                stringBuffer.append(str2);
            }
            DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(stringBuffer.toString());
            try {
                ByteArrayEntity byteArrayEntity = new ByteArrayEntity(compress);
                byteArrayEntity.setContentType("binary/octet-stream");
                httpPost.setEntity(byteArrayEntity);
                HttpResponse execute = defaultHttpClient.execute(httpPost);
                if (execute == null || execute.getStatusLine() == null) {
                    ab.e("MicroMsg.StackReportUploader", "execute http failed resp null");
                    AppMethodBeat.o(72657);
                    return false;
                } else if (execute.getStatusLine().getStatusCode() != 200) {
                    ab.e("MicroMsg.StackReportUploader", "error response code:%d ", new Object[]{Integer.valueOf(execute.getStatusLine().getStatusCode())});
                    AppMethodBeat.o(72657);
                    return false;
                } else {
                    AppMethodBeat.o(72657);
                    return true;
                }
            } catch (Exception e) {
                ab.e("MicroMsg.StackReportUploader", "exception:%s", new Object[]{bo.l(e)});
                ab.d("MicroMsg.StackReportUploader", "execute post failed msg:%s", new Object[]{e.getMessage()});
                AppMethodBeat.o(72657);
                return false;
            }
        }
    }
}
