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

Go to the source code of this file.

Functions

static ut8make_string (RzBuffer *buf, st64 size)
 
static char * resolve_const_pool_index (ConstPool **pool, ut32 poolsize, ut32 index)
 
bool java_attribute_set_unknown (Attribute *attr, RzBuffer *buf)
 
bool java_attribute_set_constantvalue (Attribute *attr, RzBuffer *buf)
 
bool java_attribute_set_code (ConstPool **pool, ut32 poolsize, Attribute *attr, RzBuffer *buf, bool is_oak)
 
bool java_attribute_set_sourcefile (Attribute *attr, RzBuffer *buf)
 
bool java_attribute_set_sourcedebugextension (Attribute *attr, RzBuffer *buf)
 
bool java_attribute_set_linenumbertable (Attribute *attr, RzBuffer *buf)
 
bool java_attribute_set_localvariabletable (Attribute *attr, RzBuffer *buf)
 
bool java_attribute_set_localvariabletypetable (Attribute *attr, RzBuffer *buf)
 
bool java_attribute_set_module (Attribute *attr, RzBuffer *buf)
 
bool java_attribute_set_modulepackages (Attribute *attr, RzBuffer *buf)
 
bool java_attribute_set_modulemainclass (Attribute *attr, RzBuffer *buf)
 
bool java_attribute_resolve (ConstPool **pool, ut32 poolsize, Attribute *attr, RzBuffer *buf, bool is_oak)
 
Attributejava_attribute_new (RzBuffer *buf, ut64 offset)
 
void java_attribute_free (Attribute *attr)
 

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)
@ ATTRIBUTE_TYPE_CODE
@ ATTRIBUTE_TYPE_MODULEPACKAGES
@ ATTRIBUTE_TYPE_MODULE
@ ATTRIBUTE_TYPE_LOCALVARIABLETABLE
@ ATTRIBUTE_TYPE_LINENUMBERTABLE
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().

◆ java_attribute_set_code()

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

Definition at line 60 of file class_attribute.c.

60  {
62  if (!ac) {
64  return false;
65  }
66 
67  if (is_oak) {
68  ut8 max_stack;
69  if (!rz_buf_read8(buf, &max_stack)) {
70  free(ac);
71  return false;
72  }
73  ac->max_stack = max_stack;
74 
75  ut8 max_locals;
76  if (!rz_buf_read8(buf, &max_locals)) {
77  free(ac);
78  return false;
79  }
80  ac->max_locals = max_locals;
81 
82  ut16 code_length;
83  if (!rz_buf_read_be16(buf, &code_length)) {
84  free(ac);
85  return false;
86  }
87  ac->code_length = code_length;
88  } else {
89  if (!rz_buf_read_be16(buf, &ac->max_stack) ||
92  free(ac);
93  return false;
94  }
95  }
96 
97  ac->code_offset = attr->offset + (is_oak ? 10 : 14); // 6 bytes for attribute + 8 as code
100  free(ac);
101  return false;
102  }
103 
104  if (ac->exceptions_count > 0) {
106  if (!ac->exceptions) {
107  free(ac);
109  return false;
110  }
111 
112  for (ut32 i = 0; i < ac->exceptions_count; ++i) {
113  if (!rz_buf_read_be16(buf, &ac->exceptions[i].start_pc) ||
117  free(ac);
118  return false;
119  }
120  }
121  }
122 
123  if (!rz_buf_read_be16(buf, &ac->attributes_count)) {
124  free(ac->exceptions);
125  free(ac);
126  return false;
127  }
128 
129  if (ac->attributes_count > 0) {
131  if (!ac->attributes) {
132  free(ac->exceptions);
133  free(ac);
135  return false;
136  }
137 
138  for (ut32 i = 0; i < ac->attributes_count; ++i) {
140  if (attr && java_attribute_resolve(pool, poolsize, attr, buf, false)) {
141  ac->attributes[i] = attr;
142  } else {
143  java_attribute_free(attr);
144  break;
145  }
146  }
147  }
148 
149  attr->type = ATTRIBUTE_TYPE_CODE;
150  attr->info = (void *)ac;
151  return true;
152 }
bool java_attribute_resolve(ConstPool **pool, ut32 poolsize, Attribute *attr, RzBuffer *buf, bool is_oak)
Attribute * java_attribute_new(RzBuffer *buf, ut64 offset)
uint16_t ut16
uint8_t ut8
Definition: lh5801.h:11
#define rz_warn_if_reached()
Definition: rz_assert.h:29
RZ_API st64 rz_buf_seek(RZ_NONNULL RzBuffer *b, st64 addr, int whence)
Modify the current cursor position in the buffer.
Definition: buf.c:1166
#define RZ_BUF_CUR
Definition: rz_buf.h:15
RZ_API bool rz_buf_read8(RZ_NONNULL RzBuffer *b, RZ_NONNULL RZ_OUT ut8 *result)
Read a byte at the cursor in the buffer.
Definition: buf.c:860
#define RZ_NEWS0(x, y)
Definition: rz_types.h:282
#define UT64_MAX
Definition: rz_types_base.h:86

