7 #define RZ_NUM_USE_CALC 1
22 return (
p[0] ==
'0' &&
p[1] ==
'x');
27 #if HAVE_ARC4RANDOM_UNIFORM
36 #if HAVE_ARC4RANDOM_UNIFORM
37 return (
int)arc4random_uniform(
mod);
48 static bool rand_initialized =
false;
49 if (!rand_initialized) {
51 rand_initialized =
true;
82 num->cb_from_value = cb2;
91 #define KB (1ULL << 10)
92 #define MB (1ULL << 20)
93 #define GB (1ULL << 30)
94 #define TB (1ULL << 40)
95 #define PB (1ULL << 50)
96 #define EB (1ULL << 60)
118 fnum = (
long double)
num;
122 }
else if (
num >=
PB) {
125 }
else if (
num >=
TB) {
128 }
else if (
num >=
GB) {
131 }
else if (
num >=
MB) {
134 }
else if (
num >=
KB) {
140 fmt_str = ((double)ceill(fnum) == (double)fnum)
148 if (
num->cb_from_value) {
165 num->nc.calc_err = err_str;
178 if (
num && !
num->nc.under_calc) {
184 for (; *
str ==
' ';) {
190 if (!strncmp(
str,
"1u", 2)) {
194 switch (atoi(
str + 2)) {
202 if (
num &&
num->callback) {
211 if (
str[0] ==
'\'' &&
str[2] ==
'\'') {
217 if (
len > 3 &&
str[4] ==
':') {
218 if (sscanf(
str,
"%04x", &
s) == 1) {
219 if (sscanf(
str + 5,
"%04x", &
a) == 1) {
220 return (
ut64)((
s << 4) +
a);
223 }
else if (
len > 6 &&
str[6] ==
':') {
224 if (sscanf(
str,
"0x%04x:0x%04x", &
s, &
a) == 2) {
225 return (
ut64)((
s << 4) +
a);
227 if (sscanf(
str,
"0x%04x:%04x", &
s, &
a) == 2) {
228 return (
ut64)((
s << 4) +
a);
231 if (
str[0] ==
'0' &&
str[1] ==
'b') {
233 for (j = 0,
i = strlen(
str) - 1;
i > 0;
i--, j++) {
236 }
else if (
str[
i] !=
'0') {
241 }
else if (
str[0] ==
'\'') {
244 }
else if (!strncmp(
str,
"0xff..", 6) || !strncmp(
str,
"0xFF..", 6)) {
247 }
else if (!strncmp(
str,
"0o", 2)) {
248 if (sscanf(
str + 2,
"%" PFMT64o, &ret) != 1) {
251 }
else if (!strncmp(
str,
"0xf..", 5) || !strncmp(
str,
"0xF..", 5)) {
254 const char *lodash = strchr(
str + 2,
'_');
262 ret = strtoull(
s,
NULL, 16);
267 ret = strtoull(
str + 2,
NULL, 16);
271 error(
num,
"number won't fit into 64 bits");
275 int len_num =
len > 0 ?
len - 1 : 0;
280 int chars_read = len_num;
281 bool zero_read =
false;
283 if (*
str ==
'0' &&
IS_DIGIT(*(
str + 1)) && lch !=
'b' && lch !=
'h' && lch !=
'H') {
290 if (!sscanf(
str,
"%" PFMT64x "%n", &ret, &chars_read) || chars_read != len_num) {
295 if (!sscanf(
str,
"%" PFMT64o "%n", &ret, &chars_read) || chars_read != len_num) {
302 if (strlen(
str) <= 65) {
303 for (j = 0,
i = strlen(
str) - 2;
i >= 0;
i--, j++) {
306 }
else if (
str[
i] !=
'0') {
316 if (!
ok || !len_num) {
317 error(
num,
"invalid binary number");
324 for (
i = strlen(
str) - 2;
i >= 0;
i--) {
329 ret +=
x * (
str[
i] -
'0');
332 if (!
ok || !len_num) {
333 error(
num,
"invalid ternary number");
338 if (strchr(
str,
'.')) {
340 if (sscanf(
str,
"%lf%n", &
d, &chars_read)) {
346 if (sscanf(
str,
"%" PFMT64d "%n", &ret, &chars_read)) {
352 if (zero_read || chars_read != len_num) {
353 error(
num,
"invalid kilobyte number");
358 if (strchr(
str,
'.')) {
360 if (sscanf(
str,
"%lf%n", &
d, &chars_read)) {
366 if (sscanf(
str,
"%" PFMT64d "%n", &ret, &chars_read)) {
372 if (zero_read || chars_read != len_num) {
373 error(
num,
"invalid megabyte number");
378 if (strchr(
str,
'.')) {
380 if (sscanf(
str,
"%lf%n", &
d, &chars_read)) {
386 if (sscanf(
str,
"%" PFMT64d "%n", &ret, &chars_read)) {
392 if (zero_read || chars_read != len_num) {
393 error(
num,
"invalid gigabyte number");
401 ret = _strtoui64 (
str, &endptr, 10);
405 ret = strtoull(
str, &endptr, 10);
407 error(
num,
"number won't fit into 64 bits");
409 if (!
IS_DIGIT(*
str) || (*endptr && *endptr != lch)) {
424 case '+':
return a +
b;
425 case '-':
return a -
b;
426 case '*':
return a *
b;
430 return b ?
a /
b : 0;
431 case '&':
return a &
b;
432 case '|':
return a |
b;
433 case '^':
return a ^
b;
442 for (
i = 0;
s[
i];
i++) {
489 for (; *
s ==
' ';
s++)
494 group = strchr(
p,
'(');
497 ret = rz_num_op(
op, ret, rz_num_math_internal(
num,
p));
498 for (;
p < group;
p += 1) {
507 char *p2 = strchr(
p,
'(');
510 ret = rz_num_op(
op, ret, rz_num_math_internal(
num,
p));
515 eprintf(
"something really bad has happened! can't find '('\n");
517 ret = rz_num_op(
op, ret, rz_num_math_internal(
num,
p));
520 ret = rz_num_op(
op, ret, rz_num_math_internal(
num,
p));
538 (void)sscanf(
str,
"%lf", &
d);
547 }
else if (
num & 0xff000000) {
549 }
else if (
num & 0xff0000) {
551 }
else if (
num & 0xff00) {
553 }
else if (
num & 0xff) {
561 char bit = ((
num >> (
size -
i - 1)) & 1) ?
'1' :
'0';
562 if (hasbit ||
bit ==
'1') {
565 if (!hasbit &&
bit ==
'1') {
571 out[realsize++] =
'0';
573 out[realsize] =
'\0';
584 out[
i] = (char)(
'0' +
num % 3);
597 if (sectorsize < 1) {
613 lgt = strchr(
p,
'<');
629 lgt = strchr(
p,
'>');
645 lgt = strchr(
p,
'=');
646 if (lgt && lgt >
p) {
657 lgt = strstr(
p,
"==");
678 return !(
value == 0 && input_value && *input_value !=
'0') || !(
value == 0 && input_value && *input_value !=
'@');
686 #define NIBBLE_TO_HEX(n) (((n)&0xf) > 9 ? 'a' + ((n)&0xf) - 10 : '0' + ((n)&0xf))
688 const char escape_map[] =
"abtnvfr";
689 if (
byte >= 7 &&
byte <= 13) {
691 *(
dst++) = escape_map[
byte - 7];
707 int stri, ret = 0,
off = 0;
712 char ch = (
num & 0xff);
713 if (ch >= 32 && ch < 127) {
729 if (!printable_only) {
740 return !(
value == 0 && *input_value !=
'0');
748 int sz = (
sizeof(
n) << 1) - 1;
749 int s = (sz -
i) * 4;
750 return (
n >>
s) & 0xf;
757 for (
i = 0;
i < 16;
i++) {
761 if (
i == 0 && !iseq) {
781 while (*
hex && (*
hex ==
' ' || *
hex ==
'.')) {
805 while (*
hex && (*
hex ==
' ' || *
hex ==
'.')) {
808 int i = strlen(
hex) * 4;
840 for (
i = 0;
i <
len;
i++) {
849 return c ==
'/' ||
c ==
'+' ||
c ==
'-' ||
c ==
'*' ||
850 c ==
'%' ||
c ==
'&' ||
c ==
'^' ||
c ==
'|';
855 int i = 0,
len = 0, st;
860 while (
str[
i] !=
'\0') {
873 while (
str[
i] !=
'\0' &&
str[
i] ==
' ') {
883 while (
str[
i] !=
'\0' &&
str[
i] ==
' ') {
895 const int len = strlen(
str);
const lzma_allocator const uint8_t size_t uint8_t * out
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
RZ_API void Ht_() free(HtName_(Ht) *ht)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static void list(RzEgg *egg)
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
RZ_API ut32 rz_list_length(RZ_NONNULL const RzList *list)
Returns the length of the list.
RZ_API RZ_OWN void * rz_list_pop_head(RZ_NONNULL RzList *list)
Removes and returns the first element of the list.
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
void * malloc(size_t size)
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz fd_set fd_set fd_set struct timeval static timeout const char char static bufsiz const char static swapflags void static offset const char static length static mode static who const char struct statfs static buf unsigned unsigned num
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
static const char hex[16]
#define rz_return_val_if_fail(expr, val)
ut64(* RzNumCallback)(struct rz_num_t *self, const char *str, int *ok)
RZ_API ut64 rz_num_calc(RzNum *num, const char *str, const char **err)
const char *(* RzNumCallback2)(struct rz_num_t *self, ut64, int *ok)
RZ_API int rz_str_delta(char *p, char a, char b)
RZ_API bool rz_str_startswith(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string starts with a specifc sequence of characters (case sensitive)
RZ_API int rz_str_replace_char(char *s, int a, int b)
RZ_API void rz_str_reverse(char *str)
RZ_API ut64 rz_time_now(void)
Returns the current time in microseconds.
#define RZ_BETWEEN(x, y, z)
static struct sockaddr static addrlen static backlog const void msg
RZ_API RzList * rz_num_str_split_list(char *str)
static ut64 rz_num_tailff(RzNum *num, const char *hex)
RZ_API ut64 rz_num_get(RzNum *num, const char *str)
RZ_API void rz_num_minmax_swap(ut64 *a, ut64 *b)
RZ_API bool rz_num_is_op(const char c)
static int escape_char(char *dst, char byte)
RZ_API ut64 rz_num_tail(RzNum *num, ut64 addr, const char *hex)
RZ_API ut64 rz_get_input_num_value(RzNum *num, const char *str)
RZ_API bool rz_is_valid_input_num_value(RzNum *num, const char *input_value)
RZ_API double rz_num_get_float(RzNum *num, const char *str)
RZ_API int rz_num_str_len(const char *str)
RZ_API RzNum * rz_num_new(RzNumCallback cb, RzNumCallback2 cb2, void *ptr)
RZ_API void rz_num_minmax_swap_i(int *a, int *b)
static ut64 __nth_nibble(ut64 n, ut32 i)
RZ_API ut64 rz_num_tail_base(RzNum *num, ut64 addr, ut64 off)
RZ_API char * rz_num_units(char *buf, size_t len, ut64 num)
RZ_API int rz_num_to_bits(char *out, ut64 num)
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
RZ_API int rz_num_is_valid_input(RzNum *num, const char *input_value)
RZ_API int rz_num_conditional(RzNum *num, const char *str)
RZ_API int rz_num_to_trits(char *out, ut64 num)
RZ_API int rz_num_str_split(char *str)
RZ_API double rz_num_cos(double a)
RZ_API ut64 rz_num_get_input_value(RzNum *num, const char *input_value)
RZ_API void * rz_num_dup(ut64 n)
RZ_API int rz_num_between(RzNum *num, const char *input_value)
RZ_API size_t rz_num_base_of_string(RzNum *num, RZ_NONNULL const char *str)
Convert the base suffix to the numeric value.
RZ_API char * rz_num_as_string(RzNum *___, ut64 n, bool printable_only)
static int rz_rand(int mod)
RZ_API int rz_num_rand(int max)
RZ_API void rz_num_free(RzNum *num)
RZ_API void rz_num_irand(void)
RZ_API double rz_num_sin(double a)
static void error(RzNum *num, const char *err_str)
static void rz_srand(int seed)
RZ_API const char * rz_num_get_name(RzNum *num, ut64 n)
RZ_API bool rz_num_is_hex_prefix(const char *p)
Checks if the first two chars of p equal "0x".
RZ_API ut64 rz_num_chs(int cylinder, int head, int sector, int sectorsize)
RZ_API int rz_num_is_float(RzNum *num, const char *str)
ut64(WINAPI *w32_GetEnabledXStateFeatures)()