Rizin
unix-like reverse engineering framework and cli tools
analysis.c File Reference
#include <rz_analysis.h>
#include <rz_util.h>
#include <rz_list.h>
#include <rz_util/rz_path.h>
#include <config.h>

Go to the source code of this file.

Macros

#define K_NORET_ADDR(x)   sdb_fmt("addr.%" PFMT64x ".noreturn", x)
 
#define K_NORET_FUNC(x)   sdb_fmt("func.%s.noreturn", x)
 

Functions

 RZ_LIB_VERSION (rz_analysis)
 
RZ_API void rz_analysis_set_limits (RzAnalysis *analysis, ut64 from, ut64 to)
 
RZ_API void rz_analysis_unset_limits (RzAnalysis *analysis)
 
static void meta_unset_for (RzEvent *ev, int type, void *user, void *data)
 
static void meta_count_for (RzEvent *ev, int type, void *user, void *data)
 
void rz_analysis_hint_storage_init (RzAnalysis *a)
 
void rz_analysis_hint_storage_fini (RzAnalysis *a)
 
static void rz_meta_item_fini (RzAnalysisMetaItem *item)
 
static void rz_meta_item_free (void *_item)
 
static void global_kv_free (HtPPKv *kv)
 
RZ_API RzAnalysisrz_analysis_new (void)
 
RZ_API void plugin_fini (RzAnalysis *analysis)
 
void __block_free_rb (RBNode *node, void *user)
 
RZ_API RzAnalysisrz_analysis_free (RzAnalysis *a)
 
RZ_API int rz_analysis_add (RzAnalysis *analysis, RzAnalysisPlugin *p)
 
RZ_API bool rz_analysis_use (RzAnalysis *analysis, const char *name)
 
RZ_API char * rz_analysis_get_reg_profile (RzAnalysis *analysis)
 
RZ_API bool rz_analysis_set_reg_profile (RzAnalysis *analysis)
 
static bool analysis_set_os (RzAnalysis *analysis, const char *os)
 
RZ_API bool rz_analysis_set_triplet (RzAnalysis *analysis, const char *os, const char *arch, int bits)
 
RZ_API bool rz_analysis_set_os (RzAnalysis *analysis, const char *os)
 
static bool is_arm_thumb_hack (RzAnalysis *analysis, int bits)
 
RZ_API bool rz_analysis_set_bits (RzAnalysis *analysis, int bits)
 
RZ_API int rz_analysis_get_address_bits (RzAnalysis *analysis)
 The actual size of an address in bits. More...
 
RZ_API void rz_analysis_set_cpu (RzAnalysis *analysis, const char *cpu)
 
RZ_API int rz_analysis_set_big_endian (RzAnalysis *analysis, int bigend)
 
RZ_API ut8rz_analysis_mask (RzAnalysis *analysis, ut32 size, const ut8 *data, ut64 at)
 
RZ_API void rz_analysis_trace_bb (RzAnalysis *analysis, ut64 addr)
 
RZ_API RzListrz_analysis_get_fcns (RzAnalysis *analysis)
 
RZ_API RzAnalysisOprz_analysis_op_hexstr (RzAnalysis *analysis, ut64 addr, const char *str)
 
RZ_API bool rz_analysis_op_is_eob (RzAnalysisOp *op)
 
RZ_API void rz_analysis_purge (RzAnalysis *analysis)
 
RZ_API int rz_analysis_archinfo (RzAnalysis *analysis, int query)
 
RZ_API bool rz_analysis_noreturn_add (RzAnalysis *analysis, const char *name, ut64 addr)
 
RZ_API bool rz_analysis_noreturn_drop (RzAnalysis *analysis, const char *expr)
 
static bool rz_analysis_is_noreturn (RzAnalysis *analysis, const char *name)
 
static bool rz_analysis_noreturn_at_name (RzAnalysis *analysis, const char *name)
 
RZ_API bool rz_analysis_noreturn_at_addr (RzAnalysis *analysis, ut64 addr)
 
static bool noreturn_recurse (RzAnalysis *analysis, ut64 addr)
 
RZ_API bool rz_analysis_noreturn_at (RzAnalysis *analysis, ut64 addr)
 
RZ_API RzListrz_analysis_noreturn_functions (RzAnalysis *analysis)
 
RZ_API void rz_analysis_bind (RzAnalysis *analysis, RzAnalysisBind *b)
 
RZ_API RzListrz_analysis_preludes (RzAnalysis *analysis)
 
RZ_API bool rz_analysis_is_prelude (RzAnalysis *analysis, const ut8 *data, int len)
 
RZ_API void rz_analysis_add_import (RzAnalysis *analysis, const char *imp)
 
RZ_API void rz_analysis_remove_import (RzAnalysis *analysis, const char *imp)
 
RZ_API void rz_analysis_purge_imports (RzAnalysis *analysis)
 

Variables

static RzAnalysisPluginanalysis_static_plugins [] = { RZ_ANALYSIS_STATIC_PLUGINS }
 

Macro Definition Documentation

◆ K_NORET_ADDR

#define K_NORET_ADDR (   x)    sdb_fmt("addr.%" PFMT64x ".noreturn", x)

Definition at line 463 of file analysis.c.

◆ K_NORET_FUNC

#define K_NORET_FUNC (   x)    sdb_fmt("func.%s.noreturn", x)

Definition at line 464 of file analysis.c.

Function Documentation

◆ __block_free_rb()

void __block_free_rb ( RBNode node,
void *  user 
)

Definition at line 85 of file block.c.

85  {
86  RzAnalysisBlock *block = unwrap(node);
87  block_free(block);
88 }
#define unwrap(rbnode)
Definition: block.c:10
static void block_free(RzAnalysisBlock *block)
Definition: block.c:70

References block_free(), and unwrap.

Referenced by rz_analysis_block_merge(), rz_analysis_block_unref(), and rz_analysis_free().

◆ analysis_set_os()

static bool analysis_set_os ( RzAnalysis analysis,
const char *  os 
)
static

Definition at line 229 of file analysis.c.

229  {
230  rz_return_val_if_fail(analysis, false);
231  if (!os || !*os) {
232  os = RZ_SYS_OS;
233  }
234  free(analysis->os);
235  analysis->os = strdup(os);
236  char *types_dir = rz_path_system(RZ_SDB_TYPES);
237  rz_type_db_set_os(analysis->typedb, os);
238  rz_type_db_reload(analysis->typedb, types_dir);
239  free(types_dir);
240  return true;
241 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
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_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API RZ_OWN char * rz_path_system(RZ_NULLABLE const char *path)
Return the full system path of the given subpath path.
Definition: path.c:162
#define RZ_SYS_OS
Definition: rz_types.h:587
#define RZ_SDB_TYPES
Definition: rz_userconf.h:83
RzTypeDB * typedb
Definition: rz_analysis.h:602
RZ_API void rz_type_db_reload(RzTypeDB *typedb, const char *types_dir)
Re-initializes the types database for current target.
Definition: type.c:357
RZ_API void rz_type_db_set_os(RzTypeDB *typedb, const char *os)
Set the RzType target architecture operating system.
Definition: type.c:175

References free(), rz_analysis_t::os, rz_path_system(), rz_return_val_if_fail, RZ_SDB_TYPES, RZ_SYS_OS, rz_type_db_reload(), rz_type_db_set_os(), strdup(), and rz_analysis_t::typedb.

Referenced by rz_analysis_set_triplet().

◆ global_kv_free()

static void global_kv_free ( HtPPKv *  kv)
static

Definition at line 58 of file analysis.c.

58  {
59  free(kv->key);
60  rz_analysis_var_global_free(kv->value);
61 }
RZ_API void rz_analysis_var_global_free(RzAnalysisVarGlobal *glob)
Free the global variable instance.
Definition: var_global.c:79

References free(), and rz_analysis_var_global_free().

Referenced by rz_analysis_new().

◆ is_arm_thumb_hack()

static bool is_arm_thumb_hack ( RzAnalysis analysis,
int  bits 
)
static

Definition at line 260 of file analysis.c.

260  {
261  if (!analysis || !analysis->cpu) {
262  return false;
263  }
264  if ((analysis->bits != bits) && !strcmp(analysis->cpu, "arm")) {
265  return (analysis->bits == 16 && bits == 32) || (analysis->bits == 32 && bits == 16);
266  }
267  return false;
268 }
int bits(struct state *s, int need)
Definition: blast.c:72

References rz_analysis_t::bits, bits(), and rz_analysis_t::cpu.

Referenced by rz_analysis_set_bits().

◆ meta_count_for()

static void meta_count_for ( RzEvent ev,
int  type,
void *  user,
void *  data 
)
static

Definition at line 35 of file analysis.c.

35  {
36  RzSpaces *s = (RzSpaces *)ev->user;
37  RzAnalysis *analysis = container_of(s, RzAnalysis, meta_spaces);
38  RzSpaceEvent *se = (RzSpaceEvent *)data;
39  se->res = rz_meta_space_count_for(analysis, se->data.count.space);
40 }
RZ_API int rz_meta_space_count_for(RzAnalysis *a, const RzSpace *space)
Definition: meta.c:295
static RzSocket * s
Definition: rtr.c:28
#define container_of(ptr, type, member)
Definition: rz_types.h:650
void * user
Definition: rz_event.h:15
struct rz_space_event_t::@311::@312 count
union rz_space_event_t::@311 data

References container_of, rz_space_event_t::count, rz_space_event_t::data, rz_space_event_t::res, rz_meta_space_count_for(), s, and rz_event_t::user.

Referenced by rz_analysis_new().

◆ meta_unset_for()

static void meta_unset_for ( RzEvent ev,
int  type,
void *  user,
void *  data 
)
static

Definition at line 28 of file analysis.c.

28  {
29  RzSpaces *s = (RzSpaces *)ev->user;
30  RzAnalysis *analysis = container_of(s, RzAnalysis, meta_spaces);
31  RzSpaceEvent *se = (RzSpaceEvent *)data;
32  rz_meta_space_unset_for(analysis, se->data.unset.space);
33 }
RZ_API void rz_meta_space_unset_for(RzAnalysis *a, const RzSpace *space)
Definition: meta.c:274
struct rz_space_event_t::@311::@313 unset

References container_of, rz_space_event_t::data, rz_meta_space_unset_for(), s, rz_space_event_t::unset, and rz_event_t::user.

Referenced by rz_analysis_new().

◆ noreturn_recurse()

static bool noreturn_recurse ( RzAnalysis analysis,
ut64  addr 
)
static

Definition at line 561 of file analysis.c.

561  {
562  RzAnalysisOp op = { 0 };
563  ut8 bbuf[0x10] = { 0 };
564  ut64 recurse_addr = UT64_MAX;
565  if (!analysis->iob.read_at(analysis->iob.io, addr, bbuf, sizeof(bbuf))) {
566  RZ_LOG_ERROR("Cannot read buffer at 0x%" PFMT64x "\n", addr);
567  return false;
568  }
569  if (rz_analysis_op(analysis, &op, addr, bbuf, sizeof(bbuf), RZ_ANALYSIS_OP_MASK_BASIC | RZ_ANALYSIS_OP_MASK_VAL) < 1) {
570  return false;
571  }
572  switch (op.type & RZ_ANALYSIS_OP_TYPE_MASK) {
574  if (op.jump == UT64_MAX) {
575  recurse_addr = op.ptr;
576  } else {
577  recurse_addr = op.jump;
578  }
579  break;
584  recurse_addr = op.ptr;
585  break;
588  recurse_addr = op.jump;
589  break;
590  }
591  if (recurse_addr == UT64_MAX || recurse_addr == addr) {
592  return false;
593  }
594  return rz_analysis_noreturn_at(analysis, recurse_addr);
595 }
RZ_API bool rz_analysis_noreturn_at(RzAnalysis *analysis, ut64 addr)
Definition: analysis.c:597
uint8_t ut8
Definition: lh5801.h:11
RZ_API int rz_analysis_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *data, int len, RzAnalysisOpMask mask)
Definition: op.c:96
@ RZ_ANALYSIS_OP_MASK_BASIC
Definition: rz_analysis.h:440
@ RZ_ANALYSIS_OP_MASK_VAL
Definition: rz_analysis.h:442
#define RZ_ANALYSIS_OP_TYPE_MASK
Definition: rz_analysis.h:358
@ RZ_ANALYSIS_OP_TYPE_ICALL
Definition: rz_analysis.h:381
@ RZ_ANALYSIS_OP_TYPE_JMP
Definition: rz_analysis.h:368
@ RZ_ANALYSIS_OP_TYPE_CCALL
Definition: rz_analysis.h:383
@ RZ_ANALYSIS_OP_TYPE_CALL
Definition: rz_analysis.h:378
@ RZ_ANALYSIS_OP_TYPE_UCALL
Definition: rz_analysis.h:379
@ RZ_ANALYSIS_OP_TYPE_RCALL
Definition: rz_analysis.h:380
@ RZ_ANALYSIS_OP_TYPE_IRCALL
Definition: rz_analysis.h:382
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
#define PFMT64x
Definition: rz_types.h:393
#define UT64_MAX
Definition: rz_types_base.h:86
RzIOBind iob
Definition: rz_analysis.h:574
RzIOReadAt read_at
Definition: rz_io.h:240
RzIO * io
Definition: rz_io.h:232
Definition: dis.c:32
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int addr
Definition: z80asm.c:58

References addr, rz_io_bind_t::io, rz_analysis_t::iob, PFMT64x, rz_io_bind_t::read_at, rz_analysis_noreturn_at(), rz_analysis_op(), RZ_ANALYSIS_OP_MASK_BASIC, RZ_ANALYSIS_OP_MASK_VAL, RZ_ANALYSIS_OP_TYPE_CALL, RZ_ANALYSIS_OP_TYPE_CCALL, RZ_ANALYSIS_OP_TYPE_ICALL, RZ_ANALYSIS_OP_TYPE_IRCALL, RZ_ANALYSIS_OP_TYPE_JMP, RZ_ANALYSIS_OP_TYPE_MASK, RZ_ANALYSIS_OP_TYPE_RCALL, RZ_ANALYSIS_OP_TYPE_UCALL, RZ_LOG_ERROR, ut64(), and UT64_MAX.

Referenced by rz_analysis_noreturn_at().

◆ plugin_fini()

RZ_API void plugin_fini ( RzAnalysis analysis)

Definition at line 127 of file analysis.c.

127  {
128  RzAnalysisPlugin *p = analysis->cur;
129  if (p && p->fini && !p->fini(analysis->plugin_data)) {
130  RZ_LOG_ERROR("analysis plugin '%s' failed to terminate.\n", p->name);
131  }
132  analysis->plugin_data = NULL;
133 }
#define NULL
Definition: cris-opc.c:27
void * p
Definition: libc.cpp:67
void * plugin_data
Definition: rz_analysis.h:561
struct rz_analysis_plugin_t * cur
Definition: rz_analysis.h:586

References rz_analysis_t::cur, NULL, p, rz_analysis_t::plugin_data, and RZ_LOG_ERROR.

Referenced by rz_analysis_free(), and rz_analysis_use().

◆ rz_analysis_add()

RZ_API int rz_analysis_add ( RzAnalysis analysis,
RzAnalysisPlugin p 
)

Definition at line 179 of file analysis.c.

179  {
180  rz_list_append(analysis->plugins, p);
181  return true;
182 }
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288
RzList * plugins
Definition: rz_analysis.h:588

References p, rz_analysis_t::plugins, and rz_list_append().

Referenced by __lib_analysis_cb(), and rz_analysis_new().

◆ rz_analysis_add_import()

RZ_API void rz_analysis_add_import ( RzAnalysis analysis,
const char *  imp 
)

Definition at line 693 of file analysis.c.

693  {
694  RzListIter *it;
695  const char *eimp;
696  rz_list_foreach (analysis->imports, it, eimp) {
697  if (!strcmp(eimp, imp)) {
698  return;
699  }
700  }
701  char *cimp = strdup(imp);
702  if (!cimp) {
703  return;
704  }
705  rz_list_push(analysis->imports, cimp);
706 }
RZ_API RZ_BORROW RzListIter * rz_list_push(RZ_NONNULL RzList *list, void *item)
Alias for rz_list_append.
Definition: list.c:60
RzList * imports
Definition: rz_analysis.h:618

References rz_analysis_t::imports, rz_list_push(), and strdup().

Referenced by import_load_cb(), and rz_global_imports_handler().

◆ rz_analysis_archinfo()

RZ_API int rz_analysis_archinfo ( RzAnalysis analysis,
int  query 
)

Definition at line 449 of file analysis.c.

449  {
450  rz_return_val_if_fail(analysis, -1);
451  switch (query) {
455  if (analysis->cur && analysis->cur->archinfo) {
456  return analysis->cur->archinfo(analysis, query);
457  }
458  break;
459  }
460  return -1;
461 }
#define RZ_ANALYSIS_ARCHINFO_ALIGN
Definition: rz_analysis.h:100
#define RZ_ANALYSIS_ARCHINFO_MAX_OP_SIZE
Definition: rz_analysis.h:99
#define RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE
Definition: rz_analysis.h:98
int(* archinfo)(RzAnalysis *analysis, int query)
Definition: rz_analysis.h:1246

References rz_analysis_plugin_t::archinfo, rz_analysis_t::cur, RZ_ANALYSIS_ARCHINFO_ALIGN, RZ_ANALYSIS_ARCHINFO_MAX_OP_SIZE, RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE, and rz_return_val_if_fail.

