Exemplo n.º 1
0
Arquivo: cmd.c Projeto: radare/ired
static int cmd_help(char *arg) {
	if(*arg) {
		ut64 ret = r_num_calc (NULL, arg, NULL);
		printf("0x%"LLF"x %"LLF"d 0%"LLF"o\n", ret, ret, ret);
	} else printf(
		"s[+-addr]     seek to relative or absolute address\n"
		"b[+-size]     change block size\n"
		"w[hex|\"str\"]  write hexpair or string\n"
		"/[hex|\"str\"]  search hexpair or string\n"
		"x[size]       hexdump\n"
		"X[size]       hexpair dump\n"
		"p[fmt]        print formatted current block ('p' for help)\n"
		"d[size]       disasemble\n"
		"r[+-[num]]    truncate or -remove N bytes\n"
		".[file]       interpret file\n"
		"<[file]       load file in current seek\n"
		">[file]       dump current block to file\n"
		"!cmd          run shell command\n"
		"?expr         calculate numeric expression\n"
		"q             quit\n");
	return 1;
}
Exemplo n.º 2
0
R_API ut64 r_num_math(RNum *num, const char *str) {
#if R_NUM_USE_CALC
	ut64 ret;
	const char *err = NULL;
	if (!str) return 0LL;
	//if (!str || !*str) return 0LL;
	ret = r_num_calc (num, str, &err);
	if (err) eprintf ("r_num_calc error: (%s) in (%s)\n", err, str);
	else if (num) num->value = ret;
	if (num != NULL)
		num->value = ret;
	return ret;
#else
	ut64 ret = 0LL;
	char op = '+';
	int len;
	char *p, *s, *os;
	char *group;
	if (!str) return 0LL;

	len = strlen (str)+1;
	os = malloc (len+1);

	s = os;
	memcpy (s, str, len);
	for (; *s==' '; s++);
	p = s;

	do {
		group = strchr (p, '(');
		if (group) {
			group[0] = '\0';
			ret = r_num_op (op, ret, r_num_math_internal (num, p));
			for (; p<group; p+=1) {
				switch (*p) {
				case '+':
				case '-':
				case '*':
				case '/':
				case '&':
				case '|':
				case '^':
					op = *p;
					break;
				}
			}
			group[0] = '(';
			p = group+1;
			if (r_str_delta (p, '(', ')')<0) {
				char *p2 = strchr (p, '(');
				if (p2 != NULL) {
					*p2 = '\0';
					ret = r_num_op (op, ret, r_num_math_internal (num, p));
					ret = r_num_op (op, ret, r_num_math (num, p2+1));
					p = p2+1; 
					continue;
				} else eprintf ("WTF!\n");
			} else ret = r_num_op (op, ret, r_num_math_internal (num, p));
		} else ret = r_num_op (op, ret, r_num_math_internal (num, p));
	} while (0);

	if (num != NULL)
		num->value = ret;
	free (os);
	return ret;
#endif
}