Rizin
unix-like reverse engineering framework and cli tools
class_attribute.h File Reference
#include <rz_types.h>
#include <rz_util.h>
#include <rz_bin.h>
#include "class_exceptions.h"
#include "class_line_number.h"
#include "class_local_variable.h"
#include "class_module.h"
#include "class_const_pool.h"

Go to the source code of this file.

Classes

struct  java_attribute_t
 
struct  java_attribute_constant_value_t
 
struct  java_attribute_code_t
 
struct  java_attribute_source_file_t
 
struct  java_attribute_line_number_table_t
 
struct  java_attribute_local_variable_table_t
 
struct  java_attribute_local_variable_type_table_t
 
struct  java_attribute_module_t
 
struct  java_attribute_module_packages_t
 
struct  java_attribute_module_main_class_t
 

Typedefs

typedef struct java_attribute_t Attribute
 
typedef struct java_attribute_constant_value_t AttributeConstantValue
 
typedef struct java_attribute_code_t AttributeCode
 
typedef struct java_attribute_source_file_t AttributeSourceFile
 
typedef struct java_attribute_line_number_table_t AttributeLineNumberTable
 
typedef struct java_attribute_local_variable_table_t AttributeLocalVariableTable
 
typedef struct java_attribute_local_variable_type_table_t AttributeLocalVariableTypeTable
 
typedef struct java_attribute_module_t AttributeModule
 
typedef struct java_attribute_module_packages_t AttributeModulePackages
 
typedef struct java_attribute_module_main_class_t AttributeModuleMainClass
 

Enumerations

enum  AttributeType {
  ATTRIBUTE_TYPE_INVALID = 0 , ATTRIBUTE_TYPE_UNKNOWN , ATTRIBUTE_TYPE_CONSTANTVALUE , ATTRIBUTE_TYPE_CODE ,
  ATTRIBUTE_TYPE_STACKMAPTABLE , ATTRIBUTE_TYPE_EXCEPTIONS , ATTRIBUTE_TYPE_INNERCLASSES , ATTRIBUTE_TYPE_ENCLOSINGMETHOD ,
  ATTRIBUTE_TYPE_SYNTHETIC , ATTRIBUTE_TYPE_SIGNATURE , ATTRIBUTE_TYPE_SOURCEFILE , ATTRIBUTE_TYPE_SOURCEDEBUGEXTENSION ,
  ATTRIBUTE_TYPE_LINENUMBERTABLE , ATTRIBUTE_TYPE_LOCALVARIABLETABLE , ATTRIBUTE_TYPE_LOCALVARIABLETYPETABLE , ATTRIBUTE_TYPE_DEPRECATED ,
  ATTRIBUTE_TYPE_RUNTIMEVISIBLEANNOTATIONS , ATTRIBUTE_TYPE_RUNTIMEINVISIBLEANNOTATIONS , ATTRIBUTE_TYPE_RUNTIMEVISIBLEPARAMETERANNOTATIONS , ATTRIBUTE_TYPE_RUNTIMEINVISIBLEPARAMETERANNOTATIONS ,
  ATTRIBUTE_TYPE_RUNTIMEVISIBLETYPEANNOTATIONS , ATTRIBUTE_TYPE_RUNTIMEINVISIBLETYPEANNOTATIONS , ATTRIBUTE_TYPE_ANNOTATIONDEFAULT , ATTRIBUTE_TYPE_BOOTSTRAPMETHODS ,
  ATTRIBUTE_TYPE_METHODPARAMETERS , ATTRIBUTE_TYPE_MODULE , ATTRIBUTE_TYPE_MODULEPACKAGES , ATTRIBUTE_TYPE_MODULEMAINCLASS ,
  ATTRIBUTE_TYPE_NESTHOST , ATTRIBUTE_TYPE_NESTMEMBERS
}
 

Functions

Attributejava_attribute_new (RzBuffer *buf, ut64 offset)
 
void java_attribute_free (Attribute *attr)
 
bool java_attribute_resolve (ConstPool **pool, ut32 poolsize, Attribute *attr, RzBuffer *buf, bool is_oak)
 

Typedef Documentation

◆ Attribute

typedef struct java_attribute_t Attribute

◆ AttributeCode

◆ AttributeConstantValue

◆ AttributeLineNumberTable

◆ AttributeLocalVariableTable

◆ AttributeLocalVariableTypeTable

◆ AttributeModule

◆ AttributeModuleMainClass

◆ AttributeModulePackages

◆ AttributeSourceFile

Enumeration Type Documentation

◆ AttributeType