Referenced by _analysis_calls(), _CbInRangeAav(), alignCheck(), cb_analysis_cpu(), cb_asmarch(), cb_asmbits(), cmd_aea(), do_syscall_search(), prevop_addr(), rz_analysis_set_bits(), rz_analysis_set_cpu(), rz_analysis_update_analysis_range(), rz_core_analysis_bytes(), rz_core_analysis_esil_emulate(), rz_core_analysis_resolve_golang_strings(), rz_core_analysis_type_match(), rz_core_analysis_value_pointers(), rz_core_bin_apply_config(), rz_core_bin_info_print(), rz_core_disasm_pde(), rz_core_esil_step(), rz_core_get_stacksz(), rz_core_link_stroff(), rz_core_seek_opcode_backward(), and rz_debug_step_soft().

◆ rz_analysis_bind()

RZ_API void rz_analysis_bind ( RzAnalysis analysis,
RzAnalysisBind b 
)

Definition at line 661 of file analysis.c.

661  {
662  if (b) {
663  b->analysis = analysis;
664  b->get_fcn_in = rz_analysis_get_fcn_in;
665  b->get_hint = rz_analysis_hint_get;
666  }
667 }
RZ_DEPRECATE RZ_API RzAnalysisFunction * rz_analysis_get_fcn_in(RzAnalysis *analysis, ut64 addr, int type)
Definition: fcn.c:1687
RZ_API RzAnalysisHint * rz_analysis_hint_get(RzAnalysis *a, ut64 addr)
Definition: hint.c:506
#define b(i)
Definition: sha256.c:42

References b, rz_analysis_get_fcn_in(), and rz_analysis_hint_get().

Referenced by rz_core_init().

◆ rz_analysis_free()

RZ_API RzAnalysis* rz_analysis_free ( RzAnalysis a)

Definition at line 137 of file analysis.c.

137  {
138  if (!a) {
139  return NULL;
140  }
141 
142  plugin_fini(a);
143 
144  rz_hash_free(a->hash);
146  rz_list_free(a->fcns);
147  ht_up_free(a->ht_addr_fun);
148  ht_pp_free(a->ht_name_fun);
149  set_u_free(a->visited);
151  rz_interval_tree_fini(&a->meta);
152  free(a->cpu);
153  free(a->os);
154  rz_list_free(a->plugins);
155  rz_rbtree_free(a->bb_tree, __block_free_rb, NULL);
156  rz_spaces_fini(&a->meta_spaces);
157  rz_syscall_free(a->syscall);
158  rz_platform_target_free(a->arch_target);
159  rz_platform_target_index_free(a->platform_target);
160  rz_reg_free(a->reg);
161  ht_up_free(a->ht_xrefs_from);
162  ht_up_free(a->ht_xrefs_to);
163  ht_up_free(a->type_links);
164  rz_list_free(a->leaddrs);
165  rz_type_db_free(a->typedb);
166  sdb_free(a->sdb);
167  if (a->esil) {
168  rz_analysis_esil_free(a->esil);
169  a->esil = NULL;
170  }
171  free(a->last_disasm_reg);
172  rz_list_free(a->imports);
173  rz_str_constpool_fini(&a->constpool);
174  ht_pp_free(a->ht_global_var);
175  free(a);
176  return NULL;
177 }
void rz_analysis_hint_storage_fini(RzAnalysis *a)
Definition: hint.c:79
void __block_free_rb(RBNode *node, void *user)
Definition: block.c:85
RZ_API void plugin_fini(RzAnalysis *analysis)
Definition: analysis.c:127
RZ_API void rz_analysis_il_vm_cleanup(RzAnalysis *analysis)
Definition: analysis_il.c:303
RZ_API void rz_analysis_esil_free(RzAnalysisEsil *esil)
Definition: esil.c:163
RZ_API void rz_hash_free(RzHash *rh)
Definition: hash.c:597
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_platform_target_free(RzPlatformTarget *t)
Frees an RzPlatformTarget type.
RZ_API void rz_platform_target_index_free(RzPlatformTargetIndex *target)
Frees an RzPlatformTargetIndex type.
RZ_API void rz_reg_free(RzReg *reg)
Definition: reg.c:279
RZ_API void rz_interval_tree_fini(RzIntervalTree *tree)
Definition: intervaltree.c:114
RZ_API void rz_rbtree_free(RZ_NULLABLE RBNode *root, RBNodeFree freefn, void *user)
Definition: rbtree.c:281
RZ_API void rz_spaces_fini(RzSpaces *sp)
Definition: spaces.c:59
RZ_API void rz_str_constpool_fini(RzStrConstPool *pool)
Definition: str_constpool.c:15
RZ_API bool sdb_free(Sdb *s)
Definition: sdb.c:206
RZ_API void set_u_free(SetU *s)
Definition: set.c:46
#define a(i)
Definition: sha256.c:41
RZ_API void rz_syscall_free(RzSyscall *s)
Frees an RzSyscall type.
Definition: syscall.c:79
RZ_API void rz_type_db_free(RzTypeDB *typedb)
Frees the instance of the RzTypeDB.
Definition: type.c:79

References __block_free_rb(), a, free(), NULL, plugin_fini(), rz_analysis_esil_free(), rz_analysis_hint_storage_fini(), rz_analysis_il_vm_cleanup(), rz_hash_free(), rz_interval_tree_fini(), rz_list_free(), rz_platform_target_free(), rz_platform_target_index_free(), rz_rbtree_free(), rz_reg_free(), rz_spaces_fini(), rz_str_constpool_fini(), rz_syscall_free(), rz_type_db_free(), sdb_free(), and set_u_free().

Referenced by __as_free(), and rz_core_fini().

◆ rz_analysis_get_address_bits()

RZ_API int rz_analysis_get_address_bits ( RzAnalysis analysis)

The actual size of an address in bits.

This may differ from analysis.bits in some cases such as arm thumb being identified as bits=16, but still using 32-bit addresses, or "8-bit" architectures like 6502 which still use 16-bit addresses.

Definition at line 303 of file analysis.c.

303  {
304  if (!analysis->cur || !analysis->cur->address_bits) {
305  return analysis->bits;
306  }
307  int r = analysis->cur->address_bits(analysis, analysis->bits);
308  return r > 0 ? r : analysis->bits;
309 }
#define r
Definition: crypto_rc6.c:12
int(* address_bits)(RzAnalysis *analysis, int bits)
Definition: rz_analysis.h:1254

References rz_analysis_plugin_t::address_bits, rz_analysis_t::bits, rz_analysis_t::cur, and r.

Referenced by rz_analysis_set_bits(), rz_core_reg_flags_candidates(), and rz_print_hexword_references_handler().

◆ rz_analysis_get_fcns()

RZ_API RzList* rz_analysis_get_fcns ( RzAnalysis analysis)

Definition at line 392 of file analysis.c.

392  {
393  // avoid received to free this thing
394  analysis->fcns->free = NULL;
395  return analysis->fcns;
396 }
RzList * fcns
Definition: rz_analysis.h:565
RzListFree free
Definition: rz_list.h:21

References rz_analysis_t::fcns, rz_list_t::free, and NULL.

Referenced by rz_core_diff_show().

◆ rz_analysis_get_reg_profile()

RZ_API char* rz_analysis_get_reg_profile ( RzAnalysis analysis)

Definition at line 212 of file analysis.c.

212  {
213  return (analysis && analysis->cur && analysis->cur->get_reg_profile)
214  ? analysis->cur->get_reg_profile(analysis)
215  : NULL;
216 }
RzAnalysisRegProfGetCallback get_reg_profile
Definition: rz_analysis.h:1259

References rz_analysis_t::cur, rz_analysis_plugin_t::get_reg_profile, and NULL.

Referenced by __esil_reg_profile(), __io_reg_profile(), and rz_analysis_set_reg_profile().

◆ rz_analysis_hint_storage_fini()

void rz_analysis_hint_storage_fini ( RzAnalysis a)

Definition at line 79 of file hint.c.

79  {
80  ht_up_free(a->addr_hints);
83 }
static void arch_hint_record_free_rb(RBNode *node, void *user)
Definition: hint.c:65
static void bits_hint_record_free_rb(RBNode *node, void *user)
Definition: hint.c:61

References a, arch_hint_record_free_rb(), bits_hint_record_free_rb(), NULL, and rz_rbtree_free().

Referenced by rz_analysis_free(), and rz_analysis_hint_clear().

◆ rz_analysis_hint_storage_init()

void rz_analysis_hint_storage_init ( RzAnalysis a)

Definition at line 72 of file hint.c.

72  {
73  a->addr_hints = ht_up_new(NULL, addr_hint_record_ht_free, NULL);
74  a->arch_hints = NULL;
75  a->bits_hints = NULL;
76 }
static void addr_hint_record_ht_free(HtUPKv *kv)
Definition: hint.c:57

References a, addr_hint_record_ht_free(), and NULL.

Referenced by rz_analysis_hint_clear(), and rz_analysis_new().

