Rizin
unix-like reverse engineering framework and cli tools
class_field.c File Reference
#include "class_field.h"
#include "class_private.h"

Go to the source code of this file.

Macros

#define FIELD_ACCESS_FLAGS_SIZE   16
 

Functions

char * java_field_access_flags_readable (const Field *field)
 
Fieldjava_field_new (ConstPool **pool, ut32 poolsize, RzBuffer *buf, ut64 offset)
 
void java_field_free (Field *field)
 
bool java_field_is_global (const Field *field)
 

Variables

static const AccessFlagsReadable access_flags_list [FIELD_ACCESS_FLAGS_SIZE]
 

Macro Definition Documentation

◆ FIELD_ACCESS_FLAGS_SIZE

#define FIELD_ACCESS_FLAGS_SIZE   16

Definition at line 7 of file class_field.c.

Function Documentation

◆ java_field_access_flags_readable()

char* java_field_access_flags_readable ( const Field field)

Definition at line 20 of file class_field.c.

20  {
22  RzStrBuf *sb = NULL;
23 
24  for (ut32 i = 0; i < FIELD_ACCESS_FLAGS_SIZE; ++i) {
26  if (field->access_flags & afr->flag) {
27  if (!sb) {
28  sb = rz_strbuf_new(afr->readable);
29  if (!sb) {
30  return NULL;
31  }
32  } else {
33  rz_strbuf_appendf(sb, " %s", afr->readable);
34  }
35  }
36  }
37 
38  return sb ? rz_strbuf_drain(sb) : NULL;
39 }
lzma_index ** i
Definition: index.h:629
static SblHeader sb
Definition: bin_mbn.c:26
static const AccessFlagsReadable access_flags_list[FIELD_ACCESS_FLAGS_SIZE]
Definition: class_field.c:8
#define FIELD_ACCESS_FLAGS_SIZE
Definition: class_field.c:7
#define NULL
Definition: cris-opc.c:27
uint32_t ut32
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API RZ_OWN char * rz_strbuf_drain(RzStrBuf *sb)
Definition: strbuf.c:342
RZ_API RzStrBuf * rz_strbuf_new(const char *s)
Definition: strbuf.c:8
RZ_API bool rz_strbuf_appendf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
ut16 access_flags
Definition: class_field.h:25

References java_field_t::access_flags, access_flags_list, FIELD_ACCESS_FLAGS_SIZE, access_flags_readable_t::flag, i, NULL, access_flags_readable_t::readable, rz_return_val_if_fail, rz_strbuf_appendf(), rz_strbuf_drain(), rz_strbuf_new(), and sb.

Referenced by rz_bin_java_class_as_source_code(), rz_bin_java_class_fields_as_json(), rz_bin_java_class_fields_as_symbols(), and rz_bin_java_class_fields_as_text().

◆ java_field_free()

void java_field_free ( Field field)

Definition at line 78 of file class_field.c.

78  {
79  if (!field) {
80  return;
81  }
82  if (field->attributes) {
83  for (ut32 i = 0; i < field->attributes_count; ++i) {
85  }
86  free(field->attributes);
87  }
88  free(field);
89 }
void java_attribute_free(Attribute *attr)
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
Attribute ** attributes
Definition: class_field.h:29
ut16 attributes_count
Definition: class_field.h:28

References java_field_t::attributes, java_field_t::attributes_count, free(), i, and java_attribute_free().

Referenced by rz_bin_java_class_free().

◆ java_field_is_global()

bool java_field_is_global ( const Field field)

Definition at line 91 of file class_field.c.

91  {
93  return field && (field->access_flags & flag) == flag;
94 }
@ FIELD_ACCESS_FLAG_PUBLIC
Definition: class_field.h:12
@ FIELD_ACCESS_FLAG_STATIC
Definition: class_field.h:15
@ FIELD_ACCESS_FLAG_FINAL
Definition: class_field.h:16
uint16_t ut16

