package o;

import dalvik.system.VMRuntime;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.HashSet;
import sun.misc.Unsafe;

/* renamed from: o.bF, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public abstract class AbstractC0797bF {
    public static final Unsafe a;
    public static final long b;
    public static final long c;
    public static final long d;
    public static final long e;
    public static final HashSet f = new HashSet();

    static {
        try {
            Unsafe unsafe = (Unsafe) Unsafe.class.getDeclaredMethod("getUnsafe", null).invoke(null, null);
            a = unsafe;
            b = unsafe.objectFieldOffset(TE.class.getDeclaredField("artMethod"));
            unsafe.objectFieldOffset(TE.class.getDeclaredField("declaringClass"));
            long jObjectFieldOffset = unsafe.objectFieldOffset(WE.class.getDeclaredField("artFieldOrMethod"));
            unsafe.objectFieldOffset(XE.class.getDeclaredField("info"));
            long jObjectFieldOffset2 = unsafe.objectFieldOffset(SE.class.getDeclaredField("methods"));
            c = jObjectFieldOffset2;
            long jObjectFieldOffset3 = unsafe.objectFieldOffset(SE.class.getDeclaredField("iFields"));
            unsafe.objectFieldOffset(SE.class.getDeclaredField("sFields"));
            unsafe.objectFieldOffset(UE.class.getDeclaredField("member"));
            Method declaredMethod = YE.class.getDeclaredMethod("a", null);
            Method declaredMethod2 = YE.class.getDeclaredMethod("b", null);
            declaredMethod.setAccessible(true);
            declaredMethod2.setAccessible(true);
            MethodHandle methodHandleUnreflect = MethodHandles.lookup().unreflect(declaredMethod);
            MethodHandle methodHandleUnreflect2 = MethodHandles.lookup().unreflect(declaredMethod2);
            long j = unsafe.getLong(methodHandleUnreflect, jObjectFieldOffset);
            long j2 = unsafe.getLong(methodHandleUnreflect2, jObjectFieldOffset);
            long j3 = unsafe.getLong(YE.class, jObjectFieldOffset2);
            long j4 = j2 - j;
            d = j4;
            e = (j - j3) - j4;
            Field declaredField = YE.class.getDeclaredField("i");
            Field declaredField2 = YE.class.getDeclaredField("j");
            declaredField.setAccessible(true);
            declaredField2.setAccessible(true);
            MethodHandle methodHandleUnreflectGetter = MethodHandles.lookup().unreflectGetter(declaredField);
            MethodHandle methodHandleUnreflectGetter2 = MethodHandles.lookup().unreflectGetter(declaredField2);
            unsafe.getLong(methodHandleUnreflectGetter, jObjectFieldOffset);
            unsafe.getLong(methodHandleUnreflectGetter2, jObjectFieldOffset);
            unsafe.getLong(YE.class, jObjectFieldOffset3);
        } catch (ReflectiveOperationException e2) {
            throw new ExceptionInInitializerError(e2);
        }
    }

    public static Object a(Class cls, Object obj, String str, Object... objArr) throws NoSuchMethodException, SecurityException {
        int i;
        if (obj != null && !cls.isInstance(obj)) {
            throw new IllegalArgumentException("this object is not an instance of the given class");
        }
        Method declaredMethod = VE.class.getDeclaredMethod("invoke", Object[].class);
        declaredMethod.setAccessible(true);
        Unsafe unsafe = a;
        long j = unsafe.getLong(cls, c);
        if (j == 0) {
            throw new NoSuchMethodException("Cannot find matching method");
        }
        int i2 = unsafe.getInt(j);
        for (int i3 = 0; i3 < i2; i3++) {
            a.putLong(declaredMethod, b, e + (i3 * d) + j);
            if (str.equals(declaredMethod.getName())) {
                Class<?>[] parameterTypes = declaredMethod.getParameterTypes();
                if (parameterTypes.length == objArr.length) {
                    for (0; i < parameterTypes.length; i + 1) {
                        if (parameterTypes[i].isPrimitive()) {
                            Class<?> cls2 = parameterTypes[i];
                            i = ((cls2 != Integer.TYPE || (objArr[i] instanceof Integer)) && (cls2 != Byte.TYPE || (objArr[i] instanceof Byte)) && ((cls2 != Character.TYPE || (objArr[i] instanceof Character)) && ((cls2 != Boolean.TYPE || (objArr[i] instanceof Boolean)) && ((cls2 != Double.TYPE || (objArr[i] instanceof Double)) && ((cls2 != Float.TYPE || (objArr[i] instanceof Float)) && ((cls2 != Long.TYPE || (objArr[i] instanceof Long)) && (cls2 != Short.TYPE || (objArr[i] instanceof Short)))))))) ? i + 1 : 0;
                        } else {
                            Object obj2 = objArr[i];
                            if (obj2 == null || parameterTypes[i].isInstance(obj2)) {
                            }
                        }
                    }
                    return declaredMethod.invoke(obj, objArr);
                }
                continue;
            }
        }
        throw new NoSuchMethodException("Cannot find matching method");
    }

    public static boolean b(String... strArr) {
        try {
            a(VMRuntime.class, a(VMRuntime.class, null, "getRuntime", new Object[0]), "setHiddenApiExemptions", strArr);
            return true;
        } catch (Throwable unused) {
            return false;
        }
    }
}
