CaVM/include/ClassFormat.h
2024-08-24 23:36:22 -04:00

112 lines
2.7 KiB
C++

#ifndef __JAVA_PARSER_CLASS_FORMAT_H
#define __JAVA_PARSER_CLASS_FORMAT_H
#include <SpecTypes.h>
#include <any>
#include <cstdlib>
#include <vector>
#include <ConstantPoolTags/Tags.h>
namespace FieldInfo
{
enum class ACCESS_FLAGS
{
ACC_PUBLIC = 0x0001,
ACC_PRIVATE,
ACC_PROTECTED = 0x0004,
ACC_STATIC = 0x0008,
ACC_FINAL = 0x0010,
ACC_VOLATILE = 0x0040,
ACC_TRANSIENT = 0x0080,
ACC_SYNTHETIC = 0x1000,
ACC_ENUM = 0x4000
};
} // namespace FieldInfo
namespace JavaClass
{
enum class ACCESS_FLAGS
{
ACC_PUBLIC = 0x0001,
ACC_FINAL = 0x0010,
ACC_SUPER = 0x0020,
ACC_INTERFACE = 0x0200,
ACC_ABSTRACT = 0x0400,
ACC_SYNTHETIC = 0x1000,
ACC_ANNOTATION = 0x2000,
ACC_ENUM = 0x4000,
ACC_MODULE = 0x8000
};
} // namespace JavaClass
namespace Method
{
enum class ACCESS_FLAGS
{
ACC_PUBLIC = 0x0001, // Declared public; may be accessed from outside its package.
ACC_PRIVATE = 0x0002, // Declared private; accessible only within the defining class and other classes belonging to the same nest (§5.4.4).
ACC_PROTECTED = 0x0004, // Declared protected; may be accessed within subclasses.
ACC_STATIC = 0x0008, // Declared static.
ACC_FINAL = 0x0010, // Declared final; must not be overridden (§5.4.5).
ACC_SYNCHRONIZED = 0x0020, // Declared synchronized; invocation is wrapped by a monitor use.
ACC_BRIDGE = 0x0040, // A bridge method, generated by the compiler.
ACC_VARARGS = 0x0080, // Declared with variable number of arguments.
ACC_NATIVE = 0x0100, // Declared native; implemented in a language other than the Java programming language.
ACC_ABSTRACT = 0x0400, // Declared abstract; no implementation is provided.
ACC_STRICT = 0x0800, // In a class file whose major version number is at least 46 and at most 60: Declared strictfp.
ACC_SYNTHETIC = 0x1000 // Declared synthetic; not present in the source code.
};
} // namespace Method
struct BaseAttribute
{
u2 attribute_name_index;
u4 attribute_length;
};
struct attribute_info
{
u2 attribute_name_index;
u4 attribute_length;
std::vector<u1> info;
};
struct method_info
{
u2 access_flags;
u2 name_index;
u2 descriptor_index;
u2 attributes_count;
std::vector<attribute_info> attributes;
};
struct field_info
{
u2 access_flags;
u2 name_index;
u2 descriptor_index;
u2 attributes_count;
std::vector<attribute_info> attributes;
};
struct JavaClassFormat
{
u4 magic;
u2 minor;
u2 major;
u2 constant_pool_count;
std::vector<std::any> constant_pool;
u2 access_flags;
u2 this_class;
u2 super_class;
u2 interfaces_count;
std::vector<u2> interfaces;
u2 fields_count;
std::vector<field_info> fields;
u2 methods_count;
std::vector<method_info> methods;
u2 attributes_count;
std::vector<attribute_info> attributes;
};
#endif