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

Go to the source code of this file.

Functions

static RzBinClass__getClass (RzBinFile *bf, const char *name)
 
static RzBinSymbol__getMethod (RzBinFile *bf, const char *klass, const char *method)
 
RZ_IPI RzBinFilerz_bin_file_new (RzBin *bin, const char *file, ut64 file_sz, int fd, const char *xtrname, bool steal_ptr)
 
RZ_IPI void rz_bin_file_free (void *_bf)
 
static RzBinPluginget_plugin_from_buffer (RzBin *bin, const char *pluginname, RzBuffer *buf)
 
RZ_API bool rz_bin_file_object_new_from_xtr_data (RzBin *bin, RzBinFile *bf, RzBinObjectLoadOptions *opts, RzBinXtrData *data)
 
static bool xtr_metadata_match (RzBinXtrData *xtr_data, const char *arch, int bits)
 
RZ_IPI RzBinFilerz_bin_file_new_from_buffer (RzBin *bin, const char *file, RzBuffer *buf, RzBinObjectLoadOptions *opts, int fd, const char *pluginname)
 
RZ_API RzBinFilerz_bin_file_find_by_arch_bits (RzBin *bin, const char *arch, int bits)
 
RZ_API RzBinFilerz_bin_file_find_by_id (RzBin *bin, ut32 bf_id)
 
RZ_API ut64 rz_bin_file_delete_all (RzBin *bin)
 
RZ_API bool rz_bin_file_delete (RzBin *bin, RzBinFile *bf)
 
RZ_API RzBinFilerz_bin_file_find_by_fd (RzBin *bin, ut32 bin_fd)
 
RZ_API RzBinFilerz_bin_file_find_by_name (RzBin *bin, const char *name)
 
RZ_API bool rz_bin_file_set_cur_by_id (RzBin *bin, ut32 bin_id)
 
RZ_API bool rz_bin_file_set_cur_by_fd (RzBin *bin, ut32 bin_fd)
 
RZ_IPI bool rz_bin_file_set_obj (RzBin *bin, RzBinFile *bf, RzBinObject *obj)
 
RZ_API bool rz_bin_file_set_cur_binfile (RzBin *bin, RzBinFile *bf)
 