References java_field_t::access_flags, FIELD_ACCESS_FLAG_FINAL, FIELD_ACCESS_FLAG_PUBLIC, and FIELD_ACCESS_FLAG_STATIC.

Referenced by rz_bin_java_class_fields_as_symbols().

◆ java_field_new()

Field* java_field_new ( ConstPool **  pool,
ut32  poolsize,
RzBuffer buf,
ut64  offset 
)

Definition at line 41 of file class_field.c.

41  {
42  Field *field = RZ_NEW0(Field);
44  field->offset = offset;
45  ut64 base = offset - rz_buf_tell(buf);
46 
47  if (!rz_buf_read_be16(buf, &field->access_flags) ||
48  !rz_buf_read_be16(buf, &field->name_index) ||
51  free(field);
52  return NULL;
53  }
54 
55  if (field->attributes_count < 1) {
56  return field;
57  }
58  field->attributes = RZ_NEWS0(Attribute *, field->attributes_count);
59  if (!field->attributes) {
60  free(field);
62  return NULL;
63  }
64 
65  for (ut32 i = 0; i < field->attributes_count; ++i) {
66  offset = rz_buf_tell(buf) + base;
68  if (attr && java_attribute_resolve(pool, poolsize, attr, buf, false)) {
69  field->attributes[i] = attr;
70  } else {
71  java_attribute_free(attr);
72  break;
73  }
74  }
75  return field;
76 }
bool java_attribute_resolve(ConstPool **pool, ut32 poolsize, Attribute *attr, RzBuffer *buf, bool is_oak)
Attribute * java_attribute_new(RzBuffer *buf, ut64 offset)
voidpf uLong offset
Definition: ioapi.h:144
voidpf void * buf
Definition: ioapi.h:138
#define rz_warn_if_reached()
Definition: rz_assert.h:29
RZ_API ut64 rz_buf_tell(RZ_NONNULL RzBuffer *b)
Return the current cursor position.
Definition: buf.c:1238
#define rz_buf_read_be16(b, result)
Definition: rz_buf.h:280
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define RZ_NEWS0(x, y)
Definition: rz_types.h:282
ut16 descriptor_index
Definition: class_field.h:27
ut16 name_index
Definition: class_field.h:26
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References java_field_t::access_flags, java_field_t::attributes, java_field_t::attributes_count, java_field_t::descriptor_index, free(), i, java_attribute_free(), java_attribute_new(), java_attribute_resolve(), java_field_t::name_index, NULL, java_field_t::offset, rz_buf_read_be16, rz_buf_tell(), RZ_NEW0, RZ_NEWS0, rz_return_val_if_fail, rz_warn_if_reached, and ut64().

Referenced by java_class_parse().

Variable Documentation

◆ access_flags_list

Initial value:
= {
{ FIELD_ACCESS_FLAG_PUBLIC, "public" },
{ FIELD_ACCESS_FLAG_PRIVATE, "private" },
{ FIELD_ACCESS_FLAG_PROTECTED, "protected" },
{ FIELD_ACCESS_FLAG_STATIC, "static" },
{ FIELD_ACCESS_FLAG_VOLATILE, "volatile" },
{ FIELD_ACCESS_FLAG_TRANSIENT, "transient" },
{ FIELD_ACCESS_FLAG_SYNTHETIC, "synthetic" },
}
@ FIELD_ACCESS_FLAG_VOLATILE
Definition: class_field.h:17
@ FIELD_ACCESS_FLAG_ENUM
Definition: class_field.h:20
@ FIELD_ACCESS_FLAG_PRIVATE
Definition: class_field.h:13
@ FIELD_ACCESS_FLAG_TRANSIENT
Definition: class_field.h:18
@ FIELD_ACCESS_FLAG_SYNTHETIC
Definition: class_field.h:19
@ FIELD_ACCESS_FLAG_PROTECTED
Definition: class_field.h:14

Definition at line 8 of file class_field.c.

Referenced by java_field_access_flags_readable().