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

Go to the source code of this file.

Classes

struct  rz_bin_string_database_t
 

Functions

RZ_IPI RzBinFilerz_bin_file_new (RzBin *bin, const char *file, ut64 file_sz, int fd, const char *xtrname, bool steal_ptr)
 
RZ_IPI RzBinObjectrz_bin_file_object_find_by_id (RzBinFile *binfile, ut32 binobj_id)
 
RZ_IPI RzBinFilerz_bin_file_find_by_object_id (RzBin *bin, ut32 binobj_id)
 
RZ_IPI bool rz_bin_file_set_obj (RzBin *bin, RzBinFile *bf, RzBinObject *obj)
 
RZ_IPI RzBinFilerz_bin_file_xtr_load_bytes (RzBin *bin, RzBinXtrPlugin *xtr, const char *filename, const ut8 *bytes, ut64 sz, ut64 file_sz, ut64 baseaddr, ut64 loadaddr, int idx, int fd)
 
RZ_IPI bool rz_bin_file_set_bytes (RzBinFile *binfile, const ut8 *bytes, ut64 sz, bool steal_ptr)
 
RZ_IPI RzBinPluginrz_bin_get_binplugin_any (RzBin *bin)
 
RZ_IPI RzBinXtrPluginrz_bin_get_xtrplugin_by_name (RzBin *bin, const char *name)
 
RZ_IPI RzBinPluginrz_bin_get_binplugin_by_name (RzBin *bin, const char *name)
 
RZ_IPI RzBinPluginrz_bin_get_binplugin_by_filename (RzBin *bin)
 
RZ_IPI RZ_OWN char * rz_bin_file_golang_compiler (RZ_NONNULL RzBinFile *binfile)
 Returns the golang compiler info if buildinfo struct is found. More...
 
RZ_IPI void rz_bin_object_free (RzBinObject *o)
 
RZ_IPI ut64 rz_bin_object_get_baddr (RzBinObject *o)
 
RZ_IPI RzBinObjectrz_bin_object_new (RzBinFile *binfile, RzBinPlugin *plugin, RzBinObjectLoadOptions *opts, ut64 offset, ut64 sz)
 
RZ_IPI RzBinObjectrz_bin_object_get_cur (RzBin *bin)
 
RZ_IPI RzBinObjectrz_bin_object_find_by_arch_bits (RzBinFile *binfile, const char *arch, int bits, const char *name)
 
RZ_IPI void rz_bin_class_free (RzBinClass *c)
 
RZ_IPI RzBinSymbolrz_bin_class_add_method (RzBinFile *binfile, const char *classname, const char *name, int nargs)
 
RZ_IPI void rz_bin_class_add_field (RzBinFile *binfile, const char *classname, const char *name)
 
RZ_IPI RzBinFilerz_bin_file_xtr_load_buffer (RzBin *bin, RzBinXtrPlugin *xtr, const char *filename, RzBuffer *buf, RzBinObjectLoadOptions *obj_opts, int idx, int fd)
 
RZ_IPI RzBinFilerz_bin_file_new_from_buffer (RzBin *bin, const char *file, RzBuffer *buf, RzBinObjectLoadOptions *opts, int fd, const char *pluginname)
 

Function Documentation

◆ rz_bin_class_add_field()

RZ_IPI void rz_bin_class_add_field ( RzBinFile binfile,
const char *  classname,
const char *  name 
)

◆ rz_bin_class_add_method()

RZ_IPI RzBinSymbol* rz_bin_class_add_method ( RzBinFile binfile,
const char *  classname,
const char *  name,
int  nargs 
)

◆ rz_bin_class_free()

RZ_IPI void rz_bin_class_free ( RzBinClass c)

Definition at line 512 of file bfile.c.

512  {
513  if (k && k->name) {
514  free(k->name);
515  free(k->super);
516  rz_list_free(k->methods);
517  rz_list_free(k->fields);
518  free(k->visibility_str);
519  free(k);
520  }
521 }
const char * k
Definition: dsignal.c:11
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137

References free(), k, and rz_list_free().