RZ_API bool rz_bin_file_set_cur_by_name (RzBin *bin, 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 bool rz_bin_file_set_bytes (RzBinFile *bf, const ut8 *bytes, ut64 sz, bool steal_ptr)
 
RZ_API RzBinPluginrz_bin_file_cur_plugin (RzBinFile *bf)
 
RZ_API ut64 rz_bin_file_get_baddr (RzBinFile *bf)
 
RZ_API bool rz_bin_file_close (RzBin *bin, int bd)
 
static bool add_file_hash (RzHashCfg *md, const char *name, RzList *list)
 
static ut64 buf_compute_hashes (const ut8 *buf, ut64 size, void *user)
 
RZ_API RZ_OWN RzListrz_bin_file_compute_hashes (RzBin *bin, RzBinFile *bf, ut64 limit)
 
RZ_API RZ_OWN RzListrz_bin_file_set_hashes (RzBin *bin, RZ_OWN RzList *new_hashes)
 Set file_hashes on current RzBinInfo. More...
 
RZ_IPI RzBinClassrz_bin_class_new (const char *name, const char *super, int view)
 
RZ_IPI void rz_bin_class_free (RzBinClass *k)
 
RZ_API RzBinClassrz_bin_file_add_class (RzBinFile *bf, const char *name, const char *super, int view)
 
RZ_API RzBinSymbolrz_bin_file_add_method (RzBinFile *bf, const char *klass, const char *method, int nargs)
 
RZ_API RzListrz_bin_file_get_trycatch (RZ_NONNULL RzBinFile *bf)
 
RZ_API RzListrz_bin_file_get_symbols (RzBinFile *bf)
 

Function Documentation

◆ __getClass()

static RzBinClass* __getClass ( RzBinFile bf,
const char *  name 
)
static

Definition at line 11 of file bfile.c.

11  {
12  rz_return_val_if_fail(bf && bf->o && bf->o->classes_ht && name, NULL);
13  return ht_pp_find(bf->o->classes_ht, name, NULL);
14 }
#define NULL
Definition: cris-opc.c:27
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
Definition: z80asm.h:102
RzBinObject * o
Definition: rz_bin.h:305
HtPP * classes_ht
Definition: rz_bin.h:282

References rz_bin_object_t::classes_ht, NULL, rz_bin_file_t::o, and rz_return_val_if_fail.

Referenced by rz_bin_file_add_class().

◆ __getMethod()

static RzBinSymbol* __getMethod ( RzBinFile bf,
const char *  klass,
const char *  method 
)
static

Definition at line 16 of file bfile.c.

16  {
17  rz_return_val_if_fail(bf && bf->o && bf->o->methods_ht && klass && method, NULL);
18  const char *name = sdb_fmt("%s::%s", klass, method);
19  return ht_pp_find(bf->o->methods_ht, name, NULL);
20 }
RZ_API char * sdb_fmt(const char *fmt,...)
Definition: fmt.c:26
HtPP * methods_ht
Definition: rz_bin.h:283

References rz_bin_object_t::methods_ht, NULL, rz_bin_file_t::o, rz_return_val_if_fail, and sdb_fmt().

Referenced by rz_bin_file_add_method().

◆ add_file_hash()

static bool add_file_hash ( RzHashCfg md,
const char *  name,
RzList list 
)
inlinestatic

Definition at line 371 of file bfile.c.

371  {
372  char hash[128];
373  const ut8 *digest = NULL;
374  RzHashSize digest_size = 0;
375 
376  digest = rz_hash_cfg_get_result(md, name, &digest_size);
377  if (!digest) {
378  return false;
379  }
380 
381  if (!strcmp(name, "entropy")) {
382  double entropy = rz_read_be_double(digest);
383  rz_strf(hash, "%f", entropy);
384  } else {
385  rz_hex_bin2str(digest, digest_size, hash);
386  }
387 
389  if (!fh) {
390  RZ_LOG_ERROR("Cannot allocate RzBinFileHash\n");
391  return false;
392  }
393 
394  fh->type = strdup(name);
395  fh->hex = strdup(hash);
396  rz_list_push(list, fh);
397  return true;
398 }
FILE * fh
Definition: cabinfo.c:52
RZ_API RZ_BORROW const ut8 * rz_hash_cfg_get_result(RZ_NONNULL RzHashCfg *md, RZ_NONNULL const char *name, RZ_NONNULL ut32 *size)
Returns the digest value of the requested algorithm name.
Definition: hash.c:445
uint8_t ut8
Definition: lh5801.h:11
static void list(RzEgg *egg)
Definition: rz-gg.c:52
RZ_API RZ_BORROW RzListIter * rz_list_push(RZ_NONNULL RzList *list, void *item)
Alias for rz_list_append.
Definition: list.c:60
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")
static double rz_read_be_double(const void *src)
Definition: rz_endian.h:157
ut32 RzHashSize
Definition: rz_hash.h:24
RZ_API int rz_hex_bin2str(const ut8 *in, int len, char *out)
Definition: hex.c:382
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
#define rz_strf(buf,...)
Convenience macro for local temporary strings.
Definition: rz_str.h:59
#define RZ_NEW0(x)
Definition: rz_types.h:284

References fh, list(), benchmark::md, NULL, rz_hash_cfg_get_result(), rz_hex_bin2str(), rz_list_push(), RZ_LOG_ERROR, RZ_NEW0, rz_read_be_double(), rz_strf, and strdup().

Referenced by rz_bin_file_compute_hashes().

◆ buf_compute_hashes()

static ut64 buf_compute_hashes ( const ut8 buf,
ut64  size,
void *  user 
)
static

Definition at line 400 of file bfile.c.

400  {
401  if (!rz_hash_cfg_update((RzHashCfg *)user, buf, size)) {
402  return 0;
403  }
404  return size;
405 }
RZ_API bool rz_hash_cfg_update(RZ_NONNULL RzHashCfg *md, RZ_NONNULL const ut8 *data, ut64 size)
Inserts data into each the message digest contextes.
Definition: hash.c:337
voidpf void uLong size
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138

References rz_hash_cfg_update().

Referenced by rz_bin_file_compute_hashes().

◆ get_plugin_from_buffer()

static RzBinPlugin* get_plugin_from_buffer ( RzBin bin,
const char *  pluginname,
RzBuffer buf 
)
static

Definition at line 74 of file bfile.c.

74  {
75  RzBinPlugin *plugin = bin->force ? rz_bin_get_binplugin_by_name(bin, bin->force) : NULL;
76  if (plugin) {
77  return plugin;
78  }
79  plugin = pluginname ? rz_bin_get_binplugin_by_name(bin, pluginname) : NULL;
80  if (plugin) {
81  return plugin;
82  }
84  if (plugin) {
85  return plugin;
86  }
88  if (plugin) {
89  return plugin;
90  }
91  return rz_bin_get_binplugin_by_name(bin, "any");
92 }
RZ_API RzBinPlugin * rz_bin_get_binplugin_by_buffer(RzBin *bin, RzBuffer *buf)
Definition: bin.c:349
RZ_IPI RzBinPlugin * rz_bin_get_binplugin_by_name(RzBin *bin, const char *name)
Definition: bin.c:335
RZ_IPI RzBinPlugin * rz_bin_get_binplugin_by_filename(RzBin *bin)
Definition: bin.c:365
Definition: malloc.c:26

References NULL, rz_bin_get_binplugin_by_buffer(), rz_bin_get_binplugin_by_filename(), and rz_bin_get_binplugin_by_name().

Referenced by rz_bin_file_new_from_buffer(), and rz_bin_file_object_new_from_xtr_data().

◆ rz_bin_class_free()

RZ_IPI void rz_bin_class_free ( RzBinClass k)

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

RZ_IPI RzBinClass* rz_bin_class_new ( const char *  name,
const char *  super,
int  view 
)

Definition at line 499 of file bfile.c.

499  {
502  if (c) {
503  c->name = strdup(name);
504  c->super = super ? strdup(super) : NULL;
505  c->methods = rz_list_new();
506  c->fields = rz_list_new();
507  c->visibility = view;
508  }
509  return c;
510 }
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
Definition: list.c:235
#define c(i)
Definition: sha256.c:43

References c, NULL, rz_list_new(), RZ_NEW0, rz_return_val_if_fail, and strdup().

Referenced by rz_bin_file_add_class().

◆ rz_bin_file_add_class()

RZ_API RzBinClass* rz_bin_file_add_class ( RzBinFile bf,
const char *  name,
const char *  super,
int  view 
)

Definition at line 523 of file bfile.c.

523  {
524  rz_return_val_if_fail(name && bf && bf->o, NULL);
525  RzBinClass *c = __getClass(bf, name);
526  if (c) {
527  if (super) {
528  free(c->super);
529  c->super = strdup(super);
530  }
531  return c;
532  }
533  c = rz_bin_class_new(name, super, view);
534  if (c) {
535  // XXX. no need for a list, the ht is iterable too
536  c->index = rz_list_length(bf->o->classes);
537  rz_list_append(bf->o->classes, c);
538  ht_pp_insert(bf->o->classes_ht, name, c);
539  }
540  return c;
541 }
static RzBinClass * __getClass(RzBinFile *bf, const char *name)
Definition: bfile.c:11
RZ_IPI RzBinClass * rz_bin_class_new(const char *name, const char *super, int view)
Definition: bfile.c:499
RZ_API ut32 rz_list_length(RZ_NONNULL const RzList *list)
Returns the length of the list.
Definition: list.c:109
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
RzList * classes
Definition: rz_bin.h:281

References __getClass(), c, rz_bin_object_t::classes, rz_bin_object_t::classes_ht, free(), NULL, rz_bin_file_t::o, rz_bin_class_new(), rz_list_append(), rz_list_length(), rz_return_val_if_fail, and strdup().

Referenced by classes_from_symbols(), and rz_bin_file_add_method().

◆ rz_bin_file_add_method()

RZ_API RzBinSymbol* rz_bin_file_add_method ( RzBinFile bf,
const char *  klass,
const char *  method,
int  nargs 
)

Definition at line 543 of file bfile.c.

543  {
545 
546  RzBinClass *c = rz_bin_file_add_class(bf, klass, NULL, 0);
547  if (!c) {
548  RZ_LOG_ERROR("Cannot allocate RzBinClass for '%s'\n", klass);
549  return NULL;
550  }
551  RzBinSymbol *sym = __getMethod(bf, klass, method);
552  if (!sym) {
553  sym = RZ_NEW0(RzBinSymbol);
554  if (sym) {
555  sym->name = strdup(method);
556  rz_list_append(c->methods, sym);
557  const char *name = sdb_fmt("%s::%s", klass, method);
558  ht_pp_insert(bf->o->methods_ht, name, sym);
559  }
560  }
561  return sym;
562 }
RZ_API RzBinClass * rz_bin_file_add_class(RzBinFile *bf, const char *name, const char *super, int view)
Definition: bfile.c:523
static RzBinSymbol * __getMethod(RzBinFile *bf, const char *klass, const char *method)
Definition: bfile.c:16
char * name
Definition: rz_bin.h:675

References __getMethod(), c, rz_bin_object_t::methods_ht, rz_bin_symbol_t::name, NULL, rz_bin_file_t::o, rz_bin_file_add_class(), rz_list_append(), RZ_LOG_ERROR, RZ_NEW0, rz_return_val_if_fail, sdb_fmt(), and strdup().

◆ rz_bin_file_close()

RZ_API bool rz_bin_file_close ( RzBin bin,
int  bd 
)

Definition at line 359 of file bfile.c.

359  {
360  rz_return_val_if_fail(bin, false);
361  RzBinFile *bf = rz_id_storage_take(bin->ids, bd);
362  if (bf) {
363  // file_free removes the fd already.. maybe its unnecessary
364  rz_id_storage_delete(bin->ids, bd);
365  rz_bin_file_free(bf);
366  return true;
367  }
368  return false;
369 }
RZ_IPI void rz_bin_file_free(void *_bf)
Definition: bfile.c:44
RZ_API void * rz_id_storage_take(RzIDStorage *storage, ut32 id)
Definition: idpool.c:248
RZ_API void rz_id_storage_delete(RzIDStorage *storage, ut32 id)
Definition: idpool.c:221
XX curplugin == o->plugin.
Definition: rz_bin.h:298

References rz_bin_file_free(), rz_id_storage_delete(), rz_id_storage_take(), and rz_return_val_if_fail.

◆ rz_bin_file_compute_hashes()

RZ_API RZ_OWN RzList* rz_bin_file_compute_hashes ( RzBin bin,
RzBinFile bf,
ut64  limit 
)

Return a list of RzBinFileHash structures with the hashes md5, sha1, sha256, crc32 and entropy computed over the whole bf .

Definition at line 411 of file bfile.c.

411  {
412  rz_return_val_if_fail(bin && bf && bf->o, NULL);
413  RzBinObject *o = bf->o;
414  RzList *file_hashes = NULL;
415  RzHashCfg *md = NULL;
416  RzBuffer *buf = rz_buf_new_with_io_fd(&bin->iob, bf->fd);
417  const ut64 buf_size = rz_buf_size(buf);
418  if (!buf_size) {
419  rz_buf_free(buf);
420  return NULL;
421  }
422  if (buf_size > limit) {
423  if (bin->verbose) {
424  RZ_LOG_WARN("rz_bin_file_hash: file exceeds bin.hashlimit\n");
425  }
426  return NULL;
427  }
429  if (!file_hashes) {
430  RZ_LOG_ERROR("Cannot allocate file hash list\n");
431  goto rz_bin_file_compute_hashes_bad;
432  }
433 
434  md = rz_hash_cfg_new(bin->hash);
435  if (!md) {
436  goto rz_bin_file_compute_hashes_bad;
437  }
438 
439  if (!rz_hash_cfg_configure(md, "md5") ||
440  !rz_hash_cfg_configure(md, "sha1") ||
441  !rz_hash_cfg_configure(md, "sha256") ||
442  !rz_hash_cfg_configure(md, "crc32") ||
443  !rz_hash_cfg_configure(md, "entropy")) {
444  goto rz_bin_file_compute_hashes_bad;
445  }
446  if (!rz_hash_cfg_init(md)) {
447  goto rz_bin_file_compute_hashes_bad;
448  }
449 
451  goto rz_bin_file_compute_hashes_bad;
452  }
453 
454  if (!rz_hash_cfg_final(md)) {
455  goto rz_bin_file_compute_hashes_bad;
456  }
457 
458  if (!add_file_hash(md, "md5", file_hashes) ||
459  !add_file_hash(md, "sha1", file_hashes) ||
460  !add_file_hash(md, "sha256", file_hashes) ||
461  !add_file_hash(md, "crc32", file_hashes) ||
462  !add_file_hash(md, "entropy", file_hashes)) {
463  goto rz_bin_file_compute_hashes_bad;
464  }
465 
466  if (o->plugin && o->plugin->hashes) {
467  RzList *plugin_hashes = o->plugin->hashes(bf);
468  rz_list_join(file_hashes, plugin_hashes);
469  rz_list_free(plugin_hashes);
470  }
471 
472  // TODO: add here more rows
473  rz_buf_free(buf);
475  return file_hashes;
476 
477 rz_bin_file_compute_hashes_bad:
478  rz_buf_free(buf);
480  rz_list_free(file_hashes);
481  return NULL;
482 }
static ut64 buf_compute_hashes(const ut8 *buf, ut64 size, void *user)
Definition: bfile.c:400
static bool add_file_hash(RzHashCfg *md, const char *name, RzList *list)
Definition: bfile.c:371
RZ_API void rz_bin_file_hash_free(RzBinFileHash *fhash)
Definition: bin.c:89
static int buf_size
Definition: debug_qnx.c:35
RZ_API RZ_OWN RzHashCfg * rz_hash_cfg_new(RZ_NONNULL RzHash *rh)
Definition: hash.c:134
RZ_API void rz_hash_cfg_free(RZ_NONNULL RzHashCfg *md)
Definition: hash.c:186
RZ_API bool rz_hash_cfg_configure(RZ_NONNULL RzHashCfg *md, RZ_NONNULL const char *name)
Allocates and configures the plugin message digest context.
Definition: hash.c:199
RZ_API bool rz_hash_cfg_init(RZ_NONNULL RzHashCfg *md)
Resets/initialize the message digest contextes.
Definition: hash.c:298
RZ_API bool rz_hash_cfg_final(RZ_NONNULL RzHashCfg *md)
Generates the final value of the message digest contextes.
Definition: hash.c:359
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_list_join(RZ_NONNULL RzList *list1, RZ_NONNULL RzList *list2)
Joins 2 list into one (list2 pointer needs to be freed by the user)
Definition: list.c:209
static uint32_t const uint8_t uint32_t uint32_t limit
Definition: memcmplen.h:45
RZ_API RZ_OWN RzBuffer * rz_buf_new_with_io_fd(RZ_NONNULL void *iob, int fd)
Creates a new buffer wrapping a file descriptor accessed through RzIOBind.
Definition: buf.c:490
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 ut64 rz_buf_fwd_scan(RZ_NONNULL RzBuffer *b, ut64 start, ut64 amount, RZ_NONNULL RzBufferFwdScan fwd_scan, RZ_NULLABLE void *user)
Scans buffer linearly in chunks calling fwd_scan for each chunk.
Definition: buf.c:1303
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
int fd
when used in combination with RzIO, this refers to the io fd.
Definition: rz_bin.h:300
struct rz_bin_plugin_t * plugin
Definition: rz_bin.h:289
RzList *(* hashes)(RzBinFile *bf)
Definition: rz_bin.h:540
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References add_file_hash(), buf_compute_hashes(), buf_size, rz_bin_file_t::fd, rz_bin_plugin_t::hashes, limit, benchmark::md, NULL, rz_bin_file_t::o, rz_bin_object_t::plugin, rz_bin_file_hash_free(), rz_buf_free(), rz_buf_fwd_scan(), rz_buf_new_with_io_fd(), rz_buf_size(), rz_hash_cfg_configure(), rz_hash_cfg_final(), rz_hash_cfg_free(), rz_hash_cfg_init(), rz_hash_cfg_new(), rz_list_free(), rz_list_join(), rz_list_newf(), RZ_LOG_ERROR, RZ_LOG_WARN, rz_return_val_if_fail, and ut64().

