kgg
kgg

Reputation: 11

How to extract all field values ​of java.lang.class in android api version 30?

I had extracted about 20 field values of all fields in java.lang.class in Android API version 28 using the getDeclaredFields() method.

Now, after upgrading the android api version to 30 and using the getDeclaredFields() method, only about 10 field values can be extracted.

test code

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    E_class E_tmp = new E_class();

    Class E_getclass1 = E_tmp.getClass();

    Class E_getclass2 = E_getclass1.getClass();
    try {
        for (int i = 0; i < E_getclass2.getDeclaredFields().length; i++) {
            Field E_f = E_getclass2.getDeclaredFields()[i];
            E_f.setAccessible(true);
            String str_E = E_f.getName();
            Log.d("error ", "error " + i + " : " + str_E + " : " + E_f.get(E_getclass1));
        }
    } catch (Exception e) {
        Log.d("error", e.toString());
    }
}

adb logcat result

{

04-26 14:59:37.509 18882 18882 D error : error 0 : accessFlags : 524289

04-26 14:59:37.510 18882 18882 D error : error 1 : classLoader : dalvik.system.PathClassLoader[DexPathList[[dex file "/data/data/com.example.goto_test/code_cache/.overlay/base.apk/classes3.dex", zip file "/data/app/~~AKLoXDGjDRlGzdI7poO8_w==/com.example.goto_test-5CgtxBKcmjogBp9uGhAibg==/base.apk"],nativeLibraryDirectories=[/data/app/~~AKLoXDGjDRlGzdI7poO8_w==/com.example.goto_test-5CgtxBKcmjogBp9uGhAibg==/lib/arm64, /system/lib64, /system_ext/lib64]]]

04-26 14:59:37.510 18882 18882 D error : error 2 : clinitThreadId : 18882

04-26 14:59:37.510 18882 18882 D error : error 3 : dexCache : java.lang.DexCache@feb7bab

04-26 14:59:37.510 18882 18882 D error : error 4 : dexClassDefIndex : 0

04-26 14:59:37.510 18882 18882 D error : error 5 : ifTable : [Ljava.lang.Object;@833f208

04-26 14:59:37.510 18882 18882 D error : error 6 : name : null

04-26 14:59:37.510 18882 18882 D error : error 7 : objectSize : 16

04-26 14:59:37.510 18882 18882 D error : error 8 : status : -536870912

04-26 14:59:37.510 18882 18882 D error : error 9 : serialVersionUID : 3206093459760846163

}

As a result of checking using android studio's debug tool, I was able to check the field values (virtualMethodsOffset, superClass... etc.) extracted from Android API version 28.

I downloaded Android API version 34's java.lang.class code and checked what field values existed.

As a result, we confirmed that values that can be checked in the debug tool exist as field values, as shown in the image below.

java.lang.class {

...

 * uninitialized or finalizable, otherwise the aligned object size.
 */
private transient int objectSizeAllocFastPath;

/**
 * The lower 16 bits is the primitive type value, or 0 if not a primitive type; set for
 * generated primitive classes.
 */
private transient int primitiveType;

/** Bitmap of offsets of iFields. */
private transient int referenceInstanceOffsets;

/** State of class initialization */
private transient int status;

/** Offset of the first virtual method copied from an interface in the methods array. */
private transient short copiedMethodsOffset;

/** Offset of the first virtual method defined in this class in the methods array. */
private transient short virtualMethodsOffset;

...

}

How can I extract and check the relevant field values even in Android API version 30 or higher?

I tried using the getDeclaredField(field name) method to extract field values that can only be checked in the debug value.

However, we found an error that the field value does not exist.

Upvotes: 0

Views: 41

Answers (0)

Related Questions