Rizin
unix-like reverse engineering framework and cli tools
core.c File Reference
#include <rz_core.h>
#include <rz_socket.h>
#include <rz_cmp.h>
#include <config.h>
#include <rz_util.h>
#include "core_private.h"

Go to the source code of this file.

Classes

struct  RzIORap
 

Macros

#define DB   core->sdb
 
#define rizin_argc   (sizeof(rizin_argv) / sizeof(const char *) - 1)
 
#define ADDARG(x)
 
#define MINLEN   1
 

Functions

 RZ_LIB_VERSION (rz_core)
 
bool rz_core_is_project (RzCore *core, const char *name)
 
RZ_API void rz_core_notify_begin (RZ_NONNULL RzCore *core, RZ_NONNULL const char *format,...)
 Prints a message definining the beginning of a task. More...
 
RZ_API void rz_core_notify_done (RZ_NONNULL RzCore *core, RZ_NONNULL const char *format,...)
 Prints a message definining the end of a task which succeeded. More...
 
RZ_API void rz_core_notify_error (RZ_NONNULL RzCore *core, RZ_NONNULL const char *format,...)
 Prints a message definining the end of a task which errored. More...
 
static int on_fcn_new (RzAnalysis *_analysis, void *_user, RzAnalysisFunction *fcn)
 
static int on_fcn_delete (RzAnalysis *_analysis, void *_user, RzAnalysisFunction *fcn)
 
static int on_fcn_rename (RzAnalysis *_analysis, void *_user, RzAnalysisFunction *fcn, const char *oname)
 
static void rz_core_debug_breakpoint_hit (RzCore *core, RzBreakpointItem *bpi)
 
static void rz_core_debug_syscall_hit (RzCore *core)
 
RZ_API RzBinRelocrz_core_getreloc (RzCore *core, ut64 addr, int size)
 
RZ_API RzBinRelocrz_core_get_reloc_to (RzCore *core, ut64 addr)
 
RZ_API ut64 rz_core_get_asmqjmps (RzCore *core, const char *str)
 
RZ_API char * rz_core_add_asmqjmp (RzCore *core, ut64 addr)
 
RZ_API void rz_core_set_asmqjmps (RzCore *core, char *str, size_t len, int pos)
 
static void setab (RzCore *core, const char *arch, int bits)
 
static const char * getName (RzCore *core, ut64 addr)
 
static char * getNameDelta (RzCore *core, ut64 addr)
 
static void archbits (RzCore *core, ut64 addr)
 
static ut64 cfggeti (RzCore *core, const char *k)
 
static const char * cfgget (RzCore *core, const char *k)
 
static bool cfgseti (RzCore *core, const char *k, ut64 v)
 
static bool cfgset (RzCore *core, const char *k, const char *v)
 
static ut64 numget (RzCore *core, const char *k)
 
static const RzList__flagsGet (RzCore *core, ut64 offset)
 
RZ_API int rz_core_bind (RzCore *core, RzCoreBind *bnd)
 
RZ_API RzCorerz_core_ncast (ut64 p)
 
RZ_API RzCorerz_core_cast (void *p)
 
static ut64 getref (RzCore *core, int n, char t, int type)
 
static ut64 bbInstructions (RzAnalysisFunction *fcn, ut64 addr)
 
static ut64 bbBegin (RzAnalysisFunction *fcn, ut64 addr)
 
static ut64 bbJump (RzAnalysisFunction *fcn, ut64 addr)
 
static ut64 bbFail (RzAnalysisFunction *fcn, ut64 addr)
 
static ut64 bbSize (RzAnalysisFunction *fcn, ut64 addr)
 
static const char * str_callback (RzNum *user, ut64 off, int *ok)
 
static ut64 num_callback (RzNum *userptr, const char *str, int *ok)
 
RZ_API RzCorerz_core_new (void)
 
static void autocomplete_process_path (RzLineCompletion *completion, const char *str, const char *path)
 
static void autocompleteFilename (RzLineCompletion *completion, RzLineBuffer *buf, char **extra_paths, int narg)
 
static void autocomplete_default (RZ_NULLABLE RzCore *core, RzLineCompletion *completion, RzLineBuffer *buf)
 
static void autocomplete_evals (RzCore *core, RzLineCompletion *completion, const char *str)
 
static void autocomplete_minus (RzCore *core, RzLineCompletion *completion, const char *str)
 
static void autocomplete_breakpoints (RzCore *core, RzLineCompletion *completion, const char *str)
 
static bool add_argv (RzFlagItem *fi, void *user)
 
static void autocomplete_flags (RzCore *core, RzLineCompletion *completion, const char *str)
 
static void autocomplete_sdb (RzCore *core, RzLineCompletion *completion, const char *str)
 
static void autocomplete_flagspaces (RzCore *core, RzLineCompletion *completion, const char *msg)
 
static void autocomplete_functions (RzCore *core, RzLineCompletion *completion, const char *str)
 
static void autocomplete_macro (RzCore *core, RzLineCompletion *completion, const char *str)
 
static void autocomplete_file (RzLineCompletion *completion, const char *str)
 
static void autocomplete_theme (RzCore *core, RzLineCompletion *completion, const char *str)
 
static bool find_e_opts (RzCore *core, RzLineCompletion *completion, RzLineBuffer *buf)
 
static bool find_autocomplete (RzCore *core, RzLineCompletion *completion, RzLineBuffer *buf)
 
RZ_API void rz_core_autocomplete (RZ_NULLABLE RzCore *core, RzLineCompletion *completion, RzLineBuffer *buf, RzLinePromptType prompt_type)
 
static RzLineNSCompletionResultrzshell_autocomplete (RzLineBuffer *buf, RzLinePromptType prompt_type, void *user)
 
RZ_API int rz_core_fgets (char *buf, int len, void *user)
 
static const char * rz_core_print_offname (void *p, ut64 addr)
 
static int rz_core_print_offsize (void *p, ut64 addr)
 
static int __disasm (void *_core, ut64 addr)
 
static void update_sdb (RzCore *core)
 
static int is_string (const ut8 *buf, int size, int *len)
 
RZ_API char * rz_core_analysis_hasrefs (RzCore *core, ut64 value, int mode)
 
static char * getvalue (ut64 value, int bits)
 
RZ_API char * rz_core_analysis_hasrefs_to_depth (RzCore *core, ut64 value, PJ *pj, int depth)
 
RZ_API char * rz_core_analysis_get_comments (RzCore *core, ut64 addr)
 
RZ_API const char * rz_core_analysis_optype_colorfor (RzCore *core, ut64 addr, bool verbose)
 
static int mywrite (const ut8 *buf, int len)
 
static bool exists_var (RzPrint *print, ut64 func_addr, char *str)
 
static bool rz_core_analysis_read_at (struct rz_analysis_t *analysis, ut64 addr, ut8 *buf, int len)
 
static void rz_core_break (RzCore *core)
 
static void * rz_core_sleep_begin (RzCore *core)
 
static void rz_core_sleep_end (RzCore *core, void *user)
 
static void __foreach (RzCore *core, const char **cmds, int type)
 
static void __init_autocomplete_default (RzCore *core)
 
static void __init_autocomplete (RzCore *core)
 
static const char * colorfor_cb (void *user, ut64 addr, bool verbose)
 
static char * hasrefs_cb (void *user, ut64 addr, int mode)
 
static const char * get_section_name (void *user, ut64 addr)
 
static char * get_comments_cb (void *user, ut64 addr)
 
static RzFlagItemcore_flg_class_set (RzFlag *f, const char *name, ut64 addr, ut32 size)
 
static RzFlagItemcore_flg_class_get (RzFlag *f, const char *name)
 
static RzFlagItemcore_flg_fcn_set (RzFlag *f, const char *name, ut64 addr, ut32 size)
 
RZ_API void rz_core_autocomplete_reload (RzCore *core)
 
RZ_API RzFlagItemrz_core_flag_get_by_spaces (RzFlag *f, ut64 off)
 
static bool bp_is_mapped (ut64 addr, int perm, void *user)
 
static void bp_maps_sync (void *user)
 
static int bp_bits_at (ut64 addr, void *user)
 
static void ev_iowrite_cb (RzEvent *ev, int type, void *user, void *data)
 
RZ_IPI void rz_core_file_io_desc_closed (RzCore *core, RzIODesc *desc)
 
RZ_IPI void rz_core_file_io_map_deleted (RzCore *core, RzIOMap *map)
 
RZ_IPI void rz_core_file_bin_file_deleted (RzCore *core, RzBinFile *bf)
 
RZ_IPI void rz_core_vfile_bin_file_deleted (RzCore *core, RzBinFile *bf)
 
static void ev_iodescclose_cb (RzEvent *ev, int type, void *user, void *data)
 
static void ev_iomapdel_cb (RzEvent *ev, int type, void *user, void *data)
 
static void ev_binfiledel_cb (RzEvent *ev, int type, void *user, void *data)
 
RZ_IPI void rz_core_task_ctx_switch (RzCoreTask *next, void *user)
 
RZ_IPI void rz_core_task_break_cb (RzCoreTask *task, void *user)
 
RZ_IPI void rz_core_file_free (RzCoreFile *cf)
 
RZ_API bool rz_core_init (RzCore *core)
 
RZ_API void __cons_cb_fkey (RzCore *core, int fkey)
 
RZ_API void rz_core_bind_cons (RzCore *core)
 
RZ_API void rz_core_fini (RzCore *c)
 
RZ_API void rz_core_free (RzCore *c)
 
RZ_API void rz_core_prompt_loop (RzCore *r)
 
static bool prompt_add_file (RzCore *core, RzStrBuf *sb, bool add_sep)
 
static bool prompt_add_section (RzCore *core, RzStrBuf *sb, bool add_sep)
 
static bool prompt_add_offset (RzCore *core, RzStrBuf *sb, bool add_sep)
 
static void set_prompt (RzCore *r)
 
RZ_API int rz_core_prompt (RzCore *r, int sync)
 
RZ_API int rz_core_prompt_exec (RzCore *r)
 
RZ_API bool rz_core_block_size (RzCore *core, ut32 bsize)
 
RZ_API char * rz_core_op_str (RzCore *core, ut64 addr)
 
RZ_API RzAnalysisOprz_core_op_analysis (RzCore *core, ut64 addr, RzAnalysisOpMask mask)
 
static void rap_break (void *u)
 
RZ_API bool rz_core_serve (RzCore *core, RzIODesc *file)
 
RZ_API int rz_core_search_cb (RzCore *core, ut64 from, ut64 to, RzCoreSearchCallback cb)
 
RZ_API RZ_OWN char * rz_core_editor (const RzCore *core, RZ_NULLABLE const char *file, RZ_NULLABLE const char *str)
 
RZ_API RzConsrz_core_get_cons (RzCore *core)
 
RZ_API RzConfigrz_core_get_config (RzCore *core)
 
RZ_API RzBinrz_core_get_bin (RzCore *core)
 
RZ_API RzBufferrz_core_syscallf (RzCore *core, const char *name, const char *fmt,...)
 
RZ_API RzBufferrz_core_syscall (RzCore *core, const char *name, const char *args)
 
RZ_API RzCoreAutocompleterz_core_autocomplete_add (RzCoreAutocomplete *parent, const char *cmd, int type, bool lock)
 
RZ_API void rz_core_autocomplete_free (RzCoreAutocomplete *obj)
 
RZ_API RzCoreAutocompleterz_core_autocomplete_find (RzCoreAutocomplete *parent, const char *cmd, bool exact)
 
RZ_API bool rz_core_autocomplete_remove (RzCoreAutocomplete *parent, const char *cmd)
 
RZ_API RzTablerz_core_table (RzCore *core)
 
RZ_API RzCmdStatus rz_core_core_plugin_print (RzCorePlugin *cp, RzCmdStateOutput *state, const char *license)
 
RZ_API RzCmdStatus rz_core_core_plugins_print (RzCore *core, RzCmdStateOutput *state)
 

Variables

static ut64 letter_divs [RZ_CORE_ASMQJMPS_LEN_LETTERS - 1]
 
static const char * rizin_argv []
 
RZ_IPI RzIOPlugin rz_core_io_plugin_vfile
 IO Plugin that opens RzBinVirtualFiles supplied by the plugin of an RzBinFile. More...
 

Macro Definition Documentation

◆ ADDARG

#define ADDARG (   x)
Value:
if (!strncmp(buf->data + chr, x, strlen(buf->data + chr))) { \
rz_line_completion_push(completion, x); \
}
voidpf void * buf
Definition: ioapi.h:138
int x
Definition: mipsasm.c:20

Definition at line 1176 of file core.c.

◆ DB

#define DB   core->sdb

Definition at line 14 of file core.c.

◆ MINLEN

#define MINLEN   1

Definition at line 1774 of file core.c.

◆ rizin_argc

#define rizin_argc   (sizeof(rizin_argv) / sizeof(const char *) - 1)

Definition at line 875 of file core.c.

Function Documentation

◆ __cons_cb_fkey()

RZ_API void __cons_cb_fkey ( RzCore core,
int  fkey 
)

Definition at line 2601 of file core.c.

2601  {
2602  char buf[32];
2603  snprintf(buf, sizeof(buf), "key.f%d", fkey);
2604  const char *v = rz_config_get(core->config, buf);
2605  if (v && *v) {
2606  rz_cons_printf("%s\n", v);
2607  rz_core_cmd0(core, v);
2608  rz_cons_flush();
2609  }
2610 }
RZ_API int rz_core_cmd0(RzCore *core, const char *cmd)
Definition: cmd.c:5428
RZ_API RZ_BORROW const char * rz_config_get(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:75
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
RZ_API void rz_cons_flush(void)
Definition: cons.c:959
const char * v
Definition: dsignal.c:12
snprintf
Definition: kernel.h:364
RzConfig * config
Definition: rz_core.h:300

References rz_core_t::config, rz_config_get(), rz_cons_flush(), rz_cons_printf(), rz_core_cmd0(), snprintf, and v.

Referenced by rz_core_bind_cons().

◆ __disasm()

static int __disasm ( void *  _core,
ut64  addr 
)
static

Disassemble one instruction at specified address.

Definition at line 1732 of file core.c.

1732  {
1733  RzCore *core = _core;
1734  ut64 prevaddr = core->offset;
1735 
1736  rz_core_seek(core, addr, true);
1737  int len = rz_core_print_disasm_instructions(core, 0, 1);
1738  rz_core_seek(core, prevaddr, true);
1739 
1740  return len;
1741 }
size_t len
Definition: 6502dis.c:15
static RzCore * _core
Definition: cmd_debug.c:1622
RZ_API int rz_core_print_disasm_instructions(RzCore *core, int nb_bytes, int nb_opcodes)
Definition: disasm.c:6030
RZ_API bool rz_core_seek(RzCore *core, ut64 addr, bool rb)
Seek to addr.
Definition: seek.c:116
ut64 offset
Definition: rz_core.h:301
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int addr
Definition: z80asm.c:58

References _core, addr, len, rz_core_t::offset, rz_core_print_disasm_instructions(), rz_core_seek(), and ut64().

Referenced by rz_core_init().

◆ __flagsGet()

static const RzList* __flagsGet ( RzCore core,
ut64  offset 
)
static

Definition at line 365 of file core.c.

365  {
366  return rz_flag_get_list(core->flags, offset);
367 }
RZ_API const RzList * rz_flag_get_list(RzFlag *f, ut64 off)
Definition: flag.c:475
voidpf uLong offset
Definition: ioapi.h:144
RzFlag * flags
Definition: rz_core.h:330

References rz_core_t::flags, and rz_flag_get_list().

Referenced by rz_core_bind().

◆ __foreach()

static void __foreach ( RzCore core,
const char **  cmds,
int  type 
)
static

Definition at line 2170 of file core.c.

2170  {
2171  int i;
2172  for (i = 0; cmds[i]; i++) {
2173  rz_core_autocomplete_add(core->autocomplete, cmds[i], type, true);
2174  }
2175 }
lzma_index ** i
Definition: index.h:629
RZ_API RzCoreAutocomplete * rz_core_autocomplete_add(RzCoreAutocomplete *parent, const char *cmd, int type, bool lock)
Definition: core.c:3366
int type
Definition: mipsasm.c:17
RzCoreAutocomplete * autocomplete
Definition: rz_core.h:380

References rz_core_t::autocomplete, i, rz_core_autocomplete_add(), and type.

Referenced by __init_autocomplete_default().

◆ __init_autocomplete()

static void __init_autocomplete ( RzCore core)
static

Definition at line 2230 of file core.c.

2230  {
2232  if (core->autocomplete_type == AUTOCOMPLETE_DEFAULT) {
2234  }
2235 }
static void __init_autocomplete_default(RzCore *core)
Definition: core.c:2177
@ AUTOCOMPLETE_DEFAULT
Definition: rz_core.h:136
#define RZ_NEW0(x)
Definition: rz_types.h:284
int autocomplete_type
Definition: rz_core.h:381

References __init_autocomplete_default(), rz_core_t::autocomplete, AUTOCOMPLETE_DEFAULT, rz_core_t::autocomplete_type, and RZ_NEW0.

Referenced by rz_core_autocomplete_reload(), and rz_core_init().

◆ __init_autocomplete_default()

static void __init_autocomplete_default ( RzCore core)
static

Definition at line 2177 of file core.c.

2177  {
2178  const char *fcns[] = {
2179  "afcf", "afn", NULL
2180  };
2181  const char *seeks[] = {
2182  "s", NULL
2183  };
2184  const char *flags[] = {
2185  "*", "s", "s+", "b", "f", "fg", "?", "?v", "ad", "bf", "c1", "db", "dbw",
2186  "f-", "fr", "tf", "/a", "/v", "/r", "/re", "aav", "aep", "aef",
2187  "afc", "axg", "axt", "axf", "dcu", "ag", "agfl", "aecu", "aesu", "aeim", NULL
2188  };
2189  const char *evals[] = {
2190  "e", "ee", "et", "e?", "e!", "ev", "evj", NULL
2191  };
2192  const char *breaks[] = {
2193  "db-", "dbc", "dbC", "dbd", "dbe", "dbs", "dbi", "dbte", "dbtd", "dbts", NULL
2194  };
2195  const char *files[] = {
2196  ".", "..", ".*", "/F", "/m", "!", "!!", "#!c", "#!v", "#!cpipe", "#!vala",
2197  "#!rust", "#!zig", "#!pipe", "#!python", "aeli", "arp", "arpg", "dmd", "drp", "drpg", "o",
2198  "idp", "idpi", "L", "obf", "o+", "oc",
2199  "rizin", "rz-agent", "rz-asm", "rz-ax", "rz-bin", "rz-diff", "rz-find", "rz-gg", "rz-hash", "rz-pm", "rz-run", "rz-sign",
2200  "cd", "ls", "on", "op", "wf", "rm", "wF", "wp", "Sd", "Sl", "to", "pm",
2201  "/m", "zos", "zfd", "zfs", "zfz", "cat", "wta", "wtf", "wxf", "dml", "vi",
2202  "less", "head", "Ps", "Pl", NULL
2203  };
2205  __foreach(core, seeks, RZ_CORE_AUTOCMPLT_SEEK);
2206  __foreach(core, fcns, RZ_CORE_AUTOCMPLT_FCN);
2207  __foreach(core, evals, RZ_CORE_AUTOCMPLT_EVAL);
2208  __foreach(core, breaks, RZ_CORE_AUTOCMPLT_BRKP);
2210 
2215  "-l", RZ_CORE_AUTOCMPLT_FILE, true);
2218  /* macros */
2221  /* just for hints */
2222  int i;
2223  for (i = 0; i < rizin_argc && rizin_argv[i]; i++) {
2224  if (!rz_core_autocomplete_find(core->autocomplete, rizin_argv[i], true)) {
2226  }
2227  }
2228 }
#define NULL
Definition: cris-opc.c:27
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 special files
Definition: file_opts.h:46
static const char * rizin_argv[]
Definition: core.c:877
#define rizin_argc
Definition: core.c:875
RZ_API RzCoreAutocomplete * rz_core_autocomplete_find(RzCoreAutocomplete *parent, const char *cmd, bool exact)
Definition: core.c:3403
static void __foreach(RzCore *core, const char **cmds, int type)
Definition: core.c:2170
@ RZ_CORE_AUTOCMPLT_FCN
Definition: rz_core.h:193
@ RZ_CORE_AUTOCMPLT_BRKP
Definition: rz_core.h:196
@ RZ_CORE_AUTOCMPLT_MACR
Definition: rz_core.h:197
@ RZ_CORE_AUTOCMPLT_DFLT
Definition: rz_core.h:189
@ RZ_CORE_AUTOCMPLT_EVAL
Definition: rz_core.h:194
@ RZ_CORE_AUTOCMPLT_FILE
Definition: rz_core.h:198
@ RZ_CORE_AUTOCMPLT_SDB
Definition: rz_core.h:202
@ RZ_CORE_AUTOCMPLT_FLAG
Definition: rz_core.h:190
@ RZ_CORE_AUTOCMPLT_MINS
Definition: rz_core.h:195
@ RZ_CORE_AUTOCMPLT_THME
Definition: rz_core.h:199
@ RZ_CORE_AUTOCMPLT_FLSP
Definition: rz_core.h:191
@ RZ_CORE_AUTOCMPLT_SEEK
Definition: rz_core.h:192
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123

References __foreach(), rz_core_t::autocomplete, files, flags, i, NULL, rizin_argc, rizin_argv, RZ_CORE_AUTOCMPLT_BRKP, RZ_CORE_AUTOCMPLT_DFLT, RZ_CORE_AUTOCMPLT_EVAL, RZ_CORE_AUTOCMPLT_FCN, RZ_CORE_AUTOCMPLT_FILE, RZ_CORE_AUTOCMPLT_FLAG, RZ_CORE_AUTOCMPLT_FLSP, RZ_CORE_AUTOCMPLT_MACR, RZ_CORE_AUTOCMPLT_MINS, RZ_CORE_AUTOCMPLT_SDB, RZ_CORE_AUTOCMPLT_SEEK, RZ_CORE_AUTOCMPLT_THME, rz_core_autocomplete_add(), and rz_core_autocomplete_find().

Referenced by __init_autocomplete().

◆ add_argv()

static bool add_argv ( RzFlagItem fi,
void *  user 
)
static

Definition at line 1247 of file core.c.

1247  {
1248  RzLineCompletion *completion = user;
1249  rz_line_completion_push(completion, fi->name);
1250  return true;
1251 }
RZ_API void rz_line_completion_push(RzLineCompletion *completion, const char *str)
Definition: line.c:79
char * name
Definition: rz_flag.h:35

References rz_flag_item_t::name, and rz_line_completion_push().

Referenced by autocomplete_flags(), and rz_core_autocomplete().

◆ archbits()

static void archbits ( RzCore core,
ut64  addr 
)
static

Definition at line 341 of file core.c.

341  {
343 }
RZ_API void rz_core_seek_arch_bits(RzCore *core, ut64 addr)
Definition: cio.c:132

References addr, and rz_core_seek_arch_bits().

Referenced by rz_core_bind().

◆ autocomplete_breakpoints()

static void autocomplete_breakpoints ( RzCore core,
RzLineCompletion completion,
const char *  str 
)
static

Definition at line 1232 of file core.c.