◆ rz_analysis_is_noreturn()

static bool rz_analysis_is_noreturn ( RzAnalysis analysis,
const char *  name 
)
static

Definition at line 534 of file analysis.c.

534  {
535  return rz_type_func_is_noreturn(analysis->typedb, name) ||
537 }
#define K_NORET_FUNC(x)
Definition: analysis.c:464
RZ_API bool sdb_bool_get(Sdb *db, const char *str, ut32 *cas)
Definition: num.c:76
Definition: z80asm.h:102
RZ_API bool rz_type_func_is_noreturn(RzTypeDB *typedb, RZ_NONNULL const char *name)
Checks if the RzCallable type is defined as "noreturn".
Definition: function.c:503

References K_NORET_FUNC, NULL, rz_type_func_is_noreturn(), sdb_bool_get(), rz_analysis_t::sdb_noret, and rz_analysis_t::typedb.

Referenced by rz_analysis_noreturn_at_name().

◆ rz_analysis_is_prelude()

RZ_API bool rz_analysis_is_prelude ( RzAnalysis analysis,
const ut8 data,
int  len 
)

Definition at line 676 of file analysis.c.

676  {
677  RzList *l = rz_analysis_preludes(analysis);
678  if (l) {
679  RzSearchKeyword *kw;
680  RzListIter *iter;
681  rz_list_foreach (l, iter, kw) {
682  int ks = kw->keyword_length;
683  if (len >= ks && !memcmp(data, kw->bin_keyword, ks)) {
684  rz_list_free(l);
685  return true;
686  }
687  }
688  rz_list_free(l);
689  }
690  return false;
691 }
size_t len
Definition: 6502dis.c:15
RZ_API RzList * rz_analysis_preludes(RzAnalysis *analysis)
Definition: analysis.c:669

References rz_search_keyword_t::bin_keyword, rz_search_keyword_t::keyword_length, len, rz_analysis_preludes(), and rz_list_free().

Referenced by run_basic_block_analysis(), and rz_analysis_check_fcn().

◆ rz_analysis_mask()

RZ_API ut8* rz_analysis_mask ( RzAnalysis analysis,
ut32  size,
const ut8 data,
ut64  at 
)

Definition at line 334 of file analysis.c.

334  {
335  RzAnalysisOp *op = NULL;
336  ut8 *ret = NULL;
337  int oplen = 0;
338  ut32 idx = 0;
339 
340  if (!data) {
341  return NULL;
342  }
343 
344  if (analysis->cur && analysis->cur->analysis_mask) {
345  return analysis->cur->analysis_mask(analysis, size, data, at);
346  }
347 
348  if (!(op = rz_analysis_op_new())) {
349  return NULL;
350  }
351 
352  if (!(ret = malloc(size))) {
354  return NULL;
355  }
356 
357  memset(ret, 0xff, size);
358 
359  while (idx < size) {
360  if ((oplen = rz_analysis_op(analysis, op, at, data + idx, size - idx, RZ_ANALYSIS_OP_MASK_BASIC)) < 1) {
361  break;
362  }
363  if ((op->ptr != UT64_MAX || op->jump != UT64_MAX) && op->nopcode != 0) {
364  memset(ret + idx + op->nopcode, 0, oplen - op->nopcode);
365  }
366  idx += oplen;
367  at += oplen;
370  }
371 
373 
374  return ret;
375 }
uint32_t ut32
voidpf void uLong size
Definition: ioapi.h:138
return memset(p, 0, total)
void * malloc(size_t size)
Definition: malloc.c:123
int idx
Definition: setup.py:197
RZ_API void rz_analysis_op_free(void *op)
Definition: op.c:61
RZ_API bool rz_analysis_op_fini(RzAnalysisOp *op)
Definition: op.c:37
RZ_API RzAnalysisOp * rz_analysis_op_new(void)
Definition: op.c:9
RZ_API void rz_analysis_op_init(RzAnalysisOp *op)
Definition: op.c:23
ut8 *(* analysis_mask)(RzAnalysis *analysis, int size, const ut8 *data, ut64 at)
Definition: rz_analysis.h:1247

References rz_analysis_plugin_t::analysis_mask, rz_analysis_t::cur, setup::idx, malloc(), memset(), NULL, rz_analysis_op(), rz_analysis_op_fini(), rz_analysis_op_free(), rz_analysis_op_init(), RZ_ANALYSIS_OP_MASK_BASIC, rz_analysis_op_new(), and UT64_MAX.

Referenced by rz_core_analysis_bytes(), and rz_sign_flirt_node_new().

◆ rz_analysis_new()

RZ_API RzAnalysis* rz_analysis_new ( void  )

Definition at line 63 of file analysis.c.

63  {
64  int i;
65  RzAnalysis *analysis = RZ_NEW0(RzAnalysis);
66  if (!analysis) {
67  return NULL;
68  }
69  if (!rz_str_constpool_init(&analysis->constpool)) {
70  free(analysis);
71  return NULL;
72  }
73  analysis->bb_tree = NULL;
74  analysis->ht_addr_fun = ht_up_new0();
75  analysis->ht_name_fun = ht_pp_new0();
76  analysis->os = strdup(RZ_SYS_OS);
78  analysis->opt.nopskip = true; // skip nops in code analysis
79  analysis->opt.hpskip = false; // skip `mov reg,reg` and `lea reg,[reg]`
80  analysis->gp = 0LL;
81  analysis->sdb = sdb_new0();
83  analysis->opt.depth = 32;
84  analysis->opt.noncode = false; // do not analyze data by default
85  rz_spaces_init(&analysis->meta_spaces, "CS");
88 
91  analysis->typedb = rz_type_db_new();
92  analysis->type_links = ht_up_new0();
93  analysis->sdb_fmts = sdb_ns(analysis->sdb, "spec", 1);
94  analysis->sdb_cc = sdb_ns(analysis->sdb, "cc", 1);
95  analysis->sdb_classes = sdb_ns(analysis->sdb, "classes", 1);
96  analysis->sdb_classes_attrs = sdb_ns(analysis->sdb_classes, "attrs", 1);
97  analysis->sdb_noret = sdb_ns(analysis->sdb, "noreturn", 1);
98  (void)rz_analysis_xrefs_init(analysis);
99  analysis->diff_thbb = RZ_ANALYSIS_THRESHOLDBB;
100  analysis->diff_thfcn = RZ_ANALYSIS_THRESHOLDFCN;
101  analysis->syscall = rz_syscall_new();
102  analysis->arch_target = rz_platform_target_new();
104  rz_io_bind_init(analysis->iob);
105  rz_flag_bind_init(analysis->flb);
106  analysis->reg = rz_reg_new();
107  analysis->last_disasm_reg = NULL;
108  analysis->stackptr = 0;
109  analysis->lineswidth = 0;
111  analysis->leaddrs = NULL;
112  analysis->imports = rz_list_newf(free);
113  rz_analysis_set_bits(analysis, 32);
114  analysis->plugins = rz_list_newf(NULL);
115  if (analysis->plugins) {
116  for (i = 0; i < RZ_ARRAY_SIZE(analysis_static_plugins); i++) {
118  }
119  }
120  analysis->ht_global_var = ht_pp_new(NULL, global_kv_free, NULL);
121  analysis->global_var_tree = NULL;
122  analysis->il_vm = NULL;
123  analysis->hash = rz_hash_new();
124  return analysis;
125 }
RZ_API void rz_analysis_function_free(void *_fcn)
Definition: function.c:92
static void meta_count_for(RzEvent *ev, int type, void *user, void *data)
Definition: analysis.c:35
RZ_API int rz_analysis_add(RzAnalysis *analysis, RzAnalysisPlugin *p)
Definition: analysis.c:179
static void rz_meta_item_free(void *_item)
Definition: analysis.c:50
static void global_kv_free(HtPPKv *kv)
Definition: analysis.c:58
static void meta_unset_for(RzEvent *ev, int type, void *user, void *data)
Definition: analysis.c:28
RZ_API bool rz_analysis_set_bits(RzAnalysis *analysis, int bits)
Definition: analysis.c:270
static RzAnalysisPlugin * analysis_static_plugins[]
Definition: analysis.c:13
void rz_analysis_hint_storage_init(RzAnalysis *a)
Definition: hint.c:72
lzma_index ** i
Definition: index.h:629
RZ_API RzHash * rz_hash_new(void)
Definition: hash.c:585
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 Sdb * sdb_ns(Sdb *s, const char *name, int create)
Definition: ns.c:186
RZ_API RZ_OWN RzPlatformTarget * rz_platform_target_new()
Creates a new RzPlatformTarget type.
RZ_API RZ_OWN RzPlatformTargetIndex * rz_platform_target_index_new()
Creates a new RzPlatformTargetIndex type.
RZ_API RzReg * rz_reg_new(void)
Definition: reg.c:286
#define RZ_ANALYSIS_ESIL_GOTO_LIMIT
Definition: rz_analysis.h:504
@ RZ_ANALYSIS_CPP_ABI_ITANIUM
Definition: rz_analysis.h:542
RZ_API RzEventCallbackHandle rz_event_hook(RzEvent *ev, int type, RzEventCallback cb, void *user)
Definition: event.c:58
#define rz_flag_bind_init(x)
Definition: rz_flag.h:94
RZ_API void rz_interval_tree_init(RzIntervalTree *tree, RzIntervalNodeFree free)
Definition: intervaltree.c:101
#define rz_io_bind_init(x)
Definition: rz_io.h:344
@ RZ_SPACE_EVENT_COUNT
Definition: rz_spaces.h:34
@ RZ_SPACE_EVENT_UNSET
Definition: rz_spaces.h:36
RZ_API bool rz_spaces_init(RzSpaces *sp, const char *name)
Definition: spaces.c:16
RZ_API bool rz_str_constpool_init(RzStrConstPool *pool)
Definition: str_constpool.c:10
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define RZ_ARRAY_SIZE(x)
Definition: rz_types.h:300
RZ_API Sdb * sdb_new0(void)
Definition: sdb.c:43
RBTree bb_tree
Definition: rz_analysis.h:564
RzPlatformTarget * arch_target
Definition: rz_analysis.h:622
RzAnalysisCPPABI cpp_abi
Definition: rz_analysis.h:560
RzStrConstPool constpool
Definition: rz_analysis.h:620
RzList * leaddrs
Definition: rz_analysis.h:621
double diff_thfcn
Definition: rz_analysis.h:573
HtUP * ht_addr_fun
Definition: rz_analysis.h:566
HtPP * ht_name_fun
Definition: rz_analysis.h:567
HtPP * ht_global_var
Definition: rz_analysis.h:624
RzIntervalTree meta
Definition: rz_analysis.h:600
HtUP * type_links
Definition: rz_analysis.h:603
RzSpaces meta_spaces
Definition: rz_analysis.h:601
ut8 * last_disasm_reg
Definition: rz_analysis.h:569
Sdb * sdb_classes_attrs
Definition: rz_analysis.h:606
RzHash * hash
Definition: rz_analysis.h:626
RzSyscall * syscall
Definition: rz_analysis.h:570
RzFlagBind flb
Definition: rz_analysis.h:575
RzPlatformTargetIndex * platform_target
Definition: rz_analysis.h:623
double diff_thbb
Definition: rz_analysis.h:572
RzAnalysisOptions opt
Definition: rz_analysis.h:608
RzAnalysisILVM * il_vm
user-faced VM, NEVER use this for any analysis passes!
Definition: rz_analysis.h:585
Sdb * sdb_classes
Definition: rz_analysis.h:605
RBTree global_var_tree
Definition: rz_analysis.h:625
RzEvent * event
Definition: rz_spaces.h:61
RZ_API RzSyscall * rz_syscall_new(void)
Creates a new RzSyscall type.
Definition: syscall.c:67
RZ_API RzTypeDB * rz_type_db_new()
Creates a new instance of the RzTypeDB.
Definition: type.c:34
RZ_API bool rz_analysis_xrefs_init(RzAnalysis *analysis)
Definition: xrefs.c:245

