Rizin
unix-like reverse engineering framework and cli tools
bobj.c File Reference
#include <rz_bin.h>
#include <rz_util.h>
#include "i/private.h"

Go to the source code of this file.

Macros

#define CMP_CHECK(member)
 

Functions

RZ_API void rz_bin_string_decode_base64 (RZ_NONNULL RzBinString *bstr)
 Tries to decode the base64 string hold by RzBinString and overwrites it. More...
 
static void bin_object_decode_all_base64_strings (RzList *strings)
 
RZ_API void rz_bin_mem_free (void *data)
 
RZ_API ut64 rz_bin_reloc_size (RzBinReloc *reloc)
 size of the reloc (where it is supposed to be patched) in bits More...
 
static int reloc_cmp (const void *a, const void *b)
 
static int reloc_target_cmp (const void *a, const void *b)
 
RZ_API RzBinRelocStoragerz_bin_reloc_storage_new (RZ_OWN RzList *relocs)
 
RZ_API void rz_bin_reloc_storage_free (RzBinRelocStorage *storage)
 
static int reloc_vaddr_cmp (ut64 ref, RzBinReloc *reloc)
 
RZ_API RzBinRelocrz_bin_reloc_storage_get_reloc_in (RzBinRelocStorage *storage, ut64 vaddr, ut64 size)
 Get the reloc with the lowest vaddr that starts inside the given interval. More...
 
static int reloc_target_vaddr_cmp (ut64 ref, RzBinReloc *reloc)
 
RZ_API RzBinRelocrz_bin_reloc_storage_get_reloc_to (RzBinRelocStorage *storage, ut64 vaddr)
 Get a reloc that points exactly to vaddr or NULL. More...
 
RZ_IPI void rz_bin_object_free (RzBinObject *o)
 
static char * swiftField (const char *dn, const char *cn)
 
static RzListclasses_from_symbols (RzBinFile *bf)
 
RZ_IPI RzBinObjectrz_bin_object_new (RzBinFile *bf, RzBinPlugin *plugin, RzBinObjectLoadOptions *opts, ut64 offset, ut64 sz)
 
static void filter_classes (RzBinFile *bf, RzList *list)
 
static void rz_bin_object_rebuild_classes_ht (RzBinObject *o)
 
RZ_API int rz_bin_object_set_items (RzBinFile *bf, RzBinObject *o)
 
RZ_API RzBinRelocStoragerz_bin_object_patch_relocs (RzBinFile *bf, RzBinObject *o)
 
RZ_API RzBinSymbolrz_bin_object_get_symbol_of_import (RzBinObject *o, RzBinImport *imp)
 Find the symbol that represents the given import This is necessary for example to determine the address of an import. More...
 
RZ_API RzBinVirtualFilerz_bin_object_get_virtual_file (RzBinObject *o, const char *name)
 
RZ_IPI RzBinObjectrz_bin_object_get_cur (RzBin *bin)
 
RZ_IPI RzBinObjectrz_bin_object_find_by_arch_bits (RzBinFile *bf, const char *arch, int bits, const char *name)
 
RZ_API ut64 rz_bin_object_addr_with_base (RzBinObject *o, ut64 addr)
 Put the given address on top of o's base address. More...
 
RZ_API ut64 rz_bin_object_get_vaddr (RzBinObject *o, ut64 paddr, ut64 vaddr)
 
RZ_API const RzBinAddrrz_bin_object_get_special_symbol (RzBinObject *o, RzBinSpecialSymbol sym)
 Return the RzBinAddr structure representing the special symbol sym. More...
 
RZ_API const RzListrz_bin_object_get_entries (RZ_NONNULL RzBinObject *obj)
 Get list of RzBinAddr representing the entry points of the binary object. More...
 
RZ_API const RzListrz_bin_object_get_fields (RZ_NONNULL RzBinObject *obj)
 Get list of RzBinField representing the fields of the binary object. More...
 
RZ_API const RzListrz_bin_object_get_imports (RZ_NONNULL RzBinObject *obj)
 Get list of RzBinImport representing the imports of the binary object. More...
 
RZ_API const RzBinInforz_bin_object_get_info (RZ_NONNULL RzBinObject *obj)
 Get the RzBinInfo of the binary object. More...
 
RZ_API const RzListrz_bin_object_get_libs (RZ_NONNULL RzBinObject *obj)
 Get list of char* representing the libraries used by the binary object. More...
 
RZ_API const RzListrz_bin_object_get_sections_all (RZ_NONNULL RzBinObject *obj)
 Get list of RzBinSection representing both the sections and the segments of the binary object. More...
 
static RzListget_sections_or_segment (RzBinObject *obj, bool is_segment)
 
RZ_API RZ_OWN RzListrz_bin_object_get_sections (RZ_NONNULL RzBinObject *obj)
 Get list of RzBinSection representing only the sections of the binary object. More...
 
RZ_API RZ_OWN RzListrz_bin_object_get_segments (RZ_NONNULL RzBinObject *obj)
 Get list of RzBinSection representing only the segments of the binary object. More...
 
RZ_API const RzListrz_bin_object_get_classes (RZ_NONNULL RzBinObject *obj)
 Get list of RzBinClass representing the classes (e.g. C++ classes) defined in the binary object. More...
 
RZ_API const RzListrz_bin_object_get_strings (RZ_NONNULL RzBinObject *obj)
 Get list of RzBinString representing the strings identified in the binary object. More...
 
RZ_API const RzListrz_bin_object_get_mem (RZ_NONNULL RzBinObject *obj)
 Get list of RzBinMem representing the memory regions identified in the binary object. More...
 
RZ_API const RzListrz_bin_object_get_symbols (RZ_NONNULL RzBinObject *obj)
 Get list of RzBinSymbol representing the symbols in the binary object. More...
 
RZ_API const RzListrz_bin_object_get_resources (RZ_NONNULL RzBinObject *obj)
 Get a list of RzBinResource representing the resources in the binary object. More...
 
RZ_API bool rz_bin_object_reset_strings (RZ_NONNULL RzBin *bin, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzBinObject *obj)
 Remove all previously identified strings in the binary object and scan it again for strings. More...
 
RZ_API RZ_BORROW RzBinStringrz_bin_object_get_string_at (RZ_NONNULL RzBinObject *obj, ut64 address, bool is_va)
 Return RzBinString if at address there is an entry in the RzBinObject string database. More...
 
RZ_API bool rz_bin_object_is_big_endian (RZ_NONNULL RzBinObject *obj)
 Return true if the binary object obj is big endian. More...
 
RZ_API bool rz_bin_object_is_static (RZ_NONNULL RzBinObject *obj)
 Return true if the binary object obj is detected as statically compiled. More...
 
static void bin_section_map_fini (void *e, void *user)
 
RZ_API RZ_OWN RzVectorrz_bin_object_sections_mapping_list (RZ_NONNULL RzBinObject *obj)
 Get the mapping between segments and sections in the binary. More...
 
static ut64 map_p2v (RzBinMap *m, ut64 paddr)
 
RZ_API ut64 rz_bin_object_p2v (RZ_NONNULL RzBinObject *obj, ut64 paddr)
 Convert offset in the file to virtual address according to binary mappings. More...
 
RZ_API RzVectorrz_bin_object_p2v_all (RZ_NONNULL RzBinObject *obj, ut64 paddr)
 Convert offset in the file to all possible virtual addresses according to binary mappings. More...
 
RZ_API ut64 rz_bin_object_v2p (RZ_NONNULL RzBinObject *obj, ut64 vaddr)
 Convert virtual address to offset in the file according to binary mappings. More...
 
RZ_API RZ_OWN RzBinStrDbrz_bin_string_database_new (RZ_NULLABLE RZ_OWN RzList *list)
 Allocates and initializes the RzBinStrDb structure with the given list of strings. More...
 
RZ_API void rz_bin_string_database_free (RZ_NULLABLE RzBinStrDb *db)
 Frees a RzBinStrDb structure. More...
 
RZ_API bool rz_bin_string_database_add (RZ_NONNULL RzBinStrDb *db, RZ_NONNULL RzBinString *bstr)
 { function_description } More...
 
RZ_API bool rz_bin_string_database_remove (RZ_NONNULL RzBinStrDb *db, ut64 address, bool is_va)
 Return true if the given address has been removed to the RzBinObject string database. More...
 

Macro Definition Documentation

◆ CMP_CHECK

#define CMP_CHECK (   member)
Value:
do { \
if (ar->member != br->member) { \
return RZ_NUM_CMP(ar->member, br->member); \
} \
} while (0);
static const ut32 ar[]
Definition: apprentice.c:1935
#define RZ_NUM_CMP(a, b)
Typical comparison (1/0/-1) for two numbers of arbitrary types, including unsigned.
Definition: rz_num.h:157
#define br(opcode, mask, lose, flags)

Definition at line 76 of file bobj.c.

Function Documentation

◆ bin_object_decode_all_base64_strings()

static void bin_object_decode_all_base64_strings ( RzList strings)
static

Definition at line 39 of file bobj.c.

39  {
41 
42  RzBinString *bstr;
44  rz_list_foreach (strings, iter, bstr) {
46  }
47 }
RZ_API void rz_bin_string_decode_base64(RZ_NONNULL RzBinString *bstr)
Tries to decode the base64 string hold by RzBinString and overwrites it.
Definition: bobj.c:15
checking print the parsed form of the magic use in n conjunction with m to debug a new magic file n before installing it n output MIME type strings(--mime-type and\n" " --mime-encoding)\n") OPT('s'
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100

References rz_bin_string_decode_base64(), rz_return_if_fail, and strings().

Referenced by rz_bin_object_reset_strings(), and rz_bin_object_set_items().

◆ bin_section_map_fini()

static void bin_section_map_fini ( void *  e,
void *  user 
)
static

Definition at line 891 of file bobj.c.

891  {
892  (void)user;
894  rz_pvector_fini(&bsm->sections);
895 }
#define e(frag)
RZ_API void rz_pvector_fini(RzPVector *vec)
Definition: vector.c:331
RzPVector sections
Definition: rz_bin.h:643

References e, rz_pvector_fini(), and rz_bin_section_map_t::sections.

Referenced by rz_bin_object_sections_mapping_list().

◆ classes_from_symbols()

static RzList* classes_from_symbols ( RzBinFile bf)
static

Definition at line 243 of file bobj.c.

