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

Go to the source code of this file.

Macros

#define DB   a->sdb;
 
#define RBINLISTFREE(x)
 
#define ARCHS_KEY   "archs"
 

Functions

 RZ_LIB_VERSION (rz_bin)
 
static ut64 __getoffset (RzBin *bin, int type, int idx)
 
static char * __getname (RzBin *bin, int type, int idx)
 
RZ_API RzBinXtrDatarz_bin_xtrdata_new (RzBuffer *buf, ut64 offset, ut64 size, ut32 file_count, RzBinXtrMetadata *metadata)
 
RZ_API void rz_bin_xtrdata_free (void *data_)
 
RZ_API void rz_bin_options_init (RzBinOptions *opt, int fd, ut64 baseaddr, ut64 loadaddr, bool patch_relocs)
 
RZ_API void rz_bin_arch_options_init (RzBinArchOptions *opt, const char *arch, int bits)
 
RZ_API void rz_bin_file_hash_free (RzBinFileHash *fhash)
 
RZ_API void rz_bin_info_free (RzBinInfo *rb)
 
RZ_API RzBinImportrz_bin_import_clone (RzBinImport *o)
 
RZ_API void rz_bin_import_free (RzBinImport *imp)
 
RZ_API void rz_bin_resource_free (RzBinResource *res)
 
RZ_API const char * rz_bin_symbol_name (RzBinSymbol *s)
 
RZ_API RzBinSymbolrz_bin_symbol_new (const char *name, ut64 paddr, ut64 vaddr)
 
RZ_API void rz_bin_symbol_free (RzBinSymbol *sym)
 
RZ_API void rz_bin_reloc_free (RzBinReloc *reloc)
 
RZ_API void rz_bin_string_free (void *_str)
 
RZ_API RzBinFilerz_bin_open (RzBin *bin, const char *file, RzBinOptions *opt)
 
RZ_API RzBinFilerz_bin_reload (RzBin *bin, RzBinFile *bf, ut64 baseaddr)
 
RZ_API RzBinFilerz_bin_open_buf (RzBin *bin, RzBuffer *buf, RzBinOptions *opt)
 
RZ_API RzBinFilerz_bin_open_io (RzBin *bin, RzBinOptions *opt)
 
RZ_IPI RzBinPluginrz_bin_get_binplugin_by_name (RzBin *bin, const char *name)
 
RZ_API RzBinPluginrz_bin_get_binplugin_by_buffer (RzBin *bin, RzBuffer *buf)
 
RZ_IPI RzBinPluginrz_bin_get_binplugin_by_filename (RzBin *bin)
 
RZ_IPI RzBinXtrPluginrz_bin_get_xtrplugin_by_name (RzBin *bin, const char *name)
 
static void rz_bin_plugin_free (RzBinPlugin *p)
 
RZ_API bool rz_bin_plugin_add (RzBin *bin, RzBinPlugin *foo)
 
RZ_API bool rz_bin_xtr_add (RzBin *bin, RzBinXtrPlugin *foo)
 
RZ_API void rz_bin_free (RzBin *bin)
 
static bool rz_bin_print_plugin_details (RzBin *bin, RzBinPlugin *bp, PJ *pj, int json)
 
static void __printXtrPluginDetails (RzBin *bin, RzBinXtrPlugin *bx, int json)
 
RZ_API bool rz_bin_list_plugin (RzBin *bin, const char *name, PJ *pj, int json)
 
RZ_API ut64 rz_bin_get_baddr (RzBin *bin)
 
RZ_API ut64 rz_bin_get_laddr (RzBin *bin)
 
RZ_API void rz_bin_set_baddr (RzBin *bin, ut64 baddr)
 
RZ_DEPRECATE RZ_API RZ_BORROW RzListrz_bin_get_entries (RZ_NONNULL RzBin *bin)
 
RZ_DEPRECATE RZ_API RZ_BORROW RzListrz_bin_get_fields (RZ_NONNULL RzBin *bin)
 
RZ_DEPRECATE RZ_API RZ_BORROW RzListrz_bin_get_imports (RZ_NONNULL RzBin *bin)
 
RZ_DEPRECATE RZ_API RZ_BORROW RzBinInforz_bin_get_info (RzBin *bin)
 
RZ_DEPRECATE RZ_API RZ_BORROW RzListrz_bin_get_libs (RZ_NONNULL RzBin *bin)
 
RZ_DEPRECATE RZ_API RZ_BORROW RzListrz_bin_get_sections (RZ_NONNULL RzBin *bin)
 
RZ_API RZ_BORROW RzBinSectionrz_bin_get_section_at (RzBinObject *o, ut64 off, int va)
 Find the binary section at offset off. More...
 
RZ_API RZ_BORROW RzBinMaprz_bin_object_get_map_at (RZ_NONNULL RzBinObject *o, ut64 off, bool va)
 Find the last binary map at offset off . More...
 
RZ_API RZ_OWN RzPVectorrz_bin_object_get_maps_at (RzBinObject *o, ut64 off, bool va)
 Find all binary maps at offset off . More...
 
RZ_DEPRECATE RZ_API RZ_BORROW RzListrz_bin_get_strings (RZ_NONNULL RzBin *bin)
 
RZ_DEPRECATE RZ_API RZ_BORROW RzListrz_bin_get_symbols (RZ_NONNULL RzBin *bin)
 
RZ_DEPRECATE RZ_API RZ_BORROW RzListrz_bin_get_mem (RZ_NONNULL RzBin *bin)
 
RZ_DEPRECATE RZ_API int rz_bin_is_static (RZ_NONNULL RzBin *bin)
 
RZ_IPI void rz_bin_file_free (void *_bf)
 
RZ_API RzBinrz_bin_new (void)
 
RZ_API bool rz_bin_use_arch (RzBin *bin, const char *arch, int bits, const char *name)
 
RZ_API bool rz_bin_select (RzBin *bin, const char *arch, int bits, const char *name)
 
RZ_API int rz_bin_select_object (RzBinFile *binfile, const char *arch, int bits, const char *name)
 
RZ_API bool rz_bin_select_bfid (RzBin *bin, ut32 bf_id)
 
RZ_API void rz_bin_set_user_ptr (RzBin *bin, void *user)
 
static RzBinSection__get_vsection_at (RzBin *bin, ut64 vaddr)
 
RZ_API void rz_bin_bind (RzBin *bin, RzBinBind *b)
 
RZ_API RzBufferrz_bin_create (RzBin *bin, const char *p, const ut8 *code, int codelen, const ut8 *data, int datalen, RzBinArchOptions *opt)
 
RZ_DEPRECATE RZ_API RZ_BORROW RzListrz_bin_get_classes (RZ_NONNULL RzBin *bin)
 
RZ_API ut64 rz_bin_get_size (RzBin *bin)
 
RZ_API RzBinFilerz_bin_cur (RzBin *bin)
 
RZ_API RzBinObjectrz_bin_cur_object (RzBin *bin)
 
RZ_API void rz_bin_force_plugin (RzBin *bin, const char *name)
 
RZ_API const char * rz_bin_entry_type_string (int etype)
 
RZ_API void rz_bin_load_filter (RzBin *bin, ut64 rules)
 
RZ_API RzBinFieldrz_bin_field_new (ut64 paddr, ut64 vaddr, int size, const char *name, const char *comment, const char *format, bool format_named)
 
RZ_API void rz_bin_field_free (RzBinField *field)
 
RZ_API const char * rz_bin_get_meth_flag_string (ut64 flag, bool compact)
 
RZ_API void rz_bin_virtual_file_free (RzBinVirtualFile *vfile)
 
RZ_API void rz_bin_map_free (RzBinMap *map)
 
RZ_API RZ_OWN RzListrz_bin_maps_of_file_sections (RZ_NONNULL RzBinFile *binfile)
 Create a list of RzBinMap from RzBinSections queried from the given file. More...
 
RZ_API RzListrz_bin_sections_of_maps (RzList *maps)
 Create a list of RzBinSection from RzBinMaps. More...
 
RZ_API RzBinSectionrz_bin_section_new (const char *name)
 
RZ_API void rz_bin_section_free (RzBinSection *bs)
 
RZ_API RZ_OWN char * rz_bin_section_type_to_string (RzBin *bin, int type)
 Converts the RzBinSection type to the string representation. More...
 
RZ_API RZ_OWN RzListrz_bin_section_flag_to_list (RzBin *bin, ut64 flag)
 Converts the RzBinSection flags to a list of string representations. More...
 
RZ_API RzBinFilerz_bin_file_at (RzBin *bin, ut64 at)
 
RZ_API RzBinTrycatchrz_bin_trycatch_new (ut64 source, ut64 from, ut64 to, ut64 handler, ut64 filter)
 
RZ_API void rz_bin_trycatch_free (RzBinTrycatch *tc)
 
RZ_API const RzBinPluginrz_bin_plugin_get (RZ_NONNULL RzBin *bin, RZ_NONNULL const char *name)
 Get a RzBinPlugin by name. More...
 
RZ_API const RzBinXtrPluginrz_bin_xtrplugin_get (RZ_NONNULL RzBin *bin, RZ_NONNULL const char *name)
 Get a RzBinXtrPlugin by name. More...
 
RZ_API RZ_OWN char * rz_bin_demangle (RZ_NULLABLE RzBinFile *bf, RZ_NULLABLE const char *language, RZ_NULLABLE const char *symbol, ut64 vaddr, bool libs)
 Demangles a symbol based on the language or the RzBinFile data. More...
 

Variables

static RzBinPluginbin_static_plugins [] = { RZ_BIN_STATIC_PLUGINS }
 
static RzBinXtrPluginbin_xtr_static_plugins [] = { RZ_BIN_XTR_STATIC_PLUGINS }
 

Macro Definition Documentation

◆ ARCHS_KEY

#define ARCHS_KEY   "archs"

Definition at line 23 of file bin.c.

◆ DB

#define DB   a->sdb;

Definition at line 16 of file bin.c.

◆ RBINLISTFREE

#define RBINLISTFREE (   x)
Value:
if (x) { \
rz_list_free(x); \
(x) = NULL; \
}
#define NULL
Definition: cris-opc.c:27
int x
Definition: mipsasm.c:20

Definition at line 17 of file bin.c.

Function Documentation

◆ __get_vsection_at()

static RzBinSection* __get_vsection_at ( RzBin bin,
ut64  vaddr 
)
static

Definition at line 843 of file bin.c.

843  {
845  if (!bin->cur) {
846  return NULL;
847  }
848  return rz_bin_get_section_at(bin->cur->o, vaddr, true);
849 }
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
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
Definition: malloc.c:26

References NULL, rz_bin_get_section_at(), and rz_return_val_if_fail.

Referenced by rz_bin_bind().

◆ __getname()

static char* __getname ( RzBin bin,
int  type,
int  idx 
)
static

Definition at line 37 of file bin.c.

37  {
40  if (plugin && plugin->get_name) {
41  return plugin->get_name(a, type, idx);
42  }
43  return NULL;
44 }
RZ_API RzBinPlugin * rz_bin_file_cur_plugin(RzBinFile *bf)
Definition: bfile.c:348
RZ_API RzBinFile * rz_bin_cur(RzBin *bin)
Definition: bin.c:895
int type
Definition: mipsasm.c:17
int idx
Definition: setup.py:197
#define a(i)
Definition: sha256.c:41
XX curplugin == o->plugin.
Definition: rz_bin.h:298
char *(* get_name)(RzBinFile *bf, int type, int idx)
Definition: rz_bin.h:547

References a, rz_bin_plugin_t::get_name, setup::idx, NULL, rz_bin_cur(), rz_bin_file_cur_plugin(), and type.

Referenced by rz_bin_bind().

◆ __getoffset()

static ut64 __getoffset ( RzBin bin,
int  type,
int  idx 
)
static

Definition at line 28 of file bin.c.

28  {
31  if (plugin && plugin->get_offset) {
32  return plugin->get_offset(a, type, idx);
33  }
34  return UT64_MAX;
35 }
#define UT64_MAX
Definition: rz_types_base.h:86
ut64(* get_offset)(RzBinFile *bf, int type, int idx)
Definition: rz_bin.h:546

References a, rz_bin_plugin_t::get_offset, setup::idx, rz_bin_cur(), rz_bin_file_cur_plugin(), type, and UT64_MAX.

Referenced by rz_bin_bind().

◆ __printXtrPluginDetails()

static void __printXtrPluginDetails ( RzBin bin,
RzBinXtrPlugin bx,
int  json 
)
static

Definition at line 486 of file bin.c.

