Rizin
unix-like reverse engineering framework and cli tools
bin_java.c File Reference
#include <rz_types.h>
#include <rz_util.h>
#include <rz_lib.h>
#include <rz_bin.h>
#include "../format/java/class_bin.h"
#include "../../asm/arch/java/const.h"

Go to the source code of this file.

Macros

#define rz_bin_file_get_java_class(bf)   ((RzBinJavaClass *)bf->o->bin_obj)
 

Functions

static RzBinInfoinfo (RzBinFile *bf)
 
static bool load_buffer (RzBinFile *bf, RzBinObject *obj, RzBuffer *buf, Sdb *sdb)
 
static void destroy (RzBinFile *bf)
 
static bool check_buffer (RzBuffer *b)
 
static ut64 baddr (RzBinFile *bf)
 
static Sdbget_sdb (RzBinFile *bf)
 
static void free_rz_bin_class (void *k)
 
static RzListclasses (RzBinFile *bf)
 
static RzListimports (RzBinFile *bf)
 
static RzListsections (RzBinFile *bf)
 
static RzListsymbols (RzBinFile *bf)
 
static RzListfields (RzBinFile *bf)
 
static RzListlibs (RzBinFile *bf)
 
static RzBinAddrbinsym (RzBinFile *bf, RzBinSpecialSymbol sym)
 
static RzListentrypoints (RzBinFile *bf)
 
static RzListstrings (RzBinFile *bf)
 
static int demangle_type (const char *str)
 
static char * enrich_asm (RzBinFile *bf, const char *asm_str, int asm_len)
 

Variables

RzBinPlugin rz_bin_plugin_java
 
RZ_API RzLibStruct rizin_plugin
 

Macro Definition Documentation

◆ rz_bin_file_get_java_class

#define rz_bin_file_get_java_class (   bf)    ((RzBinJavaClass *)bf->o->bin_obj)

Definition at line 12 of file bin_java.c.

Function Documentation

◆ baddr()

static ut64 baddr ( RzBinFile bf)
static

Definition at line 61 of file bin_java.c.

61  {
62  return 0;
63 }

◆ binsym()

static RzBinAddr* binsym ( RzBinFile bf,
RzBinSpecialSymbol  sym 
)
static

Definition at line 174 of file bin_java.c.

174  {
176  if (!jclass) {
177  return NULL;
178  }
179 
181 }
#define rz_bin_file_get_java_class(bf)
Definition: bin_java.c:12
RZ_API RZ_OWN RzBinAddr * rz_bin_java_class_resolve_symbol(RZ_NONNULL RzBinJavaClass *bin, RzBinSpecialSymbol resolve)
Resolves and returns the RzBinAddr struct linked to the input RzBinSpecialSymbol.
Definition: class_bin.c:870
#define NULL
Definition: cris-opc.c:27
jobject jclass
Definition: jni.h:104

References NULL, rz_bin_file_get_java_class, and rz_bin_java_class_resolve_symbol().

◆ check_buffer()

static bool check_buffer ( RzBuffer b)
static

Definition at line 52 of file bin_java.c.

52  {
53  if (rz_buf_size(b) > 32) {
54  ut8 buf[4];
55  rz_buf_read_at(b, 0, buf, sizeof(buf));
56  return !memcmp(buf, "\xca\xfe\xba\xbe", 4);
57  }
58  return false;
59 }
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
RZ_API st64 rz_buf_read_at(RZ_NONNULL RzBuffer *b, ut64 addr, RZ_NONNULL RZ_OUT ut8 *buf, ut64 len)
Read len bytes of the buffer at the specified address.
Definition: buf.c:1136
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
Definition: buf.c:1225
#define b(i)
Definition: sha256.c:42

References b, rz_buf_read_at(), and rz_buf_size().

◆ classes()

static RzList* classes ( RzBinFile bf)
static

Definition at line 81 of file bin_java.c.