References ATTRIBUTE_TYPE_CODE, java_attribute_code_t::attributes, java_attribute_code_t::attributes_count, java_exception_table_t::catch_type, java_attribute_code_t::code_length, java_attribute_code_t::code_offset, java_exception_table_t::end_pc, java_attribute_code_t::exceptions, java_attribute_code_t::exceptions_count, free(), java_exception_table_t::handler_pc, i, java_attribute_t::info, java_attribute_free(), java_attribute_new(), java_attribute_resolve(), java_attribute_code_t::max_locals, java_attribute_code_t::max_stack, java_attribute_t::offset, RZ_BUF_CUR, rz_buf_read8(), rz_buf_read_be16, rz_buf_read_be32, rz_buf_seek(), RZ_NEW0, RZ_NEWS0, rz_warn_if_reached, java_exception_table_t::start_pc, java_attribute_t::type, and UT64_MAX.

Referenced by java_attribute_resolve().

◆ java_attribute_set_constantvalue()

bool java_attribute_set_constantvalue ( Attribute attr,
RzBuffer buf 
)

Definition at line 42 of file class_attribute.c.

42  {
45  if (!acv) {
47  return false;
48  }
49 
50  if (!rz_buf_read_be16(buf, &acv->index)) {
51  free(acv);
52  return false;
53  }
54 
56  attr->info = (void *)acv;
57  return true;
58 }
@ ATTRIBUTE_TYPE_CONSTANTVALUE
#define rz_warn_if_fail(expr)
Definition: rz_assert.h:35

References java_attribute_t::attribute_length, ATTRIBUTE_TYPE_CONSTANTVALUE, free(), java_attribute_constant_value_t::index, java_attribute_t::info, rz_buf_read_be16, RZ_NEW0, rz_warn_if_fail, rz_warn_if_reached, and java_attribute_t::type.

Referenced by java_attribute_resolve().

◆ java_attribute_set_linenumbertable()

bool java_attribute_set_linenumbertable ( Attribute attr,
RzBuffer buf 
)

Definition at line 189 of file class_attribute.c.

189  {
190  rz_warn_if_fail(attr->attribute_length >= 2);
192  if (!alnt) {
194  return false;
195  }
196  if (!rz_buf_read_be16(buf, &alnt->table_length)) {
197  free(alnt);
198  return false;
199  }
200  if (alnt->table_length > 0) {
201  alnt->table = RZ_NEWS0(LineNumberTable, alnt->table_length);
202  if (!alnt->table) {
203  free(alnt);
205  return false;
206  }
207  for (ut32 i = 0; i < alnt->table_length; ++i) {
208  if (!rz_buf_read_be16(buf, &alnt->table[i].start_pc) ||
209  !rz_buf_read_be16(buf, &alnt->table[i].line_number)) {
210  free(alnt->table);
211  free(alnt);
212  return false;
213  }
214  }
215  }
216 
218  attr->info = (void *)alnt;
219  return true;
220 }

References java_attribute_t::attribute_length, ATTRIBUTE_TYPE_LINENUMBERTABLE, free(), i, java_attribute_t::info, java_line_number_table_t::line_number, rz_buf_read_be16, RZ_NEW0, RZ_NEWS0, rz_warn_if_fail, rz_warn_if_reached, java_line_number_table_t::start_pc, java_attribute_line_number_table_t::table, java_attribute_line_number_table_t::table_length, and java_attribute_t::type.

Referenced by java_attribute_resolve().