486  {
487  if (json == 'q') {
488  bin->cb_printf("%s\n", bx->name);
489  } else if (json) {
490  PJ *pj = pj_new();
491  if (!pj) {
492  return;
493  }
494  pj_o(pj);
495  pj_ks(pj, "name", bx->name);
496  pj_ks(pj, "description", bx->desc);
497  pj_ks(pj, "license", bx->license ? bx->license : "???");
498  pj_end(pj);
499  bin->cb_printf("%s\n", pj_string(pj));
500  pj_free(pj);
501  } else {
502  bin->cb_printf("Name: %s\n", bx->name);
503  bin->cb_printf("Description: %s\n", bx->desc);
504  if (bx->license) {
505  bin->cb_printf("License: %s\n", bx->license);
506  }
507  }
508 }
RZ_API PJ * pj_new(void)
Definition: pj.c:25
RZ_API PJ * pj_end(PJ *j)
Definition: pj.c:87
RZ_API const char * pj_string(PJ *pj)
Definition: pj.c:57
RZ_API void pj_free(PJ *j)
Definition: pj.c:34
RZ_API PJ * pj_o(PJ *j)
Definition: pj.c:75
RZ_API PJ * pj_ks(PJ *j, const char *k, const char *v)
Definition: pj.c:170
Definition: rz_pj.h:12

References rz_bin_xtr_plugin_t::desc, rz_bin_xtr_plugin_t::license, rz_bin_xtr_plugin_t::name, pj_end(), pj_free(), pj_ks(), pj_new(), pj_o(), and pj_string().

Referenced by rz_bin_list_plugin().

◆ rz_bin_arch_options_init()

RZ_API void rz_bin_arch_options_init ( RzBinArchOptions opt,
const char *  arch,
int  bits 
)

Definition at line 84 of file bin.c.

84  {
85  opt->arch = arch ? arch : RZ_SYS_ARCH;
86  opt->bits = bits ? bits : RZ_SYS_BITS;
87 }
int bits(struct state *s, int need)
Definition: blast.c:72
cs_arch arch
Definition: cstool.c:13
#define RZ_SYS_BITS
Definition: rz_types.h:520
#define RZ_SYS_ARCH
Definition: rz_types.h:519
const char * arch
Definition: rz_bin.h:414

References rz_bin_arch_options_t::arch, arch, rz_bin_arch_options_t::bits, bits(), RZ_SYS_ARCH, and RZ_SYS_BITS.

Referenced by create(), and rz_main_rz_bin().

◆ rz_bin_bind()

RZ_API void rz_bin_bind ( RzBin bin,
RzBinBind b 
)

Definition at line 851 of file bin.c.

851  {
852  if (b) {
853  b->bin = bin;
854  b->get_offset = __getoffset;
855  b->get_name = __getname;
856  b->get_sections = rz_bin_get_sections;
857  b->get_vsect_at = __get_vsection_at;
858  b->demangle = rz_bin_demangle;
859  }
860 }
RZ_API RZ_OWN char * rz_bin_demangle(RZ_NULLABLE RzBinFile *bf, RZ_NULLABLE const char *language, RZ_NULLABLE const char *symbol, ut64 vaddr, bool libs)
Demangles a symbol based on the language or the RzBinFile data.
Definition: bin.c:1295
static RzBinSection * __get_vsection_at(RzBin *bin, ut64 vaddr)
Definition: bin.c:843
static char * __getname(RzBin *bin, int type, int idx)
Definition: bin.c:37
RZ_DEPRECATE RZ_API RZ_BORROW RzList * rz_bin_get_sections(RZ_NONNULL RzBin *bin)
Definition: bin.c:597
static ut64 __getoffset(RzBin *bin, int type, int idx)
Definition: bin.c:28
#define b(i)
Definition: sha256.c:42

References __get_vsection_at(), __getname(), __getoffset(), b, rz_bin_demangle(), and rz_bin_get_sections().

Referenced by rz_core_init().

◆ rz_bin_create()

RZ_API RzBuffer* rz_bin_create ( RzBin bin,
const char *  p,
const ut8 code,
int  codelen,
const ut8 data,
int  datalen,
RzBinArchOptions opt 
)

Definition at line 862 of file bin.c.

865  {
866 
867  rz_return_val_if_fail(bin && p && opt, NULL);
868 
870  if (!plugin) {
871  RZ_LOG_WARN("Cannot find RzBin plugin named '%s'.\n", p);
872  return NULL;
873  }
874  if (!plugin->create) {
875  RZ_LOG_WARN("RzBin plugin '%s' does not implement \"create\" method.\n", p);
876  return NULL;
877  }
878  codelen = RZ_MAX(codelen, 0);
879  datalen = RZ_MAX(datalen, 0);
880  return plugin->create(bin, code, codelen, data, datalen, opt);
881 }
RZ_IPI RzBinPlugin * rz_bin_get_binplugin_by_name(RzBin *bin, const char *name)
Definition: bin.c:335
void * p
Definition: libc.cpp:67
#define RZ_LOG_WARN(fmtstr,...)
Definition: rz_log.h:56
#define RZ_MAX(x, y)
Definition: inftree9.h:24
RzBuffer *(* create)(RzBin *bin, const ut8 *code, int codelen, const ut8 *data, int datalen, RzBinArchOptions *opt)
Definition: rz_bin.h:551

References rz_bin_plugin_t::create, NULL, p, rz_bin_get_binplugin_by_name(), RZ_LOG_WARN, RZ_MAX, and rz_return_val_if_fail.

Referenced by create(), and rz_main_rz_bin().

◆ rz_bin_cur()

◆ rz_bin_cur_object()

◆ rz_bin_demangle()

RZ_API RZ_OWN char* rz_bin_demangle ( RZ_NULLABLE RzBinFile bf,
RZ_NULLABLE const char *  language,
RZ_NULLABLE const char *  symbol,
ut64  vaddr,
bool  libs 
)

Demangles a symbol based on the language or the RzBinFile data.

This function demangles a symbol based on the language or the RzBinFile data When C++ or rust is selected as the language, it will add methods into the RzBinFile structure based on the demangled symbol. When libs is set to true, the demangled symbol will be appended to the library name <libname>_<demangled symbol>.

Parameters
bfRzBinFile data to be used for demangling
languageLanguage to be used for demanglind
symbolSymbol to be demangled
vaddrvaddr of the symbol to be demangled
libsAppend the library name to the demangled symbol, if set to true
Returns
char* Demangled name of the symbol

Definition at line 1295 of file bin.c.

1295  {
1296  if (RZ_STR_ISEMPTY(symbol)) {
1297  return NULL;
1298  }
1299 
1301  RzBin *bin = bf ? bf->rbin : NULL;
1302  RzBinObject *o = bf ? bf->o : NULL;
1303 
1304  if (!language && o && o->info && o->info->lang) {
1305  language = o->info->lang;
1306  }
1307 
1308  RzListIter *iter;
1309  const char *lib = NULL;
1310  if (!strncmp(symbol, "reloc.", 6)) {
1311  symbol += 6;
1312  }
1313  if (!strncmp(symbol, "sym.", 4)) {
1314  symbol += 4;
1315  }
1316  if (!strncmp(symbol, "imp.", 4)) {
1317  symbol += 4;
1318  }
1319  if (!strncmp(symbol, "target.", 7)) {
1320  symbol += 7;
1321  }
1322  if (o) {
1323  bool found = false;
1324  rz_list_foreach (o->libs, iter, lib) {
1325  size_t len = strlen(lib);
1326  if (!rz_str_ncasecmp(symbol, lib, len)) {
1327  symbol += len;
1328  if (*symbol == '_') {
1329  symbol++;
1330  }
1331  found = true;
1332  break;
1333  }
1334  }
1335  if (!found) {
1336  lib = NULL;
1337  }
1338  size_t len = strlen(bin->file);
1339  if (!rz_str_ncasecmp(symbol, bin->file, len)) {
1340  lib = bin->file;
1341  symbol += len;
1342  if (*symbol == '_') {
1343  symbol++;
1344  }
1345  }
1346  }
1347 
1348  if (RZ_STR_ISEMPTY(symbol)) {
1349  return NULL;
1350  }
1351 
1352  if (!strncmp(symbol, "__", 2)) {
1353  if (symbol[2] == 'T') {
1355  } else {
1357  }
1358  }
1359 
1360  if (type == RZ_BIN_LANGUAGE_UNKNOWN) {
1361  type = rz_bin_language_to_id(language);
1362  // ignore "with blocks"
1364  language = rz_bin_language_to_string(type);
1365  }
1366  if (!language) {
1367  return NULL;
1368  }
1369  char *demangled = NULL;
1370  switch (type) {
1371  case RZ_BIN_LANGUAGE_UNKNOWN: return NULL;
1373  /* fall-thru */
1375  /* fall-thru */
1376  case RZ_BIN_LANGUAGE_DART:
1377  /* fall-thru */
1378  case RZ_BIN_LANGUAGE_JAVA: demangled = rz_demangler_java(symbol); break;
1379  case RZ_BIN_LANGUAGE_OBJC: demangled = rz_demangler_objc(symbol); break;
1380  case RZ_BIN_LANGUAGE_MSVC: demangled = rz_demangler_msvc(symbol); break;
1381 #if WITH_GPL
1382  case RZ_BIN_LANGUAGE_RUST: demangled = bin_demangle_rust(bf, symbol, vaddr); break;
1383  case RZ_BIN_LANGUAGE_CXX: demangled = bin_demangle_cxx(bf, symbol, vaddr); break;
1384 #else
1385  case RZ_BIN_LANGUAGE_RUST: demangled = NULL; break;
1386  case RZ_BIN_LANGUAGE_CXX: demangled = NULL; break;
1387 #endif
1388  default: rz_demangler_resolve(bin->demangler, symbol, language, &demangled);
1389  }
1390  if (libs && demangled && lib) {
1391  char *d = rz_str_newf("%s_%s", lib, demangled);
1392  free(demangled);
1393  demangled = d;
1394  }
1395  return demangled;
1396 }
size_t len
Definition: 6502dis.c:15
static RzList * libs(RzBinFile *bf)
Definition: bin_coff.c:379
RZ_API RzBinLanguage rz_bin_language_to_id(const char *language)
returns the language identifier based on the given lang name
Definition: bin_language.c:193
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
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API const KEY_TYPE bool * found
Definition: ht_inc.h:130
RZ_API RZ_OWN char * rz_demangler_objc(RZ_NONNULL const char *symbol)
Demangles objc symbols.
Definition: demangler.c:56
RZ_API RZ_OWN char * rz_demangler_msvc(RZ_NONNULL const char *symbol)
Demangles microsft vc symbols.
Definition: demangler.c:74
RZ_API RZ_OWN char * rz_demangler_java(RZ_NULLABLE const char *symbol)
Demangles java symbols.
Definition: demangler.c:38
RZ_API bool rz_demangler_resolve(RZ_NONNULL RzDemangler *dem, RZ_NULLABLE const char *symbol, RZ_NONNULL const char *language, RZ_NONNULL RZ_OWN char **output)
Resolves a symbol based on its language and return an output that needs to be freed.
Definition: demangler.c:187
RzBinLanguage
Definition: rz_bin.h:145
@ RZ_BIN_LANGUAGE_UNKNOWN
Definition: rz_bin.h:146
@ RZ_BIN_LANGUAGE_GROOVY
Definition: rz_bin.h:157
@ RZ_BIN_LANGUAGE_OBJC
Definition: rz_bin.h:151
@ RZ_BIN_LANGUAGE_KOTLIN
Definition: rz_bin.h:156
@ RZ_BIN_LANGUAGE_RUST
Definition: rz_bin.h:155
@ RZ_BIN_LANGUAGE_JAVA
Definition: rz_bin.h:147
@ RZ_BIN_LANGUAGE_DART
Definition: rz_bin.h:158
@ RZ_BIN_LANGUAGE_CXX
Definition: rz_bin.h:150
@ RZ_BIN_LANGUAGE_SWIFT
Definition: rz_bin.h:152
@ RZ_BIN_LANGUAGE_MSVC
Definition: rz_bin.h:154
#define RZ_BIN_LANGUAGE_MASK(x)
Definition: rz_bin.h:162
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
#define RZ_STR_ISEMPTY(x)
Definition: rz_str.h:67
RZ_API int rz_str_ncasecmp(const char *dst, const char *orig, size_t n)
Definition: str.c:129
#define d(i)
Definition: sha256.c:44
const char * lang
Definition: rz_bin.h:224
RzBinInfo * info
Definition: rz_bin.h:287
RzList * libs
Definition: rz_bin.h:278

