Rizin
unix-like reverse engineering framework and cli tools
debug_io.c File Reference
#include <rz_io.h>
#include <rz_debug.h>

Go to the source code of this file.

Functions

static int __io_step (RzDebug *dbg)
 
static int __io_step_over (RzDebug *dbg)
 
static RzList__io_maps (RzDebug *dbg)
 
static RzDebugReasonType __io_wait (RzDebug *dbg, int pid)
 
static int __io_attach (RzDebug *dbg, int pid)
 
static char * __io_reg_profile (RzDebug *dbg)
 
static int __reg_read (RzDebug *dbg, int type, ut8 *buf, int size)
 
static int __io_continue (RzDebug *dbg, int pid, int tid, int sig)
 
static bool __io_kill (RzDebug *dbg, int pid, int tid, int sig)
 

Variables

RzDebugPlugin rz_debug_plugin_io
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ __io_attach()

static int __io_attach ( RzDebug dbg,
int  pid 
)
static

Definition at line 72 of file debug_io.c.

72  {
73  return true;
74 }

◆ __io_continue()

static int __io_continue ( RzDebug dbg,
int  pid,
int  tid,
int  sig 
)
static

Definition at line 127 of file debug_io.c.

127  {
128  dbg->iob.system(dbg->iob.io, "dc");
129  rz_cons_flush();
130  return true;
131 }
RZ_API void rz_cons_flush(void)
Definition: cons.c:959
RzDebug * dbg
Definition: desil.c:30
RzIOBind iob
Definition: rz_debug.h:293
RzIOSystem system
Definition: rz_io.h:242
RzIO * io
Definition: rz_io.h:232

References dbg, rz_io_bind_t::io, rz_debug_t::iob, rz_cons_flush(), and rz_io_bind_t::system.

◆ __io_kill()

static bool __io_kill ( RzDebug dbg,
int  pid,
int  tid,
int  sig 
)
static

Definition at line 134 of file debug_io.c.

134  {
135  const char *cmd = sdb_fmt("dk %d", sig);
136  dbg->iob.system(dbg->iob.io, cmd);
137  rz_cons_flush();
138  return true;
139 }
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
RZ_API char * sdb_fmt(const char *fmt,...)
Definition: fmt.c:26

References cmd, dbg, rz_io_bind_t::io, rz_debug_t::iob, rz_cons_flush(), sdb_fmt(), and rz_io_bind_t::system.

◆ __io_maps()

static RzList* __io_maps ( RzDebug dbg)
static

Definition at line 17 of file debug_io.c.

17  {
18  RzList *list = rz_list_new();
19  char *str = dbg->iob.system(dbg->iob.io, "dm");
20  if (!str) {
22  return NULL;
23  }
24  char *ostr = str;
25  ut64 map_start, map_end;
26  char perm[32];
27  char name[512];
28  for (;;) {
29  char *nl = strchr(str, '\n');
30  if (nl) {
31  *nl = 0;
32  *name = 0;
33  *perm = 0;
34  map_start = map_end = 0LL;
35  if (!strncmp(str, "sys ", 4)) {
36  char *sp = strchr(str + 4, ' ');
37  if (sp) {
38  str = sp + 1;
39  } else {
40  str += 4;
41  }
42  }
43  char *_s_ = strstr(str, " s ");
44  if (_s_) {
45  memmove(_s_, _s_ + 2, strlen(_s_));
46  }
47  _s_ = strstr(str, " ? ");
48  if (_s_) {
49  memmove(_s_, _s_ + 2, strlen(_s_));
50  }
51  sscanf(str, "0x%" PFMT64x " - 0x%" PFMT64x " %s %s",
52  &map_start, &map_end, perm, name);
53  if (map_end != 0LL) {
54  RzDebugMap *map = rz_debug_map_new(name, map_start, map_end, rz_str_rwx(perm), 0);
56  }
57  str = nl + 1;
58  } else {
59  break;
60  }
61  }
62  free(ostr);
63  rz_cons_reset();
64  return list;
65 }
RZ_API void rz_cons_reset(void)
Definition: cons.c:804
#define NULL
Definition: cris-opc.c:27
RZ_API RzDebugMap * rz_debug_map_new(char *name, ut64 addr, ut64 addr_end, int perm, int user)
Definition: dmap.c:7
size_t map(int syms, int left, int len)
Definition: enough.c:237
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
static void list(RzEgg *egg)
Definition: rz-gg.c:52
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
Definition: list.c:235
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
RZ_API int rz_str_rwx(const char *str)
Definition: str.c:318
#define PFMT64x
Definition: rz_types.h:393
Definition: z80asm.h:102
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int sp
Definition: z80asm.c:91