◆ java_attribute_set_localvariabletable()

bool java_attribute_set_localvariabletable ( Attribute attr,
RzBuffer buf 
)

Definition at line 222 of file class_attribute.c.

222  {
223  rz_warn_if_fail(attr->attribute_length >= 2);
225  if (!alvt) {
227  return false;
228  }
229  if (!rz_buf_read_be16(buf, &alvt->table_length)) {
230  free(alvt);
231  return false;
232  }
233  if (alvt->table_length > 0) {
235  if (!alvt->table) {
236  free(alvt);
238  return false;
239  }
240  for (ut32 i = 0; i < alvt->table_length; ++i) {
241  if (!rz_buf_read_be16(buf, &alvt->table[i].start_pc) ||
242  !rz_buf_read_be16(buf, &alvt->table[i].length) ||
243  !rz_buf_read_be16(buf, &alvt->table[i].name_index) ||
245  !rz_buf_read_be16(buf, &alvt->table[i].index)) {
246  free(alvt->table);
247  free(alvt);
248  return false;
249  }
250  }
251  }
252 
254  attr->info = (void *)alvt;
255  return true;
256 }

References java_attribute_t::attribute_length, ATTRIBUTE_TYPE_LOCALVARIABLETABLE, java_local_variable_table_t::descriptor_index, free(), i, java_local_variable_table_t::index, java_attribute_t::info, java_local_variable_table_t::length, java_local_variable_table_t::name_index, rz_buf_read_be16, RZ_NEW0, RZ_NEWS0, rz_warn_if_fail, rz_warn_if_reached, java_local_variable_table_t::start_pc, java_attribute_local_variable_table_t::table, java_attribute_local_variable_table_t::table_length, and java_attribute_t::type.

Referenced by java_attribute_resolve().

◆ java_attribute_set_localvariabletypetable()

bool java_attribute_set_localvariabletypetable ( Attribute attr,
RzBuffer buf 
)

Definition at line 258 of file class_attribute.c.

258  {
259  rz_warn_if_fail(attr->attribute_length >= 2);
261  if (!alvtt) {
263  return false;
264  }
265  if (!rz_buf_read_be16(buf, &alvtt->table_length)) {
266  free(alvtt);
267  return false;
268  }
269  if (alvtt->table_length > 0) {
271  if (!alvtt->table) {
272  free(alvtt);
274  return false;
275  }
276  for (ut32 i = 0; i < alvtt->table_length; ++i) {
277  if (!rz_buf_read_be16(buf, &alvtt->table[i].start_pc) ||
278  !rz_buf_read_be16(buf, &alvtt->table[i].length) ||
279  !rz_buf_read_be16(buf, &alvtt->table[i].name_index) ||
281  !rz_buf_read_be16(buf, &alvtt->table[i].index)) {
282  free(alvtt->table);
283  free(alvtt);
284  return false;
285  }
286  }
287  }
288 
290  attr->info = (void *)alvtt;
291  return true;
292 }
@ ATTRIBUTE_TYPE_LOCALVARIABLETYPETABLE

References java_attribute_t::attribute_length, ATTRIBUTE_TYPE_LOCALVARIABLETYPETABLE, free(), i, java_local_variable_type_table_t::index, java_attribute_t::info, java_local_variable_type_table_t::length, java_local_variable_type_table_t::name_index, rz_buf_read_be16, RZ_NEW0, RZ_NEWS0, rz_warn_if_fail, rz_warn_if_reached, java_local_variable_type_table_t::signature_index, java_local_variable_type_table_t::start_pc, java_attribute_local_variable_type_table_t::table, java_attribute_local_variable_type_table_t::table_length, and java_attribute_t::type.

Referenced by java_attribute_resolve().

◆ java_attribute_set_module()

bool java_attribute_set_module ( Attribute attr,
RzBuffer buf 
)

Definition at line 294 of file class_attribute.c.