References d, found, free(), rz_bin_object_t::info, rz_bin_info_t::lang, len, libs(), rz_bin_object_t::libs, NULL, RZ_BIN_LANGUAGE_CXX, RZ_BIN_LANGUAGE_DART, RZ_BIN_LANGUAGE_GROOVY, RZ_BIN_LANGUAGE_JAVA, RZ_BIN_LANGUAGE_KOTLIN, RZ_BIN_LANGUAGE_MASK, RZ_BIN_LANGUAGE_MSVC, RZ_BIN_LANGUAGE_OBJC, RZ_BIN_LANGUAGE_RUST, RZ_BIN_LANGUAGE_SWIFT, rz_bin_language_to_id(), rz_bin_language_to_string(), RZ_BIN_LANGUAGE_UNKNOWN, rz_demangler_java(), rz_demangler_msvc(), rz_demangler_objc(), rz_demangler_resolve(), RZ_STR_ISEMPTY, rz_str_ncasecmp(), rz_str_newf(), and type.

Referenced by ds_print_relocs(), ds_show_flags(), ds_show_functions(), reloc_set_flag(), rz_bin_bind(), rz_bin_filter_sym(), rz_core_analysis_fcn_name(), rz_core_bin_imports_print(), rz_core_bin_relocs_print(), rz_core_sym_name_init(), symbols(), and symbols_from_mach0().

◆ rz_bin_entry_type_string()

RZ_API const char* rz_bin_entry_type_string ( int  etype)

Definition at line 912 of file bin.c.

912  {
913  switch (etype) {
915  return "program";
917  return "main";
919  return "init";
921  return "fini";
923  return "tls";
925  return "preinit";
926  }
927  return NULL;
928 }
#define RZ_BIN_ENTRY_TYPE_PREINIT
Definition: rz_bin.h:38
#define RZ_BIN_ENTRY_TYPE_TLS
Definition: rz_bin.h:37
#define RZ_BIN_ENTRY_TYPE_FINI
Definition: rz_bin.h:36
#define RZ_BIN_ENTRY_TYPE_INIT
Definition: rz_bin.h:35
#define RZ_BIN_ENTRY_TYPE_PROGRAM
Definition: rz_bin.h:33
#define RZ_BIN_ENTRY_TYPE_MAIN
Definition: rz_bin.h:34

References NULL, RZ_BIN_ENTRY_TYPE_FINI, RZ_BIN_ENTRY_TYPE_INIT, RZ_BIN_ENTRY_TYPE_MAIN, RZ_BIN_ENTRY_TYPE_PREINIT, RZ_BIN_ENTRY_TYPE_PROGRAM, and RZ_BIN_ENTRY_TYPE_TLS.

Referenced by entries_initfini_print(), and rz_core_bin_apply_entry().

◆ rz_bin_field_free()

RZ_API void rz_bin_field_free ( RzBinField field)

Definition at line 950 of file bin.c.

950  {
951  if (field) {
952  free(field->name);
953  free(field->visibility_str);
954  free(field->type);
955  free(field->comment);
956  free(field->format);
957  free(field);
958  }
959 }
char * comment
Definition: rz_bin.h:770
char * format
Definition: rz_bin.h:771
char * name
Definition: rz_bin.h:767
char * type
Definition: rz_bin.h:768
char * visibility_str
Definition: rz_bin.h:769

References rz_bin_field_t::comment, rz_bin_field_t::format, free(), rz_bin_field_t::name, rz_bin_field_t::type, and rz_bin_field_t::visibility_str.

Referenced by dex_resolve_fields_in_class(), fields(), get_ivar_list_t(), MACH0_(), rz_bin_dex_fields(), and rz_bin_java_class_fields_as_binfields().

◆ rz_bin_field_new()

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 at line 935 of file bin.c.

935  {
936  RzBinField *ptr = RZ_NEW0(RzBinField);
937  if (ptr) {
938  ptr->name = strdup(name);
939  ptr->comment = (comment && *comment) ? strdup(comment) : NULL;
940  ptr->format = (format && *format) ? strdup(format) : NULL;
941  ptr->format_named = format_named;
942  ptr->paddr = paddr;
943  ptr->size = size;
944  // ptr->visibility = any default visibility?
945  ptr->vaddr = vaddr;
946  }
947  return ptr;
948 }
voidpf void uLong size
Definition: ioapi.h:138
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")
#define RZ_NEW0(x)
Definition: rz_types.h:284
Definition: z80asm.h:102
ut64 vaddr
Definition: rz_bin.h:762
ut64 paddr
Definition: rz_bin.h:763
bool format_named
Definition: rz_bin.h:772

References rz_bin_field_t::comment, rz_bin_field_t::format, rz_bin_field_t::format_named, rz_bin_field_t::name, NULL, rz_bin_field_t::paddr, RZ_NEW0, rz_bin_field_t::size, strdup(), and rz_bin_field_t::vaddr.

Referenced by classes_from_symbols(), fields(), MACH0_(), and rz_bin_java_class_fields_as_binfields().

◆ rz_bin_file_at()

RZ_API RzBinFile* rz_bin_file_at ( RzBin bin,
ut64  at 
)

Definition at line 1160 of file bin.c.

1160  {
1161  RzListIter *it;
1162  RzBinFile *bf;
1163  rz_list_foreach (bin->binfiles, it, bf) {
1164  if (!bf->o) {
1165  continue;
1166  }
1167  RzBinMap *map = rz_bin_object_get_map_at(bf->o, at, true);
1168  if (map) {
1169  return bf;
1170  }
1171  if (at >= bf->o->opts.baseaddr && at < (bf->o->opts.baseaddr + bf->size)) {
1172  return bf;
1173  }
1174  }
1175  return NULL;
1176 }
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
size_t map(int syms, int left, int len)
Definition: enough.c:237
ut64 baseaddr
where the linker maps the binary in memory
Definition: rz_bin.h:248
Description of a single memory mapping into virtual memory from a binary.
Definition: rz_bin.h:602
RzBinObjectLoadOptions opts
Definition: rz_bin.h:260

References rz_bin_file_load_options_t::baseaddr, map(), NULL, rz_bin_file_t::o, rz_bin_object_t::opts, rz_bin_object_get_map_at(), and rz_bin_file_t::size.

Referenced by rz_core_binfiles_delete(), rz_core_seek(), and rz_open_binary_show_handler().

◆ 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_IPI void rz_bin_object_free(RzBinObject *o)
Definition: bobj.c:188
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
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 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
char * file
Definition: rz_bin.h:299
RzBuffer * buf
Definition: rz_bin.h:303
RzList * xtr_data
Definition: rz_bin.h:314
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_hash_free()

RZ_API void rz_bin_file_hash_free ( RzBinFileHash fhash)

Definition at line 89 of file bin.c.

89  {
90  if (fhash) {
91  RZ_FREE(fhash->type);
92  RZ_FREE(fhash->hex);
93  free(fhash);
94  }
95 }
#define RZ_FREE(x)
Definition: rz_types.h:369
const char * type
Definition: rz_bin.h:205
const char * hex
Definition: rz_bin.h:206

References free(), rz_bin_file_hash_t::hex, RZ_FREE, and rz_bin_file_hash_t::type.

Referenced by rz_bin_file_compute_hashes().

◆ rz_bin_force_plugin()

RZ_API void rz_bin_force_plugin ( RzBin bin,
const char *  name 
)

Definition at line 906 of file bin.c.

906  {
908  free(bin->force);
909  bin->force = (name && *name) ? strdup(name) : NULL;
910 }
const char * name
Definition: op.c:541
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100

References free(), name, NULL, rz_return_if_fail, and strdup().

Referenced by cb_binforce(), rz_main_rizin(), and rz_main_rz_bin().

◆ rz_bin_free()

RZ_API void rz_bin_free ( RzBin bin)

Definition at line 440 of file bin.c.

440  {
441  if (!bin) {
442  return;
443  }
444  bin->file = NULL;
445  free(bin->force);
446  free(bin->srcdir);
447  free(bin->strenc);
448  // rz_bin_free_bin_files (bin);
449  rz_list_free(bin->binfiles);
450  rz_list_free(bin->binxtrs);
451  rz_list_free(bin->plugins);
452  sdb_free(bin->sdb);
453  rz_id_storage_free(bin->ids);
454  rz_hash_free(bin->hash);
455  rz_event_free(bin->event);
456  rz_str_constpool_fini(&bin->constpool);
457  rz_demangler_free(bin->demangler);
458  free(bin);
459 }
RZ_API void rz_hash_free(RzHash *rh)
Definition: hash.c:597
RZ_API void rz_demangler_free(RZ_NULLABLE RzDemangler *dem)
Frees the RzDemangler struct.
Definition: demangler.c:112
RZ_API void rz_event_free(RzEvent *ev)
Definition: event.c:37
RZ_API void rz_id_storage_free(RzIDStorage *storage)
Definition: idpool.c:270
RZ_API void rz_str_constpool_fini(RzStrConstPool *pool)
Definition: str_constpool.c:15

References free(), NULL, rz_demangler_free(), rz_event_free(), rz_hash_free(), rz_id_storage_free(), rz_list_free(), rz_str_constpool_fini(), and sdb_free().

Referenced by create(), download_pdb(), rz_core_fini(), rz_diff_file_close(), rz_diff_file_open(), and rzfind_open_file().

◆ rz_bin_get_baddr()

RZ_API ut64 rz_bin_get_baddr ( RzBin bin)

Definition at line 536 of file bin.c.

536  {
538  return rz_bin_file_get_baddr(bin->cur);
539 }
RZ_API ut64 rz_bin_file_get_baddr(RzBinFile *bf)
Definition: bfile.c:352

References rz_bin_file_get_baddr(), rz_return_val_if_fail, and UT64_MAX.

Referenced by entries_initfini_print(), rz_core_bin_apply_all_info(), rz_core_bin_info_print(), rz_core_file_reopen_remote_debug(), and rz_core_pdb_load_info().

◆ rz_bin_get_binplugin_by_buffer()

RZ_API RzBinPlugin* rz_bin_get_binplugin_by_buffer ( RzBin bin,
RzBuffer buf 
)

Definition at line 349 of file bin.c.

349  {
350  RzBinPlugin *plugin;
351  RzListIter *it;
352 
354 
355  rz_list_foreach (bin->plugins, it, plugin) {
356  if (plugin->check_buffer) {
357  if (plugin->check_buffer(buf)) {
358  return plugin;
359  }
360  }
361  }
362  return NULL;
363 }
voidpf void * buf
Definition: ioapi.h:138
bool(* check_buffer)(RzBuffer *buf)
Definition: rz_bin.h:519

References rz_bin_plugin_t::check_buffer, NULL, and rz_return_val_if_fail.

Referenced by cmd_search_bin(), and get_plugin_from_buffer().

◆ 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 }
const char * filename
Definition: ioapi.h:137
#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 }
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_classes()

RZ_DEPRECATE RZ_API RZ_BORROW RzList* rz_bin_get_classes ( RZ_NONNULL RzBin bin)

Definition at line 883 of file bin.c.

883  {
886  return o ? o->classes : NULL;
887 }
RZ_API RzBinObject * rz_bin_cur_object(RzBin *bin)
Definition: bin.c:900
RzList * classes
Definition: rz_bin.h:281

References rz_bin_object_t::classes, NULL, rz_bin_cur_object(), and rz_return_val_if_fail.

Referenced by findClassBounds(), rz_analysis_class_recover_from_rzbin(), rz_core_visual_classes(), and rz_core_visual_hudclasses().

◆ rz_bin_get_entries()

RZ_DEPRECATE RZ_API RZ_BORROW RzList* rz_bin_get_entries ( RZ_NONNULL RzBin bin)

Definition at line 567 of file bin.c.

567  {
570  return o ? (RzList *)rz_bin_object_get_entries(o) : NULL;
571 }
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: bobj.c:710

References NULL, rz_bin_cur_object(), rz_bin_object_get_entries(), and rz_return_val_if_fail.

Referenced by initializeEsil(), and rz_core_analysis_all().

◆ rz_bin_get_fields()

RZ_DEPRECATE RZ_API RZ_BORROW RzList* rz_bin_get_fields ( RZ_NONNULL RzBin bin)

Definition at line 573 of file bin.c.

573  {
576  return o ? (RzList *)rz_bin_object_get_fields(o) : NULL;
577 }
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: bobj.c:718

References NULL, rz_bin_cur_object(), rz_bin_object_get_fields(), and rz_return_val_if_fail.

◆ rz_bin_get_imports()

RZ_DEPRECATE RZ_API RZ_BORROW RzList* rz_bin_get_imports ( RZ_NONNULL RzBin bin)

Definition at line 579 of file bin.c.

579  {
582  return o ? (RzList *)rz_bin_object_get_imports(o) : NULL;
583 }
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: bobj.c:726

References NULL, rz_bin_cur_object(), rz_bin_object_get_imports(), and rz_return_val_if_fail.

Referenced by rz_core_bin_load(), and rz_core_cmd_foreach3().

◆ rz_bin_get_info()

RZ_DEPRECATE RZ_API RZ_BORROW RzBinInfo* rz_bin_get_info ( RzBin bin)

◆ rz_bin_get_laddr()

RZ_API ut64 rz_bin_get_laddr ( RzBin bin)

Definition at line 542 of file bin.c.

542  {
545  return o ? o->opts.loadaddr : UT64_MAX;
546 }
ut64 loadaddr
starting physical address to read from the target file
Definition: rz_bin.h:249

References rz_bin_file_load_options_t::loadaddr, rz_bin_object_t::opts, rz_bin_cur_object(), rz_return_val_if_fail, and UT64_MAX.

Referenced by entries_initfini_print(), rabin_do_operation(), rz_bin_use_arch(), and rz_core_bin_info_print().

◆ rz_bin_get_libs()

RZ_DEPRECATE RZ_API RZ_BORROW RzList* rz_bin_get_libs ( RZ_NONNULL RzBin bin)

Definition at line 591 of file bin.c.

591  {
594  return o ? (RzList *)rz_bin_object_get_libs(o) : NULL;
595 }
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: bobj.c:742

References NULL, rz_bin_cur_object(), rz_bin_object_get_libs(), and rz_return_val_if_fail.

Referenced by rz_core_bin_load().

◆ rz_bin_get_mem()

RZ_DEPRECATE RZ_API RZ_BORROW RzList* rz_bin_get_mem ( RZ_NONNULL RzBin bin)

Definition at line 702 of file bin.c.

702  {
705  return o ? (RzList *)rz_bin_object_get_mem(o) : NULL;
706 }
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: bobj.c:809

References NULL, rz_bin_cur_object(), rz_bin_object_get_mem(), and rz_return_val_if_fail.

◆ rz_bin_get_meth_flag_string()

RZ_API const char* rz_bin_get_meth_flag_string ( ut64  flag,
bool  compact 
)

Definition at line 961 of file bin.c.

961  {
962  switch (flag) {
963  case RZ_BIN_METH_CLASS:
964  return compact ? "c" : "class";
965  case RZ_BIN_METH_STATIC:
966  return compact ? "s" : "static";
967  case RZ_BIN_METH_PUBLIC:
968  return compact ? "p" : "public";
969  case RZ_BIN_METH_PRIVATE:
970  return compact ? "P" : "private";
972  return compact ? "r" : "protected";
974  return compact ? "i" : "internal";
975  case RZ_BIN_METH_OPEN:
976  return compact ? "o" : "open";
978  return compact ? "e" : "fileprivate";
979  case RZ_BIN_METH_FINAL:
980  return compact ? "f" : "final";
981  case RZ_BIN_METH_VIRTUAL:
982  return compact ? "v" : "virtual";
983  case RZ_BIN_METH_CONST:
984  return compact ? "k" : "const";
986  return compact ? "m" : "mutating";
988  return compact ? "a" : "abstract";
990  return compact ? "y" : "synchronized";
991  case RZ_BIN_METH_NATIVE:
992  return compact ? "n" : "native";
993  case RZ_BIN_METH_BRIDGE:
994  return compact ? "b" : "bridge";
995  case RZ_BIN_METH_VARARGS:
996  return compact ? "g" : "varargs";
998  return compact ? "h" : "synthetic";
999  case RZ_BIN_METH_STRICT:
1000  return compact ? "t" : "strict";
1001  case RZ_BIN_METH_MIRANDA:
1002  return compact ? "A" : "miranda";
1004  return compact ? "C" : "constructor";
1006  return compact ? "Y" : "declared_synchronized";
1007  default:
1008  return NULL;
1009  }
1010 }
#define RZ_BIN_METH_INTERNAL
Definition: rz_bin.h:88
#define RZ_BIN_METH_VIRTUAL
Definition: rz_bin.h:92
#define RZ_BIN_METH_CLASS
Definition: rz_bin.h:83
#define RZ_BIN_METH_CONSTRUCTOR
Definition: rz_bin.h:103
#define RZ_BIN_METH_FILEPRIVATE
Definition: rz_bin.h:90
#define RZ_BIN_METH_SYNCHRONIZED
Definition: rz_bin.h:96
#define RZ_BIN_METH_PUBLIC
Definition: rz_bin.h:85
#define RZ_BIN_METH_VARARGS
Definition: rz_bin.h:99
#define RZ_BIN_METH_SYNTHETIC
Definition: rz_bin.h:100
#define RZ_BIN_METH_STRICT
Definition: rz_bin.h:101
#define RZ_BIN_METH_ABSTRACT
Definition: rz_bin.h:95
#define RZ_BIN_METH_DECLARED_SYNCHRONIZED
Definition: rz_bin.h:104
#define RZ_BIN_METH_MUTATING
Definition: rz_bin.h:94
#define RZ_BIN_METH_FINAL
Definition: rz_bin.h:91
#define RZ_BIN_METH_MIRANDA
Definition: rz_bin.h:102
#define RZ_BIN_METH_OPEN
Definition: rz_bin.h:89
#define RZ_BIN_METH_CONST
Definition: rz_bin.h:93
#define RZ_BIN_METH_BRIDGE
Definition: rz_bin.h:98
#define RZ_BIN_METH_STATIC
Definition: rz_bin.h:84
#define RZ_BIN_METH_PRIVATE
Definition: rz_bin.h:86
#define RZ_BIN_METH_PROTECTED
Definition: rz_bin.h:87
#define RZ_BIN_METH_NATIVE
Definition: rz_bin.h:97

References NULL, RZ_BIN_METH_ABSTRACT, RZ_BIN_METH_BRIDGE, RZ_BIN_METH_CLASS, RZ_BIN_METH_CONST, RZ_BIN_METH_CONSTRUCTOR, RZ_BIN_METH_DECLARED_SYNCHRONIZED, RZ_BIN_METH_FILEPRIVATE, RZ_BIN_METH_FINAL, RZ_BIN_METH_INTERNAL, RZ_BIN_METH_MIRANDA, RZ_BIN_METH_MUTATING, RZ_BIN_METH_NATIVE, RZ_BIN_METH_OPEN, RZ_BIN_METH_PRIVATE, RZ_BIN_METH_PROTECTED, RZ_BIN_METH_PUBLIC, RZ_BIN_METH_STATIC, RZ_BIN_METH_STRICT, RZ_BIN_METH_SYNCHRONIZED, RZ_BIN_METH_SYNTHETIC, RZ_BIN_METH_VARARGS, and RZ_BIN_METH_VIRTUAL.

Referenced by flags_to_json(), resolve_method_flags(), and rz_core_bin_method_flags_str().

◆ rz_bin_get_section_at()

RZ_API RZ_BORROW RzBinSection* rz_bin_get_section_at ( RzBinObject o,
ut64  off,
int  va 
)

Find the binary section at offset off.

Parameters
oReference to the RzBinObject instance
offAddress to search
vaWhen 0 the offset off is considered a physical address, otherwise a virtual address
Returns
Pointer to a RzBinSection containing the address

Definition at line 611 of file bin.c.

611  {
613  RzListIter *iter;
614  ut64 from, to;
615 
617  // TODO: must be O(1) .. use sdb here
618  rz_list_foreach (o->sections, iter, section) {
619  if (section->is_segment) {
620  continue;
621  }
622  from = va ? rz_bin_object_addr_with_base(o, section->vaddr) : section->paddr;
623  to = from + (va ? section->vsize : section->size);
624  if (off >= from && off < to) {
625  return section;
626  }
627  }
628  return NULL;
629 }
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
int off
Definition: pal.c:13
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr from
Definition: sfsocketcall.h:123
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr socklen_t static fromlen const void const struct sockaddr to
Definition: sfsocketcall.h:125
RzList * sections
Definition: rz_bin.h:267
uint32_t size
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References from, NULL, off, rz_bin_object_addr_with_base(), rz_return_val_if_fail, rz_bin_object_t::sections, section::size, to, and ut64().

Referenced by __get_vsection_at(), ds_print_lines_left(), ds_print_ptr(), num_callback(), print_bin_string(), print_string(), prompt_add_section(), recover_string_at(), rz_bin_object_get_vaddr(), rz_cmd_debug_step_prog_handler(), rz_core_analysis_datarefs(), rz_core_analysis_hasrefs_to_depth(), rz_core_arch_bits_at(), rz_core_get_section_name(), rz_core_visual_cmd(), and strings_print().

◆ rz_bin_get_sections()

RZ_DEPRECATE RZ_API RZ_BORROW RzList* rz_bin_get_sections ( RZ_NONNULL RzBin bin)

Definition at line 597 of file bin.c.

597  {
600  return o ? (RzList *)rz_bin_object_get_sections_all(o) : NULL;
601 }
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

References NULL, rz_bin_cur_object(), rz_bin_object_get_sections_all(), and rz_return_val_if_fail.

Referenced by __dumpSections(), __save_old_sections(), cb_iova(), core_objc_new(), rz_bin_bind(), rz_core_analysis_recover_golang_functions(), and rz_main_rizin().

◆ rz_bin_get_size()

RZ_API ut64 rz_bin_get_size ( RzBin bin)

Definition at line 889 of file bin.c.

889  {
892  return o ? o->size : 0;
893 }

References rz_bin_cur_object(), rz_return_val_if_fail, rz_bin_object_t::size, and UT64_MAX.

Referenced by rz_core_bin_info_print(), and rz_core_bin_size_print().

◆ rz_bin_get_strings()

RZ_DEPRECATE RZ_API RZ_BORROW RzList* rz_bin_get_strings ( RZ_NONNULL RzBin bin)

Definition at line 690 of file bin.c.

690  {
693  return o ? (RzList *)rz_bin_object_get_strings(o) : NULL;
694 }
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: bobj.c:798

References NULL, rz_bin_cur_object(), rz_bin_object_get_strings(), and rz_return_val_if_fail.

Referenced by core_bin_strings(), DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), and rz_core_cmd_foreach3().

◆ rz_bin_get_symbols()

RZ_DEPRECATE RZ_API RZ_BORROW RzList* rz_bin_get_symbols ( RZ_NONNULL RzBin bin)

Definition at line 696 of file bin.c.

696  {
699  return o ? (RzList *)rz_bin_object_get_symbols(o) : NULL;
700 }
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_cur_object(), rz_bin_object_get_symbols(), and rz_return_val_if_fail.

Referenced by __core_analysis_fcn(), DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), get_va_symbol(), rabin_dump_symbols(), rz_cmd_debug_dmi(), rz_core_analysis_get_stats(), rz_core_analysis_recover_golang_functions(), rz_core_bin_apply_symbols(), rz_core_cmd_foreach3(), and rz_core_debug_bp_add_noreturn_func().

◆ 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_import_clone()

RZ_API RzBinImport* rz_bin_import_clone ( RzBinImport o)

Definition at line 125 of file bin.c.

125  {
127 
128  RzBinImport *res = rz_mem_dup(o, sizeof(*o));
129  if (res) {
130  res->name = RZ_STR_DUP(o->name);
131  res->classname = RZ_STR_DUP(o->classname);
132  res->descriptor = RZ_STR_DUP(o->descriptor);
133  }
134  return res;
135 }
RZ_API void * rz_mem_dup(const void *s, int l)
Definition: mem.c:319
#define RZ_STR_DUP(x)
Definition: rz_str.h:69
char * descriptor
Definition: rz_bin.h:706
char * name
Definition: rz_bin.h:701
char * classname
Definition: rz_bin.h:705

References rz_bin_import_t::classname, rz_bin_import_t::descriptor, rz_bin_import_t::name, NULL, rz_mem_dup(), rz_return_val_if_fail, and RZ_STR_DUP.

◆ rz_bin_import_free()

RZ_API void rz_bin_import_free ( RzBinImport imp)

◆ rz_bin_info_free()

RZ_API void rz_bin_info_free ( RzBinInfo rb)

Definition at line 97 of file bin.c.

97  {
98  if (!rb) {
99  return;
100  }
101 
103  free(rb->intrp);
104  free(rb->file);
105  free(rb->type);
106  free(rb->bclass);
107  free(rb->rclass);
108  free(rb->arch);
109  free(rb->cpu);
110  free(rb->machine);
111  free(rb->os);
112  free(rb->features);
113  free(rb->subsystem);
114  free(rb->default_cc);
115  free(rb->rpath);
116  free(rb->guid);
117  free(rb->debug_file_name);
118  free(rb->actual_checksum);
119  free(rb->claimed_checksum);
120  free(rb->compiler);
121  free(rb->head_flag);
122  free(rb);
123 }
char * claimed_checksum
Definition: rz_bin.h:237
char * type
Definition: rz_bin.h:211
RzList * file_hashes
Definition: rz_bin.h:226
char * intrp
Definition: rz_bin.h:243
char * default_cc
Definition: rz_bin.h:225
char * os
Definition: rz_bin.h:219
char * head_flag
Definition: rz_bin.h:217
char * subsystem
Definition: rz_bin.h:220
char * machine
Definition: rz_bin.h:216
char * bclass
Definition: rz_bin.h:212
char * guid
Definition: rz_bin.h:222
char * file
Definition: rz_bin.h:210
char * debug_file_name
Definition: rz_bin.h:223
char * features
Definition: rz_bin.h:218
char * rpath
Definition: rz_bin.h:221
char * cpu
Definition: rz_bin.h:215
char * actual_checksum
Definition: rz_bin.h:236
char * rclass
Definition: rz_bin.h:213
char * arch
Definition: rz_bin.h:214
char * compiler
Definition: rz_bin.h:244

References rz_bin_info_t::actual_checksum, rz_bin_info_t::arch, rz_bin_info_t::bclass, rz_bin_info_t::claimed_checksum, rz_bin_info_t::compiler, rz_bin_info_t::cpu, rz_bin_info_t::debug_file_name, rz_bin_info_t::default_cc, rz_bin_info_t::features, rz_bin_info_t::file, rz_bin_info_t::file_hashes, free(), rz_bin_info_t::guid, rz_bin_info_t::head_flag, rz_bin_info_t::intrp, rz_bin_info_t::machine, rz_bin_info_t::os, rz_bin_info_t::rclass, rz_bin_info_t::rpath, rz_list_free(), rz_bin_info_t::subsystem, and rz_bin_info_t::type.

Referenced by load_buffer(), rz_bin_object_free(), and rz_core_bin_load().

◆ rz_bin_is_static()

RZ_DEPRECATE RZ_API int rz_bin_is_static ( RZ_NONNULL RzBin bin)

Definition at line 708 of file bin.c.

708  {
709  rz_return_val_if_fail(bin, false);
711  return o ? rz_bin_object_is_static(o) : false;
712 }
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: bobj.c:883
#define false

References rz_bin_cur_object(), rz_bin_object_is_static(), and rz_return_val_if_fail.

Referenced by rz_core_bin_info_print().

◆ rz_bin_list_plugin()

RZ_API bool rz_bin_list_plugin ( RzBin bin,
const char *  name,
PJ pj,
int  json 
)

Definition at line 510 of file bin.c.

510  {
511  RzListIter *it;
512  RzBinPlugin *bp;
513  RzBinXtrPlugin *bx;
514 
515  rz_return_val_if_fail(bin && name, false);
516 
517  rz_list_foreach (bin->plugins, it, bp) {
518  if (rz_str_cmp(name, bp->name, strlen(name))) {
519  continue;
520  }
521  return rz_bin_print_plugin_details(bin, bp, pj, json);
522  }
523  rz_list_foreach (bin->binxtrs, it, bx) {
524  if (rz_str_cmp(name, bx->name, strlen(name))) {
525  continue;
526  }
527  __printXtrPluginDetails(bin, bx, json);
528  return true;
529  }
530 
531  RZ_LOG_ERROR("Cannot find plugin %s\n", name);
532  return false;
533 }
static void __printXtrPluginDetails(RzBin *bin, RzBinXtrPlugin *bx, int json)
Definition: bin.c:486
static bool rz_bin_print_plugin_details(RzBin *bin, RzBinPlugin *bp, PJ *pj, int json)
Definition: bin.c:461
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
RZ_API int rz_str_cmp(const char *dst, const char *orig, int len)
Definition: str.c:974

References __printXtrPluginDetails(), rz_bin_xtr_plugin_t::name, rz_bin_plugin_t::name, rz_bin_print_plugin_details(), RZ_LOG_ERROR, rz_return_val_if_fail, and rz_str_cmp().

Referenced by __listPlugins().

◆ rz_bin_load_filter()

RZ_API void rz_bin_load_filter ( RzBin bin,
ut64  rules 
)

Definition at line 930 of file bin.c.

930  {
931  bin->filter_rules = rules;
932 }

Referenced by rz_main_rz_bin().

◆ rz_bin_map_free()

RZ_API void rz_bin_map_free ( RzBinMap map)

Definition at line 1023 of file bin.c.

1023  {
1024  if (!map) {
1025  return;
1026  }
1027  free(map->vfile_name);
1028  free(map->name);
1029  free(map);
1030 }

References free(), and map().

Referenced by get_maps_unpatched(), load_buffer(), maps(), and rz_bin_maps_of_file_sections().

◆ rz_bin_maps_of_file_sections()

RZ_API RZ_OWN RzList* rz_bin_maps_of_file_sections ( RZ_NONNULL RzBinFile binfile)

Create a list of RzBinMap from RzBinSections queried from the given file.

Some binary formats have a 1:1 correspondence of mapping and their RzBinSections. This is not always the case (e.g. ELF) but if it is, plugins can use this function as their maps callback, which will generate mappings for sections.

Definition at line 1040 of file bin.c.

1040  {
1041  rz_return_val_if_fail(binfile, NULL);
1042  if (!binfile->o || !binfile->o->plugin || !binfile->o->plugin->sections) {
1043  return NULL;
1044  }
1045  RzList *sections = binfile->o->plugin->sections(binfile);
1046  if (!sections) {
1047  return NULL;
1048  }
1050  if (!r) {
1051  goto hcf;
1052  }
1053  RzBinSection *sec;
1054  RzListIter *it;
1055  rz_list_foreach (sections, it, sec) {
1057  if (!map) {
1058  goto hcf;
1059  }
1060  map->name = sec->name ? strdup(sec->name) : NULL;
1061  map->paddr = sec->paddr;
1062  map->psize = sec->size;
1063  map->vaddr = sec->vaddr;
1064  map->vsize = sec->vsize;
1065  map->perm = sec->perm;
1066  rz_list_push(r, map);
1067  }
1068 hcf:
1070  return r;
1071 }
RZ_API void rz_bin_map_free(RzBinMap *map)
Definition: bin.c:1023
RzList * sections(RzBinFile *bf)
Definition: bin_ne.c:110
#define r
Definition: crypto_rc6.c:12
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
RZ_API RZ_BORROW RzListIter * rz_list_push(RZ_NONNULL RzList *list, void *item)
Alias for rz_list_append.
Definition: list.c:60
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
char * name
Definition: rz_bin.h:619

References map(), rz_bin_section_t::name, NULL, rz_bin_section_t::paddr, rz_bin_section_t::perm, r, rz_bin_map_free(), rz_list_free(), rz_list_newf(), rz_list_push(), RZ_NEW0, rz_return_val_if_fail, sections(), rz_bin_section_t::size, strdup(), rz_bin_section_t::vaddr, and rz_bin_section_t::vsize.

Referenced by maps().

◆ rz_bin_new()

RZ_API RzBin* rz_bin_new ( void  )

Definition at line 716 of file bin.c.

716  {
717  int i;
718  RzBinXtrPlugin *static_xtr_plugin;
719  RzBin *bin = RZ_NEW0(RzBin);
720  if (!bin) {
721  return NULL;
722  }
723  /* demanglers */
724  bin->demangler = rz_demangler_new();
725  if (!bin->demangler) {
726  goto trashbin;
727  }
728  if (!rz_str_constpool_init(&bin->constpool)) {
729  goto trashbin_demangler;
730  }
731  bin->event = rz_event_new(bin);
732  if (!bin->event) {
733  goto trashbin_constpool;
734  }
735  bin->force = NULL;
736  bin->filter_rules = UT64_MAX;
737  bin->sdb = sdb_new0();
738  bin->cb_printf = (PrintfCallback)printf;
740  bin->minstrlen = 0;
741  bin->strpurge = NULL;
742  bin->strenc = NULL;
743  bin->want_dbginfo = true;
744  bin->cur = NULL;
745  bin->hash = rz_hash_new();
746  if (!bin->hash) {
747  goto trashbin_event;
748  }
749 
750  bin->ids = rz_id_storage_new(0, ST32_MAX);
751 
752  /* bin parsers */
754  for (i = 0; i < RZ_ARRAY_SIZE(bin_static_plugins); i++) {
756  }
757  /* extractors */
758  bin->binxtrs = rz_list_new();
759  bin->binxtrs->free = free;
760  for (i = 0; i < RZ_ARRAY_SIZE(bin_xtr_static_plugins); i++) {
761  static_xtr_plugin = RZ_NEW0(RzBinXtrPlugin);
762  if (!static_xtr_plugin) {
763  goto trashbin_binxtrs;
764  }
765  *static_xtr_plugin = *bin_xtr_static_plugins[i];
766  if (!rz_bin_xtr_add(bin, static_xtr_plugin)) {
767  free(static_xtr_plugin);
768  }
769  }
770  return bin;
771 
772 trashbin_binxtrs:
773  rz_list_free(bin->binxtrs);
774  rz_list_free(bin->binfiles);
775  rz_id_storage_free(bin->ids);
776 trashbin_event:
777  rz_event_free(bin->event);
778 trashbin_constpool:
779  rz_str_constpool_fini(&bin->constpool);
780 trashbin_demangler:
781  rz_demangler_free(bin->demangler);
782 trashbin:
783  free(bin);
784  return NULL;
785 }
lzma_index ** i
Definition: index.h:629
RZ_API bool rz_bin_plugin_add(RzBin *bin, RzBinPlugin *foo)
Definition: bin.c:404
static RzBinXtrPlugin * bin_xtr_static_plugins[]
Definition: bin.c:26
static RzBinPlugin * bin_static_plugins[]
Definition: bin.c:25
RZ_API bool rz_bin_xtr_add(RzBin *bin, RzBinXtrPlugin *foo)
Definition: bin.c:421
static void rz_bin_plugin_free(RzBinPlugin *p)
Definition: bin.c:400
RZ_IPI void rz_bin_file_free(void *_bf)
Definition: bfile.c:44
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
RZ_API RzHash * rz_hash_new(void)
Definition: hash.c:585
RZ_API RZ_OWN RzDemangler * rz_demangler_new(void)
Initializes the plugin list and returns a RzDemangler struct.
Definition: demangler.c:81
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
Definition: list.c:235
RZ_API RzEvent * rz_event_new(void *user)
Definition: event.c:17
RZ_API RzIDStorage * rz_id_storage_new(ut32 start_id, ut32 last_id)
Definition: idpool.c:80
RZ_API bool rz_str_constpool_init(RzStrConstPool *pool)
Definition: str_constpool.c:10
int(* PrintfCallback)(const char *str,...) RZ_PRINTF_CHECK(1
Definition: rz_types.h:233
#define RZ_ARRAY_SIZE(x)
Definition: rz_types.h:300
#define ST32_MAX
Definition: rz_types_base.h:97
RZ_API Sdb * sdb_new0(void)
Definition: sdb.c:43

References bin_static_plugins, bin_xtr_static_plugins, free(), i, NULL, printf(), RZ_ARRAY_SIZE, rz_bin_file_free(), rz_bin_plugin_add(), rz_bin_plugin_free(), rz_bin_xtr_add(), rz_demangler_free(), rz_demangler_new(), rz_event_free(), rz_event_new(), rz_hash_new(), rz_id_storage_free(), rz_id_storage_new(), rz_list_free(), rz_list_new(), rz_list_newf(), RZ_NEW0, rz_str_constpool_fini(), rz_str_constpool_init(), sdb_new0(), ST32_MAX, and UT64_MAX.

Referenced by create(), download_pdb(), rz_core_init(), rz_diff_file_open(), and rzfind_open_file().

◆ rz_bin_object_get_map_at()

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 .

This function returns the last binary map that contains offset off, because it assumes that maps are sorted by priority, thus the last one will be the most important one.

Parameters
oReference to the RzBinObject instance
offAddress to search
vaWhen false the offset off is considered a physical address, otherwise a virtual address
Returns
Pointer to a RzBinMap containing the address

Definition at line 643 of file bin.c.

643  {
645 
646  RzBinMap *map;
647  RzListIter *iter;
648  ut64 from, to;
649 
650  rz_list_foreach_prev(o->maps, iter, map) {
651  from = va ? rz_bin_object_addr_with_base(o, map->vaddr) : map->paddr;
652  to = from + (va ? map->vsize : map->psize);
653  if (off >= from && off < to) {
654  return map;
655  }
656  }
657  return NULL;
658 }

References from, map(), NULL, off, rz_bin_object_addr_with_base(), rz_return_val_if_fail, to, and ut64().

Referenced by rz_bin_file_at(), rz_bin_object_p2v(), and rz_bin_object_v2p().

◆ rz_bin_object_get_maps_at()

RZ_API RZ_OWN RzPVector* rz_bin_object_get_maps_at ( RzBinObject o,
ut64  off,
bool  va 
)

Find all binary maps at offset off .

Parameters
oReference to the RzBinObject instance
offAddress to search
vaWhen false the offset off is considered a physical address, otherwise a virtual address
Returns
Vector of RzBinMap pointers

Definition at line 668 of file bin.c.

668  {
670 
671  RzBinMap *map;
672  RzListIter *iter;
673  ut64 from, to;
674 
675  RzPVector *res = rz_pvector_new(NULL);
676  if (!res) {
677  return NULL;
678  }
679 
680  rz_list_foreach (o->maps, iter, map) {
681  from = va ? rz_bin_object_addr_with_base(o, map->vaddr) : map->paddr;
682  to = from + (va ? map->vsize : map->psize);
683  if (off >= from && off < to) {
684  rz_pvector_push(res, map);
685  }
686  }
687  return res;
688 }
RZ_API RzPVector * rz_pvector_new(RzPVectorFree free)
Definition: vector.c:302
static void ** rz_pvector_push(RzPVector *vec, void *x)
Definition: rz_vector.h:300
RzList * maps
Definition: rz_bin.h:266

References from, map(), rz_bin_object_t::maps, NULL, off, rz_bin_object_addr_with_base(), rz_pvector_new(), rz_pvector_push(), rz_return_val_if_fail, to, and ut64().

Referenced by rz_bin_object_p2v_all().

◆ rz_bin_open()

RZ_API RzBinFile* rz_bin_open ( RzBin bin,
const char *  file,
RzBinOptions *  opt 
)

Definition at line 200 of file bin.c.

200  {
201  rz_return_val_if_fail(bin && bin->iob.io && opt, NULL);
202 
203  RzIOBind *iob = &(bin->iob);
204  if (!iob->desc_get(iob->io, opt->fd)) {
205  opt->fd = iob->fd_open(iob->io, file, RZ_PERM_R, 0644);
206  }
207  if (opt->fd < 0) {
208  RZ_LOG_ERROR("Couldn't open bin for file '%s'\n", file);
209  return NULL;
210  }
211  opt->sz = 0;
212  opt->pluginname = NULL;
213  return rz_bin_open_io(bin, opt);
214 }
RZ_API RzBinFile * rz_bin_open_io(RzBin *bin, RzBinOptions *opt)
Definition: bin.c:283
#define RZ_PERM_R
Definition: rz_types.h:93
Definition: gzappend.c:170
RzIOFdOpen fd_open
Definition: rz_io.h:243
RzIO * io
Definition: rz_io.h:232
RzIODescGet desc_get
Definition: rz_io.h:235

References rz_io_bind_t::desc_get, rz_io_bind_t::fd_open, rz_io_bind_t::io, NULL, rz_bin_open_io(), RZ_LOG_ERROR, RZ_PERM_R, and rz_return_val_if_fail.

Referenced by core_file_do_load_for_debug(), download_pdb(), get_va_symbol(), rz_core_bin_load_structs(), rz_debug_dmp_frames(), rz_main_rz_bin(), and rzfind_open_file().

◆ rz_bin_open_buf()

RZ_API RzBinFile* rz_bin_open_buf ( RzBin bin,
RzBuffer buf,
RzBinOptions *  opt 
)

Definition at line 238 of file bin.c.

238  {
239  rz_return_val_if_fail(bin && opt, NULL);
240 
241  RzListIter *it;
242  RzBinXtrPlugin *xtr;
243 
244  bin->file = opt->filename;
245  if (opt->obj_opts.loadaddr == UT64_MAX) {
246  opt->obj_opts.loadaddr = 0;
247  }
248 
249  RzBinFile *bf = NULL;
250  if (bin->use_xtr && !opt->pluginname) {
251  // XXX - for the time being this is fine, but we may want to
252  // change the name to something like
253  // <xtr_name>:<bin_type_name>
254  rz_list_foreach (bin->binxtrs, it, xtr) {
255  if (!xtr->check_buffer) {
256  RZ_LOG_ERROR("Missing check_buffer callback for '%s'\n", xtr->name);
257  continue;
258  }
259  if (xtr->check_buffer(buf)) {
260  if (xtr->extract_from_buffer || xtr->extractall_from_buffer ||
263  bin->file, buf, &opt->obj_opts,
264  opt->xtr_idx, opt->fd);
265  }
266  }
267  }
268  }
269  if (!bf) {
270  // Uncomment for this speedup: 20s vs 22s
271  // RzBuffer *buf = rz_buf_new_slurp (bin->file);
272  bf = rz_bin_file_new_from_buffer(bin, bin->file, buf,
273  &opt->obj_opts, opt->fd, opt->pluginname);
274  if (!bf) {
275  return NULL;
276  }
277  }
279  rz_id_storage_set(bin->ids, bin->cur, bf->id);
280  return bf;
281 }
RZ_API bool rz_bin_file_set_cur_binfile(RzBin *bin, RzBinFile *bf)
Definition: bfile.c:288
RZ_IPI RzBinFile * rz_bin_file_new_from_buffer(RzBin *bin, const char *file, RzBuffer *buf, RzBinObjectLoadOptions *opts, int fd, const char *pluginname)
Definition: bfile.c:139
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: bfile.c:299
RZ_API bool rz_id_storage_set(RzIDStorage *storage, void *data, ut32 id)
Definition: idpool.c:131
int fd
Definition: gzjoin.c:80
bool(* check_buffer)(RzBuffer *b)
Definition: rz_bin.h:398
RzBinXtrData *(* extract_from_bytes)(RzBin *bin, const ut8 *buf, ut64 size, int idx)
Definition: rz_bin.h:400
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
RzBinXtrData *(* extract_from_buffer)(RzBin *bin, RzBuffer *buf, int idx)
Definition: rz_bin.h:401