81  {
82  RzBinClass *bclass = NULL;
83  RzList *classes = NULL;
85  if (!jclass) {
86  return NULL;
87  }
88 
90  if (!classes) {
91  return NULL;
92  }
93 
94  bclass = RZ_NEW0(RzBinClass);
95  if (!bclass) {
97  return NULL;
98  }
99  rz_list_append(classes, bclass);
100 
105 
108  if (!bclass->methods || !bclass->fields) {
110  return NULL;
111  }
112 
113  return classes;
114 }
static RzList * classes(RzBinFile *bf)
Definition: bin_java.c:81
static void free_rz_bin_class(void *k)
Definition: bin_java.c:69
RZ_API RZ_OWN RzList * rz_bin_java_class_methods_as_symbols(RZ_NONNULL RzBinJavaClass *bin)
Returns a RzList<RzBinSymbol*> containing the class methods.
Definition: class_bin.c:1052
RZ_API RZ_OWN char * rz_bin_java_class_access_flags_readable(RZ_NONNULL RzBinJavaClass *bin, ut16 mask)
Returns the readable class access flags.
Definition: class_bin.c:485
RZ_API RZ_OWN char * rz_bin_java_class_name(RZ_NONNULL RzBinJavaClass *bin)
Returns the class name.
Definition: class_bin.c:447
RZ_API RZ_OWN RzList * rz_bin_java_class_fields_as_binfields(RZ_NONNULL RzBinJavaClass *bin)
Returns a RzList<RzBinField*> containing the class fields.
Definition: class_bin.c:1277
RZ_API RZ_OWN char * rz_bin_java_class_super(RZ_NONNULL RzBinJavaClass *bin)
Returns the class super name.
Definition: class_bin.c:466
RZ_API ut32 rz_bin_java_class_access_flags(RZ_NONNULL RzBinJavaClass *bin)
Definition: class_bin.c:477
#define ACCESS_FLAG_MASK_ALL_NO_SUPER
Definition: class_bin.h:37
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
#define RZ_NEW0(x)
Definition: rz_types.h:284
char * super
Definition: rz_bin.h:649
RzList * fields
Definition: rz_bin.h:654
char * name
Definition: rz_bin.h:647
int visibility
Definition: rz_bin.h:656
RzList * methods
Definition: rz_bin.h:653
char * visibility_str
Definition: rz_bin.h:650

References ACCESS_FLAG_MASK_ALL_NO_SUPER, rz_bin_class_t::fields, free_rz_bin_class(), rz_bin_class_t::methods, rz_bin_class_t::name, NULL, rz_bin_file_get_java_class, rz_bin_java_class_access_flags(), rz_bin_java_class_access_flags_readable(), rz_bin_java_class_fields_as_binfields(), rz_bin_java_class_methods_as_symbols(), rz_bin_java_class_name(), rz_bin_java_class_super(), rz_list_append(), rz_list_free(), rz_list_newf(), RZ_NEW0, rz_bin_class_t::super, rz_bin_class_t::visibility, and rz_bin_class_t::visibility_str.

◆ demangle_type()

static int demangle_type ( const char *  str)
static

Definition at line 201 of file bin_java.c.

201  {
202  return RZ_BIN_LANGUAGE_JAVA;
203 }
@ RZ_BIN_LANGUAGE_JAVA
Definition: rz_bin.h:147

References RZ_BIN_LANGUAGE_JAVA.

◆ destroy()

static void destroy ( RzBinFile bf)
static

Definition at line 48 of file bin_java.c.

48  {
50 }
RZ_API void rz_bin_java_class_free(RZ_NULLABLE RzBinJavaClass *bin)
Frees a RzBinJavaClass pointer.
Definition: class_bin.c:407

References rz_bin_file_get_java_class, and rz_bin_java_class_free().

◆ enrich_asm()

static char* enrich_asm ( RzBinFile bf,
const char *  asm_str,
int  asm_len 
)
static

Definition at line 205 of file bin_java.c.

205  {
207  if (!jclass) {
208  return NULL;
209  }
210  for (int i = 0; i < asm_len; ++i) {
211  if (!strncmp(asm_str + i, JAVA_ASM_CONSTANT_POOL_STR, strlen(JAVA_ASM_CONSTANT_POOL_STR))) {
212  const char *snum = asm_str + i + strlen(JAVA_ASM_CONSTANT_POOL_STR);
213  if (!IS_DIGIT(*snum)) {
215  continue;
216  }
217  int index = atoi(snum);
219  if (!tmp) {
221  return NULL;
222  }
223  char *result = rz_str_newf("%.*s%s", i, asm_str, tmp);
224  free(tmp);
225  return result;
226  }
227  }
228  return NULL;
229 }
lzma_index ** i
Definition: index.h:629
RZ_API RZ_OWN char * rz_bin_java_class_const_pool_resolve_index(RZ_NONNULL RzBinJavaClass *bin, st32 index)
Returns the string linked to the class const pool index.
Definition: class_bin.c:644
#define JAVA_ASM_CONSTANT_POOL_STR
Definition: const.h:7
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
#define rz_warn_if_reached()
Definition: rz_assert.h:29
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
#define IS_DIGIT(x)
Definition: rz_str_util.h:11

