2015-10-31 00:57:52 +00:00
|
|
|
/* radare - LGPL - Copyright 2010-2015 pancake */
|
2010-03-04 00:46:25 +00:00
|
|
|
|
|
|
|
#include <r_debug.h>
|
|
|
|
|
2015-10-29 10:22:49 +00:00
|
|
|
R_API ut64 r_debug_arg_get (RDebug *dbg, int cctype, int num) {
|
2015-10-31 00:57:52 +00:00
|
|
|
ut32 n32;
|
|
|
|
ut64 n64, sp;
|
2014-11-20 00:30:37 +00:00
|
|
|
char reg[32];
|
2016-07-27 11:50:14 +00:00
|
|
|
//TODO replace the hardcoded implementation with the sdb
|
2015-10-29 10:22:49 +00:00
|
|
|
switch (cctype) {
|
|
|
|
case R_ANAL_CC_TYPE_SYSV:
|
|
|
|
case R_ANAL_CC_TYPE_FASTCALL:
|
2016-04-22 17:33:23 +00:00
|
|
|
snprintf (reg, sizeof (reg)-1, "A%d", num);
|
2015-10-29 10:22:49 +00:00
|
|
|
return r_debug_reg_get (dbg, reg);
|
|
|
|
case R_ANAL_CC_TYPE_STDCALL:
|
|
|
|
case R_ANAL_CC_TYPE_PASCAL:
|
2015-10-31 00:57:52 +00:00
|
|
|
sp = r_debug_reg_get (dbg, "SP");
|
|
|
|
if (dbg->bits == 64) {
|
2019-06-20 04:45:00 +00:00
|
|
|
sp += 8; // skip return address, assume we are inside the call
|
2015-10-31 00:57:52 +00:00
|
|
|
sp += 8 * num;
|
|
|
|
dbg->iob.read_at (dbg->iob.io, sp, (ut8*)&n64, sizeof(ut64));
|
|
|
|
// TODO: honor endianness of platform
|
|
|
|
return (ut64)n64;
|
|
|
|
} else {
|
2019-06-20 04:45:00 +00:00
|
|
|
sp += 4; // skip return address, assume we are inside the call
|
2015-10-31 00:57:52 +00:00
|
|
|
sp += 4 * num;
|
|
|
|
dbg->iob.read_at (dbg->iob.io, sp, (ut8*)&n32, sizeof(ut32));
|
|
|
|
// TODO: honor endianness of platform
|
|
|
|
return (ut64)n32;
|
2015-10-29 22:37:51 +00:00
|
|
|
}
|
2015-10-29 10:22:49 +00:00
|
|
|
}
|
2016-04-22 17:33:23 +00:00
|
|
|
snprintf (reg, sizeof (reg)-1, "A%d", num);
|
2010-03-04 00:46:25 +00:00
|
|
|
return r_debug_reg_get (dbg, reg);
|
|
|
|
}
|
|
|
|
|
2015-10-29 10:22:49 +00:00
|
|
|
R_API bool r_debug_arg_set (RDebug *dbg, int cctype, int num, ut64 val) {
|
2016-07-27 11:50:14 +00:00
|
|
|
// TODO replace the hardcoded implementation with the sdb
|
2015-10-29 10:22:49 +00:00
|
|
|
char reg[32];
|
|
|
|
switch (cctype) {
|
|
|
|
case R_ANAL_CC_TYPE_SYSV:
|
|
|
|
case R_ANAL_CC_TYPE_FASTCALL:
|
2015-10-31 00:57:52 +00:00
|
|
|
snprintf (reg, 30, "A%d", num);
|
2015-10-29 10:22:49 +00:00
|
|
|
return r_debug_reg_set (dbg, reg, val);
|
|
|
|
case R_ANAL_CC_TYPE_STDCALL:
|
|
|
|
case R_ANAL_CC_TYPE_PASCAL:
|
|
|
|
/* TODO: get from stack */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
2010-03-04 00:46:25 +00:00
|
|
|
}
|