References analysis_static_plugins, rz_analysis_t::arch_target, rz_analysis_t::bb_tree, rz_analysis_t::constpool, rz_analysis_t::cpp_abi, rz_analysis_options_t::depth, rz_analysis_t::diff_thbb, rz_analysis_t::diff_thfcn, rz_analysis_t::esil_goto_limit, rz_spaces_t::event, rz_analysis_t::fcns, rz_analysis_t::flb, free(), global_kv_free(), rz_analysis_t::global_var_tree, rz_analysis_t::gp, rz_analysis_t::hash, rz_analysis_options_t::hpskip, rz_analysis_t::ht_addr_fun, rz_analysis_t::ht_global_var, rz_analysis_t::ht_name_fun, i, rz_analysis_t::il_vm, rz_analysis_t::imports, rz_analysis_t::iob, rz_analysis_t::last_disasm_reg, rz_analysis_t::leaddrs, rz_analysis_t::lineswidth, rz_analysis_t::meta, meta_count_for(), rz_analysis_t::meta_spaces, meta_unset_for(), rz_analysis_options_t::noncode, rz_analysis_options_t::nopskip, NULL, rz_analysis_t::opt, rz_analysis_t::os, rz_analysis_t::platform_target, rz_analysis_t::plugins, rz_analysis_t::reg, rz_analysis_add(), RZ_ANALYSIS_CPP_ABI_ITANIUM, RZ_ANALYSIS_ESIL_GOTO_LIMIT, rz_analysis_function_free(), rz_analysis_hint_storage_init(), rz_analysis_set_bits(), rz_analysis_xrefs_init(), RZ_ARRAY_SIZE, rz_event_hook(), rz_flag_bind_init, rz_hash_new(), rz_interval_tree_init(), rz_io_bind_init, rz_list_newf(), rz_meta_item_free(), RZ_NEW0, rz_platform_target_index_new(), rz_platform_target_new(), rz_reg_new(), RZ_SPACE_EVENT_COUNT, RZ_SPACE_EVENT_UNSET, rz_spaces_init(), rz_str_constpool_init(), RZ_SYS_OS, rz_syscall_new(), rz_type_db_new(), rz_analysis_t::sdb, rz_analysis_t::sdb_cc, rz_analysis_t::sdb_classes, rz_analysis_t::sdb_classes_attrs, rz_analysis_t::sdb_fmts, sdb_new0(), rz_analysis_t::sdb_noret, sdb_ns(), rz_analysis_t::stackptr, strdup(), rz_analysis_t::syscall, rz_analysis_t::type_links, and rz_analysis_t::typedb.

Referenced by __as_new(), and rz_core_init().

◆ rz_analysis_noreturn_add()

RZ_API bool rz_analysis_noreturn_add ( RzAnalysis analysis,
const char *  name,
ut64  addr 
)

Definition at line 466 of file analysis.c.

466  {
467  const char *tmp_name = NULL;
468  Sdb *NDB = analysis->sdb_noret;
469  char *fnl_name = NULL;
470  if (addr != UT64_MAX) {
471  if (sdb_bool_set(NDB, K_NORET_ADDR(addr), true, 0)) {
473  if (fcn) {
474  fcn->is_noreturn = true;
475  }
476  return true;
477  }
478  }
479  if (name && *name) {
480  tmp_name = name;
481  } else {
482  RzAnalysisFunction *fcn = rz_analysis_get_fcn_in(analysis, addr, -1);
483  RzFlagItem *fi = analysis->flb.get_at(analysis->flb.f, addr, false);
484  if (!fcn && !fi) {
485  RZ_LOG_ERROR("Cannot find function and flag at address 0x%" PFMT64x "\n", addr);
486  return false;
487  }
488  tmp_name = fcn ? fcn->name : fi->name;
489  if (fcn) {
490  fcn->is_noreturn = true;
491  }
492  }
493  if (rz_type_func_exist(analysis->typedb, tmp_name)) {
494  fnl_name = strdup(tmp_name);
495  } else if (!(fnl_name = rz_analysis_function_name_guess(analysis->typedb, (char *)tmp_name))) {
496  if (addr == UT64_MAX) {
497  if (name) {
498  sdb_bool_set(NDB, K_NORET_FUNC(name), true, 0);
499  } else {
500  RZ_LOG_ERROR("Cannot find prototype for: %s\n", tmp_name);
501  }
502  } else {
503  RZ_LOG_ERROR("Cannot find prototype for: %s\n", tmp_name);
504  }
505  // return false;
506  }
507  if (fnl_name) {
508  sdb_bool_set(NDB, K_NORET_FUNC(fnl_name), true, 0);
509  free(fnl_name);
510  }
511  return true;
512 }
RZ_API RZ_OWN char * rz_analysis_function_name_guess(RzTypeDB *typedb, RZ_NONNULL char *name)
Checks if varions function name variations present in the database.
Definition: function.c:458
RZ_API RzAnalysisFunction * rz_analysis_get_function_at(RzAnalysis *analysis, ut64 addr)
Definition: function.c:184
#define K_NORET_ADDR(x)
Definition: analysis.c:463
RZ_API int sdb_bool_set(Sdb *db, const char *str, bool v, ut32 cas)
Definition: num.c:72
const char * name
Definition: op.c:541
RzFlagGetAt get_at
Definition: rz_flag.h:81
RzFlag * f
Definition: rz_flag.h:78
char * name
Definition: rz_flag.h:35
Definition: sdb.h:63
RZ_API bool rz_type_func_exist(RzTypeDB *typedb, RZ_NONNULL const char *name)
Checks if the RzCallable type exists in the database given the name.
Definition: function.c:203

