mirror of
https://github.com/radareorg/radare2.git
synced 2024-10-07 02:23:58 +00:00
Boolify all the ESIL callbacks ##esil
This commit is contained in:
parent
ec40935090
commit
2bed411446
@ -212,7 +212,7 @@ static bool alignCheck(RAnalEsil *esil, ut64 addr) {
|
||||
return !(dataAlign > 0 && addr % dataAlign);
|
||||
}
|
||||
|
||||
static int internal_esil_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
|
||||
static bool internal_esil_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
|
||||
r_return_val_if_fail (esil && esil->anal && esil->anal->iob.io, 0);
|
||||
|
||||
addr &= esil->addrmask;
|
||||
@ -244,7 +244,7 @@ static int internal_esil_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len)
|
||||
return len;
|
||||
}
|
||||
|
||||
static int internal_esil_mem_read_no_null(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
|
||||
static bool internal_esil_mem_read_no_null(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
|
||||
r_return_val_if_fail (esil && esil->anal && esil->anal->iob.io, 0);
|
||||
|
||||
addr &= esil->addrmask;
|
||||
@ -266,9 +266,9 @@ static int internal_esil_mem_read_no_null(RAnalEsil *esil, ut64 addr, ut8 *buf,
|
||||
return len;
|
||||
}
|
||||
|
||||
R_API int r_anal_esil_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
|
||||
int i, ret = 0;
|
||||
R_API bool r_anal_esil_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
|
||||
r_return_val_if_fail (buf && esil, 0);
|
||||
bool ret = false;
|
||||
addr &= esil->addrmask;
|
||||
if (esil->cb.hook_mem_read) {
|
||||
ret = esil->cb.hook_mem_read (esil, addr, buf, len);
|
||||
@ -288,6 +288,7 @@ R_API int r_anal_esil_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
|
||||
}
|
||||
}
|
||||
IFDBG {
|
||||
size_t i;
|
||||
eprintf ("0x%08" PFMT64x " R> ", addr);
|
||||
for (i = 0; i < len; i++) {
|
||||
eprintf ("%02x", buf[i]);
|
||||
@ -297,7 +298,7 @@ R_API int r_anal_esil_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int internal_esil_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
|
||||
static bool internal_esil_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
|
||||
int ret = 0;
|
||||
if (!esil || !esil->anal || !esil->anal->iob.io || esil->nowrite) {
|
||||
return 0;
|
||||
@ -332,13 +333,13 @@ static int internal_esil_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, i
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int internal_esil_mem_write_no_null(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
|
||||
int ret = 0;
|
||||
static bool internal_esil_mem_write_no_null(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
|
||||
bool ret = false;
|
||||
if (!esil || !esil->anal || !esil->anal->iob.io || !addr) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
if (esil->nowrite) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
addr &= esil->addrmask;
|
||||
if (esil->anal->iob.write_at (esil->anal->iob.io, addr, buf, len)) {
|
||||
@ -355,11 +356,9 @@ static int internal_esil_mem_write_no_null(RAnalEsil *esil, ut64 addr, const ut8
|
||||
return ret;
|
||||
}
|
||||
|
||||
R_API int r_anal_esil_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
|
||||
R_API bool r_anal_esil_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
|
||||
r_return_val_if_fail (esil && buf, false);
|
||||
int i, ret = 0;
|
||||
if (!buf || !esil) {
|
||||
return 0;
|
||||
}
|
||||
addr &= esil->addrmask;
|
||||
IFDBG {
|
||||
eprintf ("0x%08" PFMT64x " <W ", addr);
|
||||
@ -377,7 +376,7 @@ R_API int r_anal_esil_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int internal_esil_reg_read(RAnalEsil *esil, const char *regname, ut64 *num, int *size) {
|
||||
static bool internal_esil_reg_read(RAnalEsil *esil, const char *regname, ut64 *num, int *size) {
|
||||
RRegItem *reg = r_reg_get (esil->anal->reg, regname, -1);
|
||||
if (reg) {
|
||||
if (size) {
|
||||
@ -391,7 +390,7 @@ static int internal_esil_reg_read(RAnalEsil *esil, const char *regname, ut64 *nu
|
||||
return false;
|
||||
}
|
||||
|
||||
static int internal_esil_reg_write(RAnalEsil *esil, const char *regname, ut64 num) {
|
||||
static bool internal_esil_reg_write(RAnalEsil *esil, const char *regname, ut64 num) {
|
||||
if (esil && esil->anal) {
|
||||
RRegItem *reg = r_reg_get (esil->anal->reg, regname, -1);
|
||||
if (reg) {
|
||||
@ -406,7 +405,7 @@ static int internal_esil_reg_write(RAnalEsil *esil, const char *regname, ut64 nu
|
||||
//Are you really trying to prevent the analyzed binary from doing anything that would cause it to segfault irl?
|
||||
//WHY?
|
||||
// - condret
|
||||
static int internal_esil_reg_write_no_null (RAnalEsil *esil, const char *regname, ut64 num) {
|
||||
static bool internal_esil_reg_write_no_null (RAnalEsil *esil, const char *regname, ut64 num) {
|
||||
r_return_val_if_fail (esil && esil->anal && esil->anal->reg, false);
|
||||
|
||||
RRegItem *reg = r_reg_get (esil->anal->reg, regname, -1);
|
||||
@ -2156,7 +2155,6 @@ static bool esil_peek_some(RAnalEsil *esil) {
|
||||
if (count) {
|
||||
isregornum (esil, count, ®s);
|
||||
if (regs > 0) {
|
||||
ut32 num32;
|
||||
ut8 a[4];
|
||||
for (i = 0; i < regs; i++) {
|
||||
char *foo = r_anal_esil_pop (esil);
|
||||
@ -2164,17 +2162,19 @@ static bool esil_peek_some(RAnalEsil *esil) {
|
||||
ERR ("Cannot pop in peek");
|
||||
free (dst);
|
||||
free (count);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
const ut32 read = r_anal_esil_mem_read (esil, ptr, a, 4);
|
||||
if (read == 4) { //this is highly questionabla
|
||||
num32 = r_read_ble32 (a, esil->anal->big_endian);
|
||||
r_anal_esil_reg_write (esil, foo, num32);
|
||||
} else {
|
||||
bool oks = r_anal_esil_mem_read (esil, ptr, a, 4);
|
||||
if (!oks) {
|
||||
if (esil->verbose) {
|
||||
eprintf ("Cannot peek from 0x%08" PFMT64x "\n", ptr);
|
||||
}
|
||||
free (dst);
|
||||
free (count);
|
||||
return false;
|
||||
}
|
||||
ut32 num32 = r_read_ble32 (a, esil->anal->big_endian);
|
||||
r_anal_esil_reg_write (esil, foo, num32);
|
||||
ptr += 4;
|
||||
free (foo);
|
||||
}
|
||||
|
@ -1,41 +1,41 @@
|
||||
/* radare - LGPL - Copyright 2014 - pancake */
|
||||
/* radare - LGPL - Copyright 2014-2021 - pancake */
|
||||
|
||||
#include <r_anal.h>
|
||||
|
||||
static int hook_flag_read(RAnalEsil *esil, const char *flag, ut64 *num) {
|
||||
static bool hook_flag_read(RAnalEsil *esil, const char *flag, ut64 *num) {
|
||||
sdb_array_add (esil->stats, "flg.read", flag, 0);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
static int hook_command(RAnalEsil *esil, const char *op) {
|
||||
static bool hook_command(RAnalEsil *esil, const char *op) {
|
||||
sdb_array_add (esil->stats, "ops.list", op, 0);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
static int hook_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
|
||||
static bool hook_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
|
||||
sdb_array_add_num (esil->stats, "mem.read", addr, 0);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
static int hook_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
|
||||
static bool hook_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
|
||||
sdb_array_add_num (esil->stats, "mem.write", addr, 0);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
static int hook_reg_read(RAnalEsil *esil, const char *name, ut64 *res, int *size) {
|
||||
static bool hook_reg_read(RAnalEsil *esil, const char *name, ut64 *res, int *size) {
|
||||
const char *key = (*name>='0' && *name<='9')? "num.load": "reg.read";
|
||||
sdb_array_add (esil->stats, key, name, 0);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
static int hook_reg_write(RAnalEsil *esil, const char *name, ut64 *val) {
|
||||
static bool hook_reg_write(RAnalEsil *esil, const char *name, ut64 *val) {
|
||||
sdb_array_add (esil->stats, "reg.write", name, 0);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
static int hook_NOP_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
|
||||
static bool hook_NOP_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
|
||||
eprintf ("NOP WRITE AT 0x%08"PFMT64x"\n", addr);
|
||||
return 1; // override
|
||||
return true;
|
||||
}
|
||||
|
||||
R_API void r_anal_esil_mem_ro(RAnalEsil *esil, int mem_readonly) {
|
||||
|
@ -106,12 +106,12 @@ static void add_mem_change(RAnalEsilTrace *trace, int idx, ut64 addr, ut8 data)
|
||||
r_vector_push (vmem, &mem);
|
||||
}
|
||||
|
||||
static int trace_hook_reg_read(RAnalEsil *esil, const char *name, ut64 *res, int *size) {
|
||||
static bool trace_hook_reg_read(RAnalEsil *esil, const char *name, ut64 *res, int *size) {
|
||||
r_return_val_if_fail (esil && name && res, -1);
|
||||
int ret = 0;
|
||||
bool ret = false;
|
||||
if (*name == '0') {
|
||||
//eprintf ("Register not found in profile\n");
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
if (ocbs.hook_reg_read) {
|
||||
RAnalEsilCallbacks cbs = esil->cb;
|
||||
@ -131,27 +131,25 @@ static int trace_hook_reg_read(RAnalEsil *esil, const char *name, ut64 *res, int
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int trace_hook_reg_write(RAnalEsil *esil, const char *name, ut64 *val) {
|
||||
int ret = 0;
|
||||
static bool trace_hook_reg_write(RAnalEsil *esil, const char *name, ut64 *val) {
|
||||
bool ret = false;
|
||||
//eprintf ("[ESIL] REG WRITE %s 0x%08"PFMT64x"\n", name, *val);
|
||||
RRegItem *ri = r_reg_get (esil->anal->reg, name, -1);
|
||||
if (!ri) {
|
||||
eprintf ("Unknown register name %s\n", name);
|
||||
return -1;
|
||||
}
|
||||
sdb_array_add (DB, KEY ("reg.write"), name, 0);
|
||||
sdb_num_set (DB, KEYREG ("reg.write", name), *val, 0);
|
||||
add_reg_change (esil->trace, esil->trace->idx + 1, ri, *val);
|
||||
if (ocbs.hook_reg_write) {
|
||||
RAnalEsilCallbacks cbs = esil->cb;
|
||||
esil->cb = ocbs;
|
||||
ret = ocbs.hook_reg_write (esil, name, val);
|
||||
esil->cb = cbs;
|
||||
if (ri) {
|
||||
sdb_array_add (DB, KEY ("reg.write"), name, 0);
|
||||
sdb_num_set (DB, KEYREG ("reg.write", name), *val, 0);
|
||||
add_reg_change (esil->trace, esil->trace->idx + 1, ri, *val);
|
||||
if (ocbs.hook_reg_write) {
|
||||
RAnalEsilCallbacks cbs = esil->cb;
|
||||
esil->cb = ocbs;
|
||||
ret = ocbs.hook_reg_write (esil, name, val);
|
||||
esil->cb = cbs;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int trace_hook_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
|
||||
static bool trace_hook_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
|
||||
char *hexbuf = calloc ((1 + len), 4);
|
||||
int ret = 0;
|
||||
if (esil->cb.mem_read) {
|
||||
@ -172,7 +170,7 @@ static int trace_hook_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int trace_hook_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
|
||||
static bool trace_hook_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
|
||||
size_t i;
|
||||
int ret = 0;
|
||||
char *hexbuf = malloc ((1 + len) * 3);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2011-2019 - pancake, Roc Valles, condret, killabyte */
|
||||
/* radare - LGPL - Copyright 2011-2021 - pancake, Roc Valles, condret, killabyte */
|
||||
|
||||
#if 0
|
||||
http://www.atmel.com/images/atmel-0856-avr-instruction-set-manual.pdf
|
||||
@ -50,11 +50,11 @@ typedef struct _opcodes_tag_ {
|
||||
|
||||
static OPCODE_DESC* avr_op_analyze(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, CPU_MODEL *cpu);
|
||||
|
||||
#define CPU_MODEL_DECL(model, pc, consts) \
|
||||
{ \
|
||||
model, \
|
||||
pc, \
|
||||
consts \
|
||||
#define CPU_MODEL_DECL(model, pc, consts)\
|
||||
{ \
|
||||
model, \
|
||||
pc, \
|
||||
consts \
|
||||
}
|
||||
#define MASK(bits) ((bits) == 32 ? 0xffffffff : (~((~((ut32) 0)) << (bits))))
|
||||
#define CPU_PC_MASK(cpu) MASK((cpu)->pc)
|
||||
@ -153,9 +153,10 @@ CPU_MODEL cpu_models[] = {
|
||||
},
|
||||
};
|
||||
|
||||
static CPU_MODEL *get_cpu_model(char *model);
|
||||
/// XXX this code is awful
|
||||
static CPU_MODEL *get_cpu_model(const char *model);
|
||||
|
||||
static CPU_MODEL *__get_cpu_model_recursive(char *model) {
|
||||
static CPU_MODEL *__get_cpu_model_recursive(const char *model) {
|
||||
CPU_MODEL *cpu = NULL;
|
||||
|
||||
for (cpu = cpu_models; cpu < cpu_models + ((sizeof (cpu_models) / sizeof (CPU_MODEL))) - 1; cpu++) {
|
||||
@ -175,22 +176,19 @@ static CPU_MODEL *__get_cpu_model_recursive(char *model) {
|
||||
return cpu;
|
||||
}
|
||||
|
||||
static CPU_MODEL *get_cpu_model(char *model) {
|
||||
static CPU_MODEL *get_cpu_model(const char *model) {
|
||||
static CPU_MODEL *cpu = NULL;
|
||||
// cached value?
|
||||
// cache
|
||||
if (cpu && !r_str_casecmp (model, cpu->model)) {
|
||||
return cpu;
|
||||
}
|
||||
// do the real search
|
||||
cpu = __get_cpu_model_recursive (model);
|
||||
return cpu;
|
||||
return cpu = __get_cpu_model_recursive (model);
|
||||
}
|
||||
|
||||
static ut32 const_get_value(CPU_CONST *c) {
|
||||
return c ? MASK (c->size * 8) & c->value : 0;
|
||||
}
|
||||
|
||||
|
||||
static CPU_CONST *const_by_name(CPU_MODEL *cpu, int type, char *c) {
|
||||
CPU_CONST **clist, *citem;
|
||||
|
||||
@ -221,7 +219,9 @@ static int __esil_pop_argument(RAnalEsil *esil, ut64 *v) {
|
||||
|
||||
static CPU_CONST *const_by_value(CPU_MODEL *cpu, int type, ut32 v) {
|
||||
CPU_CONST **clist, *citem;
|
||||
|
||||
if (!cpu) {
|
||||
return NULL;
|
||||
}
|
||||
for (clist = cpu->consts; *clist; clist++) {
|
||||
for (citem = *clist; citem && citem->key; citem++) {
|
||||
if (citem->value == (MASK (citem->size * 8) & v)
|
||||
@ -1778,9 +1778,7 @@ static bool avr_custom_des (RAnalEsil *esil) {
|
||||
|
||||
// ESIL operation SPM_PAGE_ERASE
|
||||
static bool avr_custom_spm_page_erase(RAnalEsil *esil) {
|
||||
CPU_MODEL *cpu;
|
||||
ut8 c;
|
||||
ut64 addr, page_size_bits, i;
|
||||
ut64 addr, i;
|
||||
|
||||
// sanity check
|
||||
if (!esil || !esil->anal || !esil->anal->reg) {
|
||||
@ -1793,15 +1791,15 @@ static bool avr_custom_spm_page_erase(RAnalEsil *esil) {
|
||||
}
|
||||
|
||||
// get details about current MCU and fix input address
|
||||
cpu = get_cpu_model (esil->anal->cpu);
|
||||
page_size_bits = const_get_value (const_by_name (cpu, CPU_CONST_PARAM, "page_size"));
|
||||
CPU_MODEL *cpu = get_cpu_model (esil->anal->cpu);
|
||||
ut64 page_size_bits = const_get_value (const_by_name (cpu, CPU_CONST_PARAM, "page_size"));
|
||||
|
||||
// align base address to page_size_bits
|
||||
addr &= ~(MASK (page_size_bits));
|
||||
|
||||
// perform erase
|
||||
//eprintf ("SPM_PAGE_ERASE %ld bytes @ 0x%08" PFMT64x ".\n", page_size, addr);
|
||||
c = 0xff;
|
||||
ut8 c = 0xff;
|
||||
for (i = 0; i < (1ULL << page_size_bits); i++) {
|
||||
r_anal_esil_mem_write (
|
||||
esil, (addr + i) & CPU_PC_MASK (cpu), &c, 1);
|
||||
@ -1888,11 +1886,11 @@ static bool avr_custom_spm_page_write(RAnalEsil *esil) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static int esil_avr_hook_reg_write(RAnalEsil *esil, const char *name, ut64 *val) {
|
||||
static bool esil_avr_hook_reg_write(RAnalEsil *esil, const char *name, ut64 *val) {
|
||||
CPU_MODEL *cpu;
|
||||
|
||||
if (!esil || !esil->anal) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
// select cpu info
|
||||
@ -1910,8 +1908,7 @@ static int esil_avr_hook_reg_write(RAnalEsil *esil, const char *name, ut64 *val)
|
||||
? *val & MASK (cpu->pc - 8)
|
||||
: 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
static int esil_avr_init(RAnalEsil *esil) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2009-2020 - pancake, nibble */
|
||||
/* radare - LGPL - Copyright 2009-2021 - pancake, nibble */
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_list.h>
|
||||
@ -4736,9 +4736,9 @@ static void handle_var_stack_access(RAnalEsil *esil, ut64 addr, RAnalVarAccessTy
|
||||
}
|
||||
}
|
||||
|
||||
static int esilbreak_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
|
||||
static bool esilbreak_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
|
||||
handle_var_stack_access (esil, addr, R_ANAL_VAR_ACCESS_TYPE_WRITE, len);
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* TODO: move into RCore? */
|
||||
@ -4748,7 +4748,7 @@ static ut64 esilbreak_last_data = UT64_MAX;
|
||||
static ut64 ntarget = UT64_MAX;
|
||||
|
||||
// TODO differentiate endian-aware mem_read with other reads; move ntarget handling to another function
|
||||
static int esilbreak_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
|
||||
static bool esilbreak_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
|
||||
ut8 str[128];
|
||||
if (addr != UT64_MAX) {
|
||||
esilbreak_last_read = addr;
|
||||
@ -4796,12 +4796,12 @@ static int esilbreak_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
|
||||
r_anal_xrefs_set (mycore->anal, esil->address, addr, R_ANAL_REF_TYPE_DATA);
|
||||
}
|
||||
}
|
||||
return 0; // fallback
|
||||
return false; // fallback
|
||||
}
|
||||
|
||||
static int esilbreak_reg_write(RAnalEsil *esil, const char *name, ut64 *val) {
|
||||
static bool esilbreak_reg_write(RAnalEsil *esil, const char *name, ut64 *val) {
|
||||
if (!esil) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
RAnal *anal = esil->anal;
|
||||
EsilBreakCtx *ctx = esil->user;
|
||||
|
@ -1716,16 +1716,16 @@ R_API char *cmd_syscall_dostr(RCore *core, st64 n, ut64 addr) {
|
||||
return r_str_appendf (res, ")");
|
||||
}
|
||||
|
||||
static int mw(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
|
||||
static bool mw(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
|
||||
int *ec = (int*)esil->user;
|
||||
*ec += (len * 2);
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int mr(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
|
||||
static bool mr(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
|
||||
int *ec = (int*)esil->user;
|
||||
*ec += len;
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int esil_cost(RCore *core, ut64 addr, const char *expr) {
|
||||
@ -5492,12 +5492,12 @@ typedef struct {
|
||||
int size;
|
||||
} AeaMemItem;
|
||||
|
||||
static int mymemwrite(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
|
||||
RListIter *iter;
|
||||
static bool mymemwrite(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
|
||||
AeaMemItem *n;
|
||||
RListIter *iter;
|
||||
r_list_foreach (mymemxsw, iter, n) {
|
||||
if (addr == n->addr) {
|
||||
return len;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (!r_io_is_valid_offset (esil->anal->iob.io, addr, 0)) {
|
||||
@ -5509,15 +5509,15 @@ static int mymemwrite(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
|
||||
n->size = len;
|
||||
r_list_push (mymemxsw, n);
|
||||
}
|
||||
return len;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int mymemread(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
|
||||
static bool mymemread(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
|
||||
RListIter *iter;
|
||||
AeaMemItem *n;
|
||||
r_list_foreach (mymemxsr, iter, n) {
|
||||
if (addr == n->addr) {
|
||||
return len;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (!r_io_is_valid_offset (esil->anal->iob.io, addr, 0)) {
|
||||
@ -5529,10 +5529,10 @@ static int mymemread(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
|
||||
n->size = len;
|
||||
r_list_push (mymemxsr, n);
|
||||
}
|
||||
return len;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int myregwrite(RAnalEsil *esil, const char *name, ut64 *val) {
|
||||
static bool myregwrite(RAnalEsil *esil, const char *name, ut64 *val) {
|
||||
AeaStats *stats = esil->user;
|
||||
if (oldregread && !strcmp (name, oldregread)) {
|
||||
r_list_pop (stats->regread);
|
||||
@ -5551,10 +5551,10 @@ static int myregwrite(RAnalEsil *esil, const char *name, ut64 *val) {
|
||||
}
|
||||
free (v);
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
static int myregread(RAnalEsil *esil, const char *name, ut64 *val, int *len) {
|
||||
static bool myregread(RAnalEsil *esil, const char *name, ut64 *val, int *len) {
|
||||
AeaStats *stats = esil->user;
|
||||
if (!IS_DIGIT (*name)) {
|
||||
if (!contains (stats->inputregs, name)) {
|
||||
@ -5569,10 +5569,10 @@ static int myregread(RAnalEsil *esil, const char *name, ut64 *val, int *len) {
|
||||
r_list_push (stats->regread, strdup (name));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
static void showregs (RList *list) {
|
||||
static void showregs(RList *list) {
|
||||
if (!r_list_empty (list)) {
|
||||
char *reg;
|
||||
RListIter *iter;
|
||||
@ -5583,10 +5583,10 @@ static void showregs (RList *list) {
|
||||
}
|
||||
}
|
||||
}
|
||||
r_cons_newline();
|
||||
r_cons_newline ();
|
||||
}
|
||||
|
||||
static void showmem (RList *list) {
|
||||
static void showmem(RList *list) {
|
||||
if (!r_list_empty (list)) {
|
||||
AeaMemItem *item;
|
||||
RListIter *iter;
|
||||
@ -5598,7 +5598,7 @@ static void showmem (RList *list) {
|
||||
r_cons_newline ();
|
||||
}
|
||||
|
||||
static void showregs_json (RList *list, PJ *pj) {
|
||||
static void showregs_json(RList *list, PJ *pj) {
|
||||
pj_a (pj);
|
||||
if (!r_list_empty (list)) {
|
||||
char *reg;
|
||||
@ -5611,7 +5611,7 @@ static void showregs_json (RList *list, PJ *pj) {
|
||||
pj_end (pj);
|
||||
}
|
||||
|
||||
static void showmem_json (RList *list, PJ *pj) {
|
||||
static void showmem_json(RList *list, PJ *pj) {
|
||||
pj_a (pj);
|
||||
if (!r_list_empty (list)) {
|
||||
RListIter *iter;
|
||||
|
@ -4219,15 +4219,15 @@ static void ds_print_relocs(RDisasmState *ds) {
|
||||
}
|
||||
}
|
||||
|
||||
static int mymemwrite0(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
|
||||
return 0;
|
||||
static bool mymemwrite0(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static int mymemwrite1(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
|
||||
return 1;
|
||||
static bool mymemwrite1(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static int mymemwrite2(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
|
||||
static bool mymemwrite2(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
|
||||
return (addr >= emustack_min && addr < emustack_max);
|
||||
}
|
||||
|
||||
@ -4249,7 +4249,7 @@ static void ssa_set(RAnalEsil *esil, const char *reg) {
|
||||
}
|
||||
|
||||
#define R_DISASM_MAX_STR 512
|
||||
static int myregread(RAnalEsil *esil, const char *name, ut64 *res, int *size) {
|
||||
static bool myregread(RAnalEsil *esil, const char *name, ut64 *res, int *size) {
|
||||
RDisasmState *ds = esil->user;
|
||||
if (ds && ds->show_emu_ssa) {
|
||||
if (!isdigit ((unsigned char)*name)) {
|
||||
@ -4258,20 +4258,20 @@ static int myregread(RAnalEsil *esil, const char *name, ut64 *res, int *size) {
|
||||
free (r);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
static int myregwrite(RAnalEsil *esil, const char *name, ut64 *val) {
|
||||
static bool myregwrite(RAnalEsil *esil, const char *name, ut64 *val) {
|
||||
char str[64], *msg = NULL;
|
||||
ut32 *n32 = (ut32*)str;
|
||||
RDisasmState *ds = esil->user;
|
||||
if (!ds) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
if (!ds->show_emu_strlea && ds->analop.type == R_ANAL_OP_TYPE_LEA) {
|
||||
// useful for ARM64
|
||||
// reduce false positives in emu.str=true when loading strings via adrp+add
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
ds->esil_likely = true;
|
||||
if (ds->show_emu_ssa) {
|
||||
@ -4279,10 +4279,10 @@ static int myregwrite(RAnalEsil *esil, const char *name, ut64 *val) {
|
||||
char *r = ssa_get (esil, name);
|
||||
ds_comment_esil (ds, true, false, ">%s", r);
|
||||
free (r);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
if (!ds->show_slow) {
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
memset (str, 0, sizeof (str));
|
||||
if (*val) {
|
||||
@ -4412,7 +4412,7 @@ static int myregwrite(RAnalEsil *esil, const char *name, ut64 *val) {
|
||||
}
|
||||
}
|
||||
free (msg);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
static void ds_pre_emulation(RDisasmState *ds) {
|
||||
@ -4604,7 +4604,7 @@ static void ds_print_esil_anal(RDisasmState *ds) {
|
||||
RCore *core = ds->core;
|
||||
RAnalEsil *esil = core->anal->esil;
|
||||
const char *pc;
|
||||
int (*hook_mem_write)(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) = NULL;
|
||||
bool (*hook_mem_write)(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) = NULL;
|
||||
int i, nargs;
|
||||
ut64 at = r_core_pava (core, ds->at);
|
||||
RConfigHold *hc = r_config_hold_new (core->config);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2015 - pancake */
|
||||
/* radare - LGPL - Copyright 2015-2021 - pancake */
|
||||
|
||||
#include <r_debug.h>
|
||||
|
||||
@ -34,7 +34,7 @@ RList *esil_watchpoints = NULL;
|
||||
#define EWPS esil_watchpoints
|
||||
#define ESIL dbg->anal->esil
|
||||
|
||||
static int exprmatch (RDebug *dbg, ut64 addr, const char *expr) {
|
||||
static int exprmatch(RDebug *dbg, ut64 addr, const char *expr) {
|
||||
char *e = strdup (expr);
|
||||
if (!e) {
|
||||
return 0;
|
||||
@ -67,7 +67,7 @@ static int exprmatch (RDebug *dbg, ut64 addr, const char *expr) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int esilbreak_check_pc (RDebug *dbg, ut64 pc) {
|
||||
static bool esilbreak_check_pc (RDebug *dbg, ut64 pc) {
|
||||
EsilBreak *ew;
|
||||
RListIter *iter;
|
||||
if (!pc) {
|
||||
@ -80,10 +80,10 @@ static int esilbreak_check_pc (RDebug *dbg, ut64 pc) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
static int esilbreak_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
|
||||
static bool esilbreak_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
|
||||
EsilBreak *ew;
|
||||
RListIter *iter;
|
||||
eprintf (Color_GREEN"MEM READ 0x%"PFMT64x"\n"Color_RESET, addr);
|
||||
@ -95,10 +95,10 @@ static int esilbreak_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0; // fallback
|
||||
return false;
|
||||
}
|
||||
|
||||
static int esilbreak_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
|
||||
static bool esilbreak_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
|
||||
EsilBreak *ew;
|
||||
RListIter *iter;
|
||||
eprintf (Color_RED"MEM WRTE 0x%"PFMT64x"\n"Color_RESET, addr);
|
||||
@ -106,19 +106,19 @@ static int esilbreak_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int l
|
||||
if (ew->rwx & R_PERM_W && ew->dev == 'm') {
|
||||
if (exprmatch (dbg, addr, ew->expr)) {
|
||||
has_match = 1;
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1; // fallback
|
||||
return false; // fallback
|
||||
}
|
||||
|
||||
static int esilbreak_reg_read(RAnalEsil *esil, const char *regname, ut64 *num, int *size) {
|
||||
static bool esilbreak_reg_read(RAnalEsil *esil, const char *regname, ut64 *num, int *size) {
|
||||
EsilBreak *ew;
|
||||
RListIter *iter;
|
||||
if (regname[0]>='0' && regname[0]<='9') {
|
||||
//eprintf (Color_CYAN"IMM READ %s\n"Color_RESET, regname);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
eprintf (Color_YELLOW"REG READ %s\n"Color_RESET, regname);
|
||||
r_list_foreach (EWPS, iter, ew) {
|
||||
@ -126,11 +126,11 @@ static int esilbreak_reg_read(RAnalEsil *esil, const char *regname, ut64 *num, i
|
||||
// XXX: support array of regs in expr
|
||||
if (!strcmp (regname, ew->expr)) {
|
||||
has_match = 1;
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0; // fallback
|
||||
return false;
|
||||
}
|
||||
|
||||
static int exprtoken(RDebug *dbg, char *s, const char *sep, char **o) {
|
||||
@ -145,7 +145,7 @@ static int exprtoken(RDebug *dbg, char *s, const char *sep, char **o) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int exprmatchreg (RDebug *dbg, const char *regname, const char *expr) {
|
||||
static int exprmatchreg(RDebug *dbg, const char *regname, const char *expr) {
|
||||
int ret = 0;
|
||||
char *p;
|
||||
char *s = strdup (expr);
|
||||
@ -188,13 +188,13 @@ static int exprmatchreg (RDebug *dbg, const char *regname, const char *expr) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int esilbreak_reg_write(RAnalEsil *esil, const char *regname, ut64 *num) {
|
||||
static bool esilbreak_reg_write(RAnalEsil *esil, const char *regname, ut64 *num) {
|
||||
EsilBreak *ew;
|
||||
RListIter *iter;
|
||||
if (regname[0] >= '0' && regname[0] <= '9') {
|
||||
// wtf this should never happen
|
||||
//eprintf (Color_BLUE"IMM WRTE %s\n"Color_RESET, regname);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
eprintf (Color_MAGENTA"REG WRTE %s 0x%"PFMT64x"\n"Color_RESET, regname, *num);
|
||||
r_list_foreach (EWPS, iter, ew) {
|
||||
@ -202,18 +202,19 @@ static int esilbreak_reg_write(RAnalEsil *esil, const char *regname, ut64 *num)
|
||||
// XXX: support array of regs in expr
|
||||
if (exprmatchreg (dbg, regname, ew->expr)) {
|
||||
has_match = 1;
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1; // fallback
|
||||
return true;
|
||||
}
|
||||
|
||||
R_API void r_debug_esil_prestep (RDebug *d, int p) {
|
||||
R_API void r_debug_esil_prestep(RDebug *d, int p) {
|
||||
prestep = p;
|
||||
}
|
||||
|
||||
R_API int r_debug_esil_stepi (RDebug *d) {
|
||||
R_API bool r_debug_esil_stepi(RDebug *d) {
|
||||
r_return_val_if_fail (d, false);
|
||||
RAnalOp op;
|
||||
ut8 obuf[64];
|
||||
int ret = 1;
|
||||
@ -308,7 +309,7 @@ static void ewps_free(EsilBreak *ew) {
|
||||
free (ew);
|
||||
}
|
||||
|
||||
R_API int r_debug_esil_watch_empty(RDebug *dbg) {
|
||||
R_API bool r_debug_esil_watch_empty(RDebug *dbg) {
|
||||
return r_list_empty (EWPS);
|
||||
}
|
||||
|
||||
|
@ -1112,17 +1112,17 @@ typedef struct r_anal_esil_trace_t {
|
||||
Sdb *db;
|
||||
} RAnalEsilTrace;
|
||||
|
||||
typedef int (*RAnalEsilHookRegWriteCB)(ESIL *esil, const char *name, ut64 *val);
|
||||
typedef bool (*RAnalEsilHookRegWriteCB)(ESIL *esil, const char *name, ut64 *val);
|
||||
|
||||
typedef struct r_anal_esil_callbacks_t {
|
||||
void *user;
|
||||
/* callbacks */
|
||||
int (*hook_flag_read)(ESIL *esil, const char *flag, ut64 *num);
|
||||
int (*hook_command)(ESIL *esil, const char *op);
|
||||
int (*hook_mem_read)(ESIL *esil, ut64 addr, ut8 *buf, int len);
|
||||
int (*mem_read)(ESIL *esil, ut64 addr, ut8 *buf, int len);
|
||||
int (*hook_mem_write)(ESIL *esil, ut64 addr, const ut8 *buf, int len);
|
||||
int (*mem_write)(ESIL *esil, ut64 addr, const ut8 *buf, int len);
|
||||
bool (*hook_flag_read)(ESIL *esil, const char *flag, ut64 *num);
|
||||
bool (*hook_command)(ESIL *esil, const char *op);
|
||||
bool (*hook_mem_read)(ESIL *esil, ut64 addr, ut8 *buf, int len);
|
||||
bool (*mem_read)(ESIL *esil, ut64 addr, ut8 *buf, int len);
|
||||
bool (*hook_mem_write)(ESIL *esil, ut64 addr, const ut8 *buf, int len);
|
||||
bool (*mem_write)(ESIL *esil, ut64 addr, const ut8 *buf, int len);
|
||||
bool (*hook_reg_read)(ESIL *esil, const char *name, ut64 *res, int *size);
|
||||
bool (*reg_read)(ESIL *esil, const char *name, ut64 *res, int *size);
|
||||
RAnalEsilHookRegWriteCB hook_reg_write;
|
||||
@ -1574,8 +1574,8 @@ R_API void r_anal_esil_free(RAnalEsil *esil);
|
||||
R_API bool r_anal_esil_runword(RAnalEsil *esil, const char *word);
|
||||
R_API bool r_anal_esil_parse(RAnalEsil *esil, const char *str);
|
||||
R_API bool r_anal_esil_dumpstack(RAnalEsil *esil);
|
||||
R_API int r_anal_esil_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len);
|
||||
R_API int r_anal_esil_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len);
|
||||
R_API bool r_anal_esil_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len);
|
||||
R_API bool r_anal_esil_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len);
|
||||
R_API bool r_anal_esil_reg_read(RAnalEsil *esil, const char *regname, ut64 *num, int *size);
|
||||
R_API bool r_anal_esil_reg_write(RAnalEsil *esil, const char *dst, ut64 num);
|
||||
R_API bool r_anal_esil_pushnum(RAnalEsil *esil, ut64 num);
|
||||
|
@ -568,13 +568,13 @@ R_API int r_debug_drx_unset(RDebug *dbg, int idx);
|
||||
|
||||
/* esil */
|
||||
R_API ut64 r_debug_num_callback(RNum *userptr, const char *str, int *ok);
|
||||
R_API int r_debug_esil_stepi(RDebug *dbg);
|
||||
R_API bool r_debug_esil_stepi(RDebug *dbg);
|
||||
R_API ut64 r_debug_esil_step(RDebug *dbg, ut32 count);
|
||||
R_API ut64 r_debug_esil_continue(RDebug *dbg);
|
||||
R_API void r_debug_esil_watch(RDebug *dbg, int rwx, int dev, const char *expr);
|
||||
R_API void r_debug_esil_watch_reset(RDebug *dbg);
|
||||
R_API void r_debug_esil_watch_list(RDebug *dbg);
|
||||
R_API int r_debug_esil_watch_empty(RDebug *dbg);
|
||||
R_API bool r_debug_esil_watch_empty(RDebug *dbg);
|
||||
R_API void r_debug_esil_prestep (RDebug *d, int p);
|
||||
|
||||
/* record & replay */
|
||||
|
Loading…
Reference in New Issue
Block a user