References dbg, free(), rz_io_bind_t::io, rz_debug_t::iob, list(), map(), NULL, PFMT64x, rz_cons_reset(), rz_debug_map_new(), rz_list_append(), rz_list_free(), rz_list_new(), rz_str_rwx(), sp, cmd_descs_generate::str, rz_io_bind_t::system, and ut64().

◆ __io_reg_profile()

static char* __io_reg_profile ( RzDebug dbg)
static

Definition at line 77 of file debug_io.c.

77  {
78  rz_cons_push();
79  char *drp = dbg->iob.system(dbg->iob.io, "drp");
80  if (drp) {
81  return drp;
82  }
83  char *buf = rz_cons_get_buffer_dup();
84  if (RZ_STR_ISNOTEMPTY(buf)) {
85  rz_cons_pop();
86  return buf;
87  }
88  free(buf);
89  rz_cons_pop();
91 }
RZ_API char * rz_analysis_get_reg_profile(RzAnalysis *analysis)
Definition: analysis.c:212
RZ_API RZ_OWN char * rz_cons_get_buffer_dup(void)
Return a newly allocated buffer containing what's currently in RzCons buffer.
Definition: cons.c:827
RZ_API void rz_cons_pop(void)
Definition: cons.c:876
RZ_API void rz_cons_push(void)
Definition: cons.c:860
voidpf void * buf
Definition: ioapi.h:138
#define RZ_STR_ISNOTEMPTY(x)
Definition: rz_str.h:68
RzAnalysis * analysis
Definition: rz_debug.h:305

References rz_debug_t::analysis, dbg, free(), rz_io_bind_t::io, rz_debug_t::iob, rz_analysis_get_reg_profile(), rz_cons_get_buffer_dup(), rz_cons_pop(), rz_cons_push(), RZ_STR_ISNOTEMPTY, and rz_io_bind_t::system.

◆ __io_step()

static int __io_step ( RzDebug dbg)
static

Definition at line 7 of file debug_io.c.

7  {
8  free(dbg->iob.system(dbg->iob.io, "ds"));
9  return true;
10 }

References dbg, free(), rz_io_bind_t::io, rz_debug_t::iob, and rz_io_bind_t::system.

◆ __io_step_over()

static int __io_step_over ( RzDebug dbg)
static

Definition at line 12 of file debug_io.c.

12  {
13  free(dbg->iob.system(dbg->iob.io, "dso"));
14  return true;
15 }

References dbg, free(), rz_io_bind_t::io, rz_debug_t::iob, and rz_io_bind_t::system.

◆ __io_wait()

static RzDebugReasonType __io_wait ( RzDebug dbg,
int  pid 
)
static

Definition at line 67 of file debug_io.c.

67  {
68  /* do nothing */
69  return RZ_DEBUG_REASON_NONE;
70 }
@ RZ_DEBUG_REASON_NONE
Definition: rz_debug.h:91

References RZ_DEBUG_REASON_NONE.

◆ __reg_read()

static int __reg_read ( RzDebug dbg,
int  type,
ut8 buf,
int  size 
)
static