Referenced by rz_cmd_info_hashes_handler(), and rz_main_rizin().

◆ rz_bin_file_cur_plugin()

◆ rz_bin_file_delete()

RZ_API bool rz_bin_file_delete ( RzBin bin,
RzBinFile bf 
)

Definition at line 213 of file bfile.c.

213  {
214  rz_return_val_if_fail(bin && bf, false);
215  RzListIter *it = rz_list_find_ptr(bin->binfiles, bf);
216  rz_return_val_if_fail(it, false); // calling del on a bf not in the bin is a programming error
217  if (bin->cur == bf) {
218  bin->cur = NULL;
219  }
220  RzEventBinFileDel ev = { bf };
222  rz_list_delete(bin->binfiles, it);
223  return true;
224 }
RZ_API RZ_BORROW RzListIter * rz_list_find_ptr(RZ_NONNULL const RzList *list, RZ_NONNULL const void *ptr)
Returns the RzListIter of the given pointer, if found.
Definition: list.c:600
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 void rz_event_send(RzEvent *ev, int type, void *data)
Definition: event.c:115
@ RZ_EVENT_BIN_FILE_DEL
Definition: rz_event.h:45

References NULL, RZ_EVENT_BIN_FILE_DEL, rz_event_send(), rz_list_delete(), rz_list_find_ptr(), and rz_return_val_if_fail.