243  {
244  RzBinSymbol *sym;
245  RzListIter *iter;
246  rz_list_foreach (bf->o->symbols, iter, sym) {
247  if (sym->name[0] != '_') {
248  continue;
249  }
250  const char *cn = sym->classname;
251  if (cn) {
253  if (!c) {
254  continue;
255  }
256  // swift specific
257  char *dn = sym->dname;
258  char *fn = swiftField(dn, cn);
259  if (fn) {
260  RzBinField *f = rz_bin_field_new(sym->paddr, sym->vaddr, sym->size, fn, NULL, NULL, false);
261  rz_list_append(c->fields, f);
262  free(fn);
263  } else {
264  char *mn = strstr(dn, "..");
265  if (!mn) {
266  mn = strstr(dn, cn);
267  if (mn && mn[strlen(cn)] == '.') {
268  rz_list_append(c->methods, sym);
269  }
270  }
271  }
272  }
273  }
274  return bf->o->classes;
275 }
RZ_API RzBinClass * rz_bin_file_add_class(RzBinFile *bf, const char *name, const char *super, int view)
Definition: bfile.c:523
RZ_API RzBinField * rz_bin_field_new(ut64 paddr, ut64 vaddr, int size, const char *name, const char *comment, const char *format, bool format_named)
Definition: bin.c:935
static char * swiftField(const char *dn, const char *cn)
Definition: bobj.c:217
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
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
static const char struct stat static buf struct stat static buf static idle const char static path static fd const char static len const void static prot const char struct module static image struct kernel_sym static table unsigned char static buf static fsuid unsigned struct dirent unsigned static count const struct iovec static count static pid const void static len static flags const struct sched_param static p static pid static policy struct timespec static tp static suid unsigned fn
Definition: sflib.h:186
#define f(i)
Definition: sha256.c:46
#define c(i)
Definition: sha256.c:43
RzBinObject * o
Definition: rz_bin.h:305
RzList * classes
Definition: rz_bin.h:281
RzList * symbols
Definition: rz_bin.h:269
char * name
Definition: rz_bin.h:675
char * classname
Definition: rz_bin.h:678
char * dname
Definition: rz_bin.h:676

References c, rz_bin_object_t::classes, rz_bin_symbol_t::classname, rz_bin_symbol_t::dname, f, fn, free(), rz_bin_symbol_t::name, NULL, rz_bin_file_t::o, rz_bin_symbol_t::paddr, rz_bin_field_new(), rz_bin_file_add_class(), rz_list_append(), rz_bin_symbol_t::size, swiftField(), rz_bin_object_t::symbols, and rz_bin_symbol_t::vaddr.

Referenced by rz_bin_object_set_items().

◆ filter_classes()

static void filter_classes ( RzBinFile bf,
RzList list 
)
static

Definition at line 337 of file bobj.c.

337  {
338  HtPU *db = ht_pu_new0();
339  HtPP *ht = ht_pp_new0();
340  RzListIter *iter, *iter2;
341  RzBinClass *cls;
342  RzBinSymbol *sym;
343  rz_list_foreach (list, iter, cls) {
344  if (!cls->name) {
345  continue;
346  }
347  int namepad_len = strlen(cls->name) + 32;
348  char *namepad = malloc(namepad_len + 1);
349  if (!namepad) {
350  RZ_LOG_ERROR("Cannot allocate %d byte(s)\n", namepad_len);
351  break;
352  }
353 
354  strcpy(namepad, cls->name);
355  char *p = rz_bin_filter_name(bf, db, cls->index, namepad);
356  if (p) {
357  namepad = p;
358  }
359  free(cls->name);
360  cls->name = namepad;
361  rz_list_foreach (cls->methods, iter2, sym) {
362  if (sym->name) {
363  rz_bin_filter_sym(bf, ht, sym->vaddr, sym);
364  }
365  }
366  }
367  ht_pu_free(db);
368  ht_pp_free(ht);
369 }
static RzILOpEffect * cls(cs_insn *insn)
Definition: arm_il64.c:915
RZ_API char * rz_bin_filter_name(RzBinFile *bf, HtPU *db, ut64 vaddr, char *name)
Definition: filter.c:33
RZ_API void rz_bin_filter_sym(RzBinFile *bf, HtPP *ht, ut64 vaddr, RzBinSymbol *sym)
Definition: filter.c:81
void * p
Definition: libc.cpp:67
static void list(RzEgg *egg)
Definition: rz-gg.c:52
void * malloc(size_t size)
Definition: malloc.c:123
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58

References cls(), free(), list(), malloc(), rz_bin_symbol_t::name, p, rz_bin_filter_name(), rz_bin_filter_sym(), RZ_LOG_ERROR, and rz_bin_symbol_t::vaddr.

Referenced by rz_bin_object_set_items().

◆ get_sections_or_segment()

static RzList* get_sections_or_segment ( RzBinObject obj,
bool  is_segment 
)
static

Definition at line 755 of file bobj.c.

755  {
756  RzList *res = rz_list_new();
757  if (!res) {
758  return NULL;
759  }
761  RzListIter *it;
762  RzBinSection *sec;
763  rz_list_foreach (all, it, sec) {
764  if (sec->is_segment == is_segment) {
765  rz_list_append(res, sec);
766  }
767  }
768  return res;
769 }
RZ_API const RzList * rz_bin_object_get_sections_all(RZ_NONNULL RzBinObject *obj)
Get list of RzBinSection representing both the sections and the segments of the binary object.
Definition: bobj.c:750
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
Definition: list.c:235
bool is_segment
Definition: rz_bin.h:634

References test_group_name::all, rz_bin_section_t::is_segment, NULL, rz_bin_object_get_sections_all(), rz_list_append(), and rz_list_new().

Referenced by rz_bin_object_get_sections(), and rz_bin_object_get_segments().

◆ map_p2v()

static ut64 map_p2v ( RzBinMap m,
ut64  paddr 
)
static

Definition at line 955 of file bobj.c.

955  {
956  ut64 delta = paddr - m->paddr;
957  if (delta >= m->vsize) {
958  return UT64_MAX;
959  }
960  return m->vaddr + delta;
961 }
#define UT64_MAX
Definition: rz_types_base.h:86
static st64 delta
Definition: vmenus.c:2425
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References delta, regress::m, ut64(), and UT64_MAX.

Referenced by rz_bin_object_p2v(), and rz_bin_object_p2v_all().

◆ reloc_cmp()

static int reloc_cmp ( const void *  a,
const void *  b 
)
static

Definition at line 83 of file bobj.c.

83  {
84  const RzBinReloc *ar = a;
85  const RzBinReloc *br = b;
86  CMP_CHECK(vaddr);
87  CMP_CHECK(paddr);
88  CMP_CHECK(type);
89  CMP_CHECK(target_vaddr);
90  return 0;
91 }
#define CMP_CHECK(member)
Definition: bobj.c:76
int type
Definition: mipsasm.c:17
#define b(i)
Definition: sha256.c:42
#define a(i)
Definition: sha256.c:41

References a, ar, b, br, CMP_CHECK, and type.

Referenced by rz_bin_reloc_storage_new().

◆ reloc_target_cmp()

static int reloc_target_cmp ( const void *  a,
const void *  b 
)
static

Definition at line 93 of file bobj.c.

93  {
94  const RzBinReloc *ar = a;
95  const RzBinReloc *br = b;
96  CMP_CHECK(target_vaddr);
97  CMP_CHECK(vaddr);
98  CMP_CHECK(paddr);
99  CMP_CHECK(type);
100  return 0;
101 }

References a, ar, b, br, CMP_CHECK, and type.

Referenced by rz_bin_reloc_storage_new().

◆ reloc_target_vaddr_cmp()

static int reloc_target_vaddr_cmp ( ut64  ref,
RzBinReloc reloc 
)
static

Definition at line 168 of file bobj.c.

168  {
169  return RZ_NUM_CMP(ref, reloc->target_vaddr);
170 }
ut64 target_vaddr
the target address that the patched reloc points to
Definition: rz_bin.h:718

References RZ_NUM_CMP, and rz_bin_reloc_t::target_vaddr.

Referenced by rz_bin_reloc_storage_get_reloc_to().

◆ reloc_vaddr_cmp()

static int reloc_vaddr_cmp ( ut64  ref,
RzBinReloc reloc 
)
static

Definition at line 149 of file bobj.c.

149  {
150  return RZ_NUM_CMP(ref, reloc->vaddr);
151 }
ut64 vaddr
the vaddr where the value should be patched into
Definition: rz_bin.h:716

References RZ_NUM_CMP, and rz_bin_reloc_t::vaddr.

Referenced by rz_bin_reloc_storage_get_reloc_in().

◆ rz_bin_mem_free()

RZ_API void rz_bin_mem_free ( void *  data)

Definition at line 49 of file bobj.c.

49  {
50  RzBinMem *mem = (RzBinMem *)data;
51  if (mem && mem->mirrors) {
52  mem->mirrors->free = rz_bin_mem_free;
53  rz_list_free(mem->mirrors);
54  mem->mirrors = NULL;
55  }
56  free(mem);
57 }
RZ_API void rz_bin_mem_free(void *data)
Definition: bobj.c:49
void * mem
Definition: libc.cpp:91
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137

References free(), mem, NULL, and rz_list_free().

Referenced by mem().

◆ rz_bin_object_addr_with_base()

RZ_API ut64 rz_bin_object_addr_with_base ( RzBinObject o,
ut64  addr 
)

Put the given address on top of o's base address.

Definition at line 661 of file bobj.c.

661  {
662  return o ? addr + o->baddr_shift : addr;
663 }
st64 baddr_shift
Definition: rz_bin.h:261
static int addr
Definition: z80asm.c:58

References addr, and rz_bin_object_t::baddr_shift.

Referenced by rz_bin_get_section_at(), rz_bin_object_get_map_at(), rz_bin_object_get_maps_at(), rz_bin_object_get_vaddr(), rz_core_bin_apply_main(), and rz_core_bin_main_print().

◆ rz_bin_object_find_by_arch_bits()

RZ_IPI RzBinObject* rz_bin_object_find_by_arch_bits ( RzBinFile bf,
const char *  arch,
int  bits,
const char *  name 
)

Definition at line 644 of file bobj.c.