References free(), i, IS_DIGIT, JAVA_ASM_CONSTANT_POOL_STR, NULL, rz_bin_file_get_java_class, rz_bin_java_class_const_pool_resolve_index(), rz_str_newf(), rz_warn_if_reached, and autogen_x86imm::tmp.

◆ entrypoints()

static RzList* entrypoints ( RzBinFile bf)
static

Definition at line 183 of file bin_java.c.

183  {
185  if (!jclass) {
186  return NULL;
187  }
188 
190 }
RZ_API RZ_OWN RzList * rz_bin_java_class_entrypoints(RZ_NONNULL RzBinJavaClass *bin)
Returns a RzList<RzBinAddr*> containing the entrypoints.
Definition: class_bin.c:927

References NULL, rz_bin_file_get_java_class, and rz_bin_java_class_entrypoints().

◆ fields()

static RzList* fields ( RzBinFile bf)
static

Definition at line 156 of file bin_java.c.

156  {
158  if (!jclass) {
159  return NULL;
160  }
161 
163 }

References NULL, rz_bin_file_get_java_class, and rz_bin_java_class_fields_as_binfields().

◆ free_rz_bin_class()

static void free_rz_bin_class ( void *  k)
static

Definition at line 69 of file bin_java.c.

69  {
70  RzBinClass *bclass = (RzBinClass *)k;
71  if (bclass) {
72  rz_list_free(bclass->methods);
73  rz_list_free(bclass->fields);
74  free(bclass->name);
75  free(bclass->super);
76  free(bclass->visibility_str);
77  free(bclass);
78  }
79 }
const char * k
Definition: dsignal.c:11

References rz_bin_class_t::fields, free(), k, rz_bin_class_t::methods, rz_bin_class_t::name, rz_list_free(), rz_bin_class_t::super, and rz_bin_class_t::visibility_str.

Referenced by classes().

◆ get_sdb()

static Sdb* get_sdb ( RzBinFile bf)
static

Definition at line 65 of file bin_java.c.

65  {
66  return bf->sdb;
67 }
RZ_DEPRECATE Sdb * sdb
deprecated, put info in C structures instead of this
Definition: rz_bin.h:315

References rz_bin_file_t::sdb.

◆ imports()

static RzList* imports ( RzBinFile bf)
static

Definition at line 116 of file bin_java.c.

116  {
118  if (!jclass) {
119  return NULL;
120  }
121 
123 }
RZ_API RZ_OWN RzList * rz_bin_java_class_const_pool_as_imports(RZ_NONNULL RzBinJavaClass *bin)
Returns a RzList<RzBinImport*> containing the class const pool.
Definition: class_bin.c:1509

References NULL, rz_bin_file_get_java_class, and rz_bin_java_class_const_pool_as_imports().

◆ info()

static RzBinInfo* info ( RzBinFile bf)
static

Definition at line 14 of file bin_java.c.