Referenced by get_bin_info(), get_va_symbol(), GetHeapGlobalsOffset(), rz_bin_reload(), rz_core_bin_load_structs(), rz_core_binfiles_delete(), rz_core_file_close(), and rz_core_file_reopen().

◆ rz_bin_file_delete_all()

RZ_API ut64 rz_bin_file_delete_all ( RzBin bin)

Definition at line 199 of file bfile.c.

199  {
201  ut64 counter = rz_list_length(bin->binfiles);
202  RzListIter *it;
203  RzBinFile *bf;
204  rz_list_foreach (bin->binfiles, it, bf) {
205  RzEventBinFileDel ev = { bf };
207  }
208  rz_list_purge(bin->binfiles);
209  bin->cur = NULL;
210  return counter;
211 }
RZ_API void rz_list_purge(RZ_NONNULL RzList *list)
Empties the list without freeing the list pointer.
Definition: list.c:120
int64_t counter
Definition: main.c:4

References counter, NULL, RZ_EVENT_BIN_FILE_DEL, rz_event_send(), rz_list_length(), rz_list_purge(), rz_return_val_if_fail, and ut64().

Referenced by __close_file_cb(), file_load(), rz_core_io_file_open(), rz_open_binary_del_all_handler(), and rz_open_close_all_handler().

