Implement RBin.attr(str2bits) ##bin

This commit is contained in:
pancake 2024-08-04 12:39:35 +02:00 committed by GitHub
parent aac8f3306b
commit bb575f247d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 43 additions and 3 deletions

View File

@ -1690,8 +1690,44 @@ R_API char *r_bin_attr_tostring(ut64 attr, bool singlechar) {
}
// 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) {
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

View File

@ -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 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);
#endif
/* filter.c */
typedef struct HtSU_t HtSU;

View File

@ -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.
// 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_return_val_if_fail (str && c, 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;
char *e = aux;
const size_t clen = strlen (c);