Referenced by parse_categories(), parse_classes(), and rz_bin_object_new().

◆ rz_bin_file_find_by_object_id()

RZ_IPI RzBinFile* rz_bin_file_find_by_object_id ( RzBin bin,
ut32  binobj_id 
)

◆ rz_bin_file_golang_compiler()

RZ_IPI RZ_OWN char* rz_bin_file_golang_compiler ( RZ_NONNULL RzBinFile bf)

Returns the golang compiler info if buildinfo struct is found.

Parameters
RzBinFileThe RzBinFile to use for the search
Returns
Returns a string on success, otherwise NULL

Definition at line 265 of file golang.c.

265  {
266  rz_return_val_if_fail(bf && bf->o, NULL);
267 
268  bool is_pe = false;
269  GoBuildInfo go_info = { 0 };
271  RzListIter *it = NULL;
272  RzList *sections = NULL;
273  const char *plugname = bf->o->plugin->name;
274 
275  if (!strcmp(plugname, "pe") || !strcmp(plugname, "pe64")) {
276  is_pe = true;
277  } else if (strcmp(plugname, "elf") && strcmp(plugname, "elf64") &&
278  strcmp(plugname, "mach0") && strcmp(plugname, "mach064")) {
279  RZ_LOG_INFO("goinfo: unsupported bin format '%s'\n", plugname);
280  return NULL;
281  }
282 
284  if (!sections) {
285  return NULL;
286  }
287 
288  rz_list_foreach (sections, it, section) {
289  if (is_pe && strstr(section->name, "data") && section->size > 16) {
290  find_go_build_info(bf, &go_info, section);
291  } else if (!is_pe && (strstr(section->name, "go_buildinfo") || strstr(section->name, "go.buildinfo"))) {
292  parse_go_build_info(bf, &go_info, section->paddr);
293  }
294  if (go_info.version) {
295  break;
296  }
297  }
299 
300  if (!go_info.version) {
301  return NULL;
302  } else if (go_info.settings) {
303  char *res = rz_str_newf("%s (%s)", go_info.version, go_info.settings);
304  free(go_info.version);
305  free(go_info.settings);
306  return res;
307  }
308 
309  return go_info.version;
310 }
static void find_go_build_info(RzBinFile *bf, GoBuildInfo *go_info, RzBinSection *section)
Definition: golang.c:253
static void parse_go_build_info(RzBinFile *bf, GoBuildInfo *go_info, ut64 bi_paddr)
Definition: golang.c:170
RzList * sections(RzBinFile *bf)
Definition: bin_ne.c:110
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: bobj.c:774
#define NULL
Definition: cris-opc.c:27
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
#define RZ_LOG_INFO(fmtstr,...)
Definition: rz_log.h:54
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
char * settings
Definition: golang.c:77
char * version
Definition: golang.c:76
uint32_t size

References scan_go_info_s::bf, find_go_build_info(), free(), scan_go_info_s::go_info, rz_bin_plugin_t::name, NULL, rz_bin_file_t::o, parse_go_build_info(), rz_bin_object_t::plugin, rz_bin_object_get_sections(), rz_list_free(), RZ_LOG_INFO, rz_return_val_if_fail, rz_str_newf(), sections(), golang_build_info_t::settings, section::size, and golang_build_info_t::version.

Referenced by rz_bin_object_set_items().

◆ rz_bin_file_new()

RZ_IPI RzBinFile* rz_bin_file_new ( RzBin bin,
const char *  file,
ut64  file_sz,
int  fd,
const char *  xtrname,
bool  steal_ptr 
)

Definition at line 22 of file bfile.c.