◆ rz_bin_file_find_by_arch_bits()

RZ_API RzBinFile* rz_bin_file_find_by_arch_bits ( RzBin bin,
const char *  arch,
int  bits 
)

Definition at line 163 of file bfile.c.

163  {
164  RzListIter *iter;
165  RzBinFile *binfile = NULL;
166  RzBinXtrData *xtr_data;
167 
169 
170  rz_list_foreach (bin->binfiles, iter, binfile) {
171  RzListIter *iter_xtr;
172  if (!binfile->xtr_data) {
173  continue;
174  }
175  // look for sub-bins in Xtr Data and Load if we need to
176  rz_list_foreach (binfile->xtr_data, iter_xtr, xtr_data) {
177  if (xtr_metadata_match(xtr_data, arch, bits)) {
178  if (!rz_bin_file_object_new_from_xtr_data(bin, binfile, &xtr_data->obj_opts, xtr_data)) {
179  return NULL;
180  }
181  return binfile;
182  }
183  }
184  }
185  return binfile;
186 }
static bool xtr_metadata_match(RzBinXtrData *xtr_data, const char *arch, int bits)
Definition: bfile.c:130
RZ_API bool rz_bin_file_object_new_from_xtr_data(RzBin *bin, RzBinFile *bf, RzBinObjectLoadOptions *opts, RzBinXtrData *data)
Definition: bfile.c:94
int bits(struct state *s, int need)
Definition: blast.c:72
cs_arch arch
Definition: cstool.c:13
RzList * xtr_data
Definition: rz_bin.h:314
RzBinObjectLoadOptions obj_opts
Definition: rz_bin.h:383

References arch, bits(), NULL, rz_bin_xtr_extract_t::obj_opts, rz_bin_file_object_new_from_xtr_data(), rz_return_val_if_fail, rz_bin_file_t::xtr_data, and xtr_metadata_match().

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

◆ rz_bin_file_find_by_fd()

RZ_API RzBinFile* rz_bin_file_find_by_fd ( RzBin bin,
ut32  bin_fd 
)

Definition at line 226 of file bfile.c.

226  {
228  RzListIter *iter;
229  RzBinFile *bf;
230 
231  rz_list_foreach (bin->binfiles, iter, bf) {
232  if (bf->fd == bin_fd) {
233  return bf;
234  }
235  }
236  return NULL;
237 }