References rz_bin_xtr_plugin_t::check_buffer, rz_bin_xtr_plugin_t::extract_from_buffer, rz_bin_xtr_plugin_t::extract_from_bytes, rz_bin_xtr_plugin_t::extractall_from_buffer, rz_bin_xtr_plugin_t::extractall_from_bytes, bin::fd, rz_bin_file_t::id, rz_bin_xtr_plugin_t::name, NULL, rz_bin_file_new_from_buffer(), rz_bin_file_set_cur_binfile(), rz_bin_file_xtr_load_buffer(), rz_id_storage_set(), RZ_LOG_ERROR, rz_return_val_if_fail, and UT64_MAX.

Referenced by rz_bin_open_io(), and rz_bin_reload().

◆ rz_bin_open_io()

RZ_API RzBinFile* rz_bin_open_io ( RzBin bin,
RzBinOptions *  opt 
)

Definition at line 283 of file bin.c.

283  {
284  rz_return_val_if_fail(bin && opt && bin->iob.io, NULL);
285  rz_return_val_if_fail(opt->fd >= 0 && (st64)opt->sz >= 0, NULL);
286 
287  RzIOBind *iob = &(bin->iob);
288  RzIO *io = iob ? iob->io : NULL;
289 
290  bool is_debugger = iob->fd_is_dbg(io, opt->fd);
291  const char *fname = iob->fd_get_name(io, opt->fd);
292  if (opt->obj_opts.loadaddr == UT64_MAX) {
293  opt->obj_opts.loadaddr = 0;
294  }
295 
296  // Create RzBuffer from the opened file
297  // When debugging something, we want to open the backed file because
298  // not all binary info are mapped in the virtual space. If that is not
299  // possible (e.g. remote file) just try to load bin info from the
300  // debugee process.
301  RzBuffer *buf = NULL;
302  if (is_debugger) {
304  is_debugger = false;
305  }
306  if (!buf) {
307  buf = rz_buf_new_with_io_fd(&bin->iob, opt->fd);
308  }
309  if (!buf) {
310  return NULL;
311  }
312 
313  if (!opt->sz) {
314  opt->sz = rz_buf_size(buf);
315  }
316 
317  // Slice buffer if necessary
318  RzBuffer *slice = buf;
319  if (!is_debugger && (opt->obj_opts.loadaddr != 0 || opt->sz != rz_buf_size(buf))) {
320  slice = rz_buf_new_slice(buf, opt->obj_opts.loadaddr, opt->sz);
321  } else if (is_debugger && opt->obj_opts.baseaddr != UT64_MAX && opt->obj_opts.baseaddr != 0) {
322  slice = rz_buf_new_slice(buf, opt->obj_opts.baseaddr, opt->sz);
323  }
324  if (slice != buf) {
325  rz_buf_free(buf);
326  buf = slice;
327  }
328 
329  opt->filename = fname;
330  RzBinFile *bf = rz_bin_open_buf(bin, buf, opt);
331  rz_buf_free(buf);
332  return bf;
333 }
RZ_API RzBinFile * rz_bin_open_buf(RzBin *bin, RzBuffer *buf, RzBinOptions *opt)
Definition: bin.c:238
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 RZ_OWN RzBuffer * rz_buf_new_slice(RzBuffer *b, ut64 offset, ut64 size)
Creates a new buffer from a slice of another buffer.
Definition: buf.c:364
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
Definition: buf.c:1225
RZ_API RZ_OWN RzBuffer * rz_buf_new_file(const char *file, int perm, int mode)
Creates a new buffer from a file.
Definition: buf.c:317
#define st64
Definition: rz_types_base.h:10
#define O_RDONLY
Definition: sftypes.h:486
RzIOFdIsDbg fd_is_dbg
Definition: rz_io.h:252
RzIOFdGetName fd_get_name
Definition: rz_io.h:253
Definition: rz_io.h:59

References bin::fd, rz_io_bind_t::fd_get_name, rz_io_bind_t::fd_is_dbg, create_tags_rz::fname, rz_io_bind_t::io, NULL, O_RDONLY, rz_bin_open_buf(), rz_buf_free(), rz_buf_new_file(), rz_buf_new_slice(), rz_buf_new_with_io_fd(), rz_buf_size(), rz_return_val_if_fail, st64, and UT64_MAX.

Referenced by cmd_search_bin(), core_file_do_load_for_io_plugin(), get_bin_info(), GetHeapGlobalsOffset(), map_multi_dex(), rz_bin_open(), rz_diff_file_open(), rz_main_rizin(), rz_open_binary_add_handler(), and rz_open_binary_file_handler().

◆ rz_bin_options_init()

RZ_API void rz_bin_options_init ( RzBinOptions *  opt,
int  fd,
ut64  baseaddr,
ut64  loadaddr,
bool  patch_relocs 
)

Definition at line 75 of file bin.c.

75  {
76  memset(opt, 0, sizeof(*opt));
77  opt->obj_opts.baseaddr = baseaddr;
78  opt->obj_opts.loadaddr = loadaddr;
79  opt->obj_opts.patch_relocs = patch_relocs;
80  opt->obj_opts.elf_load_sections = true;
81  opt->fd = fd;
82 }
return memset(p, 0, total)
RZ_API void MACH0_() patch_relocs(RzBinFile *bf, struct MACH0_(obj_t) *obj)
Patching of external relocs in a sparse overlay buffer.
Definition: mach0_relocs.c:614
static const z80_opcode fd[]
Definition: z80_tab.h:997
static int baseaddr
Definition: z80asm.c:79

References baseaddr, fd, memset(), and patch_relocs().

Referenced by core_file_do_load_for_debug(), get_va_symbol(), rz_bin_reload(), rz_core_bin_options_init(), rz_diff_file_open(), rz_main_rz_bin(), and rzfind_open_file().

◆ rz_bin_plugin_add()

RZ_API bool rz_bin_plugin_add ( RzBin bin,
RzBinPlugin foo 
)

Definition at line 404 of file bin.c.

404  {
405  RzListIter *it;
406  RzBinPlugin *plugin;
407 
408  rz_return_val_if_fail(bin && foo, false);
409 
410  rz_list_foreach (bin->plugins, it, plugin) {
411  if (!strcmp(plugin->name, foo->name)) {
412  return false;
413  }
414  }
415  plugin = RZ_NEW0(RzBinPlugin);
416  memcpy(plugin, foo, sizeof(RzBinPlugin));
417  rz_list_append(bin->plugins, plugin);
418  return true;
419 }
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static RzMain foo[]
Definition: main.c:11
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
const char * name
Definition: rz_main.h:17

References foo, memcpy(), rz_bin_plugin_t::name, rz_main_t::name, rz_list_append(), RZ_NEW0, and rz_return_val_if_fail.

Referenced by __lib_bin_cb(), and rz_bin_new().

◆ rz_bin_plugin_free()

static void rz_bin_plugin_free ( RzBinPlugin p)
static

Definition at line 400 of file bin.c.

400  {
401  RZ_FREE(p);
402 }

References p, and RZ_FREE.

Referenced by rz_bin_new().

◆ rz_bin_plugin_get()

RZ_API const RzBinPlugin* rz_bin_plugin_get ( RZ_NONNULL RzBin bin,
RZ_NONNULL const char *  name 
)

Get a RzBinPlugin by name.

Definition at line 1197 of file bin.c.

1197  {
1199 
1200  RzListIter *iter;
1201  RzBinPlugin *bp;
1202 
1203  rz_list_foreach (bin->plugins, iter, bp) {
1204  if (!strcmp(bp->name, name)) {
1205  return bp;
1206  }
1207  }
1208  return NULL;
1209 }

References rz_bin_plugin_t::name, NULL, and rz_return_val_if_fail.

Referenced by rz_cmd_info_plugins_handler().

◆ rz_bin_print_plugin_details()

static bool rz_bin_print_plugin_details ( RzBin bin,
RzBinPlugin bp,
PJ pj,
int  json 
)
static

Definition at line 461 of file bin.c.

461  {
462  if (json == 'q') {
463  bin->cb_printf("%s\n", bp->name);
464  } else if (json) {
465  pj_o(pj);
466  pj_ks(pj, "name", bp->name);
467  pj_ks(pj, "description", bp->desc);
468  pj_ks(pj, "license", bp->license ? bp->license : "???");
469  pj_end(pj);
470  } else {
471  bin->cb_printf("Name: %s\n", bp->name);
472  bin->cb_printf("Description: %s\n", bp->desc);
473  if (bp->license) {
474  bin->cb_printf("License: %s\n", bp->license);
475  }
476  if (bp->version) {
477  bin->cb_printf("Version: %s\n", bp->version);
478  }
479  if (bp->author) {
480  bin->cb_printf("Author: %s\n", bp->author);
481  }
482  }
483  return true;
484 }
char * desc
Definition: rz_bin.h:510
char * license
Definition: rz_bin.h:513
char * version
Definition: rz_bin.h:512
char * author
Definition: rz_bin.h:511

References rz_bin_plugin_t::author, rz_bin_plugin_t::desc, rz_bin_plugin_t::license, rz_bin_plugin_t::name, pj_end(), pj_ks(), pj_o(), and rz_bin_plugin_t::version.

Referenced by rz_bin_list_plugin().

◆ rz_bin_reload()

RZ_API RzBinFile* rz_bin_reload ( RzBin bin,
RzBinFile bf,
ut64  baseaddr 
)

Definition at line 216 of file bin.c.

216  {
218 
219  bool big_endian = bf->o ? bf->o->opts.big_endian : false;
220  bool patch_relocs = bf->o ? bf->o->opts.patch_relocs : false;
221  bool elf_load_sections = bf->o ? bf->o->opts.elf_load_sections : false;
222  bool elf_checks_sections = bf->o ? bf->o->opts.elf_checks_sections : false;
223  bool elf_checks_segments = bf->o ? bf->o->opts.elf_checks_segments : false;
224 
225  RzBinOptions opt;
227  opt.obj_opts.elf_load_sections = elf_load_sections;
228  opt.obj_opts.elf_checks_sections = elf_checks_sections;
229  opt.obj_opts.elf_checks_segments = elf_checks_segments;
230  opt.obj_opts.big_endian = big_endian;
231  opt.filename = bf->file;
232  rz_buf_seek(bf->buf, 0, RZ_BUF_SET);
233  RzBinFile *nbf = rz_bin_open_buf(bin, bf->buf, &opt);
234  rz_bin_file_delete(bin, bf);
235  return nbf;
236 }
RZ_API bool rz_bin_file_delete(RzBin *bin, RzBinFile *bf)
Definition: bfile.c:213
RZ_API void rz_bin_options_init(RzBinOptions *opt, int fd, ut64 baseaddr, ut64 loadaddr, bool patch_relocs)
Definition: bin.c:75
RZ_API st64 rz_buf_seek(RZ_NONNULL RzBuffer *b, st64 addr, int whence)
Modify the current cursor position in the buffer.
Definition: buf.c:1166
#define RZ_BUF_SET
Definition: rz_buf.h:14
bool elf_checks_sections
ELF specific, checks or not ELF sections.
Definition: rz_bin.h:253
bool patch_relocs
ask the bin plugin to fill relocs with valid contents for analysis
Definition: rz_bin.h:250
bool elf_load_sections
ELF specific, load or not ELF sections.
Definition: rz_bin.h:252
bool elf_checks_segments
ELF specific, checks or not ELF sections.
Definition: rz_bin.h:254
bool big_endian
only used for binary formats that do not specify the endian in the file, but need it to load,...
Definition: rz_bin.h:251
ut64 loadaddr
Definition: rz_bin.h:307
int fd
when used in combination with RzIO, this refers to the io fd.
Definition: rz_bin.h:300

References baseaddr, rz_bin_file_load_options_t::big_endian, rz_bin_file_t::buf, rz_bin_file_load_options_t::elf_checks_sections, rz_bin_file_load_options_t::elf_checks_segments, rz_bin_file_load_options_t::elf_load_sections, rz_bin_file_t::fd, rz_bin_file_t::file, rz_bin_file_t::loadaddr, NULL, rz_bin_file_t::o, rz_bin_object_t::opts, patch_relocs(), rz_bin_file_load_options_t::patch_relocs, rz_bin_file_delete(), rz_bin_open_buf(), rz_bin_options_init(), rz_buf_seek(), RZ_BUF_SET, and rz_return_val_if_fail.

Referenced by core_bin_reload().

◆ rz_bin_reloc_free()

RZ_API void rz_bin_reloc_free ( RzBinReloc reloc)

Definition at line 188 of file bin.c.

188  {
189  free(reloc);
190 }

References free().

Referenced by rz_bin_le_get_relocs(), and rz_bin_reloc_storage_free().

◆ rz_bin_resource_free()

RZ_API void rz_bin_resource_free ( RzBinResource res)

Definition at line 147 of file bin.c.

147  {
148  if (!res) {
149  return;
150  }
151  RZ_FREE(res->name);
152  RZ_FREE(res->time);
153  RZ_FREE(res->type);
154  RZ_FREE(res->language);
155  free(res);
156 }
char * language
Definition: rz_bin.h:794

References free(), rz_bin_resource_t::language, rz_bin_resource_t::name, RZ_FREE, rz_bin_resource_t::time, and rz_bin_resource_t::type.

◆ rz_bin_section_flag_to_list()

RZ_API RZ_OWN RzList* rz_bin_section_flag_to_list ( RzBin bin,
ut64  flag 
)

Converts the RzBinSection flags to a list of string representations.

Some binary formats have a function interface called "section_flag_to_rzlist" The returned string flag names are different between formats

Parameters
binRzBin instance
flagA flag field of the RzBinSection (differs between formats)

Definition at line 1151 of file bin.c.

1151  {
1152  RzBinFile *a = rz_bin_cur(bin);
1154  if (plugin && plugin->section_flag_to_rzlist) {
1155  return plugin->section_flag_to_rzlist(flag);
1156  }
1157  return NULL;
1158 }
RzList *(* section_flag_to_rzlist)(ut64 flag)
Definition: rz_bin.h:550

References a, NULL, rz_bin_cur(), rz_bin_file_cur_plugin(), and rz_bin_plugin_t::section_flag_to_rzlist.

Referenced by sections_print_json(), and sections_print_table().

◆ rz_bin_section_free()

RZ_API void rz_bin_section_free ( RzBinSection bs)

Definition at line 1116 of file bin.c.

1116  {
1117  if (bs) {
1118  free(bs->name);
1119  free(bs->format);
1120  free(bs);
1121  }
1122 }
char * format
Definition: rz_bin.h:630

References rz_bin_section_t::format, free(), and rz_bin_section_t::name.

Referenced by get_segments(), load_buffer(), rz_bin_dex_sections(), rz_bin_le_get_sections(), rz_bin_mz_get_segments(), rz_bin_ne_get_segments(), rz_bin_sections_of_maps(), section_free(), and sections().

◆ rz_bin_section_new()

RZ_API RzBinSection* rz_bin_section_new ( const char *  name)

Definition at line 1108 of file bin.c.

1108  {
1110  if (s) {
1111  s->name = name ? strdup(name) : NULL;
1112  }
1113  return s;
1114 }
static RzSocket * s
Definition: rtr.c:28

References NULL, RZ_NEW0, s, and strdup().

Referenced by get_segments().

◆ rz_bin_section_type_to_string()

RZ_API RZ_OWN char* rz_bin_section_type_to_string ( RzBin bin,
int  type 
)

Converts the RzBinSection type to the string representation.

Some binary formats have a function interface called "section_type_to_string" The returned string type name is different between formats

Parameters
binRzBin instance
typeA type field of the RzBinSection (differs between formats)

Definition at line 1133 of file bin.c.

1133  {
1134  RzBinFile *a = rz_bin_cur(bin);
1136  if (plugin && plugin->section_type_to_string) {
1137  return plugin->section_type_to_string(type);
1138  }
1139  return NULL;
1140 }
char *(* section_type_to_string)(ut64 type)
Definition: rz_bin.h:549

References a, NULL, rz_bin_cur(), rz_bin_file_cur_plugin(), rz_bin_plugin_t::section_type_to_string, and type.

Referenced by sections_print_json(), and sections_print_table().

◆ rz_bin_sections_of_maps()

RZ_API RzList* rz_bin_sections_of_maps ( RzList maps)

Create a list of RzBinSection from RzBinMaps.

Some binary formats have a 1:1 correspondence of mapping and some of their RzBinSections, but also want to add some unmapped sections. In this case, they can implement their mapped sections in their maps callback, then in their sections callback use this function to create sections from them and add some additional ones. See also rz_bin_maps_of_file_sections() for the inverse, when no additional sections should be added.

Definition at line 1084 of file bin.c.

1084  {
1087  if (!ret) {
1088  return NULL;
1089  }
1090  RzListIter *it;
1091  RzBinMap *map;
1092  rz_list_foreach (maps, it, map) {
1094  if (!sec) {
1095  break;
1096  }
1097  sec->name = map->name ? strdup(map->name) : NULL;
1098  sec->paddr = map->paddr;
1099  sec->size = map->psize;
1100  sec->vaddr = map->vaddr;
1101  sec->vsize = map->vsize;
1102  sec->perm = map->perm;
1103  rz_list_append(ret, sec);
1104  }
1105  return ret;
1106 }
RZ_API void rz_bin_section_free(RzBinSection *bs)
Definition: bin.c:1116
static RzList * maps(RzBinFile *bf)
Definition: bin_bf.c:116

References map(), maps(), rz_bin_section_t::name, NULL, rz_bin_section_t::paddr, rz_bin_section_t::perm, rz_bin_section_free(), rz_list_append(), rz_list_newf(), RZ_NEW0, rz_return_val_if_fail, rz_bin_section_t::size, strdup(), rz_bin_section_t::vaddr, and rz_bin_section_t::vsize.

Referenced by sections().

◆ rz_bin_select()

RZ_API bool rz_bin_select ( RzBin bin,
const char *  arch,
int  bits,
const char *  name 
)

Definition at line 813 of file bin.c.

813  {
814  rz_return_val_if_fail(bin, false);
815 
816  RzBinFile *cur = rz_bin_cur(bin);
817  RzBinObject *obj = NULL;
818  name = !name && cur ? cur->file : name;
820  if (binfile && name) {
821  obj = rz_bin_object_find_by_arch_bits(binfile, arch, bits, name);
822  }
823  return rz_bin_file_set_obj(bin, binfile, obj);
824 }
RZ_IPI bool rz_bin_file_set_obj(RzBin *bin, RzBinFile *bf, RzBinObject *obj)
Definition: bfile.c:263
RZ_API RzBinFile * rz_bin_file_find_by_arch_bits(RzBin *bin, const char *arch, int bits)
Definition: bfile.c:163
RZ_IPI RzBinObject * rz_bin_object_find_by_arch_bits(RzBinFile *bf, const char *arch, int bits, const char *name)
Definition: bobj.c:644

References arch, bits(), rz_bin_file_t::file, name, NULL, rz_bin_cur(), rz_bin_file_find_by_arch_bits(), rz_bin_file_set_obj(), rz_bin_object_find_by_arch_bits(), and rz_return_val_if_fail.

Referenced by rz_main_rz_bin().

◆ rz_bin_select_bfid()

RZ_API bool rz_bin_select_bfid ( RzBin bin,
ut32  bf_id 
)

Definition at line 833 of file bin.c.

833  {
834  rz_return_val_if_fail(bin, false);
835  RzBinFile *bf = rz_bin_file_find_by_id(bin, bf_id);
836  return bf ? rz_bin_file_set_obj(bin, bf, NULL) : false;
837 }
RZ_API RzBinFile * rz_bin_file_find_by_id(RzBin *bin, ut32 bf_id)
Definition: bfile.c:188

