2014-01-08 22:23:06 +00:00
|
|
|
/* radare - LGPL - Copyright 2009-2014 - pancake */
|
2009-09-18 18:11:42 +00:00
|
|
|
|
2009-02-05 21:08:46 +00:00
|
|
|
#include <r_reg.h>
|
2009-09-18 18:11:42 +00:00
|
|
|
#include <r_util.h>
|
2009-09-19 19:54:22 +00:00
|
|
|
#include <list.h>
|
2009-09-18 18:11:42 +00:00
|
|
|
|
2014-01-08 22:23:06 +00:00
|
|
|
R_LIB_VERSION (r_reg);
|
2013-06-14 00:51:33 +00:00
|
|
|
|
2010-02-18 15:36:55 +00:00
|
|
|
static const char *types[R_REG_TYPE_LAST+1] = {
|
2010-01-21 01:38:52 +00:00
|
|
|
"gpr", "drx", "fpu", "mmx", "xmm", "flg", "seg", NULL
|
2010-01-19 10:25:17 +00:00
|
|
|
};
|
|
|
|
|
2010-02-18 15:36:55 +00:00
|
|
|
R_API const char *r_reg_get_type(int idx) {
|
|
|
|
if (idx>=0 && idx<R_REG_TYPE_LAST)
|
|
|
|
return types[idx];
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-09-18 00:51:17 +00:00
|
|
|
static void r_reg_item_free(RRegItem *item) {
|
|
|
|
free (item->name);
|
2010-09-24 02:09:39 +00:00
|
|
|
free (item->flags);
|
2010-09-18 00:51:17 +00:00
|
|
|
free (item);
|
2009-09-18 18:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-02-03 17:15:31 +00:00
|
|
|
R_API int r_reg_get_name_idx(const char *type) {
|
2010-06-22 18:27:14 +00:00
|
|
|
if (type)
|
|
|
|
switch (*type | (type[1]<<8)) {
|
2014-01-08 22:23:06 +00:00
|
|
|
/* flags */
|
|
|
|
case 'z'+('f'<<8): return R_REG_NAME_ZF;
|
|
|
|
case 's'+('f'<<8): return R_REG_NAME_SF;
|
|
|
|
case 'c'+('f'<<8): return R_REG_NAME_CF;
|
|
|
|
case 'o'+('f'<<8): return R_REG_NAME_OF;
|
|
|
|
/* gpr */
|
2010-06-22 18:27:14 +00:00
|
|
|
case 'p'+('c'<<8): return R_REG_NAME_PC;
|
|
|
|
case 's'+('r'<<8): return R_REG_NAME_SR;
|
|
|
|
case 's'+('p'<<8): return R_REG_NAME_SP;
|
|
|
|
case 'b'+('p'<<8): return R_REG_NAME_BP;
|
2014-06-14 00:01:03 +00:00
|
|
|
case 's'+('n'<<8): return R_REG_NAME_SN;
|
2014-01-08 22:23:06 +00:00
|
|
|
/* args */
|
2010-06-22 18:27:14 +00:00
|
|
|
case 'a'+('0'<<8): return R_REG_NAME_A0;
|
|
|
|
case 'a'+('1'<<8): return R_REG_NAME_A1;
|
|
|
|
case 'a'+('2'<<8): return R_REG_NAME_A2;
|
|
|
|
case 'a'+('3'<<8): return R_REG_NAME_A3;
|
2010-02-03 13:34:00 +00:00
|
|
|
}
|
2010-06-22 18:27:14 +00:00
|
|
|
return -1;
|
2010-02-03 17:15:31 +00:00
|
|
|
}
|
|
|
|
|
2010-09-18 00:51:17 +00:00
|
|
|
R_API int r_reg_set_name(RReg *reg, int role, const char *name) {
|
|
|
|
if (role>=0 && role<R_REG_NAME_LAST) {
|
2010-02-03 13:34:00 +00:00
|
|
|
reg->name[role] = r_str_dup (reg->name[role], name);
|
2010-09-18 00:51:17 +00:00
|
|
|
return R_TRUE;
|
|
|
|
}
|
|
|
|
return R_FALSE;
|
2010-02-03 13:34:00 +00:00
|
|
|
}
|
|
|
|
|
2010-09-18 00:51:17 +00:00
|
|
|
R_API const char *r_reg_get_name(RReg *reg, int role) {
|
2010-06-16 07:42:46 +00:00
|
|
|
if (reg && role>=0 && role<R_REG_NAME_LAST)
|
2010-02-03 17:15:31 +00:00
|
|
|
return reg->name[role];
|
2010-02-28 21:58:21 +00:00
|
|
|
return NULL;
|
2010-02-03 17:15:31 +00:00
|
|
|
}
|
|
|
|
|
2010-09-18 00:51:17 +00:00
|
|
|
R_API void r_reg_free_internal(RReg *reg) {
|
|
|
|
int i;
|
2014-09-06 01:59:28 +00:00
|
|
|
|
|
|
|
free (reg->reg_profile_str);
|
|
|
|
reg->reg_profile_str = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < R_REG_NAME_LAST; i++) {
|
2014-08-24 23:18:35 +00:00
|
|
|
if (reg->name[i]) {
|
|
|
|
free (reg->name[i]);
|
|
|
|
reg->name[i] = NULL;
|
|
|
|
}
|
2014-08-25 02:27:25 +00:00
|
|
|
}
|
2014-09-06 01:59:28 +00:00
|
|
|
for (i = 0; i<R_REG_TYPE_LAST; i++) {
|
2014-08-25 02:27:25 +00:00
|
|
|
r_list_purge (reg->regset[i].regs);
|
2012-12-23 12:52:57 +00:00
|
|
|
reg->regset[i].regs = r_list_newf ((RListFree)r_reg_item_free);
|
2011-07-02 21:15:40 +00:00
|
|
|
}
|
2014-09-06 01:59:28 +00:00
|
|
|
reg->size = 0;
|
2010-09-18 00:51:17 +00:00
|
|
|
}
|
|
|
|
|
2012-03-07 09:43:02 +00:00
|
|
|
R_API void r_reg_free(RReg *reg) {
|
|
|
|
int i;
|
2014-09-06 01:59:28 +00:00
|
|
|
|
|
|
|
if (!reg)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < R_REG_TYPE_LAST; i++) {
|
2014-05-02 14:54:27 +00:00
|
|
|
r_list_purge (reg->regset[i].pool);
|
2012-03-07 09:43:02 +00:00
|
|
|
reg->regset[i].pool = NULL;
|
2009-09-18 18:11:42 +00:00
|
|
|
}
|
2012-03-07 09:43:02 +00:00
|
|
|
r_reg_free_internal (reg);
|
|
|
|
free (reg);
|
2009-09-18 18:11:42 +00:00
|
|
|
}
|
|
|
|
|
2010-09-18 00:51:17 +00:00
|
|
|
R_API RReg *r_reg_new() {
|
2011-06-04 01:14:04 +00:00
|
|
|
RRegArena *arena;
|
2014-09-06 01:59:28 +00:00
|
|
|
RReg *reg = R_NEW0 (RReg);
|
|
|
|
int i;
|
|
|
|
|
2014-08-25 20:56:49 +00:00
|
|
|
for (i=0; i<R_REG_TYPE_LAST; i++) {
|
2011-06-04 01:14:04 +00:00
|
|
|
arena = r_reg_arena_new (0);
|
2014-05-03 07:09:10 +00:00
|
|
|
if (!arena) {
|
|
|
|
free (reg);
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-12-23 12:52:57 +00:00
|
|
|
reg->regset[i].pool = r_list_newf ((RListFree)r_reg_arena_free);
|
|
|
|
reg->regset[i].regs = r_list_newf ((RListFree)r_reg_item_free);
|
2013-08-29 14:59:24 +00:00
|
|
|
reg->regset[i].arena = arena;
|
|
|
|
//r_list_append (reg->regset[i].pool, arena);
|
2009-09-13 22:37:28 +00:00
|
|
|
}
|
|
|
|
return reg;
|
|
|
|
}
|
2009-02-05 21:08:46 +00:00
|
|
|
|
2010-02-28 21:58:21 +00:00
|
|
|
R_API int r_reg_type_by_name(const char *str) {
|
2010-01-19 10:25:17 +00:00
|
|
|
int i;
|
2014-11-16 09:24:04 +00:00
|
|
|
for (i=0; i<R_REG_TYPE_LAST && types[i]; i++)
|
2010-02-18 15:36:55 +00:00
|
|
|
if (!strcmp (types[i], str))
|
2010-01-19 10:25:17 +00:00
|
|
|
return i;
|
|
|
|
if (!strcmp (str, "all"))
|
|
|
|
return R_REG_TYPE_ALL;
|
|
|
|
eprintf ("Unknown register type: '%s'\n", str);
|
2014-01-08 22:23:06 +00:00
|
|
|
return -1;
|
2009-09-25 02:04:51 +00:00
|
|
|
}
|
|
|
|
|
2014-09-06 01:59:28 +00:00
|
|
|
static const char *parse_alias (RReg *reg, char **tok, const int n) {
|
|
|
|
int role;
|
|
|
|
|
|
|
|
if (n != 2)
|
|
|
|
return "Invalid syntax";
|
|
|
|
|
|
|
|
role = r_reg_get_name_idx(tok[0] + 1);
|
|
|
|
return r_reg_set_name(reg, role, tok[1]) ?
|
|
|
|
NULL :
|
|
|
|
"Invalid alias";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sizes prepended with a dot are expressed in bits
|
|
|
|
// strtoul with base 0 allows the input to be in decimal/octal/hex format
|
|
|
|
#define parse_size(c) \
|
|
|
|
((c)[0] == '.') ? \
|
|
|
|
strtoul((c) + 1, &end, 10) : \
|
|
|
|
strtoul((c), &end, 0) << 3;
|
|
|
|
|
|
|
|
static const char *parse_def (RReg *reg, char **tok, const int n) {
|
|
|
|
RRegItem *item;
|
|
|
|
char *end;
|
|
|
|
int type;
|
|
|
|
|
|
|
|
if (n != 5 && n != 6)
|
|
|
|
return "Invalid syntax";
|
|
|
|
|
|
|
|
type = r_reg_type_by_name (tok[0]);
|
|
|
|
if (type < 0)
|
|
|
|
return "Invalid register type";
|
|
|
|
|
|
|
|
item = R_NEW0 (RRegItem);
|
|
|
|
|
|
|
|
item->type = type;
|
|
|
|
item->name = strdup (tok[1]);
|
|
|
|
// All the numeric arguments are strictly checked
|
|
|
|
item->size = parse_size (tok[2]);
|
|
|
|
if (*end != '\0' || !item->size) {
|
2014-09-14 20:07:47 +00:00
|
|
|
r_reg_item_free (item);
|
2014-09-06 01:59:28 +00:00
|
|
|
return "Invalid size";
|
2009-09-19 19:54:22 +00:00
|
|
|
}
|
2014-09-06 01:59:28 +00:00
|
|
|
item->offset = parse_size (tok[3]);
|
|
|
|
if (*end != '\0') {
|
2014-09-14 20:07:47 +00:00
|
|
|
r_reg_item_free (item);
|
2014-09-06 01:59:28 +00:00
|
|
|
return "Invalid offset";
|
|
|
|
}
|
|
|
|
item->packed_size = parse_size (tok[4]);
|
|
|
|
if (*end != '\0') {
|
2014-09-14 20:07:47 +00:00
|
|
|
r_reg_item_free (item);
|
2014-09-06 01:59:28 +00:00
|
|
|
return "Invalid packed size";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dynamically update the list of supported bit sizes
|
|
|
|
reg->bits |= item->size;
|
|
|
|
|
|
|
|
// This is optional
|
|
|
|
if (n == 6)
|
|
|
|
item->flags = strdup (tok[5]);
|
|
|
|
|
2014-09-14 20:07:47 +00:00
|
|
|
// Don't allow duplicate registers
|
|
|
|
if (r_reg_get (reg, item->name, R_REG_TYPE_ALL)) {
|
|
|
|
r_reg_item_free (item);
|
|
|
|
return "Duplicate register definition";
|
|
|
|
}
|
2014-09-06 01:59:28 +00:00
|
|
|
|
|
|
|
r_list_append (reg->regset[item->type].regs, item);
|
|
|
|
|
2014-09-14 20:07:47 +00:00
|
|
|
// Update the overall profile size
|
|
|
|
if (item->offset + item->size > reg->size)
|
|
|
|
reg->size = item->offset + item->size;
|
|
|
|
|
2014-09-06 01:59:28 +00:00
|
|
|
return NULL;
|
2009-09-19 19:54:22 +00:00
|
|
|
}
|
|
|
|
|
2014-09-06 01:59:28 +00:00
|
|
|
#define PARSER_MAX_TOKENS 8
|
|
|
|
|
2014-09-13 00:23:03 +00:00
|
|
|
R_API int r_reg_set_profile_string(RReg *reg, const char *str) {
|
2014-09-06 01:59:28 +00:00
|
|
|
char *tok[PARSER_MAX_TOKENS];
|
|
|
|
char tmp[128];
|
|
|
|
int i, j, l;
|
2014-09-13 00:23:03 +00:00
|
|
|
const char *p = str;
|
2014-09-06 01:59:28 +00:00
|
|
|
|
|
|
|
if (!reg || !str)
|
2009-09-19 19:54:22 +00:00
|
|
|
return R_FALSE;
|
2014-09-06 01:59:28 +00:00
|
|
|
|
|
|
|
// Same profile, no need to change
|
|
|
|
if (reg->reg_profile_str && !strcmp (reg->reg_profile_str, str))
|
2014-06-23 16:13:41 +00:00
|
|
|
return R_TRUE;
|
2014-09-06 01:59:28 +00:00
|
|
|
|
|
|
|
// Purge the old registers
|
2010-02-03 13:34:00 +00:00
|
|
|
r_reg_free_internal (reg);
|
2009-09-19 19:54:22 +00:00
|
|
|
|
2014-09-06 01:59:28 +00:00
|
|
|
// Cache the profile string
|
2014-09-10 00:21:10 +00:00
|
|
|
reg->reg_profile_str = strdup (str);
|
2014-09-06 01:59:28 +00:00
|
|
|
|
|
|
|
// Line number
|
|
|
|
l = 0;
|
|
|
|
// For every line
|
|
|
|
do {
|
|
|
|
// Increment line number
|
|
|
|
l++;
|
|
|
|
// Skip comment lines
|
|
|
|
if (*p == '#') {
|
|
|
|
while (*p != '\n')
|
|
|
|
p++;
|
2009-09-19 19:54:22 +00:00
|
|
|
continue;
|
|
|
|
}
|
2014-09-06 01:59:28 +00:00
|
|
|
j = 0;
|
|
|
|
// For every word
|
|
|
|
while (*p) {
|
|
|
|
// Skip the whitespace
|
|
|
|
while (*p == ' ' || *p == '\t')
|
|
|
|
p++;
|
|
|
|
// Skip the rest of the line is a comment is encountered
|
|
|
|
if (*p == '#')
|
|
|
|
while (*p != '\n')
|
|
|
|
p++;
|
|
|
|
// EOL ?
|
|
|
|
if (*p == '\n')
|
|
|
|
break;
|
|
|
|
// Gather a handful of chars
|
|
|
|
// Use isgraph instead of isprint because the latter considers ' ' printable
|
2014-09-11 11:36:35 +00:00
|
|
|
for (i = 0; isgraph (*p) && i < sizeof(tmp) - 1;)
|
2014-09-06 01:59:28 +00:00
|
|
|
tmp[i++] = *p++;
|
|
|
|
tmp[i] = '\0';
|
|
|
|
// Limit the number of tokens
|
2014-09-11 11:36:35 +00:00
|
|
|
if (j > PARSER_MAX_TOKENS - 1)
|
2014-09-06 01:59:28 +00:00
|
|
|
break;
|
|
|
|
// Save the token
|
|
|
|
tok[j++] = strdup (tmp);
|
|
|
|
}
|
|
|
|
// Empty line, eww
|
|
|
|
if (j) {
|
|
|
|
// Do the actual parsing
|
|
|
|
char *first = tok[0];
|
|
|
|
// Check whether it's defining an alias or a register
|
|
|
|
const char *r = (*first == '=') ?
|
|
|
|
parse_alias (reg, tok, j) :
|
|
|
|
parse_def (reg, tok, j);
|
|
|
|
// Clean up
|
|
|
|
for (i = 0; i < j; i++)
|
|
|
|
free(tok[i]);
|
|
|
|
// Warn the user if something went wrong
|
|
|
|
if (r) {
|
|
|
|
eprintf("%s: Parse error @ line %d (%s)\n", __FUNCTION__, l, r);
|
|
|
|
// Clean up
|
|
|
|
r_reg_free_internal (reg);
|
2009-09-19 19:54:22 +00:00
|
|
|
return R_FALSE;
|
2011-03-23 23:54:09 +00:00
|
|
|
}
|
2009-09-19 19:54:22 +00:00
|
|
|
}
|
2014-09-06 01:59:28 +00:00
|
|
|
} while(*p++);
|
|
|
|
|
|
|
|
// Align to byte boundary if needed
|
|
|
|
if (reg->size&7)
|
|
|
|
reg->size += 8 - (reg->size&7);
|
|
|
|
|
|
|
|
// Transform to bytes
|
|
|
|
reg->size >>= 3;
|
|
|
|
|
2010-01-21 01:38:52 +00:00
|
|
|
r_reg_fit_arena (reg);
|
2010-09-18 00:51:17 +00:00
|
|
|
|
2014-09-06 01:59:28 +00:00
|
|
|
return R_TRUE;
|
2009-02-05 21:08:46 +00:00
|
|
|
}
|
|
|
|
|
2010-09-18 00:51:17 +00:00
|
|
|
R_API int r_reg_set_profile(RReg *reg, const char *profile) {
|
2014-09-10 22:41:33 +00:00
|
|
|
int ret;
|
|
|
|
char *base, *file;
|
|
|
|
char *str = r_file_slurp (profile, NULL);
|
2014-09-06 01:59:28 +00:00
|
|
|
if (!str) {
|
|
|
|
// XXX we must define this varname in r_lib.h /compiletime/
|
2010-01-19 10:25:17 +00:00
|
|
|
base = r_sys_getenv ("LIBR_PLUGINS");
|
2009-09-18 18:11:42 +00:00
|
|
|
if (base) {
|
2011-08-27 22:01:03 +00:00
|
|
|
file = r_str_concat (base, profile);
|
2010-01-19 10:25:17 +00:00
|
|
|
str = r_file_slurp (file, NULL);
|
2010-06-16 07:42:46 +00:00
|
|
|
free (file);
|
2009-02-05 21:08:46 +00:00
|
|
|
}
|
|
|
|
}
|
2014-09-06 01:59:28 +00:00
|
|
|
|
|
|
|
if (!str) {
|
|
|
|
eprintf ("r_reg_set_profile: Cannot find '%s'\n", profile);
|
|
|
|
return R_FALSE;
|
2014-05-03 07:06:46 +00:00
|
|
|
}
|
2014-09-06 01:59:28 +00:00
|
|
|
|
2014-09-10 22:41:33 +00:00
|
|
|
ret = r_reg_set_profile_string (reg, str);
|
|
|
|
free (str);
|
|
|
|
return ret;
|
2009-02-05 21:08:46 +00:00
|
|
|
}
|
2009-09-18 18:11:42 +00:00
|
|
|
|
2014-01-28 03:03:35 +00:00
|
|
|
R_API ut64 r_reg_setv(RReg *reg, const char *name, ut64 val) {
|
|
|
|
return r_reg_set_value (reg, r_reg_get (reg, name, -1), val);
|
|
|
|
}
|
|
|
|
|
2013-06-20 00:49:39 +00:00
|
|
|
R_API ut64 r_reg_getv(RReg *reg, const char *name) {
|
|
|
|
return r_reg_get_value (reg, r_reg_get (reg, name, -1));
|
|
|
|
}
|
|
|
|
|
2010-09-18 00:51:17 +00:00
|
|
|
R_API RRegItem *r_reg_get(RReg *reg, const char *name, int type) {
|
|
|
|
RListIter *iter;
|
|
|
|
RRegItem *r;
|
2009-10-12 15:41:52 +00:00
|
|
|
int i, e;
|
2010-10-14 17:01:14 +00:00
|
|
|
if (!reg || !name)
|
2010-06-16 07:42:46 +00:00
|
|
|
return NULL;
|
2009-10-12 15:41:52 +00:00
|
|
|
if (type == -1) {
|
|
|
|
i = 0;
|
|
|
|
e = R_REG_TYPE_LAST;
|
|
|
|
} else {
|
|
|
|
i = type;
|
|
|
|
e = type+1;
|
|
|
|
}
|
2009-09-18 18:11:42 +00:00
|
|
|
|
2010-09-18 00:51:17 +00:00
|
|
|
for (; i<e; i++) {
|
|
|
|
r_list_foreach (reg->regset[i].regs, iter, r) {
|
2014-08-08 00:11:23 +00:00
|
|
|
if (r->name && !strcmp (r->name, name)) {
|
2010-09-18 00:51:17 +00:00
|
|
|
return r;
|
2014-08-08 00:11:23 +00:00
|
|
|
}
|
2010-09-18 00:51:17 +00:00
|
|
|
}
|
2009-09-18 18:11:42 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-09-18 00:51:17 +00:00
|
|
|
R_API RList *r_reg_get_list(RReg *reg, int type) {
|
2014-04-26 22:31:04 +00:00
|
|
|
if (type < 0 || type > (R_REG_TYPE_LAST-1))
|
2009-09-18 18:11:42 +00:00
|
|
|
return NULL;
|
2010-09-18 00:51:17 +00:00
|
|
|
return reg->regset[type].regs;
|
2009-09-18 18:11:42 +00:00
|
|
|
}
|
2010-09-20 12:02:45 +00:00
|
|
|
|
2010-09-24 14:45:56 +00:00
|
|
|
R_API ut64 r_reg_cmp(RReg *reg, RRegItem *item) {
|
2012-06-14 00:18:15 +00:00
|
|
|
ut64 ret, ret2;
|
2013-08-29 14:59:24 +00:00
|
|
|
RListIter *it;
|
2012-06-14 00:18:15 +00:00
|
|
|
int ptr = !(reg->iters%2);
|
2010-09-20 12:02:45 +00:00
|
|
|
int len = (item->size/8); // TODO: must use r_mem_bitcmp or so.. flags not correctly checked
|
2010-09-24 14:45:56 +00:00
|
|
|
int off = BITS2BYTES (item->offset);
|
2013-08-29 14:59:24 +00:00
|
|
|
RRegArena *dst, *src;
|
|
|
|
it = r_list_head (reg->regset[item->type].pool);
|
|
|
|
if (!it || !it->n)
|
|
|
|
return UT64_MAX;
|
|
|
|
src = r_list_head (reg->regset[item->type].pool)->data;
|
|
|
|
dst = it->n->data;
|
2011-06-04 01:14:04 +00:00
|
|
|
if (off+len>src->size) len = src->size-off;
|
2012-02-01 10:49:46 +00:00
|
|
|
if (off+len>dst->size) len = dst->size-off;
|
2013-03-01 11:20:18 +00:00
|
|
|
if (len>1 && memcmp (dst->bytes+off, src->bytes+off, len)) {
|
2010-09-24 14:45:56 +00:00
|
|
|
r_reg_arena_set (reg, ptr, 0);
|
|
|
|
ret = r_reg_get_value (reg, item);
|
|
|
|
r_reg_arena_set (reg, !ptr, 0);
|
2012-06-14 00:18:15 +00:00
|
|
|
ret2 = r_reg_get_value (reg, item);
|
|
|
|
return ret-ret2;
|
2010-09-24 14:45:56 +00:00
|
|
|
}
|
|
|
|
return 0LL;
|
2010-09-20 12:02:45 +00:00
|
|
|
}
|
2014-06-26 10:18:45 +00:00
|
|
|
|
2014-07-03 11:48:35 +00:00
|
|
|
// TODO regsize is in bits, delta in bytes, maybe we should standarize this..
|
2014-06-26 10:18:45 +00:00
|
|
|
R_API RRegItem *r_reg_get_at (RReg *reg, int type, int regsize, int delta) {
|
|
|
|
RList *list = r_reg_get_list (reg, type);
|
|
|
|
RRegItem *ri;
|
|
|
|
RListIter *iter;
|
|
|
|
r_list_foreach (list, iter, ri) {
|
|
|
|
if (ri->size == regsize) {
|
2014-07-03 11:48:35 +00:00
|
|
|
if (BITS2BYTES(ri->offset) == delta)
|
2014-06-26 10:18:45 +00:00
|
|
|
return ri;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return the next register in the current regset that differs from */
|
|
|
|
R_API RRegItem *r_reg_next_diff(RReg *reg, int type, const ut8* buf, int buflen, RRegItem *prev_ri, int regsize) {
|
2014-07-03 11:48:35 +00:00
|
|
|
int bregsize = BITS2BYTES (regsize);
|
2014-06-26 10:18:45 +00:00
|
|
|
RRegArena *arena;
|
|
|
|
int delta;
|
|
|
|
if (type < 0 || type > (R_REG_TYPE_LAST-1))
|
|
|
|
return NULL;
|
|
|
|
arena = reg->regset[type].arena;
|
|
|
|
delta = prev_ri? prev_ri->offset+prev_ri->size: 0;
|
2014-06-27 13:33:25 +00:00
|
|
|
for (;;) {
|
2014-07-03 11:48:35 +00:00
|
|
|
if (delta+bregsize>=arena->size || delta+bregsize >= buflen)
|
2014-06-27 13:33:25 +00:00
|
|
|
break;
|
2014-07-03 11:48:35 +00:00
|
|
|
if (memcmp (arena->bytes+delta, buf+delta, bregsize)) {
|
|
|
|
RRegItem *ri = r_reg_get_at (reg, type, regsize, delta);
|
2014-06-27 13:33:25 +00:00
|
|
|
if (ri) return ri;
|
|
|
|
}
|
2014-07-03 11:48:35 +00:00
|
|
|
delta += bregsize;
|
|
|
|
}
|
2014-06-26 10:18:45 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2014-10-15 00:24:22 +00:00
|
|
|
|
|
|
|
R_API RRegSet *r_reg_regset_get(RReg *r, int type) {
|
|
|
|
RRegSet *rs;
|
|
|
|
if (type<0 || type>=R_REG_TYPE_LAST)
|
|
|
|
return NULL;
|
|
|
|
rs = &r->regset[type];
|
|
|
|
if (rs->arena)
|
|
|
|
return rs;
|
|
|
|
return NULL;
|
|
|
|
}
|