References rz_bin_file_t::fd, NULL, and rz_return_val_if_fail.

Referenced by core_bin_reload(), prioritize_file(), resolve_import_cb(), rz_bin_file_set_cur_by_fd(), rz_core_bin_set_cur(), rz_core_file_reopen(), rz_core_file_reopen_debug(), rz_open_binary_select_fd_handler(), and rz_open_use_handler().

◆ rz_bin_file_find_by_id()

RZ_API RzBinFile* rz_bin_file_find_by_id ( RzBin bin,
ut32  bf_id 
)

Definition at line 188 of file bfile.c.

188  {
189  RzBinFile *bf;
190  RzListIter *iter;
191  rz_list_foreach (bin->binfiles, iter, bf) {
192  if (bf->id == bf_id) {
193  return bf;
194  }
195  }
196  return NULL;
197 }

References rz_bin_file_t::id, and NULL.

Referenced by rz_bin_file_set_cur_by_id(), rz_bin_select_bfid(), rz_open_binary_del_handler(), and vf_open().

◆ rz_bin_file_find_by_name()

RZ_API RzBinFile* rz_bin_file_find_by_name ( RzBin bin,
const char *  name 
)

Definition at line 239 of file bfile.c.

239  {
240  RzListIter *iter;
241  RzBinFile *bf;
242 
244 
245  rz_list_foreach (bin->binfiles, iter, bf) {
246  if (bf->file && !strcmp(bf->file, name)) {
247  return bf;
248  }
249  }
250  return NULL;
251 }
char * file
Definition: rz_bin.h:299

References rz_bin_file_t::file, NULL, and rz_return_val_if_fail.

Referenced by rz_bin_file_set_cur_by_name(), and rz_bin_file_xtr_load_buffer().

◆ rz_bin_file_free()

RZ_IPI void rz_bin_file_free ( void *  _bf)

Definition at line 44 of file bfile.c.

44  {
45  if (!_bf) {
46  return;
47  }
48  RzBinFile *bf = _bf;
49  if (bf->rbin->cur == bf) {
50  bf->rbin->cur = NULL;
51  }
52  RzBinPlugin *plugin = rz_bin_file_cur_plugin(bf);
53  // Binary format objects are connected to the
54  // RzBinObject, so the plugin must destroy the
55  // format data first
56  if (plugin && plugin->destroy) {
57  plugin->destroy(bf);
58  }
59  rz_buf_free(bf->buf);
60  if (bf->curxtr && bf->curxtr->destroy && bf->xtr_obj) {
61  bf->curxtr->free_xtr((void *)(bf->xtr_obj));
62  }
63  free(bf->file);
64  rz_bin_object_free(bf->o);
66  sdb_free(bf->sdb);
67  if (bf->id != -1) {
68  // TODO: use rz_storage api
69  rz_id_pool_kick_id(bf->rbin->ids->pool, bf->id);
70  }
71  free(bf);
72 }
RZ_API RzBinPlugin * rz_bin_file_cur_plugin(RzBinFile *bf)
Definition: bfile.c:348
RZ_IPI void rz_bin_object_free(RzBinObject *o)
Definition: bobj.c:188
RZ_API bool rz_id_pool_kick_id(RzIDPool *pool, ut32 kick)
Definition: idpool.c:53
RZ_API bool sdb_free(Sdb *s)
Definition: sdb.c:206
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
struct rz_bin_xtr_plugin_t * curxtr
Definition: rz_bin.h:312
RzBuffer * buf
Definition: rz_bin.h:303
void * xtr_obj
Definition: rz_bin.h:306
void(* destroy)(RzBinFile *bf)
Definition: rz_bin.h:517
RZ_DEPRECATE RzBinFile * cur
never use this in new code! Get a file from the binfiles list or track it yourself.
Definition: rz_bin.h:330
RzIDStorage * ids
Definition: rz_bin.h:341
void(* free_xtr)(void *xtr_obj)
Definition: rz_bin.h:410
void(* destroy)(RzBin *bin)
Definition: rz_bin.h:409
RzIDPool * pool
Definition: rz_idpool.h:28

References rz_bin_file_t::buf, rz_bin_t::cur, rz_bin_file_t::curxtr, rz_bin_xtr_plugin_t::destroy, rz_bin_plugin_t::destroy, rz_bin_file_t::file, free(), rz_bin_xtr_plugin_t::free_xtr, rz_bin_file_t::id, rz_bin_t::ids, NULL, rz_bin_file_t::o, rz_id_storage_t::pool, rz_bin_file_t::rbin, rz_bin_file_cur_plugin(), rz_bin_object_free(), rz_buf_free(), rz_id_pool_kick_id(), rz_list_free(), rz_bin_file_t::sdb, sdb_free(), rz_bin_file_t::xtr_data, and rz_bin_file_t::xtr_obj.

Referenced by rz_bin_file_close(), and rz_bin_new().

◆ rz_bin_file_get_baddr()

RZ_API ut64 rz_bin_file_get_baddr ( RzBinFile bf)

Definition at line 352 of file bfile.c.

352  {
353  if (bf && bf->o) {
354  return bf->o->opts.baseaddr;
355  }
356  return UT64_MAX;
357 }
#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