References NULL, rz_bin_file_find_by_id(), rz_bin_file_set_obj(), and rz_return_val_if_fail.

Referenced by rz_core_bin_raise(), and rz_core_seek().

◆ rz_bin_select_object()

RZ_API int rz_bin_select_object ( RzBinFile binfile,
const char *  arch,
int  bits,
const char *  name 
)

Definition at line 826 of file bin.c.

826  {
827  rz_return_val_if_fail(binfile, false);
829  return rz_bin_file_set_obj(binfile->rbin, binfile, obj);
830 }

References arch, bits(), rz_bin_file_t::rbin, rz_bin_file_set_obj(), rz_bin_object_find_by_arch_bits(), and rz_return_val_if_fail.

◆ rz_bin_set_baddr()

RZ_API void rz_bin_set_baddr ( RzBin bin,
ut64  baddr 
)

Definition at line 549 of file bin.c.

549  {
551  RzBinFile *bf = rz_bin_cur(bin);
553  if (!o || !o->plugin || !o->plugin->baddr) {
554  return;
555  }
556  ut64 file_baddr = o->plugin->baddr(bf);
557  if (baddr == UT64_MAX) {
558  o->opts.baseaddr = file_baddr;
559  o->baddr_shift = 0; // o->baddr; // - file_baddr;
560  } else if (file_baddr != UT64_MAX) {
561  o->opts.baseaddr = baddr;
562  o->baddr_shift = baddr - file_baddr;
563  }
564 }
static ut64 baddr(RzBinFile *bf)
Definition: bin_any.c:58
struct rz_bin_plugin_t * plugin
Definition: rz_bin.h:289
st64 baddr_shift
Definition: rz_bin.h:261
ut64(* baddr)(RzBinFile *bf)
Definition: rz_bin.h:521

References baddr(), rz_bin_plugin_t::baddr, rz_bin_object_t::baddr_shift, rz_bin_file_load_options_t::baseaddr, rz_bin_object_t::opts, rz_bin_object_t::plugin, rz_bin_cur(), rz_bin_cur_object(), rz_return_if_fail, ut64(), and UT64_MAX.

Referenced by rebase_helper(), rz_bin_object_new(), rz_cmd_debug_dmi(), and rz_main_rz_bin().

◆ rz_bin_set_user_ptr()

RZ_API void rz_bin_set_user_ptr ( RzBin bin,
void *  user 
)

Definition at line 839 of file bin.c.

839  {
840  bin->user = user;
841 }

Referenced by rz_core_init().

◆ rz_bin_string_free()

RZ_API void rz_bin_string_free ( void *  _str)

◆ rz_bin_symbol_free()

◆ rz_bin_symbol_name()

RZ_API const char* rz_bin_symbol_name ( RzBinSymbol s)

Definition at line 158 of file bin.c.

158  {
159  if (s->dup_count) {
160  return sdb_fmt("%s_%d", s->name, s->dup_count);
161  }
162  return s->name;
163 }
RZ_API char * sdb_fmt(const char *fmt,...)
Definition: fmt.c:26

References s, and sdb_fmt().

Referenced by rz_core_sym_name_init().

◆ rz_bin_symbol_new()

RZ_API RzBinSymbol* rz_bin_symbol_new ( const char *  name,
ut64  paddr,
ut64  vaddr 
)

Definition at line 165 of file bin.c.

165  {
167  if (sym) {
168  sym->name = name ? strdup(name) : NULL;
169  sym->paddr = paddr;
170  sym->vaddr = vaddr;
171  }
172  return sym;
173 }

References rz_bin_symbol_t::name, NULL, rz_bin_symbol_t::paddr, RZ_NEW0, strdup(), and rz_bin_symbol_t::vaddr.

Referenced by add_new_func_symbol(), rz_bin_java_class_const_pool_as_symbols(), rz_bin_java_class_fields_as_symbols(), and rz_bin_java_class_methods_as_symbols().

◆ rz_bin_trycatch_free()

RZ_API void rz_bin_trycatch_free ( RzBinTrycatch tc)

Definition at line 1190 of file bin.c.

1190  {
1191  free(tc);
1192 }

References free().

Referenced by trycatch().

◆ rz_bin_trycatch_new()

RZ_API RzBinTrycatch* rz_bin_trycatch_new ( ut64  source,
ut64  from,
ut64  to,
ut64  handler,
ut64  filter 
)

Definition at line 1178 of file bin.c.

1178  {
1180  if (tc) {
1181  tc->source = source;
1182  tc->from = from;
1183  tc->to = to;
1184  tc->handler = handler;
1185  tc->filter = filter;
1186  }
1187  return tc;
1188 }
const char * source
Definition: lz4.h:699
static bool filter(RzParse *p, ut64 addr, RzFlag *f, RzAnalysisHint *hint, char *data, char *str, int len, bool big_endian)
Definition: filter.c:185

References rz_bin_trycatch_t::filter, filter(), rz_bin_trycatch_t::from, from, rz_bin_trycatch_t::handler, RZ_NEW0, rz_bin_trycatch_t::source, source, rz_bin_trycatch_t::to, and to.

Referenced by trycatch().

◆ rz_bin_use_arch()

RZ_API bool rz_bin_use_arch ( RzBin bin,
const char *  arch,
int  bits,
const char *  name 
)

Definition at line 787 of file bin.c.

787  {
788  rz_return_val_if_fail(bin && arch, false);
789 
791  if (!binfile) {
792  RZ_LOG_WARN("Cannot find binfile with arch/bits %s/%d\n", arch, bits);
793  return false;
794  }
795 
797  if (!obj && binfile->xtr_data) {
798  RzBinXtrData *xtr_data = rz_list_get_n(binfile->xtr_data, 0);
799  if (xtr_data && !xtr_data->loaded) {
800  RzBinObjectLoadOptions obj_opts = {
801  .baseaddr = UT64_MAX,
802  .loadaddr = rz_bin_get_laddr(bin)
803  };
804  if (!rz_bin_file_object_new_from_xtr_data(bin, binfile, &obj_opts, xtr_data)) {
805  return false;
806  }
807  }
808  obj = binfile->o;
809  }
810  return rz_bin_file_set_obj(bin, binfile, obj);
811 }
RZ_API bool rz_bin_file_object_new_from_xtr_data(RzBin *bin, RzBinFile *bf, RzBinObjectLoadOptions *opts, RzBinXtrData *data)
Definition: bfile.c:94
RZ_API ut64 rz_bin_get_laddr(RzBin *bin)
Definition: bin.c:542
RZ_API RZ_BORROW void * rz_list_get_n(RZ_NONNULL const RzList *list, ut32 n)
Returns the N-th element of the list.
Definition: list.c:574

References arch, rz_bin_file_load_options_t::baseaddr, bits(), rz_bin_xtr_extract_t::loaded, rz_bin_file_t::o, rz_bin_file_find_by_arch_bits(), rz_bin_file_object_new_from_xtr_data(), rz_bin_file_set_obj(), rz_bin_get_laddr(), rz_bin_object_find_by_arch_bits(), rz_list_get_n(), RZ_LOG_WARN, rz_return_val_if_fail, UT64_MAX, and rz_bin_file_t::xtr_data.

Referenced by rz_core_bin_set_arch_bits().

◆ rz_bin_virtual_file_free()

RZ_API void rz_bin_virtual_file_free ( RzBinVirtualFile vfile)

Definition at line 1012 of file bin.c.

1012  {
1013  if (!vfile) {
1014  return;
1015  }
1016  if (vfile->buf_owned) {
1017  rz_buf_free(vfile->buf);
1018  }
1019  free(vfile->name);
1020  free(vfile);
1021 }
RZ_NONNULL RzBuffer * buf
Definition: rz_bin.h:597
bool buf_owned
whether buf is owned and freed by this RzBinVirtualFile
Definition: rz_bin.h:598
RZ_OWN RZ_NONNULL char * name
Definition: rz_bin.h:596

References rz_bin_virtual_file_t::buf, rz_bin_virtual_file_t::buf_owned, free(), rz_bin_virtual_file_t::name, and rz_buf_free().

Referenced by get_virtual_files(), and virtual_files().

◆ rz_bin_xtr_add()

RZ_API bool rz_bin_xtr_add ( RzBin bin,
RzBinXtrPlugin foo 
)

Definition at line 421 of file bin.c.

421  {
422  RzListIter *it;
423  RzBinXtrPlugin *xtr;
424 
425  rz_return_val_if_fail(bin && foo, false);
426 
427  if (foo->init) {
428  foo->init(bin->user);
429  }
430  // avoid duplicates
431  rz_list_foreach (bin->binxtrs, it, xtr) {
432  if (!strcmp(xtr->name, foo->name)) {
433  return false;
434  }
435  }
436  rz_list_append(bin->binxtrs, foo);
437  return true;
438 }

References foo, rz_bin_xtr_plugin_t::name, rz_main_t::name, rz_list_append(), and rz_return_val_if_fail.

Referenced by __lib_bin_xtr_cb(), and rz_bin_new().

◆ rz_bin_xtrdata_free()

RZ_API void rz_bin_xtrdata_free ( void *  data_)

Definition at line 61 of file bin.c.

61  {
62  RzBinXtrData *data = data_;
63  rz_return_if_fail(data);
64  if (data->metadata) {
65  free(data->metadata->libname);
66  free(data->metadata->arch);
67  free(data->metadata->machine);
68  free(data->metadata);
69  }
70  free(data->file);
71  rz_buf_free(data->buf);
72  free(data);
73 }
RzBuffer * buf
Definition: rz_bin.h:380
RzBinXtrMetadata * metadata
Definition: rz_bin.h:386

References rz_bin_xtr_metadata_t::arch, rz_bin_xtr_extract_t::buf, rz_bin_xtr_extract_t::file, free(), rz_bin_xtr_metadata_t::libname, rz_bin_xtr_metadata_t::machine, rz_bin_xtr_extract_t::metadata, rz_buf_free(), and rz_return_if_fail.

Referenced by oneshotall(), oneshotall_buffer(), and rz_bin_file_new().

◆ rz_bin_xtrdata_new()

RZ_API RzBinXtrData* rz_bin_xtrdata_new ( RzBuffer buf,
ut64  offset,
ut64  size,
ut32  file_count,
RzBinXtrMetadata metadata 
)

Definition at line 47 of file bin.c.

47  {
49  if (data) {
50  data->offset = offset;
51  data->size = size;
52  data->file_count = file_count;
53  data->metadata = metadata;
54  data->loaded = 0;
55  // don't slice twice TODO. review this
56  data->buf = rz_buf_ref(buf); // rz_buf_new_slice (buf, offset, size);
57  }
58  return data;
59 }
voidpf uLong offset
Definition: ioapi.h:144
RZ_API RzBuffer * rz_buf_ref(RzBuffer *b)
Increment the reference count of the buffer.
Definition: buf.c:668

References rz_bin_xtr_extract_t::buf, rz_bin_xtr_extract_t::file_count, rz_bin_xtr_extract_t::loaded, rz_bin_xtr_extract_t::metadata, rz_bin_xtr_extract_t::offset, rz_buf_ref(), RZ_NEW0, and rz_bin_xtr_extract_t::size.

Referenced by extract(), oneshot(), and oneshot_buffer().

◆ rz_bin_xtrplugin_get()

RZ_API const RzBinXtrPlugin* rz_bin_xtrplugin_get ( RZ_NONNULL RzBin bin,
RZ_NONNULL const char *  name 
)

Get a RzBinXtrPlugin by name.

Definition at line 1214 of file bin.c.

1214  {
1216 
1217  RzListIter *iter;
1218  RzBinXtrPlugin *bp;
1219 
1220  rz_list_foreach (bin->binxtrs, iter, bp) {
1221  if (!strcmp(bp->name, name)) {
1222  return bp;
1223  }
1224  }
1225  return NULL;
1226 }

References rz_bin_xtr_plugin_t::name, NULL, and rz_return_val_if_fail.

Referenced by rz_cmd_info_plugins_handler().

◆ RZ_LIB_VERSION()

RZ_LIB_VERSION ( rz_bin  )

Variable Documentation

◆ bin_static_plugins

RzBinPlugin* bin_static_plugins[] = { RZ_BIN_STATIC_PLUGINS }
static

Definition at line 25 of file bin.c.

Referenced by rz_bin_new().

◆ bin_xtr_static_plugins

RzBinXtrPlugin* bin_xtr_static_plugins[] = { RZ_BIN_XTR_STATIC_PLUGINS }
static

Definition at line 26 of file bin.c.

Referenced by rz_bin_new().