294  {
295  rz_warn_if_fail(attr->attribute_length >= 16);
297  if (!am) {
299  return false;
300  }
301  ut16 *tmp16 = NULL;
302  if (!rz_buf_read_be16(buf, &am->module_name_index) ||
305  goto java_attribute_set_module_bad;
306  return false;
307  }
308 
309  if (!rz_buf_read_be16(buf, &am->requires_count)) {
310  goto java_attribute_set_module_bad;
311  }
312 
313  if (am->requires_count > 0) {
315  if (!am->requires) {
316  goto java_attribute_set_module_bad;
317  }
318  for (ut32 i = 0; i < am->requires_count; ++i) {
319  if (!rz_buf_read_be16(buf, &am->requires[i].index) ||
320  !rz_buf_read_be16(buf, &am->requires[i].flags) ||
322  goto java_attribute_set_module_bad;
323  }
324  }
325  }
326 
327  if (!rz_buf_read_be16(buf, &am->exports_count)) {
328  goto java_attribute_set_module_bad;
329  }
330 
331  if (am->exports_count > 0) {
333  if (!am->exports) {
334  goto java_attribute_set_module_bad;
335  }
336  for (ut32 i = 0; i < am->exports_count; ++i) {
337  if (!rz_buf_read_be16(buf, &am->exports[i].index) ||
338  !rz_buf_read_be16(buf, &am->exports[i].flags) ||
340  goto java_attribute_set_module_bad;
341  }
342  tmp16 = RZ_NEWS0(ut16, am->exports[i].to_count);
343  if (!tmp16) {
344  goto java_attribute_set_module_bad;
345  }
346  am->exports[i].to_indices = tmp16;
347  for (ut32 k = 0; k < am->exports[i].to_count; ++k) {
348  if (!rz_buf_read_be16(buf, &tmp16[k])) {
349  goto java_attribute_set_module_bad;
350  }
351  }
352  }
353  }
354 
355  if (!rz_buf_read_be16(buf, &am->opens_count)) {
356  goto java_attribute_set_module_bad;
357  }
358 
359  if (am->opens_count > 0) {
360  am->opens = RZ_NEWS0(ModuleOpen, am->opens_count);
361  if (!am->opens) {
362  goto java_attribute_set_module_bad;
363  }
364  for (ut32 i = 0; i < am->opens_count; ++i) {
365  if (!rz_buf_read_be16(buf, &am->opens[i].index) ||
366  !rz_buf_read_be16(buf, &am->opens[i].flags) ||
367  !rz_buf_read_be16(buf, &am->opens[i].to_count)) {
368  goto java_attribute_set_module_bad;
369  }
370  tmp16 = RZ_NEWS0(ut16, am->opens[i].to_count);
371  if (!tmp16) {
372  goto java_attribute_set_module_bad;
373  }
374  am->opens[i].to_indices = tmp16;
375  for (ut32 k = 0; k < am->opens[i].to_count; ++k) {
376  if (!rz_buf_read_be16(buf, &tmp16[k])) {
377  goto java_attribute_set_module_bad;
378  }
379  }
380  }
381  }
382 
383  if (!rz_buf_read_be16(buf, &am->uses_count)) {
384  goto java_attribute_set_module_bad;
385  }
386 
387  if (am->uses_count > 0) {
388  tmp16 = RZ_NEWS0(ut16, am->uses_count);
389  if (!tmp16) {
390  goto java_attribute_set_module_bad;
391  }
392  am->uses_index = tmp16;
393  for (ut32 i = 0; i < am->uses_count; ++i) {
394  if (!rz_buf_read_be16(buf, &tmp16[i])) {
395  goto java_attribute_set_module_bad;
396  }
397  }
398  }
399 
400  if (!rz_buf_read_be16(buf, &am->provides_count)) {
401  goto java_attribute_set_module_bad;
402  }
403 
404  if (am->provides_count > 0) {
406  if (!am->provides) {
407  goto java_attribute_set_module_bad;
408  }
409  for (ut32 i = 0; i < am->provides_count; ++i) {
410  if (!rz_buf_read_be16(buf, &am->provides[i].index) ||
412  goto java_attribute_set_module_bad;
413  }
414  tmp16 = RZ_NEWS0(ut16, am->provides[i].with_count);
415  if (!tmp16) {
416  goto java_attribute_set_module_bad;
417  }
418  am->provides[i].with_indices = tmp16;
419  for (ut32 k = 0; k < am->provides[i].with_count; ++k) {
420  if (!rz_buf_read_be16(buf, &tmp16[k])) {
421  goto java_attribute_set_module_bad;
422  }
423  }
424  }
425  }
426 
427  attr->type = ATTRIBUTE_TYPE_MODULE;
428  attr->info = (void *)am;
429  return true;
430 
431 java_attribute_set_module_bad:
432  if (am->exports) {
433  for (ut32 i = 0; i < am->exports_count; ++i) {
434  free(am->exports[i].to_indices);
435  }
436  }
437  if (am->opens) {
438  for (ut32 i = 0; i < am->opens_count; ++i) {
439  free(am->opens[i].to_indices);
440  }
441  }
442  if (am->provides) {
443  for (ut32 i = 0; i < am->provides_count; ++i) {
444  free(am->provides[i].with_indices);
445  }
446  }
447  free(am->uses_index);
448  free(am->exports);
449  free(am->requires);
450  free(am);
451  return false;
452 }
const char * k
Definition: dsignal.c:11

