All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.virjar.ratel.api.inspect.ClassStatusUtils Maven / Gradle / Ivy

Go to download

ratel api,used for developer on ratel system,an extension for xposed framewrok,ratel api compatable with original xposed framework

There is a newer version: 1.3.6
Show newest version
package com.virjar.ratel.api.inspect;


import android.os.Build;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.lang.reflect.Modifier;

public class ClassStatusUtils {

    static Field fieldStatusOfClass;

    static {
        try {
            fieldStatusOfClass = Class.class.getDeclaredField("status");
            fieldStatusOfClass.setAccessible(true);
        } catch (NoSuchFieldException e) {
        }
    }

    public static int getClassStatus(Class clazz, boolean isUnsigned) {
        if (clazz == null) {
            return 0;
        }
        int status = 0;
        try {
            status = fieldStatusOfClass.getInt(clazz);
        } catch (Throwable e) {
        }
        if (isUnsigned) {
            status = (int) (toUnsignedLong(status) >> (32 - 4));
        }
        return status;
    }

    public static long toUnsignedLong(int x) {
        return ((long) x) & 0xffffffffL;
    }


    /**
     * 5.0-8.0: kInitialized = 10 int
     * 8.1:     kInitialized = 11 int
     * 9.0:     kInitialized = 14 uint8_t
     */
    public static boolean isInitialized(Class clazz) {
        if (fieldStatusOfClass == null)
            return true;
        if (Build.VERSION.SDK_INT >= 28) {
            return getClassStatus(clazz, true) == 14;
        } else if (Build.VERSION.SDK_INT == 27) {
            return getClassStatus(clazz, false) == 11;
        } else {
            return getClassStatus(clazz, false) == 10;
        }
    }

    public static boolean isStaticAndNoInited(Member hookMethod) {
        if (hookMethod == null || hookMethod instanceof Constructor) {
            return false;
        }
        Class declaringClass = hookMethod.getDeclaringClass();
        return Modifier.isStatic(hookMethod.getModifiers())
                && !ClassStatusUtils.isInitialized(declaringClass);
    }

    public static boolean isNotInited(Member hookMethod) {
        if (hookMethod == null || hookMethod instanceof Constructor) {
            return false;
        }
        Class declaringClass = hookMethod.getDeclaringClass();
        return !ClassStatusUtils.isInitialized(declaringClass);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy