Rizin
unix-like reverse engineering framework and cli tools
debug_esil.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2013-2017 pancake <pancake@nopcode.org>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 // r2 -Desil ls
4 
5 #include <rz_debug.h>
6 
7 #if 0
8 static int is_io_esil(RzDebug *dbg) {
9  RzIODesc *d = dbg->iob.io->desc;
10  if (d && d->plugin && d->plugin->name)
11  if (!strcmp ("esil", d->plugin->name))
12  return true;
13  return false;
14 }
15 #endif
16 
18  eprintf("TODO: ESIL STEP OVER\n");
19  return true;
20 }
21 
22 static int __esil_step(RzDebug *dbg) {
23  int oplen;
24  ut8 buf[64];
25  ut64 pc = 0LL; // getreg("pc")
26  RzAnalysisOp op = { 0 };
27 
29  pc = rz_debug_reg_get(dbg, "PC");
30  eprintf("PC = 0x%" PFMT64x "\n", pc);
32  // pc = 0x100001478;
33  // memset (buf, 0, sizeof (buf));
34  dbg->iob.read_at(dbg->iob.io, pc, buf, 64);
35  eprintf("READ 0x%08" PFMT64x " %02x %02x %02x\n", pc, buf[0], buf[1], buf[2]);
37  if (oplen > 0) {
38  if (*RZ_STRBUF_SAFEGET(&op.esil)) {
39  eprintf("ESIL: %s\n", RZ_STRBUF_SAFEGET(&op.esil));
41  }
42  }
44  eprintf("TODO: ESIL STEP\n");
45  return true;
46 }
47 
48 static bool __esil_init(RzDebug *dbg, void **user) {
49  dbg->tid = dbg->pid = 1;
50  // aeim
51  // aei
52  return true;
53 }
54 
55 static int __esil_continue(RzDebug *dbg, int pid, int tid, int sig) {
56  eprintf("TODO continue\n");
57  return true;
58 }
59 
60 static int __esil_continue_syscall(RzDebug *dbg, int pid, int num) {
61  eprintf("TODO: esil continue until syscall\n");
62  return true;
63 }
64 
66  /* do nothing */
67  return RZ_DEBUG_REASON_NONE;
68 }
69 
70 static int __esil_attach(RzDebug *dbg, int pid) {
71  eprintf("OK attach\n");
72  return true;
73 #if 0
74  if (!is_io_esil (dbg))
75  return false;
76 #endif
77 #if 0
78  RzIOBdescbg *o;
79  o = dbg->iob.io->desc->data;
80 eprintf ("base = %llx\n", o->bfvm->base);
81 eprintf ("screen = %llx\n", o->bfvm->screen);
82 eprintf ("input = %llx\n", o->bfvm->input);
83 #endif
84  return true;
85 }
86 
87 static int __esil_detach(RzDebug *dbg, int pid) {
88  // reset vm?
89  return true;
90 }
91 
92 static char *__esil_reg_profile(RzDebug *dbg) {
93  if (!strcmp(dbg->arch, "bf")) {
94  return strdup(
95  "=PC pc\n"
96  "=SP esp\n"
97  "=BP ptr\n"
98  "=A0 rax\n"
99  "gpr rax .32 0 0\n"
100  "gpr pc .32 0 0\n"
101  "gpr ptr .32 4 0\n"
102  "gpr esp .32 8 0\n"
103  "gpr scr .32 12 0\n"
104  "gpr scri .32 16 0\n"
105  "gpr inp .32 20 0\n"
106  "gpr inpi .32 24 0\n"
107  "gpr mem .32 28 0\n"
108  "gpr memi .32 32 0\n");
109  }
111 }
112 
113 static int __esil_breakpoint(RzBreakpoint *bp, RzBreakpointItem *b, bool set) {
114  // rz_io_system (dbg->iob.io, "db");
115  return false;
116 }
117 
118 static bool __esil_kill(RzDebug *dbg, int pid, int tid, int sig) {
119  // TODO: ESIL reset
120  return true;
121 }
122 
123 static int __esil_stop(RzDebug *dbg) {
124  eprintf("ESIL: stop\n");
125  return true;
126 }
127 
128 static int __reg_read(RzDebug *dbg, int type, ut8 *buf, int size) {
129  int sz;
130  /* do nothing */
132  memcpy(buf, bytes, RZ_MIN(size, sz));
133  free(bytes);
134  return size;
135 }
136 
138  .name = "esil",
139  .license = "LGPL3",
140  .arch = "any", // TODO: exception!
141  .bits = RZ_SYS_BITS_32 | RZ_SYS_BITS_64,
142  .init = __esil_init,
143  .step = __esil_step,
144  .step_over = __esil_step_over,
145  .cont = __esil_continue,
146  .contsc = __esil_continue_syscall,
147  .attach = &__esil_attach,
148  .detach = &__esil_detach,
149  .wait = &__esil_wait,
150  .stop = __esil_stop,
151  .kill = __esil_kill,
152  .breakpoint = __esil_breakpoint,
153  .reg_profile = __esil_reg_profile,
154  .reg_read = __reg_read,
155 };
156 
157 #ifndef RZ_PLUGIN_INCORE
160  .data = &rz_debug_plugin_esil,
162 };
163 #endif
RZ_API char * rz_analysis_get_reg_profile(RzAnalysis *analysis)
Definition: analysis.c:212
RZ_API ut8 * rz_reg_get_bytes(RzReg *reg, int type, int *size)
Definition: arena.c:8
static ut8 bytes[32]
Definition: asm_arc.c:23
#define RZ_API
static bool __esil_init(RzDebug *dbg, void **user)
Definition: debug_esil.c:48
static int __esil_step_over(RzDebug *dbg)
Definition: debug_esil.c:17
static int __esil_breakpoint(RzBreakpoint *bp, RzBreakpointItem *b, bool set)
Definition: debug_esil.c:113
static RzDebugReasonType __esil_wait(RzDebug *dbg, int pid)
Definition: debug_esil.c:65
static int __reg_read(RzDebug *dbg, int type, ut8 *buf, int size)
Definition: debug_esil.c:128
static int __esil_detach(RzDebug *dbg, int pid)
Definition: debug_esil.c:87
RZ_API RzLibStruct rizin_plugin
Definition: debug_esil.c:158
static char * __esil_reg_profile(RzDebug *dbg)
Definition: debug_esil.c:92
static int __esil_continue(RzDebug *dbg, int pid, int tid, int sig)
Definition: debug_esil.c:55
RzDebugPlugin rz_debug_plugin_esil
Definition: debug_esil.c:137
static int __esil_step(RzDebug *dbg)
Definition: debug_esil.c:22
static int __esil_attach(RzDebug *dbg, int pid)
Definition: debug_esil.c:70
static bool __esil_kill(RzDebug *dbg, int pid, int tid, int sig)
Definition: debug_esil.c:118
static int __esil_continue_syscall(RzDebug *dbg, int pid, int num)
Definition: debug_esil.c:60
static int __esil_stop(RzDebug *dbg)
Definition: debug_esil.c:123
RzDebug * dbg
Definition: desil.c:30
RZ_API ut64 rz_debug_reg_get(RzDebug *dbg, const char *name)
Definition: dreg.c:99
RZ_API int rz_debug_reg_sync(RzDebug *dbg, int type, int write)
Definition: dreg.c:9
RZ_API bool rz_analysis_esil_parse(RzAnalysisEsil *esil, const char *str)
Definition: esil.c:2998
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void uLong size
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
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
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 pid
Definition: sflib.h:64
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")
int type
Definition: mipsasm.c:17
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
#define eprintf(x, y...)
Definition: rlcc.c:7
@ RZ_ANALYSIS_OP_MASK_ESIL
Definition: rz_analysis.h:441
RzDebugReasonType
Definition: rz_debug.h:89
@ RZ_DEBUG_REASON_NONE
Definition: rz_debug.h:91
@ RZ_LIB_TYPE_DBG
Definition: rz_lib.h:70
@ RZ_REG_TYPE_GPR
Definition: rz_reg.h:21
#define RZ_STRBUF_SAFEGET(sb)
Definition: rz_strbuf.h:18
@ RZ_SYS_BITS_32
Definition: rz_sys.h:20
@ RZ_SYS_BITS_64
Definition: rz_sys.h:21
#define PFMT64x
Definition: rz_types.h:393
#define RZ_MIN(x, y)
#define RZ_VERSION
Definition: rz_version.h:8
#define d(i)
Definition: sha256.c:44
#define b(i)
Definition: sha256.c:42
BfvmCPU * bfvm
Definition: debug_bf.c:13
ut64 base
Definition: bfvm.h:25
ut64 input
Definition: bfvm.h:32
ut64 screen
Definition: bfvm.h:28
struct rz_analysis_esil_t * esil
Definition: rz_analysis.h:584
Definition: rz_bp.h:78
const char * version
Definition: rz_debug.h:362
const char * name
Definition: rz_debug.h:359
RzAnalysis * analysis
Definition: rz_debug.h:305
char * arch
Definition: rz_debug.h:242
RzIOBind iob
Definition: rz_debug.h:293
RzIOReadAt read_at
Definition: rz_io.h:240
RzIO * io
Definition: rz_io.h:232
void * data
Definition: rz_io.h:102
struct rz_io_desc_t * desc
Definition: rz_io.h:60
Definition: dis.c:32
ut64(WINAPI *w32_GetEnabledXStateFeatures)()