101 size_t newlen = l +
sb->len;
102 char *ns =
malloc(newlen + 1);
104 char *sb_str =
sb->ptr ?
sb->ptr :
sb->buf;
105 char *pivot = strrchr(sb_str,
c);
110 size_t idx = pivot - sb_str;
131 size_t l = strlen(
s);
137 char *sb_str =
sb->ptr ?
sb->ptr :
sb->buf;
138 char *pivot = strstr(sb_str, needle);
142 pivot += strlen(needle);
143 size_t idx = pivot - sb_str;
144 size_t newlen = l +
sb->len;
145 char *ns =
malloc(newlen + 1);
170 if (name_attr_idx != -1) {
187 if (byte_size_idx != -1) {
192 if (bit_size_idx != -1) {
213 for (j =
idx; child_depth > 0 && j <
ctx->count; j++) {
219 for (
i = 0;
i < child_die->
count;
i++) {
221 switch (
value->attr_name) {
280 if (type_idx == -1) {
310 if (type_idx == -1) {
322 if (type_idx != -1) {
329 if (type_idx != -1) {
336 if (type_idx != -1) {
343 if (type_idx != -1) {
350 if (type_idx != -1) {
357 if (type_idx != -1) {
537 if (!base_type->
name) {
544 if (spec_attr_idx != -1) {
551 if (name_attr_idx != -1) {
565 for (j =
idx; child_depth > 0 && j <
ctx->count; j++) {
609 if (!base_type->
name) {
616 if (type_attr_idx != -1) {
623 if (!base_type->
type) {
634 for (j =
idx; child_depth > 0 && j <
ctx->count; j++) {
711 if (!base_type->
type) {
772 if (linkage_name_attr_idx != -1) {
779 if (name_attr_idx != -1) {
790 if (attr_idx != -1) {
802 if (!strcmp(lang,
"rust")) {
804 }
else if (!strcmp(lang,
"ada")) {
815 bool has_linkage_name =
false;
819 switch (
val->attr_name) {
821 if (!get_linkage_name || !has_linkage_name) {
828 has_linkage_name =
true;
844 case 0:
return "rax";
845 case 1:
return "rdx";
846 case 2:
return "rcx";
847 case 3:
return "rbx";
848 case 4:
return "rsi";
849 case 5:
return "rdi";
858 case 10:
return "r10";
859 case 11:
return "r11";
860 case 12:
return "r12";
861 case 13:
return "r13";
862 case 14:
return "r14";
863 case 15:
return "r15";
864 case 17:
return "xmm0";
865 case 18:
return "xmm1";
866 case 19:
return "xmm2";
867 case 20:
return "xmm3";
868 case 21:
return "xmm4";
869 case 22:
return "xmm5";
870 case 23:
return "xmm6";
871 case 24:
return "xmm7";
874 return "unsupported_reg";
885 case 1:
return "edx";
886 case 2:
return "ecx";
887 case 3:
return "ebx";
894 case 6:
return "esi";
895 case 7:
return "edi";
896 case 9:
return "EFLAGS";
897 case 11:
return "st0";
898 case 12:
return "st1";
899 case 13:
return "st2";
900 case 14:
return "st3";
901 case 15:
return "st4";
902 case 16:
return "st5";
903 case 17:
return "st6";
904 case 18:
return "st7";
905 case 21:
return "xmm0";
906 case 22:
return "xmm1";
907 case 23:
return "xmm2";
908 case 24:
return "xmm3";
909 case 25:
return "xmm4";
910 case 26:
return "xmm5";
911 case 27:
return "xmm6";
912 case 28:
return "xmm7";
913 case 29:
return "mm0";
914 case 30:
return "mm1";
915 case 31:
return "mm2";
916 case 32:
return "mm3";
917 case 33:
return "mm4";
918 case 34:
return "mm5";
919 case 35:
return "mm6";
920 case 36:
return "mm7";
921 case 40:
return "es";
922 case 41:
return "cs";
923 case 42:
return "ss";
924 case 43:
return "ds";
925 case 44:
return "fs";
926 case 45:
return "gs";
930 return "unsupported_reg";
950 case 10:
return "r10";
951 case 11:
return "r11";
952 case 12:
return "r12";
953 case 13:
return "r13";
954 case 14:
return "r14";
955 case 15:
return "r15";
956 case 16:
return "r16";
957 case 17:
return "r17";
958 case 18:
return "r18";
959 case 19:
return "r19";
960 case 20:
return "r20";
961 case 21:
return "r21";
962 case 22:
return "r22";
963 case 23:
return "r23";
964 case 24:
return "r24";
965 case 25:
return "r25";
966 case 26:
return "r26";
967 case 27:
return "r27";
968 case 28:
return "r28";
969 case 29:
return "r29";
970 case 30:
return "r30";
971 case 31:
return "r31";
975 return "unsupported_reg";
982 if (!strcmp(
arch,
"x86")) {
988 }
else if (!strcmp(
arch,
"ppc")) {
994 return "unsupported_reg";
999 ut64 max_range_size = 0;
1002 rz_list_foreach (loc_list,
iter,
range) {
1004 if (diff > max_range_size) {
1005 max_range_size = diff;
1038 block = *
range->expression;
1047 const char *reg_name =
NULL;
1050 switch (block.
data[
i]) {
1057 const ut8 *dump = &block.
data[++
i];
1172 const int addr_size =
ctx->analysis->bits / 8;
1173 const ut8 *dump = &block.
data[++
i];
1175 if (block.
length -
i < addr_size) {
1178 switch (addr_size) {
1213 location->
kind = kind;
1224 int child_depth = 1;
1227 bool has_linkage_name =
false;
1230 for (j =
idx; child_depth > 0 && j <
ctx->count; j++) {
1238 for (
i = 0;
i < child_die->
count;
i++) {
1240 switch (
val->attr_name) {
1242 if (!get_linkage_name || !has_linkage_name) {
1249 has_linkage_name =
true;
1301 if (
args->len > 0) {
1310 sdb_set(sdb, sname,
"fcn", 0);
1312 char *addr_key =
rz_str_newf(
"fcn.%s.addr", sname);
1314 sdb_set(sdb, addr_key, addr_val, 0);
1319 char *name_key =
rz_str_newf(
"fcn.%s.name", sname);
1321 sdb_set(sdb, name_key, name_val, 0);
1325 char *signature_key =
rz_str_newf(
"fcn.%s.sig", sname);
1327 free(signature_key);
1333 rz_list_foreach (variables,
iter, var) {
1384 char *vars_key =
rz_str_newf(
"fcn.%s.vars", sname);
1386 sdb_set(sdb, vars_key, vars_val, 0);
1404 bool has_linkage_name =
false;
1417 if (!get_linkage_name || !has_linkage_name) {
1424 has_linkage_name =
true;
1477 if (ret_type.
len == 0) {
1481 char *new_name =
ctx->analysis->binb.demangle(
NULL,
ctx->lang, fcn.
name, fcn.
addr,
false);
1491 rz_list_foreach (variables,
iter, var) {
1518 switch (
val->uconstant) {
1607 for (
i = 0;
i <
info->count;
i++) {
1611 .all_dies = unit->
dies,
1613 .die_map =
info->lookup_table,
1615 .locations =
ctx->loc,
1618 for (j = 0; j < unit->
count; j++) {
1627 return !strcmp(
v,
"fcn");
1646 char *func_sname = kv->
base.key;
1648 char *addr_key =
rz_str_newf(
"fcn.%s.addr", func_sname);
1656 char *real_name_key =
rz_str_newf(
"fcn.%s.name", func_sname);
1657 char *real_name =
sdb_get(dwarf_sdb, real_name_key, 0);
1658 free(real_name_key);
1660 char *dwf_name =
rz_str_newf(
"dbg.%s", real_name);
1673 char *var_names_key =
rz_str_newf(
"fcn.%s.vars", func_sname);
1674 char *vars =
sdb_get(dwarf_sdb, var_names_key,
NULL);
1677 char *var_key =
rz_str_newf(
"fcn.%s.var.%s", func_sname, var_name);
1678 char *var_data =
sdb_get(dwarf_sdb, var_key,
NULL);
1683 char *kind =
sdb_anext(var_data, &extra);
1695 char *global_name =
rz_str_newf(
"global_%s", var_name);
1699 }
else if (*kind ==
's' && fcn) {
1701 }
else if (*kind ==
'r' && fcn) {
1716 free(var_names_key);
RZ_API RzAnalysisFunction * rz_analysis_get_function_at(RzAnalysis *analysis, ut64 addr)
RZ_API bool rz_analysis_function_rename(RzAnalysisFunction *fcn, const char *name)
RZ_API void rz_type_base_type_free(RzBaseType *type)
Frees the RzBaseType instance and all of its members.
RZ_API void rz_type_base_enum_case_free(void *e, void *user)
RZ_API RZ_OWN RzBaseType * rz_type_base_type_new(RzBaseTypeKind kind)
Allocates a new instance of RzBaseType given the kind.
RZ_API void rz_type_db_save_base_type(const RzTypeDB *typedb, const RzBaseType *type)
Saves RzBaseType into the Types DB.
RzBinInfo * info(RzBinFile *bf)
int bits(struct state *s, int need)
RZ_API RZ_OWN RzType * rz_type_parse_string_single(RzTypeParser *parser, const char *code, char **error_msg)
Parses the single C type definition.
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len key
static void parse_typedef(Context *ctx, ut64 idx)
Parses a typedef entry into RzBaseType and saves it using rz_analysis_save_base_type ()
static bool strbuf_rev_append_char(RzStrBuf *sb, const char *s, const char *needle)
Pasted from rz_strbuf_* Appends string after a first occurence of character c Used to replicate prope...
static st32 find_attr_idx(const RzBinDwarfDie *die, st32 attr_name)
static st32 parse_function_args_and_vars(Context *ctx, ut64 idx, RzStrBuf *args, RzList *variables)
static RzTypeStructMember * parse_struct_member(Context *ctx, ut64 idx, RzTypeStructMember *result)
Parses structured entry into *result RzTypeStructMember http://www.dwarfstd.org/doc/DWARF4....
static void sdb_save_dwarf_function(Function *dwarf_fcn, RzList *variables, Sdb *sdb)
static const char * map_dwarf_reg_to_x86_reg(ut64 reg_num, VariableLocationKind *kind)
static void variable_free(Variable *var)
enum dwarf_location_kind VariableLocationKind
static VariableLocation * parse_dwarf_location(Context *ctx, const RzBinDwarfAttrValue *loc, const RzBinDwarfAttrValue *frame_base)
static bool strbuf_rev_prepend_char(RzStrBuf *sb, const char *s, int c)
Pasted from rz_strbuf_* Prepends string before a last occurence of character c Used to replicate prop...
static st32 parse_type_outer(Context *ctx, const ut64 offset, RzStrBuf *strbuf, ut64 *size)
Convenience function for calling parse_type with an empty visited set See documentation of parse_type...
static void parse_structure_type(Context *ctx, ut64 idx)
Parses a structured entry (structs, classes, unions) into RzBaseType and saves it using rz_analysis_s...
static st32 parse_array_type(Context *ctx, ut64 idx, RzStrBuf *strbuf)
Parses array type entry signature into strbuf.
struct dwarf_function_t Function
static RzBinDwarfLocRange * find_largest_loc_range(RzList *loc_list)
struct dwarf_parse_context_t Context
struct dwarf_variable_t Variable
static bool prefer_linkage_name(char *lang)
static void parse_enum_type(Context *ctx, ut64 idx)
Parses a enum entry into RzBaseType and saves it int Sdb using rz_analysis_save_base_type ()
static char * create_type_name_from_offset(ut64 offset)
static char * parse_comp_unit_lang(const RzBinDwarfDie *die)
Get's language from comp unit for demangling.
static const char * map_dwarf_reg_to_x86_64_reg(ut64 reg_num, VariableLocationKind *kind)
static void parse_abstract_origin(Context *ctx, ut64 offset, RzStrBuf *type, const char **name)
static char * get_die_name(const RzBinDwarfDie *die)
Get the DIE name or create unique one from its offset.
RZ_API void rz_analysis_dwarf_process_info(const RzAnalysis *analysis, RzAnalysisDwarfContext *ctx)
Parses type and function information out of DWARF entries and stores them to the sdb for further use.
static const char * get_dwarf_reg_name(RZ_NONNULL char *arch, int reg_num, VariableLocationKind *kind, int bits)
struct dwarf_var_location_t VariableLocation
static void get_spec_die_type(Context *ctx, RzBinDwarfDie *die, RzStrBuf *ret_type)
bool filter_sdb_function_names(void *user, const char *k, const char *v)
static RzBinDwarfAttrValue * find_attr(const RzBinDwarfDie *die, st32 attr_name)
RZ_API void rz_analysis_dwarf_integrate_functions(RzAnalysis *analysis, RzFlag *flags, Sdb *dwarf_sdb)
Use parsed DWARF function info from Sdb in the function analysis XXX right now we only save parsed na...
static const char * map_dwarf_reg_to_ppc64_reg(ut64 reg_num, VariableLocationKind *kind)
static void parse_function(Context *ctx, ut64 idx)
Parse function,it's arguments, variables and save the information into the Sdb.
static const char * get_specification_die_name(const RzBinDwarfDie *die)
static void parse_atomic_type(Context *ctx, ut64 idx)
static ut64 get_die_size(const RzBinDwarfDie *die)
Get the DIE size in bits.
static void parse_type_entry(Context *ctx, ut64 idx)
Delegates DIE to it's proper parsing method.
static st32 parse_type(Context *ctx, const ut64 offset, RzStrBuf *strbuf, ut64 *size, RZ_NONNULL SetU *visited)
Recursively parses type entry of a certain offset into strbuf saves type size into *size.
static RzTypeEnumCase * parse_enumerator(Context *ctx, ut64 idx, RzTypeEnumCase *result)
Parses enum entry into *result RzTypeEnumCase http://www.dwarfstd.org/doc/DWARF4.pdf#page=110&zoom=10...
RZ_API RzFlagItem * rz_flag_set_next(RzFlag *f, const char *name, ut64 off, ut32 size)
RZ_API bool rz_flag_unset_off(RzFlag *f, ut64 off)
RZ_API void Ht_() free(HtName_(Ht) *ht)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
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)
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 void ls_free(SdbList *list)
#define ls_foreach(list, it, pos)
RZ_API Sdb * sdb_ns(Sdb *s, const char *name, int create)
RZ_API ut64 sdb_num_get(Sdb *s, const char *key, ut32 *cas)
RZ_API RzRegItem * rz_reg_get(RzReg *reg, const char *name, int type)
#define rz_warn_if_reached()
#define rz_warn_if_fail(expr)
#define rz_return_if_fail(expr)
#define rz_return_val_if_fail(expr, val)
#define DW_AT_specification
#define DW_TAG_subrange_type
#define DW_TAG_subprogram
#define DW_TAG_volatile_type
#define DW_AT_data_member_location
#define DW_TAG_formal_parameter
#define DW_TAG_class_type
#define DW_TAG_structure_type
static const char * rz_bin_dwarf_attr_value_get_string_content(const RzBinDwarfAttrValue *val)
Safely get the string content from an RzBinDwarfAttrValue if it has one.
#define DW_LANG_C_plus_plus
#define DW_AT_upper_bound
#define DW_TAG_array_type
#define DW_AT_accessibility
#define DW_AT_data_bit_offset
#define DW_TAG_pointer_type
#define DW_AT_vtable_elem_location
#define DW_AT_MIPS_linkage_name
#define DW_LANG_Fortran03
#define DW_AT_abstract_origin
#define DW_AT_containing_type
#define DW_TAG_subroutine_type
#define DW_TAG_const_type
#define DW_LANG_C_plus_plus_14
#define DW_AT_declaration
#define DW_TAG_compile_unit
#define DW_LANG_Fortran08
#define DW_TAG_unspecified_parameters
#define DW_LANG_ObjC_plus_plus
#define DW_TAG_restrict_type
#define DW_LANG_Fortran77
#define DW_OP_call_frame_cfa
#define DW_AT_const_value
#define DW_TAG_enumeration_type
#define DW_TAG_rvalue_reference_type
#define DW_TAG_enumerator
#define DW_AT_object_pointer
#define DW_TAG_reference_type
#define DW_TAG_union_type
#define DW_LANG_Fortran95
#define DW_AT_linkage_name
#define DW_LANG_Fortran90
static ut64 rz_read_ble64(const void *src, bool big_endian)
static ut8 rz_read_ble8(const void *src)
static ut32 rz_read_ble32(const void *src, bool big_endian)
static ut16 rz_read_ble16(const void *src, bool big_endian)
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API char * rz_str_sanitize_sdb_key(const char *s)
RZ_API RZ_OWN char * rz_strbuf_drain_nofree(RzStrBuf *sb)
RZ_API const char * rz_strbuf_set(RzStrBuf *sb, const char *s)
RZ_API char * rz_strbuf_get(RzStrBuf *sb)
RZ_API bool rz_strbuf_slice(RZ_NONNULL RzStrBuf *sb, size_t from, size_t len)
Cuts the current string into a substring.
RZ_API bool rz_strbuf_append(RzStrBuf *sb, const char *s)
RZ_API void rz_strbuf_fini(RzStrBuf *sb)
RZ_API bool rz_strbuf_appendf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
RZ_API void rz_strbuf_init(RzStrBuf *sb)
@ RZ_BASE_TYPE_KIND_TYPEDEF
@ RZ_BASE_TYPE_KIND_ATOMIC
@ RZ_BASE_TYPE_KIND_UNION
@ RZ_BASE_TYPE_KIND_STRUCT
RZ_API const ut8 * rz_uleb128(const ut8 *data, int datalen, RZ_NULLABLE ut64 *v, const char **error)
RZ_API st64 rz_sleb128(const ut8 **data, const ut8 *end)
RZ_API void * rz_vector_push(RzVector *vec, void *x)
RZ_API int sdb_set(Sdb *s, const char *key, const char *val, ut32 cas)
RZ_API char * sdb_get(Sdb *s, const char *key, ut32 *cas)
RZ_API SdbList * sdb_foreach_list_filter(Sdb *s, SdbForeachCallback filter, bool sorted)
RZ_API char * sdb_anext(char *str, char **next)
#define sdb_aforeach_next(x)
#define sdb_aforeach(x, y)
RZ_API SetU * set_u_new(void)
RZ_API void set_u_free(SetU *s)
RZ_API void set_u_delete(SetU *s, ut64 u)
RZ_API void set_u_add(SetU *s, ut64 u)
RZ_API bool set_u_contains(SetU *s, ut64 u)
static struct sockaddr static addrlen static backlog const void static flags void flags
RzBinDwarfAttrValue * attr_values
const RzBinDwarfDie * all_dies
const RzAnalysis * analysis
VariableLocationKind kind
VariableLocation * location
RzBaseTypeStruct struct_data
RZ_API void rz_type_free(RZ_NULLABLE RzType *type)
Frees the RzType.
RZ_API RZ_BORROW RzAnalysisVar * rz_analysis_function_set_var(RzAnalysisFunction *fcn, int delta, char kind, RZ_BORROW RZ_NULLABLE const RzType *type, int size, bool isarg, RZ_NONNULL const char *name)
ut64(WINAPI *w32_GetEnabledXStateFeatures)()