14  {
16  if (!jclass) {
17  return NULL;
18  }
19  RzBinInfo *binfo = RZ_NEW0(RzBinInfo);
20  if (!binfo) {
21  return NULL;
22  }
24  binfo->file = strdup(bf->file);
25  binfo->type = strdup("JAVA CLASS");
27  binfo->has_va = false;
28  binfo->rclass = strdup("class");
29  binfo->os = strdup("any");
30  binfo->subsystem = strdup("any");
31  binfo->machine = strdup("jvm");
32  binfo->arch = strdup("java");
33  binfo->bits = 32;
34  binfo->big_endian = true;
36  return binfo;
37 }
RZ_API RZ_BORROW const char * rz_bin_java_class_language(RZ_NONNULL RzBinJavaClass *bin)
Definition: class_bin.c:378
RZ_API ut64 rz_bin_java_class_debug_info(RZ_NONNULL RzBinJavaClass *bin)
Definition: class_bin.c:351
RZ_API RZ_OWN char * rz_bin_java_class_version(RZ_NONNULL RzBinJavaClass *bin)
Parses the java class file and returns a RzBinJavaClass struct.
Definition: class_bin.c:306
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
char * file
Definition: rz_bin.h:299
int has_va
Definition: rz_bin.h:228
char * type
Definition: rz_bin.h:211
char * os
Definition: rz_bin.h:219
char * subsystem
Definition: rz_bin.h:220
char * machine
Definition: rz_bin.h:216
const char * lang
Definition: rz_bin.h:224
char * bclass
Definition: rz_bin.h:212
char * file
Definition: rz_bin.h:210
ut64 dbg_info
Definition: rz_bin.h:240
char * rclass
Definition: rz_bin.h:213
char * arch
Definition: rz_bin.h:214
int big_endian
Definition: rz_bin.h:235

References rz_bin_info_t::arch, rz_bin_info_t::bclass, rz_bin_info_t::big_endian, rz_bin_info_t::bits, rz_bin_info_t::dbg_info, rz_bin_info_t::file, rz_bin_file_t::file, rz_bin_info_t::has_va, rz_bin_info_t::lang, rz_bin_info_t::machine, NULL, rz_bin_info_t::os, rz_bin_info_t::rclass, rz_bin_file_get_java_class, rz_bin_java_class_debug_info(), rz_bin_java_class_language(), rz_bin_java_class_version(), RZ_NEW0, strdup(), rz_bin_info_t::subsystem, and rz_bin_info_t::type.

◆ libs()

static RzList* libs ( RzBinFile bf)
static

Definition at line 165 of file bin_java.c.

165  {
167  if (!jclass) {
168  return NULL;
169  }
170 
172 }
RZ_API RZ_OWN RzList * rz_bin_java_class_as_libraries(RZ_NONNULL RzBinJavaClass *bin)
Returns a RzList<char*> containing the class libraries.
Definition: class_bin.c:1846

References NULL, rz_bin_file_get_java_class, and rz_bin_java_class_as_libraries().

◆ load_buffer()

static bool load_buffer ( RzBinFile bf,
RzBinObject obj,
RzBuffer buf,
Sdb sdb 
)
static

Definition at line 39 of file bin_java.c.

39  {
41  if (!jclass) {
42  return false;
43  }
44  obj->bin_obj = jclass;
45  return true;
46 }
RZ_API RZ_OWN RzBinJavaClass * rz_bin_java_class_new(RZ_NONNULL RzBuffer *buf, ut64 offset, RZ_NONNULL Sdb *kv)
Parses the java class file and returns a RzBinJavaClass struct.
Definition: class_bin.c:289
ut64 loadaddr
starting physical address to read from the target file
Definition: rz_bin.h:249
RzBinObjectLoadOptions opts
Definition: rz_bin.h:260
void * bin_obj
Definition: rz_bin.h:293

References rz_bin_object_t::bin_obj, rz_bin_file_load_options_t::loadaddr, rz_bin_object_t::opts, and rz_bin_java_class_new().

◆ sections()

static RzList* sections ( RzBinFile bf)
static

Definition at line 125 of file bin_java.c.

125  {
127  if (!jclass) {
128  return NULL;
129  }
130 
132 }
RZ_API RZ_OWN RzList * rz_bin_java_class_as_sections(RZ_NONNULL RzBinJavaClass *bin)
Returns a RzList<RzBinSection*> containing the class sections.
Definition: class_bin.c:1718

References NULL, rz_bin_file_get_java_class, and rz_bin_java_class_as_sections().

◆ strings()

static RzList* strings ( RzBinFile bf)
static

Definition at line 192 of file bin_java.c.

192  {
194  if (!jclass) {
195  return NULL;
196  }
197 
199 }
RZ_API RZ_OWN RzList * rz_bin_java_class_strings(RZ_NONNULL RzBinJavaClass *bin)
Returns a RzList<RzBinString*> containing the strings.
Definition: class_bin.c:986

References NULL, rz_bin_file_get_java_class, and rz_bin_java_class_strings().

