4 #undef _FILE_OFFSET_BITS
5 #define _FILE_OFFSET_BITS 64
13 #if HAVE_HEADER_INTTYPES_H
25 #define RZ_MODE_PRINT 0x000
26 #define RZ_MODE_RIZINCMD 0x001
27 #define RZ_MODE_SET 0x002
28 #define RZ_MODE_SIMPLE 0x004
29 #define RZ_MODE_JSON 0x008
30 #define RZ_MODE_ARRAY 0x010
31 #define RZ_MODE_SIMPLEST 0x020
32 #define RZ_MODE_CLASSDUMP 0x040
33 #define RZ_MODE_EQUAL 0x080
55 #define RZ_OWN __attribute__((annotate("RZ_OWN")))
56 #define RZ_BORROW __attribute__((annotate("RZ_BORROW")))
58 #define RZ_NONNULL __attribute__((annotate("RZ_NONNULL")))
59 #define RZ_NULLABLE __attribute__((annotate("RZ_NULLABLE")))
60 #define RZ_DEPRECATE __attribute__((annotate("RZ_DEPRECATE")))
71 #define RZ_UNUSED __attribute__((__unused__))
96 #define RZ_PERM_RW (RZ_PERM_R | RZ_PERM_W)
97 #define RZ_PERM_RX (RZ_PERM_R | RZ_PERM_X)
98 #define RZ_PERM_RWX (RZ_PERM_R | RZ_PERM_W | RZ_PERM_X)
99 #define RZ_PERM_WX (RZ_PERM_W | RZ_PERM_X)
100 #define RZ_PERM_SHAR 8
101 #define RZ_PERM_PRIV 16
102 #define RZ_PERM_ACCESS 32
103 #define RZ_PERM_CREAT 64
105 #if defined(__powerpc) || defined(__powerpc__)
107 #define __POWERPC__ 1
110 #if defined(__OpenBSD__)
111 #include <sys/param.h>
115 #define UNUSED_FUNCTION(x) __attribute__((__unused__)) UNUSED_##x
117 #define UNUSED_FUNCTION(x) UNUSED_##x
120 #ifdef __EMSCRIPTEN__
128 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
140 #define strcasecmp stricmp
141 #define strncasecmp strnicmp
142 #define __WINDOWS__ 1
145 #if defined(EMSCRIPTEN) || defined(__linux__) || defined(__APPLE__) || defined(__GNU__) || defined(__ANDROID__) || defined(__QNX__) || defined(__sun) || defined(__HAIKU__)
149 #if __KFBSD__ || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
153 #if __WINDOWS__ || _WIN32
154 #define __WINDOWS__ 1
160 #if defined(__APPLE__) && ((__arm__ || __arm64__ || __aarch64__) && IS_IOS)
161 #define TARGET_OS_IPHONE 1
163 #define TARGET_OS_IPHONE 0
167 #define FUNC_ATTR_MALLOC __attribute__((malloc))
168 #define FUNC_ATTR_ALLOC_SIZE(x) __attribute__((alloc_size(x)))
169 #define FUNC_ATTR_ALLOC_SIZE_PROD(x, y) __attribute__((alloc_size(x, y)))
170 #define FUNC_ATTR_ALLOC_ALIGN(x) __attribute__((alloc_align(x)))
171 #define FUNC_ATTR_PURE __attribute__((pure))
172 #define FUNC_ATTR_CONST __attribute__((const))
173 #define FUNC_ATTR_USED __attribute__((used))
174 #define FUNC_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
175 #define FUNC_ATTR_ALWAYS_INLINE __attribute__((always_inline))
177 #define FUNC_ATTR_MALLOC
178 #define FUNC_ATTR_ALLOC_SIZE(x)
179 #define FUNC_ATTR_ALLOC_SIZE_PROD(x, y)
180 #define FUNC_ATTR_ALLOC_ALIGN(x)
181 #define FUNC_ATTR_PURE
182 #define FUNC_ATTR_CONST
183 #define FUNC_ATTR_USED
184 #define FUNC_ATTR_WARN_UNUSED_RESULT
185 #define FUNC_ATTR_ALWAYS_INLINE
189 #if defined(__clang__) || defined(__GNUC__)
190 #define RZ_PRINTF_CHECK(fmt, dots) __attribute__((format(printf, fmt, dots)))
192 #define RZ_PRINTF_CHECK(fmt, dots)
213 #define RZ_SYS_DIR "\\"
214 #define RZ_SYS_ENVSEP ";"
215 #define RZ_SYS_HOME "USERPROFILE"
216 #define RZ_SYS_TMP "TEMP"
218 #define RZ_SYS_DIR "/"
219 #define RZ_SYS_ENVSEP ":"
220 #define RZ_SYS_HOME "HOME"
221 #define RZ_SYS_TMP "TMPDIR"
224 #define RZ_JOIN_2_PATHS(p1, p2) p1 RZ_SYS_DIR p2
225 #define RZ_JOIN_3_PATHS(p1, p2, p3) p1 RZ_SYS_DIR p2 RZ_SYS_DIR p3
226 #define RZ_JOIN_4_PATHS(p1, p2, p3, p4) p1 RZ_SYS_DIR p2 RZ_SYS_DIR p3 RZ_SYS_DIR p4
227 #define RZ_JOIN_5_PATHS(p1, p2, p3, p4, p5) p1 RZ_SYS_DIR p2 RZ_SYS_DIR p3 RZ_SYS_DIR p4 RZ_SYS_DIR p5
230 #define __packed __attribute__((__packed__))
236 #define CTO(y, z) ((size_t) & ((y *)0)->z)
237 #define CTA(x, y, z) (x + CTO(y, z))
238 #define CTI(x, y, z) (*((size_t *)(CTA(x, y, z))))
239 #define CTS(x, y, z, t, v) \
241 t *_ = (t *)CTA(x, y, z); \
260 #define RZ_API __attribute__((annotate("RZ_API")))
262 #define RZ_API inline
264 #if defined(__GNUC__) && __GNUC__ >= 4
265 #define RZ_API __attribute__((visibility("default")))
266 #elif defined(_MSC_VER)
267 #define RZ_API __declspec(dllexport)
273 #define RZ_LIB_VERSION_HEADER(x) \
274 RZ_API const char *x##_version(void)
275 #define RZ_LIB_VERSION(x) \
276 RZ_API const char *x##_version(void) { \
277 return "" RZ_VERSION; \
280 #define BITS2BYTES(x) (((x) / 8) + (((x) % 8) ? 1 : 0))
281 #define ZERO_FILL(x) memset(&x, 0, sizeof(x))
282 #define RZ_NEWS0(x, y) (x *)calloc(y, sizeof(x))
283 #define RZ_NEWS(x, y) (x *)malloc(sizeof(x) * (y))
284 #define RZ_NEW0(x) (x *)calloc(1, sizeof(x))
285 #define RZ_NEW(x) (x *)malloc(sizeof(x))
286 #define RZ_NEWCOPY(x, y) (x *)rz_new_copy(sizeof(x), y)
296 #define RZ_NEW_COPY(x, y) \
297 x = (void *)malloc(sizeof(y)); \
298 memcpy(x, y, sizeof(y))
299 #define RZ_MEM_ALIGN(x) ((void *)(size_t)(((ut64)(size_t)x) & 0xfffffffffffff000LL))
300 #define RZ_ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
301 #define RZ_PTR_MOVE(d, s) \
305 #define RZ_PTR_ALIGN(v, t) \
306 ((char *)(((size_t)(v)) & ~(t - 1)))
307 #define RZ_PTR_ALIGN_NEXT(v, t) \
308 ((char *)(((size_t)(v) + (t - 1)) & ~(t - 1)))
310 #define RZ_BIT_MASK32(x, y) ((1UL << (x)) - (1UL << (y)))
311 #define RZ_BIT_SET(x, y) (((ut8 *)x)[y >> 4] |= (1 << (y & 0xf)))
312 #define RZ_BIT_UNSET(x, y) (((ut8 *)x)[y >> 4] &= ~(1 << (y & 0xf)))
313 #define RZ_BIT_TOGGLE(x, y) (RZ_BIT_CHK(x, y) ? RZ_BIT_UNSET(x, y) : RZ_BIT_SET(x, y))
316 #define RZ_BIT_CHK(x, y) (*(x) & (1 << (y)))
319 #if defined(_MSC_VER) && (_MSC_VER <= 1800)
320 #define __func__ __FUNCTION__
323 #define PERROR_WITH_FILELINE 0
325 #if PERROR_WITH_FILELINE
327 #define _perror(str, file, line, func) \
330 snprintf(buf, sizeof(buf), "[%s:%d %s] %s", file, line, func, str); \
331 rz_sys_perror_str(buf); \
333 #define perror(x) _perror(x, __FILE__, __LINE__, __func__)
334 #define rz_sys_perror(x) _perror(x, __FILE__, __LINE__, __func__)
336 #define rz_sys_perror(x) rz_sys_perror_str(x);
340 #include <sys/types.h>
341 #include <sys/stat.h>
345 #include <sys/time.h>
349 #define eprintf(...) fprintf(stderr, __VA_ARGS__)
350 #define HAVE_EPRINTF 1
354 #define typeof(arg) __typeof__(arg)
359 #if !(defined(__GNUC__) && __GNUC__ < 5) || defined(__clang__)
360 #define rz_offsetof(type, member) offsetof(type, member)
363 #define rz_offsetof(type, member) ((unsigned long)(ut64) & ((type *)0)->member)
365 #define rz_offsetof(type, member) ((unsigned long)&((type *)0)->member)
375 #define RZ_FREE_CUSTOM(x, y) \
382 #define PFMT64x "I64x"
383 #define PFMT64d "I64d"
384 #define PFMT64u "I64u"
385 #define PFMT64o "I64o"
393 #define PFMT64x "llx"
394 #define PFMT64d "lld"
395 #define PFMT64u "llu"
396 #define PFMT64o "llo"
405 #define PFMTDPTR "td"
418 #define RZ_SYS_BASE ((ut64)0x1000)
420 #define RZ_SYS_BASE ((ut64)0x100000000)
422 #define RZ_SYS_BASE ((ut64)0x1000)
425 #define RZ_SYS_BASE ((ut64)0x01001000)
427 #if __arm__ || __arm64__
428 #define RZ_SYS_BASE ((ut64)0x4000)
430 #define RZ_SYS_BASE ((ut64)0x8048000)
436 #define RZ_SYS_ARCH "x86"
437 #define RZ_SYS_BITS RZ_SYS_BITS_32
438 #define RZ_SYS_ENDIAN 0
440 #define RZ_SYS_ARCH "wasm"
441 #define RZ_SYS_BITS (RZ_SYS_BITS_32 | RZ_SYS_BITS_64)
442 #define RZ_SYS_ENDIAN 0
444 #define RZ_SYS_ARCH "x86"
445 #define RZ_SYS_BITS (RZ_SYS_BITS_32 | RZ_SYS_BITS_64)
446 #define RZ_SYS_ENDIAN 0
448 #define RZ_SYS_ARCH "ppc"
450 #define RZ_SYS_BITS (RZ_SYS_BITS_32 | RZ_SYS_BITS_64)
452 #define RZ_SYS_BITS RZ_SYS_BITS_32
454 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
455 #define RZ_SYS_ENDIAN 0
457 #define RZ_SYS_ENDIAN 1
460 #define RZ_SYS_ARCH "arm"
461 #define RZ_SYS_BITS RZ_SYS_BITS_32
462 #define RZ_SYS_ENDIAN 0
463 #elif __arm64__ || __aarch64__
464 #define RZ_SYS_ARCH "arm"
465 #define RZ_SYS_BITS (RZ_SYS_BITS_32 | RZ_SYS_BITS_64)
466 #define RZ_SYS_ENDIAN 0
468 #define RZ_SYS_ARCH "arc"
469 #define RZ_SYS_BITS RZ_SYS_BITS_32
470 #define RZ_SYS_ENDIAN 0
472 #define RZ_SYS_ARCH "sysz"
473 #define RZ_SYS_BITS RZ_SYS_BITS_64
474 #define RZ_SYS_ENDIAN 1
476 #define RZ_SYS_ARCH "sparc"
477 #define RZ_SYS_BITS RZ_SYS_BITS_32
478 #define RZ_SYS_ENDIAN 1
480 #define RZ_SYS_ARCH "mips"
481 #define RZ_SYS_BITS RZ_SYS_BITS_32
482 #define RZ_SYS_ENDIAN 1
485 #define RZ_SYS_ARCH "x86"
486 #define RZ_SYS_BITS RZ_SYS_BITS_32
487 #elif __riscv__ || __riscv
488 #define RZ_SYS_ARCH "riscv"
489 #define RZ_SYS_ENDIAN 0
490 #if __riscv_xlen == 32
491 #define RZ_SYS_BITS RZ_SYS_BITS_32
493 #define RZ_SYS_BITS (RZ_SYS_BITS_32 | RZ_SYS_BITS_64)
497 #if defined(_M_X64) || defined(_M_AMD64)
498 #define RZ_SYS_ARCH "x86"
499 #define RZ_SYS_BITS (RZ_SYS_BITS_32 | RZ_SYS_BITS_64)
500 #define RZ_SYS_ENDIAN 0
502 #elif defined(_M_IX86)
503 #define RZ_SYS_ARCH "x86"
504 #define RZ_SYS_BITS (RZ_SYS_BITS_32)
505 #define RZ_SYS_ENDIAN 0
507 #elif defined(_M_ARM64)
508 #define RZ_SYS_ARCH "arm"
509 #define RZ_SYS_BITS (RZ_SYS_BITS_32 | RZ_SYS_BITS_64)
510 #define RZ_SYS_ENDIAN 0
512 #elif defined(_M_ARM)
513 #define RZ_SYS_ARCH "arm"
514 #define RZ_SYS_BITS RZ_SYS_BITS_32
515 #define RZ_SYS_ENDIAN 0
519 #define RZ_SYS_ARCH "unknown"
520 #define RZ_SYS_BITS RZ_SYS_BITS_32
521 #define RZ_SYS_ENDIAN 0
525 #define RZ_SYS_ENDIAN_NONE 0
526 #define RZ_SYS_ENDIAN_LITTLE 1
527 #define RZ_SYS_ENDIAN_BIG 2
528 #define RZ_SYS_ENDIAN_BI 3
569 #define RZ_SYS_OS "qnx"
572 #elif defined(__APPLE__)
573 #define RZ_SYS_OS "darwin"
574 #elif defined(__linux__)
575 #define RZ_SYS_OS "linux"
576 #elif defined(__WINDOWS__)
577 #define RZ_SYS_OS "windows"
578 #elif defined(__NetBSD__)
579 #define RZ_SYS_OS "netbsd"
580 #elif defined(__OpenBSD__)
581 #define RZ_SYS_OS "openbsd"
582 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
583 #define RZ_SYS_OS "freebsd"
584 #elif defined(__HAIKU__)
585 #define RZ_SYS_OS "haiku"
587 #define RZ_SYS_OS "unknown"
595 ((void (*)(
void *))(fcn))(arg1);
599 ((void (*)(
void *,
void *))(fcn))(arg1, arg2);
602 static inline void rz_run_call3(
void *fcn,
void *arg1,
void *arg2,
void *arg3) {
603 ((void (*)(
void *,
void *,
void *))(fcn))(arg1, arg2, arg3);
606 static inline void rz_run_call4(
void *fcn,
void *arg1,
void *arg2,
void *arg3,
void *arg4) {
607 ((void (*)(
void *,
void *,
void *,
void *))(fcn))(arg1, arg2, arg3, arg4);
610 static inline void rz_run_call5(
void *fcn,
void *arg1,
void *arg2,
void *arg3,
void *arg4,
void *arg5) {
611 ((void (*)(
void *,
void *,
void *,
void *,
void *))(fcn))(arg1, arg2, arg3, arg4, arg5);
614 static inline void rz_run_call6(
void *fcn,
void *arg1,
void *arg2,
void *arg3,
void *arg4,
void *arg5,
616 ((void (*)(
void *,
void *,
void *,
void *,
void *,
void *))(fcn))(arg1, arg2, arg3, arg4, arg5, arg6);
619 static inline void rz_run_call7(
void *fcn,
void *arg1,
void *arg2,
void *arg3,
void *arg4,
void *arg5,
620 void *arg6,
void *arg7) {
621 ((void (*)(
void *,
void *,
void *,
void *,
void *,
void *,
void *))(fcn))(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
624 static inline void rz_run_call8(
void *fcn,
void *arg1,
void *arg2,
void *arg3,
void *arg4,
void *arg5,
625 void *arg6,
void *arg7,
void *arg8) {
626 ((void (*)(
void *,
void *,
void *,
void *,
void *,
void *,
void *,
void *))(fcn))(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
629 static inline void rz_run_call9(
void *fcn,
void *arg1,
void *arg2,
void *arg3,
void *arg4,
void *arg5,
630 void *arg6,
void *arg7,
void *arg8,
void *arg9) {
631 ((void (*)(
void *,
void *,
void *,
void *,
void *,
void *,
void *,
void *,
void *))(fcn))(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
634 static inline void rz_run_call10(
void *fcn,
void *arg1,
void *arg2,
void *arg3,
void *arg4,
void *arg5,
635 void *arg6,
void *arg7,
void *arg8,
void *arg9,
void *arg10) {
636 ((void (*)(
void *,
void *,
void *,
void *,
void *,
void *,
void *,
void *,
void *,
void *))(fcn))(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10);
639 #define RZ_V_NOT(op, fail_ret) \
640 if ((op) == (fail_ret)) \
641 RZ_LOG_WARN(#op " at %s:%d failed: %s\n", __FILE__, __LINE__, strerror(errno))
642 #define rz_xwrite(fd, buf, count) RZ_V_NOT(write(fd, buf, count), -1)
643 #define rz_xread(fd, buf, count) RZ_V_NOT(read(fd, buf, count), -1)
644 #define rz_xfreopen(pathname, mode, stream) RZ_V_NOT(freopen(pathname, mode, stream), NULL)
648 #define container_of(ptr, type, member) ((type *)((char *)(ptr)-offsetof(type, member)))
650 #define container_of(ptr, type, member) ((type *)((char *)(__typeof__(((type *)0)->member) *){ ptr } - offsetof(type, member)))
657 #define RZ_REF_NAME refcount
658 #define rz_ref(x) x->RZ_REF_NAME++;
659 #define rz_ref_init(x) x->RZ_REF_NAME = 1
660 #define rz_unref(x, f) \
662 assert(x->RZ_REF_NAME > 0); \
663 if (!--(x->RZ_REF_NAME)) { \
668 #define RZ_REF_TYPE RzRef RZ_REF_NAME
669 #define RZ_REF_FUNCTIONS(s, n) \
670 static inline void n##_ref(s *x) { \
673 static inline void n##_unref(s *x) { \
674 rz_unref(x, n##_free); \
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
void * malloc(size_t size)
static void rz_run_call8(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5, void *arg6, void *arg7, void *arg8)
static void rz_run_call9(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5, void *arg6, void *arg7, void *arg8, void *arg9)
static void rz_run_call1(void *fcn, void *arg1)
static void rz_run_call6(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5, void *arg6)
int(* PrintfCallback)(const char *str,...) RZ_PRINTF_CHECK(1
#define RZ_PRINTF_CHECK(fmt, dots)
static void rz_run_call3(void *fcn, void *arg1, void *arg2, void *arg3)
static void rz_run_call4(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4)
static void * rz_new_copy(int size, void *data)
static void rz_run_call5(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5)
static void rz_run_call10(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5, void *arg6, void *arg7, void *arg8, void *arg9, void *arg10)
static void rz_run_call7(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5, void *arg6, void *arg7)
RzOutputMode
Enum to describe the way data are printed.
@ RZ_OUTPUT_MODE_LONG_JSON
@ RZ_OUTPUT_MODE_QUIETEST
@ RZ_OUTPUT_MODE_STANDARD
static void rz_run_call2(void *fcn, void *arg1, void *arg2)