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

Go to the source code of this file.

Macros

#define METHOD_ACCESS_FLAGS_SIZE   16
 

Functions

char * java_method_access_flags_readable (const Method *method)
 
static bool java_method_new_aux (RzBuffer *buf, Method *method)
 
Methodjava_method_new (ConstPool **pool, ut32 poolsize, RzBuffer *buf, ut64 offset, bool is_oak)
 
void java_method_free (Method *method)
 
bool java_method_is_global (const Method *method)
 

Variables

static const AccessFlagsReadable access_flags_list [METHOD_ACCESS_FLAGS_SIZE]
 

Macro Definition Documentation

◆ METHOD_ACCESS_FLAGS_SIZE

#define METHOD_ACCESS_FLAGS_SIZE   16

Definition at line 7 of file class_method.c.

Function Documentation

◆ java_method_access_flags_readable()

char* java_method_access_flags_readable ( const Method method)

Definition at line 26 of file class_method.c.

26  {
27  rz_return_val_if_fail(method, NULL);
28  RzStrBuf *sb = NULL;
29 
30  for (ut32 i = 0; i < METHOD_ACCESS_FLAGS_SIZE; ++i) {
32  if (method->access_flags & afr->flag) {
33  if (!sb) {
34  sb = rz_strbuf_new(afr->readable);
35  if (!sb) {
36  return NULL;
37  }
38  } else {
39  rz_strbuf_appendf(sb, " %s", afr->readable);
40  }
41  }
42  }
43 
44  return sb ? rz_strbuf_drain(sb) : NULL;
45 }
lzma_index ** i
Definition: index.h:629
static SblHeader sb
Definition: bin_mbn.c:26
static const AccessFlagsReadable access_flags_list[METHOD_ACCESS_FLAGS_SIZE]
Definition: class_method.c:8
#define METHOD_ACCESS_FLAGS_SIZE
Definition: class_method.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

References java_method_t::access_flags, access_flags_list, access_flags_readable_t::flag, i, METHOD_ACCESS_FLAGS_SIZE, 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_methods_as_json(), rz_bin_java_class_methods_as_symbols(), and rz_bin_java_class_methods_as_text().

◆ java_method_free()

void java_method_free ( Method method)

Definition at line 89 of file class_method.c.

89  {
90  if (!method) {
91  return;
92  }
93  if (method->attributes) {
94  for (ut32 i = 0; i < method->attributes_count; ++i) {
96  }
97  free(method->attributes);
98  }
99  free(method);
100 }
void java_attribute_free(Attribute *attr)
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
Attribute ** attributes
Definition: class_method.h:35
ut16 attributes_count
Definition: class_method.h:34

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

Referenced by rz_bin_java_class_free().

◆ java_method_is_global()

bool java_method_is_global ( const Method method)

Definition at line 102 of file class_method.c.

102  {
104  return method && (method->access_flags & flag) == flag;
105 }
@ METHOD_ACCESS_FLAG_PUBLIC
Definition: class_method.h:12
@ METHOD_ACCESS_FLAG_FINAL
Definition: class_method.h:16
@ METHOD_ACCESS_FLAG_STATIC
Definition: class_method.h:15
uint16_t ut16

References java_method_t::access_flags, METHOD_ACCESS_FLAG_FINAL, METHOD_ACCESS_FLAG_PUBLIC, and METHOD_ACCESS_FLAG_STATIC.

Referenced by rz_bin_java_class_methods_as_symbols().

◆ java_method_new()

Method* java_method_new ( ConstPool **  pool,
ut32  poolsize,
RzBuffer buf,
ut64  offset,
bool  is_oak 
)

Definition at line 54 of file class_method.c.

