// types for Java's Classfile structure // https://docs.oracle.com/javase/specs/jvms/se22/html/jvms-4.html #include #pragma pack(1) typedef uint8_t u1; typedef uint16_t u2; typedef uint32_t u4; typedef enum { ACC_PUBLIC = 0x0001, ACC_PRIVATE = 0x0002, ACC_PROTECTED = 0x0004, ACC_STATIC = 0x0008, ACC_FINAL = 0x0010, ACC_SUPER = 0x0020, ACC_SYNCHRONIZED = 0x0020, ACC_VOLATLE = 0x0040, ACC_BRIDGE = 0x0040, ACC_TRANSIENT = 0x0080, ACC_VARARGS = 0x0080, ACC_NATIVE = 0x0100, ACC_INTERFACE = 0x0200, ACC_ABSTRACT = 0x0400, ACC_STRICT = 0x0800, ACC_SYNTHETIC = 0x1000, ACC_ANNOTATION = 0x2000, ACC_ENUM = 0x4000, ACC_MODULE = 0x8000, } ACCESS_FLAGS; typedef enum { CONSTANT_Class = 7, CONSTANT_Fieldref = 9, CONSTANT_Methodref = 10, CONSTANT_InterfaceMethodref = 11, CONSTANT_String = 8, CONSTANT_Integer = 3, CONSTANT_Float = 4, CONSTANT_Long = 5, CONSTANT_Double = 6, CONSTANT_NameAndType = 12, CONSTANT_Utf8 = 1, CONSTANT_MethodHandle = 15, CONSTANT_MethodType = 16, CONSTANT_Dynamic = 17, CONSTANT_InvokeDynamic = 18, CONSTANT_Module = 19, CONSTANT_Package = 20, } CONSTANT_TAGS; typedef struct { u1 tag; void *info; } cp_info; typedef struct { u1 tag; u2 name_index; } CONSTANT_Class_info; typedef struct { u1 tag; u2 class_index; u2 name_and_type_index; } CONSTANT_Fieldref_info; typedef CONSTANT_Fieldref_info CONSTANT_Methodref_info; typedef CONSTANT_Fieldref_info CONSTANT_InterfaceMethodref_info; typedef struct { u1 tag; u2 string_index; } CONSTANT_String_info; typedef struct { u1 tag; u4 bytes; } CONSTANT_Integer_info; typedef CONSTANT_Integer_info CONSTANT_Float_info; typedef struct { u1 tag; u4 high_bytes; u4 low_bytes; } CONSTANT_Long_info; typedef CONSTANT_Long_info CONSTANT_Double_info; typedef struct { u1 tag; u2 name_index; u2 descriptor_index; } CONSTANT_NameAndType_info; typedef struct { u1 tag; u2 length; u1 *bytes; } CONSTANT_Utf8_info; typedef struct { u1 tag; u1 reference_kind; u2 reference_index; } CONSTANT_MethodHandle_info; typedef struct { u1 tag; u2 descriptor_index; } CONSTANT_MethodType_info; typedef struct { u1 tag; u2 bootstrap_method_attr_index; u2 name_and_type_index; } CONSTANT_Dynamic_info; typedef CONSTANT_Dynamic_info CONSTANT_InvokeDynamic_info; typedef struct { u1 tag; u2 name_index; } CONSTANT_Module_info; typedef struct { u1 tag; u2 name_index; } CONSTANT_Package_info; typedef struct { u2 attribute_name_index; u4 attribute_length; u1 *info; } attribute_info; typedef struct { u2 access_flags; u2 name_index; u2 descriptor_index; u2 attributes_count; attribute_info *attributes; } field_info; typedef struct { u2 access_flags; u2 name_index; u2 descriptor_index; u2 attributes_count; attribute_info *attributes; } method_info; typedef struct { u4 magic; u2 minor_version; u2 major_version; u2 constant_pool_count; cp_info *constant_pool; u2 access_flags; u2 this_class; u2 super_class; u2 interfaces_count; u2 *interfaces; u2 fields_count; field_info *fields; u2 methods_count; method_info *methods; u2 attributes_count; attribute_info *attributes; } ClassFile; ClassFile *ClassFile_load(const char *path); void ClassFile_info(const ClassFile *cf); #pragma pack()