22  {
23  ut32 bf_id;
24  if (!rz_id_pool_grab_id(bin->ids->pool, &bf_id)) {
25  return NULL;
26  }
28  if (!bf) {
29  return NULL;
30  }
31 
32  bf->id = bf_id;
33  bf->rbin = bin;
34  bf->file = RZ_STR_DUP(file);
35  bf->fd = fd;
36  bf->curxtr = xtrname ? rz_bin_get_xtrplugin_by_name(bin, xtrname) : NULL;
37  bf->size = file_sz;
39  bf->xtr_obj = NULL;
40  bf->sdb = sdb_new0();
41  return bf;
42 }
RZ_API void rz_bin_xtrdata_free(void *data_)
Definition: bin.c:61
RZ_IPI RzBinXtrPlugin * rz_bin_get_xtrplugin_by_name(RzBin *bin, const char *name)
Definition: bin.c:383
uint32_t ut32
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 bool rz_id_pool_grab_id(RzIDPool *pool, ut32 *grabber)
Definition: idpool.c:34
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
#define RZ_STR_DUP(x)
Definition: rz_str.h:69
#define RZ_NEW0(x)
Definition: rz_types.h:284
RZ_API Sdb * sdb_new0(void)
Definition: sdb.c:43
Definition: malloc.c:26
Definition: gzappend.c:170
XX curplugin == o->plugin.
Definition: rz_bin.h:298
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
struct rz_bin_xtr_plugin_t * curxtr
Definition: rz_bin.h:312
char * file
Definition: rz_bin.h:299
RzList * xtr_data
Definition: rz_bin.h:314
void * xtr_obj
Definition: rz_bin.h:306
static const z80_opcode fd[]
Definition: z80_tab.h:997

References rz_bin_file_t::curxtr, fd, rz_bin_file_t::fd, rz_bin_file_t::file, rz_bin_file_t::id, NULL, rz_bin_file_t::rbin, rz_bin_get_xtrplugin_by_name(), rz_bin_xtrdata_free(), rz_id_pool_grab_id(), rz_list_newf(), RZ_NEW0, RZ_STR_DUP, rz_bin_file_t::sdb, sdb_new0(), rz_bin_file_t::size, rz_bin_file_t::xtr_data, and rz_bin_file_t::xtr_obj.

Referenced by rz_bin_file_new_from_buffer(), and rz_bin_file_xtr_load_buffer().

◆ rz_bin_file_new_from_buffer()

RZ_IPI RzBinFile* rz_bin_file_new_from_buffer ( RzBin bin,
const char *  file,
RzBuffer buf,
RzBinObjectLoadOptions opts,
int  fd,
const char *  pluginname 
)

Definition at line 139 of file bfile.c.

139  {
141 
142  RzBinFile *bf = rz_bin_file_new(bin, file, rz_buf_size(buf), fd, pluginname, false);
143  if (!bf) {
144  return NULL;
145  }
146 
147  RzListIter *item = rz_list_append(bin->binfiles, bf);
148  bf->buf = rz_buf_ref(buf);
149  RzBinPlugin *plugin = get_plugin_from_buffer(bin, pluginname, bf->buf);
150  RzBinObject *o = rz_bin_object_new(bf, plugin, opts, 0, rz_buf_size(bf->buf));
151  if (!o) {
152  rz_list_delete(bin->binfiles, item);
153  return NULL;
154  }
155  // size is set here because the reported size of the object depends on
156  // if loaded from xtr plugin or partially read
157  if (!o->size) {
158  o->size = rz_buf_size(buf);
159  }
160  return bf;
161 }
static RzBinPlugin * get_plugin_from_buffer(RzBin *bin, const char *pluginname, RzBuffer *buf)
Definition: bfile.c:74
RZ_IPI RzBinFile * rz_bin_file_new(RzBin *bin, const char *file, ut64 file_sz, int fd, const char *xtrname, bool steal_ptr)
Definition: bfile.c:22
RZ_IPI RzBinObject * rz_bin_object_new(RzBinFile *bf, RzBinPlugin *plugin, RzBinObjectLoadOptions *opts, ut64 offset, ut64 sz)
Definition: bobj.c:278
voidpf void * buf
Definition: ioapi.h:138
RZ_API void rz_list_delete(RZ_NONNULL RzList *list, RZ_NONNULL RzListIter *iter)
Removes an entry in the list by using the RzListIter pointer.
Definition: list.c:162
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288
RZ_API RzBuffer * rz_buf_ref(RzBuffer *b)
Increment the reference count of the buffer.
Definition: buf.c:668
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
Definition: buf.c:1225
RzBuffer * buf
Definition: rz_bin.h:303