644  {
645  rz_return_val_if_fail(bf && arch && name, NULL);
646  if (bf->o) {
647  RzBinInfo *info = bf->o->info;
648  if (info && info->arch && info->file &&
649  (bits == info->bits) &&
650  !strcmp(info->arch, arch) &&
651  !strcmp(info->file, name)) {
652  return bf->o;
653  }
654  }
655  return NULL;
656 }
RzBinInfo * info(RzBinFile *bf)
Definition: bin_ne.c:86
int bits(struct state *s, int need)
Definition: blast.c:72
cs_arch arch
Definition: cstool.c:13
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
Definition: z80asm.h:102
char * file
Definition: rz_bin.h:210
char * arch
Definition: rz_bin.h:214
RzBinInfo * info
Definition: rz_bin.h:287

References rz_bin_info_t::arch, arch, rz_bin_info_t::bits, bits(), rz_bin_info_t::file, info(), rz_bin_object_t::info, NULL, rz_bin_file_t::o, and rz_return_val_if_fail.

Referenced by rz_bin_select(), rz_bin_select_object(), and rz_bin_use_arch().

◆ rz_bin_object_free()

RZ_IPI void rz_bin_object_free ( RzBinObject o)

Definition at line 188 of file bobj.c.

188  {
189  if (!o) {
190  return;
191  }
192  free(o->regstate);
194  ht_up_free(o->addrzklassmethod);
195  rz_list_free(o->entries);
196  rz_list_free(o->maps);
197  rz_list_free(o->vfiles);
198  rz_list_free(o->fields);
199  rz_list_free(o->imports);
200  rz_list_free(o->libs);
204  ht_pp_free(o->import_name_symbols);
205  rz_list_free(o->symbols);
206  rz_list_free(o->classes);
207  ht_pp_free(o->classes_ht);
208  ht_pp_free(o->methods_ht);
210  rz_list_free(o->mem);
211  for (ut32 i = 0; i < RZ_BIN_SPECIAL_SYMBOL_LAST; i++) {
212  free(o->binsym[i]);
213  }
214  free(o);
215 }
lzma_index ** i
Definition: index.h:629
RZ_API void rz_bin_info_free(RzBinInfo *rb)
Definition: bin.c:97
RZ_API void rz_bin_string_database_free(RZ_NULLABLE RzBinStrDb *db)
Frees a RzBinStrDb structure.
Definition: bobj.c:1076
RZ_API void rz_bin_reloc_storage_free(RzBinRelocStorage *storage)
Definition: bobj.c:137
RZ_API void rz_bin_source_line_info_free(RzBinSourceLineInfo *sli)
Definition: dbginfo.c:137
uint32_t ut32
@ RZ_BIN_SPECIAL_SYMBOL_LAST
Definition: rz_bin.h:141
RzList * fields
Definition: rz_bin.h:277
RzList * imports
Definition: rz_bin.h:268
HtPP * import_name_symbols
Acceleration structure for fast access of the symbol for a given import. This associates the name of ...
Definition: rz_bin.h:275
RzList * maps
Definition: rz_bin.h:266
RzList * entries
Definition: rz_bin.h:276
RzBinStrDb * strings
Definition: rz_bin.h:280
RzBinSourceLineInfo * lines
Definition: rz_bin.h:284
HtPP * methods_ht
Definition: rz_bin.h:283
RzList * mem
Definition: rz_bin.h:285
HtPP * classes_ht
Definition: rz_bin.h:282
char * regstate
Definition: rz_bin.h:286
RzList * libs
Definition: rz_bin.h:278
RzList * sections
Definition: rz_bin.h:267
RzList * vfiles
Definition: rz_bin.h:265
HtUP * addrzklassmethod
Definition: rz_bin.h:292
RzBinAddr * binsym[RZ_BIN_SPECIAL_SYMBOL_LAST]
Definition: rz_bin.h:288
RzBinRelocStorage * relocs
Definition: rz_bin.h:279

References rz_bin_object_t::addrzklassmethod, rz_bin_object_t::binsym, rz_bin_object_t::classes, rz_bin_object_t::classes_ht, rz_bin_object_t::entries, rz_bin_object_t::fields, free(), i, rz_bin_object_t::import_name_symbols, rz_bin_object_t::imports, rz_bin_object_t::info, rz_bin_object_t::libs, rz_bin_object_t::lines, rz_bin_object_t::maps, rz_bin_object_t::mem, rz_bin_object_t::methods_ht, rz_bin_object_t::regstate, rz_bin_object_t::relocs, rz_bin_info_free(), rz_bin_reloc_storage_free(), rz_bin_source_line_info_free(), RZ_BIN_SPECIAL_SYMBOL_LAST, rz_bin_string_database_free(), rz_list_free(), rz_bin_object_t::sections, rz_bin_object_t::strings, rz_bin_object_t::symbols, and rz_bin_object_t::vfiles.

Referenced by rz_bin_file_free(), and rz_bin_object_new().

◆ rz_bin_object_get_classes()

RZ_API const RzList* rz_bin_object_get_classes ( RZ_NONNULL RzBinObject obj)

Get list of RzBinClass representing the classes (e.g. C++ classes) defined in the binary object.

Definition at line 790 of file bobj.c.

790  {
792  return obj->classes;
793 }

References NULL, and rz_return_val_if_fail.

Referenced by rz_core_bin_class_as_source_print(), rz_core_bin_class_fields_print(), rz_core_bin_class_methods_print(), and rz_core_bin_classes_print().

◆ rz_bin_object_get_cur()

RZ_IPI RzBinObject* rz_bin_object_get_cur ( RzBin bin)

Definition at line 639 of file bobj.c.

639  {
640  rz_return_val_if_fail(bin && bin->cur, NULL);
641  return bin->cur->o;
642 }
Definition: malloc.c:26

References NULL, and rz_return_val_if_fail.

◆ rz_bin_object_get_entries()

RZ_API const RzList* rz_bin_object_get_entries ( RZ_NONNULL RzBinObject obj)

Get list of RzBinAddr representing the entry points of the binary object.

Definition at line 710 of file bobj.c.

710  {
712  return obj->entries;
713 }

References NULL, and rz_return_val_if_fail.

Referenced by entries_initfini_print(), and rz_bin_get_entries().

◆ rz_bin_object_get_fields()

RZ_API const RzList* rz_bin_object_get_fields ( RZ_NONNULL RzBinObject obj)

Get list of RzBinField representing the fields of the binary object.

Definition at line 718 of file bobj.c.

718  {
720  return obj->fields;
721 }

References NULL, and rz_return_val_if_fail.

Referenced by rz_bin_get_fields(), and rz_core_bin_fields_print().

◆ rz_bin_object_get_imports()

RZ_API const RzList* rz_bin_object_get_imports ( RZ_NONNULL RzBinObject obj)

Get list of RzBinImport representing the imports of the binary object.

Definition at line 726 of file bobj.c.

726  {
728  return obj->imports;
729 }

References NULL, and rz_return_val_if_fail.

Referenced by rz_bin_get_imports(), rz_core_bin_imports_print(), and rzfind_open_file().

◆ rz_bin_object_get_info()

RZ_API const RzBinInfo* rz_bin_object_get_info ( RZ_NONNULL RzBinObject obj)

Get the RzBinInfo of the binary object.

Definition at line 734 of file bobj.c.

734  {
736  return obj->info;
737 }

References NULL, and rz_return_val_if_fail.

Referenced by rz_bin_get_info().

◆ rz_bin_object_get_libs()

RZ_API const RzList* rz_bin_object_get_libs ( RZ_NONNULL RzBinObject obj)

Get list of char* representing the libraries used by the binary object.

Definition at line 742 of file bobj.c.

742  {
744  return obj->libs;
745 }

References NULL, and rz_return_val_if_fail.

Referenced by rz_bin_get_libs(), and rz_core_bin_libs_print().

◆ rz_bin_object_get_mem()

RZ_API const RzList* rz_bin_object_get_mem ( RZ_NONNULL RzBinObject obj)

Get list of RzBinMem representing the memory regions identified in the binary object.

Definition at line 809 of file bobj.c.

809  {
811  return obj->mem;
812 }

References NULL, and rz_return_val_if_fail.

Referenced by rz_bin_get_mem(), and rz_core_bin_memory_print().

◆ rz_bin_object_get_resources()

RZ_API const RzList* rz_bin_object_get_resources ( RZ_NONNULL RzBinObject obj)

Get a list of RzBinResource representing the resources in the binary object.

Definition at line 825 of file bobj.c.

825  {
827  return obj->resources;
828 }

References NULL, and rz_return_val_if_fail.

Referenced by rz_core_bin_resources_print().

◆ rz_bin_object_get_sections()

RZ_API RZ_OWN RzList* rz_bin_object_get_sections ( RZ_NONNULL RzBinObject obj)

Get list of RzBinSection representing only the sections of the binary object.

Definition at line 774 of file bobj.c.

774  {
776  return get_sections_or_segment(obj, false);
777 }
static RzList * get_sections_or_segment(RzBinObject *obj, bool is_segment)
Definition: bobj.c:755

References get_sections_or_segment(), NULL, and rz_return_val_if_fail.

Referenced by rz_bin_file_golang_compiler(), rz_cmd_info_section_bars_handler(), and rz_core_bin_sections_print().

◆ rz_bin_object_get_sections_all()

RZ_API const RzList* rz_bin_object_get_sections_all ( RZ_NONNULL RzBinObject obj)

Get list of RzBinSection representing both the sections and the segments of the binary object.

Definition at line 750 of file bobj.c.

750  {
752  return obj->sections;
753 }

References NULL, and rz_return_val_if_fail.

Referenced by get_sections_or_segment(), rz_bin_get_sections(), and rz_bin_object_sections_mapping_list().

◆ rz_bin_object_get_segments()

RZ_API RZ_OWN RzList* rz_bin_object_get_segments ( RZ_NONNULL RzBinObject obj)

Get list of RzBinSection representing only the segments of the binary object.

Definition at line 782 of file bobj.c.

782  {
784  return get_sections_or_segment(obj, true);
785 }

References get_sections_or_segment(), NULL, and rz_return_val_if_fail.

Referenced by rz_core_bin_segments_print().

◆ rz_bin_object_get_special_symbol()

RZ_API const RzBinAddr* rz_bin_object_get_special_symbol ( RzBinObject o,
RzBinSpecialSymbol  sym 
)

