LibJClass Reference Manual |
---|
Class — Main class structure.
#include <jclass/class.h> typedef JavaClass; #define JAVA_CLASS_MAGIC #define ACC_PUBLIC #define ACC_PRIVATE #define ACC_PROTECTED #define ACC_STATIC #define ACC_FINAL #define ACC_SYNCHRONIZED #define ACC_VOLATILE #define ACC_TRANSIENT #define ACC_NATIVE #define ACC_INTERFACE #define ACC_ABSTRACT #define ACC_STRICTFP JavaClass* jclass_class_new (const char *filename, const ClassPath *classpath); JavaClass* jclass_class_new_from_buffer (const char *data); JavaClass* jclass_class_new_from_file (FILE *classfile); void jclass_class_free (JavaClass *javaclass); const char* jclass_class_get_vm_spec (JavaClass *javaclass); char* jclass_class_get_class_name (JavaClass *javaclass); char* jclass_class_get_super_class_name (JavaClass *javaclass); char* jclass_class_get_package_name (JavaClass *javaclass); char** jclass_class_get_interfaces (JavaClass *class_struct); char* jclass_class_get_sourcefile_name (JavaClass *javaclass);
typedef struct { /* Minor version of the class file specification */ uint16_t minor_version; /* Major version of the class file specification */ uint16_t major_version; /* The constant pool */ ConstantPool *constant_pool; /* A 16-bit access flag.*/ uint16_t access_flags; /* The number of interfaces implemented by this class */ uint16_t interfaces_count; /* An array with the constant pool indices of the ClassEntry entries * for the interfaces implemented by this class */ uint16_t *interfaces; /* The number of fields this class has */ uint16_t fields_count; /* An array with the fields for this class */ Field *fields; /* The number of methods this class has */ uint16_t methods_count; /* An array with the method for this class */ Field *methods; /* The number of attributes for this class */ uint16_t attributes_count; /* An array with the attributes for this class */ AttributeContainer *attributes; } JavaClass;
Holds information about a class. Everything is stored in native order with the exception of the of attributes. They are stored big-endian inside their AttributeContainer.
#define ACC_SYNCHRONIZED 0x0020
Mask for synchronized.
#define ACC_STRICTFP 0x0800
Mask to indicate that strict IEEE-754 floating point behavior is required.
JavaClass* jclass_class_new (const char *filename, const ClassPath *classpath);
Initializes a new JavaClass struct with info from the given file/class. If parsing fails it returns NULL. Use jclass_class_free() to free the class.
filename : | The filename or classname for the class. |
classpath : | The classpath to use to locate the class. |
Returns : | A JavaClass struct allocated with malloc. |
JavaClass* jclass_class_new_from_buffer (const char *data);
Creates a JavaClass struct from the given buffer. The buffer should be in the same format as a class file.
data : | The buffer containing the class. |
Returns : | A JavaClass struct allocated with malloc. |
JavaClass* jclass_class_new_from_file (FILE *classfile);
Creates a JavaClass struct from the given class file. The file must be opened with "rb" permissions. The file will always be closed when the function returns.
classfile : | The file containing the class. |
Returns : | A JavaClass struct allocated with malloc. |
void jclass_class_free (JavaClass *javaclass);
Frees a JavaClass struct.
javaclass : | The JavaClass struct to free. |
const char* jclass_class_get_vm_spec (JavaClass *javaclass);
Gives the minimum VM spec needed to run this class. The function returns a pointer to a constant string. Do not free it!
javaclass : | The class to get the VM spec for. |
Returns : | A statically allocated string. |
char* jclass_class_get_class_name (JavaClass *javaclass);
Gives the fully qualified name of the class.
javaclass : | The JavaClass that we want the class name for. |
Returns : | A string allocated with malloc. |
char* jclass_class_get_super_class_name (JavaClass *javaclass);
Gives the fully qualified name of the super class for the given class.
javaclass : | The class that we want the super class name for. |
Returns : | A string allocated with malloc. |
char* jclass_class_get_package_name (JavaClass *javaclass);
Gives the name of the package this class is part of. If the class is not in a package it returns NULL.
javaclass : | The class to get its package name. |
Returns : | A string allocated with malloc. |
char** jclass_class_get_interfaces (JavaClass *class_struct);
Gives a null terminated array with the names of all interfaces implemented by the given class. If the class does not implement anything it returns NULL.
Since: 0.4
class_struct : | The class to get its interfaces. |
Returns : | A string allocated with malloc. |
char* jclass_class_get_sourcefile_name (JavaClass *javaclass);
Gives the name of the source file used to compile this class. If the class does not have a SourceFile attribute it returns NULL.
javaclass : | The class. |
Returns : | A string allocated with malloc. |
<< API Reference | Constant pool >> |