attributes half implemented

This commit is contained in:
Benedek László 2024-04-12 17:07:31 +02:00
parent 7a003fc89f
commit c4eea4d1d1
2 changed files with 76 additions and 1 deletions

View File

@ -160,6 +160,8 @@ ClassFile *ClassFile_load(const char *path) {
// attribute_name_index 2bytes, attribute_length 4bytes
read_u2(&(cf->fields[i].attributes[j].attribute_name_index), 1, file);
read_u4(&(cf->fields[i].attributes[j].attribute_length), 1, file);
// TODO: parse attributes by tag
// this has an unknown amount of layers, should be moved out to a function
cf->fields[i].attributes[j].info =
(u1 *)malloc(cf->fields[i].attributes[j].attribute_length);
fread(cf->fields[i].attributes[j].info,
@ -182,6 +184,8 @@ ClassFile *ClassFile_load(const char *path) {
// attribute_name_index 2bytes, attribute_length 4bytes
read_u2(&(cf->methods[i].attributes[j].attribute_name_index), 1, file);
read_u4(&(cf->methods[i].attributes[j].attribute_length), 1, file);
// TODO: parse attributes by tag
// this has an unknown amount of layers, should be moved out to a function
cf->methods[i].attributes[j].info =
(u1 *)malloc(cf->methods[i].attributes[j].attribute_length);
fread(cf->methods[i].attributes[j].info,
@ -200,6 +204,8 @@ ClassFile *ClassFile_load(const char *path) {
read_u2(&(cf->attributes[i].attribute_name_index), 1, file);
read_u4(&(cf->attributes[i].attribute_length), 1, file);
cf->attributes[i].info = (u1 *)malloc(cf->attributes[i].attribute_length);
// TODO: parse attributes by tag
// this has an unknown amount of layers, should be moved out to a function
fread(cf->attributes[i].info, cf->attributes[i].attribute_length, 1, file);
}

View File

@ -133,10 +133,79 @@ typedef struct {
} info;
} cp_info;
typedef struct {
u2 constantvalue_index;
} ConstantValue_attribute;
typedef struct {
u2 attribute_name_index;
u4 attribute_length;
u1 *info;
u2 max_stack;
u2 max_locals;
u4 code_length;
u1 *code;
u2 exception_table_length;
struct {
u2 start_pc;
u2 end_pc;
u2 handler_pc;
u2 catch_type;
} * exception_table;
u2 attributes_count;
void *attributes;
} Code_attribute;
// TODO: stack_map_frame
typedef struct {
u2 attribute_name_index;
u4 attribute_length;
u2 number_of_entries;
//stack_map_frame *entries;
} StackMapTable_attribute;
typedef struct {
u2 attribute_name_index;
u4 attribute_length;
u2 num_bootstrap_methods;
struct {
u2 bootstrap_method_ref;
u2 num_bootstrap_arguments;
u2 *bootstrap_arguments;
} * bootstrap_methods;
} BootstrapMethods_attribute;
typedef struct {
u2 attribute_name_index;
u4 attribute_length;
u2 host_class_index;
} NestHost_attribute;
typedef struct {
u2 attribute_name_index;
u4 attribute_length;
u2 number_of_classes;
u2 *classes;
} NestMembers_attribute;
typedef struct {
u2 attribute_name_index;
u4 attribute_length;
u2 number_of_classes;
u2 *classes;
} PermittedSubclasses_attribute;
typedef struct {
u2 attribute_name_index;
u4 attribute_length;
union {
ConstantValue_attribute constant_value_attribute;
Code_attribute code_attribute;
StackMapTable_attribute stack_map_table_attribute;
BootstrapMethods_attribute bootstrap_methods_attribute;
NestHost_attribute nest_host_attribute;
NestMembers_attribute nest_members_attribute;
PermittedSubclasses_attribute permitted_subclasses_attribute;
} info;
} attribute_info;
typedef struct {