radare2/libr/anal/esil_stats.c

69 lines
1.9 KiB
C
Raw Normal View History

2014-09-17 09:01:36 +00:00
/* radare - LGPL - Copyright 2014 - pancake */
2014-09-11 02:48:33 +00:00
#include <r_anal.h>
2014-09-12 23:32:34 +00:00
static int hook_flag_read(RAnalEsil *esil, const char *flag, ut64 *num) {
sdb_array_add (esil->stats, "flg.read", flag, 0);
2014-09-11 02:48:33 +00:00
return 0;
}
static int hook_command(RAnalEsil *esil, const char *op) {
sdb_array_add (esil->stats, "ops.list", op, 0);
return 0;
}
static int hook_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) {
sdb_array_add_num (esil->stats, "mem.read", addr, 0);
return 0;
}
static int hook_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) {
sdb_array_add_num (esil->stats, "mem.write", addr, 0);
return 0;
}
static int 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);
2014-09-11 02:48:33 +00:00
return 0;
}
static int hook_reg_write(RAnalEsil *esil, const char *name, ut64 *val) {
2014-09-11 02:48:33 +00:00
sdb_array_add (esil->stats, "reg.write", name, 0);
return 0;
}
static int 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
}
R_API void r_anal_esil_mem_ro(RAnalEsil *esil, int mem_readonly) {
if (mem_readonly) {
esil->cb.hook_mem_write = hook_NOP_mem_write;
2014-09-11 02:48:33 +00:00
} else {
esil->cb.hook_mem_write = NULL;
2014-09-11 02:48:33 +00:00
}
}
R_API void r_anal_esil_stats(RAnalEsil *esil, int enable) {
if (enable) {
if (esil->stats)
sdb_reset (esil->stats);
else esil->stats = sdb_new0();
// reset sdb->stats
esil->cb.hook_reg_read = hook_reg_read;
esil->cb.hook_mem_read = hook_mem_read;
esil->cb.hook_mem_write = hook_mem_write;
esil->cb.hook_reg_write = hook_reg_write;
esil->cb.hook_flag_read = hook_flag_read;
esil->cb.hook_command = hook_command;
2014-09-11 02:48:33 +00:00
} else {
esil->cb.hook_mem_write = NULL;
esil->cb.hook_flag_read = NULL;
esil->cb.hook_command = NULL;
2014-09-11 02:48:33 +00:00
sdb_free (esil->stats);
esil->stats = NULL;
}
}