diff --git a/libr/core/cmd_debug.c b/libr/core/cmd_debug.c index ef4cc56170..6ea648cea7 100644 --- a/libr/core/cmd_debug.c +++ b/libr/core/cmd_debug.c @@ -797,16 +797,25 @@ free (rf); regname = r_reg_get_name (core->dbg->reg, r_reg_get_name_idx (string)); if (!regname) - regname= string; + regname = string; r = r_reg_get (core->dbg->reg, regname, -1); //R_REG_TYPE_GPR); if (r) { - r_cons_printf ("0x%08"PFMT64x" ->", str, - r_reg_get_value (core->dbg->reg, r)); - r_reg_set_value (core->dbg->reg, r, - r_num_math (core->num, arg+1)); - r_debug_reg_sync (core->dbg, -1, R_TRUE); - r_cons_printf ("0x%08"PFMT64x"\n", - r_reg_get_value (core->dbg->reg, r)); + if (r->flags) { + r_cons_printf ("0x%08"PFMT64x" ->", + r_reg_get_value (core->dbg->reg, r)); + r_reg_set_bvalue (core->dbg->reg, r, arg+1); + r_debug_reg_sync (core->dbg, -1, R_TRUE); + r_cons_printf ("0x%08"PFMT64x"\n", + r_reg_get_value (core->dbg->reg, r)); + } else { + r_cons_printf ("0x%08"PFMT64x" ->", str, + r_reg_get_value (core->dbg->reg, r)); + r_reg_set_value (core->dbg->reg, r, + r_num_math (core->num, arg+1)); + r_debug_reg_sync (core->dbg, -1, R_TRUE); + r_cons_printf ("0x%08"PFMT64x"\n", + r_reg_get_value (core->dbg->reg, r)); + } } else eprintf ("Unknown register '%s'\n", string); free (string); return; diff --git a/libr/include/r_reg.h b/libr/include/r_reg.h index 94fc293d0e..2ea1586e54 100644 --- a/libr/include/r_reg.h +++ b/libr/include/r_reg.h @@ -136,6 +136,7 @@ R_API float r_reg_get_fvalue(RReg *reg, RRegItem *item); R_API int r_reg_set_fvalue(RReg *reg, RRegItem *item, float value); R_API ut64 r_reg_get_pvalue(RReg *reg, RRegItem *item, int packidx); R_API char *r_reg_get_bvalue(RReg *reg, RRegItem *item); +R_API ut64 r_reg_set_bvalue(RReg *reg, RRegItem *item, const char *str); R_API int r_reg_set_pvalue(RReg *reg, RRegItem *item, ut64 value, int packidx); /* byte arena */ diff --git a/libr/include/r_util.h b/libr/include/r_util.h index ec618df0bf..83f7cae906 100644 --- a/libr/include/r_util.h +++ b/libr/include/r_util.h @@ -382,6 +382,7 @@ R_API int r_str_split(char *str, char ch); R_API char* r_str_replace(char *str, const char *key, const char *val, int g); #define r_str_cpy(x,y) memmove(x,y,strlen(y)+1); R_API int r_str_bits (char *strout, const ut8 *buf, int len, const char *bitz); +R_API ut64 r_str_bits_from_string(const char *buf, const char *bitz); R_API int r_str_rwx(const char *str); R_API int r_str_replace_char (char *s, int a, int b); R_API const char *r_str_rwx_i(int rwx); diff --git a/libr/reg/value.c b/libr/reg/value.c index e1d0a13581..ad127ccf0b 100644 --- a/libr/reg/value.c +++ b/libr/reg/value.c @@ -122,6 +122,17 @@ R_API int r_reg_set_value(RReg *reg, RRegItem *item, ut64 value) { return R_FALSE; } +R_API ut64 r_reg_set_bvalue(RReg *reg, RRegItem *item, const char *str) { + ut64 num; + if (!item->flags) + return UT64_MAX; + num = r_str_bits_from_string (str, item->flags); + if (num == UT64_MAX) + r_reg_set_value (reg, item, r_num_math (NULL, str)); + else r_reg_set_value (reg, item, num); + return num; +} + R_API char *r_reg_get_bvalue(RReg *reg, RRegItem *item) { char *out; ut64 num; diff --git a/libr/util/str.c b/libr/util/str.c index b32052e564..ef3c8cd273 100644 --- a/libr/util/str.c +++ b/libr/util/str.c @@ -118,28 +118,21 @@ R_API int r_str_bits (char *strout, const ut8 *buf, int len, const char *bitz) { * function: r_str_bits_from_num * */ -#if 0 -R_API ut64 r_str_bits_from_string(const char *buf, int len, const char *bitz) { +R_API ut64 r_str_bits_from_string(const char *buf, const char *bitz) { + ut64 out = 0LL; /* return the numberic value associated to a string (rflags) */ - int i, j; - if (bitz) { - for (i=j=0; i0 && (i%8)==0) - buf++; - if (*buf&(1<<(i%8))) - strout[j++] = toupper (bitz[i]); - } - } else { - for (i=j=0; i0 && (i%8)==0) - buf++; - strout[j++] = (*buf&(1<<(7-(i%8))))?'1':'0'; + for (; *buf; buf++) { + char *ch = strchr (bitz, toupper (*buf)); + if (!ch) ch = strchr (bitz, tolower (*buf)); + if (ch) { + int bit = (int)(size_t)(ch - bitz); + out |= (ut64)(1LL << bit); + } else { + return UT64_MAX; } } - strout[j] = 0; - return j; + return out; } -#endif /* int c; ret = hex2int(&c, 'c'); */ static int hex2int (ut8 *val, ut8 c) {