2020-11-22 22:28:52 +00:00
|
|
|
/* radare - LGPL - Copyright 2010-2020 pancake */
|
2010-03-04 00:46:25 +00:00
|
|
|
|
|
|
|
#include <r_debug.h>
|
|
|
|
|
2020-11-22 22:44:52 +00:00
|
|
|
R_API ut64 r_debug_arg_get(RDebug *dbg, const char *cc, int num) {
|
2020-11-22 22:28:52 +00:00
|
|
|
r_return_val_if_fail (dbg, UT64_MAX);
|
2020-11-22 22:44:52 +00:00
|
|
|
if (!cc) {
|
|
|
|
cc = r_anal_syscc_default (dbg->anal);
|
|
|
|
}
|
2020-11-22 22:28:52 +00:00
|
|
|
if (dbg->anal) {
|
|
|
|
if (!R_STR_ISEMPTY (cc)) {
|
|
|
|
if (!strcmp (cc, "stdcall") || !strcmp (cc, "pascal")) {
|
2020-11-22 22:44:52 +00:00
|
|
|
ut64 sp = r_debug_reg_get (dbg, "SP");
|
2020-11-22 22:28:52 +00:00
|
|
|
if (dbg->bits == 64) {
|
2020-11-22 22:44:52 +00:00
|
|
|
ut64 n64;
|
2020-11-22 22:28:52 +00:00
|
|
|
sp += 8; // skip return address, assume we are inside the call
|
|
|
|
sp += 8 * num;
|
2022-08-18 12:37:29 +00:00
|
|
|
dbg->iob.read_at (dbg->iob.io, sp, (ut8*)&n64, sizeof (ut64));
|
2020-11-22 22:28:52 +00:00
|
|
|
// TODO: honor endianness of platform
|
|
|
|
return (ut64)n64;
|
|
|
|
} else {
|
|
|
|
sp += 4; // skip return address, assume we are inside the call
|
|
|
|
sp += 4 * num;
|
2020-11-22 22:44:52 +00:00
|
|
|
ut32 n32;
|
2022-08-18 12:37:29 +00:00
|
|
|
dbg->iob.read_at (dbg->iob.io, sp, (ut8*)&n32, sizeof (ut32));
|
2020-11-22 22:28:52 +00:00
|
|
|
// TODO: honor endianness of platform
|
|
|
|
return (ut64)n32;
|
|
|
|
}
|
|
|
|
}
|
2023-08-25 16:45:02 +00:00
|
|
|
const char *rn = r_anal_cc_arg (dbg->anal, cc, num, -1);
|
2020-11-22 22:28:52 +00:00
|
|
|
if (rn) {
|
|
|
|
return r_debug_reg_get (dbg, rn);
|
|
|
|
}
|
2015-10-29 22:37:51 +00:00
|
|
|
}
|
2015-10-29 10:22:49 +00:00
|
|
|
}
|
2020-11-22 22:44:52 +00:00
|
|
|
char reg[32];
|
2020-11-22 22:28:52 +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);
|
|
|
|
}
|
|
|
|
|
2020-11-22 22:44:52 +00:00
|
|
|
R_API bool r_debug_arg_set(RDebug *dbg, const char *cc, int num, ut64 val) {
|
2020-11-22 22:28:52 +00:00
|
|
|
r_return_val_if_fail (dbg, false);
|
|
|
|
if (!R_STR_ISEMPTY (cc)) {
|
2020-11-22 22:44:52 +00:00
|
|
|
cc = r_anal_syscc_default (dbg->anal);
|
2020-11-22 22:28:52 +00:00
|
|
|
}
|
2023-08-25 16:45:02 +00:00
|
|
|
const char *rn = r_anal_cc_arg (dbg->anal, cc, num, -1);
|
2020-11-22 22:28:52 +00:00
|
|
|
if (rn) {
|
|
|
|
r_debug_reg_set (dbg, rn, val);
|
|
|
|
return true;
|
2015-10-29 10:22:49 +00:00
|
|
|
}
|
2020-11-22 22:28:52 +00:00
|
|
|
char reg[32];
|
|
|
|
snprintf (reg, sizeof (reg) - 1, "A%d", num);
|
|
|
|
r_debug_reg_set (dbg, reg, val);
|
|
|
|
return true;
|
2010-03-04 00:46:25 +00:00
|
|
|
}
|