References rz_bin_file_t::buf, fd, get_plugin_from_buffer(), NULL, rz_bin_file_new(), rz_bin_object_new(), rz_buf_ref(), rz_buf_size(), rz_list_append(), rz_list_delete(), rz_return_val_if_fail, and rz_bin_object_t::size.

Referenced by rz_bin_open_buf().

◆ rz_bin_file_object_find_by_id()

RZ_IPI RzBinObject* rz_bin_file_object_find_by_id ( RzBinFile binfile,
ut32  binobj_id 
)

◆ rz_bin_file_set_bytes()

RZ_IPI bool rz_bin_file_set_bytes ( RzBinFile binfile,
const ut8 bytes,
ut64  sz,
bool  steal_ptr 
)

Definition at line 337 of file bfile.c.

337  {
338  rz_return_val_if_fail(bf && bytes, false);
339  rz_buf_free(bf->buf);
340  if (steal_ptr) {
341  bf->buf = rz_buf_new_with_pointers(bytes, sz, true);
342  } else {
343  bf->buf = rz_buf_new_with_bytes(bytes, sz);
344  }
345  return bf->buf != NULL;
346 }
static ut8 bytes[32]
Definition: asm_arc.c:23
RZ_API RZ_OWN RzBuffer * rz_buf_new_with_pointers(const ut8 *bytes, ut64 len, bool steal)
Creates a new buffer with a bytes array.
Definition: buf.c:552
RZ_API void rz_buf_free(RzBuffer *b)
Free all internal data hold by the buffer and the buffer.
Definition: buf.c:1253
RZ_API RZ_OWN RzBuffer * rz_buf_new_with_bytes(RZ_NULLABLE RZ_BORROW const ut8 *bytes, ut64 len)
Creates a new buffer with a bytes array.
Definition: buf.c:465

References rz_bin_file_t::buf, bytes, NULL, rz_buf_free(), rz_buf_new_with_bytes(), rz_buf_new_with_pointers(), and rz_return_val_if_fail.

◆ rz_bin_file_set_obj()

RZ_IPI bool rz_bin_file_set_obj ( RzBin bin,
RzBinFile bf,
RzBinObject obj 
)

Definition at line 263 of file bfile.c.

263  {
264  rz_return_val_if_fail(bin && bf, false);
265  bin->file = bf->file;
266  bin->cur = bf;
267  bin->narch = bf->narch;
268  if (obj) {
269  bf->o = obj;
270  } else {
271  obj = bf->o;
272  }
273  RzBinPlugin *plugin = rz_bin_file_cur_plugin(bf);
274  if (bin->minstrlen < 1) {
275  bin->minstrlen = plugin ? plugin->minstrlen : bin->minstrlen;
276  }
277  if (obj) {
278  if (!obj->info) {
279  return false;
280  }
281  if (!obj->info->lang) {
282  obj->info->lang = rz_bin_language_to_string(obj->lang);
283  }
284  }
285  return true;
286 }
RZ_API RzBinPlugin * rz_bin_file_cur_plugin(RzBinFile *bf)
Definition: bfile.c:348
RZ_API const char * rz_bin_language_to_string(RzBinLanguage language)
returns the language name based on the given language identifier
Definition: bin_language.c:229
RzBinObject * o
Definition: rz_bin.h:305
const char * lang
Definition: rz_bin.h:224
RzBinLanguage lang
Definition: rz_bin.h:290
RzBinInfo * info
Definition: rz_bin.h:287

References rz_bin_file_t::file, rz_bin_object_t::info, rz_bin_info_t::lang, rz_bin_object_t::lang, rz_bin_plugin_t::minstrlen, rz_bin_file_t::narch, rz_bin_file_t::o, rz_bin_file_cur_plugin(), rz_bin_language_to_string(), and rz_return_val_if_fail.