54  {
55  Method *method = RZ_NEW0(Method);
56  rz_return_val_if_fail(method, NULL);
57  method->offset = offset;
58  ut64 base = offset - rz_buf_tell(buf);
59 
60  if (!java_method_new_aux(buf, method)) {
61  free(method);
62  return NULL;
63  }
64 
65  if (method->attributes_count < 1) {
66  return method;
67  }
68 
69  method->attributes = RZ_NEWS0(Attribute *, method->attributes_count);
70  if (!method->attributes) {
71  free(method);
73  return NULL;
74  }
75 
76  for (ut32 i = 0; i < method->attributes_count; ++i) {
77  offset = rz_buf_tell(buf) + base;
79  if (attr && java_attribute_resolve(pool, poolsize, attr, buf, is_oak)) {
80  method->attributes[i] = attr;
81  } else {
82  java_attribute_free(attr);
83  break;
84  }
85  }
86  return method;
87 }
bool java_attribute_resolve(ConstPool **pool, ut32 poolsize, Attribute *attr, RzBuffer *buf, bool is_oak)
Attribute * java_attribute_new(RzBuffer *buf, ut64 offset)
static bool java_method_new_aux(RzBuffer *buf, Method *method)
Definition: class_method.c:47
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_NEW0(x)
Definition: rz_types.h:284
#define RZ_NEWS0(x, y)
Definition: rz_types.h:282
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References java_method_t::attributes, java_method_t::attributes_count, free(), i, java_attribute_free(), java_attribute_new(), java_attribute_resolve(), java_method_new_aux(), NULL, java_method_t::offset, rz_buf_tell(), RZ_NEW0, RZ_NEWS0, rz_return_val_if_fail, rz_warn_if_reached, and ut64().

Referenced by java_class_parse().

◆ java_method_new_aux()

static bool java_method_new_aux ( RzBuffer buf,
Method method 
)
static

Definition at line 47 of file class_method.c.

47  {
48  return rz_buf_read_be16(buf, &method->access_flags) &&
49  rz_buf_read_be16(buf, &method->name_index) &&
52 }
#define rz_buf_read_be16(b, result)
Definition: rz_buf.h:280
ut16 descriptor_index
Definition: class_method.h:33

References java_method_t::access_flags, java_method_t::attributes_count, java_method_t::descriptor_index, java_method_t::name_index, and rz_buf_read_be16.

Referenced by java_method_new().

Variable Documentation

◆ access_flags_list

Initial value:
= {
{ METHOD_ACCESS_FLAG_PROTECTED, "protected" },
{ METHOD_ACCESS_FLAG_SYNCHRONIZED, "synchronized" },
{ METHOD_ACCESS_FLAG_INTERFACE, "interface" },
{ METHOD_ACCESS_FLAG_ABSTRACT, "abstract" },
{ METHOD_ACCESS_FLAG_SYNTHETIC, "synthetic" },
{ METHOD_ACCESS_FLAG_ANNOTATION, "annotation" },
}
@ METHOD_ACCESS_FLAG_ABSTRACT
Definition: class_method.h:22
@ METHOD_ACCESS_FLAG_SYNTHETIC
Definition: class_method.h:24
@ METHOD_ACCESS_FLAG_PRIVATE
Definition: class_method.h:13
@ METHOD_ACCESS_FLAG_SYNCHRONIZED
Definition: class_method.h:17
@ METHOD_ACCESS_FLAG_STRICT
Definition: class_method.h:23
@ METHOD_ACCESS_FLAG_PROTECTED
Definition: class_method.h:14
@ METHOD_ACCESS_FLAG_BRIDGE
Definition: class_method.h:18
@ METHOD_ACCESS_FLAG_ANNOTATION
Definition: class_method.h:25
@ METHOD_ACCESS_FLAG_ENUM
Definition: class_method.h:26
@ METHOD_ACCESS_FLAG_INTERFACE
Definition: class_method.h:21
@ METHOD_ACCESS_FLAG_VARARGS
Definition: class_method.h:19
@ METHOD_ACCESS_FLAG_NATIVE
Definition: class_method.h:20

Definition at line 8 of file class_method.c.

Referenced by java_method_access_flags_readable().