JVM
javaclass.h File Reference
#include <stdio.h>
#include <stdint.h>
#include "constantpool.h"
#include "attributes.h"
#include "fields.h"
#include "methods.h"
Include dependency graph for javaclass.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  JavaClass
 

Typedefs

typedef struct JavaClass JavaClass
 

Enumerations

enum  AccessFlagsType { ACCT_CLASS, ACCT_FIELD, ACCT_METHOD, ACCT_INNERCLASS }
 
enum  AccessFlags {
  ACC_PUBLIC = 0x0001, ACC_PRIVATE = 0x0002, ACC_PROTECTED = 0x0004, ACC_STATIC = 0x0008,
  ACC_FINAL = 0x0010, ACC_SUPER = 0x0020, ACC_SYNCHRONIZED = 0x0020, ACC_BRIDGE = 0x0040,
  ACC_VOLATILE = 0x0040, ACC_TRANSIENT = 0x0080, ACC_VARARGS = 0x0080, ACC_NATIVE = 0x0100,
  ACC_INTERFACE = 0x0200, ACC_ABSTRACT = 0x0400, ACC_STRICT = 0x0800, ACC_SYNTHETIC = 0x1000,
  ACC_INVALID_CLASS_FLAG_MASK = ~(ACC_PUBLIC | ACC_FINAL | ACC_SUPER | ACC_INTERFACE | ACC_ABSTRACT), ACC_INVALID_FIELD_FLAG_MASK, ACC_INVALID_METHOD_FLAG_MASK, ACC_INVALID_INNERCLASS_FLAG_MASK
}
 
enum  JavaClassStatus {
  CLASS_STATUS_OK, CLASS_STATUS_UNSUPPORTED_VERSION, CLASS_STATUS_FILE_COULDNT_BE_OPENED, CLASS_STATUS_INVALID_SIGNATURE,
  MEMORY_ALLOCATION_FAILED, INVALID_CONSTANT_POOL_COUNT, UNEXPECTED_EOF, UNEXPECTED_EOF_READING_CONSTANT_POOL,
  UNEXPECTED_EOF_READING_UTF8, UNEXPECTED_EOF_READING_INTERFACES, UNEXPECTED_EOF_READING_ATTRIBUTE_INFO, INVALID_UTF8_BYTES,
  INVALID_CONSTANT_POOL_INDEX, UNKNOWN_CONSTANT_POOL_TAG, INVALID_ACCESS_FLAGS, USE_OF_RESERVED_CLASS_ACCESS_FLAGS,
  USE_OF_RESERVED_METHOD_ACCESS_FLAGS, USE_OF_RESERVED_FIELD_ACCESS_FLAGS, INVALID_THIS_CLASS_INDEX, INVALID_SUPER_CLASS_INDEX,
  INVALID_INTERFACE_INDEX, INVALID_FIELD_DESCRIPTOR_INDEX, INVALID_METHOD_DESCRIPTOR_INDEX, INVALID_NAME_INDEX,
  INVALID_STRING_INDEX, INVALID_CLASS_INDEX, INVALID_NAME_AND_TYPE_INDEX, INVALID_JAVA_IDENTIFIER,
  ATTRIBUTE_LENGTH_MISMATCH, ATTRIBUTE_INVALID_CONSTANTVALUE_INDEX, ATTRIBUTE_INVALID_SOURCEFILE_INDEX, ATTRIBUTE_INVALID_INNERCLASS_INDEXES,
  ATTRIBUTE_INVALID_EXCEPTIONS_CLASS_INDEX, ATTRIBUTE_INVALID_CODE_LENGTH, FILE_CONTAINS_UNEXPECTED_DATA
}
 

Functions

void openClassFile (JavaClass *jc, const char *path)
 Opens a class file and parse it, storing the class information in the JavaClass structure. More...
 
void closeClassFile (JavaClass *jc)
 Closes the .class file and releases resources used by the JavaClass struct. More...
 
const char * decodeJavaClassStatus (enum JavaClassStatus)
 Decodes JavaClassStatus enumeration elements. More...
 
void decodeAccessFlags (uint16_t flags, char *buffer, int32_t buffer_len, enum AccessFlagsType acctype)
 Given flags of a certain method/field/class, this class will convert the bits to a string telling which flags are set to 1, writing the result in the output buffer. More...
 
void printClassFileDebugInfo (JavaClass *jc)
 
void printClassFileInfo (JavaClass *jc)
 

Typedef Documentation

§ JavaClass

typedef struct JavaClass JavaClass

Enumeration Type Documentation

§ AccessFlags

