Rizin
unix-like reverse engineering framework and cli tools
class_method.h File Reference
#include <rz_types.h>
#include <rz_util.h>
#include <rz_bin.h>
#include "class_attribute.h"

Go to the source code of this file.

Classes

struct  java_method_t
 

Typedefs

typedef struct java_method_t Method
 

Enumerations

enum  MethodAccessFlag {
  METHOD_ACCESS_FLAG_PUBLIC = 0x0001 , METHOD_ACCESS_FLAG_PRIVATE = 0x0002 , METHOD_ACCESS_FLAG_PROTECTED = 0x0004 , METHOD_ACCESS_FLAG_STATIC = 0x0008 ,
  METHOD_ACCESS_FLAG_FINAL = 0x0010 , METHOD_ACCESS_FLAG_SYNCHRONIZED = 0x0020 , METHOD_ACCESS_FLAG_BRIDGE = 0x0040 , METHOD_ACCESS_FLAG_VARARGS = 0x0080 ,
  METHOD_ACCESS_FLAG_NATIVE = 0x0100 , METHOD_ACCESS_FLAG_INTERFACE = 0x0200 , METHOD_ACCESS_FLAG_ABSTRACT = 0x0400 , METHOD_ACCESS_FLAG_STRICT = 0x0800 ,
  METHOD_ACCESS_FLAG_SYNTHETIC = 0x1000 , METHOD_ACCESS_FLAG_ANNOTATION = 0x2000 , METHOD_ACCESS_FLAG_ENUM = 0x4000
}
 

Functions

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

Typedef Documentation

◆ Method

typedef struct java_method_t Method

Enumeration Type Documentation

◆ MethodAccessFlag

Enumerator
METHOD_ACCESS_FLAG_PUBLIC 
METHOD_ACCESS_FLAG_PRIVATE 
METHOD_ACCESS_FLAG_PROTECTED 
METHOD_ACCESS_FLAG_STATIC 
METHOD_ACCESS_FLAG_FINAL 
METHOD_ACCESS_FLAG_SYNCHRONIZED 
METHOD_ACCESS_FLAG_BRIDGE 
METHOD_ACCESS_FLAG_VARARGS 
METHOD_ACCESS_FLAG_NATIVE 
METHOD_ACCESS_FLAG_INTERFACE 
METHOD_ACCESS_FLAG_ABSTRACT 
METHOD_ACCESS_FLAG_STRICT 
METHOD_ACCESS_FLAG_SYNTHETIC 
METHOD_ACCESS_FLAG_ANNOTATION 
METHOD_ACCESS_FLAG_ENUM 

Definition at line 11 of file class_method.h.

11  {
12  METHOD_ACCESS_FLAG_PUBLIC /* */ = 0x0001,
13  METHOD_ACCESS_FLAG_PRIVATE /* */ = 0x0002,
14  METHOD_ACCESS_FLAG_PROTECTED /* */ = 0x0004,
15  METHOD_ACCESS_FLAG_STATIC /* */ = 0x0008,
16  METHOD_ACCESS_FLAG_FINAL /* */ = 0x0010,
18  METHOD_ACCESS_FLAG_BRIDGE /* */ = 0x0040,
19  METHOD_ACCESS_FLAG_VARARGS /* */ = 0x0080,
20  METHOD_ACCESS_FLAG_NATIVE /* */ = 0x0100,
21  METHOD_ACCESS_FLAG_INTERFACE /* */ = 0x0200,
22  METHOD_ACCESS_FLAG_ABSTRACT /* */ = 0x0400,
23  METHOD_ACCESS_FLAG_STRICT /* */ = 0x0800,
24  METHOD_ACCESS_FLAG_SYNTHETIC /* */ = 0x1000,
25  METHOD_ACCESS_FLAG_ANNOTATION /* */ = 0x2000,
26  METHOD_ACCESS_FLAG_ENUM /* */ = 0x4000
MethodAccessFlag
Definition: class_method.h:11
@ 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_PUBLIC
Definition: class_method.h:12
@ 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_FINAL
Definition: class_method.h:16
@ METHOD_ACCESS_FLAG_STATIC
Definition: class_method.h:15
@ METHOD_ACCESS_FLAG_NATIVE
Definition: class_method.h:20

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 }
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().