References java_attribute_t::attribute_length, ATTRIBUTE_TYPE_MODULE, java_attribute_module_t::exports, java_attribute_module_t::exports_count, java_module_open_t::flags, java_module_export_t::flags, java_module_require_t::flags, free(), i, java_module_provide_t::index, java_module_open_t::index, java_module_export_t::index, java_module_require_t::index, java_attribute_t::info, k, java_attribute_module_t::module_flags, java_attribute_module_t::module_name_index, java_attribute_module_t::module_version_index, NULL, java_attribute_module_t::opens, java_attribute_module_t::opens_count, java_attribute_module_t::provides, java_attribute_module_t::provides_count, java_attribute_module_t::requires, java_attribute_module_t::requires_count, rz_buf_read_be16, RZ_NEW0, RZ_NEWS0, rz_warn_if_fail, rz_warn_if_reached, java_module_open_t::to_count, java_module_export_t::to_count, java_module_open_t::to_indices, java_module_export_t::to_indices, java_attribute_t::type, java_attribute_module_t::uses_count, java_attribute_module_t::uses_index, java_module_require_t::version_index, java_module_provide_t::with_count, and java_module_provide_t::with_indices.

Referenced by java_attribute_resolve().

◆ java_attribute_set_modulemainclass()

bool java_attribute_set_modulemainclass ( Attribute attr,
RzBuffer buf 
)

Definition at line 488 of file class_attribute.c.

488  {
489  rz_warn_if_fail(attr->attribute_length == 2);
491  if (!ammc) {
493  return false;
494  }
495  if (!rz_buf_read_be16(buf, &ammc->main_class_index)) {
496  free(ammc);
497  return false;
498  }
500  attr->info = (void *)ammc;
501  return true;
502 }
@ ATTRIBUTE_TYPE_MODULEMAINCLASS

References java_attribute_t::attribute_length, ATTRIBUTE_TYPE_MODULEMAINCLASS, free(), java_attribute_t::info, java_attribute_module_main_class_t::main_class_index, rz_buf_read_be16, RZ_NEW0, rz_warn_if_fail, rz_warn_if_reached, and java_attribute_t::type.

Referenced by java_attribute_resolve().

◆ java_attribute_set_modulepackages()

bool java_attribute_set_modulepackages ( Attribute attr,
RzBuffer buf 
)

Definition at line 454 of file class_attribute.c.

454  {
455  rz_warn_if_fail(attr->attribute_length >= 2);
457  if (!amp) {
459  return false;
460  }
461 
462  if (!rz_buf_read_be16(buf, &amp->package_count)) {
463  free(amp);
464  return false;
465  }
466 
467  if (amp->package_count > 0) {
469  if (!amp->package_index) {
470  free(amp);
472  return false;
473  }
474  for (ut32 k = 0; k < amp->package_count; ++k) {
475  if (!rz_buf_read_be16(buf, &amp->package_index[k])) {
476  free(amp->package_index);
477  free(amp);
478  return false;
479  }
480  }
481  }
482 
484  attr->info = (void *)amp;
485  return true;
486 }

References java_attribute_t::attribute_length, ATTRIBUTE_TYPE_MODULEPACKAGES, free(), java_attribute_t::info, k, java_attribute_module_packages_t::package_count, java_attribute_module_packages_t::package_index, rz_buf_read_be16, RZ_NEW0, RZ_NEWS0, rz_warn_if_fail, rz_warn_if_reached, and java_attribute_t::type.

Referenced by java_attribute_resolve().