Return the RzBinAddr structure representing the special symbol sym.

Definition at line 699 of file bobj.c.

699  {
701  if (sym < 0 || sym >= RZ_BIN_SPECIAL_SYMBOL_LAST) {
702  return NULL;
703  }
704  return o ? o->binsym[sym] : NULL;
705 }

References rz_bin_object_t::binsym, NULL, RZ_BIN_SPECIAL_SYMBOL_LAST, and rz_return_val_if_fail.

Referenced by rz_core_analysis_all(), rz_core_bin_apply_main(), and rz_core_bin_main_print().

◆ rz_bin_object_get_string_at()

RZ_API RZ_BORROW RzBinString* rz_bin_object_get_string_at ( RZ_NONNULL RzBinObject obj,
ut64  address,
bool  is_va 
)

Return RzBinString if at address there is an entry in the RzBinObject string database.

Definition at line 861 of file bobj.c.

861  {
862  rz_return_val_if_fail(obj, false);
863  if (!obj->strings) {
864  return NULL;
865  }
866  if (is_va) {
867  return ht_up_find(obj->strings->virt, address, NULL);
868  }
869  return ht_up_find(obj->strings->phys, address, NULL);
870 }

References NULL, and rz_return_val_if_fail.

Referenced by add_new_bin_string(), and rz_analysis_set_stringrefs().

◆ rz_bin_object_get_strings()

RZ_API const RzList* rz_bin_object_get_strings ( RZ_NONNULL RzBinObject obj)

Get list of RzBinString representing the strings identified in the binary object.

Definition at line 798 of file bobj.c.

798  {
800  if (!obj->strings) {
801  return NULL;
802  }
803  return obj->strings->list;
804 }

References NULL, and rz_return_val_if_fail.

Referenced by add_new_bin_string(), rz_bin_get_strings(), rz_core_bin_strings_print(), and rz_diff_strings_new().

◆ rz_bin_object_get_symbol_of_import()

RZ_API RzBinSymbol* rz_bin_object_get_symbol_of_import ( RzBinObject o,
RzBinImport imp 
)

Find the symbol that represents the given import This is necessary for example to determine the address of an import.

Definition at line 616 of file bobj.c.

616  {
617  rz_return_val_if_fail(o && imp && imp->name, NULL);
618  if (!o->import_name_symbols) {
619  return NULL;
620  }
621  return ht_pp_find(o->import_name_symbols, imp->name, NULL);
622 }
char * name
Definition: rz_bin.h:701

References rz_bin_object_t::import_name_symbols, rz_bin_import_t::name, NULL, and rz_return_val_if_fail.

Referenced by rz_core_analysis_importxrefs(), rz_core_bin_apply_imports(), and rz_core_bin_imports_print().

◆ rz_bin_object_get_symbols()

RZ_API const RzList* rz_bin_object_get_symbols ( RZ_NONNULL RzBinObject obj)

Get list of RzBinSymbol representing the symbols in the binary object.

Definition at line 817 of file bobj.c.

817  {
819  return obj->symbols;
820 }

References NULL, and rz_return_val_if_fail.

Referenced by rz_analyze_symbols_entries_handler(), rz_bin_file_get_symbols(), rz_bin_get_symbols(), rzfind_open_file(), and symbols_print().

◆ rz_bin_object_get_vaddr()

RZ_API ut64 rz_bin_object_get_vaddr ( RzBinObject o,
ut64  paddr,
ut64  vaddr 
)

Definition at line 669 of file bobj.c.

669  {
671 
672  if (paddr == UT64_MAX) {
673  // everything we have is the vaddr
674  return vaddr;
675  }
676 
677  /* hack to realign thumb symbols */
678  if (o->info && o->info->arch) {
679  if (o->info->bits == 16) {
680  RzBinSection *s = rz_bin_get_section_at(o, paddr, false);
681  // autodetect thumb
682  if (s && (s->perm & RZ_PERM_X) && strstr(s->name, "text")) {
683  if (!strcmp(o->info->arch, "arm") && (vaddr & 1)) {
684  vaddr = (vaddr >> 1) << 1;
685  }
686  }
687  }
688  }
689 
690  if (o->info && o->info->has_va) {
691  return rz_bin_object_addr_with_base(o, vaddr);
692  }
693  return paddr;
694 }
RZ_API RZ_BORROW RzBinSection * rz_bin_get_section_at(RzBinObject *o, ut64 off, int va)
Find the binary section at offset off.
Definition: bin.c:611
RZ_API ut64 rz_bin_object_addr_with_base(RzBinObject *o, ut64 addr)
Put the given address on top of o's base address.
Definition: bobj.c:661
static RzSocket * s
Definition: rtr.c:28
#define RZ_PERM_X
Definition: rz_types.h:95
int has_va
Definition: rz_bin.h:228

References rz_bin_info_t::arch, rz_bin_info_t::bits, rz_bin_info_t::has_va, rz_bin_object_t::info, rz_bin_get_section_at(), rz_bin_object_addr_with_base(), RZ_PERM_X, rz_return_val_if_fail, s, and UT64_MAX.

Referenced by print_bin_string(), print_string(), rva(), rz_core_analysis_all(), and rz_core_analysis_importxrefs().

◆ rz_bin_object_get_virtual_file()

RZ_API RzBinVirtualFile* rz_bin_object_get_virtual_file ( RzBinObject o,
const char *  name 
)

Definition at line 624 of file bobj.c.

624  {
626  if (!o->vfiles) {
627  return NULL;
628  }
629  RzListIter *it;
630  RzBinVirtualFile *vf;
631  rz_list_foreach (o->vfiles, it, vf) {
632  if (!strcmp(vf->name, name)) {
633  return vf;
634  }
635  }
636  return NULL;
637 }
RZ_OWN RZ_NONNULL char * name
Definition: rz_bin.h:596

References rz_bin_virtual_file_t::name, NULL, rz_return_val_if_fail, and rz_bin_object_t::vfiles.

◆ rz_bin_object_is_big_endian()

RZ_API bool rz_bin_object_is_big_endian ( RZ_NONNULL RzBinObject obj)

Return true if the binary object obj is big endian.

Definition at line 875 of file bobj.c.

875  {
876  rz_return_val_if_fail(obj, false);
877  return obj->info ? obj->info->big_endian : false;
878 }

References rz_return_val_if_fail.

◆ rz_bin_object_is_static()

RZ_API bool rz_bin_object_is_static ( RZ_NONNULL RzBinObject obj)

Return true if the binary object obj is detected as statically compiled.

Definition at line 883 of file bobj.c.

883  {
884  rz_return_val_if_fail(obj, false);
885  if (obj->libs && rz_list_length(obj->libs) > 0) {
886  return RZ_BIN_DBG_STATIC & obj->info->dbg_info;
887  }
888  return true;
889 }
RZ_API ut32 rz_list_length(RZ_NONNULL const RzList *list)
Returns the length of the list.
Definition: list.c:109
#define RZ_BIN_DBG_STATIC
Definition: rz_bin.h:28

References RZ_BIN_DBG_STATIC, rz_list_length(), and rz_return_val_if_fail.

Referenced by rz_bin_is_static().

◆ rz_bin_object_new()

RZ_IPI RzBinObject* rz_bin_object_new ( RzBinFile bf,
RzBinPlugin plugin,
RzBinObjectLoadOptions opts,
ut64  offset,
ut64  sz 
)

Definition at line 278 of file bobj.c.