Enumerator
ACC_PUBLIC 
ACC_PRIVATE 
ACC_PROTECTED 
ACC_STATIC 
ACC_FINAL 
ACC_SUPER 
ACC_SYNCHRONIZED 
ACC_BRIDGE 
ACC_VOLATILE 
ACC_TRANSIENT 
ACC_VARARGS 
ACC_NATIVE 
ACC_INTERFACE 
ACC_ABSTRACT 
ACC_STRICT 
ACC_SYNTHETIC 
ACC_INVALID_CLASS_FLAG_MASK 
ACC_INVALID_FIELD_FLAG_MASK 
ACC_INVALID_METHOD_FLAG_MASK 
ACC_INVALID_INNERCLASS_FLAG_MASK 

§ AccessFlagsType

Enumerator
ACCT_CLASS 
ACCT_FIELD 
ACCT_METHOD 
ACCT_INNERCLASS 

§ JavaClassStatus

Enumerator
CLASS_STATUS_OK 
CLASS_STATUS_UNSUPPORTED_VERSION 
CLASS_STATUS_FILE_COULDNT_BE_OPENED 
CLASS_STATUS_INVALID_SIGNATURE 
MEMORY_ALLOCATION_FAILED 
INVALID_CONSTANT_POOL_COUNT 
UNEXPECTED_EOF 
UNEXPECTED_EOF_READING_CONSTANT_POOL 
UNEXPECTED_EOF_READING_UTF8 
UNEXPECTED_EOF_READING_INTERFACES 
UNEXPECTED_EOF_READING_ATTRIBUTE_INFO 
INVALID_UTF8_BYTES 
INVALID_CONSTANT_POOL_INDEX 
UNKNOWN_CONSTANT_POOL_TAG 
INVALID_ACCESS_FLAGS 
USE_OF_RESERVED_CLASS_ACCESS_FLAGS 
USE_OF_RESERVED_METHOD_ACCESS_FLAGS 
USE_OF_RESERVED_FIELD_ACCESS_FLAGS 
INVALID_THIS_CLASS_INDEX 
INVALID_SUPER_CLASS_INDEX 
INVALID_INTERFACE_INDEX 
INVALID_FIELD_DESCRIPTOR_INDEX 
INVALID_METHOD_DESCRIPTOR_INDEX 
INVALID_NAME_INDEX 
INVALID_STRING_INDEX 
INVALID_CLASS_INDEX 
INVALID_NAME_AND_TYPE_INDEX 
INVALID_JAVA_IDENTIFIER 
ATTRIBUTE_LENGTH_MISMATCH 
ATTRIBUTE_INVALID_CONSTANTVALUE_INDEX 
ATTRIBUTE_INVALID_SOURCEFILE_INDEX 
ATTRIBUTE_INVALID_INNERCLASS_INDEXES 
ATTRIBUTE_INVALID_EXCEPTIONS_CLASS_INDEX 
ATTRIBUTE_INVALID_CODE_LENGTH 
FILE_CONTAINS_UNEXPECTED_DATA 

Function Documentation

§ closeClassFile()

void closeClassFile ( JavaClass jc)

Closes the .class file and releases resources used by the JavaClass struct.

Parameters
JavaClass*jc - pointer to the class to be closed.
Note
This function does not free the *jc pointer.
See also
openClassFile()
Here is the call graph for this function:
Here is the caller graph for this function:

§ decodeAccessFlags()

void decodeAccessFlags ( uint16_t  flags,
char *  buffer,
int32_t  buffer_len,
enum AccessFlagsType  acctype 
)

Given flags of a certain method/field/class, this class will convert the bits to a string telling which flags are set to 1, writing the result in the output buffer.

Parameters
uint16_tflags - the flags of the method/field/class
[out]char*buffer - pointer to where the string will be stored
int32_tbuffer_len - length of the buffer
enumAccessFlagsType acctype - type of access flags, telling if it is a class, a method or a field.

This method will write at most buffer_len characters to the output buffer. Depending on parameter acctype, meaning for some bits might change.

Here is the call graph for this function:
Here is the caller graph for this function:

§ decodeJavaClassStatus()

const char* decodeJavaClassStatus ( enum JavaClassStatus  status)

Decodes JavaClassStatus enumeration elements.

Parameters
enumJavaClassStatus status - identifier of the enumeration to be translated.
Returns
const char* - pointer to char containing the decoded status
Here is the caller graph for this function:

§ openClassFile()

void openClassFile ( JavaClass jc,
const char *  path 
)

Opens a class file and parse it, storing the class information in the JavaClass structure.

Parameters
JavaClass*jc - pointer to the structure that will hold the class data
constchar* path - string containing the path to the class file to be read

This function opens the .class file and reads its content from the file by filling in the fields of the JavaClass struct. A bunch of other functions from different modules are called to read some pieces of the class file. Various checks are made during the parsing of the read data.

See also
closeClassFile, printClassFileInfo(), printClassFileDebugInfo()
Here is the call graph for this function:
Here is the caller graph for this function:

§ printClassFileDebugInfo()

void printClassFileDebugInfo ( JavaClass jc)
Here is the caller graph for this function:

§ printClassFileInfo()

void printClassFileInfo ( JavaClass jc)
Here is the caller graph for this function: