package com.bytedance.crash.gwpasan;

import X.C27338hY;
import X.C27468hl;
import X.C27798iI;
import X.C27908iT;
import X.C28338jA;
import android.content.Context;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.librarian.Librarian;
import java.io.File;
import org.json.JSONArray;

public class GwpAsan {
    public static String LIZ;
    public static String LIZIZ;
    public static String LIZJ;
    public static String LIZLLL;
    public static String[] LJ;
    public static boolean LJFF;
    public static boolean LJI;
    public static boolean LJII;
    public static boolean LJIIIIZZ;
    public static File LJIIIZ;
    public static Context LJIIJ;
    public static JSONArray LJIIJJI;
    public static boolean LJIIL;
    public static File LJIILJJIL;
    public boolean LJIILIIL;

    static {
        Covode.recordClassIndex(25078);
    }

    public static native int gwpAsanNativeInit(int i, String[] strArr);

    public static boolean LIZIZ() {
        File LIZIZ2 = C27468hl.LIZIZ(C27798iI.LIZ);
        if (!LIZIZ2.exists() || !LIZIZ2.isDirectory()) {
            LIZIZ2.mkdirs();
        }
        long currentTimeMillis = System.currentTimeMillis() / 1000;
        if (LIZ(LIZIZ2, "gwpfile")) {
            try {
                long parseLong = Long.parseLong(C27338hY.LIZ(LJIILJJIL, "\n"));
                if (currentTimeMillis >= parseLong) {
                    if (currentTimeMillis - parseLong < 604800) {
                        return false;
                    }
                    if (currentTimeMillis - parseLong >= 604800) {
                        C27338hY.LIZ(LJIILJJIL);
                        return true;
                    }
                }
                if (parseLong > currentTimeMillis) {
                    return false;
                }
            } catch (Throwable th) {
                C28338jA.LIZ.LIZ("NPTH_CATCH", th);
            }
        }
        return true;
    }

    public final boolean LIZ() {
        C27798iI.LJI.isDebugMode();
        if (!this.LJIILIIL) {
            try {
                Librarian.LIZIZ("npth_xasan", true, LJIIJ);
                this.LJIILIIL = true;
            } catch (Throwable unused) {
            }
        }
        return this.LJIILIIL;
    }

    public static String LIZ(String str) {
        StringBuilder sb = new StringBuilder();
        try {
            if (str.length() < 16) {
                sb.append(str);
            } else {
                sb.append(str.charAt(6));
                sb.append(str.charAt(7));
                sb.append(str.charAt(4));
                sb.append(str.charAt(5));
                sb.append(str.charAt(2));
                sb.append(str.charAt(3));
                sb.append(str.charAt(0));
                sb.append(str.charAt(1));
                sb.append(str.charAt(10));
                sb.append(str.charAt(11));
                sb.append(str.charAt(8));
                sb.append(str.charAt(9));
                sb.append(str.charAt(14));
                sb.append(str.charAt(15));
                sb.append(str.charAt(12));
                sb.append(str.charAt(13));
                if (str.length() >= 32) {
                    sb.append(str, 16, 32);
                    sb.append('0');
                }
            }
        } catch (Throwable unused) {
        }
        return sb.toString().toUpperCase();
    }

    public static boolean LIZ(boolean z) {
        MethodCollector.i(8909);
        try {
            String[] strArr = new String[8];
            LJ = strArr;
            if (LJIIJJI == null) {
                if (LJIIL) {
                    if (z) {
                        strArr[0] = "0";
                        strArr[1] = "8192";
                        strArr[2] = "150";
                        strArr[3] = "0";
                        strArr[4] = "0";
                    } else {
                        strArr[0] = "0";
                        strArr[1] = "64";
                        strArr[2] = "5000";
                        strArr[3] = "0";
                        strArr[4] = "1";
                    }
                    C27798iI.LJI.isDebugMode();
                    MethodCollector.o(8909);
                    return true;
                }
                Thread.sleep(15000);
                LJIIJJI = C27908iT.LJ();
                C27798iI.LJI.isDebugMode();
            }
            JSONArray jSONArray = LJIIJJI;
            if (jSONArray != null && jSONArray.length() > 0) {
                if (z) {
                    LJ[0] = LJIIJJI.optString(0);
                    String[] strArr2 = LJ;
                    strArr2[1] = "8192";
                    strArr2[2] = "150";
                    strArr2[3] = LJIIJJI.optString(3);
                    LJ[4] = "0";
                } else {
                    for (int i = 0; i < LJIIJJI.length(); i++) {
                        LJ[i] = LJIIJJI.optString(i);
                    }
                }
                C27798iI.LJI.isDebugMode();
                MethodCollector.o(8909);
                return true;
            }
        } catch (Throwable th) {
            C28338jA.LIZ.LIZ("NPTH_CATCH", th);
        }
        MethodCollector.o(8909);
        return false;
    }

    public static boolean LIZ(File file, String str) {
        File[] listFiles = file.listFiles();
        for (File file2 : listFiles) {
            try {
                if (!file2.getName().isEmpty() && !file2.isDirectory() && file2.getName().equals(str) && file2.length() >= 0) {
                    LJIILJJIL = file2.getAbsoluteFile();
                    return true;
                }
            } catch (Throwable th) {
                C28338jA.LIZ.LIZ("NPTH_CATCH", th);
            }
        }
        return false;
    }

    public static int LIZ(JSONArray jSONArray, int i, String str) {
        while (i < jSONArray.length()) {
            String optString = jSONArray.optString(i, (String) null);
            if (optString != null && optString.startsWith(str)) {
                return i;
            }
            i++;
        }
        return -1;
    }

    public static String LIZ(String str, String str2, String str3) {
        int indexOf = str.indexOf(str2);
        int indexOf2 = str.indexOf(str3);
        if (indexOf >= 0 && indexOf2 >= 0) {
            return str.substring(indexOf, indexOf2).substring(str2.length());
        }
        return "null";
    }

    public GwpAsan(boolean z, Context context, File file, JSONArray jSONArray) {
        context = context == null ? C27798iI.LIZ : context;
        LJIIL = z;
        LJIIJ = context;
        LJIIIZ = file;
        LJIIJJI = jSONArray;
        LJII = false;
        LJIIIIZZ = false;
    }
}
