/*
 * Turns the given little endian decimal string into a long long. Throws an error if the
 * string contains non-digits or is larger or smaller than the allowable range of long long.
 */
long long convert_dec_string_of_size_to_long_long(char *orig_string, int /*size*/)
{
	if (!is_decimal_string(orig_string))
		error_message(PARSE_ERROR, -1, -1, "Invalid decimal number: %s.\n", orig_string);

	errno = 0;
	long long number = strtoll(orig_string, NULL, 10);
	if (errno == ERANGE)
		error_message(PARSE_ERROR, -1, -1, "This suspected decimal number (%s) is too long for Odin\n", orig_string);

	return number;
}
int is_string_of_radix(char *string, int radix)
{
	if (radix == 16)
		return is_hex_string(string);
	else if (radix == 10)
		return is_decimal_string(string);
	else if (radix == 8)
		return is_octal_string(string);
	else if (radix == 2)
		return is_binary_string(string);
	else
		return FALSE;
}
Ejemplo n.º 3
0
/*
 * Turns the given little endian decimal string into a long long. Throws an error if the
 * string contains non-digits or is larger or smaller than the allowable range of long long.
 */
long long convert_dec_string_of_size_to_long_long(char *orig_string, int size)
{
	if (!is_decimal_string(orig_string))
		error_message(PARSE_ERROR, -1, -1, "Invalid decimal number: %s.\n", orig_string);

	#ifdef LLONG_MAX
	long long number = strtoll(orig_string, NULL, 10);
	if (number == LLONG_MAX || number == LLONG_MIN)
		error_message(PARSE_ERROR, -1, -1, "This suspected decimal number (%s) is too long for Odin\n", orig_string);
	#else
	long long number = strtol(orig_string, NULL, 10);
	if (number == LONG_MAX || number == LONG_MIN)
		error_message(PARSE_ERROR, -1, -1, "This suspected decimal number (%s) is too long for Odin\n", orig_string);
	#endif

	return number;
}