1232  {
1234  RzListIter *iter;
1235  RzBreakpoint *bp = core->dbg->bp;
1237  int n = strlen(str);
1238  rz_list_foreach (bp->bps, iter, b) {
1239  char *addr = rz_str_newf("0x%" PFMT64x "", b->addr);
1240  if (!strncmp(addr, str, n)) {
1241  rz_line_completion_push(completion, addr);
1242  }
1243  free(addr);
1244  }
1245 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
int n
Definition: mipsasm.c:19
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
#define PFMT64x
Definition: rz_types.h:393
#define b(i)
Definition: sha256.c:42
Definition: rz_bp.h:78
RzList * bps
Definition: rz_bp.h:93
RzDebug * dbg
Definition: rz_core.h:329
RzBreakpoint * bp
Definition: rz_debug.h:288

References addr, b, rz_debug_t::bp, rz_bp_t::bps, rz_core_t::dbg, free(), n, PFMT64x, rz_line_completion_push(), rz_return_if_fail, rz_str_newf(), and cmd_descs_generate::str.

Referenced by find_autocomplete().

◆ autocomplete_default()

static void autocomplete_default ( RZ_NULLABLE RzCore core,
RzLineCompletion completion,
RzLineBuffer buf 
)
static

Definition at line 1181 of file core.c.

1181  {
1182  RzCoreAutocomplete *a = core ? core->autocomplete : NULL;
1183  int i;
1184  if (a) {
1185  for (i = 0; i < a->n_subcmds; i++) {
1186  if (buf->data[0] == 0 || !strncmp(a->subcmds[i]->cmd, buf->data, a->subcmds[i]->length)) {
1187  rz_line_completion_push(completion, a->subcmds[i]->cmd);
1188  }
1189  }
1190  } else {
1191  for (i = 0; i < rizin_argc && rizin_argv[i]; i++) {
1192  int length = strlen(rizin_argv[i]);
1193  if (!strncmp(rizin_argv[i], buf->data, length)) {
1194  rz_line_completion_push(completion, rizin_argv[i]);
1195  }
1196  }
1197  }
1198 }
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 static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
Definition: sflib.h:133
#define a(i)
Definition: sha256.c:41

References a, i, length, NULL, rizin_argc, rizin_argv, and rz_line_completion_push().

Referenced by rz_core_autocomplete().

◆ autocomplete_evals()

static void autocomplete_evals ( RzCore core,
RzLineCompletion completion,
const char *  str 
)
static

Definition at line 1200 of file core.c.

1200  {
1202  RzConfigNode *bt;
1203  RzListIter *iter;
1204  const char *tmp = strrchr(str, ' ');
1205  if (tmp) {
1206  str = tmp + 1;
1207  }
1208  size_t n = strlen(str);
1209  rz_list_foreach (core->config->nodes, iter, bt) {
1210  if (!strncmp(bt->name, str, n)) {
1211  rz_line_completion_push(completion, bt->name);
1212  }
1213  }
1214 }
RzList * nodes
Definition: rz_config.h:56

References rz_core_t::config, n, rz_config_node_t::name, rz_config_t::nodes, rz_line_completion_push(), rz_return_if_fail, cmd_descs_generate::str, and autogen_x86imm::tmp.

Referenced by find_autocomplete().

◆ autocomplete_file()

static void autocomplete_file ( RzLineCompletion completion,
const char *  str 
)
static

Definition at line 1380 of file core.c.

1380  {
1382  char *pipe = strchr(str, '>');
1383 
1384  if (pipe) {
1385  str = rz_str_trim_head_ro(pipe + 1);
1386  }
1387  if (str && !*str) {
1388  autocomplete_process_path(completion, str, "./");
1389  } else {
1390  autocomplete_process_path(completion, str, str);
1391  }
1392 }
static void autocomplete_process_path(RzLineCompletion *completion, const char *str, const char *path)
Definition: core.c:1052
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause const char static mode static sync const char const char static newpath const char static pathname pipe
Definition: sflib.h:73
RZ_API const char * rz_str_trim_head_ro(const char *str)
Definition: str_trim.c:86

References autocomplete_process_path(), pipe, rz_return_if_fail, rz_str_trim_head_ro(), and cmd_descs_generate::str.

Referenced by find_autocomplete(), and rz_core_autocomplete().

◆ autocomplete_flags()

static void autocomplete_flags ( RzCore core,
RzLineCompletion completion,
const char *  str 
)
static

Definition at line 1253 of file core.c.

1253  {
1255  int n = strlen(str);
1256  rz_flag_foreach_prefix(core->flags, str, n, add_argv, completion);
1257 }
RZ_API void rz_flag_foreach_prefix(RzFlag *f, const char *pfx, int pfx_len, RzFlagItemCb cb, void *user)
Definition: flag.c:804
static bool add_argv(RzFlagItem *fi, void *user)
Definition: core.c:1247

References add_argv(), rz_core_t::flags, n, rz_flag_foreach_prefix(), rz_return_if_fail, and cmd_descs_generate::str.

Referenced by find_autocomplete(), and rz_core_autocomplete().

◆ autocomplete_flagspaces()

static void autocomplete_flagspaces ( RzCore core,
RzLineCompletion completion,
const char *  msg 
)
static

Definition at line 1332 of file core.c.

1332  {
1334  int length = strlen(msg);
1335  RzFlag *flag = core->flags;
1336  RzSpaceIter it;
1337  RzSpace *s;
1338  rz_flag_space_foreach(flag, it, s) {
1339  if (!strncmp(msg, s->name, length)) {
1340  rz_line_completion_push(completion, s->name);
1341  }
1342  }
1343 
1344  if (strlen(msg) == 0) {
1345  rz_line_completion_push(completion, "*");
1346  }
1347 }
static RzSocket * s
Definition: rtr.c:28
static struct sockaddr static addrlen static backlog const void msg
Definition: sfsocketcall.h:119

References rz_core_t::flags, length, msg, rz_line_completion_push(), rz_return_if_fail, and s.

Referenced by find_autocomplete().

◆ autocomplete_functions()

static void autocomplete_functions ( RzCore core,
RzLineCompletion completion,
const char *  str 
)
static

Definition at line 1349 of file core.c.

1349  {
1351  RzListIter *iter;
1352  RzAnalysisFunction *fcn;
1353  int n = strlen(str);
1354  rz_list_foreach (core->analysis->fcns, iter, fcn) {
1355  char *name = rz_core_analysis_fcn_name(core, fcn);
1356  if (!strncmp(name, str, n)) {
1357  rz_line_completion_push(completion, name);
1358  }
1359  free(name);
1360  }
1361 }
RZ_API char * rz_core_analysis_fcn_name(RzCore *core, RzAnalysisFunction *fcn)
Definition: canalysis.c:2647
Definition: z80asm.h:102
RzList * fcns
Definition: rz_analysis.h:565
RzAnalysis * analysis
Definition: rz_core.h:322

References rz_core_t::analysis, rz_analysis_t::fcns, free(), n, rz_core_analysis_fcn_name(), rz_line_completion_push(), rz_return_if_fail, and cmd_descs_generate::str.

Referenced by find_autocomplete().

◆ autocomplete_macro()

static void autocomplete_macro ( RzCore core,
RzLineCompletion completion,
const char *  str 
)
static

Definition at line 1363 of file core.c.

1363  {
1364  rz_return_if_fail(core && core->rcmd && completion && str);
1365  RzCmdMacroItem *item;
1366  RzListIter *iter;
1367  size_t n = strlen(str);
1368  rz_list_foreach (core->rcmd->macro.macros, iter, item) {
1369  char *p = item->name;
1370  if (!*str || !strncmp(str, p, n)) {
1371  char *buf = rz_str_newf("%s%s)", str, p);
1372  if (buf) {
1373  rz_line_completion_push(completion, buf);
1374  free(buf);
1375  }
1376  }
1377  }
1378 }
void * p
Definition: libc.cpp:67
RzList * macros
Definition: rz_cmd.h:148
RzCmdMacro macro
Definition: rz_cmd.h:482
RzCmd * rcmd
Definition: rz_core.h:319

References free(), rz_cmd_t::macro, rz_cmd_macro_t::macros, n, rz_cmd_macro_item_t::name, p, rz_core_t::rcmd, rz_line_completion_push(), rz_return_if_fail, rz_str_newf(), and cmd_descs_generate::str.

Referenced by find_autocomplete().

◆ autocomplete_minus()

static void autocomplete_minus ( RzCore core,
RzLineCompletion completion,
const char *  str 
)
static

Definition at line 1216 of file core.c.

1216  {
1218  int count;
1219  int length = strlen(str);
1220  char **keys = rz_cmd_alias_keys(core->rcmd, &count);
1221  if (!keys) {
1222  return;
1223  }
1224  int i;
1225  for (i = 0; i < count; i++) {
1226  if (!strncmp(keys[i], str, length)) {
1227  rz_line_completion_push(completion, keys[i]);
1228  }
1229  }
1230 }
RZ_API char ** rz_cmd_alias_keys(RzCmd *cmd, int *sz)
Definition: cmd_api.c:412
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 count
Definition: sflib.h:98
static struct @218 keys[]

References count, i, keys, length, rz_core_t::rcmd, rz_cmd_alias_keys(), rz_line_completion_push(), rz_return_if_fail, and cmd_descs_generate::str.

Referenced by find_autocomplete().

◆ autocomplete_process_path()

static void autocomplete_process_path ( RzLineCompletion completion,
const char *  str,
const char *  path 
)
static

Definition at line 1052 of file core.c.

1052  {
1053  char *lpath = NULL, *dirname = NULL, *basename = NULL;
1054  char *home = NULL, *filename = NULL, *p = NULL;
1055  int n = 0;
1056  RzList *list;
1057  RzListIter *iter;
1058 
1059  if (!path) {
1060  goto out;
1061  }
1062 
1063  lpath = rz_str_new(path);
1064 #if __WINDOWS__
1065  rz_str_replace_ch(lpath, '/', '\\', true);
1066 #endif
1067  p = (char *)rz_str_last(lpath, RZ_SYS_DIR);
1068  if (p) {
1069  *p = 0;
1070  if (p == lpath) { // /xxx
1071 #if __WINDOWS__
1072  dirname = strdup("\\.\\");
1073 #else
1074  dirname = rz_str_new(RZ_SYS_DIR);
1075 #endif
1076  } else if (lpath[0] == '~' && lpath[1]) { // ~/xxx/yyy
1077  dirname = rz_str_home(lpath + 2);
1078  } else if (lpath[0] == '~') { // ~/xxx
1079  if (!(home = rz_str_home(NULL))) {
1080  goto out;
1081  }
1082  dirname = rz_str_newf("%s%s", home, RZ_SYS_DIR);
1083  free(home);
1084  } else if (lpath[0] == '.' || lpath[0] == RZ_SYS_DIR[0]) { // ./xxx/yyy || /xxx/yyy
1085  dirname = rz_str_newf("%s%s", lpath, RZ_SYS_DIR);
1086  } else { // xxx/yyy
1087  char *fmt = ".%s%s%s";
1088 #if __WINDOWS__
1089  if (strchr(path, ':')) {
1090  fmt = "%.0s%s%s";
1091  }
1092 #endif
1093  dirname = rz_str_newf(fmt, RZ_SYS_DIR, lpath, RZ_SYS_DIR);
1094  }
1095  basename = rz_str_new(p + 1);
1096  } else { // xxx
1097  dirname = rz_str_newf(".%s", RZ_SYS_DIR);
1098  basename = rz_str_new(lpath);
1099  }
1100 
1101  if (!dirname || !basename) {
1102  goto out;
1103  }
1104 
1105  list = rz_sys_dir(dirname);
1106  n = strlen(basename);
1107  bool chgdir = !strncmp(str, "cd ", 3);
1108  if (list) {
1109  rz_list_foreach (list, iter, filename) {
1110  if (*filename == '.') {
1111  continue;
1112  }
1113  if (!basename[0] || !strncmp(filename, basename, n)) {
1114  char *tmpstring = rz_str_newf("%s%s", dirname, filename);
1115  if (rz_file_is_directory(tmpstring)) {
1116  char *s = rz_str_newf("%s%s", tmpstring, RZ_SYS_DIR);
1117  rz_line_completion_push(completion, s);
1118  free(s);
1119  } else if (!chgdir) {
1120  rz_line_completion_push(completion, tmpstring);
1121  }
1122  free(tmpstring);
1123  }
1124  }
1125  rz_list_free(list);
1126  }
1127 out:
1128  free(lpath);
1129  free(dirname);
1130  free(basename);
1131 }
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
static static fork const void static count static fd const char const char static newpath const char static path const char path
Definition: sflib.h:35
const char * filename
Definition: ioapi.h:137
#define basename
Definition: libiberty.h:109
static void list(RzEgg *egg)
Definition: rz-gg.c:52
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
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 bool rz_file_is_directory(const char *str)
Definition: file.c:167
RZ_API char * rz_str_new(const char *str)
Definition: str.c:865
RZ_API char * rz_str_home(const char *str)
Definition: str.c:354
RZ_API const char * rz_str_last(const char *in, const char *ch)
Definition: str.c:3565
RZ_API int rz_str_replace_ch(char *s, char a, char b, bool g)
Definition: str.c:139
RZ_API RzList * rz_sys_dir(const char *path)
Definition: sys.c:216
#define RZ_SYS_DIR
Definition: rz_types.h:218

References basename, free(), list(), n, NULL, out, p, path, rz_file_is_directory(), rz_line_completion_push(), rz_list_free(), rz_str_home(), rz_str_last(), rz_str_new(), rz_str_newf(), rz_str_replace_ch(), RZ_SYS_DIR, rz_sys_dir(), s, cmd_descs_generate::str, and strdup().

Referenced by autocomplete_file(), and autocompleteFilename().

◆ autocomplete_sdb()

static void autocomplete_sdb ( RzCore core,
RzLineCompletion completion,
const char *  str 
)
static

Definition at line 1260 of file core.c.

1260  {
1261  rz_return_if_fail(core && completion && str);
1262  char *pipe = strchr(str, '>');
1263  Sdb *sdb = core->sdb;
1264  char *lpath = NULL, *p1 = NULL, *out = NULL, *p2 = NULL;
1265  char *cur_pos = NULL, *cur_cmd = NULL, *next_cmd = NULL;
1266  char *temp_cmd = NULL, *temp_pos = NULL, *key = NULL;
1267  if (pipe) {
1268  str = rz_str_trim_head_ro(pipe + 1);
1269  }
1270  lpath = rz_str_new(str);
1271  p1 = strchr(lpath, '/');
1272  if (p1) {
1273  *p1 = 0;
1274  char *ns = p1 + 1;
1275  p2 = strchr(ns, '/');
1276  if (!p2) { // analysis/m
1277  char *tmp = p1 + 1;
1278  int n = strlen(tmp);
1279  out = sdb_querys(sdb, NULL, 0, "analysis/**");
1280  if (!out) {
1281  return;
1282  }
1283  while (*out) {
1284  cur_pos = strchr(out, '\n');
1285  if (!cur_pos) {
1286  break;
1287  }
1288  cur_cmd = rz_str_ndup(out, cur_pos - out);
1289  if (!strncmp(tmp, cur_cmd, n)) {
1290  char *cmplt = rz_str_newf("analysis/%s/", cur_cmd);
1291  rz_line_completion_push(completion, cmplt);
1292  free(cmplt);
1293  }
1294  out += cur_pos - out + 1;
1295  }
1296 
1297  } else { // analysis/meta/*
1298  char *tmp = p2 + 1;
1299  int n = strlen(tmp);
1300  char *spltr = strchr(ns, '/');
1301  *spltr = 0;
1302  next_cmd = rz_str_newf("analysis/%s/*", ns);
1303  out = sdb_querys(sdb, NULL, 0, next_cmd);
1304  if (!out) {
1305  free(lpath);
1306  return;
1307  }
1308  while (*out) {
1309  temp_pos = strchr(out, '\n');
1310  if (!temp_pos) {
1311  break;
1312  }
1313  temp_cmd = rz_str_ndup(out, temp_pos - out); // contains the key=value pair
1314  key = strchr(temp_cmd, '=');
1315  *key = 0;
1316  if (!strncmp(tmp, temp_cmd, n)) {
1317  char *cmplt = rz_str_newf("analysis/%s/%s", ns, temp_cmd);
1318  rz_line_completion_push(completion, cmplt);
1319  free(cmplt);
1320  }
1321  out += temp_pos - out + 1;
1322  }
1323  }
1324  } else {
1325  int n = strlen(lpath);
1326  if (!strncmp(lpath, "analysis", n)) {
1327  rz_line_completion_push(completion, "analysis/");
1328  }
1329  }
1330 }
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
Definition: sflib.h:118
RZ_API char * sdb_querys(Sdb *r, char *buf, size_t len, const char *_cmd)
Definition: query.c:164
RZ_API char * rz_str_ndup(RZ_NULLABLE const char *ptr, int len)
Create new copy of string ptr limited to size len.
Definition: str.c:1006
Sdb * sdb
Definition: rz_core.h:365
Definition: sdb.h:63

References free(), key, n, NULL, out, pipe, rz_line_completion_push(), rz_return_if_fail, rz_str_ndup(), rz_str_new(), rz_str_newf(), rz_str_trim_head_ro(), rz_core_t::sdb, sdb_querys(), cmd_descs_generate::str, and autogen_x86imm::tmp.

Referenced by find_autocomplete().

◆ autocomplete_theme()

static void autocomplete_theme ( RzCore core,
RzLineCompletion completion,
const char *  str 
)
static

Definition at line 1394 of file core.c.

1394  {
1396  int len = strlen(str);
1397  char *theme;
1398  RzListIter *iter;
1399  RzList *themes = rz_core_theme_list(core);
1400  rz_list_foreach (themes, iter, theme) {
1401  if (!len || !strncmp(str, theme, len)) {
1402  rz_line_completion_push(completion, theme);
1403  }
1404  }
1405  rz_list_free(themes);
1406 }
RZ_API RZ_OWN RzList * rz_core_theme_list(RZ_NONNULL RzCore *core)
Returns the list of the rizin themes.
Definition: cmd_eval.c:119

References len, rz_core_theme_list(), rz_line_completion_push(), rz_list_free(), rz_return_if_fail, and cmd_descs_generate::str.

Referenced by find_autocomplete().

◆ autocompleteFilename()

static void autocompleteFilename ( RzLineCompletion completion,
RzLineBuffer buf,
char **  extra_paths,
int  narg 
)
static

Definition at line 1133 of file core.c.

1133  {
1134  char *args = NULL, *input = NULL;
1135  int n = 0, i = 0;
1136  char *pipe = strchr(buf->data, '>');
1137  if (pipe) {
1138  args = rz_str_new(pipe + 1);
1139  } else {
1140  args = rz_str_new(buf->data);
1141  }
1142  if (!args) {
1143  goto out;
1144  }
1145 
1146  n = rz_str_word_set0(args);
1147  if (n < narg) {
1148  goto out;
1149  }
1150 
1152  if (!input) {
1153  goto out;
1154  }
1155  const char *tinput = rz_str_trim_head_ro(input);
1156 
1157  autocomplete_process_path(completion, buf->data, tinput);
1158 
1159  if (input[0] == '/' || input[0] == '.' || !extra_paths) {
1160  goto out;
1161  }
1162 
1163  for (i = 0; extra_paths[i]; i++) {
1164  char *s = rz_str_newf("%s%s%s", extra_paths[i], RZ_SYS_DIR, tinput);
1165  if (!s) {
1166  break;
1167  }
1168  autocomplete_process_path(completion, buf->data, s);
1169  free(s);
1170  }
1171 out:
1172  free(args);
1173  free(input);
1174 }
int args
Definition: mipsasm.c:18
RZ_API int rz_str_word_set0(char *str)
Definition: str.c:423
RZ_API const char * rz_str_word_get0(const char *str, int idx)
Definition: str.c:598
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)

References args, autocomplete_process_path(), free(), i, input(), n, NULL, out, pipe, rz_str_new(), rz_str_newf(), rz_str_trim_head_ro(), rz_str_word_get0(), rz_str_word_set0(), RZ_SYS_DIR, and s.

Referenced by rz_core_autocomplete().

◆ bbBegin()

static ut64 bbBegin ( RzAnalysisFunction fcn,
ut64  addr 
)
static

Definition at line 440 of file core.c.

440  {
441  RzListIter *iter;
442  RzAnalysisBlock *bb;
443  rz_list_foreach (fcn->bbs, iter, bb) {
444  if (RZ_BETWEEN(bb->addr, addr, bb->addr + bb->size - 1)) {
445  return bb->addr;
446  }
447  }
448  return UT64_MAX;
449 }
#define UT64_MAX
Definition: rz_types_base.h:86
#define RZ_BETWEEN(x, y, z)

References addr, rz_analysis_bb_t::addr, rz_analysis_function_t::bbs, RZ_BETWEEN, rz_analysis_bb_t::size, and UT64_MAX.

Referenced by num_callback().

◆ bbFail()

static ut64 bbFail ( RzAnalysisFunction fcn,
ut64  addr 
)
static

Definition at line 462 of file core.c.

462  {
463  RzListIter *iter;
464  RzAnalysisBlock *bb;
465  rz_list_foreach (fcn->bbs, iter, bb) {
466  if (RZ_BETWEEN(bb->addr, addr, bb->addr + bb->size - 1)) {
467  return bb->fail;
468  }
469  }
470  return UT64_MAX;
471 }

References addr, rz_analysis_bb_t::addr, rz_analysis_function_t::bbs, rz_analysis_bb_t::fail, RZ_BETWEEN, rz_analysis_bb_t::size, and UT64_MAX.

Referenced by num_callback().

◆ bbInstructions()

static ut64 bbInstructions ( RzAnalysisFunction fcn,
ut64  addr 
)
static

Definition at line 429 of file core.c.

429  {
430  RzListIter *iter;
431  RzAnalysisBlock *bb;
432  rz_list_foreach (fcn->bbs, iter, bb) {
433  if (RZ_BETWEEN(bb->addr, addr, bb->addr + bb->size - 1)) {
434  return bb->ninstr;
435  }
436  }
437  return UT64_MAX;
438 }

References addr, rz_analysis_bb_t::addr, rz_analysis_function_t::bbs, rz_analysis_bb_t::ninstr, RZ_BETWEEN, rz_analysis_bb_t::size, and UT64_MAX.

Referenced by num_callback().

◆ bbJump()

static ut64 bbJump ( RzAnalysisFunction fcn,
ut64  addr 
)
static

Definition at line 451 of file core.c.

451  {
452  RzListIter *iter;
453  RzAnalysisBlock *bb;
454  rz_list_foreach (fcn->bbs, iter, bb) {
455  if (RZ_BETWEEN(bb->addr, addr, bb->addr + bb->size - 1)) {
456  return bb->jump;
457  }
458  }
459  return UT64_MAX;
460 }

References addr, rz_analysis_bb_t::addr, rz_analysis_function_t::bbs, rz_analysis_bb_t::jump, RZ_BETWEEN, rz_analysis_bb_t::size, and UT64_MAX.

Referenced by num_callback().

◆ bbSize()

static ut64 bbSize ( RzAnalysisFunction fcn,
ut64  addr 
)
static

Definition at line 473 of file core.c.

473  {
474  RzListIter *iter;
475  RzAnalysisBlock *bb;
476  rz_list_foreach (fcn->bbs, iter, bb) {
477  if (RZ_BETWEEN(bb->addr, addr, bb->addr + bb->size - 1)) {
478  return bb->size;
479  }
480  }
481  return 0;
482 }

References addr, rz_analysis_bb_t::addr, rz_analysis_function_t::bbs, RZ_BETWEEN, and rz_analysis_bb_t::size.

Referenced by num_callback().

◆ bp_bits_at()

static int bp_bits_at ( ut64  addr,
void *  user 
)
static

Definition at line 2335 of file core.c.

2335  {
2336  RzCore *core = user;
2337  int r = 0;
2338  rz_core_arch_bits_at(core, addr, &r, NULL);
2339  return r ? r : core->analysis->bits;
2340 }
RZ_API void rz_core_arch_bits_at(RzCore *core, ut64 addr, RZ_OUT RZ_NULLABLE int *bits, RZ_OUT RZ_BORROW RZ_NULLABLE const char **arch)
Definition: cio.c:97
#define r
Definition: crypto_rc6.c:12

References addr, rz_core_t::analysis, rz_analysis_t::bits, NULL, r, and rz_core_arch_bits_at().

Referenced by rz_core_init().

◆ bp_is_mapped()

static bool bp_is_mapped ( ut64  addr,
int  perm,
void *  user 
)
static

Definition at line 2307 of file core.c.

2307  {
2308  RzCore *core = user;
2309  if (rz_core_is_debug(core)) {
2310  // RzList *maps = core->dbg->maps;
2311  RzDebugMap *map = NULL;
2312  RzListIter *iter = NULL;
2313 
2314  rz_list_foreach (core->dbg->maps, iter, map) {
2315  if (addr < map->addr || addr >= map->addr_end) {
2316  continue;
2317  }
2318  if (perm <= 0 || (map->perm & perm)) {
2319  return true;
2320  }
2321  }
2322  return false;
2323  }
2324 
2325  return rz_io_map_is_mapped(core->io, addr);
2326 }
RZ_API bool rz_core_is_debug(RzCore *core)
Check whether the core is in debug mode (equivalent to cfg.debug)
Definition: cdebug.c:13
size_t map(int syms, int left, int len)
Definition: enough.c:237
RZ_API bool rz_io_map_is_mapped(RzIO *io, ut64 addr)
Definition: io_map.c:181
RzIO * io
Definition: rz_core.h:313
RzList * maps
Definition: rz_debug.h:306

References addr, rz_core_t::dbg, rz_core_t::io, map(), rz_debug_t::maps, NULL, rz_core_is_debug(), and rz_io_map_is_mapped().

Referenced by rz_core_init().

◆ bp_maps_sync()

static void bp_maps_sync ( void *  user)
static

Definition at line 2328 of file core.c.

2328  {
2329  RzCore *core = user;
2330  if (rz_core_is_debug(core)) {
2331  rz_debug_map_sync(core->dbg);
2332  }
2333 }
RZ_API bool rz_debug_map_sync(RzDebug *dbg)
Definition: dmap.c:33

References rz_core_t::dbg, rz_core_is_debug(), and rz_debug_map_sync().

Referenced by rz_core_init().

◆ cfgget()

static const char* cfgget ( RzCore core,
const char *  k 
)
static

Definition at line 349 of file core.c.

349  {
350  return rz_config_get(core->config, k);
351 }
const char * k
Definition: dsignal.c:11

References rz_core_t::config, k, and rz_config_get().

Referenced by rz_core_bind().

◆ cfggeti()

static ut64 cfggeti ( RzCore core,
const char *  k 
)
static

Definition at line 345 of file core.c.

345  {
346  return rz_config_get_i(core->config, k);
347 }
RZ_API ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:119

References rz_core_t::config, k, and rz_config_get_i().

Referenced by rz_core_bind().

◆ cfgset()

static bool cfgset ( RzCore core,
const char *  k,
const char *  v 
)
static

Definition at line 357 of file core.c.

357  {
358  return rz_config_set(core->config, k, v);
359 }
RZ_API RzConfigNode * rz_config_set(RzConfig *cfg, RZ_NONNULL const char *name, const char *value)
Definition: config.c:267

References rz_core_t::config, k, rz_config_set(), and v.

Referenced by rz_core_bind().

◆ cfgseti()

static bool cfgseti ( RzCore core,
const char *  k,
ut64  v 
)
static

Definition at line 353 of file core.c.

353  {
354  return rz_config_set_i(core->config, k, v);
355 }
RZ_API RzConfigNode * rz_config_set_i(RzConfig *cfg, RZ_NONNULL const char *name, const ut64 i)
Definition: config.c:419

References rz_core_t::config, k, rz_config_set_i(), and v.

Referenced by rz_core_bind().

◆ colorfor_cb()

static const char* colorfor_cb ( void *  user,
ut64  addr,
bool  verbose 
)
static

Definition at line 2237 of file core.c.

2237  {
2239 }
RZ_API const char * rz_core_analysis_optype_colorfor(RzCore *core, ut64 addr, bool verbose)
Definition: core.c:2108
static int verbose
Definition: z80asm.c:73

References addr, rz_core_analysis_optype_colorfor(), and verbose.

Referenced by rz_core_init().

◆ core_flg_class_get()

static RzFlagItem* core_flg_class_get ( RzFlag f,
const char *  name 
)
static

Definition at line 2260 of file core.c.

2260  {
2261  rz_flag_space_push(f, RZ_FLAGS_FS_CLASSES);
2262  RzFlagItem *res = rz_flag_get(f, name);
2263  rz_flag_space_pop(f);
2264  return res;
2265 }
RZ_API RzFlagItem * rz_flag_get(RzFlag *f, const char *name)
Definition: flag.c:310
#define RZ_FLAGS_FS_CLASSES
Definition: rz_core.h:57
#define f(i)
Definition: sha256.c:46

References f, rz_flag_get(), and RZ_FLAGS_FS_CLASSES.

Referenced by rz_core_init().

◆ core_flg_class_set()

static RzFlagItem* core_flg_class_set ( RzFlag f,
const char *  name,
ut64  addr,
ut32  size 
)
static

Definition at line 2253 of file core.c.

2253  {
2254  rz_flag_space_push(f, RZ_FLAGS_FS_CLASSES);
2255  RzFlagItem *res = rz_flag_set(f, name, addr, size);
2256  rz_flag_space_pop(f);
2257  return res;
2258 }
RZ_API RzFlagItem * rz_flag_set(RzFlag *f, const char *name, ut64 off, ut32 size)
Definition: flag.c:521
voidpf void uLong size
Definition: ioapi.h:138

References addr, f, rz_flag_set(), and RZ_FLAGS_FS_CLASSES.

Referenced by rz_core_init().

◆ core_flg_fcn_set()

static RzFlagItem* core_flg_fcn_set ( RzFlag f,
const char *  name,
ut64  addr,
ut32  size 
)
static

Definition at line 2267 of file core.c.

2267  {
2268  rz_flag_space_push(f, RZ_FLAGS_FS_FUNCTIONS);
2269  RzFlagItem *res = rz_flag_set(f, name, addr, size);
2270  rz_flag_space_pop(f);
2271  return res;
2272 }
#define RZ_FLAGS_FS_FUNCTIONS
Definition: rz_core.h:58

References addr, f, rz_flag_set(), and RZ_FLAGS_FS_FUNCTIONS.

Referenced by rz_core_init().

◆ ev_binfiledel_cb()

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

Definition at line 2369 of file core.c.

2369  {
2370  RzEventBinFileDel *bev = data;
2371  rz_core_file_bin_file_deleted(user, bev->bf);
2372  rz_core_vfile_bin_file_deleted(user, bev->bf);
2373 }
RZ_IPI void rz_core_vfile_bin_file_deleted(RzCore *core, RzBinFile *bf)
Definition: cvfile.c:156
RZ_IPI void rz_core_file_bin_file_deleted(RzCore *core, RzBinFile *bf)
Definition: cfile.c:1290

References rz_core_file_bin_file_deleted(), and rz_core_vfile_bin_file_deleted().

Referenced by rz_core_init().

◆ ev_iodescclose_cb()

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

Definition at line 2359 of file core.c.

2359  {
2360  RzEventIODescClose *ioc = data;
2361  rz_core_file_io_desc_closed(user, ioc->desc);
2362 }
RZ_IPI void rz_core_file_io_desc_closed(RzCore *core, RzIODesc *desc)
Definition: cfile.c:1271

References rz_event_io_desc_close_t::desc, and rz_core_file_io_desc_closed().

Referenced by rz_core_init().

◆ ev_iomapdel_cb()

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

Definition at line 2364 of file core.c.

2364  {
2365  RzEventIOMapDel *iod = data;
2366  rz_core_file_io_map_deleted(user, iod->map);
2367 }
RZ_IPI void rz_core_file_io_map_deleted(RzCore *core, RzIOMap *map)
Definition: cfile.c:1280
RzIOMap * map
Definition: rz_io.h:186

References rz_event_io_map_del_t::map, and rz_core_file_io_map_deleted().

Referenced by rz_core_init().

◆ ev_iowrite_cb()

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

Definition at line 2342 of file core.c.

2342  {
2343  RzCore *core = user;
2344  RzEventIOWrite *iow = data;
2345  if (rz_config_get_i(core->config, "analysis.detectwrites")) {
2347  if (core->cons->event_resize && core->cons->event_data) {
2348  // Force a reload of the graph
2349  core->cons->event_resize(core->cons->event_data);
2350  }
2351  }
2352 }
RZ_API void rz_analysis_update_analysis_range(RzAnalysis *analysis, ut64 addr, int size)
Definition: fcn.c:2396
RzConsEvent event_resize
Definition: rz_cons.h:522
void * event_data
Definition: rz_cons.h:523
RzCons * cons
Definition: rz_core.h:312

References rz_event_io_write_t::addr, rz_core_t::analysis, rz_core_t::config, rz_core_t::cons, rz_cons_t::event_data, rz_cons_t::event_resize, rz_event_io_write_t::len, rz_analysis_update_analysis_range(), and rz_config_get_i().

Referenced by rz_core_init().

◆ exists_var()

static bool exists_var ( RzPrint print,
ut64  func_addr,
char *  str 
)
static

Definition at line 2139 of file core.c.

2139  {
2140  RzAnalysis *analysis = ((RzCore *)(print->user))->analysis;
2141  RzAnalysisFunction *fcn = rz_analysis_get_function_at(analysis, func_addr);
2142  if (!fcn) {
2143  return false;
2144  }
2146 }
RZ_API RzAnalysisFunction * rz_analysis_get_function_at(RzAnalysis *analysis, ut64 addr)
Definition: function.c:184
void * user
Definition: rz_print.h:110
RZ_API RZ_BORROW RzAnalysisVar * rz_analysis_function_get_var_byname(RzAnalysisFunction *fcn, const char *name)
Definition: var.c:247

References rz_analysis_function_get_var_byname(), rz_analysis_get_function_at(), cmd_descs_generate::str, and rz_print_t::user.

Referenced by rz_core_init().

◆ find_autocomplete()

static bool find_autocomplete ( RzCore core,
RzLineCompletion completion,
RzLineBuffer buf 
)
static

Definition at line 1456 of file core.c.

1456  {
1457  RzCoreAutocomplete *child = NULL;
1458  RzCoreAutocomplete *parent = core->autocomplete;
1459  const char *p = buf->data;
1460  if (!*p) {
1461  return false;
1462  }
1463  char arg[256];
1464  arg[0] = 0;
1465  while (*p) {
1466  const char *e = rz_str_trim_head_wp(p);
1467  if (!e || (e - p) >= 256 || e == p) {
1468  return false;
1469  }
1470  memcpy(arg, p, e - p);
1471  arg[e - p] = 0;
1472  child = rz_core_autocomplete_find(parent, arg, false);
1473  if (child && child->length < buf->length && p[child->length] == ' ') {
1474  // if is spaced then i can provide the
1475  // next subtree as suggestion..
1476  p = rz_str_trim_head_ro(p + child->length);
1477  if (child->type == RZ_CORE_AUTOCMPLT_OPTN) {
1478  continue;
1479  }
1480  parent = child;
1481  } else {
1482  break;
1483  }
1484  }
1485  int i;
1486  /* if something went wrong this will prevent bad behavior */
1487  rz_line_completion_clear(completion);
1488  switch (parent->type) {
1490  autocomplete_functions(core, completion, p);
1491  // fallthrough
1493  autocomplete_flags(core, completion, p);
1494  break;
1496  autocomplete_flagspaces(core, completion, p);
1497  break;
1498  case RZ_CORE_AUTOCMPLT_FCN:
1499  autocomplete_functions(core, completion, p);
1500  break;
1502  autocomplete_evals(core, completion, p);
1503  break;
1505  autocomplete_minus(core, completion, p);
1506  break;
1508  autocomplete_breakpoints(core, completion, p);
1509  break;
1511  autocomplete_macro(core, completion, p);
1512  break;
1514  autocomplete_file(completion, p);
1515  break;
1517  autocomplete_theme(core, completion, p);
1518  break;
1519  case RZ_CORE_AUTOCMPLT_SDB:
1520  autocomplete_sdb(core, completion, p);
1521  break;
1523  // handled before
1524  break;
1525  default:
1526  if (rz_config_get_i(core->config, "cfg.newtab")) {
1528  for (i = 0; arg[i] && desc; i++) {
1529  ut8 c = arg[i];
1530  desc = c < RZ_ARRAY_SIZE(desc->sub) ? desc->sub[c] : NULL;
1531  }
1532  if (desc && desc->help_msg) {
1533  rz_core_cmd_help(core, desc->help_msg);
1534  rz_cons_flush();
1535  return true;
1536  }
1537  // fallback to command listing
1538  }
1539  int length = strlen(arg);
1540  for (i = 0; i < parent->n_subcmds; i++) {
1541  if (!strncmp(arg, parent->subcmds[i]->cmd, length)) {
1542  rz_line_completion_push(completion, parent->subcmds[i]->cmd);
1543  }
1544  }
1545  break;
1546  }
1547  return true;
1548 }
#define e(frag)
const char * desc
Definition: bin_vsf.c:19
RZ_API void rz_core_cmd_help(const RzCore *core, const char *help[])
Definition: cmd.c:163
uint8_t ut8
Definition: lh5801.h:11
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static void autocomplete_flags(RzCore *core, RzLineCompletion *completion, const char *str)
Definition: core.c:1253
static void autocomplete_theme(RzCore *core, RzLineCompletion *completion, const char *str)
Definition: core.c:1394
static void autocomplete_file(RzLineCompletion *completion, const char *str)
Definition: core.c:1380
static void autocomplete_minus(RzCore *core, RzLineCompletion *completion, const char *str)
Definition: core.c:1216
static void autocomplete_functions(RzCore *core, RzLineCompletion *completion, const char *str)
Definition: core.c:1349
static void autocomplete_flagspaces(RzCore *core, RzLineCompletion *completion, const char *msg)
Definition: core.c:1332
static void autocomplete_evals(RzCore *core, RzLineCompletion *completion, const char *str)
Definition: core.c:1200
static void autocomplete_macro(RzCore *core, RzLineCompletion *completion, const char *str)
Definition: core.c:1363
static void autocomplete_breakpoints(RzCore *core, RzLineCompletion *completion, const char *str)
Definition: core.c:1232
static void autocomplete_sdb(RzCore *core, RzLineCompletion *completion, const char *str)
Definition: core.c:1260
RZ_API void rz_line_completion_clear(RzLineCompletion *completion)
Definition: line.c:109
@ RZ_CORE_AUTOCMPLT_OPTN
Definition: rz_core.h:200
RZ_API const char * rz_str_trim_head_wp(const char *str)
Definition: str_trim.c:95
#define RZ_ARRAY_SIZE(x)
Definition: rz_types.h:300
#define c(i)
Definition: sha256.c:43
struct rz_core_autocomplete_t ** subcmds
Definition: rz_core.h:213
const char * cmd
Definition: rz_core.h:208
RzCmdDescriptor root_cmd_descriptor
Definition: rz_core.h:320

References rz_core_t::autocomplete, autocomplete_breakpoints(), autocomplete_evals(), autocomplete_file(), autocomplete_flags(), autocomplete_flagspaces(), autocomplete_functions(), autocomplete_macro(), autocomplete_minus(), autocomplete_sdb(), autocomplete_theme(), c, rz_core_autocomplete_t::cmd, rz_core_t::config, desc, e, i, rz_core_autocomplete_t::length, length, memcpy(), rz_core_autocomplete_t::n_subcmds, NULL, p, rz_core_t::root_cmd_descriptor, RZ_ARRAY_SIZE, rz_config_get_i(), rz_cons_flush(), RZ_CORE_AUTOCMPLT_BRKP, RZ_CORE_AUTOCMPLT_EVAL, RZ_CORE_AUTOCMPLT_FCN, RZ_CORE_AUTOCMPLT_FILE, RZ_CORE_AUTOCMPLT_FLAG, RZ_CORE_AUTOCMPLT_FLSP, RZ_CORE_AUTOCMPLT_MACR, RZ_CORE_AUTOCMPLT_MINS, RZ_CORE_AUTOCMPLT_OPTN, RZ_CORE_AUTOCMPLT_SDB, RZ_CORE_AUTOCMPLT_SEEK, RZ_CORE_AUTOCMPLT_THME, rz_core_autocomplete_find(), rz_core_cmd_help(), rz_line_completion_clear(), rz_line_completion_push(), rz_str_trim_head_ro(), rz_str_trim_head_wp(), rz_core_autocomplete_t::subcmds, and rz_core_autocomplete_t::type.

Referenced by rz_core_autocomplete().

◆ find_e_opts()

static bool find_e_opts ( RzCore core,
RzLineCompletion completion,
RzLineBuffer buf 
)
static

Definition at line 1408 of file core.c.

1408  {
1409  const char *pattern = "e (.*)=";
1410  RzRegex *rx = rz_regex_new(pattern, "e");
1411  const size_t nmatch = 2;
1412  RzRegexMatch pmatch[2] = { 0 };
1413  bool ret = false;
1414 
1415  if (rz_regex_exec(rx, buf->data, nmatch, pmatch, 1)) {
1416  goto out;
1417  }
1418  int i;
1419  char *str = NULL, *sp;
1420  for (i = pmatch[1].rm_so; i < pmatch[1].rm_eo; i++) {
1421  str = rz_str_appendch(str, buf->data[i]);
1422  }
1423  if (!str) {
1424  goto out;
1425  }
1426  if ((sp = strchr(str, ' '))) {
1427  // if the name contains a space, just null
1428  *sp = 0;
1429  }
1430  RzConfigNode *node = rz_config_node_get(core->config, str);
1431  if (sp) {
1432  // if nulled, then restore.
1433  *sp = ' ';
1434  }
1435  if (!node) {
1436  return false;
1437  }
1438  RzListIter *iter;
1439  char *option;
1440  char *p = (char *)strchr(buf->data, '=');
1441  p = rz_str_ichr(p + 1, ' ');
1442  int n = strlen(p);
1443  rz_list_foreach (node->options, iter, option) {
1444  if (!strncmp(option, p, n)) {
1445  rz_line_completion_push(completion, option);
1446  }
1447  }
1448  completion->opt = true;
1449  ret = true;
1450 
1451 out:
1452  rz_regex_free(rx);
1453  return ret;
1454 }
RZ_API RZ_BORROW RzConfigNode * rz_config_node_get(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:48
RZ_API RzRegex * rz_regex_new(const char *pattern, const char *cflags)
Definition: regcomp.c:183
RZ_API int rz_regex_exec(const RzRegex *preg, const char *string, size_t nmatch, RzRegexMatch __pmatch[], int eflags)
Definition: regexec.c:149
RZ_API void rz_regex_free(RzRegex *)
Definition: regcomp.c:249
RZ_API char * rz_str_ichr(char *str, char chr)
Definition: str.c:660
RZ_API char RZ_API char * rz_str_appendch(char *x, char y)
Definition: str.c:1105
Definition: getopt.h:84
RzList * options
Definition: rz_config.h:47
st64 rm_eo
Definition: rz_regex.h:18
static int option
Definition: vmenus.c:2426
static int sp
Definition: z80asm.c:91

References rz_core_t::config, i, n, NULL, rz_line_comp_t::opt, option, rz_config_node_t::options, out, p, rz_regmatch_t::rm_eo, rz_config_node_get(), rz_line_completion_push(), rz_regex_exec(), rz_regex_free(), rz_regex_new(), rz_str_appendch(), rz_str_ichr(), sp, and cmd_descs_generate::str.

Referenced by rz_core_autocomplete().

◆ get_comments_cb()

static char* get_comments_cb ( void *  user,
ut64  addr 
)
static

Definition at line 2249 of file core.c.

2249  {
2250  return rz_core_analysis_get_comments((RzCore *)user, addr);
2251 }
RZ_API char * rz_core_analysis_get_comments(RzCore *core, ut64 addr)
Definition: core.c:2091

References addr, and rz_core_analysis_get_comments().

Referenced by rz_core_init().

◆ get_section_name()

static const char* get_section_name ( void *  user,
ut64  addr 
)
static

Definition at line 2245 of file core.c.

2245  {
2246  return rz_core_get_section_name((RzCore *)user, addr);
2247 }
RZ_API const char * rz_core_get_section_name(RzCore *core, ut64 addr)
Definition: disasm.c:457

References addr, and rz_core_get_section_name().

Referenced by rz_core_init().

◆ getName()

static const char* getName ( RzCore core,
ut64  addr 
)
static

Definition at line 314 of file core.c.

314  {
315  RzFlagItem *item = rz_flag_get_i(core->flags, addr);
316  if (item) {
317  if (core->flags->realnames) {
318  return item->realname
319  ? item->realname
320  : item->name;
321  }
322  return item->name;
323  }
324  return NULL;
325 }
RZ_API RzFlagItem * rz_flag_get_i(RzFlag *f, ut64 off)
Definition: flag.c:317
char * realname
Definition: rz_flag.h:36
bool realnames
Definition: rz_flag.h:49

References addr, rz_core_t::flags, rz_flag_item_t::name, NULL, rz_flag_item_t::realname, rz_flag_t::realnames, and rz_flag_get_i().

Referenced by rz_core_bind().

◆ getNameDelta()

static char* getNameDelta ( RzCore core,
ut64  addr 
)
static

Definition at line 327 of file core.c.

327  {
328  RzFlagItem *item = rz_flag_get_at(core->flags, addr, true);
329  if (item) {
330  if (item->offset != addr) {
331  const char *name = core->flags->realnames
332  ? item->realname
333  : item->name;
334  return rz_str_newf("%s+%" PFMT64u, name, addr - item->offset);
335  }
336  return strdup(item->name);
337  }
338  return NULL;
339 }
RZ_API RzFlagItem * rz_flag_get_at(RzFlag *f, ut64 off, bool closest)
Definition: flag.c:404
#define PFMT64u
Definition: rz_types.h:395
ut64 offset
Definition: rz_flag.h:38

References addr, rz_core_t::flags, rz_flag_item_t::name, NULL, rz_flag_item_t::offset, PFMT64u, rz_flag_item_t::realname, rz_flag_t::realnames, rz_flag_get_at(), rz_str_newf(), and strdup().

Referenced by rz_core_bind().

◆ getref()

static ut64 getref ( RzCore core,
int  n,
char  t,
int  type 
)
static

Definition at line 400 of file core.c.

400  {
402  RzListIter *iter;
403  RzAnalysisXRef *r;
404  RzList *list;
405  int i = 0;
406  if (!fcn) {
407  return UT64_MAX;
408  }
409  if (t == 'r') {
411  } else {
413  }
414  rz_list_foreach (list, iter, r) {
415  if (r->type == type) {
416  if (i == n) {
417  ut64 addr = t == 'r' ? r->to : r->from;
419  return addr;
420  }
421  i++;
422  }
423  }
425 
426  return UT64_MAX;
427 }
RZ_DEPRECATE RZ_API RzAnalysisFunction * rz_analysis_get_fcn_in(RzAnalysis *analysis, ut64 addr, int type)
Definition: fcn.c:1687
RZ_API RzList * rz_analysis_function_get_xrefs_to(RzAnalysisFunction *fcn)
Definition: xrefs.c:302
RZ_API RzList * rz_analysis_function_get_xrefs_from(RzAnalysisFunction *fcn)
Definition: xrefs.c:297

References addr, rz_core_t::analysis, i, list(), n, rz_core_t::offset, r, rz_analysis_function_get_xrefs_from(), rz_analysis_function_get_xrefs_to(), rz_analysis_get_fcn_in(), rz_list_free(), type, ut64(), and UT64_MAX.

Referenced by num_callback().

◆ getvalue()

static char* getvalue ( ut64  value,
int  bits 
)
static

Definition at line 1820 of file core.c.

1820  {
1821  switch (bits) {
1822  case 16: // umf, not in sync with pxr
1823  {
1824  st16 v = (st16)(value & UT16_MAX);
1825  st16 h = UT16_MAX / 0x100;
1826  if (v > -h && v < h) {
1827  return rz_str_newf("%hd", v);
1828  }
1829  } break;
1830  case 32: {
1831  st32 v = (st32)(value & UT32_MAX);
1832  st32 h = UT32_MAX / 0x10000;
1833  if (v > -h && v < h) {
1834  return rz_str_newf("%d", v);
1835  }
1836  } break;
1837  case 64: {
1838  st64 v = (st64)(value);
1839  st64 h = UT64_MAX / 0x1000000;
1840  if (v > -h && v < h) {
1841  return rz_str_newf("%" PFMT64d, v);
1842  }
1843  } break;
1844  }
1845  return NULL;
1846 }
int bits(struct state *s, int need)
Definition: blast.c:72
static int value
Definition: cmd_api.c:93
#define PFMT64d
Definition: rz_types.h:394
#define st64
Definition: rz_types_base.h:10
#define UT32_MAX
Definition: rz_types_base.h:99
#define st16
Definition: rz_types_base.h:14
#define st32
Definition: rz_types_base.h:12
#define UT16_MAX
#define h(i)
Definition: sha256.c:48

References bits(), h, NULL, PFMT64d, rz_str_newf(), st16, st32, st64, UT16_MAX, UT32_MAX, UT64_MAX, v, and value.

Referenced by rz_core_analysis_hasrefs_to_depth().

◆ hasrefs_cb()

static char* hasrefs_cb ( void *  user,
ut64  addr,
int  mode 
)
static

Definition at line 2241 of file core.c.

2241  {
2242  return rz_core_analysis_hasrefs((RzCore *)user, addr, mode);
2243 }
const char int mode
Definition: ioapi.h:137
RZ_API char * rz_core_analysis_hasrefs(RzCore *core, ut64 value, int mode)
Definition: core.c:1805

References addr, and rz_core_analysis_hasrefs().

Referenced by rz_core_init().

◆ is_string()

static int is_string ( const ut8 buf,
int  size,
int len 
)
static

Definition at line 1775 of file core.c.

1775  {
1776  int i;
1777  if (size < 1) {
1778  return 0;
1779  }
1780  if (size > 3 && buf[0] && !buf[1] && buf[2] && !buf[3]) {
1781  *len = 1; // XXX: TODO: Measure wide string length
1782  return 2; // is wide
1783  }
1784  for (i = 0; i < size; i++) {
1785  if (!buf[i] && i > MINLEN) {
1786  *len = i;
1787  return 1;
1788  }
1789  if (buf[i] == 10 || buf[i] == 13 || buf[i] == 9) {
1790  continue;
1791  }
1792  if (buf[i] < 32 || buf[i] > 127) {
1793  // not ascii text
1794  return 0;
1795  }
1796  if (!IS_PRINTABLE(buf[i])) {
1797  *len = i;
1798  return 0;
1799  }
1800  }
1801  *len = i;
1802  return 1;
1803 }
#define MINLEN
Definition: core.c:1774
#define IS_PRINTABLE(x)
Definition: rz_str_util.h:10

References i, IS_PRINTABLE, len, and MINLEN.

Referenced by rz_core_analysis_hasrefs_to_depth().

◆ mywrite()

static int mywrite ( const ut8 buf,
int  len 
)
static

Definition at line 2135 of file core.c.

2135  {
2136  return rz_cons_memcat((const char *)buf, len);
2137 }
RZ_API int rz_cons_memcat(const char *str, int len)
Definition: cons.c:1224

References len, and rz_cons_memcat().

Referenced by rz_core_init().

◆ num_callback()

static ut64 num_callback ( RzNum userptr,
const char *  str,
int ok 
)
static

Definition at line 501 of file core.c.

501  {
502  RzCore *core = (RzCore *)userptr; // XXX ?
503  RzAnalysisFunction *fcn;
504  char *ptr, *bptr, *out = NULL;
505  RzFlagItem *flag;
506  RzBinSection *s;
508  ut64 ret = 0;
509 
510  if (ok) {
511  *ok = false;
512  }
513  switch (*str) {
514  case '.':
515  if (str[1] == '.') {
516  if (ok) {
517  *ok = true;
518  }
519  return rz_num_tail(core->num, core->offset, str + 2);
520  }
521  if (core->num->nc.curr_tok == '+') {
522  ut64 off = core->num->nc.number_value.n;
523  if (!off) {
524  off = core->offset;
525  }
527  if (fcn) {
528  if (ok) {
529  *ok = true;
530  }
532  if (dst == UT64_MAX) {
533  dst = fcn->addr;
534  }
535  st64 delta = dst - off;
536  if (delta < 0) {
537  core->num->nc.curr_tok = '-';
538  delta = off - dst;
539  }
540  return delta;
541  }
542  }
543  break;
544  case '[': {
545  ut64 n = 0LL;
546  int refsz = core->rasm->bits / 8;
547  const char *p = NULL;
548  if (strlen(str) > 5) {
549  p = strchr(str + 5, ':');
550  }
551  if (p) {
552  refsz = atoi(str + 1);
553  str = p;
554  }
555  // push state
556  if (str[0] && str[1]) {
557  const char *q;
558  char *o = strdup(str + 1);
559  if (o) {
560  q = rz_num_calc_index(core->num, NULL);
561  if (q) {
562  if (rz_str_replace_char(o, ']', 0) > 0) {
563  n = rz_num_math(core->num, o);
564  if (core->num->nc.errors) {
565  return 0;
566  }
567  rz_num_calc_index(core->num, q);
568  }
569  }
570  free(o);
571  }
572  } else {
573  return 0;
574  }
575  // pop state
576  if (ok) {
577  *ok = 1;
578  }
579  ut8 buf[sizeof(ut64)] = RZ_EMPTY;
580  (void)rz_io_read_at(core->io, n, buf, RZ_MIN(sizeof(buf), refsz));
581  switch (refsz) {
582  case 8:
583  return rz_read_ble64(buf, core->print->big_endian);
584  case 4:
585  return rz_read_ble32(buf, core->print->big_endian);
586  case 2:
587  return rz_read_ble16(buf, core->print->big_endian);
588  case 1:
589  return rz_read_ble8(buf);
590  default:
591  eprintf("Invalid reference size: %d (%s)\n", refsz, str);
592  return 0LL;
593  }
594  } break;
595  case '$':
596  if (ok) {
597  *ok = 1;
598  }
599  // TODO: group analop-dependant vars after a char, so i can filter
601  rz_analysis_op_fini(&op); // we don't need strings or pointers, just values, which are not nullified in fini
602  // XXX the above line is assuming op after fini keeps jump, fail, ptr, val, size and rz_analysis_op_is_eob()
603  switch (str[1]) {
604  case '.': // can use pc, sp, a0, a1, ...
605  return rz_debug_reg_get(core->dbg, str + 2);
606  case 'k': // $k{kv}
607  if (str[2] != '{') {
608  eprintf("Expected '{' after 'k'.\n");
609  break;
610  }
611  bptr = strdup(str + 3);
612  ptr = strchr(bptr, '}');
613  if (!ptr) {
614  // invalid json
615  free(bptr);
616  break;
617  }
618  *ptr = '\0';
619  ret = 0LL;
620  out = sdb_querys(core->sdb, NULL, 0, bptr);
621  if (out && *out) {
622  if (strstr(out, "$k{")) {
623  eprintf("Recursivity is not permitted here\n");
624  } else {
625  ret = rz_num_math(core->num, out);
626  }
627  }
628  free(bptr);
629  free(out);
630  return ret;
631  case '{': // ${ev} eval var
632  bptr = strdup(str + 2);
633  ptr = strchr(bptr, '}');
634  if (ptr) {
635  ptr[0] = '\0';
636  ut64 ret = rz_config_get_i(core->config, bptr);
637  free(bptr);
638  return ret;
639  }
640  // take flag here
641  free(bptr);
642  break;
643  case 'c': // $c console width
644  return rz_cons_get_size(NULL);
645  case 'r': // $r
646  if (str[2] == '{') {
647  bptr = strdup(str + 3);
648  ptr = strchr(bptr, '}');
649  if (!ptr) {
650  free(bptr);
651  break;
652  }
653  *ptr = 0;
654  return rz_core_reg_getv_by_role_or_name(core, bptr);
655  free(bptr);
656  return 0; // UT64_MAX;
657  } else {
658  int rows;
659  (void)rz_cons_get_size(&rows);
660  return rows;
661  }
662  break;
663  case 'e': // $e
664  if (str[2] == '{') { // $e{flag} flag off + size
665  char *flagName = strdup(str + 3);
666  int flagLength = strlen(flagName);
667  if (flagLength > 0) {
668  flagName[flagLength - 1] = 0;
669  }
670  RzFlagItem *flag = rz_flag_get(core->flags, flagName);
671  free(flagName);
672  if (flag) {
673  return flag->offset + flag->size;
674  }
675  return UT64_MAX;
676  }
677  return rz_analysis_op_is_eob(&op);
678  case 'j': // $j jump address
679  return op.jump;
680  case 'p': // $p
681  return rz_sys_getpid();
682  case 'P': // $P
683  return core->dbg->pid > 0 ? core->dbg->pid : 0;
684  case 'f': // $f jump fail address
685  if (str[2] == 'l') { // $fl flag length
686  RzFlagItem *fi = rz_flag_get_i(core->flags, core->offset);
687  if (fi) {
688  return fi->size;
689  }
690  return 0;
691  }
692  return op.fail;
693  case 'm': // $m memref
694  return op.ptr;
695  case 'B': // $B base address
696  case 'M': { // $M map address
697  ut64 lower = UT64_MAX;
698  ut64 size = 0LL;
699  RzIOMap *map = rz_io_map_get(core->io, core->offset);
700  if (map) {
701  lower = rz_itv_begin(map->itv);
702  size = rz_itv_size(map->itv);
703  }
704 
705  if (str[1] == 'B') {
706  /* clear lower bits of the lowest map address to define the base address */
707  const int clear_bits = 16;
708  lower >>= clear_bits;
709  lower <<= clear_bits;
710  }
711  if (str[2] == 'M') {
712  return size;
713  }
714  return (lower == UT64_MAX) ? 0LL : lower;
715  } break;
716  case 'v': // $v immediate value
717  return op.val;
718  case 'l': // $l opcode length
719  return op.size;
720  case 'b': // $b
721  return core->blocksize;
722  case 's': // $s file size
723  if (str[2] == '{') { // $s{flag} flag size
724  bptr = strdup(str + 3);
725  ptr = strchr(bptr, '}');
726  if (!ptr) {
727  // invalid json
728  free(bptr);
729  break;
730  }
731  *ptr = '\0';
732  RzFlagItem *flag = rz_flag_get(core->flags, bptr);
733  ret = flag ? flag->size : 0LL; // flag
734  free(bptr);
735  free(out);
736  return ret;
737  } else if (core->file) {
738  return rz_io_fd_size(core->io, core->file->fd);
739  }
740  return 0LL;
741  case 'w': // $w word size
742  return rz_config_get_i(core->config, "asm.bits") / 8;
743  case 'S': // $S section offset
744  {
745  RzBinObject *bo = rz_bin_cur_object(core->bin);
746  if (bo && (s = rz_bin_get_section_at(bo, core->offset, true))) {
747  return (str[2] == 'S' ? s->size : s->vaddr);
748  }
749  }
750  return 0LL;
751  case 'D': // $D
752  if (str[2] == 'B') { // $DD
753  return rz_debug_get_baddr(core->dbg, NULL);
754  } else if (IS_DIGIT(str[2])) {
755  return getref(core, atoi(str + 2), 'r', RZ_ANALYSIS_XREF_TYPE_DATA);
756  } else {
757  RzDebugMap *map;
758  RzListIter *iter;
759  rz_list_foreach (core->dbg->maps, iter, map) {
760  if (core->offset >= map->addr && core->offset < map->addr_end) {
761  return (str[2] == 'D') ? map->size : map->addr;
762  }
763  }
764  }
765  return 0LL; // maybe // return UT64_MAX;
766  case '?': // $?
767  return core->num->value; // rc;
768  case '$': // $$ offset
769  return str[2] == '$' ? core->prompt_offset : core->offset;
770  case 'o': { // $o
772  return s ? core->offset - s->vaddr + s->paddr : core->offset;
773  break;
774  }
775  case 'O': // $O
776  if (core->print->cur_enabled) {
777  return core->offset + core->print->cur;
778  }
779  return core->offset;
780  case 'C': // $C nth call
781  return getref(core, atoi(str + 2), 'r', RZ_ANALYSIS_XREF_TYPE_CALL);
782  case 'J': // $J nth jump
783  return getref(core, atoi(str + 2), 'r', RZ_ANALYSIS_XREF_TYPE_CODE);
784  case 'X': // $X nth xref
785  return getref(core, atoi(str + 2), 'x', RZ_ANALYSIS_XREF_TYPE_CALL);
786  case 'F': // $F function size
787  fcn = rz_analysis_get_fcn_in(core->analysis, core->offset, 0);
788  if (fcn) {
789  switch (str[2]) {
790  /* function bounds (uppercase) */
791  case 'B': return fcn->addr; // begin
792  case 'E': return rz_analysis_function_max_addr(fcn); // end
793  case 'S': return (str[3] == 'S') ? rz_analysis_function_realsize(fcn) : rz_analysis_function_linear_size(fcn);
794  case 'I': return fcn->ninstr;
795  /* basic blocks (lowercase) */
796  case 'b': return bbBegin(fcn, core->offset);
797  case 'e': return bbBegin(fcn, core->offset) + bbSize(fcn, core->offset);
798  case 'i': return bbInstructions(fcn, core->offset);
799  case 's': return bbSize(fcn, core->offset);
800  case 'j': return bbJump(fcn, core->offset); // jump
801  case 'f': return bbFail(fcn, core->offset); // fail
802  }
803  return fcn->addr;
804  }
805  return 0;
806  }
807  break;
808  default:
809  if (*str >= 'A') {
810  // NOTE: functions override flags
812  if (fcn) {
813  if (ok) {
814  *ok = true;
815  }
816  return fcn->addr;
817  }
818 #if 0
819  ut64 addr = rz_analysis_fcn_label_get (core->analysis, core->offset, str);
820  if (addr != 0) {
821  ret = addr;
822  } else {
823  ...
824  }
825 #endif
826  if ((flag = rz_flag_get(core->flags, str))) {
827  ret = flag->offset;
828  if (ok) {
829  *ok = true;
830  }
831  return ret;
832  }
833 
834  // check for reg alias
835  RzReg *reg = rz_core_reg_default(core);
836  struct rz_reg_item_t *r = rz_reg_get(reg, str, -1);
837  if (!r) {
838  int role = rz_reg_get_name_idx(str);
839  if (role != -1) {
840  const char *alias = rz_reg_get_name(reg, role);
841  if (alias) {
842  r = rz_reg_get(reg, alias, -1);
843  if (r) {
844  if (ok) {
845  *ok = true;
846  }
847  ret = rz_reg_get_value(reg, r);
848  return ret;
849  }
850  }
851  }
852  } else {
853  if (ok) {
854  *ok = true;
855  }
856  ret = rz_reg_get_value(reg, r);
857  return ret;
858  }
859  }
860  break;
861  }
862 
863  return ret;
864 }
ut8 op
Definition: 6502dis.c:13
RZ_API ut64 rz_analysis_function_max_addr(RzAnalysisFunction *fcn)
Definition: function.c:328
RZ_API ut64 rz_analysis_function_linear_size(RzAnalysisFunction *fcn)
Definition: function.c:318
RZ_API ut64 rz_analysis_function_realsize(const RzAnalysisFunction *fcn)
Definition: function.c:338
RZ_API bool rz_analysis_op_is_eob(RzAnalysisOp *op)
Definition: analysis.c:414
RZ_API RzBinObject * rz_bin_cur_object(RzBin *bin)
Definition: bin.c:900
RZ_API RZ_BORROW RzBinSection * rz_bin_get_section_at(RzBinObject *o, ut64 off, int va)
Find the binary section at offset off.
Definition: bin.c:611
RZ_API int rz_cons_get_size(int *rows)
Definition: cons.c:1446
RZ_API RzReg * rz_core_reg_default(RzCore *core)
Get the currently relevant RzReg.
Definition: creg.c:17
RZ_API ut64 rz_core_reg_getv_by_role_or_name(RzCore *core, const char *name)
rz_reg_getv_by_role_or_name() on rz_core_reg_default()
Definition: creg.c:24
RZ_API ut64 rz_debug_reg_get(RzDebug *dbg, const char *name)
Definition: dreg.c:99
RZ_API RzAnalysisFunction * rz_analysis_get_function_byname(RzAnalysis *a, const char *name)
Definition: fcn.c:1729
RZ_API ut64 rz_analysis_function_get_label(RzAnalysisFunction *fcn, const char *name)
Definition: labels.c:9
#define reg(n)
static ut64 getref(RzCore *core, int n, char t, int type)
Definition: core.c:400
static ut64 bbSize(RzAnalysisFunction *fcn, ut64 addr)
Definition: core.c:473
static ut64 bbJump(RzAnalysisFunction *fcn, ut64 addr)
Definition: core.c:451
static ut64 bbInstructions(RzAnalysisFunction *fcn, ut64 addr)
Definition: core.c:429
static ut64 bbBegin(RzAnalysisFunction *fcn, ut64 addr)
Definition: core.c:440
static ut64 bbFail(RzAnalysisFunction *fcn, ut64 addr)
Definition: core.c:462
RZ_API ut64 rz_debug_get_baddr(RzDebug *dbg, const char *file)
Definition: debug.c:1682
@ ok
Definition: lz4.c:1706
char * dst
Definition: lz4.h:724
RZ_API bool rz_analysis_op_fini(RzAnalysisOp *op)
Definition: op.c:37
RZ_API int rz_analysis_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *data, int len, RzAnalysisOpMask mask)
Definition: op.c:96
int off
Definition: pal.c:13
RZ_API RzRegItem * rz_reg_get(RzReg *reg, const char *name, int type)
Definition: reg.c:344
RZ_API const char * rz_reg_get_name(RzReg *reg, int role)
Definition: reg.c:147
RZ_API int rz_reg_get_name_idx(const char *type)
Definition: reg.c:102
#define eprintf(x, y...)
Definition: rlcc.c:7
RZ_API ut64 rz_reg_get_value(RzReg *reg, RzRegItem *item)
Definition: rvalue.c:114
@ RZ_ANALYSIS_XREF_TYPE_CODE
Definition: rz_analysis.h:900
@ RZ_ANALYSIS_XREF_TYPE_CALL
Definition: rz_analysis.h:901
@ RZ_ANALYSIS_XREF_TYPE_DATA
Definition: rz_analysis.h:902
@ RZ_ANALYSIS_OP_MASK_BASIC
Definition: rz_analysis.h:440
static ut64 rz_read_ble64(const void *src, bool big_endian)
Definition: rz_endian.h:501
static ut8 rz_read_ble8(const void *src)
Definition: rz_endian.h:12
static ut32 rz_read_ble32(const void *src, bool big_endian)
Definition: rz_endian.h:497
static ut16 rz_read_ble16(const void *src, bool big_endian)
Definition: rz_endian.h:493
RZ_API ut64 rz_io_fd_size(RzIO *io, int fd)
Definition: io_fd.c:42
RZ_API bool rz_io_read_at(RzIO *io, ut64 addr, ut8 *buf, int len)
Definition: io.c:300
RZ_API RzIOMap * rz_io_map_get(RzIO *io, ut64 addr)
Definition: io_map.c:176
static ut64 rz_itv_begin(RzInterval itv)
Definition: rz_itv.h:34
static ut64 rz_itv_size(RzInterval itv)
Definition: rz_itv.h:38
RZ_API ut64 rz_num_tail(RzNum *num, ut64 addr, const char *hex)
Definition: unum.c:775
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
Definition: unum.c:456
RZ_API const char * rz_num_calc_index(RzNum *num, const char *p)
Definition: calc.c:288
RZ_API int rz_str_replace_char(char *s, int a, int b)
Definition: str.c:169
#define IS_DIGIT(x)
Definition: rz_str_util.h:11
RZ_API int rz_sys_getpid(void)
Definition: sys.c:1164
#define RZ_EMPTY
Definition: rz_types_base.h:68
#define RZ_MIN(x, y)
int bits
Definition: rz_asm.h:100
RzBin * bin
Definition: rz_core.h:298
RzAsm * rasm
Definition: rz_core.h:323
RzNum * num
Definition: rz_core.h:316
ut64 prompt_offset
Definition: rz_core.h:302
ut8 * block
Definition: rz_core.h:305
RzPrint * print
Definition: rz_core.h:327
RzCoreFile * file
Definition: rz_core.h:314
ut32 blocksize
Definition: rz_core.h:303
RzNumCalcValue number_value
Definition: rz_num.h:48
RzNumCalcToken curr_tok
Definition: rz_num.h:47
int errors
Definition: rz_num.h:50
RzNumCalc nc
division by zero happened
Definition: rz_num.h:67
ut64 value
Definition: rz_num.h:63
int big_endian
Definition: rz_print.h:124
bool cur_enabled
Definition: rz_print.h:130
Definition: dis.c:32
static st64 delta
Definition: vmenus.c:2425

References addr, rz_analysis_function_t::addr, rz_core_t::analysis, bbBegin(), bbFail(), bbInstructions(), bbJump(), bbSize(), rz_print_t::big_endian, rz_core_t::bin, rz_asm_t::bits, rz_core_t::block, rz_core_t::blocksize, rz_core_t::config, rz_print_t::cur, rz_print_t::cur_enabled, rz_num_calc_t::curr_tok, rz_core_t::dbg, delta, dst, eprintf, rz_num_calc_t::errors, rz_core_file_t::fd, rz_core_t::file, rz_core_t::flags, free(), getref(), rz_core_t::io, IS_DIGIT, map(), rz_debug_t::maps, n, RzNumCalcValue::n, rz_num_t::nc, rz_analysis_function_t::ninstr, NULL, rz_core_t::num, rz_num_calc_t::number_value, off, rz_core_t::offset, rz_flag_item_t::offset, ok, op, out, p, rz_debug_t::pid, rz_core_t::print, rz_core_t::prompt_offset, r, rz_core_t::rasm, reg, rz_analysis_function_get_label(), rz_analysis_function_linear_size(), rz_analysis_function_max_addr(), rz_analysis_function_realsize(), rz_analysis_get_fcn_in(), rz_analysis_get_function_at(), rz_analysis_get_function_byname(), rz_analysis_op(), rz_analysis_op_fini(), rz_analysis_op_is_eob(), RZ_ANALYSIS_OP_MASK_BASIC, RZ_ANALYSIS_XREF_TYPE_CALL, RZ_ANALYSIS_XREF_TYPE_CODE, RZ_ANALYSIS_XREF_TYPE_DATA, rz_bin_cur_object(), rz_bin_get_section_at(), rz_config_get_i(), rz_cons_get_size(), rz_core_reg_default(), rz_core_reg_getv_by_role_or_name(), rz_debug_get_baddr(), rz_debug_reg_get(), RZ_EMPTY, rz_flag_get(), rz_flag_get_i(), rz_io_fd_size(), rz_io_map_get(), rz_io_read_at(), rz_itv_begin(), rz_itv_size(), RZ_MIN, rz_num_calc_index(), rz_num_math(), rz_num_tail(), rz_read_ble16(), rz_read_ble32(), rz_read_ble64(), rz_read_ble8(), rz_reg_get(), rz_reg_get_name(), rz_reg_get_name_idx(), rz_reg_get_value(), rz_str_replace_char(), rz_sys_getpid(), s, rz_core_t::sdb, sdb_querys(), rz_flag_item_t::size, st64, cmd_descs_generate::str, strdup(), ut64(), UT64_MAX, and rz_num_t::value.

Referenced by rz_core_init().

◆ numget()

static ut64 numget ( RzCore core,
const char *  k 
)
static

Definition at line 361 of file core.c.

361  {
362  return rz_num_math(core->num, k);
363 }

References k, rz_core_t::num, and rz_num_math().

Referenced by rz_core_bind().

◆ on_fcn_delete()

static int on_fcn_delete ( RzAnalysis _analysis,
void *  _user,
RzAnalysisFunction fcn 
)
static

Definition at line 121 of file core.c.

121  {
122  RzCore *core = (RzCore *)_user;
123  const char *cmd = rz_config_get(core->config, "cmd.fcn.delete");
124  if (cmd && *cmd) {
125  ut64 oaddr = core->offset;
126  ut64 addr = fcn->addr;
127  rz_core_seek(core, addr, true);
128  rz_core_cmd0(core, cmd);
129  rz_core_seek(core, oaddr, true);
130  }
131  return 0;
132 }
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 cmd
Definition: sflib.h:79

References addr, rz_analysis_function_t::addr, cmd, rz_core_t::config, rz_core_t::offset, rz_config_get(), rz_core_cmd0(), rz_core_seek(), and ut64().

Referenced by rz_core_init().

◆ on_fcn_new()

static int on_fcn_new ( RzAnalysis _analysis,
void *  _user,
RzAnalysisFunction fcn 
)
static

Definition at line 108 of file core.c.

108  {
109  RzCore *core = (RzCore *)_user;
110  const char *cmd = rz_config_get(core->config, "cmd.fcn.new");
111  if (cmd && *cmd) {
112  ut64 oaddr = core->offset;
113  ut64 addr = fcn->addr;
114  rz_core_seek(core, addr, true);
115  rz_core_cmd0(core, cmd);
116  rz_core_seek(core, oaddr, true);
117  }
118  return 0;
119 }

References addr, rz_analysis_function_t::addr, cmd, rz_core_t::config, rz_core_t::offset, rz_config_get(), rz_core_cmd0(), rz_core_seek(), and ut64().

Referenced by rz_core_init().

◆ on_fcn_rename()

static int on_fcn_rename ( RzAnalysis _analysis,
void *  _user,
RzAnalysisFunction fcn,
const char *  oname 
)
static

Definition at line 134 of file core.c.

134  {
135  RzCore *core = (RzCore *)_user;
136  const char *cmd = rz_config_get(core->config, "cmd.fcn.rename");
137  if (cmd && *cmd) {
138  // XXX: wat do with old name here?
139  ut64 oaddr = core->offset;
140  ut64 addr = fcn->addr;
141  rz_core_seek(core, addr, true);
142  rz_core_cmd0(core, cmd);
143  rz_core_seek(core, oaddr, true);
144  }
145  return 0;
146 }

References addr, rz_analysis_function_t::addr, cmd, rz_core_t::config, rz_core_t::offset, rz_config_get(), rz_core_cmd0(), rz_core_seek(), and ut64().

Referenced by rz_core_init().

◆ prompt_add_file()

static bool prompt_add_file ( RzCore core,
RzStrBuf sb,
bool  add_sep 
)
static

Definition at line 2707 of file core.c.

2707  {
2708  if (!rz_config_get_b(core->config, "scr.prompt.file") || !core->io->desc) {
2709  return add_sep;
2710  }
2711  if (add_sep) {
2712  rz_strbuf_append(sb, ":");
2713  }
2715  return true;
2716 }
static SblHeader sb
Definition: bin_mbn.c:26
RZ_API bool rz_config_get_b(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:142
RZ_API const char * rz_file_basename(const char *path)
Definition: file.c:83
RZ_API bool rz_strbuf_append(RzStrBuf *sb, const char *s)
Definition: strbuf.c:222
char * name
Definition: rz_io.h:99
struct rz_io_desc_t * desc
Definition: rz_io.h:60

References rz_core_t::config, rz_io_t::desc, rz_core_t::io, rz_io_desc_t::name, rz_config_get_b(), rz_file_basename(), rz_strbuf_append(), and sb.

Referenced by set_prompt().

◆ prompt_add_offset()

static bool prompt_add_offset ( RzCore core,
RzStrBuf sb,
bool  add_sep 
)
static

Definition at line 2733 of file core.c.

2733  {
2734  if (add_sep) {
2735  rz_strbuf_append(sb, ":");
2736  }
2737  if (rz_config_get_b(core->config, "scr.prompt.flag")) {
2738  const RzFlagItem *f = rz_flag_get_at(core->flags, core->offset, true);
2739  if (f) {
2740  if (f->offset < core->offset) {
2741  rz_strbuf_appendf(sb, "%s + %" PFMT64u, f->name, core->offset - f->offset);
2742  } else {
2743  rz_strbuf_appendf(sb, "%s", f->name);
2744  }
2745  if (rz_config_get_b(core->config, "scr.prompt.flag.only")) {
2746  return true;
2747  }
2748 
2749  rz_strbuf_append(sb, ":");
2750  }
2751  }
2752 
2753  if (rz_config_get_b(core->config, "asm.segoff")) {
2754  ut32 a, b;
2755  unsigned int seggrn = rz_config_get_i(core->config, "asm.seggrn");
2756 
2757  a = ((core->offset >> 16) << (16 - seggrn));
2758  b = (core->offset & 0xffff);
2759  rz_strbuf_appendf(sb, "%04x:%04x", a, b);
2760  } else {
2761  if (core->print->wide_offsets && core->dbg->bits & RZ_SYS_BITS_64) {
2762  rz_strbuf_appendf(sb, "0x%016" PFMT64x, core->offset);
2763  } else {
2764  rz_strbuf_appendf(sb, "0x%08" PFMT64x, core->offset);
2765  }
2766  }
2767  return true;
2768 }
uint32_t ut32
RZ_API bool rz_strbuf_appendf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
@ RZ_SYS_BITS_64
Definition: rz_sys.h:21
int bits
Definition: rz_debug.h:243
bool wide_offsets
Definition: rz_print.h:162

References a, b, rz_debug_t::bits, rz_core_t::config, rz_core_t::dbg, f, rz_core_t::flags, rz_core_t::offset, PFMT64u, PFMT64x, rz_core_t::print, rz_config_get_b(), rz_config_get_i(), rz_flag_get_at(), rz_strbuf_append(), rz_strbuf_appendf(), RZ_SYS_BITS_64, sb, and rz_print_t::wide_offsets.

Referenced by set_prompt().

◆ prompt_add_section()

static bool prompt_add_section ( RzCore core,
RzStrBuf sb,
bool  add_sep 
)
static

Definition at line 2718 of file core.c.

2718  {
2719  if (!rz_config_get_b(core->config, "scr.prompt.sect")) {
2720  return add_sep;
2721  }
2722  const RzBinSection *sec = rz_bin_get_section_at(rz_bin_cur_object(core->bin), core->offset, true);
2723  if (!sec) {
2724  return add_sep;
2725  }
2726  if (add_sep) {
2727  rz_strbuf_append(sb, ":");
2728  }
2729  rz_strbuf_append(sb, sec->name);
2730  return true;
2731 }
char * name
Definition: rz_bin.h:619

References rz_core_t::bin, rz_core_t::config, rz_bin_section_t::name, rz_core_t::offset, rz_bin_cur_object(), rz_bin_get_section_at(), rz_config_get_b(), rz_strbuf_append(), and sb.

Referenced by set_prompt().

◆ rap_break()

static void rap_break ( void *  u)
static

Definition at line 2894 of file core.c.

2894  {
2895  RzIORap *rior = (RzIORap *)u;
2896  if (u) {
2897  rz_socket_close(rior->fd);
2898  rior->fd = NULL;
2899  }
2900 }
RZ_API int rz_socket_close(RzSocket *s)
Definition: socket.c:419
Definition: core.c:2888
RzSocket * fd
Definition: core.c:2889

References RzIORap::fd, NULL, and rz_socket_close().

Referenced by rz_core_serve().

◆ rz_core_add_asmqjmp()

RZ_API char* rz_core_add_asmqjmp ( RzCore core,
ut64  addr 
)

Takes addr and returns already saved shortcut or a new one The returned buffer needs to be freed

Definition at line 238 of file core.c.

238  {
239  bool found = false;
240  if (!core->asmqjmps) {
241  return NULL;
242  }
243  if (core->is_asmqjmps_letter) {
245  return NULL;
246  }
247  if (core->asmqjmps_count >= core->asmqjmps_size - 2) {
248  core->asmqjmps = realloc(core->asmqjmps, core->asmqjmps_size * 2 * sizeof(ut64));
249  if (!core->asmqjmps) {
250  return NULL;
251  }
252  core->asmqjmps_size *= 2;
253  }
254  }
255  if (core->asmqjmps_count < core->asmqjmps_size - 1) {
256  int i = 0;
257  char t[RZ_CORE_ASMQJMPS_LEN_LETTERS + 1] = { 0 };
258  for (i = 0; i < core->asmqjmps_count + 1; i++) {
259  if (core->asmqjmps[i] == addr) {
260  found = true;
261  break;
262  }
263  }
264  if (!found) {
265  i = ++core->asmqjmps_count;
266  core->asmqjmps[i] = addr;
267  }
268  // This check makes pos never be <1, thefor not fill 't' with trash
269  if (i < 1) {
270  return NULL;
271  }
272  rz_core_set_asmqjmps(core, t, sizeof(t), i);
273  return strdup(t);
274  }
275  return NULL;
276 }
RZ_API const KEY_TYPE bool * found
Definition: ht_inc.h:130
RZ_API void rz_core_set_asmqjmps(RzCore *core, char *str, size_t len, int pos)
Definition: core.c:282
void * realloc(void *ptr, size_t size)
Definition: malloc.c:144
#define RZ_CORE_ASMQJMPS_MAX_LETTERS
Definition: rz_core.h:185
#define RZ_CORE_ASMQJMPS_LEN_LETTERS
Definition: rz_core.h:186
int asmqjmps_size
Definition: rz_core.h:348
int asmqjmps_count
Definition: rz_core.h:347
ut64 * asmqjmps
Definition: rz_core.h:346
bool is_asmqjmps_letter
Definition: rz_core.h:349

References addr, rz_core_t::asmqjmps, rz_core_t::asmqjmps_count, rz_core_t::asmqjmps_size, found, i, rz_core_t::is_asmqjmps_letter, NULL, realloc(), RZ_CORE_ASMQJMPS_LEN_LETTERS, RZ_CORE_ASMQJMPS_MAX_LETTERS, rz_core_set_asmqjmps(), strdup(), and ut64().

Referenced by ds_print_shortcut(), get_bbnodes(), and get_bbupdate().

◆ rz_core_analysis_get_comments()

RZ_API char* rz_core_analysis_get_comments ( RzCore core,
ut64  addr 
)

Definition at line 2091 of file core.c.

2091  {
2092  if (core) {
2093  const char *type = rz_meta_get_string(core->analysis, RZ_META_TYPE_VARTYPE, addr);
2094  const char *cmt = rz_meta_get_string(core->analysis, RZ_META_TYPE_COMMENT, addr);
2095  if (type && cmt) {
2096  return rz_str_newf("%s %s", type, cmt);
2097  }
2098  if (type) {
2099  return strdup(type);
2100  }
2101  if (cmt) {
2102  return strdup(cmt);
2103  }
2104  }
2105  return NULL;
2106 }
RZ_API const char * rz_meta_get_string(RzAnalysis *a, RzAnalysisMetaType type, ut64 addr)
Definition: meta.c:146
@ RZ_META_TYPE_VARTYPE
Definition: rz_analysis.h:297
@ RZ_META_TYPE_COMMENT
Definition: rz_analysis.h:295

References addr, rz_core_t::analysis, NULL, rz_meta_get_string(), RZ_META_TYPE_COMMENT, RZ_META_TYPE_VARTYPE, rz_str_newf(), strdup(), and type.

Referenced by disasm_strings(), and get_comments_cb().

◆ rz_core_analysis_hasrefs()

RZ_API char* rz_core_analysis_hasrefs ( RzCore core,
ut64  value,
int  mode 
)

Definition at line 1805 of file core.c.

1805  {
1806  if (mode) {
1807  PJ *pj = (mode == 'j') ? pj_new() : NULL;
1808  const int hex_depth = 1; // r_config_get_i (core->config, "hex.depth");
1809  char *res = rz_core_analysis_hasrefs_to_depth(core, value, pj, hex_depth);
1810  if (pj) {
1811  free(res);
1812  return pj_drain(pj);
1813  }
1814  return res;
1815  }
1816  RzFlagItem *fi = rz_flag_get_i(core->flags, value);
1817  return fi ? strdup(fi->name) : NULL;
1818 }
RZ_API char * rz_core_analysis_hasrefs_to_depth(RzCore *core, ut64 value, PJ *pj, int depth)
Definition: core.c:1853
RZ_API PJ * pj_new(void)
Definition: pj.c:25
RZ_API char * pj_drain(PJ *j)
Definition: pj.c:50
Definition: rz_pj.h:12

References rz_core_t::flags, free(), rz_flag_item_t::name, NULL, pj_drain(), pj_new(), rz_core_analysis_hasrefs_to_depth(), rz_flag_get_i(), strdup(), and value.

Referenced by hasrefs_cb(), references_handler(), and rz_regs_show_valgroup().

◆ rz_core_analysis_hasrefs_to_depth()

RZ_API char* rz_core_analysis_hasrefs_to_depth ( RzCore core,
ut64  value,
PJ pj,
int  depth 
)

Definition at line 1853 of file core.c.

1853  {
1854  const int bits = core->rasm->bits;
1855  rz_return_val_if_fail(core, NULL);
1857  if (pj) {
1858  pj_o(pj);
1859  pj_kn(pj, "addr", value);
1860  }
1861  if (depth < 1 || value == UT64_MAX) {
1862  if (pj) {
1863  pj_end(pj);
1864  }
1865  return NULL;
1866  }
1867 
1868  char *val = getvalue(value, bits);
1869  if (val) {
1870  if (pj) {
1871  pj_ks(pj, "value", val);
1872  } else {
1873  rz_strbuf_appendf(s, "%s ", val);
1874  }
1875  RZ_FREE(val);
1876  }
1877 
1878  if (value && value != UT64_MAX) {
1880  if (map && map->name && map->name[0]) {
1881  if (pj) {
1882  pj_ks(pj, "map", map->name);
1883  } else {
1884  rz_strbuf_appendf(s, "%s ", map->name);
1885  }
1886  }
1887  }
1889  RzBinObject *obj = rz_bin_cur_object(core->bin);
1890  RzBinSection *sect = value && obj ? rz_bin_get_section_at(obj, value, true) : NULL;
1892  // Do not repeat "stack" or "heap" words unnecessarily.
1893  if (sect && sect->name[0]) {
1894  if (pj) {
1895  pj_ks(pj, "section", sect->name);
1896  } else {
1897  rz_strbuf_appendf(s, "%s ", sect->name);
1898  }
1899  }
1900  }
1901  if (value != 0 && value != UT64_MAX) {
1902  if (pj) {
1903  RzListIter *iter;
1904  RzFlagItem *f;
1905  const RzList *flags = rz_flag_get_list(core->flags, value);
1906  if (flags && !rz_list_empty(flags)) {
1907  pj_ka(pj, "flags");
1908  rz_list_foreach (flags, iter, f) {
1909  pj_s(pj, f->name);
1910  }
1911  pj_end(pj);
1912  }
1913  } else {
1914  char *flags = rz_flag_get_liststr(core->flags, value);
1915  if (flags) {
1916  rz_strbuf_appendf(s, "%s ", flags);
1917  free(flags);
1918  }
1919  }
1920  }
1922  if (fcn) {
1923  if (pj) {
1924  pj_ks(pj, "fcn", fcn->name);
1925  } else {
1926  rz_strbuf_appendf(s, "%s ", fcn->name);
1927  }
1928  }
1929  if (type) {
1930  const char *c = rz_core_analysis_optype_colorfor(core, value, true);
1931  const char *cend = (c && *c) ? Color_RESET : "";
1932  if (!c) {
1933  c = "";
1934  }
1935  if (pj) {
1936  pj_ka(pj, "attr");
1937  }
1939  if (pj) {
1940  pj_s(pj, "heap");
1941  } else {
1942  rz_strbuf_appendf(s, "%sheap%s ", c, cend);
1943  }
1944  } else if (type & RZ_ANALYSIS_ADDR_TYPE_STACK) {
1945  if (pj) {
1946  pj_s(pj, "stack");
1947  } else {
1948  rz_strbuf_appendf(s, "%sstack%s ", c, cend);
1949  }
1950  }
1952  if (pj) {
1953  pj_s(pj, "program");
1954  } else {
1955  rz_strbuf_appendf(s, "%sprogram%s ", c, cend);
1956  }
1957  }
1959  if (pj) {
1960  pj_s(pj, "library");
1961  } else {
1962  rz_strbuf_appendf(s, "%slibrary%s ", c, cend);
1963  }
1964  }
1966  if (pj) {
1967  pj_s(pj, "ascii");
1968  } else {
1969  rz_strbuf_appendf(s, "%sascii%s ('%c') ", c, cend, (char)value);
1970  }
1971  }
1973  if (pj) {
1974  pj_s(pj, "sequence");
1975  } else {
1976  rz_strbuf_appendf(s, "%ssequence%s ", c, cend);
1977  }
1978  }
1979  if (pj) {
1981  pj_s(pj, "R");
1982  }
1984  pj_s(pj, "W");
1985  }
1987  pj_s(pj, "X");
1988  }
1989  } else {
1991  rz_strbuf_appendf(s, "%sR%s ", c, cend);
1992  }
1994  rz_strbuf_appendf(s, "%sW%s ", c, cend);
1995  }
1997  RzAsmOp op;
1998  ut8 buf[32];
1999  rz_strbuf_appendf(s, "%sX%s ", c, cend);
2000  /* instruction disassembly */
2001  rz_io_read_at(core->io, value, buf, sizeof(buf));
2002  rz_asm_set_pc(core->rasm, value);
2003  rz_asm_disassemble(core->rasm, &op, buf, sizeof(buf));
2004  rz_strbuf_appendf(s, "'%s' ", rz_asm_op_get_asm(&op));
2005  /* get library name */
2006  { // NOTE: dup for mapname?
2007  RzDebugMap *map;
2008  RzListIter *iter;
2009  rz_list_foreach (core->dbg->maps, iter, map) {
2010  if ((value >= map->addr) &&
2011  (value < map->addr_end)) {
2012  const char *lastslash = rz_str_lchr(map->name, '/');
2013  rz_strbuf_appendf(s, "'%s' ", lastslash ? lastslash + 1 : map->name);
2014  break;
2015  }
2016  }
2017  }
2018  } else if (type & RZ_ANALYSIS_ADDR_TYPE_READ) {
2019  ut8 buf[32];
2020  ut32 *n32 = (ut32 *)buf;
2021  ut64 *n64 = (ut64 *)buf;
2022  if (rz_io_read_at(core->io, value, buf, sizeof(buf))) {
2023  ut64 n = (bits == 64) ? *n64 : *n32;
2024  rz_strbuf_appendf(s, "0x%" PFMT64x " ", n);
2025  }
2026  }
2027  }
2028  if (pj) {
2029  pj_end(pj);
2030  }
2031  }
2032  {
2033  ut8 buf[128], widebuf[256];
2034  const char *c = rz_config_get_i(core->config, "scr.color") ? core->cons->context->pal.ai_ascii : "";
2035  const char *cend = (c && *c) ? Color_RESET : "";
2036  int len, r;
2037  if (rz_io_read_at(core->io, value, buf, sizeof(buf))) {
2038  buf[sizeof(buf) - 1] = 0;
2039  switch (is_string(buf, sizeof(buf), &len)) {
2040  case 1:
2041  if (pj) {
2042  pj_ks(pj, "string", (const char *)buf);
2043  } else {
2044  rz_strbuf_appendf(s, "%s%s%s ", c, buf, cend);
2045  }
2046  break;
2047  case 2:
2048  r = rz_utf8_encode_str((const RzRune *)buf, widebuf, sizeof(widebuf) - 1);
2049  if (r == -1) {
2050  eprintf("Something was wrong with refs\n");
2051  } else {
2052  if (pj) {
2053  pj_ks(pj, "string", (const char *)widebuf);
2054  } else {
2055  rz_strbuf_appendf(s, "%s%s%s ", c, widebuf, cend);
2056  }
2057  }
2058  break;
2059  }
2060  }
2061  }
2063  // Try to telescope further, but only several levels deep.
2064  ut8 buf[32];
2065  ut32 *n32 = (ut32 *)buf;
2066  ut64 *n64 = (ut64 *)buf;
2067  if (rz_io_read_at(core->io, value, buf, sizeof(buf))) {
2068  ut64 n = (bits == 64) ? *n64 : *n32;
2069  if (n != value) {
2070  if (pj) {
2071  pj_k(pj, "ref");
2072  }
2073  char *rrstr = rz_core_analysis_hasrefs_to_depth(core, n, pj, depth - 1);
2074  if (rrstr) {
2075  if (!pj && rrstr[0]) {
2076  rz_strbuf_appendf(s, " -> %s", rrstr);
2077  }
2078  free(rrstr);
2079  }
2080  }
2081  }
2082  }
2083  if (pj) {
2084  pj_end(pj);
2085  }
2086  char *res = rz_strbuf_drain(s);
2087  rz_str_trim_tail(res);
2088  return res;
2089 }
RZ_API char * rz_asm_op_get_asm(RzAsmOp *op)
Definition: aop.c:37
ut16 val
Definition: armass64_const.h:6
RZ_API int rz_asm_set_pc(RzAsm *a, ut64 pc)
Definition: asm.c:533
RZ_API int rz_asm_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
Definition: asm.c:543
RZ_API ut64 rz_core_analysis_address(RzCore *core, ut64 addr)
Definition: canalysis.c:168
RZ_API RzDebugMap * rz_debug_map_get(RzDebug *dbg, ut64 addr)
Definition: dmap.c:65
RZ_API char * rz_flag_get_liststr(RzFlag *f, ut64 off)
Definition: flag.c:480
static char * getvalue(ut64 value, int bits)
Definition: core.c:1820
static int is_string(const ut8 *buf, int size, int *len)
Definition: core.c:1775
#define RZ_ANALYSIS_ADDR_TYPE_STACK
Definition: rz_analysis.h:91
#define RZ_ANALYSIS_ADDR_TYPE_SEQUENCE
Definition: rz_analysis.h:96
#define RZ_ANALYSIS_ADDR_TYPE_ASCII
Definition: rz_analysis.h:95
#define RZ_ANALYSIS_ADDR_TYPE_EXEC
Definition: rz_analysis.h:85
#define RZ_ANALYSIS_ADDR_TYPE_HEAP
Definition: rz_analysis.h:90
#define RZ_ANALYSIS_ADDR_TYPE_LIBRARY
Definition: rz_analysis.h:94
#define RZ_ANALYSIS_ADDR_TYPE_WRITE
Definition: rz_analysis.h:87
#define RZ_ANALYSIS_ADDR_TYPE_READ
Definition: rz_analysis.h:86
#define RZ_ANALYSIS_ADDR_TYPE_PROGRAM
Definition: rz_analysis.h:93
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
#define Color_RESET
Definition: rz_cons.h:617
RZ_API PJ * pj_ka(PJ *j, const char *k)
Definition: pj.c:163
RZ_API PJ * pj_k(PJ *j, const char *k)
Definition: pj.c:104
RZ_API PJ * pj_end(PJ *j)
Definition: pj.c:87
RZ_API PJ * pj_o(PJ *j)
Definition: pj.c:75
RZ_API PJ * pj_s(PJ *j, const char *k)
Definition: pj.c:197
RZ_API PJ * pj_ks(PJ *j, const char *k, const char *v)
Definition: pj.c:170
RZ_API PJ * pj_kn(PJ *j, const char *k, ut64 n)
Definition: pj.c:121
RZ_API const char * rz_str_lchr(const char *str, char chr)
Definition: str.c:669
RZ_API RZ_BORROW char * rz_str_trim_tail(RZ_NONNULL char *str)
Removes whitespace characters (space, tab, newline etc.) from the end of a string and replaces them w...
Definition: str_trim.c:125
RZ_API RZ_OWN char * rz_strbuf_drain(RzStrBuf *sb)
Definition: strbuf.c:342
RZ_API RzStrBuf * rz_strbuf_new(const char *s)
Definition: strbuf.c:8
#define RZ_FREE(x)
Definition: rz_types.h:369
RZ_API int rz_utf8_encode_str(const RzRune *str, ut8 *dst, const int dst_length)
Definition: utf8.c:559
ut32 RzRune
Definition: rz_utf8.h:13
RzConsPrintablePalette pal
Definition: rz_cons.h:491
RzConsContext * context
Definition: rz_cons.h:502
ut8 * buf
Definition: core.c:75

References rz_cons_printable_palette_t::ai_ascii, rz_core_t::analysis, rz_core_t::bin, rz_asm_t::bits, bits(), buf, c, Color_RESET, rz_core_t::config, rz_core_t::cons, rz_cons_t::context, rz_core_t::dbg, eprintf, f, rz_core_t::flags, flags, free(), getvalue(), rz_core_t::io, is_string(), len, map(), rz_debug_t::maps, n, rz_analysis_function_t::name, rz_bin_section_t::name, NULL, op, rz_cons_context_t::pal, PFMT64x, pj_end(), pj_k(), pj_ka(), pj_kn(), pj_ks(), pj_o(), pj_s(), r, rz_core_t::rasm, RZ_ANALYSIS_ADDR_TYPE_ASCII, RZ_ANALYSIS_ADDR_TYPE_EXEC, RZ_ANALYSIS_ADDR_TYPE_HEAP, RZ_ANALYSIS_ADDR_TYPE_LIBRARY, RZ_ANALYSIS_ADDR_TYPE_PROGRAM, RZ_ANALYSIS_ADDR_TYPE_READ, RZ_ANALYSIS_ADDR_TYPE_SEQUENCE, RZ_ANALYSIS_ADDR_TYPE_STACK, RZ_ANALYSIS_ADDR_TYPE_WRITE, rz_analysis_get_fcn_in(), rz_asm_disassemble(), rz_asm_op_get_asm(), rz_asm_set_pc(), rz_bin_cur_object(), rz_bin_get_section_at(), rz_config_get_i(), rz_core_analysis_address(), rz_core_analysis_optype_colorfor(), rz_debug_map_get(), rz_flag_get_list(), rz_flag_get_liststr(), RZ_FREE, rz_io_read_at(), rz_return_val_if_fail, rz_str_lchr(), rz_str_trim_tail(), rz_strbuf_appendf(), rz_strbuf_drain(), rz_strbuf_new(), rz_utf8_encode_str(), s, type, ut64(), UT64_MAX, val, and value.

Referenced by cmd_pxr(), and rz_core_analysis_hasrefs().

◆ rz_core_analysis_optype_colorfor()

RZ_API const char* rz_core_analysis_optype_colorfor ( RzCore core,
ut64  addr,
bool  verbose 
)

Definition at line 2108 of file core.c.

2108  {
2109  ut64 type;
2110  if (!(core->print->flags & RZ_PRINT_FLAGS_COLOR)) {
2111  return NULL;
2112  }
2113  if (!rz_config_get_i(core->config, "scr.color")) {
2114  return NULL;
2115  }
2118  return core->cons->context->pal.ai_exec; // Color_RED;
2119  }
2121  return core->cons->context->pal.ai_write; // Color_BLUE;
2122  }
2124  return core->cons->context->pal.ai_read; // Color_GREEN;
2125  }
2127  return core->cons->context->pal.ai_seq; // Color_MAGENTA;
2128  }
2130  return core->cons->context->pal.ai_ascii; // Color_YELLOW;
2131  }
2132  return NULL;
2133 }
#define RZ_PRINT_FLAGS_COLOR
Definition: rz_print.h:15
int flags
Definition: rz_print.h:137

References addr, rz_cons_printable_palette_t::ai_ascii, rz_cons_printable_palette_t::ai_exec, rz_cons_printable_palette_t::ai_read, rz_cons_printable_palette_t::ai_seq, rz_cons_printable_palette_t::ai_write, rz_core_t::config, rz_core_t::cons, rz_cons_t::context, rz_print_t::flags, NULL, rz_cons_context_t::pal, rz_core_t::print, RZ_ANALYSIS_ADDR_TYPE_ASCII, RZ_ANALYSIS_ADDR_TYPE_EXEC, RZ_ANALYSIS_ADDR_TYPE_READ, RZ_ANALYSIS_ADDR_TYPE_SEQUENCE, RZ_ANALYSIS_ADDR_TYPE_WRITE, rz_config_get_i(), rz_core_analysis_address(), RZ_PRINT_FLAGS_COLOR, type, and ut64().

Referenced by colorfor_cb(), and rz_core_analysis_hasrefs_to_depth().

◆ rz_core_analysis_read_at()

static bool rz_core_analysis_read_at ( struct rz_analysis_t analysis,
ut64  addr,
ut8 buf,
int  len 
)
static

Definition at line 2148 of file core.c.

2148  {
2149  return rz_io_read_at(analysis->iob.io, addr, buf, len);
2150 }
RzIOBind iob
Definition: rz_analysis.h:574
RzIO * io
Definition: rz_io.h:232

References addr, rz_io_bind_t::io, rz_analysis_t::iob, len, and rz_io_read_at().

Referenced by rz_core_init().

◆ rz_core_autocomplete()

RZ_API void rz_core_autocomplete ( RZ_NULLABLE RzCore core,
RzLineCompletion completion,
RzLineBuffer buf,
RzLinePromptType  prompt_type 
)

Definition at line 1550 of file core.c.

1550  {
1551  if (!core) {
1552  autocomplete_default(core, completion, buf);
1553  return;
1554  }
1555  rz_line_completion_clear(completion);
1556  char *pipe = strchr(buf->data, '>');
1557  char *ptr = strchr(buf->data, '@');
1558  if (pipe && strchr(pipe + 1, ' ') && buf->data + buf->index >= pipe) {
1559  autocompleteFilename(completion, buf, NULL, 1);
1560  } else if (ptr && strchr(ptr + 1, ' ') && buf->data + buf->index >= ptr) {
1561  int sdelta, n;
1562  ptr = (char *)rz_str_trim_head_ro(ptr + 1);
1563  n = strlen(ptr); //(buf->data+sdelta);
1564  sdelta = (int)(size_t)(ptr - buf->data);
1565  rz_flag_foreach_prefix(core->flags, buf->data + sdelta, n, add_argv, completion);
1566  } else if (!strncmp(buf->data, "#!pipe ", 7)) {
1567  if (strchr(buf->data + 7, ' ')) {
1568  autocompleteFilename(completion, buf, NULL, 2);
1569  } else {
1570  int chr = 7;
1571  ADDARG("node");
1572  ADDARG("vala");
1573  ADDARG("ruby");
1574  ADDARG("newlisp");
1575  ADDARG("perl");
1576  ADDARG("python");
1577  }
1578  } else if (!strncmp(buf->data, "ec ", 3)) {
1579  if (strchr(buf->data + 3, ' ')) {
1580  autocompleteFilename(completion, buf, NULL, 2);
1581  } else {
1582  int chr = 3;
1583  ADDARG("comment")
1584  ADDARG("usrcmt")
1585  ADDARG("args")
1586  ADDARG("fname")
1587  ADDARG("floc")
1588  ADDARG("fline")
1589  ADDARG("flag")
1590  ADDARG("label")
1591  ADDARG("help")
1592  ADDARG("flow")
1593  ADDARG("prompt")
1594  ADDARG("offset")
1595  ADDARG("input")
1596  ADDARG("invalid")
1597  ADDARG("other")
1598  ADDARG("b0x00")
1599  ADDARG("b0x7f")
1600  ADDARG("b0xff")
1601  ADDARG("math")
1602  ADDARG("bin")
1603  ADDARG("btext")
1604  ADDARG("push")
1605  ADDARG("pop")
1606  ADDARG("crypto")
1607  ADDARG("jmp")
1608  ADDARG("cjmp")
1609  ADDARG("call")
1610  ADDARG("nop")
1611  ADDARG("ret")
1612  ADDARG("trap")
1613  ADDARG("swi")
1614  ADDARG("cmp")
1615  ADDARG("reg")
1616  ADDARG("creg")
1617  ADDARG("num")
1618  ADDARG("mov")
1619  ADDARG("func_var")
1620  ADDARG("func_var_type")
1621  ADDARG("func_var_addr")
1622  ADDARG("widget_bg")
1623  ADDARG("widget_sel")
1624  ADDARG("ai.read")
1625  ADDARG("ai.write")
1626  ADDARG("ai.exec")
1627  ADDARG("ai.seq")
1628  ADDARG("ai.ascii")
1629  ADDARG("ai.unmap")
1630  ADDARG("graph.box")
1631  ADDARG("graph.box2")
1632  ADDARG("graph.box3")
1633  ADDARG("graph.box4")
1634  ADDARG("graph.true")
1635  ADDARG("graph.false")
1636  ADDARG("graph.ujump")
1637  ADDARG("graph.current")
1638  ADDARG("graph.traced")
1639  ADDARG("gui.cflow")
1640  ADDARG("gui.dataoffset")
1641  ADDARG("gui.background")
1642  ADDARG("gui.alt_background")
1643  ADDARG("gui.border")
1644  }
1645  } else if ((!strncmp(buf->data, "afvn ", 5)) || (!strncmp(buf->data, "afan ", 5))) {
1646  RzAnalysisFunction *fcn = rz_analysis_get_fcn_in(core->analysis, core->offset, 0);
1647  RzList *vars;
1648  if (!strncmp(buf->data, "afvn ", 5)) {
1649  vars = rz_analysis_var_list(core->analysis, fcn, RZ_ANALYSIS_VAR_KIND_BPV);
1650  } else {
1651  vars = rz_list_new(); // TODO rz_analysis_var_list (core->analysis, fcn, RZ_ANALYSIS_VAR_KIND_ARG);
1652  }
1653  const char *f_ptr, *l_ptr;
1654  RzAnalysisVar *var;
1655  int len = strlen(buf->data);
1656 
1657  f_ptr = rz_sub_str_lchr(buf->data, 0, buf->index, ' ');
1658  f_ptr = f_ptr != NULL ? f_ptr + 1 : buf->data;
1659  l_ptr = rz_sub_str_rchr(buf->data, buf->index, len, ' ');
1660  if (!l_ptr) {
1661  l_ptr = buf->data + len;
1662  }
1663  RzListIter *iter;
1664  rz_list_foreach (vars, iter, var) {
1665  if (!strncmp(f_ptr, var->name, l_ptr - f_ptr)) {
1666  rz_line_completion_push(completion, var->name);
1667  }
1668  }
1669  rz_list_free(vars);
1670  } else if (!strncmp(buf->data, "$", 1)) {
1671  int i;
1672  for (i = 0; i < core->rcmd->aliases.count; i++) {
1673  const char *key = core->rcmd->aliases.keys[i];
1674  int len = strlen(buf->data);
1675  if (!len || !strncmp(buf->data, key, len)) {
1676  rz_line_completion_push(completion, key);
1677  }
1678  }
1679  } else if (find_e_opts(core, completion, buf)) {
1680  return;
1681  } else if (prompt_type == RZ_LINE_PROMPT_OFFSET) {
1682  autocomplete_flags(core, completion, buf->data);
1683  } else if (prompt_type == RZ_LINE_PROMPT_FILE) {
1684  autocomplete_file(completion, buf->data);
1685  } else if (!find_autocomplete(core, completion, buf)) {
1686  autocomplete_default(core, completion, buf);
1687  }
1688 }
#define jmp
#define cjmp
static RzILOpEffect * cmp(cs_insn *insn, bool is_thumb)
Definition: arm_il32.c:942
static RzILOpEffect * mov(cs_insn *insn, bool is_thumb)
Definition: arm_il32.c:351
int call(int a, int b)
Definition: bcj_test.c:25
static static fork write
Definition: sflib.h:33
#define true
#define false
static void autocomplete_default(RZ_NULLABLE RzCore *core, RzLineCompletion *completion, RzLineBuffer *buf)
Definition: core.c:1181
static void autocompleteFilename(RzLineCompletion *completion, RzLineBuffer *buf, char **extra_paths, int narg)
Definition: core.c:1133
static bool find_e_opts(RzCore *core, RzLineCompletion *completion, RzLineBuffer *buf)
Definition: core.c:1408
#define ADDARG(x)
Definition: core.c:1176
static bool find_autocomplete(RzCore *core, RzLineCompletion *completion, RzLineBuffer *buf)
Definition: core.c:1456
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
Definition: list.c:235
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz fd_set fd_set fd_set struct timeval static timeout const char char static bufsiz const char static swapflags void static offset const char static length static mode static who const char struct statfs static buf unsigned unsigned num
Definition: sflib.h:126
@ RZ_ANALYSIS_VAR_KIND_BPV
Definition: rz_analysis.h:704
@ RZ_LINE_PROMPT_OFFSET
Definition: rz_cons.h:1038
@ RZ_LINE_PROMPT_FILE
Definition: rz_cons.h:1039
RZ_API const char * rz_sub_str_rchr(const char *str, int start, int end, char chr)
Definition: str.c:690
RZ_API const char * rz_sub_str_lchr(const char *str, int start, int end, char chr)
Definition: str.c:682
static int
Definition: sfsocketcall.h:114
#define creg(n)
Definition: malloc.c:26
Definition: dis.h:35
RZ_API RzList * rz_analysis_var_list(RzAnalysis *a, RzAnalysisFunction *fcn, int kind)
Definition: var.c:1154
static char * prompt(const char *str, const char *txt)
Definition: vmenus.c:30
else
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4
int read(izstream &zs, T *x, Items items)
Definition: zstream.h:115

References add_argv(), ADDARG, autocomplete_default(), autocomplete_file(), autocomplete_flags(), autocompleteFilename(), find_autocomplete(), find_e_opts(), i, int, key, len, n, rz_analysis_var_t::name, NULL, pipe, rz_analysis_get_fcn_in(), RZ_ANALYSIS_VAR_KIND_BPV, rz_analysis_var_list(), rz_flag_foreach_prefix(), rz_line_completion_clear(), rz_line_completion_push(), RZ_LINE_PROMPT_FILE, RZ_LINE_PROMPT_OFFSET, rz_list_free(), rz_list_new(), rz_str_trim_head_ro(), rz_sub_str_lchr(), and rz_sub_str_rchr().

◆ rz_core_autocomplete_add()

RZ_API RzCoreAutocomplete* rz_core_autocomplete_add ( RzCoreAutocomplete parent,
const char *  cmd,
int  type,
bool  lock 
)

Definition at line 3366 of file core.c.

3366  {
3367  if (!parent || !cmd || type < 0 || type >= RZ_CORE_AUTOCMPLT_END) {
3368  return NULL;
3369  }
3371  if (!autocmpl) {
3372  return NULL;
3373  }
3374  RzCoreAutocomplete **updated = realloc(parent->subcmds, (parent->n_subcmds + 1) * sizeof(RzCoreAutocomplete *));
3375  if (!updated) {
3376  free(autocmpl);
3377  return NULL;
3378  }
3379  parent->subcmds = updated;
3380  parent->subcmds[parent->n_subcmds] = autocmpl;
3381  parent->n_subcmds++;
3382  autocmpl->cmd = strdup(cmd);
3383  autocmpl->locked = lock;
3384  autocmpl->type = type;
3385  autocmpl->length = strlen(cmd);
3386  return autocmpl;
3387 }
@ RZ_CORE_AUTOCMPLT_END
Definition: rz_core.h:204
static void lock(volatile int *lk)
Definition: malloc.c:61

References rz_core_autocomplete_t::cmd, cmd, free(), rz_core_autocomplete_t::length, lock(), rz_core_autocomplete_t::locked, rz_core_autocomplete_t::n_subcmds, NULL, realloc(), RZ_CORE_AUTOCMPLT_END, RZ_NEW0, strdup(), rz_core_autocomplete_t::subcmds, type, and rz_core_autocomplete_t::type.

Referenced by __foreach(), and __init_autocomplete_default().

◆ rz_core_autocomplete_find()

RZ_API RzCoreAutocomplete* rz_core_autocomplete_find ( RzCoreAutocomplete parent,
const char *  cmd,
bool  exact 
)

Definition at line 3403 of file core.c.

3403  {
3404  if (!parent || !cmd) {
3405  return false;
3406  }
3407  int len = strlen(cmd);
3408  int i;
3409  for (i = 0; i < parent->n_subcmds; i++) {
3410  if (exact && len == parent->subcmds[i]->length && !strncmp(cmd, parent->subcmds[i]->cmd, len)) {
3411  return parent->subcmds[i];
3412  } else if (!exact && !strncmp(cmd, parent->subcmds[i]->cmd, len)) {
3413  return parent->subcmds[i];
3414  }
3415  }
3416  return NULL;
3417 }

References rz_core_autocomplete_t::cmd, cmd, i, len, rz_core_autocomplete_t::length, rz_core_autocomplete_t::n_subcmds, NULL, and rz_core_autocomplete_t::subcmds.

Referenced by __init_autocomplete_default(), and find_autocomplete().

◆ rz_core_autocomplete_free()

RZ_API void rz_core_autocomplete_free ( RzCoreAutocomplete obj)

Definition at line 3389 of file core.c.

3389  {
3390  if (!obj) {
3391  return;
3392  }
3393  int i;
3394  for (i = 0; i < obj->n_subcmds; i++) {
3396  obj->subcmds[i] = NULL;
3397  }
3398  free(obj->subcmds);
3399  free((char *)obj->cmd);
3400  free(obj);
3401 }
RZ_API void rz_core_autocomplete_free(RzCoreAutocomplete *obj)
Definition: core.c:3389

References rz_core_autocomplete_t::cmd, free(), i, rz_core_autocomplete_t::n_subcmds, NULL, and rz_core_autocomplete_t::subcmds.

Referenced by rz_core_autocomplete_reload(), rz_core_autocomplete_remove(), and rz_core_fini().

◆ rz_core_autocomplete_reload()

RZ_API void rz_core_autocomplete_reload ( RzCore core)

Definition at line 2274 of file core.c.

2274  {
2275  rz_return_if_fail(core);
2277  __init_autocomplete(core);
2278 }
static void __init_autocomplete(RzCore *core)
Definition: core.c:2230

References __init_autocomplete(), rz_core_t::autocomplete, rz_core_autocomplete_free(), and rz_return_if_fail.

◆ rz_core_autocomplete_remove()

RZ_API bool rz_core_autocomplete_remove ( RzCoreAutocomplete parent,
const char *  cmd 
)

Definition at line 3419 of file core.c.

3419  {
3420  if (!parent || !cmd) {
3421  return false;
3422  }
3423  int i, j;
3424  for (i = 0; i < parent->n_subcmds; i++) {
3425  RzCoreAutocomplete *ac = parent->subcmds[i];
3426  if (ac->locked) {
3427  continue;
3428  }
3429  // if (!strncmp (parent->subcmds[i]->cmd, cmd, parent->subcmds[i]->length)) {
3430  if (rz_str_glob(ac->cmd, cmd)) {
3431  for (j = i + 1; j < parent->n_subcmds; j++) {
3432  parent->subcmds[j - 1] = parent->subcmds[j];
3433  parent->subcmds[j] = NULL;
3434  }
3436  RzCoreAutocomplete **updated = realloc(parent->subcmds, (parent->n_subcmds - 1) * sizeof(RzCoreAutocomplete *));
3437  if (!updated && (parent->n_subcmds - 1) > 0) {
3438  eprintf("Something really bad has happen.. this should never ever happen..\n");
3439  return false;
3440  }
3441  parent->subcmds = updated;
3442  parent->n_subcmds--;
3443  i--;
3444  }
3445  }
3446  return false;
3447 }
RZ_API bool rz_str_glob(const char *str, const char *glob)
Definition: str.c:2368

References rz_core_autocomplete_t::cmd, cmd, eprintf, i, rz_core_autocomplete_t::locked, rz_core_autocomplete_t::n_subcmds, NULL, realloc(), rz_core_autocomplete_free(), rz_str_glob(), and rz_core_autocomplete_t::subcmds.

◆ rz_core_bind()

RZ_API int rz_core_bind ( RzCore core,
RzCoreBind bnd 
)

Definition at line 369 of file core.c.

369  {
370  bnd->core = core;
373  bnd->cmd = (RzCoreCmd)rz_core_cmd0;
374  bnd->cmdf = (RzCoreCmdF)rz_core_cmdf;
378  bnd->setab = (RzCoreSetArchBits)setab;
379  bnd->getName = (RzCoreGetName)getName;
383  bnd->cfgGet = (RzCoreConfigGet)cfgget;
385  bnd->cfgSet = (RzCoreConfigSet)cfgset;
386  bnd->numGet = (RzCoreNumGet)numget;
389  return true;
390 }
RZ_API bool rz_core_bin_apply_info(RzCore *r, RzBinFile *binfile, ut32 mask)
Definition: cbin.c:261
RZ_API char * rz_core_cmd_strf(RzCore *core, const char *fmt,...)
Definition: cmd.c:5472
RZ_API int rz_core_cmdf(RzCore *core, const char *fmt,...)
Definition: cmd.c:5413
RZ_API char * rz_core_cmd_str(RzCore *core, const char *cmd)
Executes a rizin command and returns the stdout as a string.
Definition: cmd.c:5513
RZ_API void rz_cons_strcat(const char *str)
Definition: cons.c:1263
static const char * cfgget(RzCore *core, const char *k)
Definition: core.c:349
static ut64 numget(RzCore *core, const char *k)
Definition: core.c:361
static bool cfgseti(RzCore *core, const char *k, ut64 v)
Definition: core.c:353
static void setab(RzCore *core, const char *arch, int bits)
Definition: core.c:305
static const char * getName(RzCore *core, ut64 addr)
Definition: core.c:314
static ut64 cfggeti(RzCore *core, const char *k)
Definition: core.c:345
static const RzList * __flagsGet(RzCore *core, ut64 offset)
Definition: core.c:365
static bool cfgset(RzCore *core, const char *k, const char *v)
Definition: core.c:357
static void rz_core_debug_breakpoint_hit(RzCore *core, RzBreakpointItem *bpi)
Definition: core.c:148
static void archbits(RzCore *core, ut64 addr)
Definition: core.c:341
static char * getNameDelta(RzCore *core, ut64 addr)
Definition: core.c:327
static void rz_core_debug_syscall_hit(RzCore *core)
Definition: core.c:169
const char *(* RzCoreGetName)(void *core, ut64 off)
Definition: rz_bind.h:19
ut64(* RzCoreNumGet)(void *core, const char *str)
Definition: rz_bind.h:26
ut64(* RzCoreConfigGetI)(void *core, const char *key)
Definition: rz_bind.h:22
char *(* RzCoreGetNameDelta)(void *core, ut64 off)
Definition: rz_bind.h:20
char *(* RzCoreCmdStr)(void *core, const char *cmd)
Definition: rz_bind.h:15
void(* RzCorePuts)(const char *cmd)
Definition: rz_bind.h:17
int(* RzCoreCmd)(void *core, const char *cmd)
Definition: rz_bind.h:11
bool(* RzCoreConfigSet)(void *core, const char *key, const char *value)
Definition: rz_bind.h:24
bool(* RzCoreBinApplyInfo)(void *core, void *binfile, ut32 mask)
Definition: rz_bind.h:28
char *(* RzCoreCmdStrF)(void *core, const char *cmd,...)
Definition: rz_bind.h:16
void(* RzCoreSetArchBits)(void *core, const char *arch, int bits)
Definition: rz_bind.h:18
void(* RzCoreSeekArchBits)(void *core, ut64 addr)
Definition: rz_bind.h:21
bool(* RzCoreConfigSetI)(void *core, const char *key, ut64 value)
Definition: rz_bind.h:25
const char *(* RzCoreConfigGet)(void *core, const char *key)
Definition: rz_bind.h:23
void(* RzCoreDebugSyscallHit)(void *core)
Definition: rz_bind.h:14
int(* RzCoreCmdF)(void *user, const char *fmt,...)
Definition: rz_bind.h:12
const RzList *(* RzCoreFlagsGet)(void *core, ut64 offset)
Definition: rz_bind.h:27
int(* RzCoreDebugBpHit)(void *core, void *bp)
Definition: rz_bind.h:13
RzCoreConfigSet cfgSet
Definition: rz_bind.h:45
RzCoreSetArchBits setab
Definition: rz_bind.h:39
RzCoreBinApplyInfo applyBinInfo
Definition: rz_bind.h:49
RzCoreFlagsGet flagsGet
Definition: rz_bind.h:48
RzCoreCmd cmd
Definition: rz_bind.h:32
RzCoreCmdStr cmdstr
Definition: rz_bind.h:34
RzCoreCmdStrF cmdstrf
Definition: rz_bind.h:35
RzCoreConfigSetI cfgSetI
Definition: rz_bind.h:46
RzCoreConfigGet cfgGet
Definition: rz_bind.h:44
RzCoreNumGet numGet
Definition: rz_bind.h:47
void * core
Definition: rz_bind.h:31
RzCoreDebugSyscallHit syshit
Definition: rz_bind.h:38
RzCoreDebugBpHit bphit
Definition: rz_bind.h:37
RzCoreGetNameDelta getNameDelta
Definition: rz_bind.h:41
RzCoreGetName getName
Definition: rz_bind.h:40
RzCorePuts puts
Definition: rz_bind.h:36
RzCoreSeekArchBits archbits
Definition: rz_bind.h:42
RzCoreCmdF cmdf
Definition: rz_bind.h:33
RzCoreConfigGetI cfggeti
Definition: rz_bind.h:43

References __flagsGet(), rz_core_bind_t::applyBinInfo, archbits(), rz_core_bind_t::archbits, rz_core_bind_t::bphit, cfgget(), rz_core_bind_t::cfgGet, cfggeti(), rz_core_bind_t::cfggeti, cfgset(), rz_core_bind_t::cfgSet, cfgseti(), rz_core_bind_t::cfgSetI, rz_core_bind_t::cmd, rz_core_bind_t::cmdf, rz_core_bind_t::cmdstr, rz_core_bind_t::cmdstrf, rz_core_bind_t::core, rz_core_bind_t::flagsGet, getName(), rz_core_bind_t::getName, getNameDelta(), rz_core_bind_t::getNameDelta, numget(), rz_core_bind_t::numGet, rz_core_bind_t::puts, rz_cons_strcat(), rz_core_bin_apply_info(), rz_core_cmd0(), rz_core_cmd_str(), rz_core_cmd_strf(), rz_core_cmdf(), rz_core_debug_breakpoint_hit(), rz_core_debug_syscall_hit(), setab(), rz_core_bind_t::setab, and rz_core_bind_t::syshit.

Referenced by rz_core_init().

◆ rz_core_bind_cons()

RZ_API void rz_core_bind_cons ( RzCore core)

Definition at line 2612 of file core.c.

2612  {
2613  core->cons->num = core->num;
2620  core->cons->user = (void *)core;
2621 }
RZ_API RZ_OWN char * rz_core_editor(const RzCore *core, RZ_NULLABLE const char *file, RZ_NULLABLE const char *str)
Definition: core.c:3214
static void * rz_core_sleep_begin(RzCore *core)
Definition: core.c:2155
static void rz_core_break(RzCore *core)
Definition: core.c:2152
RZ_API void __cons_cb_fkey(RzCore *core, int fkey)
Definition: core.c:2601
static void rz_core_sleep_end(RzCore *core, void *user)
Definition: core.c:2163
void(* RzConsQueueTaskOneshot)(void *core, void *task, void *user)
Definition: rz_cons.h:438
void(* RzConsFunctionKey)(void *core, int fkey)
Definition: rz_cons.h:439
void *(* RzConsSleepBeginCallback)(void *core)
Definition: rz_cons.h:436
void(* RzConsSleepEndCallback)(void *core, void *user)
Definition: rz_cons.h:437
char *(* RzConsEditorCallback)(void *core, const char *file, const char *str)
Definition: rz_cons.h:433
void(* RzConsBreakCallback)(void *core)
Definition: rz_cons.h:435
RzNum * num
Definition: rz_cons.h:543
RzConsSleepBeginCallback cb_sleep_begin
Definition: rz_cons.h:528
RzConsSleepEndCallback cb_sleep_end
Definition: rz_cons.h:529
RzConsBreakCallback cb_break
Definition: rz_cons.h:527
RzConsQueueTaskOneshot cb_task_oneshot
Definition: rz_cons.h:531
void * user
Definition: rz_cons.h:534
RzConsEditorCallback cb_editor
Definition: rz_cons.h:526
RzConsFunctionKey cb_fkey
Definition: rz_cons.h:532
RZ_API void rz_core_task_enqueue_oneshot(RzCoreTaskScheduler *scheduler, RzCoreTaskOneShot func, void *user)
Definition: task.c:391

References __cons_cb_fkey(), rz_cons_t::cb_break, rz_cons_t::cb_editor, rz_cons_t::cb_fkey, rz_cons_t::cb_sleep_begin, rz_cons_t::cb_sleep_end, rz_cons_t::cb_task_oneshot, rz_core_t::cons, rz_cons_t::num, rz_core_t::num, rz_core_break(), rz_core_editor(), rz_core_sleep_begin(), rz_core_sleep_end(), rz_core_task_enqueue_oneshot(), and rz_cons_t::user.

Referenced by rz_core_init().

◆ rz_core_block_size()

RZ_API bool rz_core_block_size ( RzCore core,
ut32  bsize 
)

Definition at line 2842 of file core.c.

2842  {
2843  ut8 *bump;
2844  if (bsize == core->blocksize) {
2845  return true;
2846  }
2847  if (bsize > core->blocksize_max) {
2848  RZ_LOG_ERROR("Block size %d is too big\n", bsize);
2849  return false;
2850  }
2851  if (bsize < 1) {
2852  bsize = 1;
2853  } else if (core->blocksize_max && bsize > core->blocksize_max) {
2854  RZ_LOG_ERROR("block size is bigger than its max (check `bm` command). set to 0x%x\n", core->blocksize_max);
2855  bsize = core->blocksize_max;
2856  }
2857  bump = realloc(core->block, bsize + 1);
2858  if (!bump) {
2859  RZ_LOG_ERROR("Oops. cannot allocate that much (%u)\n", bsize);
2860  return false;
2861  }
2862  core->block = bump;
2863  core->blocksize = bsize;
2864  memset(core->block, 0xff, core->blocksize);
2865  rz_core_seek(core, core->offset, true);
2866  return true;
2867 }
return memset(p, 0, total)
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
ut32 blocksize_max
Definition: rz_core.h:304

References rz_core_t::block, rz_core_t::blocksize, rz_core_t::blocksize_max, memset(), rz_core_t::offset, realloc(), rz_core_seek(), and RZ_LOG_ERROR.

Referenced by backup_current_addr(), cmd_pCd(), cmd_pCD(), cmd_print_bars(), cmd_print_format(), core_disassembly(), DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), do_iter_offsets(), do_iter_sections(), foreach_pairs(), handle_tmp_desc(), printraw(), restore_current_addr(), rz_analyze_n_ins_esil_handler(), rz_analyze_n_ins_handler(), rz_analyze_n_ins_size_handler(), rz_block_decrease_handler(), rz_block_flag_handler(), rz_block_handler(), rz_block_increase_handler(), rz_cmd_analysis(), rz_cmd_disassembly_all_methods_class_handler(), rz_cmd_disassembly_all_possible_opcodes_handler(), rz_cmd_disassembly_all_possible_opcodes_treeview_handler(), rz_cmd_disassembly_function_handler(), rz_cmd_disassembly_function_summary_handler(), rz_cmd_disassembly_n_instrs_as_text_json_handler(), rz_cmd_print(), rz_cmd_sizes_of_n_instructions_handler(), rz_core_cmd_foreach(), rz_core_cmd_foreach3(), rz_core_cmd_subst_i(), rz_core_handle_backwards_disasm(), rz_core_print_disasm_json(), rz_core_serve(), rz_core_visual(), rz_core_visual_cmd(), rz_core_visual_title(), rz_core_visual_trackflags(), rz_main_rizin(), rz_print_utf16be_handler(), rz_print_utf16le_handler(), rz_print_utf32be_handler(), rz_print_utf32le_handler(), and rz_serialize_core_load().

◆ rz_core_break()

static void rz_core_break ( RzCore core)
static

Definition at line 2152 of file core.c.

2152  {
2153 }

Referenced by rz_core_bind_cons().

◆ rz_core_cast()

RZ_API RzCore* rz_core_cast ( void *  p)

Definition at line 396 of file core.c.

396  {
397  return (RzCore *)p;
398 }

References p.

◆ rz_core_core_plugin_print()

RZ_API RzCmdStatus rz_core_core_plugin_print ( RzCorePlugin cp,
RzCmdStateOutput state,
const char *  license 
)

Definition at line 3457 of file core.c.

3457  {
3458  PJ *pj = state->d.pj;
3459  switch (state->mode) {
3460  case RZ_OUTPUT_MODE_JSON: {
3461  pj_o(pj);
3462  pj_ks(pj, "name", cp->name);
3463  pj_ks(pj, "description", cp->desc);
3464  pj_ks(pj, "author", cp->author);
3465  pj_ks(pj, "version", cp->version);
3466  pj_ks(pj, "license", license);
3467  pj_end(pj);
3468  break;
3469  }
3470  case RZ_OUTPUT_MODE_STANDARD: {
3471  rz_cons_printf("%s: %s (Made by %s, v%s, %s)\n",
3472  cp->name, cp->desc, cp->author, cp->version, license);
3473  break;
3474  }
3475  default: {
3478  }
3479  }
3480  return RZ_CMD_STATUS_OK;
3481 }
#define rz_warn_if_reached()
Definition: rz_assert.h:29
@ RZ_CMD_STATUS_OK
command handler exited in the right way
Definition: rz_cmd.h:24
@ RZ_CMD_STATUS_NONEXISTINGCMD
command does not exist
Definition: rz_cmd.h:28
@ RZ_OUTPUT_MODE_JSON
Definition: rz_types.h:40
@ RZ_OUTPUT_MODE_STANDARD
Definition: rz_types.h:39
const char * version
Definition: rz_core.h:128
const char * desc
Definition: rz_core.h:125
const char * author
Definition: rz_core.h:127
const char * name
Definition: rz_core.h:124
Definition: dis.h:43