Definition at line 94 of file debug_io.c.

94  {
95  char *dr8 = dbg->iob.system(dbg->iob.io, "dr8");
96  if (!dr8) {
97  char *fb = rz_cons_get_buffer_dup();
98  if (RZ_STR_ISEMPTY(fb)) {
99  free(fb);
100  eprintf("debug.io: Failed to get dr8 from io\n");
101  return -1;
102  }
103  dr8 = fb;
104  rz_cons_reset();
105  }
106  ut8 *bregs = calloc(1, strlen(dr8));
107  if (!bregs) {
108  free(dr8);
109  return -1;
110  }
111  rz_str_trim((char *)bregs);
112  int sz = rz_hex_str2bin(dr8, bregs);
113  if (sz > 0) {
114  memcpy(buf, bregs, RZ_MIN(size, sz));
115  free(bregs);
116  free(dr8);
117  return size;
118  } else {
119  // eprintf ("SIZE %d (%s)\n", sz, regs);
120  }
121  free(bregs);
122  free(dr8);
123  return -1;
124 }
voidpf void uLong size
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
#define eprintf(x, y...)
Definition: rlcc.c:7
RZ_API int rz_hex_str2bin(const char *in, ut8 *out)
Convert an input string in into the binary form in out.
Definition: hex.c:444
#define RZ_STR_ISEMPTY(x)
Definition: rz_str.h:67
RZ_API void rz_str_trim(RZ_NONNULL RZ_INOUT char *str)
Removes whitespace characters (space, tab, newline etc.) from the beginning and end of a string.
Definition: str_trim.c:190
#define RZ_MIN(x, y)

References calloc(), dbg, eprintf, free(), rz_io_bind_t::io, rz_debug_t::iob, memcpy(), rz_cons_get_buffer_dup(), rz_cons_reset(), rz_hex_str2bin(), RZ_MIN, RZ_STR_ISEMPTY, rz_str_trim(), and rz_io_bind_t::system.

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_DBG,
}
RzDebugPlugin rz_debug_plugin_io
Definition: debug_io.c:141
@ RZ_LIB_TYPE_DBG
Definition: rz_lib.h:70
#define RZ_VERSION
Definition: rz_version.h:8
const char * version
Definition: rz_debug.h:362

Definition at line 166 of file debug_io.c.

◆ rz_debug_plugin_io

RzDebugPlugin rz_debug_plugin_io
Initial value:
= {
.name = "io",
.license = "MIT",
.arch = "any",
.step = __io_step,
.map_get = __io_maps,
.attach = &__io_attach,
.wait = &__io_wait,
.reg_read = __reg_read,
.cont = __io_continue,
.kill = __io_kill,
.reg_profile = __io_reg_profile,
.step_over = __io_step_over,
.canstep = 1,
}
static char * __io_reg_profile(RzDebug *dbg)
Definition: debug_io.c:77
static bool __io_kill(RzDebug *dbg, int pid, int tid, int sig)
Definition: debug_io.c:134
static RzDebugReasonType __io_wait(RzDebug *dbg, int pid)
Definition: debug_io.c:67
static RzList * __io_maps(RzDebug *dbg)
Definition: debug_io.c:17
static int __reg_read(RzDebug *dbg, int type, ut8 *buf, int size)
Definition: debug_io.c:94
static int __io_continue(RzDebug *dbg, int pid, int tid, int sig)
Definition: debug_io.c:127
static int __io_attach(RzDebug *dbg, int pid)
Definition: debug_io.c:72
static int __io_step_over(RzDebug *dbg)
Definition: debug_io.c:12
static int __io_step(RzDebug *dbg)
Definition: debug_io.c:7
@ RZ_SYS_BITS_32
Definition: rz_sys.h:20
@ RZ_SYS_BITS_64
Definition: rz_sys.h:21

Definition at line 141 of file debug_io.c.