Use stdint types for ut64 and friends (#6276)

* Use `stdint` types for `ut64` and friends
* Use `inttypes.h` format specifiers
This commit is contained in:
Khairul Azhar Kasmiran 2026-04-22 21:43:04 +08:00 committed by GitHub
parent a74ed707ea
commit 3204f0c405
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 44 additions and 31 deletions

View file

@ -299,7 +299,7 @@ RZ_IPI int rz_arm_cs_analysis_op_32_esil(RzAnalysis *a, RzAnalysisOp *op, ut64 a
case ARM_INS_BXJ: case ARM_INS_BXJ:
case ARM_INS_B: case ARM_INS_B:
if (ISREG(0) && REGID(0) == ARM_REG_PC) { if (ISREG(0) && REGID(0) == ARM_REG_PC) {
rz_strbuf_appendf(&op->esil, "0x%" PFMT64x ",pc,=", (addr & ~3LL) + pcdelta); rz_strbuf_appendf(&op->esil, "0x%" PFMT64x ",pc,=", (addr & ~(ut64)3) + pcdelta);
} else { } else {
if (ISIMM(0)) { if (ISIMM(0)) {
rz_strbuf_appendf(&op->esil, "%s,pc,=", ARG(0)); rz_strbuf_appendf(&op->esil, "%s,pc,=", ARG(0));

View file

@ -33,7 +33,7 @@
DEF_READ_GENERIC(1, 8, " 0x%X") DEF_READ_GENERIC(1, 8, " 0x%X")
DEF_READ_GENERIC(2, 16, " 0x%X") DEF_READ_GENERIC(2, 16, " 0x%X")
DEF_READ_GENERIC(4, 32, " 0x%X") DEF_READ_GENERIC(4, 32, " 0x%X")
DEF_READ_GENERIC(8, 64, " 0x%llX") DEF_READ_GENERIC(8, 64, " 0x%" PFMT64X)
DEF_READ_GENERIC(4, _float, " %f") DEF_READ_GENERIC(4, _float, " %f")
DEF_READ_GENERIC(8, _double, " %f") DEF_READ_GENERIC(8, _double, " %f")

View file

@ -993,7 +993,7 @@ static void anop_esil(RzAnalysis *a, RzAnalysisOp *op, const ut8 *buf, int len,
esilprintf(op, esilprintf(op,
"%s,%s,==,$z,zf,:=,%u,$b,cf,:=,$p,pf,:=,%u,$s,sf,:=," "%s,%s,==,$z,zf,:=,%u,$b,cf,:=,$p,pf,:=,%u,$s,sf,:=,"
"%s,0x%" PFMT64x ",-,!,%u,$o,^,of,:=,3,$b,af,:=", "%s,0x%" PFMT64x ",-,!,%u,$o,^,of,:=,3,$b,af,:=",
src, dst, bitsize, bitsize - 1, src, 1ULL << (bitsize - 1), bitsize - 1); src, dst, bitsize, bitsize - 1, src, (ut64)1 << (bitsize - 1), bitsize - 1);
} else { } else {
const char *rsrc = ZydisRegisterGetString(INSOP(1).mem.base); const char *rsrc = ZydisRegisterGetString(INSOP(1).mem.base);
const char *rdst = ZydisRegisterGetString(INSOP(0).mem.base); const char *rdst = ZydisRegisterGetString(INSOP(0).mem.base);
@ -1001,7 +1001,7 @@ static void anop_esil(RzAnalysis *a, RzAnalysisOp *op, const ut8 *buf, int len,
esilprintf(op, esilprintf(op,
"%s,%s,==,$z,zf,:=,%u,$b,cf,:=,$p,pf,:=,%u,$s,sf,:=,%s,0x%" PFMT64x "," "%s,%s,==,$z,zf,:=,%u,$b,cf,:=,$p,pf,:=,%u,$s,sf,:=,%s,0x%" PFMT64x ","
"-,!,%u,$o,^,of,:=,3,$b,af,:=,df,?{,%" PFMT32d ",%s,-=,%" PFMT32d ",%s,-=,}{,%" PFMT32d ",%s,+=,%" PFMT32d ",%s,+=,}", "-,!,%u,$o,^,of,:=,3,$b,af,:=,df,?{,%" PFMT32d ",%s,-=,%" PFMT32d ",%s,-=,}{,%" PFMT32d ",%s,+=,%" PFMT32d ",%s,+=,}",
src, dst, bitsize, bitsize - 1, src, 1ULL << (bitsize - 1), bitsize - 1, src, dst, bitsize, bitsize - 1, src, (ut64)1 << (bitsize - 1), bitsize - 1,
width, rsrc, width, rdst, width, rsrc, width, rdst); width, rsrc, width, rdst, width, rsrc, width, rdst);
} }
} break; } break;
@ -1472,7 +1472,7 @@ static void anop_esil(RzAnalysis *a, RzAnalysisOp *op, const ut8 *buf, int len,
// We use $b rather than $c here as the carry flag really // We use $b rather than $c here as the carry flag really
// represents a "borrow" // represents a "borrow"
esilprintf(op, "%s,%s,%s,0x%" PFMT64x ",-,!,%u,$o,^,of,:=,%u,$s,sf,:=,$z,zf,:=,$p,pf,:=,%u,$b,cf,:=,3,$b,af,:=", esilprintf(op, "%s,%s,%s,0x%" PFMT64x ",-,!,%u,$o,^,of,:=,%u,$s,sf,:=,$z,zf,:=,$p,pf,:=,%u,$b,cf,:=,3,$b,af,:=",
src, dst, src, 1ULL << (bitsize - 1), bitsize - 1, bitsize - 1, bitsize); src, dst, src, (ut64)1 << (bitsize - 1), bitsize - 1, bitsize - 1, bitsize);
} break; } break;
case X86_INS_SBB: case X86_INS_SBB:
// dst = dst - (src + cf) // dst = dst - (src + cf)

View file

@ -2539,7 +2539,7 @@ static void patch_reloc_riscv(RZ_INOUT RzBuffer *buf_patched, const ut64 patch_a
ut8 old_val = 0; ut8 old_val = 0;
rz_buf_read_ble8_at(buf_patched, patch_addr, &old_val, big_endian); rz_buf_read_ble8_at(buf_patched, patch_addr, &old_val, big_endian);
ut64 result = ((ut64)old_val) + S + A; ut64 result = ((ut64)old_val) + S + A;
unsigned long long addr = patch_addr; ut64 addr = patch_addr;
bool success = rz_buf_write_ble8_offset(buf_patched, &addr, (ut8)result, big_endian); bool success = rz_buf_write_ble8_offset(buf_patched, &addr, (ut8)result, big_endian);
RISCV_CHECK_SUCCESS_RET_IF_FAIL(success, "R_RISCV_ADD8"); RISCV_CHECK_SUCCESS_RET_IF_FAIL(success, "R_RISCV_ADD8");
break; break;
@ -2580,7 +2580,7 @@ static void patch_reloc_riscv(RZ_INOUT RzBuffer *buf_patched, const ut64 patch_a
bool success = rz_buf_read_ble8_at(buf_patched, patch_addr, &old_val, big_endian); bool success = rz_buf_read_ble8_at(buf_patched, patch_addr, &old_val, big_endian);
RISCV_CHECK_SUCCESS_RET_IF_FAIL(success, "R_RISCV_SUB8 [r]"); RISCV_CHECK_SUCCESS_RET_IF_FAIL(success, "R_RISCV_SUB8 [r]");
ut64 result = ((ut64)old_val) - S - A; ut64 result = ((ut64)old_val) - S - A;
unsigned long long addr = patch_addr; ut64 addr = patch_addr;
success = rz_buf_write_ble8_offset(buf_patched, &addr, (ut8)result, big_endian); success = rz_buf_write_ble8_offset(buf_patched, &addr, (ut8)result, big_endian);
RISCV_CHECK_SUCCESS_RET_IF_FAIL(success, "R_RISCV_SUB8 [w]"); RISCV_CHECK_SUCCESS_RET_IF_FAIL(success, "R_RISCV_SUB8 [w]");
break; break;
@ -2618,7 +2618,7 @@ static void patch_reloc_riscv(RZ_INOUT RzBuffer *buf_patched, const ut64 patch_a
case R_RISCV_SET8: { case R_RISCV_SET8: {
val = S + A; val = S + A;
unsigned long long addr = patch_addr; ut64 addr = patch_addr;
bool success = rz_buf_write_ble8_offset(buf_patched, &addr, (ut8)val, big_endian); bool success = rz_buf_write_ble8_offset(buf_patched, &addr, (ut8)val, big_endian);
RISCV_CHECK_SUCCESS_RET_IF_FAIL(success, "R_RISCV_SET8"); RISCV_CHECK_SUCCESS_RET_IF_FAIL(success, "R_RISCV_SET8");
break; break;

View file

@ -69,7 +69,7 @@ static const RzRegItem *parse_register(const RzCore *core, const char *str, ut64
return rz_reg_get(areg, reg, RZ_REG_TYPE_ANY); return rz_reg_get(areg, reg, RZ_REG_TYPE_ANY);
} }
static bool parse_constant(const char *str, RZ_NONNULL ut64 *idx, unsigned long long *value) { static bool parse_constant(const char *str, RZ_NONNULL ut64 *idx, ut64 *value) {
rz_return_val_if_fail(idx, false); rz_return_val_if_fail(idx, false);
int neg = 0; int neg = 0;
int len = strlen(str); int len = strlen(str);

View file

@ -508,11 +508,27 @@ static inline void *rz_new_copy(int size, const void *data) {
x = NULL; \ x = NULL; \
} }
#if HAVE_HEADER_INTTYPES_H
#define PFMT64x PRIx64
#define PFMT64X PRIX64
#define PFMT64d PRId64
#define PFMT64u PRIu64
#define PFMT64o PRIo64
#elif __WINDOWS__
#define PFMT64x "I64x"
#define PFMT64X "I64X"
#define PFMT64d "I64d"
#define PFMT64u "I64u"
#define PFMT64o "I64o"
#else
#define PFMT64x "lx"
#define PFMT64X "lX"
#define PFMT64d "ld"
#define PFMT64u "lu"
#define PFMT64o "lo"
#endif
#if __WINDOWS__ #if __WINDOWS__
#define PFMT64x "I64x"
#define PFMT64d "I64d"
#define PFMT64u "I64u"
#define PFMT64o "I64o"
#define PFMTSZx "Ix" #define PFMTSZx "Ix"
#define PFMTSZd "Id" #define PFMTSZd "Id"
#define PFMTSZu "Iu" #define PFMTSZu "Iu"
@ -521,10 +537,6 @@ static inline void *rz_new_copy(int size, const void *data) {
#define LDBLFMTf "f" #define LDBLFMTf "f"
#define HHXFMT "x" #define HHXFMT "x"
#else #else
#define PFMT64x "llx"
#define PFMT64d "lld"
#define PFMT64u "llu"
#define PFMT64o "llo"
#define PFMTSZx "zx" #define PFMTSZx "zx"
#define PFMTSZd "zd" #define PFMTSZd "zd"
#define PFMTSZu "zu" #define PFMTSZu "zu"

View file

@ -4,6 +4,7 @@
#include <ctype.h> #include <ctype.h>
#include <sys/types.h> #include <sys/types.h>
#include <limits.h> #include <limits.h>
#include <stdint.h>
#if defined(_MSC_VER) #if defined(_MSC_VER)
// required to forbid the declaration // required to forbid the declaration
@ -19,14 +20,14 @@
#endif #endif
#define cut8 const unsigned char #define cut8 const unsigned char
#define ut64 unsigned long long #define ut64 uint64_t
#define st64 long long #define st64 int64_t
#define ut32 unsigned int #define ut32 uint32_t
#define st32 int #define st32 int32_t
#define ut16 unsigned short #define ut16 uint16_t
#define st16 short #define st16 int16_t
#define ut8 unsigned char #define ut8 uint8_t
#define st8 signed char #define st8 int8_t
#define utptr uintptr_t #define utptr uintptr_t
#define boolt int #define boolt int

View file

@ -33,8 +33,8 @@ static bool set_chunk_size(RZ_NONNULL RzSearchOpt *opt, ut64 chunk_size) {
rz_return_val_if_fail(opt, false); rz_return_val_if_fail(opt, false);
if (chunk_size < RZ_SEARCH_MIN_CHUNK_SIZE || chunk_size > RZ_SEARCH_MAX_CHUNK_SIZE) { if (chunk_size < RZ_SEARCH_MIN_CHUNK_SIZE || chunk_size > RZ_SEARCH_MAX_CHUNK_SIZE) {
RZ_LOG_ERROR("search: Chunk size is not in range of %#" PFMT64x "-%#" PFMT64x " bytes.\n", RZ_LOG_ERROR("search: Chunk size is not in range of %#" PFMT64x "-%#" PFMT64x " bytes.\n",
RZ_SEARCH_MIN_CHUNK_SIZE, (ut64)RZ_SEARCH_MIN_CHUNK_SIZE,
RZ_SEARCH_MAX_CHUNK_SIZE); (ut64)RZ_SEARCH_MAX_CHUNK_SIZE);
return false; return false;
} }
opt->chunk_size = chunk_size; opt->chunk_size = chunk_size;

View file

@ -648,7 +648,7 @@ static bool perform_sanity_checks(
} }
if (opt->chunk_size < RZ_SEARCH_MIN_CHUNK_SIZE) { if (opt->chunk_size < RZ_SEARCH_MIN_CHUNK_SIZE) {
RZ_LOG_ERROR("search: cannot search when buffer size is less than %#" PFMT64x " bytes.\n", RZ_SEARCH_MIN_CHUNK_SIZE); RZ_LOG_ERROR("search: cannot search when buffer size is less than %#" PFMT64x " bytes.\n", (ut64)RZ_SEARCH_MIN_CHUNK_SIZE);
return false; return false;
} }

View file

@ -892,7 +892,7 @@ RZ_API RZ_OWN char *rz_print_hexdump_str(RZ_NONNULL RzPrint *p, ut64 addr, RZ_NO
oPrintValue = printValue; oPrintValue = printValue;
j += step - 1; j += step - 1;
} else if (base == -8) { } else if (base == -8) {
long long w = rz_read_ble64(buf + j, p->big_endian); st64 w = rz_read_ble64(buf + j, p->big_endian);
print_cursor_l(sb, p, j, 8); print_cursor_l(sb, p, j, 8);
rz_strbuf_appendf(sb, "%23" PFMT64d " ", w); rz_strbuf_appendf(sb, "%23" PFMT64d " ", w);
print_cursor_r(sb, p, j, 8); print_cursor_r(sb, p, j, 8);

View file

@ -1442,7 +1442,7 @@ bool test_rz_buf_negative(bool use_slice) {
int all_tests() { int all_tests() {
time_t seed = time(0); time_t seed = time(0);
printf("Jamie Seed: %" PFMT64u "\n", (unsigned long long)seed); printf("Jamie Seed: %" PFMT64u "\n", (ut64)seed);
srand(seed); srand(seed);
mu_run_test(test_rz_buf_file); mu_run_test(test_rz_buf_file);
mu_run_test(test_rz_buf_bytes); mu_run_test(test_rz_buf_bytes);

View file

@ -1633,7 +1633,7 @@ static bool test_array_bounds_fuzz(void) {
static int all_tests(void) { static int all_tests(void) {
time_t seed = time(0); time_t seed = time(0);
printf("Gillian Seed: %" PFMT64u "\n", (unsigned long long)seed); printf("Gillian Seed: %" PFMT64u "\n", (ut64)seed);
srand(seed); srand(seed);
mu_run_test(test_vector_init); mu_run_test(test_vector_init);
mu_run_test(test_vector_new); mu_run_test(test_vector_new);