◆ symbols()

static RzList* symbols ( RzBinFile bf)
static

Definition at line 134 of file bin_java.c.

134  {
135  RzList *tmp;
137  if (!jclass) {
138  return NULL;
139  }
140 
142  if (!list) {
143  return NULL;
144  }
145 
148  rz_list_free(tmp);
149 
152  rz_list_free(tmp);
153  return list;
154 }
RZ_API RZ_OWN RzList * rz_bin_java_class_fields_as_symbols(RZ_NONNULL RzBinJavaClass *bin)
Returns a RzList<RzBinSymbol*> containing the class fields.
Definition: class_bin.c:1227
RZ_API RZ_OWN RzList * rz_bin_java_class_const_pool_as_symbols(RZ_NONNULL RzBinJavaClass *bin)
Returns a RzList<RzBinSymbol*> containing the class const pool.
Definition: class_bin.c:1435
static void list(RzEgg *egg)
Definition: rz-gg.c:52
RZ_API bool rz_list_join(RZ_NONNULL RzList *list1, RZ_NONNULL RzList *list2)
Joins 2 list into one (list2 pointer needs to be freed by the user)
Definition: list.c:209

References list(), NULL, rz_bin_file_get_java_class, rz_bin_java_class_const_pool_as_symbols(), rz_bin_java_class_fields_as_symbols(), rz_bin_java_class_methods_as_symbols(), rz_list_free(), rz_list_join(), and autogen_x86imm::tmp.

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_BIN,
}
RzBinPlugin rz_bin_plugin_java
Definition: bin_java.c:231
@ RZ_LIB_TYPE_BIN
Definition: rz_lib.h:75
#define RZ_VERSION
Definition: rz_version.h:8
char * version
Definition: rz_bin.h:512

Definition at line 257 of file bin_java.c.

◆ rz_bin_plugin_java

RzBinPlugin rz_bin_plugin_java
Initial value:
= {
.name = "java",
.desc = "java bin plugin",
.license = "LGPL3",
.get_sdb = &get_sdb,
.load_buffer = &load_buffer,
.destroy = &destroy,
.check_buffer = &check_buffer,
.baddr = &baddr,
.binsym = &binsym,
.entries = &entrypoints,
.sections = sections,
.symbols = symbols,
.imports = &imports,
.strings = &strings,
.enrich_asm = &enrich_asm,
.info = &info,
.fields = fields,
.libs = libs,
.classes = classes,
.demangle_type = demangle_type,
.minstrlen = 3,
}
RZ_API RZ_OWN RzList * rz_bin_maps_of_file_sections(RZ_NONNULL RzBinFile *binfile)
Create a list of RzBinMap from RzBinSections queried from the given file.
Definition: bin.c:1040
static RzBinAddr * binsym(RzBinFile *bf, RzBinSpecialSymbol sym)
Definition: bin_java.c:174
static Sdb * get_sdb(RzBinFile *bf)
Definition: bin_java.c:65
static bool load_buffer(RzBinFile *bf, RzBinObject *obj, RzBuffer *buf, Sdb *sdb)
Definition: bin_java.c:39
static RzList * symbols(RzBinFile *bf)
Definition: bin_java.c:134
static char * enrich_asm(RzBinFile *bf, const char *asm_str, int asm_len)
Definition: bin_java.c:205
static RzList * libs(RzBinFile *bf)
Definition: bin_java.c:165
static RzList * strings(RzBinFile *bf)
Definition: bin_java.c:192
static RzList * fields(RzBinFile *bf)
Definition: bin_java.c:156
static void destroy(RzBinFile *bf)
Definition: bin_java.c:48
static bool check_buffer(RzBuffer *b)
Definition: bin_java.c:52
static RzBinInfo * info(RzBinFile *bf)
Definition: bin_java.c:14
static ut64 baddr(RzBinFile *bf)
Definition: bin_java.c:61
static RzList * sections(RzBinFile *bf)
Definition: bin_java.c:125
static RzList * imports(RzBinFile *bf)
Definition: bin_java.c:116
static int demangle_type(const char *str)
Definition: bin_java.c:201
static RzList * entrypoints(RzBinFile *bf)
Definition: bin_java.c:183

Definition at line 231 of file bin_java.c.