References rz_bin_file_load_options_t::baseaddr, rz_bin_file_t::o, rz_bin_object_t::opts, and UT64_MAX.

Referenced by rz_bin_get_baddr().

◆ rz_bin_file_get_symbols()

RZ_API RzList* rz_bin_file_get_symbols ( RzBinFile bf)

Definition at line 572 of file bfile.c.

572  {
574  RzBinObject *o = bf->o;
575  return o ? (RzList *)rz_bin_object_get_symbols(o) : NULL;
576 }
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: bobj.c:817

References NULL, rz_bin_file_t::o, rz_bin_object_get_symbols(), and rz_return_val_if_fail.

Referenced by resolve_import_cb().

◆ rz_bin_file_get_trycatch()

RZ_API RzList* rz_bin_file_get_trycatch ( RZ_NONNULL RzBinFile bf)

Definition at line 564 of file bfile.c.

564  {
565  rz_return_val_if_fail(bf && bf->o && bf->o->plugin, NULL);
566  if (bf->o->plugin->trycatch) {
567  return bf->o->plugin->trycatch(bf);
568  }
569  return NULL;
570 }

References NULL, and rz_return_val_if_fail.

Referenced by bin_trycatch().

◆ 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 bool rz_id_pool_grab_id(RzIDPool *pool, ut32 *grabber)
Definition: idpool.c:34
#define RZ_STR_DUP(x)
Definition: rz_str.h:69
RZ_API Sdb * sdb_new0(void)
Definition: sdb.c:43
Definition: gzappend.c:170
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
RZ_API RzBuffer * rz_buf_ref(RzBuffer *b)
Increment the reference count of the buffer.
Definition: buf.c:668

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

RZ_API bool rz_bin_file_object_new_from_xtr_data ( RzBin bin,
RzBinFile bf,
RzBinObjectLoadOptions opts,
RzBinXtrData data 
)

Definition at line 94 of file bfile.c.

94  {
95  rz_return_val_if_fail(bin && bf && data, false);
96 
97  ut64 offset = data->offset;
98  ut64 sz = data->size;
99 
100  RzBinPlugin *plugin = get_plugin_from_buffer(bin, NULL, data->buf);
101  bf->buf = rz_buf_ref(data->buf);
102 
103  RzBinObject *o = rz_bin_object_new(bf, plugin, opts, offset, sz);
104  if (!o) {
105  return false;
106  }
107  // size is set here because the reported size of the object depends on
108  // if loaded from xtr plugin or partially read
109  if (!o->size) {
110  o->size = sz;
111  }
112  bf->narch = data->file_count;
113  if (!o->info) {
114  o->info = RZ_NEW0(RzBinInfo);
115  }
116  free(o->info->file);
117  free(o->info->arch);
118  free(o->info->machine);
119  free(o->info->type);
120  o->info->file = strdup(bf->file);
121  o->info->arch = strdup(data->metadata->arch);
122  o->info->machine = strdup(data->metadata->machine);
123  o->info->type = strdup(data->metadata->type);
124  o->info->bits = data->metadata->bits;
125  o->info->has_crypto = bf->o->info->has_crypto;
126  data->loaded = true;
127  return true;
128 }
voidpf uLong offset
Definition: ioapi.h:144
char * type
Definition: rz_bin.h:211
int has_crypto
Definition: rz_bin.h:233
char * machine
Definition: rz_bin.h:216
char * file
Definition: rz_bin.h:210
char * arch
Definition: rz_bin.h:214
RzBinInfo * info
Definition: rz_bin.h:287
RzBuffer * buf
Definition: rz_bin.h:380
RzBinXtrMetadata * metadata
Definition: rz_bin.h:386

References rz_bin_info_t::arch, rz_bin_xtr_metadata_t::arch, rz_bin_info_t::bits, rz_bin_xtr_metadata_t::bits, rz_bin_file_t::buf, rz_bin_xtr_extract_t::buf, rz_bin_info_t::file, rz_bin_file_t::file, rz_bin_xtr_extract_t::file_count, free(), get_plugin_from_buffer(), rz_bin_info_t::has_crypto, rz_bin_object_t::info, rz_bin_xtr_extract_t::loaded, rz_bin_info_t::machine, rz_bin_xtr_metadata_t::machine, rz_bin_xtr_extract_t::metadata, rz_bin_file_t::narch, NULL, rz_bin_file_t::o, rz_bin_xtr_extract_t::offset, rz_bin_object_new(), rz_buf_ref(), RZ_NEW0, rz_return_val_if_fail, rz_bin_object_t::size, rz_bin_xtr_extract_t::size, strdup(), rz_bin_info_t::type, rz_bin_xtr_metadata_t::type, and ut64().

Referenced by rabin_do_operation(), rz_bin_file_find_by_arch_bits(), and rz_bin_use_arch().

◆ rz_bin_file_set_bytes()