References addr, rz_flag_bind_t::f, rz_analysis_t::flb, free(), rz_flag_bind_t::get_at, rz_analysis_function_t::is_noreturn, K_NORET_ADDR, K_NORET_FUNC, name, rz_analysis_function_t::name, rz_flag_item_t::name, NULL, PFMT64x, rz_analysis_function_name_guess(), rz_analysis_get_fcn_in(), rz_analysis_get_function_at(), RZ_LOG_ERROR, rz_type_func_exist(), sdb_bool_set(), rz_analysis_t::sdb_noret, strdup(), rz_analysis_t::typedb, and UT64_MAX.

Referenced by reanalyze_fcns_cb(), relocation_function_process_noreturn(), rz_core_analysis_propagate_noreturn(), and rz_type_list_noreturn_handler().

◆ rz_analysis_noreturn_at()

RZ_API bool rz_analysis_noreturn_at ( RzAnalysis analysis,
ut64  addr 
)

Definition at line 597 of file analysis.c.

597  {
598  if (!addr || addr == UT64_MAX) {
599  return false;
600  }
601  if (rz_analysis_noreturn_at_addr(analysis, addr)) {
602  return true;
603  }
604  /* XXX this is very slow */
606  if (f) {
607  if (rz_analysis_noreturn_at_name(analysis, f->name)) {
608  return true;
609  }
610  }
611  RzFlagItem *fi = analysis->flag_get(analysis->flb.f, addr);
612  if (fi) {
613  if (rz_analysis_noreturn_at_name(analysis, fi->realname ? fi->realname : fi->name)) {
614  return true;
615  }
616  }
617  if (analysis->recursive_noreturn) {
618  return noreturn_recurse(analysis, addr);
619  }
620  return false;
621 }
static bool rz_analysis_noreturn_at_name(RzAnalysis *analysis, const char *name)
Definition: analysis.c:539
RZ_API bool rz_analysis_noreturn_at_addr(RzAnalysis *analysis, ut64 addr)
Definition: analysis.c:557
static bool noreturn_recurse(RzAnalysis *analysis, ut64 addr)
Definition: analysis.c:561
#define f(i)
Definition: sha256.c:46
RzFlagGetAtAddr flag_get
Definition: rz_analysis.h:616
bool recursive_noreturn
Definition: rz_analysis.h:593
char * realname
Definition: rz_flag.h:36

References addr, rz_flag_bind_t::f, f, rz_analysis_t::flag_get, rz_analysis_t::flb, rz_flag_item_t::name, noreturn_recurse(), rz_flag_item_t::realname, rz_analysis_t::recursive_noreturn, rz_analysis_get_function_at(), rz_analysis_noreturn_at_addr(), rz_analysis_noreturn_at_name(), and UT64_MAX.

Referenced by noreturn_recurse(), run_basic_block_analysis(), and rz_core_debug_bp_add_noreturn_func().

◆ rz_analysis_noreturn_at_addr()

RZ_API bool rz_analysis_noreturn_at_addr ( RzAnalysis analysis,
ut64  addr 
)

◆ rz_analysis_noreturn_at_name()

static bool rz_analysis_noreturn_at_name ( RzAnalysis analysis,
const char *  name 
)
static

Definition at line 539 of file analysis.c.