References rz_core_plugin_t::author, rz_core_plugin_t::desc, rz_core_plugin_t::name, pj_end(), pj_ks(), pj_o(), RZ_CMD_STATUS_NONEXISTINGCMD, RZ_CMD_STATUS_OK, rz_cons_printf(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_STANDARD, rz_warn_if_reached, and rz_core_plugin_t::version.

Referenced by rz_core_core_plugins_print().

◆ rz_core_core_plugins_print()

RZ_API RzCmdStatus rz_core_core_plugins_print ( RzCore core,
RzCmdStateOutput state 
)

Definition at line 3483 of file core.c.

3483  {
3484  RzListIter *iter;
3485  RzCorePlugin *cp;
3487  if (!core) {
3488  return RZ_CMD_STATUS_ERROR;
3489  }
3491  rz_list_foreach (core->plugins, iter, cp) {
3492  const char *license = cp->license
3493  ? cp->license
3494  : "???";
3495  status = rz_core_core_plugin_print(cp, state, license);
3496  if (status != RZ_CMD_STATUS_OK) {
3497  return status;
3498  }
3499  }
3501  return RZ_CMD_STATUS_OK;
3502 }
RZ_API void rz_cmd_state_output_array_start(RzCmdStateOutput *state)
Mark the start of an array of elements in the output.
Definition: cmd_api.c:2558
RZ_API void rz_cmd_state_output_array_end(RzCmdStateOutput *state)
Mark the end of an array of elements in the output.
Definition: cmd_api.c:2572
RZ_API RzCmdStatus rz_core_core_plugin_print(RzCorePlugin *cp, RzCmdStateOutput *state, const char *license)
Definition: core.c:3457
static const char struct stat static buf struct stat static buf static vhangup int status
Definition: sflib.h:145
enum rz_cmd_status_t RzCmdStatus
@ RZ_CMD_STATUS_ERROR
command handler had issues while running (e.g. allocation error, etc.)
Definition: rz_cmd.h:26
const char * license
Definition: rz_core.h:126
RzList * plugins
List of registered core plugins.
Definition: rz_core.h:299

References rz_core_plugin_t::license, rz_core_t::plugins, rz_cmd_state_output_array_end(), rz_cmd_state_output_array_start(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_core_plugin_print(), and status.

Referenced by rz_plugins_core_print_handler().

◆ rz_core_debug_breakpoint_hit()

static void rz_core_debug_breakpoint_hit ( RzCore core,
RzBreakpointItem bpi 
)
static

Definition at line 148 of file core.c.

148  {
149  const char *cmdbp = rz_config_get(core->config, "cmd.bp");
150  const bool cmdbp_exists = (cmdbp && *cmdbp);
151  const bool bpcmd_exists = (bpi->data && bpi->data[0]);
152  const bool may_output = (cmdbp_exists || bpcmd_exists);
153  if (may_output) {
154  rz_cons_push();
155  }
156  if (cmdbp_exists) {
157  rz_core_cmd0(core, cmdbp);
158  }
159  if (bpcmd_exists) {
160  rz_core_cmd0(core, bpi->data);
161  }
162  if (may_output) {
163  rz_cons_set_flush(true);
164  rz_cons_flush();
165  rz_cons_pop();
166  }
167 }
RZ_API void rz_cons_set_flush(bool flush)
Set whether RzCons should flush content to screen or not.
Definition: cons.c:2006
RZ_API void rz_cons_pop(void)
Definition: cons.c:876
RZ_API void rz_cons_push(void)
Definition: cons.c:860
char * data
Definition: rz_bp.h:59

References rz_core_t::config, rz_bp_item_t::data, rz_config_get(), rz_cons_flush(), rz_cons_pop(), rz_cons_push(), rz_cons_set_flush(), and rz_core_cmd0().

Referenced by rz_core_bind().

◆ rz_core_debug_syscall_hit()

static void rz_core_debug_syscall_hit ( RzCore core)
static

Definition at line 169 of file core.c.

169  {
170  const char *cmdhit = rz_config_get(core->config, "cmd.onsyscall");
171 
172  if (cmdhit && cmdhit[0] != 0) {
173  rz_core_cmd0(core, cmdhit);
174  rz_cons_flush();
175  }
176 }

References rz_core_t::config, rz_config_get(), rz_cons_flush(), and rz_core_cmd0().

Referenced by rz_core_bind().

◆ rz_core_editor()

RZ_API RZ_OWN char* rz_core_editor ( const RzCore core,
RZ_NULLABLE const char *  file,
RZ_NULLABLE const char *  str 
)

Definition at line 3214 of file core.c.

3214  {
3215  const bool interactive = rz_cons_is_interactive();
3216  if (!interactive) {
3217  return NULL;
3218  }
3219 
3220  const char *editor = rz_config_get(core->config, "cfg.editor");
3221  if (RZ_STR_ISEMPTY(editor)) {
3222  RZ_LOG_ERROR("Please set \"cfg.editor\" to run the editor");
3223  return NULL;
3224  }
3225  char *name = NULL, *ret = NULL;
3226  int fd;
3227 
3228  bool readonly = false;
3229  if (file && *file != '*') {
3230  name = strdup(file);
3231  fd = rz_sys_open(file, O_RDWR, 0644);
3232  if (fd == -1) {
3233  fd = rz_sys_open(file, O_RDWR | O_CREAT, 0644);
3234  if (fd == -1) {
3235  fd = rz_sys_open(file, O_RDONLY, 0644);
3236  readonly = true;
3237  }
3238  }
3239  } else {
3240  fd = rz_file_mkstemp(file, &name);
3241  }
3242  if (fd == -1) {
3243  free(name);
3244  return NULL;
3245  }
3246  if (readonly) {
3247  eprintf("Opening in read-only\n");
3248  } else {
3249  if (str) {
3250  const size_t str_len = strlen(str);
3251  if (write(fd, str, str_len) != str_len) {
3252  close(fd);
3253  free(name);
3254  return NULL;
3255  }
3256  }
3257  }
3258  close(fd);
3259 
3260  if (name) {
3261  char *escaped_name = rz_str_escape_sh(name);
3262  rz_sys_cmdf("%s \"%s\"", editor, escaped_name);
3263  free(escaped_name);
3264  }
3265  size_t len = 0;
3266  ret = name ? rz_file_slurp(name, &len) : 0;
3267  if (ret) {
3268  if (len && ret[len - 1] == '\n') {
3269  ret[len - 1] = 0; // chop
3270  }
3271  if (!file) {
3272  rz_file_rm(name);
3273  }
3274  }
3275  free(name);
3276  return ret;
3277 }
RZ_API bool rz_cons_is_interactive(void)
Definition: cons.c:365
static static fork const void static count close
Definition: sflib.h:33
RZ_API int rz_file_mkstemp(RZ_NULLABLE const char *prefix, char **oname)
Definition: file.c:1058
RZ_API RZ_OWN char * rz_file_slurp(const char *str, RZ_NULLABLE size_t *usz)
Definition: file.c:454
RZ_API bool rz_file_rm(const char *file)
Definition: file.c:865
#define RZ_STR_ISEMPTY(x)
Definition: rz_str.h:67
RZ_API char * rz_str_escape_sh(const char *buf)
Definition: str.c:1560
RZ_API int rz_sys_cmdf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API int rz_sys_open(const char *path, int perm, int mode)
Definition: sys.c:1740
#define O_CREAT
Definition: sftypes.h:489
#define O_RDONLY
Definition: sftypes.h:486
#define O_RDWR
Definition: sftypes.h:488
Definition: gzappend.c:170
static const z80_opcode fd[]
Definition: z80_tab.h:997

References close, rz_core_t::config, eprintf, fd, free(), len, NULL, O_CREAT, O_RDONLY, O_RDWR, rz_config_get(), rz_cons_is_interactive(), rz_file_mkstemp(), rz_file_rm(), rz_file_slurp(), RZ_LOG_ERROR, rz_str_escape_sh(), RZ_STR_ISEMPTY, rz_sys_cmdf(), rz_sys_open(), cmd_descs_generate::str, strdup(), and write.

Referenced by config_visual_hit(), meta_variable_comment_editor(), rz_cmd_alias(), rz_cmd_debug_process_profile_edit_handler(), rz_cmd_panels(), rz_core_analysis_function_signature_editor(), rz_core_bind_cons(), rz_core_init(), rz_core_meta_editor(), rz_core_run_script(), rz_eval_editor_handler(), rz_types_open_editor(), rz_types_open_file(), rz_write_from_file_handler(), rz_write_hex_from_file_handler(), rz_yank_editor_handler(), and visual_comma().

◆ rz_core_fgets()

RZ_API int rz_core_fgets ( char *  buf,
int  len,
void *  user 
)

Definition at line 1694 of file core.c.

1694  {
1695  RzCore *core = (RzCore *)user;
1696  RzCons *cons = rz_cons_singleton();
1697  RzLine *rzline = cons->line;
1698  bool prompt = cons->context->is_interactive;
1699  buf[0] = '\0';
1700  if (prompt) {
1702  rzline->ns_completion.run_user = core;
1703  rzline->completion.run = NULL;
1704  } else {
1705  rzline->history.data = NULL;
1706  rz_line_completion_set(&rzline->completion, 0, NULL);
1707  rzline->completion.run = NULL;
1708  rzline->completion.run_user = NULL;
1709  }
1710  const char *ptr = rz_line_readline();
1711  if (!ptr) {
1712  return -1;
1713  }
1714  return rz_str_ncpy(buf, ptr, len - 1);
1715 }
RZ_API RzCons * rz_cons_singleton(void)
Definition: cons.c:300
RZ_API const char * rz_line_readline(void)
Definition: dietline.c:913
static RzLineNSCompletionResult * rzshell_autocomplete(RzLineBuffer *buf, RzLinePromptType prompt_type, void *user)
Definition: core.c:1690
RZ_API void rz_line_completion_set(RzLineCompletion *completion, int argc, const char **argv)
Definition: line.c:95
RZ_API size_t rz_str_ncpy(char *dst, const char *src, size_t n)
Secure string copy with null terminator.
Definition: str.c:923
bool is_interactive
Definition: rz_cons.h:485
struct rz_line_t * line
Definition: rz_cons.h:553
RzLineCompletionCb run
Definition: rz_cons.h:1048
void * run_user
Definition: rz_cons.h:1049
char ** data
Definition: rz_cons.h:1012
void * run_user
User data that can be passed to the callback.
Definition: rz_cons.h:1081
RzLineNSCompletionCb run
Callback function that is called when autocompletion is required. (e.g. TAB is pressed)
Definition: rz_cons.h:1080
RzLineCompletion completion
Definition: rz_cons.h:1089
RzLineHistory history
Definition: rz_cons.h:1092
RzLineNSCompletion ns_completion
Definition: rz_cons.h:1090

References rz_line_t::completion, rz_cons_t::context, rz_line_hist_t::data, rz_line_t::history, rz_cons_context_t::is_interactive, len, rz_cons_t::line, rz_line_t::ns_completion, NULL, prompt(), rz_line_comp_t::run, rz_line_ns_completion_t::run, rz_line_comp_t::run_user, rz_line_ns_completion_t::run_user, rz_cons_singleton(), rz_line_completion_set(), rz_line_readline(), rz_str_ncpy(), and rzshell_autocomplete().

Referenced by cb_scrfgets(), and rz_core_init().

◆ rz_core_file_bin_file_deleted()

RZ_IPI void rz_core_file_bin_file_deleted ( RzCore core,
RzBinFile bf 
)

Definition at line 1290 of file cfile.c.

1290  {
1291  // remove all references to the deleted binfile
1292  RzListIter *it;
1293  RzCoreFile *cf;
1294  rz_list_foreach (core->files, it, cf) {
1295  rz_pvector_remove_data(&cf->binfiles, bf);
1296  }
1297 }
RZ_API void rz_pvector_remove_data(RzPVector *vec, void *x)
Definition: vector.c:362
RzPVector binfiles
all bin files that have been created for this core file
Definition: rz_core.h:155
RzList * files
Definition: rz_core.h:315

References rz_core_file_t::binfiles, rz_core_t::files, and rz_pvector_remove_data().

Referenced by ev_binfiledel_cb().

◆ rz_core_file_free()

RZ_IPI void rz_core_file_free ( RzCoreFile cf)

Definition at line 26 of file cfile.c.

26  {
27  if (!cf) {
28  return;
29  }
32  rz_pvector_fini(&cf->maps);
33  free(cf);
34 }
RZ_API void rz_pvector_fini(RzPVector *vec)
Definition: vector.c:331
RzPVector extra_files
additional files opened during mapping, for example for zeroed maps
Definition: rz_core.h:156
RzPVector maps
all maps that have been created as a result of loading this file
Definition: rz_core.h:157

References rz_core_file_t::binfiles, rz_core_file_t::extra_files, free(), rz_core_file_t::maps, and rz_pvector_fini().

Referenced by rz_core_init().

◆ rz_core_file_io_desc_closed()

RZ_IPI void rz_core_file_io_desc_closed ( RzCore core,
RzIODesc desc 
)

Definition at line 1271 of file cfile.c.

1271  {
1272  // remove all references to the closed desc
1273  RzListIter *it;
1274  RzCoreFile *cf;
1275  rz_list_foreach (core->files, it, cf) {
1277  }
1278 }

References desc, rz_core_file_t::extra_files, rz_core_t::files, and rz_pvector_remove_data().

Referenced by ev_iodescclose_cb().

◆ rz_core_file_io_map_deleted()

RZ_IPI void rz_core_file_io_map_deleted ( RzCore core,
RzIOMap map 
)

Definition at line 1280 of file cfile.c.

1280  {
1281  // remove all references to the deleted map
1282  RzListIter *it;
1283  RzCoreFile *cf;
1284  rz_list_foreach (core->files, it, cf) {
1286  }
1288 }
RZ_IPI void rz_core_io_map_info_free(RzCoreIOMapInfo *info)
Definition: cfile.c:1679

References rz_core_t::files, map(), rz_core_file_t::maps, rz_core_io_map_info_free(), and rz_pvector_remove_data().

Referenced by ev_iomapdel_cb().

◆ rz_core_fini()

RZ_API void rz_core_fini ( RzCore c)

Definition at line 2623 of file core.c.

2623  {
2624  if (!c) {
2625  return;
2626  }
2628  rz_core_task_break_all(&c->tasks);
2629  rz_core_task_join(&c->tasks, NULL, -1);
2630  rz_core_wait(c);
2631  // avoid double free
2632  RZ_FREE_CUSTOM(c->hash, rz_hash_free);
2633  RZ_FREE_CUSTOM(c->ropchain, rz_list_free);
2635  RZ_FREE(c->cmdlog);
2636  RZ_FREE(c->lastsearch);
2637  RZ_FREE(c->cons->pager);
2638  RZ_FREE(c->cmdqueue);
2639  RZ_FREE(c->lastcmd);
2640  RZ_FREE(c->stkcmd);
2641  RZ_FREE_CUSTOM(c->visual.tabs, rz_list_free);
2642  RZ_FREE(c->block);
2643  RZ_FREE_CUSTOM(c->autocomplete, rz_core_autocomplete_free);
2644 
2645  RZ_FREE_CUSTOM(c->gadgets, rz_list_free);
2646  RZ_FREE_CUSTOM(c->num, rz_num_free);
2647  RZ_FREE(c->table_query);
2648  RZ_FREE_CUSTOM(c->io, rz_io_free);
2649  RZ_FREE_CUSTOM(c->files, rz_list_free);
2650  RZ_FREE_CUSTOM(c->watchers, rz_list_free);
2651  RZ_FREE_CUSTOM(c->scriptstack, rz_list_free);
2652  rz_core_task_scheduler_fini(&c->tasks);
2653  RZ_FREE_CUSTOM(c->rcmd, rz_cmd_free);
2654  RZ_FREE_CUSTOM(c->cmd_descriptors, rz_list_free);
2655  RZ_FREE_CUSTOM(c->analysis, rz_analysis_free);
2656  RZ_FREE_CUSTOM(c->rasm, rz_asm_free);
2657  RZ_FREE_CUSTOM(c->print, rz_print_free);
2658  RZ_FREE_CUSTOM(c->bin, rz_bin_free);
2659  RZ_FREE_CUSTOM(c->lang, rz_lang_free);
2661  RZ_FREE_CUSTOM(c->config, rz_config_free);
2662  /* after rz_config_free, the value of I.teefile is trashed */
2663  /* rconfig doesnt knows how to deinitialize vars, so we
2664  should probably need to add a rz_config_free_payload callback */
2665  rz_cons_free();
2666  rz_cons_singleton()->teefile = NULL; // HACK
2667  RZ_FREE_CUSTOM(c->search, rz_search_free);
2668  RZ_FREE_CUSTOM(c->flags, rz_flag_free);
2669  RZ_FREE_CUSTOM(c->egg, rz_egg_free);
2670  RZ_FREE_CUSTOM(c->lib, rz_lib_free);
2671  RZ_FREE_CUSTOM(c->yank_buf, rz_buf_free);
2672  RZ_FREE_CUSTOM(c->graph, rz_agraph_free);
2673  RZ_FREE(c->visual_inputing);
2674  RZ_FREE(c->asmqjmps);
2675  RZ_FREE_CUSTOM(c->sdb, sdb_free);
2676  RZ_FREE_CUSTOM(c->parser, rz_parse_free);
2677  RZ_FREE(c->times);
2679  RZ_FREE(c->rtr_host);
2680  RZ_FREE(c->curtheme);
2681 }
RZ_API void rz_agraph_free(RzAGraph *g)
Definition: agraph.c:3909
RZ_API RzAnalysis * rz_analysis_free(RzAnalysis *a)
Definition: analysis.c:137
RZ_API void rz_asm_free(RzAsm *a)
Definition: asm.c:315
RZ_API void rz_bin_free(RzBin *bin)
Definition: bin.c:440
RZ_API RzCmd * rz_cmd_free(RzCmd *cmd)
Definition: cmd_api.c:208
RZ_API void rz_config_free(RzConfig *cfg)
Definition: config.c:523
RZ_API RzCons * rz_cons_free(void)
Definition: cons.c:658
RZ_API bool rz_core_plugin_fini(RzCore *core)
Definition: cplugin.c:12
RZ_API void rz_egg_free(RzEgg *egg)
Definition: egg.c:111
RZ_API RzFlag * rz_flag_free(RzFlag *f)
Definition: flag.c:271
RZ_API void rz_hash_free(RzHash *rh)
Definition: hash.c:597
RZ_API void rz_lang_free(RzLang *lang)
Definition: lang.c:46
RZ_API RzDebug * rz_debug_free(RzDebug *dbg)
Definition: debug.c:416
RZ_API void rz_parse_free(RzParse *p)
Definition: parse.c:40
RZ_API RzPrint * rz_print_free(RzPrint *p)
Definition: print.c:101
RZ_API void rz_core_wait(RzCore *core)
Definition: rtr.c:52
RZ_API void rz_buf_free(RzBuffer *b)
Free all internal data hold by the buffer and the buffer.
Definition: buf.c:1253
RZ_API void rz_event_free(RzEvent *ev)
Definition: event.c:37
RZ_API void rz_io_free(RzIO *io)
Definition: io.c:126
RZ_API void rz_lib_free(RzLib *lib)
Definition: lib.c:189
RZ_API void rz_num_free(RzNum *num)
Definition: unum.c:87
#define RZ_FREE_CUSTOM(x, y)
Definition: rz_types.h:375
RZ_API bool sdb_free(Sdb *s)
Definition: sdb.c:206
RZ_API RzSearch * rz_search_free(RzSearch *s)
Definition: search.c:52
RZ_API void rz_core_seek_free(RzCore *core)
Definition: seek.c:398
const char * teefile
Definition: rz_cons.h:519
RZ_API void rz_core_task_join(RzCoreTaskScheduler *scheduler, RzCoreTask *current, int id)
Definition: task.c:96
RZ_API void rz_core_task_break_all(RzCoreTaskScheduler *scheduler)
Definition: task.c:495
RZ_API void rz_core_task_scheduler_fini(RzCoreTaskScheduler *tasks)
Definition: task.c:27

References c, NULL, rz_agraph_free(), rz_analysis_free(), rz_asm_free(), rz_bin_free(), rz_buf_free(), rz_cmd_free(), rz_config_free(), rz_cons_free(), rz_cons_singleton(), rz_core_autocomplete_free(), rz_core_plugin_fini(), rz_core_seek_free(), rz_core_task_break_all(), rz_core_task_join(), rz_core_task_scheduler_fini(), rz_core_wait(), rz_debug_free(), rz_egg_free(), rz_event_free(), rz_flag_free(), RZ_FREE, RZ_FREE_CUSTOM, rz_hash_free(), rz_io_free(), rz_lang_free(), rz_lib_free(), rz_list_free(), rz_num_free(), rz_parse_free(), rz_print_free(), rz_search_free(), sdb_free(), and rz_cons_t::teefile.

Referenced by open_core_file(), rz_core_free(), and rz_main_rz_bin().

◆ rz_core_flag_get_by_spaces()

RZ_API RzFlagItem* rz_core_flag_get_by_spaces ( RzFlag f,
ut64  off 
)

Definition at line 2280 of file core.c.

2280  {
2281  return rz_flag_get_by_spaces(f, off,
2293  NULL);
2294 }
RZ_API RzFlagItem * rz_flag_get_by_spaces(RzFlag *f, ut64 off,...)
Definition: flag.c:326
#define RZ_FLAGS_FS_IMPORTS
Definition: rz_core.h:59
#define RZ_FLAGS_FS_SYMBOLS_SECTIONS
Definition: rz_core.h:68
#define RZ_FLAGS_FS_STRINGS
Definition: rz_core.h:66
#define RZ_FLAGS_FS_SECTIONS
Definition: rz_core.h:63
#define RZ_FLAGS_FS_RELOCS
Definition: rz_core.h:60
#define RZ_FLAGS_FS_SYMBOLS
Definition: rz_core.h:67
#define RZ_FLAGS_FS_SEGMENTS
Definition: rz_core.h:64
#define RZ_FLAGS_FS_SIGNS
Definition: rz_core.h:65
#define RZ_FLAGS_FS_RESOURCES
Definition: rz_core.h:62

References f, NULL, off, rz_flag_get_by_spaces(), RZ_FLAGS_FS_CLASSES, RZ_FLAGS_FS_FUNCTIONS, RZ_FLAGS_FS_IMPORTS, RZ_FLAGS_FS_RELOCS, RZ_FLAGS_FS_RESOURCES, RZ_FLAGS_FS_SECTIONS, RZ_FLAGS_FS_SEGMENTS, RZ_FLAGS_FS_SIGNS, RZ_FLAGS_FS_STRINGS, RZ_FLAGS_FS_SYMBOLS, and RZ_FLAGS_FS_SYMBOLS_SECTIONS.

Referenced by __core_analysis_fcn(), disasm_strings(), ds_print_ptr(), ds_sub_jumps(), getFunctionName(), rz_core_analysis_esil(), rz_core_debug_bp_add(), and rz_core_init().

◆ rz_core_free()

RZ_API void rz_core_free ( RzCore c)

Definition at line 2683 of file core.c.

2683  {
2684  rz_core_fini(c);
2685  free(c);
2686 }
RZ_API void rz_core_fini(RzCore *c)
Definition: core.c:2623

References c, free(), and rz_core_fini().

Referenced by execute_command(), rz_diff_graphs_files(), rz_diff_hex_visual(), rz_diff_load_file_with_core(), rz_main_rizin(), rz_main_rz_asm(), and rz_main_rz_sign().

◆ rz_core_get_asmqjmps()

RZ_API ut64 rz_core_get_asmqjmps ( RzCore core,
const char *  str 
)

Definition at line 203 of file core.c.

203  {
204  if (!core->asmqjmps) {
205  return UT64_MAX;
206  }
207  if (core->is_asmqjmps_letter) {
208  int i, pos = 0;
209  int len = strlen(str);
210  for (i = 0; i < len - 1; i++) {
211  if (!isupper((ut8)str[i])) {
212  return UT64_MAX;
213  }
215  pos += str[i] - 'A' + 1;
216  }
217  if (!islower((ut8)str[i])) {
218  return UT64_MAX;
219  }
221  pos += str[i] - 'a';
222  if (pos < core->asmqjmps_count) {
223  return core->asmqjmps[pos + 1];
224  }
225  } else if (str[0] > '0' && str[1] <= '9') {
226  int pos = str[0] - '0';
227  if (pos <= core->asmqjmps_count) {
228  return core->asmqjmps[pos];
229  }
230  }
231  return UT64_MAX;
232 }
#define RZ_CORE_ASMQJMPS_LETTERS
Definition: rz_core.h:184
#define islower(c)
Definition: safe-ctype.h:135
#define isupper(c)
Definition: safe-ctype.h:143
int pos
Definition: main.c:11

References rz_core_t::asmqjmps, i, rz_core_t::is_asmqjmps_letter, islower, isupper, len, pos, RZ_CORE_ASMQJMPS_LETTERS, cmd_descs_generate::str, and UT64_MAX.

Referenced by goto_asmqjmps(), and rz_core_visual_jump().

◆ rz_core_get_bin()

RZ_API RzBin* rz_core_get_bin ( RzCore core)

Definition at line 3288 of file core.c.

3288  {
3289  return core->bin;
3290 }

References rz_core_t::bin.

◆ rz_core_get_config()

RZ_API RzConfig* rz_core_get_config ( RzCore core)

Definition at line 3284 of file core.c.

3284  {
3285  return core->config;
3286 }

References rz_core_t::config.

◆ rz_core_get_cons()

RZ_API RzCons* rz_core_get_cons ( RzCore core)

Definition at line 3280 of file core.c.

3280  {
3281  return core->cons;
3282 }

References rz_core_t::cons.

◆ rz_core_get_reloc_to()

RZ_API RzBinReloc* rz_core_get_reloc_to ( RzCore core,
ut64  addr 
)

Definition at line 189 of file core.c.

189  {
191  RzBinFile *bf = rz_bin_cur(core->bin);
192  if (!bf || !bf->o || !bf->o->relocs) {
193  return NULL;
194  }
196 }
RZ_API RzBinFile * rz_bin_cur(RzBin *bin)
Definition: bin.c:895
RZ_API RzBinReloc * rz_bin_reloc_storage_get_reloc_to(RzBinRelocStorage *storage, ut64 vaddr)
Get a reloc that points exactly to vaddr or NULL.
Definition: bobj.c:173
XX curplugin == o->plugin.
Definition: rz_bin.h:298
RzBinObject * o
Definition: rz_bin.h:305
RzBinRelocStorage * relocs
Definition: rz_bin.h:279

References addr, rz_core_t::bin, NULL, rz_bin_file_t::o, rz_bin_object_t::relocs, rz_bin_cur(), rz_bin_reloc_storage_get_reloc_to(), and rz_return_val_if_fail.

Referenced by ds_print_relocs(), and ds_sub_jumps().

◆ rz_core_getreloc()

RZ_API RzBinReloc* rz_core_getreloc ( RzCore core,
ut64  addr,
int  size 
)

Definition at line 178 of file core.c.

178  {
179  if (size < 1 || addr == UT64_MAX) {
180  return NULL;
181  }
182  RzBinFile *bf = rz_bin_cur(core->bin);
183  if (!bf || !bf->o || !bf->o->relocs) {
184  return NULL;
185  }
187 }
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.
Definition: bobj.c:154

References addr, rz_core_t::bin, NULL, rz_bin_file_t::o, rz_bin_object_t::relocs, rz_bin_cur(), rz_bin_reloc_storage_get_reloc_in(), and UT64_MAX.

Referenced by _analysis_calls(), ds_print_relocs(), ds_sub_jumps(), process_reference_noreturn_cb(), rz_cmd_print(), and rz_core_print_disasm_json().

◆ rz_core_init()

RZ_API bool rz_core_init ( RzCore core)

XXX shouhld be using coreb

Definition at line 2381 of file core.c.

2381  {
2382  core->blocksize = RZ_CORE_BLOCKSIZE;
2383  core->block = (ut8 *)calloc(RZ_CORE_BLOCKSIZE + 1, 1);
2384  if (!core->block) {
2385  eprintf("Cannot allocate %d byte(s)\n", RZ_CORE_BLOCKSIZE);
2386  /* XXX memory leak */
2387  return false;
2388  }
2389  core->ev = rz_event_new(core);
2390  core->max_cmd_depth = RZ_CONS_CMD_DEPTH + 1;
2391  core->sdb = sdb_new(NULL, "rzkv.sdb", 0); // XXX: path must be in home?
2392  rz_core_seek_reset(core);
2393  core->lastsearch = NULL;
2394  core->cmdfilter = NULL;
2395  core->curtheme = strdup("default");
2396  core->switch_file_view = 0;
2397  core->cmdremote = 0;
2398  core->incomment = false;
2399  core->config = NULL;
2400  core->http_up = false;
2402  core->print = rz_print_new();
2404  rz_core_bind(core, &(core->print->coreb));
2405  core->print->user = core;
2406  core->print->num = core->num;
2409  core->print->cb_printf = rz_cons_printf;
2410  core->visual_is_inputing = false;
2411  core->visual_inputing = NULL;
2412 #if __WINDOWS__
2413  core->print->cb_eprintf = win_eprintf;
2414 #endif
2416  core->print->write = mywrite;
2417  core->print->exists_var = exists_var;
2418  core->print->disasm = __disasm;
2419  core->print->colorfor = colorfor_cb;
2420  core->print->hasrefs = hasrefs_cb;
2423  core->print->use_comments = false;
2424  rz_core_rtr_init(core);
2425  core->rtr_n = 0;
2428  core->watchers = rz_list_new();
2430  core->scriptstack = rz_list_new();
2431  core->scriptstack->free = (RzListFree)free;
2432  core->times = RZ_NEW0(RzCoreTimes);
2433  core->vmode = false;
2434  core->printidx = 0;
2435  core->lastcmd = NULL;
2436  core->cmdlog = NULL;
2437  core->stkcmd = NULL;
2438  core->cmdqueue = NULL;
2439  core->cmdrepeat = true;
2440  core->yank_buf = rz_buf_new_with_bytes(NULL, 0);
2441  core->num = rz_num_new(&num_callback, &str_callback, core);
2442  core->egg = rz_egg_new();
2444 
2445  core->fixedarch = false;
2446  core->fixedbits = false;
2447 
2448  /* initialize libraries */
2449  core->cons = rz_cons_new();
2450  if (core->cons->refcnt == 1) {
2451  core->cons = rz_cons_singleton();
2452  if (core->cons->line) {
2453  core->cons->line->user = core;
2454  core->cons->line->cb_editor =
2456  core->cons->line->cb_fkey = core->cons->cb_fkey;
2457  }
2458 #if __EMSCRIPTEN__
2459  core->cons->user_fgets = NULL;
2460 #else
2461  core->cons->user_fgets = (void *)rz_core_fgets;
2462  core->cons->user_fgets_user = core;
2463 #endif
2464  char *history = rz_path_home_history();
2465  rz_line_hist_load(history);
2466  free(history);
2467  }
2468  core->print->cons = core->cons;
2469  rz_cons_bind(&core->print->consbind);
2470 
2471  // We save the old num ad user, in order to restore it after free
2472  core->lang = rz_lang_new();
2473  core->lang->cmd_str = (char *(*)(void *, const char *))rz_core_cmd_str;
2474  core->lang->cmdf = (int (*)(void *, const char *, ...))rz_core_cmdf;
2475  rz_core_bind_cons(core);
2476  core->lang->cb_printf = rz_cons_printf;
2477  rz_lang_define(core->lang, "RzCore", "core", core);
2478  rz_lang_set_user_ptr(core->lang, core);
2479  core->rasm = rz_asm_new();
2480  core->rasm->num = core->num;
2481  core->rasm->core = core;
2482  core->analysis = rz_analysis_new();
2484  core->analysis->ev = core->ev;
2487  core->analysis->cb.on_fcn_new = on_fcn_new;
2490  core->rasm->syscall = rz_syscall_ref(core->analysis->syscall); // BIND syscall analysis/asm
2491  core->analysis->core = core;
2492  core->parser = rz_parse_new();
2493  rz_analysis_bind(core->analysis, &(core->parser->analb));
2496  rz_parse_set_user_ptr(core->parser, core);
2497  core->bin = rz_bin_new();
2499  rz_cons_bind(&core->bin->consb);
2500  // XXX we shuold use RzConsBind instead of this hardcoded pointer
2502  rz_bin_set_user_ptr(core->bin, core);
2503  core->io = rz_io_new();
2508  core->io->ff = 1;
2510  core->flags = rz_flag_new();
2511  core->graph = rz_agraph_new(rz_cons_canvas_new(1, 1));
2512  core->graph->need_reload_nodes = false;
2514  if (sizeof(ut64) * core->asmqjmps_size < core->asmqjmps_size) {
2515  core->asmqjmps_size = 0;
2516  core->asmqjmps = NULL;
2517  } else {
2518  core->asmqjmps = RZ_NEWS(ut64, core->asmqjmps_size);
2519  }
2520  core->hash = rz_hash_new();
2521 
2522  rz_bin_bind(core->bin, &(core->rasm->binb));
2523  rz_bin_bind(core->bin, &(core->analysis->binb));
2524  rz_bin_bind(core->bin, &(core->analysis->binb));
2525 
2526  rz_io_bind(core->io, &(core->search->iob));
2527  rz_io_bind(core->io, &(core->print->iob));
2528  rz_io_bind(core->io, &(core->analysis->iob));
2529  rz_io_bind(core->io, &(core->analysis->typedb->iob));
2530  rz_io_bind(core->io, &(core->bin->iob));
2531  rz_flag_bind(core->flags, &(core->analysis->flb));
2535  rz_analysis_bind(core->analysis, &(core->parser->analb));
2538 
2539  rz_core_bind(core, &(core->analysis->coreb));
2540 
2541  core->file = NULL;
2543  core->offset = 0LL;
2544  core->prompt_offset = 0LL;
2545  rz_core_cmd_init(core);
2546  rz_core_plugin_init(core);
2547 
2548  RzBreakpointContext bp_ctx = {
2549  .user = core,
2550  .is_mapped = bp_is_mapped,
2551  .maps_sync = bp_maps_sync,
2552  .bits_at = bp_bits_at
2553  };
2554  core->dbg = rz_debug_new(&bp_ctx);
2555 
2556  rz_io_bind(core->io, &(core->dbg->iob));
2557  rz_io_bind(core->io, &(core->dbg->bp->iob));
2558  rz_core_bind(core, &core->dbg->corebind);
2559  rz_core_bind(core, &core->io->corebind);
2560  core->dbg->analysis = core->analysis; // XXX: dupped instance.. can cause lost pointerz
2561  // rz_debug_use (core->dbg, "native");
2562  // XXX pushing uninitialized regstate results in trashed reg values
2563  // rz_reg_arena_push (core->dbg->reg); // create a 2 level register state stack
2564  // core->dbg->analysis->reg = core->analysis->reg; // XXX: dupped instance.. can cause lost pointerz
2565  core->io->cb_printf = rz_cons_printf;
2566  core->dbg->cb_printf = rz_cons_printf;
2567  core->dbg->bp->cb_printf = rz_cons_printf;
2568  core->dbg->ev = core->ev;
2569  // initialize config before any corebind
2570  rz_core_config_init(core);
2571 
2572  rz_core_loadlibs_init(core);
2573 
2574  // TODO: get arch from rz_bin or from native arch
2575  rz_asm_use(core->rasm, RZ_SYS_ARCH);
2577  if (RZ_SYS_BITS & RZ_SYS_BITS_64) {
2578  rz_config_set_i(core->config, "asm.bits", 64);
2579  } else {
2580  if (RZ_SYS_BITS & RZ_SYS_BITS_32) {
2581  rz_config_set_i(core->config, "asm.bits", 32);
2582  }
2583  }
2584  rz_config_set(core->config, "asm.arch", RZ_SYS_ARCH);
2585  rz_bp_use(core->dbg->bp, RZ_SYS_ARCH);
2586  update_sdb(core);
2587  {
2588  char *a = rz_path_system(RZ_FLAGS);
2589  if (a) {
2590  char *file = rz_file_path_join(a, "tags.rz");
2591  (void)rz_core_run_script(core, file);
2592  free(file);
2593  free(a);
2594  }
2595  }
2597  __init_autocomplete(core);
2598  return 0;
2599 }
RZ_API RzAGraph * rz_agraph_new(RzConsCanvas *can)
Definition: agraph.c:3922
RZ_API void rz_analysis_bind(RzAnalysis *analysis, RzAnalysisBind *b)
Definition: analysis.c:661
RZ_API RzAnalysis * rz_analysis_new(void)
Definition: analysis.c:63
RZ_API bool rz_analysis_use(RzAnalysis *analysis, const char *name)
Definition: analysis.c:184
RZ_API RzAsm * rz_asm_new(void)
Definition: asm.c:262
RZ_API bool rz_asm_use(RzAsm *a, const char *name)
Puts an Asm plugin in use and disables the previous one.
Definition: asm.c:429
RZ_API RzBin * rz_bin_new(void)
Definition: bin.c:716
RZ_API void rz_bin_bind(RzBin *bin, RzBinBind *b)
Definition: bin.c:851
RZ_API void rz_bin_set_user_ptr(RzBin *bin, void *user)
Definition: bin.c:839
RZ_API int rz_bp_use(RZ_NONNULL RzBreakpoint *bp, RZ_NONNULL const char *name)
Definition: bp_plugin.c:47
RZ_API void rz_core_analysis_type_init(RzCore *core)
Definition: canalysis.c:6610
RZ_API RzConsCanvas * rz_cons_canvas_new(int w, int h)
Definition: canvas.c:223
RZ_API int rz_core_config_init(RzCore *core)
Definition: cconfig.c:2830
RZ_API bool rz_core_run_script(RzCore *core, RZ_NONNULL const char *file)
Definition: cmd.c:457
RZ_API void rz_core_cmd_init(RzCore *core)
Definition: cmd.c:5562
RZ_API void rz_core_gadget_free(RzCoreGadget *g)
Frees a visual print gadget.
Definition: cmd_print.c:1174
RZ_API void rz_cons_bind(RzConsBind *bind)
Definition: cons.c:1910
RZ_API RzCons * rz_cons_new(void)
Definition: cons.c:589
RZ_API bool rz_core_plugin_init(RzCore *core)
Definition: cplugin.c:37
RZ_API int rz_line_hist_load(RZ_NONNULL const char *path)
Load the history of commands from path.
Definition: dietline.c:474
RZ_API RzEgg * rz_egg_new(void)
Definition: egg.c:44
RZ_API bool rz_egg_setup(RzEgg *egg, const char *arch, int bits, int endian, const char *os)
Definition: egg.c:139
RZ_API void rz_flag_bind(RzFlag *f, RzFlagBind *fb)
Definition: flag.c:752
RZ_API RzFlag * rz_flag_new(void)
Definition: flag.c:220
RZ_API void rz_core_cmpwatch_free(RzCoreCmpWatcher *w)
Definition: cmp.c:300
RZ_API RzHash * rz_hash_new(void)
Definition: hash.c:585
RZ_API const char * rz_analysis_function_get_label_at(RzAnalysisFunction *fcn, ut64 addr)
Definition: labels.c:15
RZ_API RzLang * rz_lang_new(void)
Definition: lang.c:20
RZ_API void rz_lang_set_user_ptr(RzLang *lang, void *user)
Definition: lang.c:61
RZ_API bool rz_lang_define(RzLang *lang, const char *type, const char *name, void *value)
Definition: lang.c:65
static RzFlagItem * core_flg_class_set(RzFlag *f, const char *name, ut64 addr, ut32 size)
Definition: core.c:2253
static const char * str_callback(RzNum *user, ut64 off, int *ok)
Definition: core.c:484
RZ_IPI RzIOPlugin rz_core_io_plugin_vfile
IO Plugin that opens RzBinVirtualFiles supplied by the plugin of an RzBinFile.
Definition: cvfile.c:134
static int on_fcn_new(RzAnalysis *_analysis, void *_user, RzAnalysisFunction *fcn)
Definition: core.c:108
static void ev_iomapdel_cb(RzEvent *ev, int type, void *user, void *data)
Definition: core.c:2364
RZ_API int rz_core_bind(RzCore *core, RzCoreBind *bnd)
Definition: core.c:369
static int __disasm(void *_core, ut64 addr)
Definition: core.c:1732
static bool rz_core_analysis_read_at(struct rz_analysis_t *analysis, ut64 addr, ut8 *buf, int len)
Definition: core.c:2148
static bool exists_var(RzPrint *print, ut64 func_addr, char *str)
Definition: core.c:2139
static void bp_maps_sync(void *user)
Definition: core.c:2328
RZ_API void rz_core_bind_cons(RzCore *core)
Definition: core.c:2612
RZ_IPI void rz_core_task_ctx_switch(RzCoreTask *next, void *user)
Definition: task.c:727
static char * get_comments_cb(void *user, ut64 addr)
Definition: core.c:2249
static int bp_bits_at(ut64 addr, void *user)
Definition: core.c:2335
static void update_sdb(RzCore *core)
Definition: core.c:1743
RZ_API RzFlagItem * rz_core_flag_get_by_spaces(RzFlag *f, ut64 off)
Definition: core.c:2280
static int on_fcn_rename(RzAnalysis *_analysis, void *_user, RzAnalysisFunction *fcn, const char *oname)
Definition: core.c:134
static ut64 num_callback(RzNum *userptr, const char *str, int *ok)
Definition: core.c:501
static void ev_binfiledel_cb(RzEvent *ev, int type, void *user, void *data)
Definition: core.c:2369
RZ_API int rz_core_fgets(char *buf, int len, void *user)
Definition: core.c:1694
static const char * get_section_name(void *user, ut64 addr)
Definition: core.c:2245
static int rz_core_print_offsize(void *p, ut64 addr)
Definition: core.c:1723
static void ev_iowrite_cb(RzEvent *ev, int type, void *user, void *data)
Definition: core.c:2342
static const char * colorfor_cb(void *user, ut64 addr, bool verbose)
Definition: core.c:2237
static int on_fcn_delete(RzAnalysis *_analysis, void *_user, RzAnalysisFunction *fcn)
Definition: core.c:121
static int mywrite(const ut8 *buf, int len)
Definition: core.c:2135
static RzFlagItem * core_flg_fcn_set(RzFlag *f, const char *name, ut64 addr, ut32 size)
Definition: core.c:2267
static const char * rz_core_print_offname(void *p, ut64 addr)
Definition: core.c:1717
static void ev_iodescclose_cb(RzEvent *ev, int type, void *user, void *data)
Definition: core.c:2359
RZ_IPI void rz_core_task_break_cb(RzCoreTask *task, void *user)
Definition: task.c:738
static bool bp_is_mapped(ut64 addr, int perm, void *user)
Definition: core.c:2307
static char * hasrefs_cb(void *user, ut64 addr, int mode)
Definition: core.c:2241
static RzFlagItem * core_flg_class_get(RzFlag *f, const char *name)
Definition: core.c:2260
RZ_IPI void rz_core_file_free(RzCoreFile *cf)
Definition: cfile.c:26
RZ_API RZ_OWN RzDebug * rz_debug_new(RZ_BORROW RZ_NONNULL RzBreakpointContext *bp_ctx)
Definition: debug.c:359
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
RZ_API void rz_core_loadlibs_init(RzCore *core)
Definition: libs.c:89
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
RZ_API char * rz_cons_rainbow_get(int idx, int last, bool bg)
Definition: pal.c:673
RZ_API void rz_parse_set_user_ptr(RzParse *p, void *user)
Definition: parse.c:175
RZ_API RzParse * rz_parse_new(void)
Definition: parse.c:16
RZ_API RzPrint * rz_print_new(void)
Definition: print.c:56
RZ_API bool rz_core_rtr_init(RZ_NONNULL RzCore *core)
Allocates core rtr structure.
Definition: rtr.c:1020
RZ_API RZ_OWN RzBuffer * rz_buf_new_with_bytes(RZ_NULLABLE RZ_BORROW const ut8 *bytes, ut64 len)
Creates a new buffer with a bytes array.
Definition: buf.c:465
#define RZ_CONS_CMD_DEPTH
Definition: rz_cons.h:55
char *(* RzLineEditorCb)(void *core, const char *str)
Definition: rz_cons.h:1084
#define RZ_CORE_BLOCKSIZE_MAX
Definition: rz_core.h:47
#define RZ_CORE_BLOCKSIZE
Definition: rz_core.h:46
#define RZ_CORE_ASMQJMPS_NUM
Definition: rz_core.h:183
@ RZ_EVENT_IO_DESC_CLOSE
Definition: rz_event.h:43
@ RZ_EVENT_IO_MAP_DEL
Definition: rz_event.h:44
@ RZ_EVENT_BIN_FILE_DEL
Definition: rz_event.h:45
@ RZ_EVENT_IO_WRITE
Definition: rz_event.h:42
RZ_API RzEvent * rz_event_new(void *user)
Definition: event.c:17
RZ_API RzEventCallbackHandle rz_event_hook(RzEvent *ev, int type, RzEventCallback cb, void *user)
Definition: event.c:58
RZ_API RZ_OWN char * rz_file_path_join(RZ_NONNULL const char *s1, RZ_NULLABLE const char *s2)
Concatenate two paths to create a new one with s1+s2 with the correct path separator.
Definition: file.c:1312
RZ_API void rz_io_bind(RzIO *io, RzIOBind *bnd)
Definition: io.c:550
RZ_API RzIO * rz_io_new(void)
Definition: io.c:110
RZ_API bool rz_io_plugin_add(RzIO *io, RZ_BORROW RzIOPlugin *plugin)
Definition: io_plugin.c:12
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
RZ_API RzNum * rz_num_new(RzNumCallback cb, RzNumCallback2 cb2, void *ptr)
Definition: unum.c:75
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
RZ_API RZ_OWN char * rz_path_home_history(void)
Return the path for the command history file.
Definition: path.c:212
@ RZ_SEARCH_KEYWORD
Definition: rz_search.h:17
@ RZ_SYS_BITS_32
Definition: rz_sys.h:20
#define RZ_NEWS(x, y)
Definition: rz_types.h:283
#define ZERO_FILL(x)
Definition: rz_types.h:281
#define RZ_SYS_BITS
Definition: rz_types.h:520
int(* PrintfCallback)(const char *str,...) RZ_PRINTF_CHECK(1
Definition: rz_types.h:233
#define RZ_SYS_ARCH
Definition: rz_types.h:519
#define RZ_SYS_OS
Definition: rz_types.h:587
#define RZ_FLAGS
Definition: rz_userconf.h:78
RZ_API Sdb * sdb_new(const char *path, const char *name, int lock)
Definition: sdb.c:47
RZ_API RzSearch * rz_search_new(int mode)
Definition: search.c:19
RZ_API void rz_core_seek_reset(RzCore *core)
Definition: seek.c:388
int(* on_fcn_delete)(struct rz_analysis_t *, void *user, RzAnalysisFunction *fcn)
Definition: rz_analysis.h:499
int(* on_fcn_rename)(struct rz_analysis_t *, void *user, RzAnalysisFunction *fcn, const char *oldname)
Definition: rz_analysis.h:500
int(* on_fcn_new)(struct rz_analysis_t *, void *user, RzAnalysisFunction *fcn)
Definition: rz_analysis.h:498
RzFlagSet flg_class_set
Definition: rz_analysis.h:576
RzAnalysisCallbacks cb
Definition: rz_analysis.h:607
RzFlagGetAtAddr flag_get
Definition: rz_analysis.h:616
bool(* read_at)(struct rz_analysis_t *analysis, ut64 addr, ut8 *buf, int len)
Definition: rz_analysis.h:614
RzEvent * ev
Definition: rz_analysis.h:617
RzBinBind binb
Definition: rz_analysis.h:579
RzFlagGet flg_class_get
Definition: rz_analysis.h:577
RzSyscall * syscall
Definition: rz_analysis.h:570
RzFlagBind flb
Definition: rz_analysis.h:575
RzTypeDB * typedb
Definition: rz_analysis.h:602
RzFlagSet flg_fcn_set
Definition: rz_analysis.h:578
RzCoreBind coreb
Definition: rz_analysis.h:580
bool need_reload_nodes
Definition: rz_agraph.h:68
RzNum * num
Definition: rz_asm.h:114
RzSyscall * syscall
Definition: rz_asm.h:113
void * core
Definition: rz_asm.h:104
RzBinBind binb
Definition: rz_asm.h:109
PrintfCallback cb_printf
Definition: rz_bin.h:345
RzConsBind consb
Definition: rz_bin.h:348
RzEvent * event
Definition: rz_bin.h:333
RzIOBind iob
Definition: rz_bin.h:347
Outer context of mappings/etc. in which the RzBreakpoint instance will operate in....
Definition: rz_bp.h:71
void * user
Definition: rz_bp.h:72
PrintfCallback cb_printf
Definition: rz_bp.h:88
RzIOBind iob
Definition: rz_bp.h:84
void * user_fgets_user
Definition: rz_cons.h:521
int refcnt
Definition: rz_cons.h:555
int(* user_fgets)(char *buf, int len, void *user)
Definition: rz_cons.h:520
bool vmode
Definition: rz_core.h:309
RzBuffer * yank_buf
Definition: rz_core.h:306
char * cmdlog
Definition: rz_core.h:340
RzCoreVisualMode printidx
Definition: rz_core.h:357
int cmdrepeat
Definition: rz_core.h:341
bool visual_is_inputing
Definition: rz_core.h:353
RzSearch * search
Definition: rz_core.h:331
RzEgg * egg
Definition: rz_core.h:332
char * cmdqueue
Definition: rz_core.h:336
char * lastcmd
Definition: rz_core.h:337
RzLang * lang
Definition: rz_core.h:328
int max_cmd_depth
Definition: rz_core.h:363
int rtr_n
Definition: rz_core.h:344
RzEvent * ev
Definition: rz_core.h:383
RzList * ropchain
Definition: rz_core.h:387
bool fixedbits
Definition: rz_core.h:375
RzList * scriptstack
Definition: rz_core.h:361
RzAGraph * graph
Definition: rz_core.h:333
RzList * watchers
Definition: rz_core.h:360
RzParse * parser
Definition: rz_core.h:326
RzCoreTaskScheduler tasks
Definition: rz_core.h:362
int incomment
Definition: rz_core.h:366
char * stkcmd
Definition: rz_core.h:358
RzList * gadgets
Definition: rz_core.h:384
char * cmdfilter
Definition: rz_core.h:371
ut8 switch_file_view
Definition: rz_core.h:364
char * curtheme
Definition: rz_core.h:372
bool fixedarch
Definition: rz_core.h:376
char * cmdremote
Definition: rz_core.h:369
RzHash * hash
Definition: rz_core.h:389
char * lastsearch
Definition: rz_core.h:370
char * visual_inputing
Definition: rz_core.h:354
RzCoreTimes * times
Definition: rz_core.h:325
int http_up
Definition: rz_core.h:355
RzCoreBind corebind
Definition: rz_debug.h:314
PrintfCallback cb_printf
Definition: rz_debug.h:292
RzEvent * ev
Definition: rz_debug.h:302
RzAnalysis * analysis
Definition: rz_debug.h:305
RzIOBind iob
Definition: rz_debug.h:293
int ff
Definition: rz_io.h:64
RzCoreBind corebind
Definition: rz_io.h:92
RzEvent * event
Definition: rz_io.h:90
PrintfCallback cb_printf
Definition: rz_io.h:91
RzCoreCmdStrCallback cmd_str
Definition: rz_lang.h:23
PrintfCallback cb_printf
Definition: rz_lang.h:22
RzCoreCmdfCallback cmdf
Definition: rz_lang.h:24
void * user
Definition: rz_cons.h:1108
RzLineEditorCb cb_editor
Definition: rz_cons.h:1097
RzConsFunctionKey cb_fkey
Definition: rz_cons.h:1099
RzListFree free
Definition: rz_list.h:21
RzFlagGetAtAddr flag_get
Definition: rz_parse.h:40
RzAnalysisBind analb
Definition: rz_parse.h:39
RzAnalysisLabelAt label_get
Definition: rz_parse.h:41
RzAnalysisVarList varlist
Definition: rz_parse.h:36
RzCons * cons
Definition: rz_print.h:154
RzPrintNameCallback offname
Definition: rz_print.h:147
RzConsBind consbind
Definition: rz_print.h:155
RzPrintSectionGet get_section_name
Definition: rz_print.h:152
int(* write)(const unsigned char *buf, int len)
Definition: rz_print.h:117
PrintfCallback cb_printf
Definition: rz_print.h:118
int(* disasm)(void *p, ut64 addr)
Definition: rz_print.h:122
RzPrintSizeCallback offsize
Definition: rz_print.h:148
bool(* exists_var)(struct rz_print_t *print, ut64 func_addr, char *str)
Definition: rz_print.h:160
PrintfCallback cb_eprintf
Definition: rz_print.h:119
RzPrintHasRefs hasrefs
Definition: rz_print.h:150
RzPrintColorFor colorfor
Definition: rz_print.h:149
RzNum * num
Definition: rz_print.h:156
bool use_comments
Definition: rz_print.h:139
RzPrintCommentCallback get_comments
Definition: rz_print.h:151
char *(* cb_color)(int idx, int last, bool bg)
Definition: rz_print.h:120
RzCoreBind coreb
Definition: rz_print.h:113
RzIOBind iob
Definition: rz_print.h:111
RzIOBind iob
Definition: rz_search.h:73
RzIOBind iob
Definition: rz_type.h:39
RZ_API RzSyscall * rz_syscall_ref(RzSyscall *sc)
Definition: syscall.c:12
RZ_API void rz_core_task_scheduler_init(RzCoreTaskScheduler *sched, RzCoreTaskContextSwitch ctx_switch, void *ctx_switch_user, RzCoreTaskBreak break_cb, void *break_cb_user)
Definition: task.c:7
RZ_DEPRECATE RZ_API RzList * rz_analysis_function_get_var_fields(RzAnalysisFunction *fcn, int kind)
Definition: var.c:1166

References __disasm(), __init_autocomplete(), a, rz_parse_t::analb, rz_core_t::analysis, rz_debug_t::analysis, rz_core_t::asmqjmps, rz_core_t::asmqjmps_size, rz_core_t::bin, rz_analysis_t::binb, rz_asm_t::binb, rz_core_t::block, rz_core_t::blocksize, rz_core_t::blocksize_max, rz_debug_t::bp, bp_bits_at(), bp_is_mapped(), bp_maps_sync(), calloc(), rz_analysis_t::cb, rz_print_t::cb_color, rz_line_t::cb_editor, rz_print_t::cb_eprintf, rz_cons_t::cb_fkey, rz_line_t::cb_fkey, rz_bin_t::cb_printf, rz_bp_t::cb_printf, rz_debug_t::cb_printf, rz_io_t::cb_printf, rz_lang_t::cb_printf, rz_print_t::cb_printf, rz_lang_t::cmd_str, rz_lang_t::cmdf, rz_core_t::cmdfilter, rz_core_t::cmdlog, rz_core_t::cmdqueue, rz_core_t::cmdremote, rz_core_t::cmdrepeat, rz_print_t::colorfor, colorfor_cb(), rz_core_t::config, rz_core_t::cons, rz_print_t::cons, rz_bin_t::consb, rz_print_t::consbind, rz_analysis_t::core, rz_asm_t::core, core_flg_class_get(), core_flg_class_set(), core_flg_fcn_set(), rz_analysis_t::coreb, rz_print_t::coreb, rz_debug_t::corebind, rz_io_t::corebind, rz_core_t::curtheme, rz_core_t::dbg, rz_print_t::disasm, rz_core_t::egg, eprintf, rz_analysis_t::ev, rz_core_t::ev, rz_debug_t::ev, ev_binfiledel_cb(), ev_iodescclose_cb(), ev_iomapdel_cb(), ev_iowrite_cb(), rz_bin_t::event, rz_io_t::event, exists_var(), rz_print_t::exists_var, rz_io_t::ff, rz_core_t::file, rz_core_t::files, rz_core_t::fixedarch, rz_core_t::fixedbits, rz_analysis_t::flag_get, rz_parse_t::flag_get, rz_core_t::flags, rz_analysis_t::flb, rz_analysis_t::flg_class_get, rz_analysis_t::flg_class_set, rz_analysis_t::flg_fcn_set, rz_list_t::free, free(), rz_core_t::gadgets, rz_print_t::get_comments, get_comments_cb(), get_section_name(), rz_print_t::get_section_name, rz_core_t::graph, rz_core_t::hash, rz_print_t::hasrefs, hasrefs_cb(), rz_core_t::http_up, rz_core_t::incomment, int, rz_core_t::io, rz_analysis_t::iob, rz_bin_t::iob, rz_bp_t::iob, rz_debug_t::iob, rz_search_t::iob, rz_type_db_t::iob, rz_print_t::iob, rz_parse_t::label_get, rz_core_t::lang, rz_core_t::lastcmd, rz_core_t::lastsearch, rz_cons_t::line, rz_core_t::max_cmd_depth, mywrite(), rz_ascii_graph_t::need_reload_nodes, NULL, rz_asm_t::num, rz_core_t::num, rz_print_t::num, num_callback(), rz_print_t::offname, rz_core_t::offset, rz_print_t::offsize, on_fcn_delete(), rz_analysis_callbacks_t::on_fcn_delete, on_fcn_new(), rz_analysis_callbacks_t::on_fcn_new, on_fcn_rename(), rz_analysis_callbacks_t::on_fcn_rename, rz_core_t::parser, rz_core_t::print, rz_core_t::printidx, rz_core_t::prompt_offset, rz_core_t::rasm, rz_analysis_t::read_at, rz_cons_t::refcnt, rz_core_t::root_cmd_descriptor, rz_core_t::ropchain, rz_core_t::rtr_n, rz_agraph_new(), rz_analysis_bind(), rz_analysis_function_get_label_at(), rz_analysis_function_get_var_fields(), rz_analysis_new(), rz_analysis_use(), rz_asm_new(), rz_asm_use(), rz_bin_bind(), rz_bin_new(), rz_bin_set_user_ptr(), rz_bp_use(), rz_buf_new_with_bytes(), rz_config_set(), rz_config_set_i(), rz_cons_bind(), rz_cons_canvas_new(), RZ_CONS_CMD_DEPTH, rz_cons_new(), rz_cons_printf(), rz_cons_rainbow_get(), rz_cons_singleton(), rz_core_analysis_read_at(), rz_core_analysis_type_init(), RZ_CORE_ASMQJMPS_NUM, rz_core_bind(), rz_core_bind_cons(), RZ_CORE_BLOCKSIZE, RZ_CORE_BLOCKSIZE_MAX, rz_core_cmd_init(), rz_core_cmd_str(), rz_core_cmdf(), rz_core_cmpwatch_free(), rz_core_config_init(), rz_core_editor(), rz_core_fgets(), rz_core_file_free(), rz_core_flag_get_by_spaces(), rz_core_gadget_free(), rz_core_io_plugin_vfile, rz_core_loadlibs_init(), rz_core_plugin_init(), rz_core_print_offname(), rz_core_print_offsize(), rz_core_rtr_init(), rz_core_run_script(), rz_core_seek_reset(), rz_core_task_break_cb(), rz_core_task_ctx_switch(), rz_core_task_scheduler_init(), rz_debug_new(), rz_egg_new(), rz_egg_setup(), RZ_EVENT_BIN_FILE_DEL, rz_event_hook(), RZ_EVENT_IO_DESC_CLOSE, RZ_EVENT_IO_MAP_DEL, RZ_EVENT_IO_WRITE, rz_event_new(), rz_file_path_join(), rz_flag_bind(), rz_flag_new(), RZ_FLAGS, rz_hash_new(), rz_io_bind(), rz_io_new(), rz_io_plugin_add(), rz_lang_define(), rz_lang_new(), rz_lang_set_user_ptr(), rz_line_hist_load(), rz_list_new(), rz_list_newf(), RZ_NEW0, RZ_NEWS, rz_num_new(), rz_parse_new(), rz_parse_set_user_ptr(), rz_path_home_history(), rz_path_system(), rz_print_new(), RZ_SEARCH_KEYWORD, rz_search_new(), RZ_SYS_ARCH, RZ_SYS_BITS, RZ_SYS_BITS_32, RZ_SYS_BITS_64, RZ_SYS_OS, rz_syscall_ref(), rz_core_t::scriptstack, rz_core_t::sdb, sdb_new(), rz_core_t::search, rz_core_t::stkcmd, str_callback(), strdup(), rz_core_t::switch_file_view, rz_analysis_t::syscall, rz_asm_t::syscall, rz_core_t::tasks, rz_core_t::times, rz_analysis_t::typedb, update_sdb(), rz_print_t::use_comments, rz_bp_context_t::user, rz_line_t::user, rz_print_t::user, rz_cons_t::user_fgets, rz_cons_t::user_fgets_user, ut64(), rz_parse_t::varlist, rz_core_t::visual_inputing, rz_core_t::visual_is_inputing, rz_core_t::vmode, rz_core_t::watchers, rz_print_t::write, rz_core_t::yank_buf, and ZERO_FILL.

Referenced by open_core_file(), rz_core_new(), and rz_main_rz_bin().

◆ rz_core_is_project()

bool rz_core_is_project ( RzCore core,
const char *  name 
)

◆ rz_core_ncast()

RZ_API RzCore* rz_core_ncast ( ut64  p)

Definition at line 392 of file core.c.

392  {
393  return (RzCore *)(size_t)p;
394 }
int size_t
Definition: sftypes.h:40

References p.

◆ rz_core_new()

RZ_API RzCore* rz_core_new ( void  )

Definition at line 866 of file core.c.

866  {
867  RzCore *c = RZ_NEW0(RzCore);
868  if (c) {
869  rz_core_init(c);
870  }
871  return c;
872 }
RZ_API bool rz_core_init(RzCore *core)
Definition: core.c:2381

References c, rz_core_init(), and RZ_NEW0.

Referenced by rz_diff_hex_visual(), rz_diff_load_file_with_core(), rz_main_rizin(), rz_main_rz_asm(), and rz_main_rz_sign().

◆ rz_core_notify_begin()

RZ_API void rz_core_notify_begin ( RZ_NONNULL RzCore core,
RZ_NONNULL const char *  format,
  ... 
)

Prints a message definining the beginning of a task.

Parameters
coreThe RzCore to use
formatThe message to notify

Definition at line 33 of file core.c.

33  {
34  rz_return_if_fail(core && format);
35  va_list args;
36  bool use_color = rz_config_get_i(core->config, "scr.color") > 0;
37  bool verbose = rz_config_get_b(core->config, "scr.prompt");
38  if (!verbose) {
39  return;
40  }
41  va_start(args, format);
42  if (use_color) {
43  fprintf(stderr, "[ ] " Color_YELLOW);
44  vfprintf(stderr, format, args);
45  fprintf(stderr, "\r[" Color_RESET);
46  } else {
47  fprintf(stderr, "[ ] ");
48  vfprintf(stderr, format, args);
49  fprintf(stderr, "\r[");
50  }
51  va_end(args);
52 }
#define Color_YELLOW
Definition: rz_cons.h:631

References args, Color_RESET, Color_YELLOW, rz_config_get_b(), rz_config_get_i(), rz_return_if_fail, and verbose.

Referenced by core_perform_auto_analysis(), objc_analyze(), objc_find_refs(), rz_core_analysis_everything(), rz_core_analysis_recover_golang_functions(), and rz_core_analysis_resolve_golang_strings().

◆ rz_core_notify_done()

RZ_API void rz_core_notify_done ( RZ_NONNULL RzCore core,
RZ_NONNULL const char *  format,
  ... 
)

Prints a message definining the end of a task which succeeded.

Parameters
coreThe RzCore to use
formatThe message to notify

Definition at line 60 of file core.c.

60  {
61  rz_return_if_fail(core && format);
62  va_list args;
63  bool use_color = rz_config_get_i(core->config, "scr.color") > 0;
64  bool verbose = rz_config_get_b(core->config, "scr.prompt");
65  if (!verbose) {
66  return;
67  }
68  va_start(args, format);
69  if (use_color) {
70  fprintf(stderr, "\r" Color_GREEN "[x]" Color_RESET " ");
71  vfprintf(stderr, format, args);
72  fprintf(stderr, "\n");
73  } else {
74  fprintf(stderr, "\r[x] ");
75  vfprintf(stderr, format, args);
76  fprintf(stderr, "\n");
77  }
78  va_end(args);
79 }
#define Color_GREEN
Definition: rz_cons.h:627

References args, Color_GREEN, Color_RESET, rz_config_get_b(), rz_config_get_i(), rz_return_if_fail, and verbose.

Referenced by core_perform_auto_analysis(), core_recover_golang_functions_go_1_16(), core_recover_golang_functions_go_1_18(), core_recover_golang_functions_go_1_2(), objc_analyze(), objc_find_refs(), rz_core_analysis_everything(), rz_core_analysis_recover_golang_functions(), rz_core_analysis_resolve_golang_strings(), and rz_core_analysis_value_pointers().

◆ rz_core_notify_error()

RZ_API void rz_core_notify_error ( RZ_NONNULL RzCore core,
RZ_NONNULL const char *  format,
  ... 
)

Prints a message definining the end of a task which errored.

Parameters
coreThe RzCore to use
formatThe message to notify

Definition at line 87 of file core.c.

87  {
88  rz_return_if_fail(core && format);
89  va_list args;
90  bool use_color = rz_config_get_i(core->config, "scr.color") > 0;
91  bool verbose = rz_config_get_b(core->config, "scr.prompt");
92  if (!verbose) {
93  return;
94  }
95  va_start(args, format);
96  if (use_color) {
97  fprintf(stderr, "\r" Color_RED "[!]" Color_RESET " ");
98  vfprintf(stderr, format, args);
99  fprintf(stderr, "\n");
100  } else {
101  fprintf(stderr, "\r[!] ");
102  vfprintf(stderr, format, args);
103  fprintf(stderr, "\n");
104  }
105  va_end(args);
106 }
#define Color_RED
Definition: rz_cons.h:623

References args, Color_RED, Color_RESET, rz_config_get_b(), rz_config_get_i(), rz_return_if_fail, and verbose.

Referenced by core_recover_golang_functions_go_1_16(), core_recover_golang_functions_go_1_18(), core_recover_golang_functions_go_1_2(), rz_core_analysis_recover_golang_functions(), and rz_core_analysis_resolve_golang_strings().

◆ rz_core_op_analysis()

RZ_API RzAnalysisOp* rz_core_op_analysis ( RzCore core,
ut64  addr,
RzAnalysisOpMask  mask 
)

Definition at line 2880 of file core.c.

2880  {
2881  ut8 buf[64];
2883  rz_io_read_at(core->io, addr, buf, sizeof(buf));
2884  rz_analysis_op(core->analysis, op, addr, buf, sizeof(buf), mask);
2885  return op;
2886 }
#define mask()
#define RZ_NEW(x)
Definition: rz_types.h:285

References addr, rz_core_t::analysis, rz_core_t::io, mask, op, rz_analysis_op(), rz_io_read_at(), and RZ_NEW.

Referenced by analyze_noreturn_function(), is_repeatable_inst(), rz_cmd_debug_trace_add_handler(), and rz_core_analysis_propagate_noreturn().

◆ rz_core_op_str()

RZ_API char* rz_core_op_str ( RzCore core,
ut64  addr 
)

Definition at line 2869 of file core.c.

2869  {
2870  RzAsmOp op = { 0 };
2871  ut8 buf[64];
2872  rz_asm_set_pc(core->rasm, addr);
2873  rz_io_read_at(core->io, addr, buf, sizeof(buf));
2874  int ret = rz_asm_disassemble(core->rasm, &op, buf, sizeof(buf));
2875  char *str = (ret > 0) ? strdup(rz_strbuf_get(&op.buf_asm)) : NULL;
2876  rz_asm_op_fini(&op);
2877  return str;
2878 }
RZ_API void rz_asm_op_fini(RzAsmOp *op)
Definition: aop.c:21
RZ_API char * rz_strbuf_get(RzStrBuf *sb)
Definition: strbuf.c:321

References addr, rz_core_t::io, NULL, rz_core_t::rasm, rz_asm_disassemble(), rz_asm_op_fini(), rz_asm_set_pc(), rz_io_read_at(), rz_strbuf_get(), cmd_descs_generate::str, and strdup().

Referenced by do_analysis_search().

◆ rz_core_print_offname()

static const char* rz_core_print_offname ( void *  p,
ut64  addr 
)
static

Definition at line 1717 of file core.c.

1717  {
1718  RzCore *c = (RzCore *)p;
1719  RzFlagItem *item = rz_flag_get_i(c->flags, addr);
1720  return item ? item->name : NULL;
1721 }

References addr, c, rz_flag_item_t::name, NULL, p, and rz_flag_get_i().

Referenced by rz_core_init().

◆ rz_core_print_offsize()

static int rz_core_print_offsize ( void *  p,
ut64  addr 
)
static

Definition at line 1723 of file core.c.

1723  {
1724  RzCore *c = (RzCore *)p;
1725  RzFlagItem *item = rz_flag_get_i(c->flags, addr);
1726  return item ? item->size : -1;
1727 }

References addr, c, p, rz_flag_get_i(), and rz_flag_item_t::size.

Referenced by rz_core_init().

◆ rz_core_prompt()

RZ_API int rz_core_prompt ( RzCore r,
int  sync 
)

Definition at line 2805 of file core.c.

2805  {
2806  char line[4096];
2807 
2808  int rnv = r->num->value;
2809  set_prompt(r);
2810  int ret = rz_cons_fgets(line, sizeof(line), 0, NULL);
2811  if (ret == -2) {
2812  return RZ_CORE_CMD_EXIT; // ^D
2813  }
2814  if (ret == -1) {
2815  return false; // FD READ ERROR
2816  }
2817  r->num->value = rnv;
2818  if (sync) {
2819  return rz_core_prompt_exec(r);
2820  }
2821  free(r->cmdqueue);
2822  r->cmdqueue = strdup(line);
2823  if (r->scr_gadgets && *line && *line != 'q') {
2825  }
2826  r->num->value = r->rc;
2827  return true;
2828 }
RZ_API void rz_core_gadget_print(RzCore *core)
Prints or displays the print gadgets while in visual mode.
Definition: cmd_print.c:1185
RZ_API int rz_cons_fgets(char *buf, int len, int argc, const char **argv)
Definition: input.c:339
static void set_prompt(RzCore *r)
Definition: core.c:2770
RZ_API int rz_core_prompt_exec(RzCore *r)
Definition: core.c:2830
line
Definition: setup.py:34
#define RZ_CORE_CMD_EXIT
Definition: rz_core.h:44

References free(), setup::line, NULL, r, rz_cons_fgets(), RZ_CORE_CMD_EXIT, rz_core_gadget_print(), rz_core_prompt_exec(), set_prompt(), and strdup().

Referenced by rz_core_prompt_loop().

◆ rz_core_prompt_exec()

RZ_API int rz_core_prompt_exec ( RzCore r)

Definition at line 2830 of file core.c.

2830  {
2831  int ret = rz_core_cmd(r, r->cmdqueue, true);
2832  r->rc = r->num->value;
2833  // int ret = rz_core_cmd (r, r->cmdqueue, true);
2834  rz_cons_echo(NULL);
2835  rz_cons_flush();
2836  if (r->cons && r->cons->line && r->cons->line->zerosep) {
2837  rz_cons_zero();
2838  }
2839  return ret;
2840 }
RZ_API int rz_core_cmd(RzCore *core, const char *cstr, int log)
Definition: cmd.c:5328
RZ_API void rz_cons_zero(void)
Definition: cons.c:1749
RZ_API void rz_cons_echo(const char *msg)
Definition: cons.c:939

References NULL, r, rz_cons_echo(), rz_cons_flush(), rz_cons_zero(), and rz_core_cmd().

Referenced by rz_core_prompt(), and rz_core_prompt_loop().

◆ rz_core_prompt_loop()

RZ_API void rz_core_prompt_loop ( RzCore r)

Definition at line 2688 of file core.c.

2688  {
2689  int ret;
2690  do {
2691  if (rz_config_get_b(r->config, "dbg.status")) {
2693  }
2694  int err = rz_core_prompt(r, false);
2695  if (err < 1) {
2696  // handle ^D
2697  r->num->value = 0; // r.num->value will be read by rz_main_rizin() after calling this fcn
2698  break;
2699  }
2700  /* -1 means invalid command, -2 means quit prompt loop */
2701  if ((ret = rz_core_prompt_exec(r)) == -2) {
2702  break;
2703  }
2704  } while (ret != RZ_CORE_CMD_EXIT);
2705 }
static bool err
Definition: armass.c:435
RZ_IPI void rz_core_debug_print_status(RzCore *core)
Definition: cdebug.c:356
RZ_API int rz_core_prompt(RzCore *r, int sync)
Definition: core.c:2805

References err, r, rz_config_get_b(), RZ_CORE_CMD_EXIT, rz_core_debug_print_status(), rz_core_prompt(), and rz_core_prompt_exec().

Referenced by rz_main_rizin().

◆ rz_core_search_cb()

RZ_API int rz_core_search_cb ( RzCore core,
ut64  from,
ut64  to,
RzCoreSearchCallback  cb 
)

Definition at line 3184 of file core.c.

3184  {
3185  int ret, len = core->blocksize;
3186  ut8 *buf = malloc(len);
3187  if (!buf) {
3188  eprintf("Cannot allocate blocksize\n");
3189  return false;
3190  }
3191  while (from < to) {
3192  ut64 delta = to - from;
3193  if (delta < len) {
3194  len = (int)delta;
3195  }
3196  if (!rz_io_read_at(core->io, from, buf, len)) {
3197  eprintf("Cannot read at 0x%" PFMT64x "\n", from);
3198  break;
3199  }
3200  for (ret = 0; ret < len;) {
3201  int done = cb(core, from, buf + ret, len - ret);
3202  if (done < 1) { /* interrupted */
3203  free(buf);
3204  return false;
3205  }
3206  ret += done;
3207  }
3208  from += len;
3209  }
3210  free(buf);
3211  return true;
3212 }
struct tab * done
Definition: enough.c:233
void * malloc(size_t size)
Definition: malloc.c:123
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
static const char * cb[]
Definition: z80_tab.h:176

References rz_core_t::blocksize, cb, delta, done, eprintf, free(), from, int, rz_core_t::io, len, malloc(), PFMT64x, rz_io_read_at(), to, and ut64().

◆ rz_core_serve()

RZ_API bool rz_core_serve ( RzCore core,
RzIODesc file 
)

Definition at line 2904 of file core.c.

2904  {
2905  // TODO: use rz_socket_rap_server API instead of duplicating the logic
2906  ut8 cmd, flg, *ptr = NULL, buf[1024];
2907  int i, pipefd = -1;
2908  ut64 x;
2909 
2910  RzIORap *rior = (RzIORap *)file->data;
2911  if (!rior || !rior->fd) {
2912  eprintf("rap: cannot listen.\n");
2913  return false;
2914  }
2915  RzSocket *fd = rior->fd;
2916  eprintf("RAP Server started (rap.loop=%s)\n",
2917  rz_config_get(core->config, "rap.loop"));
2919 reaccept:
2920  while (!rz_cons_is_breaked()) {
2922  if (!c) {
2923  break;
2924  }
2925  if (rz_cons_is_breaked()) {
2926  goto out_of_function;
2927  }
2928  if (!c) {
2929  eprintf("rap: cannot accept\n");
2930  rz_socket_free(c);
2931  goto out_of_function;
2932  }
2933  eprintf("rap: client connected\n");
2934  for (; !rz_cons_is_breaked();) {
2935  if (!rz_socket_read_block(c, &cmd, 1)) {
2936  eprintf("rap: connection closed\n");
2937  if (rz_config_get_i(core->config, "rap.loop")) {
2938  eprintf("rap: waiting for new connection\n");
2939  rz_socket_free(c);
2940  goto reaccept;
2941  }
2942  goto out_of_function;
2943  }
2944  switch (cmd) {
2945  case RAP_PACKET_OPEN:
2946  rz_socket_read_block(c, &flg, 1); // flags
2947  eprintf("open (%d): ", cmd);
2948  rz_socket_read_block(c, &cmd, 1); // len
2949  pipefd = -1;
2950  if (UT8_ADD_OVFCHK(cmd, 1)) {
2951  goto out_of_function;
2952  }
2953  ptr = malloc((size_t)cmd + 1);
2954  if (!ptr) {
2955  eprintf("Cannot malloc in rmt-open len = %d\n", cmd);
2956  } else {
2957  ut64 baddr = rz_config_get_i(core->config, "bin.laddr");
2958  rz_socket_read_block(c, ptr, cmd);
2959  ptr[cmd] = 0;
2960  ut32 perm = RZ_PERM_R;
2961  if (flg & RZ_PERM_W) {
2962  perm |= RZ_PERM_W;
2963  }
2964  if (rz_core_file_open(core, (const char *)ptr, perm, 0)) {
2965  int fd = rz_io_fd_get_current(core->io);
2966  rz_core_bin_load(core, NULL, baddr);
2967  rz_io_map_add(core->io, fd, perm, 0, 0, rz_io_fd_size(core->io, fd));
2968  if (core->file) {
2969  pipefd = fd;
2970  } else {
2971  pipefd = -1;
2972  }
2973  eprintf("(flags: %d) len: %d filename: '%s'\n",
2974  flg, cmd, ptr); // config.file);
2975  } else {
2976  eprintf("Cannot open file (%s)\n", ptr);
2977  rz_socket_close(c);
2978  if (rz_config_get_i(core->config, "rap.loop")) {
2979  eprintf("rap: waiting for new connection\n");
2980  rz_socket_free(c);
2981  goto reaccept;
2982  }
2983  goto out_of_function; // XXX: Close connection and goto accept
2984  }
2985  }
2987  rz_write_be32(buf + 1, pipefd);
2988  rz_socket_write(c, buf, 5);
2989  rz_socket_flush(c);
2990  RZ_FREE(ptr);
2991  break;
2992  case RAP_PACKET_READ:
2993  rz_socket_read_block(c, (ut8 *)&buf, 4);
2994  i = rz_read_be32(buf);
2995  ptr = (ut8 *)malloc(i + core->blocksize + 5);
2996  if (ptr) {
2997  rz_core_block_read(core);
2998  ptr[0] = RAP_PACKET_READ | RAP_PACKET_REPLY;
2999  if (i > RAP_PACKET_MAX) {
3000  i = RAP_PACKET_MAX;
3001  }
3002  if (i > core->blocksize) {
3003  rz_core_block_size(core, i);
3004  }
3005  if (i + 128 < core->blocksize) {
3006  rz_core_block_size(core, i);
3007  }
3008  rz_write_be32(ptr + 1, i);
3009  memcpy(ptr + 5, core->block, i); // core->blocksize);
3010  rz_socket_write(c, ptr, i + 5);
3011  rz_socket_flush(c);
3012  RZ_FREE(ptr);
3013  } else {
3014  eprintf("Cannot read %d byte(s)\n", i);
3015  rz_socket_free(c);
3016  // TODO: reply error here
3017  goto out_of_function;
3018  }
3019  break;
3020  case RAP_PACKET_CMD: {
3021  char *cmd = NULL, *cmd_output = NULL;
3022  char bufr[8], *bufw = NULL;
3023  ut32 cmd_len = 0;
3024  int i;
3025 
3026  /* read */
3027  rz_socket_read_block(c, (ut8 *)&bufr, 4);
3028  i = rz_read_be32(bufr);
3029  if (i > 0 && i < RAP_PACKET_MAX) {
3030  if ((cmd = malloc(i + 1))) {
3031  rz_socket_read_block(c, (ut8 *)cmd, i);
3032  cmd[i] = '\0';
3033  int scr_interactive = rz_config_get_i(core->config, "scr.interactive");
3034  rz_config_set_i(core->config, "scr.interactive", 0);
3035  cmd_output = rz_core_cmd_str(core, cmd);
3036  rz_config_set_i(core->config, "scr.interactive", scr_interactive);
3037  free(cmd);
3038  } else {
3039  eprintf("rap: cannot malloc\n");
3040  }
3041  } else {
3042  eprintf("rap: invalid length '%d'\n", i);
3043  }
3044  /* write */
3045  if (cmd_output) {
3046  cmd_len = strlen(cmd_output) + 1;
3047  } else {
3048  cmd_output = strdup("");
3049  cmd_len = 0;
3050  }
3051 #if DEMO_SERVER_SENDS_CMD_TO_CLIENT
3052  static bool once = true;
3053  /* TODO: server can reply a command request to the client only here */
3054  if (once) {
3055  const char *cmd = "pd 4";
3056  int cmd_len = strlen(cmd) + 1;
3057  ut8 *b = malloc(cmd_len + 5);
3058  b[0] = RAP_PACKET_CMD;
3059  rz_write_be32(b + 1, cmd_len);
3060  strcpy((char *)b + 5, cmd);
3061  rz_socket_write(c, b, 5 + cmd_len);
3062  rz_socket_flush(c);
3063 
3064  /* read response */
3065  rz_socket_read_block(c, b, 5);
3066  if (b[0] == (RAP_PACKET_CMD | RAP_PACKET_REPLY)) {
3067  ut32 n = rz_read_be32(b + 1);
3068  eprintf("REPLY %d\n", n);
3069  if (n > 0) {
3070  ut8 *res = calloc(1, n);
3071  rz_socket_read_block(c, res, n);
3072  eprintf("RESPONSE(%s)\n", (const char *)res);
3073  free(res);
3074  }
3075  }
3076  rz_socket_flush(c);
3077  free(b);
3078  once = false;
3079  }
3080 #endif
3081  bufw = malloc(cmd_len + 5);
3082  bufw[0] = (ut8)(RAP_PACKET_CMD | RAP_PACKET_REPLY);
3083  rz_write_be32(bufw + 1, cmd_len);
3084  memcpy(bufw + 5, cmd_output, cmd_len);
3085  rz_socket_write(c, bufw, cmd_len + 5);
3086  rz_socket_flush(c);
3087  free(bufw);
3088  free(cmd_output);
3089  break;
3090  }
3091  case RAP_PACKET_WRITE:
3092  rz_socket_read_block(c, buf, 4);
3093  x = rz_read_at_be32(buf, 0);
3094  ptr = malloc(x);
3095  rz_socket_read_block(c, ptr, x);
3096  int ret = rz_core_write_at(core, core->offset, ptr, x);
3098  rz_write_be32(buf + 1, ret);
3099  rz_socket_write(c, buf, 5);
3100  rz_socket_flush(c);
3101  RZ_FREE(ptr);
3102  break;
3103  case RAP_PACKET_SEEK:
3104  rz_socket_read_block(c, buf, 9);
3105  x = rz_read_at_be64(buf, 1);
3106  if (buf[0] == 2) {
3107  if (core->file) {
3108  x = rz_io_fd_size(core->io, core->file->fd);
3109  } else {
3110  x = 0;
3111  }
3112  } else {
3113  if (buf[0] == 0) {
3114  rz_core_seek(core, x, true); // buf[0]);
3115  }
3116  x = core->offset;
3117  }
3119  rz_write_be64(buf + 1, x);
3120  rz_socket_write(c, buf, 9);
3121  rz_socket_flush(c);
3122  break;
3123  case RAP_PACKET_CLOSE:
3124  // XXX : proper shutdown
3125  rz_socket_read_block(c, buf, 4);
3126  i = rz_read_be32(buf);
3127  {
3128  // FIXME: Use rz_socket_close
3129  int ret = close(i);
3130  rz_write_be32(buf + 1, ret);
3132  rz_socket_write(c, buf, 5);
3133  rz_socket_flush(c);
3134  }
3135  break;
3136  default:
3137  if (cmd == 'G') {
3138  // silly http emulation over rap://
3139  char line[256] = { 0 };
3140  rz_socket_read_block(c, (ut8 *)line, sizeof(line));
3141  if (!strncmp(line, "ET /cmd/", 8)) {
3142  char *cmd = line + 8;
3143  char *http = strstr(cmd, "HTTP");
3144  if (http) {
3145  *http = 0;
3146  http--;
3147  if (*http == ' ') {
3148  *http = 0;
3149  }
3150  }
3152  char *res = rz_core_cmd_str(core, cmd);
3153  if (res) {
3154  rz_socket_printf(c, "HTTP/1.0 %d %s\r\n%s"
3155  "Connection: close\r\nContent-Length: %d\r\n\r\n",
3156  200, "OK", "", -1); // strlen (res));
3157  rz_socket_write(c, res, strlen(res));
3158  free(res);
3159  }
3160  rz_socket_flush(c);
3161  rz_socket_close(c);
3162  }
3163  } else {
3164  eprintf("[rap] unknown command 0x%02x\n", cmd);
3165  rz_socket_close(c);
3166  RZ_FREE(ptr);
3167  }
3168  if (rz_config_get_i(core->config, "rap.loop")) {
3169  eprintf("rap: waiting for new connection\n");
3170  rz_socket_free(c);
3171  goto reaccept;
3172  }
3173  goto out_of_function;
3174  }
3175  }
3176  eprintf("client: disconnected\n");
3177  rz_socket_free(c);
3178  }
3179 out_of_function:
3181  return false;
3182 }
static ut64 baddr(RzBinFile *bf)
Definition: bin_any.c:58
RZ_API RZ_BORROW RzCoreFile * rz_core_file_open(RZ_NONNULL RzCore *r, RZ_NONNULL const char *file, int flags, ut64 loadaddr)
Tries to open the file as is, otherwise tries as is a compilation of files.
Definition: cfile.c:1182
RZ_API bool rz_core_bin_load(RZ_NONNULL RzCore *r, RZ_NULLABLE const char *filenameuri, ut64 baddr)
Definition: cfile.c:942
RZ_API bool rz_core_write_at(RzCore *core, ut64 addr, const ut8 *buf, int size)
Definition: cio.c:145
RZ_API int rz_core_block_read(RzCore *core)
Definition: cio.c:243
RZ_API void rz_cons_break_pop(void)
Definition: cons.c:361
RZ_API void rz_cons_break_push(RzConsBreak cb, void *user)
Definition: cons.c:357
RZ_API bool rz_cons_is_breaked(void)
Definition: cons.c:373
#define ut8
Definition: dcpu16.h:8
static void rap_break(void *u)
Definition: core.c:2894
RZ_API bool rz_core_block_size(RzCore *core, ut32 bsize)
Definition: core.c:2842
static void rz_write_be64(void *dest, ut64 val)
Definition: rz_endian.h:119
static ut64 rz_read_at_be64(const void *src, size_t offset)
Definition: rz_endian.h:114
static ut32 rz_read_at_be32(const void *src, size_t offset)
Definition: rz_endian.h:93
static ut32 rz_read_be32(const void *src)
Definition: rz_endian.h:87
static void rz_write_be32(void *dest, ut32 val)
Definition: rz_endian.h:98
RZ_API int rz_io_fd_get_current(RzIO *io)
Definition: io_fd.c:135
RZ_API RzIOMap * rz_io_map_add(RzIO *io, int fd, int flags, ut64 delta, ut64 addr, ut64 size)
Definition: io_map.c:151
RZ_API int rz_socket_read_block(RzSocket *s, unsigned char *buf, int len)
Definition: socket.c:808
RZ_API RzSocket * rz_socket_accept(RzSocket *s)
Definition: socket.c:582
RZ_API int rz_socket_flush(RzSocket *s)
Definition: socket.c:677
RZ_API void rz_socket_printf(RzSocket *s, const char *fmt,...) RZ_PRINTF_CHECK(2
@ RAP_PACKET_MAX
Definition: rz_socket.h:179
@ RAP_PACKET_READ
Definition: rz_socket.h:172
@ RAP_PACKET_SEEK
Definition: rz_socket.h:174
@ RAP_PACKET_OPEN
Definition: rz_socket.h:171
@ RAP_PACKET_CMD
Definition: rz_socket.h:177
@ RAP_PACKET_REPLY
Definition: rz_socket.h:178
@ RAP_PACKET_CLOSE
Definition: rz_socket.h:175
@ RAP_PACKET_WRITE
Definition: rz_socket.h:173
RZ_API int rz_socket_free(RzSocket *s)
Definition: socket.c:453
RZ_API int rz_socket_write(RzSocket *s, void *buf, int len)
Definition: socket.c:724
RZ_API void rz_str_uri_decode(char *buf)
Definition: str.c:2845
#define RZ_PERM_R
Definition: rz_types.h:93
#define RZ_PERM_W
Definition: rz_types.h:94
#define UT8_ADD_OVFCHK(x, y)
static uv_once_t once
Definition: threadpool.c:32

References b, baddr(), rz_core_t::block, rz_core_t::blocksize, c, calloc(), close, cmd, rz_core_t::config, eprintf, fd, RzIORap::fd, rz_core_file_t::fd, rz_core_t::file, free(), i, if(), rz_core_t::io, setup::line, malloc(), memcpy(), n, NULL, rz_core_t::offset, once, rap_break(), RAP_PACKET_CLOSE, RAP_PACKET_CMD, RAP_PACKET_MAX, RAP_PACKET_OPEN, RAP_PACKET_READ, RAP_PACKET_REPLY, RAP_PACKET_SEEK, RAP_PACKET_WRITE, rz_config_get(), rz_config_get_i(), rz_config_set_i(), rz_cons_break_pop(), rz_cons_break_push(), rz_cons_is_breaked(), rz_core_bin_load(), rz_core_block_read(), rz_core_block_size(), rz_core_cmd_str(), rz_core_file_open(), rz_core_seek(), rz_core_write_at(), RZ_FREE, rz_io_fd_get_current(), rz_io_fd_size(), rz_io_map_add(), RZ_PERM_R, RZ_PERM_W, rz_read_at_be32(), rz_read_at_be64(), rz_read_be32(), rz_socket_accept(), rz_socket_close(), rz_socket_flush(), rz_socket_free(), rz_socket_printf(), rz_socket_read_block(), rz_socket_write(), rz_str_uri_decode(), rz_write_be32(), rz_write_be64(), strdup(), ut64(), ut8, UT8_ADD_OVFCHK, and x.

Referenced by rz_core_file_open(), and rz_core_rtr_rap_run().

◆ rz_core_set_asmqjmps()

RZ_API void rz_core_set_asmqjmps ( RzCore core,
char *  str,
size_t  len,
int  pos 
)

Definition at line 282 of file core.c.

282  {
283  if (core->is_asmqjmps_letter) {
284  int i, j = 0;
285  // if (pos > 0) {
286  pos--;
288  for (i = 0; i < RZ_CORE_ASMQJMPS_LEN_LETTERS - 1; i++) {
289  int div = pos / letter_divs[i];
290  pos %= letter_divs[i];
291  if (div > 0 && j < len) {
292  str[j++] = 'A' + div - 1;
293  }
294  }
295  if (j < len) {
296  int div = pos % RZ_CORE_ASMQJMPS_LETTERS;
297  str[j++] = 'a' + div;
298  }
299  str[j] = '\0';
300  } else {
301  snprintf(str, len, "%d", pos);
302  }
303 }
static ut64 letter_divs[RZ_CORE_ASMQJMPS_LEN_LETTERS - 1]
Definition: core.c:18

References i, rz_core_t::is_asmqjmps_letter, len, letter_divs, pos, RZ_CORE_ASMQJMPS_LEN_LETTERS, RZ_CORE_ASMQJMPS_LETTERS, snprintf, and cmd_descs_generate::str.

Referenced by rz_core_add_asmqjmp().

◆ rz_core_sleep_begin()

static void* rz_core_sleep_begin ( RzCore core)
static

Definition at line 2155 of file core.c.

2155  {
2156  RzCoreTask *task = rz_core_task_self(&core->tasks);
2157  if (task) {
2159  }
2160  return task;
2161 }
struct rz_core_task_t RzCoreTask
Definition: rz_core.h:254
RZ_API void rz_core_task_sleep_begin(RzCoreTask *task)
Definition: task.c:438
RZ_API RzCoreTask * rz_core_task_self(RzCoreTaskScheduler *scheduler)
Definition: task.c:446

References rz_core_task_self(), rz_core_task_sleep_begin(), and rz_core_t::tasks.

Referenced by rz_core_bind_cons().

◆ rz_core_sleep_end()

static void rz_core_sleep_end ( RzCore core,
void *  user 
)
static

Definition at line 2163 of file core.c.

2163  {
2164  RzCoreTask *task = (RzCoreTask *)user;
2165  if (task) {
2166  rz_core_task_sleep_end(task);
2167  }
2168 }
RZ_API void rz_core_task_sleep_end(RzCoreTask *task)
Definition: task.c:442

References rz_core_task_sleep_end().

Referenced by rz_core_bind_cons().

◆ rz_core_syscall()

RZ_API RzBuffer* rz_core_syscall ( RzCore core,
const char *  name,
const char *  args 
)

XXX USE trap

Definition at line 3305 of file core.c.

3305  {
3306  RzBuffer *b = NULL;
3307  char code[1024];
3308  int num;
3309 
3310  // arch check
3311  if (strcmp(core->analysis->cur->arch, "x86")) {
3312  eprintf("architecture not yet supported!\n");
3313  return 0;
3314  }
3315 
3317 
3318  // bits check
3319  switch (core->rasm->bits) {
3320  case 32:
3321  if (strcmp(name, "setup") && !num) {
3322  eprintf("syscall not found!\n");
3323  return 0;
3324  }
3325  break;
3326  case 64:
3327  if (strcmp(name, "read") && !num) {
3328  eprintf("syscall not found!\n");
3329  return 0;
3330  }
3331  break;
3332  default:
3333  eprintf("syscall not found!\n");
3334  return 0;
3335  }
3336 
3337  snprintf(code, sizeof(code),
3338  "sc@syscall(%d);\n"
3339  "main@global(0) { sc(%s);\n"
3340  ":int3\n"
3341  "}\n",
3342  num, args);
3343  rz_egg_reset(core->egg);
3344  // TODO: setup arch/bits/os?
3345  rz_egg_load(core->egg, code, 0);
3346 
3347  if (!rz_egg_compile(core->egg)) {
3348  eprintf("Cannot compile.\n");
3349  }
3350  if (!rz_egg_assemble(core->egg)) {
3351  eprintf("rz_egg_assemble: invalid assembly\n");
3352  }
3353  if ((b = rz_egg_get_bin(core->egg))) {
3354 #if 0
3355  if (b->length > 0) {
3356  for (i = 0; i < b->length; i++) {
3357  rz_cons_printf ("%02x", b->buf[i]);
3358  }
3359  rz_cons_printf ("\n");
3360  }
3361 #endif
3362  }
3363  return b;
3364 }
RZ_API void rz_egg_reset(RzEgg *egg)
Definition: egg.c:128
RZ_API int rz_egg_compile(RzEgg *egg)
Definition: egg.c:394
RZ_API RzBuffer * rz_egg_get_bin(RzEgg *egg)
Definition: egg.c:423
RZ_API void rz_egg_load(RzEgg *egg, const char *code, int format)
Definition: egg.c:202
RZ_API bool rz_egg_assemble(RzEgg *egg)
Definition: egg.c:390
Definition: inftree9.h:24
struct rz_analysis_plugin_t * cur
Definition: rz_analysis.h:586
RZ_API int rz_syscall_get_num(RzSyscall *s, const char *str)
Definition: syscall.c:376

References rz_core_t::analysis, rz_analysis_plugin_t::arch, args, b, rz_asm_t::bits, rz_analysis_t::cur, rz_core_t::egg, eprintf, i, NULL, num, rz_core_t::rasm, rz_cons_printf(), rz_egg_assemble(), rz_egg_compile(), rz_egg_get_bin(), rz_egg_load(), rz_egg_reset(), rz_syscall_get_num(), snprintf, and rz_analysis_t::syscall.

Referenced by rz_cmd_debug(), rz_core_syscallf(), and rz_egg_syscall_handler().

◆ rz_core_syscallf()

RZ_API RzBuffer* rz_core_syscallf ( RzCore core,
const char *  name,
const char *  fmt,
  ... 
)

Definition at line 3292 of file core.c.

3292  {
3293  char str[1024];
3294  RzBuffer *buf;
3295  va_list ap;
3296  va_start(ap, fmt);
3297 
3298  vsnprintf(str, sizeof(str), fmt, ap);
3299  buf = rz_core_syscall(core, name, str);
3300 
3301  va_end(ap);
3302  return buf;
3303 }
vsnprintf
Definition: kernel.h:366
RZ_API RzBuffer * rz_core_syscall(RzCore *core, const char *name, const char *args)
Definition: core.c:3305

References buf, rz_core_syscall(), cmd_descs_generate::str, and vsnprintf.

Referenced by rz_cmd_debug().

◆ rz_core_table()

RZ_API RzTable* rz_core_table ( RzCore core)

Definition at line 3449 of file core.c.

3449  {
3450  RzTable *table = rz_table_new();
3451  if (table) {
3452  table->cons = core->cons;
3453  }
3454  return table;
3455 }
RZ_API RzTable * rz_table_new(void)
Definition: table.c:103
void * cons
Definition: rz_table.h:53

References rz_core_t::cons, RzTable::cons, and rz_table_new().

Referenced by cmd_print_blocks(), references_handler(), rz_analysis_function_list_ascii_handler(), rz_cmd_info_section_bars_handler(), rz_core_analysis_bbs_asciiart(), rz_open_binary_list_ascii_handler(), and rz_open_maps_list_ascii_handler().

◆ rz_core_task_break_cb()

RZ_IPI void rz_core_task_break_cb ( RzCoreTask task,
void *  user 
)

Definition at line 738 of file task.c.

738  {
739  CoreTaskCtx *ctx = task->runner_user;
740  rz_cons_context_break(ctx ? ctx->cons_context : NULL);
741 }
RZ_API void rz_cons_context_break(RzConsContext *context)
Definition: cons.c:917

References NULL, and rz_cons_context_break().

Referenced by rz_core_init().

◆ rz_core_task_ctx_switch()

RZ_IPI void rz_core_task_ctx_switch ( RzCoreTask next,
void *  user 
)

Definition at line 727 of file task.c.

727  {
728  if (next->runner_user) {
729  CoreTaskCtx *ctx = next->runner_user;
730  if (ctx->cons_context) {
731  rz_cons_context_load(ctx->cons_context);
732  return;
733  }
734  }
736 }
RZ_API void rz_cons_context_reset(void)
Definition: cons.c:909
RZ_API void rz_cons_context_load(RzConsContext *context)
Definition: cons.c:905

References rz_cons_context_load(), and rz_cons_context_reset().

Referenced by rz_core_init().

◆ rz_core_vfile_bin_file_deleted()

RZ_IPI void rz_core_vfile_bin_file_deleted ( RzCore core,
RzBinFile bf 
)

Definition at line 156 of file cvfile.c.

156  {
157  // close all vfile descs that point into the binfile that is about to be closed
158  // This is strictly necessary because VFileCtx holds pointers into it!
159  RzList *descs = rz_id_storage_list(core->io->files);
160  if (!descs) {
161  return;
162  }
163  RzListIter *it;
164  RzIODesc *desc;
165  rz_list_foreach (descs, it, desc) {
166  if (strcmp(desc->plugin->name, rz_core_io_plugin_vfile.name)) {
167  continue;
168  }
169  VFileCtx *ctx = desc->data;
170  if (ctx->bf == bf) {
172  }
173  }
174  rz_list_free(descs);
175 }
RzIOPlugin rz_core_io_plugin_vfile
IO Plugin that opens RzBinVirtualFiles supplied by the plugin of an RzBinFile.
Definition: cvfile.c:134
RZ_API RzList * rz_id_storage_list(RzIDStorage *s)
Definition: idpool.c:283
RZ_API bool rz_io_desc_close(RzIODesc *desc)
Definition: io_desc.c:165
Definition: cvfile.c:9
const char * name
Definition: rz_io.h:115
RzIDStorage * files
Definition: rz_io.h:75

References desc, rz_io_t::files, rz_core_t::io, rz_io_plugin_t::name, rz_core_io_plugin_vfile, rz_id_storage_list(), rz_io_desc_close(), and rz_list_free().

Referenced by ev_binfiledel_cb().

◆ RZ_LIB_VERSION()

RZ_LIB_VERSION ( rz_core  )

◆ rzshell_autocomplete()

static RzLineNSCompletionResult* rzshell_autocomplete ( RzLineBuffer buf,
RzLinePromptType  prompt_type,
void *  user 
)
static

Definition at line 1690 of file core.c.

1690  {
1691  return rz_core_autocomplete_rzshell((RzCore *)user, buf, prompt_type);
1692 }
RZ_API RzLineNSCompletionResult * rz_core_autocomplete_rzshell(RzCore *core, RzLineBuffer *buf, RzLinePromptType prompt_type)
Definition: cautocmpl.c:1048

References rz_core_autocomplete_rzshell().

Referenced by rz_core_fgets().

◆ set_prompt()

static void set_prompt ( RzCore r)
static

Definition at line 2770 of file core.c.

2770  {
2771  const char *cmdprompt = rz_config_get(r->config, "cmd.prompt");
2772  const char *BEGIN = "";
2773  const char *END = "";
2774  const char *remote = "";
2775 
2776  if (cmdprompt && *cmdprompt) {
2777  rz_core_cmd(r, cmdprompt, 0);
2778  }
2779 
2780  if (r->cmdremote) {
2781  char *s = rz_core_cmd_str(r, "s");
2782  r->offset = rz_num_math(NULL, s);
2783  free(s);
2784  remote = "R!";
2785  }
2786 
2787  if (rz_config_get_i(r->config, "scr.color")) {
2788  BEGIN = r->cons->context->pal.prompt;
2789  END = r->cons->context->pal.reset;
2790  }
2791 
2792  RzStrBuf prompt_ct;
2793  rz_strbuf_init(&prompt_ct);
2794  rz_strbuf_appendf(&prompt_ct, "%s[%s", BEGIN, remote);
2795  bool added = prompt_add_file(r, &prompt_ct, false);
2796  added = prompt_add_section(r, &prompt_ct, added);
2797  added = prompt_add_offset(r, &prompt_ct, added);
2798  rz_strbuf_appendf(&prompt_ct, "]>%s ", END);
2799 
2800  char *prompt = rz_strbuf_drain_nofree(&prompt_ct);
2802  free(prompt);
2803 }
static bool prompt_add_section(RzCore *core, RzStrBuf *sb, bool add_sep)
Definition: core.c:2718
static bool prompt_add_offset(RzCore *core, RzStrBuf *sb, bool add_sep)
Definition: core.c:2733
static bool prompt_add_file(RzCore *core, RzStrBuf *sb, bool add_sep)
Definition: core.c:2707
RZ_API void rz_line_set_prompt(const char *prompt)
Definition: line.c:56
RZ_API RZ_OWN char * rz_strbuf_drain_nofree(RzStrBuf *sb)
Definition: strbuf.c:349
RZ_API void rz_strbuf_init(RzStrBuf *sb)
Definition: strbuf.c:33

References free(), NULL, prompt(), prompt_add_file(), prompt_add_offset(), prompt_add_section(), r, rz_config_get(), rz_config_get_i(), rz_core_cmd(), rz_core_cmd_str(), rz_line_set_prompt(), rz_num_math(), rz_strbuf_appendf(), rz_strbuf_drain_nofree(), rz_strbuf_init(), and s.

Referenced by rz_core_prompt().

◆ setab()

static void setab ( RzCore core,
const char *  arch,
int  bits 
)
static

Definition at line 305 of file core.c.

305  {
306  if (arch) {
307  rz_config_set(core->config, "asm.arch", arch);
308  }
309  if (bits > 0) {
310  rz_config_set_i(core->config, "asm.bits", bits);
311  }
312 }
cs_arch arch
Definition: cstool.c:13

References arch, bits(), rz_core_t::config, rz_config_set(), and rz_config_set_i().

Referenced by rz_core_bind().

◆ str_callback()

static const char* str_callback ( RzNum user,
ut64  off,
int ok 
)
static

Definition at line 484 of file core.c.

484  {
485  RzFlag *f = (RzFlag *)user;
486  if (ok) {
487  *ok = 0;
488  }
489  if (f) {
490  RzFlagItem *item = rz_flag_get_i(f, off);
491  if (item) {
492  if (ok) {
493  *ok = true;
494  }
495  return item->name;
496  }
497  }
498  return NULL;
499 }

References f, rz_flag_item_t::name, NULL, off, ok, and rz_flag_get_i().

Referenced by rz_core_init().

◆ update_sdb()

static void update_sdb ( RzCore core)
static

Definition at line 1743 of file core.c.

1743  {
1744  Sdb *d;
1745  RzBinObject *o;
1746  if (!core) {
1747  return;
1748  }
1749  // SDB// analysis/
1750  if (core->analysis && core->analysis->sdb) {
1751  sdb_ns_set(DB, "analysis", core->analysis->sdb);
1752  }
1753  // SDB// bin/
1754  if (core->bin && core->bin->sdb) {
1755  sdb_ns_set(DB, "bin", core->bin->sdb);
1756  }
1757  // SDB// bin/info
1758  o = rz_bin_cur_object(core->bin);
1759  if (o) {
1760  sdb_ns_set(sdb_ns(DB, "bin", 1), "info", o->kv);
1761  }
1762  // sdb_ns_set (core->sdb, "flags", core->flags->sdb);
1763  // sdb_ns_set (core->sdb, "bin", core->bin->sdb);
1764  // SDB// syscall/
1765  if (core->rasm && core->rasm->syscall && core->rasm->syscall->db) {
1766  sdb_ns_set(DB, "syscall", core->rasm->syscall->db);
1767  }
1768  d = sdb_ns(DB, "debug", 1);
1769  if (core->dbg->sgnls) {
1770  sdb_ns_set(d, "signals", core->dbg->sgnls);
1771  }
1772 }
#define DB
Definition: core.c:14
RZ_API int sdb_ns_set(Sdb *s, const char *name, Sdb *r)
Definition: ns.c:156
RZ_API Sdb * sdb_ns(Sdb *s, const char *name, int create)
Definition: ns.c:186
#define d(i)
Definition: sha256.c:44
RZ_DEPRECATE RZ_BORROW Sdb * kv
deprecated, put info in C structures instead of this (holds a copy of another pointer....
Definition: rz_bin.h:291
RZ_DEPRECATE Sdb * sdb
Definition: rz_bin.h:340
Sdb * sgnls
Definition: rz_debug.h:313

References rz_core_t::analysis, rz_core_t::bin, d, DB, rz_syscall_t::db, rz_core_t::dbg, rz_bin_object_t::kv, rz_core_t::rasm, rz_bin_cur_object(), rz_analysis_t::sdb, rz_bin_t::sdb, sdb_ns(), sdb_ns_set(), rz_debug_t::sgnls, and rz_asm_t::syscall.

Referenced by rz_core_init().

Variable Documentation

◆ letter_divs

◆ rizin_argv

const char* rizin_argv[]
static

Definition at line 877 of file core.c.

Referenced by __init_autocomplete_default(), and autocomplete_default().

◆ rz_core_io_plugin_vfile

RZ_IPI RzIOPlugin rz_core_io_plugin_vfile
extern
Initial value:
= {
.name = "vfile",
.desc = "Virtual Files provided by RzBin Files",
.uris = URI_SCHEME,
.license = "LGPL",
.open = vf_open,
.close = vf_close,
.read = vf_read,
.check = vf_check,
.lseek = vf_lseek,
.write = vf_write,
.resize = vf_resize
}
static int vf_read(RzIO *io, RzIODesc *fd, ut8 *buf, int count)
Definition: cvfile.c:88
static int vf_write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count)
Definition: cvfile.c:79
static bool vf_resize(RzIO *io, RzIODesc *fd, ut64 size)
Definition: cvfile.c:121
static int vf_close(RzIODesc *fd)
Definition: cvfile.c:94
static bool vf_check(RzIO *io, const char *pathname, bool many)
Definition: cvfile.c:17
static ut64 vf_lseek(struct rz_io_t *io, RzIODesc *fd, ut64 offset, int whence)
Definition: cvfile.c:102
#define URI_SCHEME
Definition: cvfile.c:6
static RzIODesc * vf_open(RzIO *io, const char *pathname, int rw, int mode)
Definition: cvfile.c:36

IO Plugin that opens RzBinVirtualFiles supplied by the plugin of an RzBinFile.

URIs look like vfile://1/decompressed_data_0 where 1 is the id of a loaded RzBinFile and decompressed_data_0 is the name of the RzBinVirtualFile inside this RzBinFile that provides the data.

Definition at line 134 of file cvfile.c.

Referenced by rz_core_init(), rz_core_vfile_bin_file_deleted(), and vf_open().