◆ java_attribute_set_sourcedebugextension()

bool java_attribute_set_sourcedebugextension ( Attribute attr,
RzBuffer buf 
)

Definition at line 171 of file class_attribute.c.

171  {
173  if (attr->attribute_length < 1) {
174  return true;
175  }
176  st64 size = (st64)attr->attribute_length;
177  /*
178  The debug_extension array holds a string, which must be in UTF-8 format. There is no terminating zero byte.
179  The string in the debug_extension item will be interpreted as extended debugging information.
180  */
181  attr->info = make_string(buf, size);
182  if (!attr->info) {
184  return false;
185  }
186  return true;
187 }
static ut8 * make_string(RzBuffer *buf, st64 size)
@ ATTRIBUTE_TYPE_SOURCEDEBUGEXTENSION
voidpf void uLong size
Definition: ioapi.h:138
#define st64
Definition: rz_types_base.h:10

References java_attribute_t::attribute_length, ATTRIBUTE_TYPE_SOURCEDEBUGEXTENSION, java_attribute_t::info, make_string(), rz_warn_if_reached, st64, and java_attribute_t::type.

Referenced by java_attribute_resolve().

◆ java_attribute_set_sourcefile()

bool java_attribute_set_sourcefile ( Attribute attr,
RzBuffer buf 
)

Definition at line 154 of file class_attribute.c.

154  {
155  rz_warn_if_fail(attr->attribute_length == 2);
157  if (!asf) {
159  return false;
160  }
161  if (!rz_buf_read_be16(buf, &asf->index)) {
162  free(asf);
163  return false;
164  }
165 
167  attr->info = (void *)asf;
168  return true;
169 }
@ ATTRIBUTE_TYPE_SOURCEFILE

References java_attribute_t::attribute_length, ATTRIBUTE_TYPE_SOURCEFILE, free(), java_attribute_source_file_t::index, java_attribute_t::info, rz_buf_read_be16, RZ_NEW0, rz_warn_if_fail, rz_warn_if_reached, and java_attribute_t::type.

Referenced by java_attribute_resolve().

◆ java_attribute_set_unknown()

bool java_attribute_set_unknown ( Attribute attr,
RzBuffer buf 
)

Definition at line 32 of file class_attribute.c.

32  {
34  if (attr->attribute_length < 1) {
35  return true;
36  }
37  st64 size = (st64)attr->attribute_length;
39  return true;
40 }
@ ATTRIBUTE_TYPE_UNKNOWN

References java_attribute_t::attribute_length, ATTRIBUTE_TYPE_UNKNOWN, RZ_BUF_CUR, rz_buf_seek(), st64, and java_attribute_t::type.

Referenced by java_attribute_resolve().

◆ make_string()

static ut8* make_string ( RzBuffer buf,
st64  size 
)
static

Definition at line 6 of file class_attribute.c.

6  {
7  ut8 *buffer;
10  return NULL;
11  }
12 
13  buffer = (ut8 *)malloc(size + 1);
14  if (!buffer || rz_buf_read(buf, buffer, size) < (size - 1)) {
16  free(buffer);
17  return NULL;
18  }
19  buffer[size] = 0;
20 
21  return buffer;
22 }
struct buffer buffer
void * malloc(size_t size)
Definition: malloc.c:123
RZ_API st64 rz_buf_read(RZ_NONNULL RzBuffer *b, RZ_NONNULL RZ_OUT ut8 *buf, ut64 len)
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
Definition: buf.c:1225
Definition: buffer.h:15
#define buffer_size(buffer)

References buffer_size, free(), malloc(), NULL, rz_buf_read(), rz_buf_size(), rz_warn_if_reached, and st64.

Referenced by java_attribute_set_sourcedebugextension().

◆ resolve_const_pool_index()

static char* resolve_const_pool_index ( ConstPool **  pool,
ut32  poolsize,
ut32  index 
)
static

Definition at line 24 of file class_attribute.c.

24  {
25  const ConstPool *cpool;
26  if (index >= poolsize || !(cpool = pool[index])) {
27  return NULL;
28  }
29  return java_constant_pool_stringify(cpool);
30 }
char * java_constant_pool_stringify(const ConstPool *cpool)

References java_constant_pool_stringify(), and NULL.

Referenced by java_attribute_resolve().