Two bugfixes for register hooks

r_anal_esil_reg_write swallowed writes when a write hook was present, but returned zero which should signal that the hook was passive.
trace_hook_reg_read logged the values before considering the effects of other hooks. Also, failure of reg_read was ignored.

Also added a local variable in r_anal_esil_reg_read to remove the burden of null-check on third argument from [hook_]reg_read implementations.
This commit is contained in:
David Kreuter 2015-04-11 22:19:35 +02:00 committed by pancake
parent 4bfd019175
commit 51b02796d6
2 changed files with 18 additions and 14 deletions

View File

@ -12,23 +12,27 @@ static RAnalEsilCallbacks ocbs = {0};
static int trace_hook_reg_read(RAnalEsil *esil, const char *name, ut64 *res) {
int ret = 0;
ut64 val = 0LL;
if (*name=='0') {
eprintf ("Register not found in profile\n");
return 0;
}
if (esil->cb.reg_read) {
(void)esil->cb.reg_read (esil, name, &val);
}
eprintf ("[ESIL] REG READ %s 0x%08"PFMT64x"\n", name, val);
sdb_array_add (DB, KEY ("reg.read"), name, 0);
sdb_num_set (DB, KEYREG ("reg.read", name), val, 0);
if (ocbs.hook_reg_read) {
RAnalEsilCallbacks cbs = esil->cb;
esil->cb = ocbs;
ret = ocbs.hook_reg_read (esil, name, res);
esil->cb = cbs;
}
if (!ret && esil->cb.reg_read) {
ret = esil->cb.reg_read (esil, name, res);
}
if (ret) {
ut64 val = *res;
eprintf ("[ESIL] REG READ %s 0x%08"PFMT64x"\n", name, val);
sdb_array_add (DB, KEY ("reg.read"), name, 0);
sdb_num_set (DB, KEYREG ("reg.read", name), val, 0);
} else {
eprintf ("[ESIL] REG READ %s FAILED\n", name);
}
return ret;
}

View File

@ -334,26 +334,26 @@ R_API int r_anal_esil_reg_write (RAnalEsil *esil, const char *dst, ut64 num) {
}
if (esil->cb.hook_reg_write) {
ret = esil->cb.hook_reg_write (esil, dst, num);
if (!ret)
return ret;
}
if (esil->cb.reg_write) {
return esil->cb.reg_write (esil, dst, num);
if (!ret && esil->cb.reg_write) {
ret = esil->cb.reg_write (esil, dst, num);
}
return ret;
}
R_API int r_anal_esil_reg_read (RAnalEsil *esil, const char *regname, ut64 *num) {
int ret = 0;
if (num)
*num = 0LL;
ut64 localnum;
if (!num)
num = &localnum;
*num = 0LL;
if (esil->cb.hook_reg_read) {
ret = esil->cb.hook_reg_read (esil, regname, num);
}
if (!ret && esil->cb.reg_read) {
ret = esil->cb.reg_read (esil, regname, num);
}
if (ret && num && esil->debug) {
if (ret && esil->debug) {
eprintf ("%s=0x%"PFMT64x"\n", regname, *num);
}
return ret;