18 char *decoded = bstr->string;
30 if (decoded == bstr->string) {
34 bstr->string = decoded;
35 bstr->length = strlen(decoded);
61 switch (reloc->
type) {
76 #define CMP_CHECK(member) \
78 if (ar->member != br->member) { \
79 return RZ_NUM_CMP(ar->member, br->member); \
118 rz_list_foreach (
relocs, it, reloc) {
165 return r->vaddr >= vaddr &&
r->vaddr < vaddr +
size ?
r :
NULL;
185 return r->target_vaddr == vaddr ?
r :
NULL;
222 char *
p = strstr(dn,
".getter_");
224 p = strstr(dn,
".setter_");
226 p = strstr(dn,
".method_");
230 char *q = strstr(dn, cn);
231 if (q && q[strlen(cn)] ==
'.') {
232 q =
strdup(q + strlen(cn) + 1);
233 char *
r = strchr(q,
'.');
247 if (sym->
name[0] !=
'_') {
257 char *dn = sym->
dname;
264 char *mn = strstr(dn,
"..");
267 if (mn && mn[strlen(cn)] ==
'.') {
302 RZ_LOG_ERROR(
"rz_bin_object_new: load_buffer failed for %s plugin\n", plugin->
name);
308 RZ_LOG_WARN(
"Plugin %s should implement load_buffer method.\n", plugin->
name);
338 HtPU *db = ht_pu_new0();
339 HtPP *ht = ht_pp_new0();
347 int namepad_len = strlen(
cls->name) + 32;
348 char *namepad =
malloc(namepad_len + 1);
350 RZ_LOG_ERROR(
"Cannot allocate %d byte(s)\n", namepad_len);
354 strcpy(namepad,
cls->name);
361 rz_list_foreach (
cls->methods, iter2, sym) {
380 rz_list_foreach (o->
classes, it, klass) {
384 rz_list_foreach (klass->
methods, it2, method) {
401 int type =
p->file_type(bf);
416 o->
size =
p->size(bf);
431 if (
p->virtual_files) {
432 o->
vfiles =
p->virtual_files(bf);
435 o->
maps =
p->maps(bf);
466 rz_list_foreach (o->
symbols, it, sym) {
476 o->
libs =
p->libs(bf);
563 rz_list_foreach (klasses,
iter, klass) {
564 rz_list_foreach (klass->
methods, iter2, method) {
575 Sdb *new_kv =
p->get_sdb(bf);
576 if (new_kv != o->
kv) {
593 static bool first =
true;
631 rz_list_foreach (o->
vfiles, it, vf) {
682 if (
s && (
s->perm &
RZ_PERM_X) && strstr(
s->name,
"text")) {
683 if (!strcmp(o->
info->
arch,
"arm") && (vaddr & 1)) {
684 vaddr = (vaddr >> 1) << 1;
752 return obj->sections;
763 rz_list_foreach (
all, it, sec) {
803 return obj->strings->list;
827 return obj->resources;
839 if (plugin && plugin->
strings) {
855 return obj->strings !=
NULL;
867 return ht_up_find(obj->strings->virt, address,
NULL);
869 return ht_up_find(obj->strings->phys, address,
NULL);
877 return obj->info ? obj->info->big_endian :
false;
926 rz_list_foreach (segments,
iter, segment) {
934 map.segment = segment;
1045 db->
phys = ht_up_new0();
1046 db->
virt = ht_up_new0();
1048 RZ_LOG_ERROR(
"rz_bin: Cannot allocate RzBinStrDb internal data structure.\n");
1054 rz_list_foreach (
list, it, bstr) {
1055 if (!ht_up_update(db->
phys, bstr->
paddr, bstr)) {
1056 RZ_LOG_ERROR(
"rz_bin: Cannot insert/update RzBinString in RzBinStrDb (phys)\n");
1059 if (!ht_up_update(db->
virt, bstr->
vaddr, bstr)) {
1060 RZ_LOG_ERROR(
"rz_bin: Cannot insert/update RzBinString in RzBinStrDb (virt)\n");
1081 ht_up_free(db->phys);
1082 ht_up_free(db->virt);
1098 RZ_LOG_ERROR(
"rz_bin: Cannot add RzBinString in RzBinStrDb (list)\n");
1102 if (!ht_up_update(db->phys, bstr->paddr, bstr)) {
1103 RZ_LOG_ERROR(
"rz_bin: Cannot add RzBinString in RzBinStrDb (phys)\n");
1107 if (!ht_up_update(db->virt, bstr->vaddr, bstr)) {
1108 RZ_LOG_ERROR(
"rz_bin: Cannot add RzBinString in RzBinStrDb (virt)\n");
1120 RzBinString *bstr = ht_up_find(is_va ? db->virt : db->phys, address,
NULL);
1125 ht_up_delete(db->virt, bstr->
vaddr);
1126 ht_up_delete(db->phys, bstr->
paddr);
static RzILOpEffect * cls(cs_insn *insn)
RZ_API RzBinClass * rz_bin_file_add_class(RzBinFile *bf, const char *name, const char *super, int view)
RZ_IPI bool rz_bin_file_set_obj(RzBin *bin, RzBinFile *bf, RzBinObject *obj)
RZ_IPI void rz_bin_class_free(RzBinClass *k)
RZ_API RZ_OWN RzList * rz_bin_file_strings(RZ_NONNULL RzBinFile *bf, size_t min_length, bool raw_strings)
Generates a RzList struct containing RzBinString from a given RzBinFile.
RZ_API void rz_bin_filter_symbols(RzBinFile *bf, RzList *list)
RZ_API void rz_bin_filter_sections(RzBinFile *bf, RzList *list)
RZ_API char * rz_bin_filter_name(RzBinFile *bf, HtPU *db, ut64 vaddr, char *name)
RZ_API void rz_bin_filter_sym(RzBinFile *bf, HtPP *ht, ut64 vaddr, RzBinSymbol *sym)
RZ_IPI RZ_OWN char * rz_bin_file_golang_compiler(RZ_NONNULL RzBinFile *bf)
Returns the golang compiler info if buildinfo struct is found.
RZ_API void rz_bin_info_free(RzBinInfo *rb)
RZ_API void rz_bin_string_free(void *_str)
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 .
RZ_API RZ_OWN RzPVector * rz_bin_object_get_maps_at(RzBinObject *o, ut64 off, bool va)
Find all binary maps at offset off .
RZ_API RZ_BORROW RzBinSection * rz_bin_get_section_at(RzBinObject *o, ut64 off, int va)
Find the binary section at offset off.
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)
RZ_API void rz_bin_set_baddr(RzBin *bin, ut64 baddr)
RZ_API void rz_bin_reloc_free(RzBinReloc *reloc)
static RzList * maps(RzBinFile *bf)
static RzList * classes(RzBinFile *bf)
RZ_API RzBinLanguage rz_bin_language_detect(RzBinFile *binfile)
Tries to detect which language is used in the binary based on symbols and libraries.
RzBinInfo * info(RzBinFile *bf)
RzList * sections(RzBinFile *bf)
RzList * relocs(RzBinFile *bf)
int bits(struct state *s, int need)
RZ_API bool rz_bin_string_database_remove(RZ_NONNULL RzBinStrDb *db, ut64 address, bool is_va)
Return true if the given address has been removed to the RzBinObject string database.
static RzList * classes_from_symbols(RzBinFile *bf)
RZ_API RZ_OWN RzBinStrDb * rz_bin_string_database_new(RZ_NULLABLE RZ_OWN RzList *list)
Allocates and initializes the RzBinStrDb structure with the given list of strings.
RZ_API const RzBinInfo * rz_bin_object_get_info(RZ_NONNULL RzBinObject *obj)
Get the RzBinInfo of the binary object.
static void filter_classes(RzBinFile *bf, RzList *list)
static char * swiftField(const char *dn, const char *cn)
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.
RZ_API const RzList * rz_bin_object_get_classes(RZ_NONNULL RzBinObject *obj)
Get list of RzBinClass representing the classes (e.g. C++ classes) defined in the binary object.
RZ_API void rz_bin_string_database_free(RZ_NULLABLE RzBinStrDb *db)
Frees a RzBinStrDb structure.
RZ_API RzBinVirtualFile * rz_bin_object_get_virtual_file(RzBinObject *o, const char *name)
RZ_API RZ_BORROW RzBinString * rz_bin_object_get_string_at(RZ_NONNULL RzBinObject *obj, ut64 address, bool is_va)
Return RzBinString if at address there is an entry in the RzBinObject string database.
RZ_API void rz_bin_string_decode_base64(RZ_NONNULL RzBinString *bstr)
Tries to decode the base64 string hold by RzBinString and overwrites it.
RZ_API const RzList * rz_bin_object_get_imports(RZ_NONNULL RzBinObject *obj)
Get list of RzBinImport representing the imports of the binary object.
RZ_API int rz_bin_object_set_items(RzBinFile *bf, RzBinObject *o)
RZ_API const RzBinAddr * rz_bin_object_get_special_symbol(RzBinObject *o, RzBinSpecialSymbol sym)
Return the RzBinAddr structure representing the special symbol sym.
RZ_API const RzList * rz_bin_object_get_fields(RZ_NONNULL RzBinObject *obj)
Get list of RzBinField representing the fields of the binary object.
RZ_API RZ_OWN RzVector * rz_bin_object_sections_mapping_list(RZ_NONNULL RzBinObject *obj)
Get the mapping between segments and sections in the binary.
static int reloc_vaddr_cmp(ut64 ref, RzBinReloc *reloc)
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.
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.
RZ_API ut64 rz_bin_object_addr_with_base(RzBinObject *o, ut64 addr)
Put the given address on top of o's base address.
RZ_API RzVector * rz_bin_object_p2v_all(RZ_NONNULL RzBinObject *obj, ut64 paddr)
Convert offset in the file to all possible virtual addresses according to binary mappings.
static void bin_section_map_fini(void *e, void *user)
RZ_IPI RzBinObject * rz_bin_object_get_cur(RzBin *bin)
RZ_API RzBinSymbol * rz_bin_object_get_symbol_of_import(RzBinObject *o, RzBinImport *imp)
Find the symbol that represents the given import This is necessary for example to determine the addre...
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.
static int reloc_cmp(const void *a, const void *b)
static int reloc_target_vaddr_cmp(ut64 ref, RzBinReloc *reloc)
RZ_API RzBinRelocStorage * rz_bin_reloc_storage_new(RZ_OWN RzList *relocs)
RZ_API bool rz_bin_object_reset_strings(RZ_NONNULL RzBin *bin, RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzBinObject *obj)
Remove all previously identified strings in the binary object and scan it again for strings.
RZ_API ut64 rz_bin_object_v2p(RZ_NONNULL RzBinObject *obj, ut64 vaddr)
Convert virtual address to offset in the file according to binary mappings.
RZ_API ut64 rz_bin_object_get_vaddr(RzBinObject *o, ut64 paddr, ut64 vaddr)
static ut64 map_p2v(RzBinMap *m, ut64 paddr)
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.
RZ_API ut64 rz_bin_object_p2v(RZ_NONNULL RzBinObject *obj, ut64 paddr)
Convert offset in the file to virtual address according to binary mappings.
RZ_API void rz_bin_mem_free(void *data)
RZ_IPI void rz_bin_object_free(RzBinObject *o)
static void rz_bin_object_rebuild_classes_ht(RzBinObject *o)
#define CMP_CHECK(member)
RZ_API bool rz_bin_string_database_add(RZ_NONNULL RzBinStrDb *db, RZ_NONNULL RzBinString *bstr)
{ function_description }
RZ_API const RzList * rz_bin_object_get_resources(RZ_NONNULL RzBinObject *obj)
Get a list of RzBinResource representing the resources in the binary object.
RZ_API RZ_OWN RzList * rz_bin_object_get_segments(RZ_NONNULL RzBinObject *obj)
Get list of RzBinSection representing only the segments of the binary object.
static RzList * get_sections_or_segment(RzBinObject *obj, bool is_segment)
RZ_API bool rz_bin_object_is_big_endian(RZ_NONNULL RzBinObject *obj)
Return true if the binary object obj is big endian.
RZ_API RZ_OWN RzList * rz_bin_object_get_sections(RZ_NONNULL RzBinObject *obj)
Get list of RzBinSection representing only the sections of the binary object.
static void bin_object_decode_all_base64_strings(RzList *strings)
RZ_IPI RzBinObject * rz_bin_object_new(RzBinFile *bf, RzBinPlugin *plugin, RzBinObjectLoadOptions *opts, ut64 offset, ut64 sz)
RZ_API RzBinReloc * rz_bin_reloc_storage_get_reloc_to(RzBinRelocStorage *storage, ut64 vaddr)
Get a reloc that points exactly to vaddr or NULL.
RZ_API RzBinReloc * rz_bin_reloc_storage_get_reloc_in(RzBinRelocStorage *storage, ut64 vaddr, ut64 size)
Get the reloc with the lowest vaddr that starts inside the given interval.
RZ_API const RzList * rz_bin_object_get_symbols(RZ_NONNULL RzBinObject *obj)
Get list of RzBinSymbol representing the symbols in the binary object.
RZ_API RzBinRelocStorage * rz_bin_object_patch_relocs(RzBinFile *bf, RzBinObject *o)
RZ_API void rz_bin_reloc_storage_free(RzBinRelocStorage *storage)
RZ_IPI RzBinObject * rz_bin_object_find_by_arch_bits(RzBinFile *bf, const char *arch, int bits, const char *name)
RZ_API bool rz_bin_object_is_static(RZ_NONNULL RzBinObject *obj)
Return true if the binary object obj is detected as statically compiled.
RZ_API ut64 rz_bin_reloc_size(RzBinReloc *reloc)
size of the reloc (where it is supposed to be patched) in bits
static int reloc_target_cmp(const void *a, const void *b)
RZ_API void rz_bin_source_line_info_free(RzBinSourceLineInfo *sli)
size_t map(int syms, int left, int len)
checking print the parsed form of the magic use in n conjunction with m to debug a new magic file n before installing it n output MIME type strings(--mime-type and\n"
" --mime-encoding)\n") OPT('s'
RZ_API char * sdb_fmt(const char *fmt,...)
RZ_API void Ht_() free(HtName_(Ht) *ht)
static void list(RzEgg *egg)
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
RZ_API bool rz_list_delete_data(RZ_NONNULL RzList *list, void *ptr)
Deletes an entry in the list by searching for a pointer.
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
RZ_API ut32 rz_list_length(RZ_NONNULL const RzList *list)
Returns the length of the list.
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
void * malloc(size_t size)
static const char struct stat static buf struct stat static buf static idle const char static path static fd const char static len const void static prot const char struct module static image struct kernel_sym static table unsigned char static buf static fsuid unsigned struct dirent unsigned static count const struct iovec static count static pid const void static len static flags const struct sched_param static p static pid static policy struct timespec static tp static suid unsigned fn
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")
RZ_API int sdb_ns_set(Sdb *s, const char *name, Sdb *r)
#define rz_warn_if_fail(expr)
#define rz_return_if_fail(expr)
#define rz_return_val_if_fail(expr, val)
RZ_API ut8 * rz_base64_decode_dyn(const char *in, int len)
#define RZ_BIN_DBG_STATIC
#define RZ_BIN_REQ_CLASSES_SOURCES
#define RZ_BIN_REQ_RELOCS
#define REBASE_PADDR(o, l, type_t)
#define RZ_BIN_REQ_CLASSES
#define RZ_BIN_REQ_IMPORTS
@ RZ_BIN_SPECIAL_SYMBOL_LAST
static bool rz_bin_reloc_has_target(RzBinReloc *reloc)
#define RZ_BIN_REQ_STRINGS
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
static ut64 rz_itv_begin(RzInterval itv)
struct rz_interval_t RzInterval
static ut64 rz_itv_end(RzInterval itv)
void(* RzListFree)(void *ptr)
#define RZ_LOG_WARN(fmtstr,...)
#define RZ_LOG_ERROR(fmtstr,...)
#define RZ_NUM_CMP(a, b)
Typical comparison (1/0/-1) for two numbers of arbitrary types, including unsigned.
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
#define RZ_STR_ISEMPTY(x)
RZ_API bool rz_str_is_printable(const char *str)
#define RZ_FREE_CUSTOM(x, y)
static void ** rz_pvector_reserve(RzPVector *vec, size_t capacity)
RZ_API void rz_pvector_sort(RzPVector *vec, RzPVectorComparator cmp)
RZ_API void rz_pvector_init(RzPVector *vec, RzPVectorFree free)
RZ_API void rz_pvector_fini(RzPVector *vec)
RZ_API void * rz_vector_reserve(RzVector *vec, size_t capacity)
static size_t rz_pvector_len(const RzPVector *vec)
RZ_API void * rz_vector_push(RzVector *vec, void *x)
#define rz_array_upper_bound(array, len, x, i, cmp)
static void ** rz_pvector_push(RzPVector *vec, void *x)
RZ_API void rz_pvector_free(RzPVector *vec)
#define rz_array_lower_bound(array, len, x, i, cmp)
RZ_API RzVector * rz_vector_new(size_t elem_size, RzVectorFree free, void *free_user)
static void ** rz_pvector_flush(RzPVector *vec)
#define rz_pvector_foreach(vec, it)
RZ_API bool sdb_free(Sdb *s)
#define br(opcode, mask, lose, flags)
ut64 loadaddr
starting physical address to read from the target file
ut64 baseaddr
where the linker maps the binary in memory
XX curplugin == o->plugin.
RZ_DEPRECATE Sdb * sdb
deprecated, put info in C structures instead of this
int fd
when used in combination with RzIO, this refers to the io fd.
Description of a single memory mapping into virtual memory from a binary.
RzBinObjectLoadOptions opts
HtPP * import_name_symbols
Acceleration structure for fast access of the symbol for a given import. This associates the name of ...
struct rz_bin_plugin_t * plugin
RzBinSourceLineInfo * lines
RZ_DEPRECATE RZ_BORROW Sdb * kv
deprecated, put info in C structures instead of this (holds a copy of another pointer....
RzBinAddr * binsym[RZ_BIN_SPECIAL_SYMBOL_LAST]
RzBinRelocStorage * relocs
RzList *(* patch_relocs)(RzBinFile *bf)
RzList *(* strings)(RzBinFile *bf)
bool(* load_buffer)(RzBinFile *bf, RzBinObject *obj, RzBuffer *buf, Sdb *sdb)
Efficient storage of relocations to query by address.
RzBinReloc ** target_relocs
all relocs that have a valid target_vaddr, ordered by their target_vaddr. size is target_relocs_count...
size_t target_relocs_count
RzBinReloc ** relocs
all relocs, ordered by their vaddr
ut64 vaddr
the vaddr where the value should be patched into
ut64 target_vaddr
the target address that the patched reloc points to
RzList * list
Contains all the strings in list form.
HtUP * virt
Contains all the strings but mapped by virtual address.
HtUP * phys
Contains all the strings but mapped by physical address.
RZ_OWN RZ_NONNULL char * name
if(dbg->bits==RZ_SYS_BITS_64)
ut64(WINAPI *w32_GetEnabledXStateFeatures)()