Referenced by rz_bin_file_set_cur_binfile(), rz_bin_object_new(), rz_bin_select(), rz_bin_select_bfid(), rz_bin_select_object(), and rz_bin_use_arch().

◆ rz_bin_file_xtr_load_buffer()

RZ_IPI RzBinFile* rz_bin_file_xtr_load_buffer ( RzBin bin,
RzBinXtrPlugin xtr,
const char *  filename,
RzBuffer buf,
RzBinObjectLoadOptions obj_opts,
int  idx,
int  fd 
)

Definition at line 299 of file bfile.c.

299  {
300  rz_return_val_if_fail(bin && xtr && buf, NULL);
301 
303  if (!bf) {
304  bf = rz_bin_file_new(bin, filename, rz_buf_size(buf), fd, xtr->name, false);
305  if (!bf) {
306  return NULL;
307  }
308  rz_list_append(bin->binfiles, bf);
309  if (!bin->cur) {
310  bin->cur = bf;
311  }
312  }
313  rz_list_free(bf->xtr_data);
314  bf->xtr_data = NULL;
315  if (xtr->extractall_from_buffer) {
316  bf->xtr_data = xtr->extractall_from_buffer(bin, buf);
317  } else if (xtr->extractall_from_bytes) {
318  ut64 sz = 0;
319  const ut8 *bytes = rz_buf_data(buf, &sz);
320  RZ_LOG_INFO("TODO: Implement extractall_from_buffer in '%s' xtr.bin plugin\n", xtr->name);
321  bf->xtr_data = xtr->extractall_from_bytes(bin, bytes, sz);
322  }
323  if (bf->xtr_data) {
324  RzListIter *iter;
325  RzBinXtrData *x;
326  // populate xtr_data with baddr and laddr that will be used later on
327  // rz_bin_file_object_new_from_xtr_data
328  rz_list_foreach (bf->xtr_data, iter, x) {
329  x->obj_opts = *obj_opts;
330  }
331  }
332  bf->loadaddr = obj_opts->loadaddr;
333  return bf;
334 }
RZ_API RzBinFile * rz_bin_file_find_by_name(RzBin *bin, const char *name)
Definition: bfile.c:239
const char * filename
Definition: ioapi.h:137
uint8_t ut8
Definition: lh5801.h:11
int x
Definition: mipsasm.c:20
RZ_DEPRECATE RZ_API RZ_BORROW ut8 * rz_buf_data(RZ_NONNULL RzBuffer *b, RZ_NONNULL RZ_OUT ut64 *size)
Return a borrowed array of bytes representing the buffer data.
Definition: buf.c:1287
ut64 loadaddr
starting physical address to read from the target file
Definition: rz_bin.h:249
ut64 loadaddr
Definition: rz_bin.h:307
RzList *(* extractall_from_bytes)(RzBin *bin, const ut8 *buf, ut64 size)
Definition: rz_bin.h:402
RzList *(* extractall_from_buffer)(RzBin *bin, RzBuffer *buf)
Definition: rz_bin.h:403
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References bytes, rz_bin_xtr_plugin_t::extractall_from_buffer, rz_bin_xtr_plugin_t::extractall_from_bytes, fd, rz_bin_file_load_options_t::loadaddr, rz_bin_file_t::loadaddr, rz_bin_xtr_plugin_t::name, NULL, rz_bin_file_find_by_name(), rz_bin_file_new(), rz_buf_data(), rz_buf_size(), rz_list_append(), rz_list_free(), RZ_LOG_INFO, rz_return_val_if_fail, ut64(), x, and rz_bin_file_t::xtr_data.

Referenced by rz_bin_open_buf().

◆ rz_bin_file_xtr_load_bytes()

RZ_IPI RzBinFile* rz_bin_file_xtr_load_bytes ( RzBin bin,
RzBinXtrPlugin xtr,
const char *  filename,
const ut8 bytes,
ut64  sz,
ut64  file_sz,
ut64  baseaddr,
ut64  loadaddr,
int  idx,
int  fd 
)

◆ rz_bin_get_binplugin_any()