Enumerator
ATTRIBUTE_TYPE_INVALID 
ATTRIBUTE_TYPE_UNKNOWN 
ATTRIBUTE_TYPE_CONSTANTVALUE 
ATTRIBUTE_TYPE_CODE 
ATTRIBUTE_TYPE_STACKMAPTABLE 
ATTRIBUTE_TYPE_EXCEPTIONS 
ATTRIBUTE_TYPE_INNERCLASSES 
ATTRIBUTE_TYPE_ENCLOSINGMETHOD 
ATTRIBUTE_TYPE_SYNTHETIC 
ATTRIBUTE_TYPE_SIGNATURE 
ATTRIBUTE_TYPE_SOURCEFILE 
ATTRIBUTE_TYPE_SOURCEDEBUGEXTENSION 
ATTRIBUTE_TYPE_LINENUMBERTABLE 
ATTRIBUTE_TYPE_LOCALVARIABLETABLE 
ATTRIBUTE_TYPE_LOCALVARIABLETYPETABLE 
ATTRIBUTE_TYPE_DEPRECATED 
ATTRIBUTE_TYPE_RUNTIMEVISIBLEANNOTATIONS 
ATTRIBUTE_TYPE_RUNTIMEINVISIBLEANNOTATIONS 
ATTRIBUTE_TYPE_RUNTIMEVISIBLEPARAMETERANNOTATIONS 
ATTRIBUTE_TYPE_RUNTIMEINVISIBLEPARAMETERANNOTATIONS 
ATTRIBUTE_TYPE_RUNTIMEVISIBLETYPEANNOTATIONS 
ATTRIBUTE_TYPE_RUNTIMEINVISIBLETYPEANNOTATIONS 
ATTRIBUTE_TYPE_ANNOTATIONDEFAULT 
ATTRIBUTE_TYPE_BOOTSTRAPMETHODS 
ATTRIBUTE_TYPE_METHODPARAMETERS 
ATTRIBUTE_TYPE_MODULE 
ATTRIBUTE_TYPE_MODULEPACKAGES 
ATTRIBUTE_TYPE_MODULEMAINCLASS 
ATTRIBUTE_TYPE_NESTHOST 
ATTRIBUTE_TYPE_NESTMEMBERS 

Definition at line 15 of file class_attribute.h.

