Skip to content

Commit

Permalink
Add r_esil_new_simple
Browse files Browse the repository at this point in the history
  • Loading branch information
condret committed Nov 23, 2024
1 parent 0806ef8 commit a531574
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
51 changes: 51 additions & 0 deletions libr/esil/esil.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#define R_LOG_ORIGIN "esil"

#include <r_anal.h>
#include <r_io.h>
#include <r_reg.h>

#if __wasi__ || EMSCRIPTEN
#define FE_OVERFLOW 0
Expand Down Expand Up @@ -156,6 +158,55 @@ R_API REsil *r_esil_new_ex(int stacksize, bool iotrap, ut32 addrsize,
return NULL;
}

static bool default_is_reg (void *reg, const char *name) {
RRegItem *ri = r_reg_get ((RReg *)reg, name, -1);
if (!ri) {
return false;
}
r_unref (ri);
return true;
}

static bool default_reg_read (void *reg, const char *name, ut64 *res, int *size) {
RRegItem *ri = r_reg_get ((RReg *)reg, name, -1);
if (!ri) {
return false;
}
*num = r_reg_get_value ((RReg *)reg, ri);
*size = ri->size;
r_unref (ri);
return true;
}

static ut32 default_reg_size (void *reg, const char *name) {
RRegItem *ri = r_reg_get ((RReg *)reg, name, -1);
if (!ri) {
return 0;
}
r_unref (ri);
return ri->size;
}

static REsilRegInterface simple_reg_if = {
.is_reg = default_is_reg,
.reg_read = default_reg_read,
.reg_write = (REsilRegWrite)r_reg_setv,
.reg_size = default_reg_size
};

static REsilMemInterface simple_mem_if = {
.mem_switch = (REsilMemSwitch)r_io_bank_use,
.mem_read = (REsilMemRead)r_io_read_at,
.mem_write = (REsilMemWrite)r_io_write_at
};

R_API REsil *r_esil_new_simple(ut32 addrsize, struct r_reg_t *reg, struct r_io_t *io) {
R_RETURN_VAL_IF_FAIL (reg && io, NULL);
simple_reg_if.reg = reg;
simple_mem_if.mem = io;
return r_esil_new_ex (4096, false, addrsize, &simple_reg_if, &simple_mem_if);
}

R_API bool r_esil_set_op(REsil *esil, const char *op, REsilOpCb code, ut32 push, ut32 pop, ut32 type) {
R_RETURN_VAL_IF_FAIL (code && R_STR_ISNOTEMPTY (op) && esil && esil->ops, false);
REsilOp *eop = ht_pp_find (esil->ops, op, NULL);
Expand Down
2 changes: 2 additions & 0 deletions libr/include/r_esil.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ typedef struct r_esil_active_plugin_t {
R_API REsil *r_esil_new(int stacksize, int iotrap, unsigned int addrsize);
R_API REsil *r_esil_new_ex(int stacksize, bool iotrap, ut32 addrsize,
REsilRegInterface *reg_if, REsilMemInterface *mem_if);
//this should replace existing r_esil_new
R_API REsil *r_esil_new_simple(ut32 addrsize, struct r_reg_t *reg, struct r_io_t *io);
R_API void r_esil_reset(REsil *esil);
R_API void r_esil_set_pc(REsil *esil, ut64 addr);
R_API bool r_esil_setup(REsil *esil, struct r_anal_t *anal, bool romem, bool stats, bool nonull);
Expand Down

0 comments on commit a531574

Please sign in to comment.