RZ_IPI RzBinPlugin* rz_bin_get_binplugin_any ( RzBin bin)

◆ rz_bin_get_binplugin_by_filename()

RZ_IPI RzBinPlugin* rz_bin_get_binplugin_by_filename ( RzBin bin)

Definition at line 365 of file bin.c.

365  {
366  RzBinPlugin *plugin;
367  RzListIter *it;
368 
370 
371  const char *filename = strrchr(bin->file, RZ_SYS_DIR[0]);
372  filename = filename ? filename + 1 : bin->file;
373  rz_list_foreach (bin->plugins, it, plugin) {
374  if (plugin->check_filename) {
375  if (plugin->check_filename(filename)) {
376  return plugin;
377  }
378  }
379  }
380  return NULL;
381 }
#define RZ_SYS_DIR
Definition: rz_types.h:218
bool(* check_filename)(const char *filename)
Definition: rz_bin.h:520

References rz_bin_plugin_t::check_filename, NULL, rz_return_val_if_fail, and RZ_SYS_DIR.

Referenced by get_plugin_from_buffer().

◆ rz_bin_get_binplugin_by_name()

RZ_IPI RzBinPlugin* rz_bin_get_binplugin_by_name ( RzBin bin,
const char *  name 
)

Definition at line 335 of file bin.c.

335  {
336  RzBinPlugin *plugin;
337  RzListIter *it;
338 
340 
341  rz_list_foreach (bin->plugins, it, plugin) {
342  if (!strcmp(plugin->name, name)) {
343  return plugin;
344  }
345  }
346  return NULL;
347 }
Definition: z80asm.h:102
char * name
Definition: rz_bin.h:509

References rz_bin_plugin_t::name, NULL, and rz_return_val_if_fail.

Referenced by get_plugin_from_buffer(), and rz_bin_create().

◆ rz_bin_get_xtrplugin_by_name()

RZ_IPI RzBinXtrPlugin* rz_bin_get_xtrplugin_by_name ( RzBin bin,
const char *  name 
)

Definition at line 383 of file bin.c.

383  {
384  RzBinXtrPlugin *xtr;
385  RzListIter *it;
386 
388 
389  // TODO: use a hashtable here
390  rz_list_foreach (bin->binxtrs, it, xtr) {
391  if (!strcmp(xtr->name, name)) {
392  return xtr;
393  }
394  // must be set to null
395  xtr = NULL;
396  }
397  return NULL;
398 }

References rz_bin_xtr_plugin_t::name, NULL, and rz_return_val_if_fail.

Referenced by rz_bin_file_new().

◆ rz_bin_object_find_by_arch_bits()

RZ_IPI RzBinObject* rz_bin_object_find_by_arch_bits ( RzBinFile binfile,
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
char * file
Definition: rz_bin.h:210
char * arch
Definition: rz_bin.h:214

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
@ RZ_BIN_SPECIAL_SYMBOL_LAST
Definition: rz_bin.h:141
RzList * classes
Definition: rz_bin.h:281
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 * symbols
Definition: rz_bin.h:269
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_baddr()

RZ_IPI ut64 rz_bin_object_get_baddr ( RzBinObject o)

◆ 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 }

References NULL, and rz_return_val_if_fail.

◆ rz_bin_object_new()

RZ_IPI RzBinObject* rz_bin_object_new ( RzBinFile binfile,
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);
318  rz_bin_set_baddr(bf->rbin, o->opts.baseaddr);
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 int sdb_ns_set(Sdb *s, const char *name, Sdb *r)
Definition: ns.c:156
#define RZ_LOG_WARN(fmtstr,...)
Definition: rz_log.h:56
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
#define UT64_MAX
Definition: rz_types_base.h:86
ut64 baseaddr
where the linker maps the binary in memory
Definition: rz_bin.h:248
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
st64 baddr_shift
Definition: rz_bin.h:261
bool(* load_buffer)(RzBinFile *bf, RzBinObject *obj, RzBuffer *buf, Sdb *sdb)
Definition: rz_bin.h:515

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