278  {
279  rz_return_val_if_fail(bf && plugin, NULL);
280  ut64 bytes_sz = rz_buf_size(bf->buf);
282  if (!o) {
283  return NULL;
284  }
285  o->opts = *opts;
286  if (o->opts.loadaddr == UT64_MAX) {
287  // no loadaddr means 0 loadaddr
288  o->opts.loadaddr = 0;
289  }
290  o->obj_size = (bytes_sz >= sz + offset) ? sz : 0;
291  o->boffset = offset;
292  o->regstate = NULL;
294  o->classes_ht = ht_pp_new0();
295  o->methods_ht = ht_pp_new0();
296  o->baddr_shift = 0;
297  o->plugin = plugin;
298 
299  if (plugin && plugin->load_buffer) {
300  if (!plugin->load_buffer(bf, o, bf->buf, bf->sdb)) {
301  if (bf->rbin->verbose) {
302  RZ_LOG_ERROR("rz_bin_object_new: load_buffer failed for %s plugin\n", plugin->name);
303  }
305  return NULL;
306  }
307  } else {
308  RZ_LOG_WARN("Plugin %s should implement load_buffer method.\n", plugin->name);
310  return NULL;
311  }
312 
313  // XXX - object size can't be set here and needs to be set where where
314  // the object is created from. The reason for this is to prevent
315  // mis-reporting when the file is loaded from impartial bytes or is
316  // extracted from a set of bytes in the file
317  rz_bin_file_set_obj(bf->rbin, bf, o);
320 
321  if (!bf->rbin->sdb) {
322  return o;
323  }
324 
325  sdb_ns_set(bf->sdb, "info", o->kv);
326  sdb_ns_set(bf->rbin->sdb, "cur", bf->sdb);
327  char *fdns = rz_str_newf("fd.%d", bf->fd);
328  if (fdns) {
329  sdb_ns_set(bf->rbin->sdb, fdns, bf->sdb);
330  free(fdns);
331  }
332  bf->sdb->refs++;
333 
334  return o;
335 }
RZ_IPI bool rz_bin_file_set_obj(RzBin *bin, RzBinFile *bf, RzBinObject *obj)
Definition: bfile.c:263
RZ_IPI void rz_bin_class_free(RzBinClass *k)
Definition: bfile.c:512
RZ_API void rz_bin_set_baddr(RzBin *bin, ut64 baddr)
Definition: bin.c:549
RZ_API int rz_bin_object_set_items(RzBinFile *bf, RzBinObject *o)
Definition: bobj.c:392
RZ_IPI void rz_bin_object_free(RzBinObject *o)
Definition: bobj.c:188
voidpf uLong offset
Definition: ioapi.h:144
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 int sdb_ns_set(Sdb *s, const char *name, Sdb *r)
Definition: ns.c:156
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
Definition: buf.c:1225
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
#define RZ_LOG_WARN(fmtstr,...)
Definition: rz_log.h:56
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
#define RZ_NEW0(x)
Definition: rz_types.h:284
ut64 loadaddr
starting physical address to read from the target file
Definition: rz_bin.h:249
ut64 baseaddr
where the linker maps the binary in memory
Definition: rz_bin.h:248
RZ_DEPRECATE Sdb * sdb
deprecated, put info in C structures instead of this
Definition: rz_bin.h:315
struct rz_bin_t * rbin
Definition: rz_bin.h:316
int fd
when used in combination with RzIO, this refers to the io fd.
Definition: rz_bin.h:300
RzBuffer * buf
Definition: rz_bin.h:303
RzBinObjectLoadOptions opts
Definition: rz_bin.h:260
ut64 boffset
Definition: rz_bin.h:262
struct rz_bin_plugin_t * plugin
Definition: rz_bin.h:289
RZ_DEPRECATE RZ_BORROW Sdb * kv
deprecated, put info in C structures instead of this (holds a copy of another pointer....
Definition: rz_bin.h:291
ut64 obj_size
Definition: rz_bin.h:264
bool(* load_buffer)(RzBinFile *bf, RzBinObject *obj, RzBuffer *buf, Sdb *sdb)
Definition: rz_bin.h:515
char * name
Definition: rz_bin.h:509
bool verbose
Definition: rz_bin.h:359
RZ_DEPRECATE Sdb * sdb
Definition: rz_bin.h:340
int refs
Definition: sdb.h:68

References rz_bin_object_t::baddr_shift, rz_bin_file_load_options_t::baseaddr, rz_bin_object_t::boffset, rz_bin_file_t::buf, rz_bin_object_t::classes, rz_bin_object_t::classes_ht, rz_bin_file_t::fd, free(), rz_bin_object_t::kv, rz_bin_plugin_t::load_buffer, rz_bin_file_load_options_t::loadaddr, rz_bin_object_t::methods_ht, rz_bin_plugin_t::name, NULL, rz_bin_object_t::obj_size, rz_bin_object_t::opts, rz_bin_object_t::plugin, rz_bin_file_t::rbin, sdb_t::refs, rz_bin_object_t::regstate, rz_bin_class_free(), rz_bin_file_set_obj(), rz_bin_object_free(), rz_bin_object_set_items(), rz_bin_set_baddr(), rz_buf_size(), rz_list_newf(), RZ_LOG_ERROR, RZ_LOG_WARN, RZ_NEW0, rz_return_val_if_fail, rz_str_newf(), rz_bin_file_t::sdb, rz_bin_t::sdb, sdb_ns_set(), ut64(), UT64_MAX, and rz_bin_t::verbose.

Referenced by rz_bin_file_new_from_buffer(), and rz_bin_file_object_new_from_xtr_data().

◆ rz_bin_object_p2v()

RZ_API ut64 rz_bin_object_p2v ( RZ_NONNULL RzBinObject obj,
ut64  paddr 
)

Convert offset in the file to virtual address according to binary mappings.

Parameters
objReference to RzBinObject
paddrOffset in the file
Returns
Converted offset to virtual address or UT64_MAX if the conversion cannot be done

Definition at line 970 of file bobj.c.

970  {
972  RzBinMap *m = rz_bin_object_get_map_at(obj, paddr, false);
973  if (!m) {
974  return UT64_MAX;
975  }
976 
977  return map_p2v(m, paddr);
978 }
RZ_API RZ_BORROW RzBinMap * rz_bin_object_get_map_at(RZ_NONNULL RzBinObject *o, ut64 off, bool va)
Find the last binary map at offset off .
Definition: bin.c:643
static ut64 map_p2v(RzBinMap *m, ut64 paddr)
Definition: bobj.c:955
Description of a single memory mapping into virtual memory from a binary.
Definition: rz_bin.h:602

References regress::m, map_p2v(), rz_bin_object_get_map_at(), rz_return_val_if_fail, and UT64_MAX.

Referenced by search_string_thread_runner().

◆ rz_bin_object_p2v_all()

RZ_API RzVector* rz_bin_object_p2v_all ( RZ_NONNULL RzBinObject obj,
ut64  paddr 
)

Convert offset in the file to all possible virtual addresses according to binary mappings.

Parameters
objReference to RzBinObject
paddrOffset in the file
Returns
Vector containing ut64 values of all possible virtual addresses

Definition at line 987 of file bobj.c.

987  {
989  RzPVector *maps = rz_bin_object_get_maps_at(obj, paddr, false);
990  if (!maps) {
991  return NULL;
992  }
993 
994  RzVector *res = rz_vector_new(sizeof(ut64), NULL, NULL);
995  void **it;
996  rz_pvector_foreach (maps, it) {
997  RzBinMap *map = *(RzBinMap **)it;
998  ut64 vaddr = map_p2v(map, paddr);
999  if (vaddr != UT64_MAX) {
1000  rz_vector_push(res, &vaddr);
1001  }
1002  }
1003 
1005  return res;
1006 }
RZ_API RZ_OWN RzPVector * rz_bin_object_get_maps_at(RzBinObject *o, ut64 off, bool va)
Find all binary maps at offset off .
Definition: bin.c:668
static RzList * maps(RzBinFile *bf)
Definition: bin_bf.c:116
size_t map(int syms, int left, int len)
Definition: enough.c:237
RZ_API void * rz_vector_push(RzVector *vec, void *x)
Definition: vector.c:197
RZ_API void rz_pvector_free(RzPVector *vec)
Definition: vector.c:336
RZ_API RzVector * rz_vector_new(size_t elem_size, RzVectorFree free, void *free_user)
Definition: vector.c:42
#define rz_pvector_foreach(vec, it)
Definition: rz_vector.h:334

References map(), map_p2v(), maps(), NULL, rz_bin_object_get_maps_at(), rz_pvector_foreach, rz_pvector_free(), rz_return_val_if_fail, rz_vector_new(), rz_vector_push(), ut64(), and UT64_MAX.

◆ rz_bin_object_patch_relocs()

RZ_API RzBinRelocStorage* rz_bin_object_patch_relocs ( RzBinFile bf,
RzBinObject o 
)

Definition at line 590 of file bobj.c.

590  {
591  rz_return_val_if_fail(bf && o, NULL);
592 
593  static bool first = true;
594  // rz_bin_object_set_items set o->relocs but there we don't have access
595  // to io so we need to be run from bin_relocs, free the previous reloc and get
596  // the patched ones
597  if (first && o->plugin && o->plugin->patch_relocs) {
598  RzList *tmp = o->plugin->patch_relocs(bf);
599  first = false;
600  if (!tmp) {
601  return o->relocs;
602  }
606  first = false;
607  bf->rbin->is_reloc_patched = true;
608  }
609  return o->relocs;
610 }
RZ_API RzBinRelocStorage * rz_bin_reloc_storage_new(RZ_OWN RzList *relocs)
Definition: bobj.c:105
#define REBASE_PADDR(o, l, type_t)
Definition: rz_bin.h:662
RzList *(* patch_relocs)(RzBinFile *bf)
Definition: rz_bin.h:539
bool is_reloc_patched
Definition: rz_bin.h:363

References rz_bin_t::is_reloc_patched, NULL, rz_bin_plugin_t::patch_relocs, rz_bin_object_t::plugin, rz_bin_file_t::rbin, REBASE_PADDR, rz_bin_object_t::relocs, rz_bin_reloc_storage_free(), rz_bin_reloc_storage_new(), rz_return_val_if_fail, and autogen_x86imm::tmp.

Referenced by rz_core_bin_apply_relocs(), and rz_core_bin_relocs_print().

◆ rz_bin_object_rebuild_classes_ht()

static void rz_bin_object_rebuild_classes_ht ( RzBinObject o)
static

Definition at line 371 of file bobj.c.

371  {
372  ht_pp_free(o->classes_ht);
373  ht_pp_free(o->methods_ht);
374  o->classes_ht = ht_pp_new0();
375  o->methods_ht = ht_pp_new0();
376 
377  RzListIter *it, *it2;
378  RzBinClass *klass;
379  RzBinSymbol *method;
380  rz_list_foreach (o->classes, it, klass) {
381  if (klass->name) {
382  ht_pp_insert(o->classes_ht, klass->name, klass);
383 
384  rz_list_foreach (klass->methods, it2, method) {
385  const char *name = sdb_fmt("%s::%s", klass->name, method->name);
386  ht_pp_insert(o->methods_ht, name, method);
387  }
388  }
389  }
390 }
RZ_API char * sdb_fmt(const char *fmt,...)
Definition: fmt.c:26
char * name
Definition: rz_bin.h:647
RzList * methods
Definition: rz_bin.h:653

References rz_bin_object_t::classes, rz_bin_object_t::classes_ht, rz_bin_class_t::methods, rz_bin_object_t::methods_ht, rz_bin_class_t::name, rz_bin_symbol_t::name, and sdb_fmt().

Referenced by rz_bin_object_set_items().

◆ rz_bin_object_reset_strings()

RZ_API bool rz_bin_object_reset_strings ( RZ_NONNULL RzBin bin,
RZ_NONNULL RzBinFile bf,
RZ_NONNULL RzBinObject obj 
)

Remove all previously identified strings in the binary object and scan it again for strings.

Definition at line 833 of file bobj.c.

833  {
834  rz_return_val_if_fail(bin && bf && obj, false);
836 
837  RzList *strings = NULL;
838  RzBinPlugin *plugin = obj->plugin;
839  if (plugin && plugin->strings) {
840  strings = plugin->strings(bf);
841  } else {
842  // when a bin plugin does not provide it's own strings
843  // we always take all the strings found in the binary
844  // the method also converts the paddrs to vaddrs
845  strings = rz_bin_file_strings(bf, bin->minstrlen, true);
846  }
847 
848  if (bin->debase64) {
850  }
852 
853  // RzBinStrDb becomes the owner of the RzList strings
854  obj->strings = rz_bin_string_database_new(strings);
855  return obj->strings != NULL;
856 }
RZ_API RZ_OWN RzList * rz_bin_file_strings(RZ_NONNULL RzBinFile *bf, size_t min_length, bool raw_strings)
Generates a RzList struct containing RzBinString from a given RzBinFile.
Definition: bfile_string.c:325
RZ_API RZ_OWN RzBinStrDb * rz_bin_string_database_new(RZ_NULLABLE RZ_OWN RzList *list)
Allocates and initializes the RzBinStrDb structure with the given list of strings.
Definition: bobj.c:1036
static void bin_object_decode_all_base64_strings(RzList *strings)
Definition: bobj.c:39
#define RZ_FREE_CUSTOM(x, y)
Definition: rz_types.h:375
RzList *(* strings)(RzBinFile *bf)
Definition: rz_bin.h:531

References bin_object_decode_all_base64_strings(), NULL, REBASE_PADDR, rz_bin_file_strings(), rz_bin_string_database_free(), rz_bin_string_database_new(), RZ_FREE_CUSTOM, rz_return_val_if_fail, strings(), and rz_bin_plugin_t::strings.

Referenced by cb_binmaxstr(), cb_binmaxstrbuf(), cb_binminstr(), and cb_binstrenc().

◆ rz_bin_object_sections_mapping_list()

RZ_API RZ_OWN RzVector* rz_bin_object_sections_mapping_list ( RZ_NONNULL RzBinObject obj)

Get the mapping between segments and sections in the binary.

Returns
A RzVector* with RzBinSectionMap structure inside.

Definition at line 902 of file bobj.c.

902  {
904 
906  if (!all) {
907  return NULL;
908  }
909 
911  RzList *segments = rz_list_new();
912  RzBinSection *section, *segment;
913  RzListIter *iter;
914 
915  rz_list_foreach (all, iter, section) {
916  RzList *list = section->is_segment ? segments : sections;
918  }
919 
921  if (!res) {
922  goto err;
923  }
924  rz_vector_reserve(res, rz_list_length(segments));
925 
926  rz_list_foreach (segments, iter, segment) {
927  if (segment->vaddr == UT64_MAX) {
928  continue;
929  }
930  RzInterval segment_itv = (RzInterval){ segment->vaddr, segment->size };
931  RzListIter *iter2;
932 
934  map.segment = segment;
935  rz_pvector_init(&map.sections, NULL);
936 
937  rz_list_foreach (sections, iter2, section) {
938  if (section->vaddr == UT64_MAX) {
939  continue;
940  }
941  RzInterval section_itv = (RzInterval){ section->vaddr, section->vsize };
942  if (rz_itv_begin(section_itv) >= rz_itv_begin(segment_itv) && rz_itv_end(section_itv) <= rz_itv_end(segment_itv) && section->name[0]) {
943  rz_pvector_push(&map.sections, section);
944  }
945  }
946  rz_vector_push(res, &map);
947  }
948 
949 err:
950  rz_list_free(segments);
952  return res;
953 }
static bool err
Definition: armass.c:435
RzList * sections(RzBinFile *bf)
Definition: bin_ne.c:110
static void bin_section_map_fini(void *e, void *user)
Definition: bobj.c:891
static ut64 rz_itv_begin(RzInterval itv)
Definition: rz_itv.h:34
struct rz_interval_t RzInterval
static ut64 rz_itv_end(RzInterval itv)
Definition: rz_itv.h:42
RZ_API void rz_pvector_init(RzPVector *vec, RzPVectorFree free)
Definition: vector.c:298
RZ_API void * rz_vector_reserve(RzVector *vec, size_t capacity)
Definition: vector.c:214
static void ** rz_pvector_push(RzPVector *vec, void *x)
Definition: rz_vector.h:300

References test_group_name::all, bin_section_map_fini(), err, list(), map(), NULL, rz_bin_object_get_sections_all(), rz_itv_begin(), rz_itv_end(), rz_list_append(), rz_list_free(), rz_list_length(), rz_list_new(), rz_pvector_init(), rz_pvector_push(), rz_return_val_if_fail, rz_vector_new(), rz_vector_push(), rz_vector_reserve(), sections(), rz_bin_section_t::size, UT64_MAX, and rz_bin_section_t::vaddr.

Referenced by rz_core_bin_sections_mapping_print().

◆ rz_bin_object_set_items()

RZ_API int rz_bin_object_set_items ( RzBinFile bf,
RzBinObject o 
)

Definition at line 392 of file bobj.c.

392  {
393  rz_return_val_if_fail(bf && o && o->plugin, false);
394 
395  RzBin *bin = bf->rbin;
396  RzBinPlugin *p = o->plugin;
397  int minlen = (bf->rbin->minstrlen > 0) ? bf->rbin->minstrlen : p->minstrlen;
398  bf->o = o;
399 
400  if (p->file_type) {
401  int type = p->file_type(bf);
402  if (type == RZ_BIN_TYPE_CORE) {
403  if (p->regstate) {
404  o->regstate = p->regstate(bf);
405  }
406  }
407  }
408 
409  if (p->boffset) {
410  o->boffset = p->boffset(bf);
411  }
412  // XXX: no way to get info from xtr pluginz?
413  // Note, object size can not be set from here due to potential
414  // inconsistencies
415  if (p->size) {
416  o->size = p->size(bf);
417  }
418  // XXX this is expensive because is O(n^n)
419  if (p->binsym) {
420  for (size_t i = 0; i < RZ_BIN_SPECIAL_SYMBOL_LAST; i++) {
421  o->binsym[i] = p->binsym(bf, i);
422  if (o->binsym[i]) {
423  o->binsym[i]->paddr += o->opts.loadaddr;
424  }
425  }
426  }
427  if (p->entries) {
428  o->entries = p->entries(bf);
430  }
431  if (p->virtual_files) {
432  o->vfiles = p->virtual_files(bf);
433  }
434  if (p->maps) {
435  o->maps = p->maps(bf);
436  if (o->maps) {
437  REBASE_PADDR(o, o->maps, RzBinMap);
438  }
439  }
440  if (p->fields) {
441  o->fields = p->fields(bf);
442  if (o->fields) {
445  }
446  }
447  if (p->imports) {
448  rz_list_free(o->imports);
449  o->imports = p->imports(bf);
450  if (o->imports) {
452  }
453  }
454  if (p->symbols) {
455  o->symbols = p->symbols(bf);
456  if (o->symbols) {
459  if (bin->filter) {
461  }
462  o->import_name_symbols = ht_pp_new0();
463  if (o->import_name_symbols) {
464  RzBinSymbol *sym;
465  RzListIter *it;
466  rz_list_foreach (o->symbols, it, sym) {
467  if (!sym->is_imported || !sym->name || !*sym->name) {
468  continue;
469  }
470  ht_pp_insert(o->import_name_symbols, sym->name, sym);
471  }
472  }
473  }
474  }
475  if (p->libs) {
476  o->libs = p->libs(bf);
477  }
478  if (p->sections) {
479  // XXX sections are populated by call to size
480  if (!o->sections) {
481  o->sections = p->sections(bf);
482  }
484  if (bin->filter) {
486  }
487  }
488 
489  o->info = p->info ? p->info(bf) : NULL;
490 
491  if (bin->filter_rules & (RZ_BIN_REQ_RELOCS | RZ_BIN_REQ_IMPORTS)) {
492  if (p->relocs) {
493  RzList *l = p->relocs(bf);
494  if (l) {
495  REBASE_PADDR(o, l, RzBinReloc);
497  }
498  }
499  }
500  if (bin->filter_rules & RZ_BIN_REQ_STRINGS) {
501  RzList *strings;
502  if (p->strings) {
503  strings = p->strings(bf);
504  } else {
505  // when a bin plugin does not provide it's own strings
506  // we always take all the strings found in the binary
507  // the method also converts the paddrs to vaddrs
508  strings = rz_bin_file_strings(bf, minlen, true);
509  }
510 
511  if (bin->debase64) {
513  }
515 
516  // RzBinStrDb becomes the owner of the RzList strings
518  }
519 
520  if (o->info && RZ_STR_ISEMPTY(o->info->compiler)) {
521  free(o->info->compiler);
523  if (o->info->compiler) {
524  o->info->lang = "go";
525  }
526  }
527 
528  o->lang = rz_bin_language_detect(bf);
529 
530  if (bin->filter_rules & (RZ_BIN_REQ_CLASSES | RZ_BIN_REQ_CLASSES_SOURCES)) {
531  if (p->classes) {
532  RzList *classes = p->classes(bf);
533  if (classes) {
534  // XXX we should probably merge them instead
535  rz_list_free(o->classes);
536  o->classes = classes;
538  }
539 
540  if (o->lang == RZ_BIN_LANGUAGE_SWIFT) {
541  o->classes = classes_from_symbols(bf);
542  }
543  } else {
545  if (classes) {
546  o->classes = classes;
547  }
548  }
549 
550  if (bin->filter) {
551  filter_classes(bf, o->classes);
552  }
553 
554  // cache addr=class+method
555  if (o->classes) {
556  RzList *klasses = o->classes;
557  RzListIter *iter, *iter2;
558  RzBinClass *klass;
559  RzBinSymbol *method;
560  if (!o->addrzklassmethod) {
561  // this is slow. must be optimized, but at least its cached
562  o->addrzklassmethod = ht_up_new0();
563  rz_list_foreach (klasses, iter, klass) {
564  rz_list_foreach (klass->methods, iter2, method) {
565  ht_up_insert(o->addrzklassmethod, method->vaddr, method);
566  }
567  }
568  }
569  }
570  }
571  if (p->lines) {
572  o->lines = p->lines(bf);
573  }
574  if (p->get_sdb) {
575  Sdb *new_kv = p->get_sdb(bf);
576  if (new_kv != o->kv) {
577  sdb_free(o->kv);
578  }
579  o->kv = new_kv;
580  }
581  if (p->mem) {
582  o->mem = p->mem(bf);
583  }
584  if (p->resources) {
585  o->resources = p->resources(bf);
586  }
587  return true;
588 }
RZ_API void rz_bin_filter_symbols(RzBinFile *bf, RzList *list)
Definition: filter.c:128
RZ_API void rz_bin_filter_sections(RzBinFile *bf, RzList *list)
Definition: filter.c:144
RZ_IPI RZ_OWN char * rz_bin_file_golang_compiler(RZ_NONNULL RzBinFile *bf)
Returns the golang compiler info if buildinfo struct is found.
Definition: golang.c:265
static RzList * classes(RzBinFile *bf)
Definition: bin_dex.c:71
RZ_API RzBinLanguage rz_bin_language_detect(RzBinFile *binfile)
Tries to detect which language is used in the binary based on symbols and libraries.
Definition: bin_language.c:69
static RzList * classes_from_symbols(RzBinFile *bf)
Definition: bobj.c:243
static void filter_classes(RzBinFile *bf, RzList *list)
Definition: bobj.c:337
static void rz_bin_object_rebuild_classes_ht(RzBinObject *o)
Definition: bobj.c:371
#define rz_warn_if_fail(expr)
Definition: rz_assert.h:35
@ RZ_BIN_LANGUAGE_SWIFT
Definition: rz_bin.h:152
#define RZ_BIN_REQ_CLASSES_SOURCES
Definition: rz_bin.h:79
#define RZ_BIN_REQ_RELOCS
Definition: rz_bin.h:58
#define RZ_BIN_REQ_CLASSES
Definition: rz_bin.h:61
#define RZ_BIN_REQ_IMPORTS
Definition: rz_bin.h:46
@ RZ_BIN_TYPE_CORE
Definition: rz_bin.h:182
#define RZ_BIN_REQ_STRINGS
Definition: rz_bin.h:52
#define RZ_STR_ISEMPTY(x)
Definition: rz_str.h:67
RZ_API bool sdb_free(Sdb *s)
Definition: sdb.c:206
ut64 paddr
Definition: rz_bin.h:187
const char * lang
Definition: rz_bin.h:224
char * compiler
Definition: rz_bin.h:244
RzBinLanguage lang
Definition: rz_bin.h:290
RzList * resources
Definition: rz_bin.h:270
bool is_imported
Definition: rz_bin.h:684
int minstrlen
Definition: rz_bin.h:336
RzListFree free
Definition: rz_list.h:21
Definition: sdb.h:63
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4

References rz_bin_object_t::addrzklassmethod, bin_object_decode_all_base64_strings(), rz_bin_object_t::binsym, rz_bin_object_t::boffset, classes(), rz_bin_object_t::classes, classes_from_symbols(), rz_bin_info_t::compiler, rz_bin_object_t::entries, rz_bin_object_t::fields, filter_classes(), rz_list_t::free, free(), i, if(), rz_bin_object_t::import_name_symbols, rz_bin_object_t::imports, rz_bin_object_t::info, rz_bin_symbol_t::is_imported, rz_bin_object_t::kv, rz_bin_info_t::lang, rz_bin_object_t::lang, rz_bin_object_t::libs, rz_bin_object_t::lines, rz_bin_file_load_options_t::loadaddr, rz_bin_object_t::maps, rz_bin_object_t::mem, rz_bin_class_t::methods, rz_bin_t::minstrlen, rz_bin_symbol_t::name, NULL, rz_bin_file_t::o, rz_bin_object_t::opts, p, rz_bin_addr_t::paddr, rz_bin_object_t::plugin, rz_bin_file_t::rbin, REBASE_PADDR, rz_bin_object_t::regstate, rz_bin_object_t::relocs, rz_bin_object_t::resources, rz_bin_file_golang_compiler(), rz_bin_file_strings(), rz_bin_filter_sections(), rz_bin_filter_symbols(), rz_bin_language_detect(), RZ_BIN_LANGUAGE_SWIFT, rz_bin_object_rebuild_classes_ht(), rz_bin_reloc_storage_new(), RZ_BIN_REQ_CLASSES, RZ_BIN_REQ_CLASSES_SOURCES, RZ_BIN_REQ_IMPORTS, RZ_BIN_REQ_RELOCS, RZ_BIN_REQ_STRINGS, RZ_BIN_SPECIAL_SYMBOL_LAST, rz_bin_string_database_new(), RZ_BIN_TYPE_CORE, rz_list_free(), rz_return_val_if_fail, RZ_STR_ISEMPTY, rz_warn_if_fail, sdb_free(), rz_bin_object_t::sections, rz_bin_object_t::size, rz_bin_object_t::strings, strings(), rz_bin_object_t::symbols, type, rz_bin_symbol_t::vaddr, and rz_bin_object_t::vfiles.

Referenced by rz_bin_object_new(), and rz_core_bin_rebase().

◆ rz_bin_object_v2p()

RZ_API ut64 rz_bin_object_v2p ( RZ_NONNULL RzBinObject obj,
ut64  vaddr 
)

Convert virtual address to offset in the file according to binary mappings.

Parameters
objReference to RzBinObject
paddrVirtual address
Returns
Converted virtual address to offset in the file or UT64_MAX if the conversion cannot be done

Definition at line 1015 of file bobj.c.

1015  {
1017  RzBinMap *m = rz_bin_object_get_map_at(obj, vaddr, true);
1018  if (!m) {
1019  return UT64_MAX;
1020  }
1021 
1022  ut64 delta = vaddr - m->vaddr;
1023  if (delta >= m->psize) {
1024  return UT64_MAX;
1025  }
1026  return m->paddr + delta;
1027 }

References delta, regress::m, rz_bin_object_get_map_at(), rz_return_val_if_fail, ut64(), and UT64_MAX.

Referenced by io_read_va_at(), and string_scan_range_cfstring().

◆ rz_bin_reloc_size()

RZ_API ut64 rz_bin_reloc_size ( RzBinReloc reloc)

size of the reloc (where it is supposed to be patched) in bits

Definition at line 60 of file bobj.c.

60  {
61  switch (reloc->type) {
62  case RZ_BIN_RELOC_8:
63  return 8;
64  case RZ_BIN_RELOC_16:
65  return 16;
66  case RZ_BIN_RELOC_24:
67  return 24;
68  case RZ_BIN_RELOC_32:
69  return 32;
70  case RZ_BIN_RELOC_64:
71  return 64;
72  }
73  return 0;
74 }
@ RZ_BIN_RELOC_32
Definition: rz_bin.h:176
@ RZ_BIN_RELOC_24
Definition: rz_bin.h:175
@ RZ_BIN_RELOC_16
Definition: rz_bin.h:174
@ RZ_BIN_RELOC_64
Definition: rz_bin.h:177
@ RZ_BIN_RELOC_8
Definition: rz_bin.h:173
RzBinRelocType type
Definition: rz_bin.h:712

References RZ_BIN_RELOC_16, RZ_BIN_RELOC_24, RZ_BIN_RELOC_32, RZ_BIN_RELOC_64, RZ_BIN_RELOC_8, and rz_bin_reloc_t::type.

Referenced by meta_for_reloc().

◆ rz_bin_reloc_storage_free()

RZ_API void rz_bin_reloc_storage_free ( RzBinRelocStorage storage)

Definition at line 137 of file bobj.c.

137  {
138  if (!storage) {
139  return;
140  }
141  for (size_t i = 0; i < storage->relocs_count; i++) {
142  rz_bin_reloc_free(storage->relocs[i]);
143  }
144  free(storage->relocs);
145  free(storage->target_relocs);
146  free(storage);
147 }
RZ_API void rz_bin_reloc_free(RzBinReloc *reloc)
Definition: bin.c:188
RzBinReloc ** target_relocs
all relocs that have a valid target_vaddr, ordered by their target_vaddr. size is target_relocs_count...
Definition: rz_bin.h:735
RzBinReloc ** relocs
all relocs, ordered by their vaddr
Definition: rz_bin.h:733

References free(), i, rz_bin_reloc_storage_t::relocs, rz_bin_reloc_storage_t::relocs_count, rz_bin_reloc_free(), and rz_bin_reloc_storage_t::target_relocs.

Referenced by rz_bin_object_free(), and rz_bin_object_patch_relocs().

◆ rz_bin_reloc_storage_get_reloc_in()

RZ_API RzBinReloc* rz_bin_reloc_storage_get_reloc_in ( RzBinRelocStorage storage,
ut64  vaddr,
ut64  size 
)

Get the reloc with the lowest vaddr that starts inside the given interval.

Definition at line 154 of file bobj.c.

154  {
155  rz_return_val_if_fail(storage && size >= 1, NULL);
156  if (!storage->relocs) {
157  return NULL;
158  }
159  size_t i;
160  rz_array_lower_bound(storage->relocs, storage->relocs_count, vaddr, i, reloc_vaddr_cmp);
161  if (i >= storage->relocs_count) {
162  return NULL;
163  }
164  RzBinReloc *r = storage->relocs[i];
165  return r->vaddr >= vaddr && r->vaddr < vaddr + size ? r : NULL;
166 }
static int reloc_vaddr_cmp(ut64 ref, RzBinReloc *reloc)
Definition: bobj.c:149
#define r
Definition: crypto_rc6.c:12
voidpf void uLong size
Definition: ioapi.h:138
#define rz_array_lower_bound(array, len, x, i, cmp)
Definition: rz_vector.h:351

References i, NULL, r, reloc_vaddr_cmp(), rz_bin_reloc_storage_t::relocs, rz_bin_reloc_storage_t::relocs_count, rz_array_lower_bound, and rz_return_val_if_fail.

Referenced by rz_core_getreloc().

◆ rz_bin_reloc_storage_get_reloc_to()

RZ_API RzBinReloc* rz_bin_reloc_storage_get_reloc_to ( RzBinRelocStorage storage,
ut64  vaddr 
)

Get a reloc that points exactly to vaddr or NULL.

Definition at line 173 of file bobj.c.

173  {
174  rz_return_val_if_fail(storage, NULL);
175  if (!storage->target_relocs) {
176  return NULL;
177  }
178  size_t i;
180  if (!i) {
181  return NULL;
182  }
183  i--;
184  RzBinReloc *r = storage->target_relocs[i];
185  return r->target_vaddr == vaddr ? r : NULL;
186 }
static int reloc_target_vaddr_cmp(ut64 ref, RzBinReloc *reloc)
Definition: bobj.c:168
#define rz_array_upper_bound(array, len, x, i, cmp)
Definition: rz_vector.h:374
size_t target_relocs_count
Definition: rz_bin.h:736

References i, NULL, r, reloc_target_vaddr_cmp(), rz_array_upper_bound, rz_return_val_if_fail, rz_bin_reloc_storage_t::target_relocs, and rz_bin_reloc_storage_t::target_relocs_count.

Referenced by rz_core_get_reloc_to().

◆ rz_bin_reloc_storage_new()

RZ_API RzBinRelocStorage* rz_bin_reloc_storage_new ( RZ_OWN RzList relocs)

Definition at line 105 of file bobj.c.

105  {
107  if (!ret) {
108  return NULL;
109  }
110  RzPVector sorter;
111  rz_pvector_init(&sorter, NULL);
113  RzPVector target_sorter;
114  rz_pvector_init(&target_sorter, NULL);
115  rz_pvector_reserve(&target_sorter, rz_list_length(relocs));
116  RzListIter *it;
117  RzBinReloc *reloc;
118  rz_list_foreach (relocs, it, reloc) {
119  rz_pvector_push(&sorter, reloc);
120  if (rz_bin_reloc_has_target(reloc)) {
121  rz_pvector_push(&target_sorter, reloc);
122  }
123  }
124  relocs->free = NULL; // ownership of relocs transferred
126  rz_pvector_sort(&sorter, reloc_cmp);
127  ret->relocs_count = rz_pvector_len(&sorter);
128  ret->relocs = (RzBinReloc **)rz_pvector_flush(&sorter);
129  rz_pvector_fini(&sorter);
130  rz_pvector_sort(&target_sorter, reloc_target_cmp);
131  ret->target_relocs_count = rz_pvector_len(&target_sorter);
132  ret->target_relocs = (RzBinReloc **)rz_pvector_flush(&target_sorter);
133  rz_pvector_fini(&target_sorter);
134  return ret;
135 }
RzList * relocs(RzBinFile *bf)
Definition: bin_ne.c:114
static int reloc_cmp(const void *a, const void *b)
Definition: bobj.c:83
static int reloc_target_cmp(const void *a, const void *b)
Definition: bobj.c:93
static bool rz_bin_reloc_has_target(RzBinReloc *reloc)
Definition: rz_bin.h:828
static void ** rz_pvector_reserve(RzPVector *vec, size_t capacity)
Definition: rz_vector.h:312
RZ_API void rz_pvector_sort(RzPVector *vec, RzPVectorComparator cmp)
Definition: vector.c:408
static size_t rz_pvector_len(const RzPVector *vec)
Definition: rz_vector.h:231
static void ** rz_pvector_flush(RzPVector *vec)
Definition: rz_vector.h:320
Efficient storage of relocations to query by address.
Definition: rz_bin.h:732

References rz_list_t::free, NULL, reloc_cmp(), reloc_target_cmp(), relocs(), rz_bin_reloc_storage_t::relocs, rz_bin_reloc_storage_t::relocs_count, rz_bin_reloc_has_target(), rz_list_free(), rz_list_length(), RZ_NEW0, rz_pvector_fini(), rz_pvector_flush(), rz_pvector_init(), rz_pvector_len(), rz_pvector_push(), rz_pvector_reserve(), rz_pvector_sort(), rz_bin_reloc_storage_t::target_relocs, and rz_bin_reloc_storage_t::target_relocs_count.

Referenced by rz_bin_object_patch_relocs(), and rz_bin_object_set_items().

◆ rz_bin_string_database_add()

RZ_API bool rz_bin_string_database_add ( RZ_NONNULL RzBinStrDb db,
RZ_NONNULL RzBinString bstr 
)

{ function_description }

Parameters
dbThe database
bstrThe bstr
Returns
{ description_of_the_return_value }

Definition at line 1094 of file bobj.c.

1094  {
1095  rz_return_val_if_fail(db && bstr, false);
1096 
1097  if (!rz_list_append(db->list, bstr)) {
1098  RZ_LOG_ERROR("rz_bin: Cannot add RzBinString in RzBinStrDb (list)\n");
1099  return false;
1100  }
1101 
1102  if (!ht_up_update(db->phys, bstr->paddr, bstr)) {
1103  RZ_LOG_ERROR("rz_bin: Cannot add RzBinString in RzBinStrDb (phys)\n");
1104  return false;
1105  }
1106 
1107  if (!ht_up_update(db->virt, bstr->vaddr, bstr)) {
1108  RZ_LOG_ERROR("rz_bin: Cannot add RzBinString in RzBinStrDb (virt)\n");
1109  return false;
1110  }
1111  return true;
1112 }

References rz_list_append(), RZ_LOG_ERROR, and rz_return_val_if_fail.

Referenced by add_new_bin_string().

◆ rz_bin_string_database_free()

RZ_API void rz_bin_string_database_free ( RZ_NULLABLE RzBinStrDb db)

Frees a RzBinStrDb structure.

Parameters
dbThe string database to free

Definition at line 1076 of file bobj.c.

1076  {
1077  if (!db) {
1078  return;
1079  }
1080  rz_list_free(db->list);
1081  ht_up_free(db->phys);
1082  ht_up_free(db->virt);
1083  free(db);
1084 }

References free(), and rz_list_free().

Referenced by rz_bin_object_free(), rz_bin_object_reset_strings(), and rz_bin_string_database_new().

◆ rz_bin_string_database_new()

RZ_API RZ_OWN RzBinStrDb* rz_bin_string_database_new ( RZ_NULLABLE RZ_OWN RzList list)

Allocates and initializes the RzBinStrDb structure with the given list of strings.

Parameters
listThe list of strings to initialize the database with
Returns
On success returns a valid pointer, otherwise NULL

Definition at line 1036 of file bobj.c.

1036  {
1037  RzBinStrDb *db = RZ_NEW0(RzBinStrDb);
1038  if (!db) {
1039  RZ_LOG_ERROR("rz_bin: Cannot allocate RzBinStrDb\n");
1040  rz_list_free(list);
1041  return NULL;
1042  }
1043 
1045  db->phys = ht_up_new0();
1046  db->virt = ht_up_new0();
1047  if (!db->list || !db->phys || !db->virt) {
1048  RZ_LOG_ERROR("rz_bin: Cannot allocate RzBinStrDb internal data structure.\n");
1049  goto fail;
1050  }
1051 
1052  RzListIter *it;
1053  RzBinString *bstr;
1054  rz_list_foreach (list, it, bstr) {
1055  if (!ht_up_update(db->phys, bstr->paddr, bstr)) {
1056  RZ_LOG_ERROR("rz_bin: Cannot insert/update RzBinString in RzBinStrDb (phys)\n");
1057  goto fail;
1058  }
1059  if (!ht_up_update(db->virt, bstr->vaddr, bstr)) {
1060  RZ_LOG_ERROR("rz_bin: Cannot insert/update RzBinString in RzBinStrDb (virt)\n");
1061  goto fail;
1062  }
1063  }
1064  return db;
1065 
1066 fail:
1068  return NULL;
1069 }
RZ_API void rz_bin_string_free(void *_str)
Definition: bin.c:192
RzList * list
Contains all the strings in list form.
Definition: private.h:38
HtUP * virt
Contains all the strings but mapped by virtual address.
Definition: private.h:40
HtUP * phys
Contains all the strings but mapped by physical address.
Definition: private.h:39
#define fail(test)
Definition: tests.h:29

References fail, rz_bin_string_database_t::list, list(), NULL, rz_bin_string_t::paddr, rz_bin_string_database_t::phys, rz_bin_string_database_free(), rz_bin_string_free(), rz_list_free(), rz_list_newf(), RZ_LOG_ERROR, RZ_NEW0, rz_bin_string_t::vaddr, and rz_bin_string_database_t::virt.

Referenced by rz_bin_object_reset_strings(), and rz_bin_object_set_items().

◆ rz_bin_string_database_remove()

RZ_API bool rz_bin_string_database_remove ( RZ_NONNULL RzBinStrDb db,
ut64  address,
bool  is_va 
)

Return true if the given address has been removed to the RzBinObject string database.

Definition at line 1117 of file bobj.c.

1117  {
1118  rz_return_val_if_fail(db, false);
1119 
1120  RzBinString *bstr = ht_up_find(is_va ? db->virt : db->phys, address, NULL);
1121  if (!bstr) {
1122  return false;
1123  }
1124 
1125  ht_up_delete(db->virt, bstr->vaddr);
1126  ht_up_delete(db->phys, bstr->paddr);
1127  rz_list_delete_data(db->list, bstr);
1128  return true;
1129 }
RZ_API bool rz_list_delete_data(RZ_NONNULL RzList *list, void *ptr)
Deletes an entry in the list by searching for a pointer.
Definition: list.c:148

References NULL, rz_bin_string_t::paddr, rz_list_delete_data(), rz_return_val_if_fail, and rz_bin_string_t::vaddr.

◆ rz_bin_string_decode_base64()

RZ_API void rz_bin_string_decode_base64 ( RZ_NONNULL RzBinString bstr)

Tries to decode the base64 string hold by RzBinString and overwrites it.

Parameters
bstrThe RzBinString to decode

Definition at line 15 of file bobj.c.

15  {
16  rz_return_if_fail(bstr);
17 
18  char *decoded = bstr->string;
19  do {
20  // ensure to decode base64 strings encoded multiple times.
21  char *tmp = (char *)rz_base64_decode_dyn(decoded, -1);
22  if (!tmp || !rz_str_is_printable(tmp)) {
23  free(tmp);
24  break;
25  }
26  free(decoded);
27  decoded = tmp;
28  } while (1);
29 
30  if (decoded == bstr->string) {
31  return;
32  }
33  free(bstr->string);
34  bstr->string = decoded;
35  bstr->length = strlen(decoded);
36  bstr->type = RZ_STRING_ENC_BASE64;
37 }
RZ_API ut8 * rz_base64_decode_dyn(const char *in, int len)
Definition: ubase64.c:65
@ RZ_STRING_ENC_BASE64
Definition: rz_str.h:27
RZ_API bool rz_str_is_printable(const char *str)
Definition: str.c:2038

References free(), rz_base64_decode_dyn(), rz_return_if_fail, rz_str_is_printable(), RZ_STRING_ENC_BASE64, and autogen_x86imm::tmp.

Referenced by bin_object_decode_all_base64_strings().

◆ swiftField()

static char* swiftField ( const char *  dn,
const char *  cn 
)
static

Definition at line 217 of file bobj.c.

217  {
218  if (!dn || !cn) {
219  return NULL;
220  }
221 
222  char *p = strstr(dn, ".getter_");
223  if (!p) {
224  p = strstr(dn, ".setter_");
225  if (!p) {
226  p = strstr(dn, ".method_");
227  }
228  }
229  if (p) {
230  char *q = strstr(dn, cn);
231  if (q && q[strlen(cn)] == '.') {
232  q = strdup(q + strlen(cn) + 1);
233  char *r = strchr(q, '.');
234  if (r) {
235  *r = 0;
236  }
237  return q;
238  }
239  }
240  return NULL;
241 }
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")

References NULL, p, r, and strdup().

Referenced by classes_from_symbols().