15  {
17  ATTRIBUTE_TYPE_UNKNOWN, // will be used only when parsing an unknown attribute
18 
19  ATTRIBUTE_TYPE_CONSTANTVALUE, /* Java SE 1.0.2 */
20  ATTRIBUTE_TYPE_CODE, /* Java SE 1.0.2 */
21  ATTRIBUTE_TYPE_STACKMAPTABLE, /* Java SE 6 */
22  ATTRIBUTE_TYPE_EXCEPTIONS, /* Java SE 1.0.2 */
23  ATTRIBUTE_TYPE_INNERCLASSES, /* Java SE 1.1 */
24  ATTRIBUTE_TYPE_ENCLOSINGMETHOD, /* Java SE 5.0 */
25  ATTRIBUTE_TYPE_SYNTHETIC, /* Java SE 1.1 */
26  ATTRIBUTE_TYPE_SIGNATURE, /* Java SE 5.0 */
27  ATTRIBUTE_TYPE_SOURCEFILE, /* Java SE 1.0.2 */
28  ATTRIBUTE_TYPE_SOURCEDEBUGEXTENSION, /* Java SE 5.0 */
29  ATTRIBUTE_TYPE_LINENUMBERTABLE, /* Java SE 1.0.2 */
30  ATTRIBUTE_TYPE_LOCALVARIABLETABLE, /* Java SE 1.0.2 */
31  ATTRIBUTE_TYPE_LOCALVARIABLETYPETABLE, /* Java SE 5.0 */
32  ATTRIBUTE_TYPE_DEPRECATED, /* Java SE 1.1 */
39  ATTRIBUTE_TYPE_ANNOTATIONDEFAULT, /* Java SE 5.0 */
40  ATTRIBUTE_TYPE_BOOTSTRAPMETHODS, /* Java SE 7 */
41  ATTRIBUTE_TYPE_METHODPARAMETERS, /* Java SE 8 */
42  ATTRIBUTE_TYPE_MODULE, /* Java SE 9 */
43  ATTRIBUTE_TYPE_MODULEPACKAGES, /* Java SE 9 */
44  ATTRIBUTE_TYPE_MODULEMAINCLASS, /* Java SE 9 */
45  ATTRIBUTE_TYPE_NESTHOST, /* Java SE 11 */
46  ATTRIBUTE_TYPE_NESTMEMBERS /* Java SE 11 */
AttributeType
@ ATTRIBUTE_TYPE_BOOTSTRAPMETHODS
@ ATTRIBUTE_TYPE_MODULEMAINCLASS
@ ATTRIBUTE_TYPE_SYNTHETIC
@ ATTRIBUTE_TYPE_EXCEPTIONS
@ ATTRIBUTE_TYPE_RUNTIMEINVISIBLETYPEANNOTATIONS
@ ATTRIBUTE_TYPE_CODE
@ ATTRIBUTE_TYPE_ENCLOSINGMETHOD
@ ATTRIBUTE_TYPE_SOURCEFILE
@ ATTRIBUTE_TYPE_MODULEPACKAGES
@ ATTRIBUTE_TYPE_ANNOTATIONDEFAULT
@ ATTRIBUTE_TYPE_INNERCLASSES
@ ATTRIBUTE_TYPE_INVALID
@ ATTRIBUTE_TYPE_SIGNATURE
@ ATTRIBUTE_TYPE_LOCALVARIABLETYPETABLE
@ ATTRIBUTE_TYPE_MODULE
@ ATTRIBUTE_TYPE_RUNTIMEINVISIBLEANNOTATIONS
@ ATTRIBUTE_TYPE_RUNTIMEINVISIBLEPARAMETERANNOTATIONS
@ ATTRIBUTE_TYPE_LOCALVARIABLETABLE
@ ATTRIBUTE_TYPE_DEPRECATED
@ ATTRIBUTE_TYPE_CONSTANTVALUE
@ ATTRIBUTE_TYPE_UNKNOWN
@ ATTRIBUTE_TYPE_LINENUMBERTABLE
@ ATTRIBUTE_TYPE_SOURCEDEBUGEXTENSION
@ ATTRIBUTE_TYPE_RUNTIMEVISIBLETYPEANNOTATIONS
@ ATTRIBUTE_TYPE_NESTHOST
@ ATTRIBUTE_TYPE_NESTMEMBERS
@ ATTRIBUTE_TYPE_RUNTIMEVISIBLEPARAMETERANNOTATIONS
@ ATTRIBUTE_TYPE_METHODPARAMETERS
@ ATTRIBUTE_TYPE_RUNTIMEVISIBLEANNOTATIONS
@ ATTRIBUTE_TYPE_STACKMAPTABLE

Function Documentation

◆ java_attribute_free()

void java_attribute_free ( Attribute attr)

Definition at line 559 of file class_attribute.c.

559  {
560  if (!attr || !attr->info) {
561  free(attr);
562  return;
563  }
564  if (attr->type == ATTRIBUTE_TYPE_CODE) {
565  AttributeCode *ac = (AttributeCode *)attr->info;
566  free(ac->exceptions);
567  if (ac->attributes) {
568  for (ut32 i = 0; i < ac->attributes_count; ++i) {
570  }
571  free(ac->attributes);
572  }
573  } else if (attr->type == ATTRIBUTE_TYPE_LINENUMBERTABLE) {
575  free(alnt->table);
576  } else if (attr->type == ATTRIBUTE_TYPE_LOCALVARIABLETABLE) {
578  free(alvt->table);
579  } else if (attr->type == ATTRIBUTE_TYPE_MODULE) {
580  AttributeModule *am = (AttributeModule *)attr->info;
581  for (ut32 i = 0; i < am->exports_count; ++i) {
582  free(am->exports[i].to_indices);
583  }
584  for (ut32 i = 0; i < am->opens_count; ++i) {
585  free(am->opens[i].to_indices);
586  }
587  for (ut32 i = 0; i < am->provides_count; ++i) {
588  free(am->provides[i].with_indices);
589  }
590  free(am->uses_index);
591  free(am->exports);
592  free(am->requires);
593  } else if (attr->type == ATTRIBUTE_TYPE_MODULEPACKAGES) {
595  free(amp->package_index);
596  }
597  free(attr->info);
598  free(attr);
599 }
lzma_index ** i
Definition: index.h:629
void java_attribute_free(Attribute *attr)
uint32_t ut32
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
ExceptionTable * exceptions
ModuleProvide * provides
ModuleRequire * requires
AttributeType type

References ATTRIBUTE_TYPE_CODE, ATTRIBUTE_TYPE_LINENUMBERTABLE, ATTRIBUTE_TYPE_LOCALVARIABLETABLE, ATTRIBUTE_TYPE_MODULE, ATTRIBUTE_TYPE_MODULEPACKAGES, java_attribute_code_t::attributes, java_attribute_code_t::attributes_count, java_attribute_code_t::exceptions, java_attribute_module_t::exports, java_attribute_module_t::exports_count, free(), i, java_attribute_t::info, java_attribute_module_t::opens, java_attribute_module_t::opens_count, java_attribute_module_packages_t::package_index, java_attribute_module_t::provides, java_attribute_module_t::provides_count, java_attribute_module_t::requires, java_attribute_line_number_table_t::table, java_attribute_local_variable_table_t::table, java_module_open_t::to_indices, java_module_export_t::to_indices, java_attribute_t::type, java_attribute_module_t::uses_index, and java_module_provide_t::with_indices.

Referenced by java_attribute_set_code(), java_class_parse(), java_field_free(), java_field_new(), java_method_free(), java_method_new(), and rz_bin_java_class_free().

◆ java_attribute_new()

Attribute* java_attribute_new ( RzBuffer buf,
ut64  offset 
)

Definition at line 540 of file class_attribute.c.

540  {
541  Attribute *attr = RZ_NEW0(Attribute);
543 
544  attr->offset = offset;
545 
546  if (!rz_buf_read_be16(buf, &attr->attribute_name_index)) {
547  free(attr);
548  return NULL;
549  }
550 
551  if (!rz_buf_read_be32(buf, &attr->attribute_length)) {
552  free(attr);
553  return NULL;
554  }
555 
556  return attr;
557 }
#define NULL
Definition: cris-opc.c:27
voidpf uLong offset
Definition: ioapi.h:144
voidpf void * buf
Definition: ioapi.h:138
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
#define rz_buf_read_be16(b, result)
Definition: rz_buf.h:280
#define rz_buf_read_be32(b, result)
Definition: rz_buf.h:281
#define RZ_NEW0(x)
Definition: rz_types.h:284

References java_attribute_t::attribute_length, java_attribute_t::attribute_name_index, free(), NULL, java_attribute_t::offset, rz_buf_read_be16, rz_buf_read_be32, RZ_NEW0, and rz_return_val_if_fail.

Referenced by java_attribute_set_code(), java_class_parse(), java_field_new(), and java_method_new().

◆ java_attribute_resolve()

bool java_attribute_resolve ( ConstPool **  pool,
ut32  poolsize,
Attribute attr,
RzBuffer buf,
bool  is_oak 
)

Definition at line 504 of file class_attribute.c.

504  {
505  char *name = resolve_const_pool_index(pool, poolsize, attr->attribute_name_index);
506  if (!name) {
507  return false;
508  }
509 
510  bool result = false;
511  if (!strcmp(name, "ConstantValue")) {
512  result = java_attribute_set_constantvalue(attr, buf);
513  } else if (!strcmp(name, "Code")) {
514  result = java_attribute_set_code(pool, poolsize, attr, buf, is_oak);
515  } else if (!strcmp(name, "SourceFile")) {
516  result = java_attribute_set_sourcefile(attr, buf);
517  } else if (!strcmp(name, "SourceDebugExtension")) {
519  } else if (!strcmp(name, "LineNumberTable")) {
520  result = java_attribute_set_linenumbertable(attr, buf);
521  } else if (!strcmp(name, "LocalVariableTable")) {
523  } else if (!strcmp(name, "LocalVariableTypeTable")) {
525  } else if (!strcmp(name, "Module")) {
526  result = java_attribute_set_module(attr, buf);
527  } else if (!strcmp(name, "ModulePackages")) {
528  result = java_attribute_set_modulepackages(attr, buf);
529  } else if (!strcmp(name, "ModuleMainClass")) {
530  result = java_attribute_set_modulemainclass(attr, buf);
531  }
532 
533  if (!result) {
534  result = java_attribute_set_unknown(attr, buf);
535  }
536  free(name);
537  return result;
538 }
bool java_attribute_set_sourcefile(Attribute *attr, RzBuffer *buf)
bool java_attribute_set_localvariabletypetable(Attribute *attr, RzBuffer *buf)
bool java_attribute_set_modulemainclass(Attribute *attr, RzBuffer *buf)
bool java_attribute_set_module(Attribute *attr, RzBuffer *buf)
bool java_attribute_set_sourcedebugextension(Attribute *attr, RzBuffer *buf)
bool java_attribute_set_modulepackages(Attribute *attr, RzBuffer *buf)
bool java_attribute_set_localvariabletable(Attribute *attr, RzBuffer *buf)
static char * resolve_const_pool_index(ConstPool **pool, ut32 poolsize, ut32 index)
bool java_attribute_set_code(ConstPool **pool, ut32 poolsize, Attribute *attr, RzBuffer *buf, bool is_oak)
bool java_attribute_set_linenumbertable(Attribute *attr, RzBuffer *buf)
bool java_attribute_set_unknown(Attribute *attr, RzBuffer *buf)
bool java_attribute_set_constantvalue(Attribute *attr, RzBuffer *buf)
Definition: z80asm.h:102

References java_attribute_t::attribute_name_index, free(), java_attribute_set_code(), java_attribute_set_constantvalue(), java_attribute_set_linenumbertable(), java_attribute_set_localvariabletable(), java_attribute_set_localvariabletypetable(), java_attribute_set_module(), java_attribute_set_modulemainclass(), java_attribute_set_modulepackages(), java_attribute_set_sourcedebugextension(), java_attribute_set_sourcefile(), java_attribute_set_unknown(), and resolve_const_pool_index().

Referenced by java_attribute_set_code(), java_class_parse(), java_field_new(), and java_method_new().