JVM
validity.c File Reference
#include "validity.h"
#include "constantpool.h"
#include "utf8.h"
#include "readfunctions.h"
#include <locale.h>
#include <wctype.h>
#include <ctype.h>
Include dependency graph for validity.c:

Functions

char checkMethodAccessFlags (JavaClass *jc, uint16_t accessFlags)
 Checks whether the "accessFlags" parameter has a valid combination of method flags. More...
 
char checkFieldAccessFlags (JavaClass *jc, uint16_t accessFlags)
 Checks whether the "accessFlags" parameter has a valid combination of field flags. More...
 
char checkClassIndexAndAccessFlags (JavaClass *jc)
 Verifies the class indexes and access flags. More...
 
char checkClassNameFileNameMatch (JavaClass *jc, const char *classFilePath)
 Checks whether the name of the class pointed by "thisClass" is the same name as the class file. More...
 
char isValidJavaIdentifier (uint8_t *utf8_bytes, int32_t utf8_len, uint8_t isClassIdentifier)
 Checks whether the UTF-8 stream is a valid Java Identifier. More...
 
char isValidUTF8Index (JavaClass *jc, uint16_t index)
 Identifies if a UTF8 index in JavaClass is valid. More...
 
char isValidNameIndex (JavaClass *jc, uint16_t name_index, uint8_t isClassIdentifier)
 Identifies if a name index in JavaClass is valid. More...
 
char isValidMethodNameIndex (JavaClass *jc, uint16_t name_index)
 checks if the name index points to a valid UTF-8 and is a valid java identifier. More...
 
char checkClassIndex (JavaClass *jc, uint16_t class_index)
 Checks whether the index points to a valid class. More...
 
char checkFieldNameAndTypeIndex (JavaClass *jc, uint16_t name_and_type_index)
 Checks if the name and the descriptor of a field are valid. More...
 
char checkMethodNameAndTypeIndex (JavaClass *jc, uint16_t name_and_type_index)
 Checks if the name and the descriptor of a method are valid. More...
 
char checkConstantPoolValidity (JavaClass *jc)
 Iterates over the constant pool looking for inconsistencies in it. More...
 

Function Documentation

§ checkClassIndex()

char checkClassIndex ( JavaClass jc,
uint16_t  class_index 
)

Checks whether the index points to a valid class.

Parameters
JavaClass*jc - pointer to the class holding the constant pool
uint16_tclass_index - index to be check
Returns
In case the check fails, jc->status is changed and the function returns 0. If everything is successful, the function returns 1 while leaving jc unchanged.
Here is the caller graph for this function:

§ checkClassIndexAndAccessFlags()

char checkClassIndexAndAccessFlags ( JavaClass jc)

Verifies the class indexes and access flags.

Checks whether the accessFlags from the class file is a valid combination of class flags. This function also checks if "thisClass" and "superClass" points to valid class indexes.

Parameters
JavaClass*jc - pointer to the class to be checked
Returns
In case of issues, jc->status is changed, and the function returns 0. Otherwise, nothing is changed with jc, and the return value is 1. This function also
Here is the caller graph for this function:

§ checkClassNameFileNameMatch()

char checkClassNameFileNameMatch ( JavaClass jc,
const char *  classFilePath 
)

Checks whether the name of the class pointed by "thisClass" is the same name as the class file.

This function also checks if the folder location match with the class package.

Parameters
JavaClass*jc - pointer to the class holding the constant pool
Returns
If there is a mismatch, the function returns 0. Otherwise, the return value is 1.
Here is the call graph for this function:
Here is the caller graph for this function:

§ checkConstantPoolValidity()

char checkConstantPoolValidity ( JavaClass jc)

Iterates over the constant pool looking for inconsistencies in it.

Parameters
JavaClass*jc - pointer to the javaClass holding the constant pool to be checked.
Returns
If no error is encountered, the function returns 1. In case of failures, the function will set jc->status accordingly and will return 0.
Here is the call graph for this function:
Here is the caller graph for this function:

§ checkFieldAccessFlags()

char checkFieldAccessFlags ( JavaClass jc,
uint16_t  accessFlags 
)

Checks whether the "accessFlags" parameter has a valid combination of field flags.

The following status can be set by calling this function:

  • USE_OF_RESERVED_FIELD_ACCESS_FLAGS
  • INVALID_ACCESS_FLAGS
Parameters
JavaClass*jc - pointer to the class containing the field
uint16_taccessFlags - field flags to be checked
Returns
In case of issues, jc->status is changed, and the function returns 0. Otherwise, nothing is changed with jc, and the return value is 1.
Here is the caller graph for this function:

§ checkFieldNameAndTypeIndex()

char checkFieldNameAndTypeIndex ( JavaClass jc,
uint16_t  name_and_type_index 
)

Checks if the name and the descriptor of a field are valid.

Parameters
JavaClass*jc - pointer to the class holding the constant pool
uint16_tname_and_type_index - index of the name_and_type of a CONSTANT_Fieldref to be checked
Returns
In case of failure, the function changes jc->status and returns 0. Otherwise, jc is left unchanged, and the function returns 1.
Here is the call graph for this function:
Here is the caller graph for this function:

§ checkMethodAccessFlags()

char checkMethodAccessFlags ( JavaClass jc,
uint16_t  accessFlags 
)

Checks whether the "accessFlags" parameter has a valid combination of method flags.

The following status can be set by calling this function:

  • USE_OF_RESERVED_METHOD_ACCESS_FLAGS
  • INVALID_ACCESS_FLAGS
Parameters
JavaClass*jc - pointer to the class containing the method
uint16_taccessFlags - method flags to be checked
Returns
In case of issues, jc->status is changed, and the function returns 0. Otherwise, nothing is changed with jc, and the return value is 1.
Here is the caller graph for this function:

§ checkMethodNameAndTypeIndex()

char checkMethodNameAndTypeIndex ( JavaClass jc,
uint16_t  name_and_type_index 
)

Checks if the name and the descriptor of a method are valid.

Parameters
JavaClass*jc - pointer to the class holding the constant pool
uint16_tname_and_type_index - index of the name_and_type of a CONSTANT_Methodref to be checked
Returns
In case of failure, the function changes jc->status and returns 0. Otherwise, jc is left unchanged, and the function returns 1.
Here is the call graph for this function:
Here is the caller graph for this function:

§ isValidJavaIdentifier()

char isValidJavaIdentifier ( uint8_t *  utf8_bytes,
int32_t  utf8_len,
uint8_t  isClassIdentifier 
)

Checks whether the UTF-8 stream is a valid Java Identifier.

A java identifer (class name, variable name, etc) must start with underscore, dollar sign or letter, and could finish with numbers, letters, dollar sign or underscore.

Parameters
uint8_t*utf8_bytes - pointer to the sequence of bytes that identify the class name
int32_tutf8_len - legth of class name
uint8_tisClassIdentifier - if set to anything but zero, then this function will accept slashes (/) as valid characters for identifiers. Classes have their full path separated by slashes, so this must be set to any value other than zero to check classes.
Returns
The function returns 1 if it the string is indeed a valid Java Identifier, otherwise zero.
Here is the call graph for this function:
Here is the caller graph for this function:

§ isValidMethodNameIndex()

char isValidMethodNameIndex ( JavaClass jc,
uint16_t  name_index 
)

checks if the name index points to a valid UTF-8 and is a valid java identifier.

The difference between this function and isValidNameIndex() is that this function accepts "<init>" and "<clinit>" as valid names for methods, whereas isValidNameIndex() (when consenquently calling isValidJavaIdentifier()) wouldn't accept those names as valid.

Parameters
JavaClass*jc - pointer to the class holding the constant pool
uint16_tname_index - name_index to be check
Returns
Returns 1 if "name_index" points to a valid UTF-8 and is a valid java identifier. Returns 0 otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

§ isValidNameIndex()

char isValidNameIndex ( JavaClass jc,
uint16_t  name_index,
uint8_t  isClassIdentifier 
)

Identifies if a name index in JavaClass is valid.

Parameters
JavaClass*jc - pointer to the class holding the constant pool
uint8_tisClassIdentifier - if set to zero, will not accept slashes (/) as valid identifier characters. If "isClassIdentifier" is different than zero, then classes with slashes in its name like "java/io/Stream" will be accepted as valid names.
uint16_tname_index - name_index to be checked.
Returns
Returns 1 if "name_index" points to a valid UTF-8 and is a valid java identifier. Returns 0 otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

§ isValidUTF8Index()

char isValidUTF8Index ( JavaClass jc,
uint16_t  index 
)

Identifies if a UTF8 index in JavaClass is valid.

Parameters
JavaClass*jc - pointer to the class holding the constant pool
uint16_tindex - index of the UTF-8 constant in the constant pool
Note
This function does not check if the UTF-8 stream is valid, and it it not necessary. UTF-8 streams are checked as they are read. To see that check, see file utf8.c.
Returns
Returns 1 if the index points to a UTF-8 constant, 0 otherwise.
Here is the caller graph for this function: