mirror of
https://github.com/radareorg/radare2.git
synced 2024-10-07 02:23:58 +00:00
Implement RBin.attr(str2bits) ##bin
This commit is contained in:
parent
aac8f3306b
commit
bb575f247d
@ -1690,8 +1690,44 @@ R_API char *r_bin_attr_tostring(ut64 attr, bool singlechar) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO : not implemented yet
|
// TODO : not implemented yet
|
||||||
|
#if R2_USE_NEW_ABI
|
||||||
|
R_API ut64 r_bin_attr_fromstring(const char *s, bool compact) {
|
||||||
|
#else
|
||||||
R_API ut64 r_bin_attr_fromstring(const char *s) {
|
R_API ut64 r_bin_attr_fromstring(const char *s) {
|
||||||
return 0ULL;
|
const bool compact = false;
|
||||||
|
#endif
|
||||||
|
int i;
|
||||||
|
ut64 bits = 0LL;
|
||||||
|
const char *word;
|
||||||
|
RListIter *iter;
|
||||||
|
if (compact) {
|
||||||
|
const char *w = s;
|
||||||
|
while (*w) {
|
||||||
|
for (i = 0; i < 64; i++) {
|
||||||
|
const char *bn = attr_bit_name (i, true);
|
||||||
|
if (bn && *w == *bn) {
|
||||||
|
bits |= (1 << i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
w++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
char *a = strdup (s);
|
||||||
|
RList *words = r_str_split_list (a, " ", 0);
|
||||||
|
r_list_foreach (words, iter, word) {
|
||||||
|
for (i = 0; i < 64; i++) {
|
||||||
|
const char *bn = attr_bit_name (i, false);
|
||||||
|
if (!strcmp (bn, word)) {
|
||||||
|
bits |= (1 << i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
r_list_free (words);
|
||||||
|
free (a);
|
||||||
|
}
|
||||||
|
return bits;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if R2_USE_NEW_ABI
|
#if R2_USE_NEW_ABI
|
||||||
|
@ -917,7 +917,11 @@ R_API void r_bin_name_filtered(RBinName *bn, const char *fname);
|
|||||||
R_API void r_bin_name_free(RBinName *bn);
|
R_API void r_bin_name_free(RBinName *bn);
|
||||||
|
|
||||||
R_API char *r_bin_attr_tostring(ut64 attr, bool singlechar);
|
R_API char *r_bin_attr_tostring(ut64 attr, bool singlechar);
|
||||||
|
#if R2_USE_NEW_ABI
|
||||||
|
R_API ut64 r_bin_attr_fromstring(const char *s, bool compact);
|
||||||
|
#else
|
||||||
R_API ut64 r_bin_attr_fromstring(const char *s);
|
R_API ut64 r_bin_attr_fromstring(const char *s);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* filter.c */
|
/* filter.c */
|
||||||
typedef struct HtSU_t HtSU;
|
typedef struct HtSU_t HtSU;
|
||||||
|
@ -3437,11 +3437,11 @@ R_API RVecStringSlice *r_str_split_vec(const char *str, const char *c, int n) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Splits the string <str> by string <c> and returns the result in a list.
|
// Splits the string <str> by string <c> and returns the result in a list.
|
||||||
// XXX should take const char * as argument!!
|
// R2_600 - char *arg must be const!!
|
||||||
R_API RList *r_str_split_list(char *str, const char *c, int n) {
|
R_API RList *r_str_split_list(char *str, const char *c, int n) {
|
||||||
r_return_val_if_fail (str && c, NULL);
|
r_return_val_if_fail (str && c, NULL);
|
||||||
RList *lst = r_list_newf (NULL);
|
RList *lst = r_list_newf (NULL);
|
||||||
char *aux = str; // XXX should be an strdup
|
char *aux = str; // R2_600 - XXX should be an strdup
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char *e = aux;
|
char *e = aux;
|
||||||
const size_t clen = strlen (c);
|
const size_t clen = strlen (c);
|
||||||
|
Loading…
Reference in New Issue
Block a user