RZ_IPI bool rz_bin_file_set_bytes ( RzBinFile bf,
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 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_cur_binfile()

RZ_API bool rz_bin_file_set_cur_binfile ( RzBin bin,
RzBinFile bf 
)

Definition at line 288 of file bfile.c.

288  {
289  rz_return_val_if_fail(bin && bf, false);
290  return rz_bin_file_set_obj(bin, bf, bf->o);
291 }
RZ_IPI bool rz_bin_file_set_obj(RzBin *bin, RzBinFile *bf, RzBinObject *obj)
Definition: bfile.c:263

References rz_bin_file_t::o, rz_bin_file_set_obj(), and rz_return_val_if_fail.

Referenced by get_bin_info(), get_va_symbol(), GetHeapGlobalsOffset(), rz_bin_file_set_cur_by_fd(), rz_bin_file_set_cur_by_id(), rz_bin_file_set_cur_by_name(), rz_bin_open_buf(), rz_core_bin_set_cur(), and rz_core_file_bin_raise().

◆ rz_bin_file_set_cur_by_fd()

RZ_API bool rz_bin_file_set_cur_by_fd ( RzBin bin,
ut32  bin_fd 
)

Definition at line 258 of file bfile.c.

258  {
259  RzBinFile *bf = rz_bin_file_find_by_fd(bin, bin_fd);
260  return bf ? rz_bin_file_set_cur_binfile(bin, bf) : false;
261 }
RZ_API bool rz_bin_file_set_cur_binfile(RzBin *bin, RzBinFile *bf)
Definition: bfile.c:288
RZ_API RzBinFile * rz_bin_file_find_by_fd(RzBin *bin, ut32 bin_fd)
Definition: bfile.c:226
#define false

References rz_bin_file_find_by_fd(), and rz_bin_file_set_cur_binfile().

Referenced by rz_core_bin_set_by_fd().

◆ rz_bin_file_set_cur_by_id()

RZ_API bool rz_bin_file_set_cur_by_id ( RzBin bin,
ut32  bin_id 
)

Definition at line 253 of file bfile.c.

253  {
254  RzBinFile *bf = rz_bin_file_find_by_id(bin, bin_id);
255  return bf ? rz_bin_file_set_cur_binfile(bin, bf) : false;
256 }
RZ_API RzBinFile * rz_bin_file_find_by_id(RzBin *bin, ut32 bf_id)
Definition: bfile.c:188

References rz_bin_file_find_by_id(), and rz_bin_file_set_cur_binfile().

Referenced by rz_open_maps_prioritize_binid_handler().

◆ rz_bin_file_set_cur_by_name()

RZ_API bool rz_bin_file_set_cur_by_name ( RzBin bin,
const char *  name 
)

Definition at line 293 of file bfile.c.

293  {
294  rz_return_val_if_fail(bin && name, false);
296  return rz_bin_file_set_cur_binfile(bin, bf);
297 }
RZ_API RzBinFile * rz_bin_file_find_by_name(RzBin *bin, const char *name)
Definition: bfile.c:239

References rz_bin_file_find_by_name(), rz_bin_file_set_cur_binfile(), and rz_return_val_if_fail.

Referenced by rz_core_bin_set_by_name().

◆ rz_bin_file_set_hashes()

RZ_API RZ_OWN RzList* rz_bin_file_set_hashes ( RzBin bin,
RZ_OWN RzList new_hashes 
)

Set file_hashes on current RzBinInfo.

Returns
RzList of previous file_hashes

Definition at line 488 of file bfile.c.

488  {
489  rz_return_val_if_fail(bin && bin->cur && bin->cur->o && bin->cur->o->info, NULL);
490  RzBinFile *bf = bin->cur;
491  RzBinInfo *info = bf->o->info;
492 
493  RzList *prev_hashes = info->file_hashes;
494  info->file_hashes = new_hashes;
495 
496  return prev_hashes;
497 }
RzBinInfo * info(RzBinFile *bf)
Definition: bin_ne.c:86
RzList * file_hashes
Definition: rz_bin.h:226

References rz_bin_info_t::file_hashes, info(), rz_bin_object_t::info, NULL, rz_bin_file_t::o, and rz_return_val_if_fail.

Referenced by rz_cmd_info_hashes_handler(), and rz_main_rizin().

◆ 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 const char * rz_bin_language_to_string(RzBinLanguage language)
returns the language name based on the given language identifier
Definition: bin_language.c:229
const char * lang
Definition: rz_bin.h:224
RzBinLanguage lang
Definition: rz_bin.h:290

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 }
const char * filename
Definition: ioapi.h:137
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
#define RZ_LOG_INFO(fmtstr,...)
Definition: rz_log.h:54
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

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

◆ xtr_metadata_match()

static bool xtr_metadata_match ( RzBinXtrData xtr_data,
const char *  arch,
int  bits 
)
static

Definition at line 130 of file bfile.c.

130  {
131  if (!xtr_data->metadata || !xtr_data->metadata->arch) {
132  return false;
133  }
134  const char *iter_arch = xtr_data->metadata->arch;
135  int iter_bits = xtr_data->metadata->bits;
136  return bits == iter_bits && !strcmp(iter_arch, arch) && !xtr_data->loaded;
137 }

References rz_bin_xtr_metadata_t::arch, arch, rz_bin_xtr_metadata_t::bits, bits(), rz_bin_xtr_extract_t::loaded, and rz_bin_xtr_extract_t::metadata.

Referenced by rz_bin_file_find_by_arch_bits().