539  {
540  if (rz_analysis_is_noreturn(analysis, name)) {
541  return true;
542  }
543  char *tmp = rz_analysis_function_name_guess(analysis->typedb, (char *)name);
544  if (tmp) {
545  if (rz_analysis_is_noreturn(analysis, tmp)) {
546  free(tmp);
547  return true;
548  }
549  free(tmp);
550  }
551  if (rz_str_startswith(name, "reloc.")) {
552  return rz_analysis_noreturn_at_name(analysis, name + 6);
553  }
554  return false;
555 }
static bool rz_analysis_is_noreturn(RzAnalysis *analysis, const char *name)
Definition: analysis.c:534
RZ_API bool rz_str_startswith(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string starts with a specifc sequence of characters (case sensitive)
Definition: str.c:3286

References free(), rz_analysis_function_name_guess(), rz_analysis_is_noreturn(), rz_str_startswith(), autogen_x86imm::tmp, and rz_analysis_t::typedb.

Referenced by rz_analysis_noreturn_at().

◆ rz_analysis_noreturn_drop()

RZ_API bool rz_analysis_noreturn_drop ( RzAnalysis analysis,
const char *  expr 
)

Definition at line 514 of file analysis.c.

514  {
515  Sdb *NDB = analysis->sdb_noret;
517  const char *fcnname = NULL;
518  if (!strncmp(expr, "0x", 2)) {
519  ut64 n = rz_num_math(NULL, expr);
520  sdb_unset(NDB, K_NORET_ADDR(n), 0);
521  RzAnalysisFunction *fcn = rz_analysis_get_fcn_in(analysis, n, -1);
522  if (!fcn) {
523  // eprintf ("can't find function at 0x%"PFMT64x"\n", n);
524  return false;
525  }
526  fcnname = fcn->name;
527  } else {
528  fcnname = expr;
529  }
530  sdb_unset(NDB, K_NORET_FUNC(fcnname), 0);
531  return false;
532 }
static RzNumCalcValue expr(RzNum *, RzNumCalc *, int)
Definition: calc.c:167
int n
Definition: mipsasm.c:19
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
Definition: unum.c:456
RZ_API const char * rz_str_trim_head_ro(const char *str)
Definition: str_trim.c:86
RZ_API int sdb_unset(Sdb *s, const char *key, ut32 cas)
Definition: sdb.c:294

References expr(), K_NORET_ADDR, K_NORET_FUNC, n, rz_analysis_function_t::name, NULL, rz_analysis_get_fcn_in(), rz_num_math(), rz_str_trim_head_ro(), rz_analysis_t::sdb_noret, sdb_unset(), and ut64().

◆ rz_analysis_noreturn_functions()

RZ_API RzList* rz_analysis_noreturn_functions ( RzAnalysis analysis)

Definition at line 623 of file analysis.c.

623  {
624  rz_return_val_if_fail(analysis, NULL);
625  // At first we read all noreturn functions from the Types DB
626  RzList *noretl = rz_type_noreturn_function_names(analysis->typedb);
627  // Then we propagate all noreturn functions that were inferred by
628  // the analysis process
629  SdbKv *kv;
630  SdbListIter *iter;
631  SdbList *l = sdb_foreach_list(analysis->sdb_noret, true);
632  ls_foreach (l, iter, kv) {
633  const char *k = sdbkv_key(kv);
634  if (!strncmp(k, "func.", 5) && strstr(k, ".noreturn")) {
635  char *s = strdup(k + 5);
636  char *d = strchr(s, '.');
637  if (d) {
638  *d = 0;
639  }
640  rz_list_append(noretl, strdup(s));
641  free(s);
642  }
643  if (!strncmp(k, "addr.", 5)) {
644  char *off;
645  if (!(off = strdup(k + 5))) {
646  break;
647  }
648  char *ptr = strstr(off, ".noreturn");
649  if (ptr) {
650  *ptr = 0;
651  char *addr = rz_str_newf("0x%s", off);
652  rz_list_append(noretl, addr);
653  }
654  free(off);
655  }
656  }
657  ls_free(l);
658  return noretl;
659 }
const char * k
Definition: dsignal.c:11
RZ_API void ls_free(SdbList *list)
Definition: ls.c:191
#define ls_foreach(list, it, pos)
Definition: ls.h:31
int off
Definition: pal.c:13
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API SdbList * sdb_foreach_list(Sdb *s, bool sorted)
Definition: sdb.c:630
static char * sdbkv_key(const SdbKv *kv)
Definition: sdbht.h:21
#define d(i)
Definition: sha256.c:44
Definition: ls.h:17
Definition: ls.h:22
Definition: sdbht.h:14
RZ_API RZ_OWN RzList * rz_type_noreturn_function_names(RzTypeDB *typedb)
Returns the list of all noreturn function type names.
Definition: function.c:588

References addr, d, free(), k, ls_foreach, ls_free(), NULL, off, rz_list_append(), rz_return_val_if_fail, rz_str_newf(), rz_type_noreturn_function_names(), s, sdb_foreach_list(), rz_analysis_t::sdb_noret, sdbkv_key(), strdup(), and rz_analysis_t::typedb.

Referenced by rz_core_analysis_propagate_noreturn_relocs().

◆ rz_analysis_op_hexstr()

RZ_API RzAnalysisOp* rz_analysis_op_hexstr ( RzAnalysis analysis,
ut64  addr,
const char *  str 
)

Definition at line 398 of file analysis.c.

398  {
400  if (!op) {
401  return NULL;
402  }
403  ut8 *buf = calloc(1, strlen(str) + 1);
404  if (!buf) {
405  free(op);
406  return NULL;
407  }
408  int len = rz_hex_str2bin(str, buf);
410  free(buf);
411  return op;
412 }
ut8 op
Definition: 6502dis.c:13
voidpf void * buf
Definition: ioapi.h:138
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
RZ_API int rz_hex_str2bin(const char *in, ut8 *out)
Convert an input string in into the binary form in out.
Definition: hex.c:444

References addr, calloc(), free(), len, NULL, op, rz_analysis_op(), RZ_ANALYSIS_OP_MASK_BASIC, rz_hex_str2bin(), RZ_NEW0, and cmd_descs_generate::str.

◆ rz_analysis_op_is_eob()

RZ_API bool rz_analysis_op_is_eob ( RzAnalysisOp op)

Definition at line 414 of file analysis.c.

414  {
415  if (op->eob) {
416  return true;
417  }
418  switch (op->type) {
427  return true;
428  default:
429  return false;
430  }
431 }
@ RZ_ANALYSIS_OP_TYPE_UJMP
Definition: rz_analysis.h:369
@ RZ_ANALYSIS_OP_TYPE_IJMP
Definition: rz_analysis.h:371
@ RZ_ANALYSIS_OP_TYPE_TRAP
Definition: rz_analysis.h:392
@ RZ_ANALYSIS_OP_TYPE_IRJMP
Definition: rz_analysis.h:372
@ RZ_ANALYSIS_OP_TYPE_RJMP
Definition: rz_analysis.h:370
@ RZ_ANALYSIS_OP_TYPE_CJMP
Definition: rz_analysis.h:373
@ RZ_ANALYSIS_OP_TYPE_RET
Definition: rz_analysis.h:385

References RZ_ANALYSIS_OP_TYPE_CJMP, RZ_ANALYSIS_OP_TYPE_IJMP, RZ_ANALYSIS_OP_TYPE_IRJMP, RZ_ANALYSIS_OP_TYPE_JMP, RZ_ANALYSIS_OP_TYPE_RET, RZ_ANALYSIS_OP_TYPE_RJMP, RZ_ANALYSIS_OP_TYPE_TRAP, and RZ_ANALYSIS_OP_TYPE_UJMP.

Referenced by num_callback().

◆ rz_analysis_preludes()

RZ_API RzList* rz_analysis_preludes ( RzAnalysis analysis)

Definition at line 669 of file analysis.c.

669  {
670  if (analysis->cur && analysis->cur->preludes) {
671  return analysis->cur->preludes(analysis);
672  }
673  return NULL;
674 }
RzList *(* preludes)(RzAnalysis *analysis)
Definition: rz_analysis.h:1248

References rz_analysis_t::cur, NULL, and rz_analysis_plugin_t::preludes.

Referenced by rz_analysis_is_prelude(), and rz_core_search_preludes().

◆ rz_analysis_purge()

RZ_API void rz_analysis_purge ( RzAnalysis analysis)

Definition at line 433 of file analysis.c.

433  {
434  rz_analysis_hint_clear(analysis);
435  rz_interval_tree_fini(&analysis->meta);
437  rz_type_db_purge(analysis->typedb);
438  ht_up_free(analysis->type_links);
439  analysis->type_links = ht_up_new0();
440  sdb_reset(analysis->sdb_classes);
441  sdb_reset(analysis->sdb_classes_attrs);
442  sdb_reset(analysis->sdb_cc);
443  sdb_reset(analysis->sdb_noret);
444  rz_list_free(analysis->fcns);
446  rz_analysis_purge_imports(analysis);
447 }
RZ_API void rz_analysis_purge_imports(RzAnalysis *analysis)
Definition: analysis.c:719
RZ_API void rz_analysis_hint_clear(RzAnalysis *a)
Definition: hint.c:85
RZ_API void sdb_reset(Sdb *s)
Definition: sdb.c:433
RZ_API void rz_type_db_purge(RzTypeDB *typedb)
Purges the instance of the RzTypeDB.
Definition: type.c:96

References rz_analysis_t::fcns, rz_analysis_t::meta, rz_analysis_function_free(), rz_analysis_hint_clear(), rz_analysis_purge_imports(), rz_interval_tree_fini(), rz_interval_tree_init(), rz_list_free(), rz_list_newf(), rz_meta_item_free(), rz_type_db_purge(), rz_analysis_t::sdb_cc, rz_analysis_t::sdb_classes, rz_analysis_t::sdb_classes_attrs, rz_analysis_t::sdb_noret, sdb_reset(), rz_analysis_t::type_links, and rz_analysis_t::typedb.

Referenced by rz_open_close_all_handler(), and rz_serialize_analysis_load().

◆ rz_analysis_purge_imports()

RZ_API void rz_analysis_purge_imports ( RzAnalysis analysis)

Definition at line 719 of file analysis.c.

719  {
720  rz_list_purge(analysis->imports);
721 }
RZ_API void rz_list_purge(RZ_NONNULL RzList *list)
Empties the list without freeing the list pointer.
Definition: list.c:120

References rz_analysis_t::imports, and rz_list_purge().

Referenced by rz_analysis_purge(), and rz_delete_global_imports_handler().

◆ rz_analysis_remove_import()

RZ_API void rz_analysis_remove_import ( RzAnalysis analysis,
const char *  imp 
)

Definition at line 708 of file analysis.c.

708  {
709  RzListIter *it;
710  const char *eimp;
711  rz_list_foreach (analysis->imports, it, eimp) {
712  if (!strcmp(eimp, imp)) {
713  rz_list_delete(analysis->imports, it);
714  return;
715  }
716  }
717 }
RZ_API void rz_list_delete(RZ_NONNULL RzList *list, RZ_NONNULL RzListIter *iter)
Removes an entry in the list by using the RzListIter pointer.
Definition: list.c:162

References rz_analysis_t::imports, and rz_list_delete().

◆ rz_analysis_set_big_endian()

RZ_API int rz_analysis_set_big_endian ( RzAnalysis analysis,
int  bigend 
)

Definition at line 325 of file analysis.c.

325  {
326  analysis->big_endian = bigend;
327  if (analysis->reg) {
328  analysis->reg->big_endian = bigend;
329  }
330  rz_type_db_set_endian(analysis->typedb, bigend);
331  return true;
332 }
bool big_endian
Definition: rz_reg.h:158
RZ_API void rz_type_db_set_endian(RzTypeDB *typedb, bool big_endian)
Set the RzType target architecture CPU.
Definition: type.c:202

References rz_analysis_t::big_endian, rz_reg_t::big_endian, rz_analysis_t::reg, rz_type_db_set_endian(), and rz_analysis_t::typedb.

Referenced by cb_asmarch(), cb_bigendian(), and rz_main_rz_asm().

◆ rz_analysis_set_bits()

RZ_API bool rz_analysis_set_bits ( RzAnalysis analysis,
int  bits 
)

Definition at line 270 of file analysis.c.

270  {
271  switch (bits) {
272  case 8:
273  case 16:
274  case 27:
275  case 32:
276  case 64:
277  if (analysis->bits != bits) {
278  bool is_hack = is_arm_thumb_hack(analysis, bits);
279  analysis->bits = bits;
281  analysis->pcalign = RZ_MAX(0, v);
282  rz_type_db_set_bits(analysis->typedb, bits);
284  if (!is_hack) {
285  char *types_dir = rz_path_system(RZ_SDB_TYPES);
286  rz_type_db_reload(analysis->typedb, types_dir);
287  free(types_dir);
288  }
289  rz_analysis_set_reg_profile(analysis);
290  }
291  return true;
292  }
293  return false;
294 }
static bool is_arm_thumb_hack(RzAnalysis *analysis, int bits)
Definition: analysis.c:260
RZ_API int rz_analysis_archinfo(RzAnalysis *analysis, int query)
Definition: analysis.c:449
RZ_API int rz_analysis_get_address_bits(RzAnalysis *analysis)
The actual size of an address in bits.
Definition: analysis.c:303
RZ_API bool rz_analysis_set_reg_profile(RzAnalysis *analysis)
Definition: analysis.c:218
const char * v
Definition: dsignal.c:12
#define RZ_MAX(x, y)
RZ_API void rz_type_db_set_address_bits(RzTypeDB *typedb, int addr_bits)
Set the RzType target adress size.
Definition: type.c:161
RZ_API void rz_type_db_set_bits(RzTypeDB *typedb, int bits)
Set the RzType target architecture bits.
Definition: type.c:145

References rz_analysis_t::bits, bits(), free(), is_arm_thumb_hack(), rz_analysis_t::pcalign, rz_analysis_archinfo(), RZ_ANALYSIS_ARCHINFO_ALIGN, rz_analysis_get_address_bits(), rz_analysis_set_reg_profile(), RZ_MAX, rz_path_system(), RZ_SDB_TYPES, rz_type_db_reload(), rz_type_db_set_address_bits(), rz_type_db_set_bits(), rz_analysis_t::typedb, and v.

Referenced by __as_set_archbits(), cb_asmbits(), rz_analysis_new(), rz_analysis_set_triplet(), and rz_main_rz_asm().

◆ rz_analysis_set_cpu()

RZ_API void rz_analysis_set_cpu ( RzAnalysis analysis,
const char *  cpu 
)

Definition at line 311 of file analysis.c.

311  {
312  free(analysis->cpu);
313  analysis->cpu = cpu ? strdup(cpu) : NULL;
315  if (v != -1) {
316  analysis->pcalign = v;
317  }
318  rz_analysis_set_reg_profile(analysis);
319  rz_type_db_set_cpu(analysis->typedb, cpu);
320  char *types_dir = rz_path_system(RZ_SDB_TYPES);
321  rz_type_db_reload(analysis->typedb, types_dir);
322  free(types_dir);
323 }
static ut32 cpu[32]
Definition: analysis_or1k.c:21
RZ_API void rz_type_db_set_cpu(RzTypeDB *typedb, const char *cpu)
Set the RzType target architecture CPU.
Definition: type.c:189

References cpu, rz_analysis_t::cpu, free(), NULL, rz_analysis_t::pcalign, rz_analysis_archinfo(), RZ_ANALYSIS_ARCHINFO_ALIGN, rz_analysis_set_reg_profile(), rz_path_system(), RZ_SDB_TYPES, rz_type_db_reload(), rz_type_db_set_cpu(), strdup(), rz_analysis_t::typedb, and v.

Referenced by cb_analysis_cpu(), and rz_main_rz_asm().

◆ rz_analysis_set_limits()

RZ_API void rz_analysis_set_limits ( RzAnalysis analysis,
ut64  from,
ut64  to 
)

Definition at line 15 of file analysis.c.

15  {
16  free(analysis->limit);
17  analysis->limit = RZ_NEW0(RzAnalysisRange);
18  if (analysis->limit) {
19  analysis->limit->from = from;
20  analysis->limit->to = to;
21  }
22 }
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
RzAnalysisRange * limit
Definition: rz_analysis.h:587

References free(), rz_analysis_range_t::from, from, rz_analysis_t::limit, RZ_NEW0, rz_analysis_range_t::to, and to.

Referenced by cb_analysis_from(), and cb_analysis_limits().

◆ rz_analysis_set_os()

RZ_API bool rz_analysis_set_os ( RzAnalysis analysis,
const char *  os 
)

Definition at line 256 of file analysis.c.

256  {
257  return rz_analysis_set_triplet(analysis, os, NULL, -1);
258 }
RZ_API bool rz_analysis_set_triplet(RzAnalysis *analysis, const char *os, const char *arch, int bits)
Definition: analysis.c:243

References NULL, and rz_analysis_set_triplet().

Referenced by cb_asmos().

◆ rz_analysis_set_reg_profile()

RZ_API bool rz_analysis_set_reg_profile ( RzAnalysis analysis)

Definition at line 218 of file analysis.c.

218  {
219  bool ret = false;
220  char *p = rz_analysis_get_reg_profile(analysis);
221  if (p) {
222  rz_reg_set_profile_string(analysis->reg, p);
223  ret = true;
224  }
225  free(p);
226  return ret;
227 }
RZ_API char * rz_analysis_get_reg_profile(RzAnalysis *analysis)
Definition: analysis.c:212
RZ_API bool rz_reg_set_profile_string(RZ_NONNULL RzReg *reg, RZ_NONNULL const char *profile_str)
Parses a register profile string and sets up all registers accordingly in reg.
Definition: profile.c:431

References free(), p, rz_analysis_t::reg, rz_analysis_get_reg_profile(), and rz_reg_set_profile_string().

Referenced by cb_asmbits(), rz_analysis_set_bits(), rz_analysis_set_cpu(), and rz_analysis_use().

◆ rz_analysis_set_triplet()

RZ_API bool rz_analysis_set_triplet ( RzAnalysis analysis,
const char *  os,
const char *  arch,
int  bits 
)

Definition at line 243 of file analysis.c.

243  {
244  rz_return_val_if_fail(analysis, false);
245  if (!arch || !*arch) {
246  arch = analysis->cur ? analysis->cur->arch : RZ_SYS_ARCH;
247  }
248  if (bits < 1) {
249  bits = analysis->bits;
250  }
251  analysis_set_os(analysis, os);
252  rz_analysis_set_bits(analysis, bits);
253  return rz_analysis_use(analysis, arch);
254 }
static bool analysis_set_os(RzAnalysis *analysis, const char *os)
Definition: analysis.c:229
RZ_API bool rz_analysis_use(RzAnalysis *analysis, const char *name)
Definition: analysis.c:184
cs_arch arch
Definition: cstool.c:13
#define RZ_SYS_ARCH
Definition: rz_types.h:519

References analysis_set_os(), rz_analysis_plugin_t::arch, arch, rz_analysis_t::bits, bits(), rz_analysis_t::cur, rz_analysis_set_bits(), rz_analysis_use(), rz_return_val_if_fail, and RZ_SYS_ARCH.

Referenced by rz_analysis_set_os().

◆ rz_analysis_trace_bb()

RZ_API void rz_analysis_trace_bb ( RzAnalysis analysis,
ut64  addr 
)

Definition at line 377 of file analysis.c.

377  {
378  RzAnalysisBlock *bbi;
379  RzAnalysisFunction *fcni;
380  RzListIter *iter2;
381  fcni = rz_analysis_get_fcn_in(analysis, addr, 0);
382  if (fcni) {
383  rz_list_foreach (fcni->bbs, iter2, bbi) {
384  if (addr >= bbi->addr && addr < (bbi->addr + bbi->size)) {
385  bbi->traced = true;
386  break;
387  }
388  }
389  }
390 }

References addr, rz_analysis_bb_t::addr, rz_analysis_function_t::bbs, rz_analysis_get_fcn_in(), rz_analysis_bb_t::size, and rz_analysis_bb_t::traced.

Referenced by rz_debug_trace_add().

◆ rz_analysis_unset_limits()

RZ_API void rz_analysis_unset_limits ( RzAnalysis analysis)

Definition at line 24 of file analysis.c.

24  {
25  RZ_FREE(analysis->limit);
26 }
#define RZ_FREE(x)
Definition: rz_types.h:369

References rz_analysis_t::limit, and RZ_FREE.

Referenced by cb_analysis_limits().

◆ rz_analysis_use()

RZ_API bool rz_analysis_use ( RzAnalysis analysis,
const char *  name 
)

Definition at line 184 of file analysis.c.

184  {
185  RzListIter *it;
187 
188  if (analysis) {
189  if (analysis->cur && !strcmp(analysis->cur->name, name)) {
190  return true;
191  }
192  rz_list_foreach (analysis->plugins, it, h) {
193  if (!h || !h->name || strcmp(h->name, name)) {
194  continue;
195  }
196  plugin_fini(analysis);
197  analysis->cur = h;
198  if (h->init && !h->init(&analysis->plugin_data)) {
199  RZ_LOG_ERROR("analysis plugin '%s' failed to initialize.\n", h->name);
200  return false;
201  }
202  rz_analysis_set_reg_profile(analysis);
203  if (analysis->il_vm) {
204  rz_analysis_il_vm_setup(analysis);
205  }
206  return true;
207  }
208  }
209  return false;
210 }
RZ_API bool rz_analysis_il_vm_setup(RzAnalysis *analysis)
Definition: analysis_il.c:285
#define h(i)
Definition: sha256.c:48

References rz_analysis_t::cur, h, rz_analysis_t::il_vm, rz_analysis_plugin_t::name, rz_analysis_t::plugin_data, plugin_fini(), rz_analysis_t::plugins, rz_analysis_il_vm_setup(), rz_analysis_set_reg_profile(), and RZ_LOG_ERROR.

Referenced by __as_set_archbits(), cb_analysis_arch(), rz_analysis_set_triplet(), rz_core_init(), and rz_main_rz_asm().

◆ RZ_LIB_VERSION()

RZ_LIB_VERSION ( rz_analysis  )

◆ rz_meta_item_fini()

static void rz_meta_item_fini ( RzAnalysisMetaItem item)
static

Definition at line 46 of file analysis.c.

46  {
47  free(item->str);
48 }

References free(), and rz_analysis_meta_item_t::str.

Referenced by rz_meta_item_free().

◆ rz_meta_item_free()

static void rz_meta_item_free ( void *  _item)
static

Definition at line 50 of file analysis.c.

50  {
51  if (_item) {
52  RzAnalysisMetaItem *item = _item;
53  rz_meta_item_fini(item);
54  free(item);
55  }
56 }
static void rz_meta_item_fini(RzAnalysisMetaItem *item)
Definition: analysis.c:46

References free(), and rz_meta_item_fini().

Referenced by rz_analysis_new(), and rz_analysis_purge().

Variable Documentation

◆ analysis_static_plugins

RzAnalysisPlugin* analysis_static_plugins[] = { RZ_ANALYSIS_STATIC_PLUGINS }
static

Definition at line 13 of file analysis.c.

Referenced by rz_analysis_new().