From 57e063e591c4c8937f381efbe6917a1e1a55ecb4 Mon Sep 17 00:00:00 2001 From: tushar3q34 Date: Tue, 3 Sep 2024 03:47:04 +0530 Subject: [PATCH 1/4] Refactor debug_native.c --- librz/debug/p/DragonFly.c | 537 +++++++++++ librz/debug/p/KFBSD.c | 543 +++++++++++ librz/debug/p/NetBSD.c | 538 +++++++++++ librz/debug/p/OpenBSD.c | 534 +++++++++++ librz/debug/p/android_arm.c | 659 +++++++++++++ librz/debug/p/android_arm64.c | 711 ++++++++++++++ librz/debug/p/android_x86_64.c | 695 ++++++++++++++ librz/debug/p/apple_aarch64.c | 300 ++++++ librz/debug/p/apple_x86_64.c | 373 ++++++++ librz/debug/p/debug_native.c | 1610 +------------------------------- librz/debug/p/linux_arm.c | 731 +++++++++++++++ librz/debug/p/linux_x86_64.c | 769 +++++++++++++++ librz/debug/p/windows.c | 433 +++++++++ 13 files changed, 6861 insertions(+), 1572 deletions(-) create mode 100644 librz/debug/p/DragonFly.c create mode 100644 librz/debug/p/KFBSD.c create mode 100644 librz/debug/p/NetBSD.c create mode 100644 librz/debug/p/OpenBSD.c create mode 100644 librz/debug/p/android_arm.c create mode 100644 librz/debug/p/android_arm64.c create mode 100644 librz/debug/p/android_x86_64.c create mode 100644 librz/debug/p/apple_aarch64.c create mode 100644 librz/debug/p/apple_x86_64.c create mode 100644 librz/debug/p/linux_arm.c create mode 100644 librz/debug/p/linux_x86_64.c create mode 100644 librz/debug/p/windows.c diff --git a/librz/debug/p/DragonFly.c b/librz/debug/p/DragonFly.c new file mode 100644 index 00000000000..babe0d52075 --- /dev/null +++ b/librz/debug/p/DragonFly.c @@ -0,0 +1,537 @@ +#include +#if !defined(__HAIKU__) && !defined(__sun) +#include +#endif +#include +#include + +#include "native/bsd/bsd_debug.h" +#include "native/procfs.h" + +#ifdef __WALL +#define WAITPID_FLAGS __WALL +#else +#define WAITPID_FLAGS 0 +#endif + +#define PROC_NAME_SZ 1024 +#define PROC_REGION_SZ 100 +// PROC_REGION_SZ - 2 (used for `0x`). Due to how RZ_STR_DEF works this can't be +// computed. +#define PROC_REGION_LEFT_SZ 98 +#define PROC_PERM_SZ 5 +#define PROC_UNKSTR_SZ 128 + +static int rz_debug_handle_signals(RzDebug *dbg) { + eprintf("Warning: signal handling is not supported on this platform\n"); + return 0; +} + +#include "native/reg.c" + +static bool rz_debug_native_step(RzDebug *dbg) { + int ret = ptrace(PT_STEP, dbg->pid, (caddr_t)1, 0); + if (ret != 0) { + perror("native-singlestep"); + return false; + } + return true; +} + +static int rz_debug_native_attach(RzDebug *dbg, int pid) { + int ret = ptrace(PTRACE_ATTACH, pid, 0, 0); + if (ret != -1) { + eprintf("Trying to attach to %d\n", pid); + perror("ptrace (PT_ATTACH)"); + } + return pid; +} + +static int rz_debug_native_detach(RzDebug *dbg, int pid) { + return ptrace(PT_DETACH, pid, NULL, 0); +} + +static int rz_debug_native_continue_syscall(RzDebug *dbg, int pid, int num) { + ut64 pc = rz_debug_reg_get(dbg, "PC"); + errno = 0; + return ptrace(PTRACE_SYSCALL, pid, (void *)(size_t)pc, 0) == 0; +} + +static int rz_debug_native_stop(RzDebug *dbg) { + return 0; +} + +static int rz_debug_native_continue(RzDebug *dbg, int pid, int tid, int sig) { + void *data = (void *)(size_t)((sig != -1) ? sig : dbg->reason.signum); + ut64 pc = rz_debug_reg_get(dbg, "PC"); + return ptrace(PTRACE_CONT, pid, (void *)(size_t)pc, (int)(size_t)data) == 0; +} + +static RzDebugInfo *rz_debug_native_info(RzDebug *dbg, const char *arg) { + return NULL; +} + +static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { + RzDebugReasonType reason = RZ_DEBUG_REASON_UNKNOWN; + + if (pid == -1) { + eprintf("ERROR: rz_debug_native_wait called with pid -1\n"); + return RZ_DEBUG_REASON_ERROR; + } + int status = -1; +#ifdef WAIT_ON_ALL_CHILDREN + int ret = waitpid(-1, &status, WAITPID_FLAGS); +#else + int ret = waitpid(-1, &status, 0); + if (ret != -1) { + reason = RZ_DEBUG_REASON_TRAP; + } +#endif + if (ret == -1) { + rz_sys_perror("waitpid"); + return RZ_DEBUG_REASON_ERROR; + } + + // eprintf ("rz_debug_native_wait: status=%d (0x%x) (return=%d)\n", status, status, ret); + if (reason == RZ_DEBUG_REASON_ERROR) { + return reason; + } + /* we don't know what to do yet, let's try harder to figure it out. */ + if (reason == RZ_DEBUG_REASON_UNKNOWN) { + if (WIFEXITED(status)) { + eprintf("child exited with status %d\n", WEXITSTATUS(status)); + reason = RZ_DEBUG_REASON_DEAD; + } else if (WIFSIGNALED(status)) { + eprintf("child received signal %d\n", WTERMSIG(status)); + reason = RZ_DEBUG_REASON_SIGNAL; + } else if (WIFSTOPPED(status)) { + if (WSTOPSIG(status) != SIGTRAP && + WSTOPSIG(status) != SIGSTOP) { + eprintf("Child stopped with signal %d\n", WSTOPSIG(status)); + } + + /* the ptrace documentation says GETSIGINFO is only necessary for + * differentiating the various stops. + * + * this might modify dbg->reason.signum + */ + if (rz_debug_handle_signals(dbg) != 0) { + return RZ_DEBUG_REASON_ERROR; + } + reason = dbg->reason.type; + +#ifdef WIFCONTINUED + } else if (WIFCONTINUED(status)) { + eprintf("child continued...\n"); + reason = RZ_DEBUG_REASON_NONE; +#endif + } else if (status == 1) { + /* XXX(jjd): does this actually happen? */ + eprintf("debugger is dead with status 1!\n"); + reason = RZ_DEBUG_REASON_DEAD; + } else if (status == 0) { + /* XXX(jjd): does this actually happen? */ + eprintf("debugger is dead with status 0\n"); + reason = RZ_DEBUG_REASON_DEAD; + } else { + if (ret != pid) { + reason = RZ_DEBUG_REASON_NEW_PID; + } else { + /* ugh. still don't know :-/ */ + eprintf("returning from wait without knowing why...\n"); + } + } +} +/* if we still don't know what to do, we have a problem... */ +if (reason == RZ_DEBUG_REASON_UNKNOWN) { + eprintf("%s: no idea what happened...\n", __func__); + reason = RZ_DEBUG_REASON_ERROR; +} +dbg->reason.tid = pid; +dbg->reason.type = reason; +return reason; +} + +#undef MAXPID +#define MAXPID 99999 + +static RzList /**/ *rz_debug_native_pids(RzDebug *dbg, int pid) { + RzList *list = rz_list_new(); + if (!list) { + return NULL; + } + return bsd_pid_list(dbg, pid, list); +} + +RZ_API RZ_OWN RzList /**/ *rz_debug_native_threads(RzDebug *dbg, int pid) { + RzList *list = rz_list_new(); + if (!list) { + eprintf("No list?\n"); + return NULL; + } + return bsd_thread_list(dbg, pid, list); +} + +RZ_API ut64 rz_debug_get_tls(RZ_NONNULL RzDebug *dbg, int tid) { + rz_return_val_if_fail(dbg, 0); + return 0; +} + +static int bsd_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { + int showfpu = false; + int pid = dbg->pid; + int ret; + if (type < -1) { + showfpu = true; // hack for debugging + type = -type; + } + switch (type) { + case RZ_REG_TYPE_DRX: + + return true; + break; + case RZ_REG_TYPE_FPU: + case RZ_REG_TYPE_MMX: + case RZ_REG_TYPE_XMM: + break; + case RZ_REG_TYPE_SEG: + case RZ_REG_TYPE_FLG: + case RZ_REG_TYPE_GPR: { + RZ_DEBUG_REG_T regs; + memset(®s, 0, sizeof(regs)); + memset(buf, 0, size); +#warning not implemented for this platform + ret = 1; + // if perror here says 'no such process' and the + // process exists still.. is because there's a + // missing call to 'wait'. and the process is not + // yet available to accept more ptrace queries. + if (ret != 0) + return false; + if (sizeof(regs) < size) + size = sizeof(regs); + memcpy(buf, ®s, size); + return sizeof(regs); + } break; + } + return true; +} + +static int rz_debug_native_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { + if (size < 1) { + return false; + } + return bsd_reg_read(dbg, type, buf, size); +} + +static int rz_debug_native_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size) { + // XXX use switch or so + if (type == RZ_REG_TYPE_DRX) { +#if __i386__ || __x86_64__ + return bsd_reg_write(dbg, type, buf, size); +#else // i386/x86-64 + return false; +#endif + } else if (type == RZ_REG_TYPE_GPR) { + return bsd_reg_write(dbg, type, buf, size); + } else if (type == RZ_REG_TYPE_FPU) { + return bsd_reg_write(dbg, type, buf, size); + } // else eprintf ("TODO: reg_write_non-gpr (%d)\n", type); + return false; +} + +static RzDebugMap *rz_debug_native_map_alloc(RzDebug *dbg, ut64 addr, int size, bool thp) { + // malloc not implemented for this platform + return NULL; +} + +static int rz_debug_native_map_dealloc(RzDebug *dbg, ut64 addr, int size) { + // mdealloc not implemented for this platform + return false; +} + +static void _map_free(RzDebugMap *map) { + if (!map) { + return; + } + free(map->name); + free(map->file); + free(map); +} + +static RzList /**/ *rz_debug_native_map_get(RzDebug *dbg) { + RzList *list = NULL; + RzDebugMap *map; + int i, perm, unk = 0; + char *pos_c; + char path[1024], line[1024], name[PROC_NAME_SZ + 1]; + char region[PROC_REGION_SZ + 1], region2[PROC_REGION_SZ + 1], perms[PROC_PERM_SZ + 1]; + FILE *fd; + if (dbg->pid == -1) { + // eprintf ("rz_debug_native_map_get: No selected pid (-1)\n"); + return NULL; + } + /* prepend 0x prefix */ + region[0] = region2[0] = '0'; + region[1] = region2[1] = 'x'; + + snprintf(path, sizeof(path), "/proc/%d/maps", dbg->pid); + + fd = rz_sys_fopen(path, "r"); + if (!fd) { + char *errmsg = rz_str_newf("Cannot open '%s'", path); + perror(errmsg); + free(errmsg); + return NULL; + } + + list = rz_list_new(); + if (!list) { + fclose(fd); + return NULL; + } + list->free = (RzListFree)_map_free; + while (!feof(fd)) { + size_t line_len; + bool map_is_shared = false; + ut64 map_start, map_end; + + if (!fgets(line, sizeof(line), fd)) { + break; + } + /* kill the newline if we got one */ + line_len = strlen(line); + if (line[line_len - 1] == '\n') { + line[line_len - 1] = '\0'; + line_len--; + } + /* maps files should not have empty lines */ + if (line_len == 0) { + break; + } + + ut64 offset = 0; + // 7fc8124c4000-7fc81278d000 r--p 00000000 fc:00 17043921 /usr/lib/locale/locale-archive + i = sscanf(line, "%" RZ_STR_DEF(PROC_REGION_LEFT_SZ) "s %" RZ_STR_DEF(PROC_PERM_SZ) "s %08" PFMT64x " %*s %*s %" RZ_STR_DEF(PROC_NAME_SZ) "[^\n]", ®ion[2], perms, &offset, name); + if (i == 3) { + name[0] = '\0'; + } else if (i != 4) { + eprintf("%s: Unable to parse \"%s\"\n", __func__, path); + eprintf("%s: problematic line: %s\n", __func__, line); + rz_list_free(list); + return NULL; + } + + /* split the region in two */ + pos_c = strchr(®ion[2], '-'); + if (!pos_c) { // should this be an error? + continue; + } + strncpy(®ion2[2], pos_c + 1, sizeof(region2) - 2 - 1); + + if (!*name) { + snprintf(name, sizeof(name), "unk%d", unk++); + } + perm = 0; + for (i = 0; i < 5 && perms[i]; i++) { + switch (perms[i]) { + case 'r': perm |= RZ_PERM_R; break; + case 'w': perm |= RZ_PERM_W; break; + case 'x': perm |= RZ_PERM_X; break; + case 'p': map_is_shared = false; break; + case 's': map_is_shared = true; break; + } + } + + map_start = rz_num_get(NULL, region); + map_end = rz_num_get(NULL, region2); + if (map_start == map_end || map_end == 0) { + eprintf("%s: ignoring invalid map size: %s - %s\n", __func__, region, region2); + continue; + } + map = rz_debug_map_new(name, map_start, map_end, perm, 0); + if (!map) { + break; + } + map->file = strdup(name); + rz_list_append(list, map); + } + fclose(fd); + return list; +} + +static RzList /**/ *rz_debug_native_modules_get(RzDebug *dbg) { + char *lastname = NULL; + RzDebugMap *map; + RzListIter *iter, *iter2; + RzList *list, *last; + bool must_delete; + if (!(list = rz_debug_native_map_get(dbg))) { + return NULL; + } + if (!(last = rz_list_newf((RzListFree)rz_debug_map_free))) { + rz_list_free(list); + return NULL; + } + rz_list_foreach_safe (list, iter, iter2, map) { + const char *file = map->file; + if (!map->file) { + file = map->file = strdup(map->name); + } + must_delete = true; + if (file && *file == '/') { + if (!lastname || strcmp(lastname, file)) { + must_delete = false; + } + } + if (must_delete) { + rz_list_delete(list, iter); + } else { + rz_list_append(last, map); + free(lastname); + lastname = strdup(file); + } + } + list->free = NULL; + free(lastname); + rz_list_free(list); + return last; +} + +static bool rz_debug_native_kill(RzDebug *dbg, int pid, int tid, int sig) { + bool ret = false; + if (pid == 0) { + pid = dbg->pid; + } + if (sig == SIGKILL && dbg->threads) { + rz_list_free(dbg->threads); + dbg->threads = NULL; + } + if ((rz_sys_kill(pid, sig) != -1)) { + ret = true; + } + if (errno == 1) { + ret = -true; // EPERM + } + return ret; +} + +struct rz_debug_desc_plugin_t rz_debug_desc_plugin_native; +static bool rz_debug_native_init(RzDebug *dbg, void **user) { + dbg->cur->desc = rz_debug_desc_plugin_native; + return true; +} + +static void rz_debug_native_fini(RzDebug *dbg, void *user) { +} + +#if __i386__ || __x86_64__ +static void sync_drx_regs(RzDebug *dbg, drxt *regs, size_t num_regs) { + /* sanity check, we rely on this assumption */ + if (num_regs != NUM_DRX_REGISTERS) { + eprintf("drx: Unsupported number of registers for get_debug_regs\n"); + return; + } + + // sync drx regs +#define R dbg->reg + regs[0] = rz_reg_getv(R, "dr0"); + regs[1] = rz_reg_getv(R, "dr1"); + regs[2] = rz_reg_getv(R, "dr2"); + regs[3] = rz_reg_getv(R, "dr3"); + /* + RESERVED + regs[4] = rz_reg_getv (R, "dr4"); + regs[5] = rz_reg_getv (R, "dr5"); +*/ + regs[6] = rz_reg_getv(R, "dr6"); + regs[7] = rz_reg_getv(R, "dr7"); +} +#endif + +#if __i386__ || __x86_64__ +static void set_drx_regs(RzDebug *dbg, drxt *regs, size_t num_regs) { + /* sanity check, we rely on this assumption */ + if (num_regs != NUM_DRX_REGISTERS) { + eprintf("drx: Unsupported number of registers for get_debug_regs\n"); + return; + } + +#define R dbg->reg + rz_reg_setv(R, "dr0", regs[0]); + rz_reg_setv(R, "dr1", regs[1]); + rz_reg_setv(R, "dr2", regs[2]); + rz_reg_setv(R, "dr3", regs[3]); + rz_reg_setv(R, "dr6", regs[6]); + rz_reg_setv(R, "dr7", regs[7]); +} +#endif + +static int rz_debug_native_drx(RzDebug *dbg, int n, ut64 addr, int sz, int rwx, int g, int api_type) { +#if __i386__ || __x86_64__ + int retval = false; + drxt regs[NUM_DRX_REGISTERS] = { 0 }; + // sync drx regs + sync_drx_regs(dbg, regs, NUM_DRX_REGISTERS); + + switch (api_type) { + case DRX_API_LIST: + drx_list(regs); + retval = false; + break; + case DRX_API_GET_BP: + /* get the index of the breakpoint at addr */ + retval = drx_get_at(regs, addr); + break; + case DRX_API_REMOVE_BP: + /* remove hardware breakpoint */ + drx_set(regs, n, addr, -1, 0, 0); + retval = true; + break; + case DRX_API_SET_BP: + /* set hardware breakpoint */ + drx_set(regs, n, addr, sz, rwx, g); + retval = true; + break; + default: + /* this should not happen, someone misused the API */ + eprintf("drx: Unsupported api type in rz_debug_native_drx\n"); + retval = false; + } + + set_drx_regs(dbg, regs, NUM_DRX_REGISTERS); + + return retval; +#else + eprintf("drx: Unsupported platform\n"); +#endif + return -1; +} + +static int rz_debug_native_bp(RzBreakpoint *bp, RzBreakpointItem *b, bool set) { + if (b && b->hw) { +#if __i386__ || __x86_64__ + return set + ? drx_add((RzDebug *)bp->user, bp, b) + : drx_del((RzDebug *)bp->user, bp, b); +#endif + } + return false; +} + +static RzList /**/ *rz_debug_desc_native_list(int pid) { +#warning list filedescriptors not supported for this platform + return NULL; +} + +static int rz_debug_native_map_protect(RzDebug *dbg, ut64 addr, int size, int perms) { + return false; +} + +static int rz_debug_desc_native_open(const char *path) { + return 0; +} + +static bool rz_debug_gcore(RzDebug *dbg, char *path, RzBuffer *dest) { + return false; +} \ No newline at end of file diff --git a/librz/debug/p/KFBSD.c b/librz/debug/p/KFBSD.c new file mode 100644 index 00000000000..333dbee0bf4 --- /dev/null +++ b/librz/debug/p/KFBSD.c @@ -0,0 +1,543 @@ +#include +#if !defined(__HAIKU__) && !defined(__sun) +#include +#endif +#include +#include + +#include "native/bsd/bsd_debug.h" +#include "native/procfs.h" + +#ifdef __WALL +#define WAITPID_FLAGS __WALL +#else +#define WAITPID_FLAGS 0 +#endif + +#define PROC_NAME_SZ 1024 +#define PROC_REGION_SZ 100 +// PROC_REGION_SZ - 2 (used for `0x`). Due to how RZ_STR_DEF works this can't be +// computed. +#define PROC_REGION_LEFT_SZ 98 +#define PROC_PERM_SZ 5 +#define PROC_UNKSTR_SZ 128 + +static int rz_debug_handle_signals(RzDebug *dbg) { + return bsd_handle_signals(dbg); +} + +#include "native/reg.c" + +static bool rz_debug_native_step(RzDebug *dbg) { + int ret = ptrace(PT_STEP, dbg->pid, (caddr_t)1, 0); + if (ret != 0) { + perror("native-singlestep"); + return false; + } + return true; +} + +static int rz_debug_native_attach(RzDebug *dbg, int pid) { + if (ptrace(PT_ATTACH, pid, 0, 0) != -1) { + perror("ptrace (PT_ATTACH)"); + } + return pid; +} + +static int rz_debug_native_detach(RzDebug *dbg, int pid) { + return ptrace(PT_DETACH, pid, NULL, 0); +} + +static int rz_debug_native_continue_syscall(RzDebug *dbg, int pid, int num) { + ut64 pc = rz_debug_reg_get(dbg, "PC"); + errno = 0; + return ptrace(PTRACE_SYSCALL, pid, (void *)(size_t)pc, 0) == 0; +} + +static int rz_debug_native_stop(RzDebug *dbg) { + return 0; +} + +static int rz_debug_native_continue(RzDebug *dbg, int pid, int tid, int sig) { + void *data = (void *)(size_t)((sig != -1) ? sig : dbg->reason.signum); + ut64 pc = rz_debug_reg_get(dbg, "PC"); + return ptrace(PTRACE_CONT, pid, (void *)(size_t)pc, (int)(size_t)data) == 0; +} + +static RzDebugInfo *rz_debug_native_info(RzDebug *dbg, const char *arg) { + return bsd_info(dbg, arg); +} + +static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { + RzDebugReasonType reason = RZ_DEBUG_REASON_UNKNOWN; + + if (pid == -1) { + eprintf("ERROR: rz_debug_native_wait called with pid -1\n"); + return RZ_DEBUG_REASON_ERROR; + } + int status = -1; +#ifdef WAIT_ON_ALL_CHILDREN + int ret = waitpid(-1, &status, WAITPID_FLAGS); +#else + int ret = waitpid(-1, &status, 0); + if (ret != -1) { + reason = RZ_DEBUG_REASON_TRAP; + } +#endif + if (ret == -1) { + rz_sys_perror("waitpid"); + return RZ_DEBUG_REASON_ERROR; + } + + // eprintf ("rz_debug_native_wait: status=%d (0x%x) (return=%d)\n", status, status, ret); + if (reason == RZ_DEBUG_REASON_ERROR) { + return reason; + } + /* we don't know what to do yet, let's try harder to figure it out. */ + if (reason == RZ_DEBUG_REASON_UNKNOWN) { + if (WIFEXITED(status)) { + eprintf("child exited with status %d\n", WEXITSTATUS(status)); + reason = RZ_DEBUG_REASON_DEAD; + } else if (WIFSIGNALED(status)) { + eprintf("child received signal %d\n", WTERMSIG(status)); + reason = RZ_DEBUG_REASON_SIGNAL; + } else if (WIFSTOPPED(status)) { + if (WSTOPSIG(status) != SIGTRAP && + WSTOPSIG(status) != SIGSTOP) { + eprintf("Child stopped with signal %d\n", WSTOPSIG(status)); + } + + /* the ptrace documentation says GETSIGINFO is only necessary for + * differentiating the various stops. + * + * this might modify dbg->reason.signum + */ + if (rz_debug_handle_signals(dbg) != 0) { + return RZ_DEBUG_REASON_ERROR; + } + reason = dbg->reason.type; +#ifdef WIFCONTINUED + } else if (WIFCONTINUED(status)) { + eprintf("child continued...\n"); + reason = RZ_DEBUG_REASON_NONE; +#endif + } else if (status == 1) { + /* XXX(jjd): does this actually happen? */ + eprintf("debugger is dead with status 1!\n"); + reason = RZ_DEBUG_REASON_DEAD; + } else if (status == 0) { + /* XXX(jjd): does this actually happen? */ + eprintf("debugger is dead with status 0\n"); + reason = RZ_DEBUG_REASON_DEAD; + } else { + if (ret != pid) { + reason = RZ_DEBUG_REASON_NEW_PID; + } else { + /* ugh. still don't know :-/ */ + eprintf("returning from wait without knowing why...\n"); + } + } +} +/* if we still don't know what to do, we have a problem... */ +if (reason == RZ_DEBUG_REASON_UNKNOWN) { + eprintf("%s: no idea what happened...\n", __func__); + reason = RZ_DEBUG_REASON_ERROR; +} +dbg->reason.tid = pid; +dbg->reason.type = reason; +return reason; +} + +#undef MAXPID +#define MAXPID 99999 + +static RzList /**/ *rz_debug_native_pids(RzDebug *dbg, int pid) { + RzList *list = rz_list_new(); + if (!list) { + return NULL; + } + return bsd_pid_list(dbg, pid, list); +} + +RZ_API RZ_OWN RzList /**/ *rz_debug_native_threads(RzDebug *dbg, int pid) { + RzList *list = rz_list_new(); + if (!list) { + eprintf("No list?\n"); + return NULL; + } + return bsd_thread_list(dbg, pid, list); +} + +RZ_API ut64 rz_debug_get_tls(RZ_NONNULL RzDebug *dbg, int tid) { + rz_return_val_if_fail(dbg, 0); + return 0; +} + +static int bsd_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { + int showfpu = false; + int pid = dbg->pid; + int ret; + if (type < -1) { + showfpu = true; // hack for debugging + type = -type; + } + switch (type) { + case RZ_REG_TYPE_DRX: +#if __i386__ || __x86_64__ + { + // TODO + struct dbreg dbr; + ret = ptrace(PT_GETDBREGS, pid, (caddr_t)&dbr, sizeof(dbr)); + if (ret != 0) + return false; + // XXX: maybe the register map is not correct, must review + } +#endif + return true; + break; + case RZ_REG_TYPE_FPU: + case RZ_REG_TYPE_MMX: + case RZ_REG_TYPE_XMM: + break; + case RZ_REG_TYPE_SEG: + case RZ_REG_TYPE_FLG: + case RZ_REG_TYPE_GPR: { + RZ_DEBUG_REG_T regs; + memset(®s, 0, sizeof(regs)); + memset(buf, 0, size); + ret = ptrace(PT_GETREGS, pid, (caddr_t)®s, 0); + // if perror here says 'no such process' and the + // process exists still.. is because there's a + // missing call to 'wait'. and the process is not + // yet available to accept more ptrace queries. + if (ret != 0) + return false; + if (sizeof(regs) < size) + size = sizeof(regs); + memcpy(buf, ®s, size); + return sizeof(regs); + } break; + } + return true; +} + +static int rz_debug_native_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { + if (size < 1) { + return false; + } + return bsd_reg_read(dbg, type, buf, size); +} + +static int rz_debug_native_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size) { + // XXX use switch or so + if (type == RZ_REG_TYPE_DRX) { +#if __i386__ || __x86_64__ + return bsd_reg_write(dbg, type, buf, size); +#else // i386/x86-64 + return false; +#endif + } else if (type == RZ_REG_TYPE_GPR) { + return bsd_reg_write(dbg, type, buf, size); + } else if (type == RZ_REG_TYPE_FPU) { + return bsd_reg_write(dbg, type, buf, size); + } // else eprintf ("TODO: reg_write_non-gpr (%d)\n", type); + return false; +} + +static RzDebugMap *rz_debug_native_map_alloc(RzDebug *dbg, ut64 addr, int size, bool thp) { + // malloc not implemented for this platform + return NULL; +} + +static int rz_debug_native_map_dealloc(RzDebug *dbg, ut64 addr, int size) { + // mdealloc not implemented for this platform + return false; +} + +static void _map_free(RzDebugMap *map) { + if (!map) { + return; + } + free(map->name); + free(map->file); + free(map); +} + +static RzList /**/ *rz_debug_native_map_get(RzDebug *dbg) { + RzList *list = NULL; + int ign; + char unkstr[PROC_UNKSTR_SZ + 1]; + RzDebugMap *map; + int i, perm, unk = 0; + char *pos_c; + char path[1024], line[1024], name[PROC_NAME_SZ + 1]; + char region[PROC_REGION_SZ + 1], region2[PROC_REGION_SZ + 1], perms[PROC_PERM_SZ + 1]; + FILE *fd; + if (dbg->pid == -1) { + // eprintf ("rz_debug_native_map_get: No selected pid (-1)\n"); + return NULL; + } + /* prepend 0x prefix */ + region[0] = region2[0] = '0'; + region[1] = region2[1] = 'x'; + + + list = bsd_native_sysctl_map(dbg); + if (list) { + return list; + } + snprintf(path, sizeof(path), "/proc/%d/map", dbg->pid); + fd = rz_sys_fopen(path, "r"); + if (!fd) { + char *errmsg = rz_str_newf("Cannot open '%s'", path); + perror(errmsg); + free(errmsg); + return NULL; + } + + list = rz_list_new(); + if (!list) { + fclose(fd); + return NULL; + } + list->free = (RzListFree)_map_free; + while (!feof(fd)) { + size_t line_len; + bool map_is_shared = false; + ut64 map_start, map_end; + + if (!fgets(line, sizeof(line), fd)) { + break; + } + /* kill the newline if we got one */ + line_len = strlen(line); + if (line[line_len - 1] == '\n') { + line[line_len - 1] = '\0'; + line_len--; + } + /* maps files should not have empty lines */ + if (line_len == 0) { + break; + } + // 0x8070000 0x8072000 2 0 0xc1fde948 rw- 1 0 0x2180 COW NC vnode /usr/bin/gcc + if (sscanf(line, "%" RZ_STR_DEF(PROC_REGION_LEFT_SZ) "s %" RZ_STR_DEF(PROC_REGION_LEFT_SZ) "s %d %d 0x%" RZ_STR_DEF(PROC_UNKSTR_SZ) "s %3s %d %d", + ®ion[2], ®ion2[2], &ign, &ign, + unkstr, perms, &ign, &ign) != 8) { + eprintf("%s: Unable to parse \"%s\"\n", __func__, path); + rz_list_free(list); + return NULL; + } + + /* snag the file name */ + pos_c = strchr(line, '/'); + if (pos_c) { + strncpy(name, pos_c, sizeof(name) - 1); + } else { + name[0] = '\0'; + } + + if (!*name) { + snprintf(name, sizeof(name), "unk%d", unk++); + } + perm = 0; + for (i = 0; i < 5 && perms[i]; i++) { + switch (perms[i]) { + case 'r': perm |= RZ_PERM_R; break; + case 'w': perm |= RZ_PERM_W; break; + case 'x': perm |= RZ_PERM_X; break; + case 'p': map_is_shared = false; break; + case 's': map_is_shared = true; break; + } + } + + map_start = rz_num_get(NULL, region); + map_end = rz_num_get(NULL, region2); + if (map_start == map_end || map_end == 0) { + eprintf("%s: ignoring invalid map size: %s - %s\n", __func__, region, region2); + continue; + } + map = rz_debug_map_new(name, map_start, map_end, perm, 0); + if (!map) { + break; + } + map->file = strdup(name); + rz_list_append(list, map); + } + fclose(fd); + return list; +} + +static RzList /**/ *rz_debug_native_modules_get(RzDebug *dbg) { + char *lastname = NULL; + RzDebugMap *map; + RzListIter *iter, *iter2; + RzList *list, *last; + bool must_delete; + if (!(list = rz_debug_native_map_get(dbg))) { + return NULL; + } + if (!(last = rz_list_newf((RzListFree)rz_debug_map_free))) { + rz_list_free(list); + return NULL; + } + rz_list_foreach_safe (list, iter, iter2, map) { + const char *file = map->file; + if (!map->file) { + file = map->file = strdup(map->name); + } + must_delete = true; + if (file && *file == '/') { + if (!lastname || strcmp(lastname, file)) { + must_delete = false; + } + } + if (must_delete) { + rz_list_delete(list, iter); + } else { + rz_list_append(last, map); + free(lastname); + lastname = strdup(file); + } + } + list->free = NULL; + free(lastname); + rz_list_free(list); + return last; +} + +static bool rz_debug_native_kill(RzDebug *dbg, int pid, int tid, int sig) { + bool ret = false; + if (pid == 0) { + pid = dbg->pid; + } + if (sig == SIGKILL && dbg->threads) { + rz_list_free(dbg->threads); + dbg->threads = NULL; + } + if ((rz_sys_kill(pid, sig) != -1)) { + ret = true; + } + if (errno == 1) { + ret = -true; // EPERM + } + return ret; +} + +struct rz_debug_desc_plugin_t rz_debug_desc_plugin_native; +static bool rz_debug_native_init(RzDebug *dbg, void **user) { + dbg->cur->desc = rz_debug_desc_plugin_native; + return true; +} + +static void rz_debug_native_fini(RzDebug *dbg, void *user) { +} + +#if __i386__ || __x86_64__ +static void sync_drx_regs(RzDebug *dbg, drxt *regs, size_t num_regs) { + /* sanity check, we rely on this assumption */ + if (num_regs != NUM_DRX_REGISTERS) { + eprintf("drx: Unsupported number of registers for get_debug_regs\n"); + return; + } + + // sync drx regs +#define R dbg->reg + regs[0] = rz_reg_getv(R, "dr0"); + regs[1] = rz_reg_getv(R, "dr1"); + regs[2] = rz_reg_getv(R, "dr2"); + regs[3] = rz_reg_getv(R, "dr3"); + /* + RESERVED + regs[4] = rz_reg_getv (R, "dr4"); + regs[5] = rz_reg_getv (R, "dr5"); +*/ + regs[6] = rz_reg_getv(R, "dr6"); + regs[7] = rz_reg_getv(R, "dr7"); +} +#endif + +#if __i386__ || __x86_64__ +static void set_drx_regs(RzDebug *dbg, drxt *regs, size_t num_regs) { + /* sanity check, we rely on this assumption */ + if (num_regs != NUM_DRX_REGISTERS) { + eprintf("drx: Unsupported number of registers for get_debug_regs\n"); + return; + } + +#define R dbg->reg + rz_reg_setv(R, "dr0", regs[0]); + rz_reg_setv(R, "dr1", regs[1]); + rz_reg_setv(R, "dr2", regs[2]); + rz_reg_setv(R, "dr3", regs[3]); + rz_reg_setv(R, "dr6", regs[6]); + rz_reg_setv(R, "dr7", regs[7]); +} +#endif + +static int rz_debug_native_drx(RzDebug *dbg, int n, ut64 addr, int sz, int rwx, int g, int api_type) { +#if __i386__ || __x86_64__ + int retval = false; + drxt regs[NUM_DRX_REGISTERS] = { 0 }; + // sync drx regs + sync_drx_regs(dbg, regs, NUM_DRX_REGISTERS); + + switch (api_type) { + case DRX_API_LIST: + drx_list(regs); + retval = false; + break; + case DRX_API_GET_BP: + /* get the index of the breakpoint at addr */ + retval = drx_get_at(regs, addr); + break; + case DRX_API_REMOVE_BP: + /* remove hardware breakpoint */ + drx_set(regs, n, addr, -1, 0, 0); + retval = true; + break; + case DRX_API_SET_BP: + /* set hardware breakpoint */ + drx_set(regs, n, addr, sz, rwx, g); + retval = true; + break; + default: + /* this should not happen, someone misused the API */ + eprintf("drx: Unsupported api type in rz_debug_native_drx\n"); + retval = false; + } + + set_drx_regs(dbg, regs, NUM_DRX_REGISTERS); + + return retval; +#else + eprintf("drx: Unsupported platform\n"); +#endif + return -1; +} + +static int rz_debug_native_bp(RzBreakpoint *bp, RzBreakpointItem *b, bool set) { + if (b && b->hw) { +#if __i386__ || __x86_64__ + return set + ? drx_add((RzDebug *)bp->user, bp, b) + : drx_del((RzDebug *)bp->user, bp, b); +#endif + } + return false; +} + +static RzList /**/ *rz_debug_desc_native_list(int pid) { + return bsd_desc_list(pid); +} + +static int rz_debug_native_map_protect(RzDebug *dbg, ut64 addr, int size, int perms) { + return false; +} + +static int rz_debug_desc_native_open(const char *path) { + return 0; +} + +static bool rz_debug_gcore(RzDebug *dbg, char *path, RzBuffer *dest) { + return bsd_generate_corefile(dbg, path, dest); +} \ No newline at end of file diff --git a/librz/debug/p/NetBSD.c b/librz/debug/p/NetBSD.c new file mode 100644 index 00000000000..85ee6740cb8 --- /dev/null +++ b/librz/debug/p/NetBSD.c @@ -0,0 +1,538 @@ +#include +#if !defined(__HAIKU__) && !defined(__sun) +#include +#endif +#include +#include + +#include "native/bsd/bsd_debug.h" +#include "native/procfs.h" + +#ifdef __WALL +#define WAITPID_FLAGS __WALL +#else +#define WAITPID_FLAGS 0 +#endif + +#define PROC_NAME_SZ 1024 +#define PROC_REGION_SZ 100 +// PROC_REGION_SZ - 2 (used for `0x`). Due to how RZ_STR_DEF works this can't be +// computed. +#define PROC_REGION_LEFT_SZ 98 +#define PROC_PERM_SZ 5 +#define PROC_UNKSTR_SZ 128 + +static int rz_debug_handle_signals(RzDebug *dbg) { +#if __KFBSD__ || __NetBSD__ + return bsd_handle_signals(dbg); +#else + eprintf("Warning: signal handling is not supported on this platform\n"); + return 0; +#endif +} + +#include "native/reg.c" + +static bool rz_debug_native_step(RzDebug *dbg) { + int ret = ptrace(PT_STEP, dbg->pid, (caddr_t)1, 0); + if (ret != 0) { + perror("native-singlestep"); + return false; + } + return true; +} + +static int rz_debug_native_attach(RzDebug *dbg, int pid) { + int ret = ptrace(PTRACE_ATTACH, pid, 0, 0); + if (ret != -1) { + eprintf("Trying to attach to %d\n", pid); + perror("ptrace (PT_ATTACH)"); + } + return pid; +} + +static int rz_debug_native_detach(RzDebug *dbg, int pid) { + return ptrace(PT_DETACH, pid, NULL, 0); +} + +static int rz_debug_native_continue_syscall(RzDebug *dbg, int pid, int num) { + ut64 pc = rz_debug_reg_get(dbg, "PC"); + errno = 0; + return ptrace(PTRACE_SYSCALL, pid, (void *)(size_t)pc, 0) == 0; +} + +static int rz_debug_native_stop(RzDebug *dbg) { + return 0; +} + +static int rz_debug_native_continue(RzDebug *dbg, int pid, int tid, int sig) { + void *data = (void *)(size_t)((sig != -1) ? sig : dbg->reason.signum); + ut64 pc = rz_debug_reg_get(dbg, "PC"); + return ptrace(PTRACE_CONT, pid, (void *)(size_t)pc, (int)(size_t)data) == 0; +} + +static RzDebugInfo *rz_debug_native_info(RzDebug *dbg, const char *arg) { + return bsd_info(dbg, arg); +} + +static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { + RzDebugReasonType reason = RZ_DEBUG_REASON_UNKNOWN; + + if (pid == -1) { + eprintf("ERROR: rz_debug_native_wait called with pid -1\n"); + return RZ_DEBUG_REASON_ERROR; + } + int status = -1; +#ifdef WAIT_ON_ALL_CHILDREN + int ret = waitpid(-1, &status, WAITPID_FLAGS); +#else + int ret = waitpid(-1, &status, 0); + if (ret != -1) { + reason = RZ_DEBUG_REASON_TRAP; + } +#endif + if (ret == -1) { + rz_sys_perror("waitpid"); + return RZ_DEBUG_REASON_ERROR; + } + + // eprintf ("rz_debug_native_wait: status=%d (0x%x) (return=%d)\n", status, status, ret); + if (reason == RZ_DEBUG_REASON_ERROR) { + return reason; + } + /* we don't know what to do yet, let's try harder to figure it out. */ + if (reason == RZ_DEBUG_REASON_UNKNOWN) { + if (WIFEXITED(status)) { + eprintf("child exited with status %d\n", WEXITSTATUS(status)); + reason = RZ_DEBUG_REASON_DEAD; + } else if (WIFSIGNALED(status)) { + eprintf("child received signal %d\n", WTERMSIG(status)); + reason = RZ_DEBUG_REASON_SIGNAL; + } else if (WIFSTOPPED(status)) { + if (WSTOPSIG(status) != SIGTRAP && + WSTOPSIG(status) != SIGSTOP) { + eprintf("Child stopped with signal %d\n", WSTOPSIG(status)); + } + + /* the ptrace documentation says GETSIGINFO is only necessary for + * differentiating the various stops. + * + * this might modify dbg->reason.signum + */ + if (rz_debug_handle_signals(dbg) != 0) { + return RZ_DEBUG_REASON_ERROR; + } + reason = dbg->reason.type; +#ifdef WIFCONTINUED + } else if (WIFCONTINUED(status)) { + eprintf("child continued...\n"); + reason = RZ_DEBUG_REASON_NONE; +#endif + } else if (status == 1) { + /* XXX(jjd): does this actually happen? */ + eprintf("debugger is dead with status 1!\n"); + reason = RZ_DEBUG_REASON_DEAD; + } else if (status == 0) { + /* XXX(jjd): does this actually happen? */ + eprintf("debugger is dead with status 0\n"); + reason = RZ_DEBUG_REASON_DEAD; + } else { + if (ret != pid) { + reason = RZ_DEBUG_REASON_NEW_PID; + } else { + /* ugh. still don't know :-/ */ + eprintf("returning from wait without knowing why...\n"); + } + } +} +/* if we still don't know what to do, we have a problem... */ +if (reason == RZ_DEBUG_REASON_UNKNOWN) { + eprintf("%s: no idea what happened...\n", __func__); + reason = RZ_DEBUG_REASON_ERROR; +} +dbg->reason.tid = pid; +dbg->reason.type = reason; +return reason; +} + +#undef MAXPID +#define MAXPID 99999 + +static RzList /**/ *rz_debug_native_pids(RzDebug *dbg, int pid) { + RzList *list = rz_list_new(); + if (!list) { + return NULL; + } + return bsd_pid_list(dbg, pid, list); +} + +RZ_API RZ_OWN RzList /**/ *rz_debug_native_threads(RzDebug *dbg, int pid) { + RzList *list = rz_list_new(); + if (!list) { + eprintf("No list?\n"); + return NULL; + } + return bsd_thread_list(dbg, pid, list); +} + +RZ_API ut64 rz_debug_get_tls(RZ_NONNULL RzDebug *dbg, int tid) { + rz_return_val_if_fail(dbg, 0); + return 0; +} + +static int bsd_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { + int showfpu = false; + int pid = dbg->pid; + int ret; + if (type < -1) { + showfpu = true; // hack for debugging + type = -type; + } + switch (type) { + case RZ_REG_TYPE_DRX: + return true; + break; + case RZ_REG_TYPE_FPU: + case RZ_REG_TYPE_MMX: + case RZ_REG_TYPE_XMM: + break; + case RZ_REG_TYPE_SEG: + case RZ_REG_TYPE_FLG: + case RZ_REG_TYPE_GPR: { + RZ_DEBUG_REG_T regs; + memset(®s, 0, sizeof(regs)); + memset(buf, 0, size); + ret = ptrace(PTRACE_GETREGS, pid, (caddr_t)®s, sizeof(regs)); + // if perror here says 'no such process' and the + // process exists still.. is because there's a + // missing call to 'wait'. and the process is not + // yet available to accept more ptrace queries. + if (ret != 0) + return false; + if (sizeof(regs) < size) + size = sizeof(regs); + memcpy(buf, ®s, size); + return sizeof(regs); + } break; + } + return true; +} + +static int rz_debug_native_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { + if (size < 1) { + return false; + } + return bsd_reg_read(dbg, type, buf, size); +} + +static int rz_debug_native_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size) { + // XXX use switch or so + if (type == RZ_REG_TYPE_DRX) { +#if __i386__ || __x86_64__ + return bsd_reg_write(dbg, type, buf, size); +#else // i386/x86-64 + return false; +#endif + } else if (type == RZ_REG_TYPE_GPR) { + return bsd_reg_write(dbg, type, buf, size); + } else if (type == RZ_REG_TYPE_FPU) { + return bsd_reg_write(dbg, type, buf, size); + } // else eprintf ("TODO: reg_write_non-gpr (%d)\n", type); + return false; +} + +static RzDebugMap *rz_debug_native_map_alloc(RzDebug *dbg, ut64 addr, int size, bool thp) { + // malloc not implemented for this platform + return NULL; +} + +static int rz_debug_native_map_dealloc(RzDebug *dbg, ut64 addr, int size) { + // mdealloc not implemented for this platform + return false; +} + +static void _map_free(RzDebugMap *map) { + if (!map) { + return; + } + free(map->name); + free(map->file); + free(map); +} + +static RzList /**/ *rz_debug_native_map_get(RzDebug *dbg) { + RzList *list = NULL; + RzDebugMap *map; + int i, perm, unk = 0; + char *pos_c; + char path[1024], line[1024], name[PROC_NAME_SZ + 1]; + char region[PROC_REGION_SZ + 1], region2[PROC_REGION_SZ + 1], perms[PROC_PERM_SZ + 1]; + FILE *fd; + if (dbg->pid == -1) { + // eprintf ("rz_debug_native_map_get: No selected pid (-1)\n"); + return NULL; + } + /* prepend 0x prefix */ + region[0] = region2[0] = '0'; + region[1] = region2[1] = 'x'; + + + snprintf(path, sizeof(path), "/proc/%d/maps", dbg->pid); + + fd = rz_sys_fopen(path, "r"); + if (!fd) { + char *errmsg = rz_str_newf("Cannot open '%s'", path); + perror(errmsg); + free(errmsg); + return NULL; + } + + list = rz_list_new(); + if (!list) { + fclose(fd); + return NULL; + } + list->free = (RzListFree)_map_free; + while (!feof(fd)) { + size_t line_len; + bool map_is_shared = false; + ut64 map_start, map_end; + + if (!fgets(line, sizeof(line), fd)) { + break; + } + /* kill the newline if we got one */ + line_len = strlen(line); + if (line[line_len - 1] == '\n') { + line[line_len - 1] = '\0'; + line_len--; + } + /* maps files should not have empty lines */ + if (line_len == 0) { + break; + } + + ut64 offset = 0; + // 7fc8124c4000-7fc81278d000 r--p 00000000 fc:00 17043921 /usr/lib/locale/locale-archive + i = sscanf(line, "%" RZ_STR_DEF(PROC_REGION_LEFT_SZ) "s %" RZ_STR_DEF(PROC_PERM_SZ) "s %08" PFMT64x " %*s %*s %" RZ_STR_DEF(PROC_NAME_SZ) "[^\n]", ®ion[2], perms, &offset, name); + if (i == 3) { + name[0] = '\0'; + } else if (i != 4) { + eprintf("%s: Unable to parse \"%s\"\n", __func__, path); + eprintf("%s: problematic line: %s\n", __func__, line); + rz_list_free(list); + return NULL; + } + + /* split the region in two */ + pos_c = strchr(®ion[2], '-'); + if (!pos_c) { // should this be an error? + continue; + } + strncpy(®ion2[2], pos_c + 1, sizeof(region2) - 2 - 1); + + if (!*name) { + snprintf(name, sizeof(name), "unk%d", unk++); + } + perm = 0; + for (i = 0; i < 5 && perms[i]; i++) { + switch (perms[i]) { + case 'r': perm |= RZ_PERM_R; break; + case 'w': perm |= RZ_PERM_W; break; + case 'x': perm |= RZ_PERM_X; break; + case 'p': map_is_shared = false; break; + case 's': map_is_shared = true; break; + } + } + + map_start = rz_num_get(NULL, region); + map_end = rz_num_get(NULL, region2); + if (map_start == map_end || map_end == 0) { + eprintf("%s: ignoring invalid map size: %s - %s\n", __func__, region, region2); + continue; + } + map = rz_debug_map_new(name, map_start, map_end, perm, 0); + if (!map) { + break; + } + map->file = strdup(name); + rz_list_append(list, map); + } + fclose(fd); + return list; +} + +static RzList /**/ *rz_debug_native_modules_get(RzDebug *dbg) { + char *lastname = NULL; + RzDebugMap *map; + RzListIter *iter, *iter2; + RzList *list, *last; + bool must_delete; + if (!(list = rz_debug_native_map_get(dbg))) { + return NULL; + } + if (!(last = rz_list_newf((RzListFree)rz_debug_map_free))) { + rz_list_free(list); + return NULL; + } + rz_list_foreach_safe (list, iter, iter2, map) { + const char *file = map->file; + if (!map->file) { + file = map->file = strdup(map->name); + } + must_delete = true; + if (file && *file == '/') { + if (!lastname || strcmp(lastname, file)) { + must_delete = false; + } + } + if (must_delete) { + rz_list_delete(list, iter); + } else { + rz_list_append(last, map); + free(lastname); + lastname = strdup(file); + } + } + list->free = NULL; + free(lastname); + rz_list_free(list); + return last; +} + +static bool rz_debug_native_kill(RzDebug *dbg, int pid, int tid, int sig) { + bool ret = false; + if (pid == 0) { + pid = dbg->pid; + } + if (sig == SIGKILL && dbg->threads) { + rz_list_free(dbg->threads); + dbg->threads = NULL; + } + if ((rz_sys_kill(pid, sig) != -1)) { + ret = true; + } + if (errno == 1) { + ret = -true; // EPERM + } + return ret; +} + +struct rz_debug_desc_plugin_t rz_debug_desc_plugin_native; +static bool rz_debug_native_init(RzDebug *dbg, void **user) { + dbg->cur->desc = rz_debug_desc_plugin_native; + return true; +} + +static void rz_debug_native_fini(RzDebug *dbg, void *user) { +} + +#if __i386__ || __x86_64__ +static void sync_drx_regs(RzDebug *dbg, drxt *regs, size_t num_regs) { + /* sanity check, we rely on this assumption */ + if (num_regs != NUM_DRX_REGISTERS) { + eprintf("drx: Unsupported number of registers for get_debug_regs\n"); + return; + } + + // sync drx regs +#define R dbg->reg + regs[0] = rz_reg_getv(R, "dr0"); + regs[1] = rz_reg_getv(R, "dr1"); + regs[2] = rz_reg_getv(R, "dr2"); + regs[3] = rz_reg_getv(R, "dr3"); + /* + RESERVED + regs[4] = rz_reg_getv (R, "dr4"); + regs[5] = rz_reg_getv (R, "dr5"); +*/ + regs[6] = rz_reg_getv(R, "dr6"); + regs[7] = rz_reg_getv(R, "dr7"); +} +#endif + +#if __i386__ || __x86_64__ +static void set_drx_regs(RzDebug *dbg, drxt *regs, size_t num_regs) { + /* sanity check, we rely on this assumption */ + if (num_regs != NUM_DRX_REGISTERS) { + eprintf("drx: Unsupported number of registers for get_debug_regs\n"); + return; + } + +#define R dbg->reg + rz_reg_setv(R, "dr0", regs[0]); + rz_reg_setv(R, "dr1", regs[1]); + rz_reg_setv(R, "dr2", regs[2]); + rz_reg_setv(R, "dr3", regs[3]); + rz_reg_setv(R, "dr6", regs[6]); + rz_reg_setv(R, "dr7", regs[7]); +} +#endif + +static int rz_debug_native_drx(RzDebug *dbg, int n, ut64 addr, int sz, int rwx, int g, int api_type) { +#if __i386__ || __x86_64__ + int retval = false; + drxt regs[NUM_DRX_REGISTERS] = { 0 }; + // sync drx regs + sync_drx_regs(dbg, regs, NUM_DRX_REGISTERS); + + switch (api_type) { + case DRX_API_LIST: + drx_list(regs); + retval = false; + break; + case DRX_API_GET_BP: + /* get the index of the breakpoint at addr */ + retval = drx_get_at(regs, addr); + break; + case DRX_API_REMOVE_BP: + /* remove hardware breakpoint */ + drx_set(regs, n, addr, -1, 0, 0); + retval = true; + break; + case DRX_API_SET_BP: + /* set hardware breakpoint */ + drx_set(regs, n, addr, sz, rwx, g); + retval = true; + break; + default: + /* this should not happen, someone misused the API */ + eprintf("drx: Unsupported api type in rz_debug_native_drx\n"); + retval = false; + } + + set_drx_regs(dbg, regs, NUM_DRX_REGISTERS); + + return retval; +#else + eprintf("drx: Unsupported platform\n"); +#endif + return -1; +} + +static int rz_debug_native_bp(RzBreakpoint *bp, RzBreakpointItem *b, bool set) { + if (b && b->hw) { +#if __i386__ || __x86_64__ + return set + ? drx_add((RzDebug *)bp->user, bp, b) + : drx_del((RzDebug *)bp->user, bp, b); +#endif + } + return false; +} + +static RzList /**/ *rz_debug_desc_native_list(int pid) { + return bsd_desc_list(pid); +} + +static int rz_debug_native_map_protect(RzDebug *dbg, ut64 addr, int size, int perms) { + return false; +} + +static int rz_debug_desc_native_open(const char *path) { + return 0; +} + +static bool rz_debug_gcore(RzDebug *dbg, char *path, RzBuffer *dest) { + return bsd_generate_corefile(dbg, path, dest); +} \ No newline at end of file diff --git a/librz/debug/p/OpenBSD.c b/librz/debug/p/OpenBSD.c new file mode 100644 index 00000000000..d03dbf3c2b0 --- /dev/null +++ b/librz/debug/p/OpenBSD.c @@ -0,0 +1,534 @@ +#include +#if !defined(__HAIKU__) && !defined(__sun) +#include +#endif +#include +#include + +#include "native/bsd/bsd_debug.h" +#include "native/procfs.h" + +#ifdef __WALL +#define WAITPID_FLAGS __WALL +#else +#define WAITPID_FLAGS 0 +#endif + +#define PROC_NAME_SZ 1024 +#define PROC_REGION_SZ 100 +// PROC_REGION_SZ - 2 (used for `0x`). Due to how RZ_STR_DEF works this can't be +// computed. +#define PROC_REGION_LEFT_SZ 98 +#define PROC_PERM_SZ 5 +#define PROC_UNKSTR_SZ 128 + +static int rz_debug_handle_signals(RzDebug *dbg) { + eprintf("Warning: signal handling is not supported on this platform\n"); + return 0; +} + +#include "native/reg.c" + +static bool rz_debug_native_step(RzDebug *dbg) { + int ret = ptrace(PT_STEP, dbg->pid, (caddr_t)1, 0); + if (ret != 0) { + perror("native-singlestep"); + return false; + } + return true; +} + +static int rz_debug_native_attach(RzDebug *dbg, int pid) { + int ret = ptrace(PTRACE_ATTACH, pid, 0, 0); + if (ret != -1) { + eprintf("Trying to attach to %d\n", pid); + perror("ptrace (PT_ATTACH)"); + } + return pid; +} + +static int rz_debug_native_detach(RzDebug *dbg, int pid) { + return ptrace(PT_DETACH, pid, NULL, 0); +} + +static int rz_debug_native_continue_syscall(RzDebug *dbg, int pid, int num) { + ut64 pc = rz_debug_reg_get(dbg, "PC"); + errno = 0; + return ptrace(PTRACE_SYSCALL, pid, (void *)(size_t)pc, 0) == 0; +} + +static int rz_debug_native_stop(RzDebug *dbg) { + return 0; +} + +static int rz_debug_native_continue(RzDebug *dbg, int pid, int tid, int sig) { + void *data = (void *)(size_t)((sig != -1) ? sig : dbg->reason.signum); + ut64 pc = rz_debug_reg_get(dbg, "PC"); + return ptrace(PTRACE_CONT, pid, (void *)(size_t)pc, (int)(size_t)data) == 0; +} + +static RzDebugInfo *rz_debug_native_info(RzDebug *dbg, const char *arg) { + return bsd_info(dbg, arg); +} + +static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { + RzDebugReasonType reason = RZ_DEBUG_REASON_UNKNOWN; + + if (pid == -1) { + eprintf("ERROR: rz_debug_native_wait called with pid -1\n"); + return RZ_DEBUG_REASON_ERROR; + } + int status = -1; +#ifdef WAIT_ON_ALL_CHILDREN + int ret = waitpid(-1, &status, WAITPID_FLAGS); +#else + int ret = waitpid(-1, &status, 0); + if (ret != -1) { + reason = RZ_DEBUG_REASON_TRAP; + } +#endif + if (ret == -1) { + rz_sys_perror("waitpid"); + return RZ_DEBUG_REASON_ERROR; + } + + // eprintf ("rz_debug_native_wait: status=%d (0x%x) (return=%d)\n", status, status, ret); + if (reason == RZ_DEBUG_REASON_ERROR) { + return reason; + } + /* we don't know what to do yet, let's try harder to figure it out. */ + if (reason == RZ_DEBUG_REASON_UNKNOWN) { + if (WIFEXITED(status)) { + eprintf("child exited with status %d\n", WEXITSTATUS(status)); + reason = RZ_DEBUG_REASON_DEAD; + } else if (WIFSIGNALED(status)) { + eprintf("child received signal %d\n", WTERMSIG(status)); + reason = RZ_DEBUG_REASON_SIGNAL; + } else if (WIFSTOPPED(status)) { + if (WSTOPSIG(status) != SIGTRAP && + WSTOPSIG(status) != SIGSTOP) { + eprintf("Child stopped with signal %d\n", WSTOPSIG(status)); + } + + /* the ptrace documentation says GETSIGINFO is only necessary for + * differentiating the various stops. + * + * this might modify dbg->reason.signum + */ + reason = RZ_DEBUG_REASON_BREAKPOINT; +#ifdef WIFCONTINUED + } else if (WIFCONTINUED(status)) { + eprintf("child continued...\n"); + reason = RZ_DEBUG_REASON_NONE; +#endif + } else if (status == 1) { + /* XXX(jjd): does this actually happen? */ + eprintf("debugger is dead with status 1!\n"); + reason = RZ_DEBUG_REASON_DEAD; + } else if (status == 0) { + /* XXX(jjd): does this actually happen? */ + eprintf("debugger is dead with status 0\n"); + reason = RZ_DEBUG_REASON_DEAD; + } else { + if (ret != pid) { + reason = RZ_DEBUG_REASON_NEW_PID; + } else { + /* ugh. still don't know :-/ */ + eprintf("returning from wait without knowing why...\n"); + } + } +} +/* if we still don't know what to do, we have a problem... */ +if (reason == RZ_DEBUG_REASON_UNKNOWN) { + eprintf("%s: no idea what happened...\n", __func__); + reason = RZ_DEBUG_REASON_ERROR; +} +dbg->reason.tid = pid; +dbg->reason.type = reason; +return reason; +} + +#undef MAXPID +#define MAXPID 99999 + +static RzList /**/ *rz_debug_native_pids(RzDebug *dbg, int pid) { + RzList *list = rz_list_new(); + if (!list) { + return NULL; + } + return bsd_pid_list(dbg, pid, list); +} + +RZ_API RZ_OWN RzList /**/ *rz_debug_native_threads(RzDebug *dbg, int pid) { + RzList *list = rz_list_new(); + if (!list) { + eprintf("No list?\n"); + return NULL; + } + return bsd_thread_list(dbg, pid, list); +} + +RZ_API ut64 rz_debug_get_tls(RZ_NONNULL RzDebug *dbg, int tid) { + rz_return_val_if_fail(dbg, 0); + return 0; +} + +static int bsd_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { + int showfpu = false; + int pid = dbg->pid; + int ret; + if (type < -1) { + showfpu = true; // hack for debugging + type = -type; + } + switch (type) { + case RZ_REG_TYPE_DRX: + return true; + break; + case RZ_REG_TYPE_FPU: + case RZ_REG_TYPE_MMX: + case RZ_REG_TYPE_XMM: + break; + case RZ_REG_TYPE_SEG: + case RZ_REG_TYPE_FLG: + case RZ_REG_TYPE_GPR: { + RZ_DEBUG_REG_T regs; + memset(®s, 0, sizeof(regs)); + memset(buf, 0, size); +#warning not implemented for this platform + ret = 1; + // if perror here says 'no such process' and the + // process exists still.. is because there's a + // missing call to 'wait'. and the process is not + // yet available to accept more ptrace queries. + if (ret != 0) + return false; + if (sizeof(regs) < size) + size = sizeof(regs); + memcpy(buf, ®s, size); + return sizeof(regs); + } break; + } + return true; +} + +static int rz_debug_native_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { + if (size < 1) { + return false; + } + return bsd_reg_read(dbg, type, buf, size); +} + +static int rz_debug_native_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size) { + // XXX use switch or so + if (type == RZ_REG_TYPE_DRX) { +#if __i386__ || __x86_64__ + return bsd_reg_write(dbg, type, buf, size); +#else // i386/x86-64 + return false; +#endif + } else if (type == RZ_REG_TYPE_GPR) { + return bsd_reg_write(dbg, type, buf, size); + } else if (type == RZ_REG_TYPE_FPU) { + return bsd_reg_write(dbg, type, buf, size); + } // else eprintf ("TODO: reg_write_non-gpr (%d)\n", type); + return false; +} + +static RzDebugMap *rz_debug_native_map_alloc(RzDebug *dbg, ut64 addr, int size, bool thp) { + // malloc not implemented for this platform + return NULL; +} + +static int rz_debug_native_map_dealloc(RzDebug *dbg, ut64 addr, int size) { + // mdealloc not implemented for this platform + return false; +} + +static void _map_free(RzDebugMap *map) { + if (!map) { + return; + } + free(map->name); + free(map->file); + free(map); +} + +static RzList /**/ *rz_debug_native_map_get(RzDebug *dbg) { + RzList *list = NULL; + RzDebugMap *map; + int i, perm, unk = 0; + char *pos_c; + char path[1024], line[1024], name[PROC_NAME_SZ + 1]; + char region[PROC_REGION_SZ + 1], region2[PROC_REGION_SZ + 1], perms[PROC_PERM_SZ + 1]; + FILE *fd; + if (dbg->pid == -1) { + // eprintf ("rz_debug_native_map_get: No selected pid (-1)\n"); + return NULL; + } + /* prepend 0x prefix */ + region[0] = region2[0] = '0'; + region[1] = region2[1] = 'x'; + + /* OpenBSD has no procfs, so no idea trying. */ + return bsd_native_sysctl_map(dbg); + + snprintf(path, sizeof(path), "/proc/%d/maps", dbg->pid); + + fd = rz_sys_fopen(path, "r"); + if (!fd) { + char *errmsg = rz_str_newf("Cannot open '%s'", path); + perror(errmsg); + free(errmsg); + return NULL; + } + + list = rz_list_new(); + if (!list) { + fclose(fd); + return NULL; + } + list->free = (RzListFree)_map_free; + while (!feof(fd)) { + size_t line_len; + bool map_is_shared = false; + ut64 map_start, map_end; + + if (!fgets(line, sizeof(line), fd)) { + break; + } + /* kill the newline if we got one */ + line_len = strlen(line); + if (line[line_len - 1] == '\n') { + line[line_len - 1] = '\0'; + line_len--; + } + /* maps files should not have empty lines */ + if (line_len == 0) { + break; + } + ut64 offset = 0; + // 7fc8124c4000-7fc81278d000 r--p 00000000 fc:00 17043921 /usr/lib/locale/locale-archive + i = sscanf(line, "%" RZ_STR_DEF(PROC_REGION_LEFT_SZ) "s %" RZ_STR_DEF(PROC_PERM_SZ) "s %08" PFMT64x " %*s %*s %" RZ_STR_DEF(PROC_NAME_SZ) "[^\n]", ®ion[2], perms, &offset, name); + if (i == 3) { + name[0] = '\0'; + } else if (i != 4) { + eprintf("%s: Unable to parse \"%s\"\n", __func__, path); + eprintf("%s: problematic line: %s\n", __func__, line); + rz_list_free(list); + return NULL; + } + + /* split the region in two */ + pos_c = strchr(®ion[2], '-'); + if (!pos_c) { // should this be an error? + continue; + } + strncpy(®ion2[2], pos_c + 1, sizeof(region2) - 2 - 1); + + if (!*name) { + snprintf(name, sizeof(name), "unk%d", unk++); + } + perm = 0; + for (i = 0; i < 5 && perms[i]; i++) { + switch (perms[i]) { + case 'r': perm |= RZ_PERM_R; break; + case 'w': perm |= RZ_PERM_W; break; + case 'x': perm |= RZ_PERM_X; break; + case 'p': map_is_shared = false; break; + case 's': map_is_shared = true; break; + } + } + + map_start = rz_num_get(NULL, region); + map_end = rz_num_get(NULL, region2); + if (map_start == map_end || map_end == 0) { + eprintf("%s: ignoring invalid map size: %s - %s\n", __func__, region, region2); + continue; + } + map = rz_debug_map_new(name, map_start, map_end, perm, 0); + if (!map) { + break; + } + map->file = strdup(name); + rz_list_append(list, map); + } + fclose(fd); + return list; +} + +static RzList /**/ *rz_debug_native_modules_get(RzDebug *dbg) { + char *lastname = NULL; + RzDebugMap *map; + RzListIter *iter, *iter2; + RzList *list, *last; + bool must_delete; + if (!(list = rz_debug_native_map_get(dbg))) { + return NULL; + } + if (!(last = rz_list_newf((RzListFree)rz_debug_map_free))) { + rz_list_free(list); + return NULL; + } + rz_list_foreach_safe (list, iter, iter2, map) { + const char *file = map->file; + if (!map->file) { + file = map->file = strdup(map->name); + } + must_delete = true; + if (file && *file == '/') { + if (!lastname || strcmp(lastname, file)) { + must_delete = false; + } + } + if (must_delete) { + rz_list_delete(list, iter); + } else { + rz_list_append(last, map); + free(lastname); + lastname = strdup(file); + } + } + list->free = NULL; + free(lastname); + rz_list_free(list); + return last; +} + +static bool rz_debug_native_kill(RzDebug *dbg, int pid, int tid, int sig) { + bool ret = false; + if (pid == 0) { + pid = dbg->pid; + } + if (sig == SIGKILL && dbg->threads) { + rz_list_free(dbg->threads); + dbg->threads = NULL; + } + if ((rz_sys_kill(pid, sig) != -1)) { + ret = true; + } + if (errno == 1) { + ret = -true; // EPERM + } + return ret; +} + +struct rz_debug_desc_plugin_t rz_debug_desc_plugin_native; +static bool rz_debug_native_init(RzDebug *dbg, void **user) { + dbg->cur->desc = rz_debug_desc_plugin_native; + return true; +} + +static void rz_debug_native_fini(RzDebug *dbg, void *user) { +} + +#if __i386__ || __x86_64__ +static void sync_drx_regs(RzDebug *dbg, drxt *regs, size_t num_regs) { + /* sanity check, we rely on this assumption */ + if (num_regs != NUM_DRX_REGISTERS) { + eprintf("drx: Unsupported number of registers for get_debug_regs\n"); + return; + } + + // sync drx regs +#define R dbg->reg + regs[0] = rz_reg_getv(R, "dr0"); + regs[1] = rz_reg_getv(R, "dr1"); + regs[2] = rz_reg_getv(R, "dr2"); + regs[3] = rz_reg_getv(R, "dr3"); + /* + RESERVED + regs[4] = rz_reg_getv (R, "dr4"); + regs[5] = rz_reg_getv (R, "dr5"); +*/ + regs[6] = rz_reg_getv(R, "dr6"); + regs[7] = rz_reg_getv(R, "dr7"); +} +#endif + +#if __i386__ || __x86_64__ +static void set_drx_regs(RzDebug *dbg, drxt *regs, size_t num_regs) { + /* sanity check, we rely on this assumption */ + if (num_regs != NUM_DRX_REGISTERS) { + eprintf("drx: Unsupported number of registers for get_debug_regs\n"); + return; + } + +#define R dbg->reg + rz_reg_setv(R, "dr0", regs[0]); + rz_reg_setv(R, "dr1", regs[1]); + rz_reg_setv(R, "dr2", regs[2]); + rz_reg_setv(R, "dr3", regs[3]); + rz_reg_setv(R, "dr6", regs[6]); + rz_reg_setv(R, "dr7", regs[7]); +} +#endif + +static int rz_debug_native_drx(RzDebug *dbg, int n, ut64 addr, int sz, int rwx, int g, int api_type) { +#if __i386__ || __x86_64__ + int retval = false; + drxt regs[NUM_DRX_REGISTERS] = { 0 }; + // sync drx regs + sync_drx_regs(dbg, regs, NUM_DRX_REGISTERS); + + switch (api_type) { + case DRX_API_LIST: + drx_list(regs); + retval = false; + break; + case DRX_API_GET_BP: + /* get the index of the breakpoint at addr */ + retval = drx_get_at(regs, addr); + break; + case DRX_API_REMOVE_BP: + /* remove hardware breakpoint */ + drx_set(regs, n, addr, -1, 0, 0); + retval = true; + break; + case DRX_API_SET_BP: + /* set hardware breakpoint */ + drx_set(regs, n, addr, sz, rwx, g); + retval = true; + break; + default: + /* this should not happen, someone misused the API */ + eprintf("drx: Unsupported api type in rz_debug_native_drx\n"); + retval = false; + } + + set_drx_regs(dbg, regs, NUM_DRX_REGISTERS); + + return retval; +#else + eprintf("drx: Unsupported platform\n"); +#endif + return -1; +} + +static int rz_debug_native_bp(RzBreakpoint *bp, RzBreakpointItem *b, bool set) { + if (b && b->hw) { +#if __i386__ || __x86_64__ + return set + ? drx_add((RzDebug *)bp->user, bp, b) + : drx_del((RzDebug *)bp->user, bp, b); +#endif + } + return false; +} + +static RzList /**/ *rz_debug_desc_native_list(int pid) { +#warning list filedescriptors not supported for this platform + return NULL; +} + +static int rz_debug_native_map_protect(RzDebug *dbg, ut64 addr, int size, int perms) { + return false; +} + +static int rz_debug_desc_native_open(const char *path) { + return 0; +} + +static bool rz_debug_gcore(RzDebug *dbg, char *path, RzBuffer *dest) { + return false; +} \ No newline at end of file diff --git a/librz/debug/p/android_arm.c b/librz/debug/p/android_arm.c new file mode 100644 index 00000000000..4fbc2349f4f --- /dev/null +++ b/librz/debug/p/android_arm.c @@ -0,0 +1,659 @@ +#include +#if !defined(__HAIKU__) && !defined(__sun) +#include +#endif +#include +#include + +#include +#include "native/linux/linux_debug.h" +#include "native/procfs.h" +#define WAIT_ANY -1 +#ifndef WIFCONTINUED +#define WIFCONTINUED(s) ((s) == 0xffff) +#endif + +#ifdef __WALL +#define WAITPID_FLAGS __WALL +#else +#define WAITPID_FLAGS 0 +#endif + +#define PROC_NAME_SZ 1024 +#define PROC_REGION_SZ 100 +// PROC_REGION_SZ - 2 (used for `0x`). Due to how RZ_STR_DEF works this can't be +// computed. +#define PROC_REGION_LEFT_SZ 98 +#define PROC_PERM_SZ 5 +#define PROC_UNKSTR_SZ 128 + +#if WAIT_ON_ALL_CHILDREN +static int rz_debug_handle_signals(RzDebug *dbg) { + eprintf("Warning: signal handling is not supported on this platform\n"); + return 0; +} +#endif + +static char *rz_debug_native_reg_profile(RzDebug *dbg) { + return linux_reg_profile(dbg); +} + +#include "native/reg.c" + +static bool rz_debug_native_step(RzDebug *dbg) { + return linux_step(dbg); +} + +static int rz_debug_native_attach(RzDebug *dbg, int pid) { + return linux_attach(dbg, pid); +} + +static int rz_debug_native_detach(RzDebug *dbg, int pid) { + return rz_debug_ptrace(dbg, PTRACE_DETACH, pid, NULL, (rz_ptrace_data_t)(size_t)0); +} + +static int rz_debug_native_select(RzDebug *dbg, int pid, int tid) { + return linux_select(dbg, pid, tid); +} + +static int rz_debug_native_continue_syscall(RzDebug *dbg, int pid, int num) { + linux_set_options(dbg, pid); + return rz_debug_ptrace(dbg, PTRACE_SYSCALL, pid, 0, 0); +} + +static void interrupt_process(RzDebug *dbg) { + rz_debug_kill(dbg, dbg->pid, dbg->tid, SIGINT); + rz_cons_break_pop(); +} + +static int rz_debug_native_stop(RzDebug *dbg) { + return linux_stop_threads(dbg, dbg->reason.tid); +} + +static int rz_debug_native_continue(RzDebug *dbg, int pid, int tid, int sig) { + int contsig = dbg->reason.signum; + int ret = -1; + + if (sig != -1) { + contsig = sig; + } + /* SIGINT handler for attached processes: dbg.consbreak (disabled by default) */ + if (dbg->consbreak) { + rz_cons_break_push((RzConsBreak)interrupt_process, dbg); + } + + if (dbg->continue_all_threads && dbg->n_threads && dbg->threads) { + RzDebugPid *th; + RzListIter *it; + rz_list_foreach (dbg->threads, it, th) { + ret = rz_debug_ptrace(dbg, PTRACE_CONT, th->pid, 0, 0); + if (ret) { + eprintf("Error: (%d) is running or dead.\n", th->pid); + } + } + } else { + ret = rz_debug_ptrace(dbg, PTRACE_CONT, tid, NULL, (rz_ptrace_data_t)(size_t)contsig); + if (ret) { + rz_sys_perror("PTRACE_CONT"); + } + } + // return ret >= 0 ? tid : false; + return tid; +} + +static RzDebugInfo *rz_debug_native_info(RzDebug *dbg, const char *arg) { + return linux_info(dbg, arg); +} + +#ifdef WAIT_ON_ALL_CHILDREN +static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { + RzDebugReasonType reason = RZ_DEBUG_REASON_UNKNOWN; + + if (pid == -1) { + eprintf("ERROR: rz_debug_native_wait called with pid -1\n"); + return RZ_DEBUG_REASON_ERROR; + } + int status = -1; + // XXX: this is blocking, ^C will be ignored + int ret = waitpid(-1, &status, WAITPID_FLAGS); + if (ret == -1) { + rz_sys_perror("waitpid"); + return RZ_DEBUG_REASON_ERROR; + } + + // eprintf ("rz_debug_native_wait: status=%d (0x%x) (return=%d)\n", status, status, ret); + + if (ret != pid) { + reason = RZ_DEBUG_REASON_NEW_PID; + eprintf("switching to pid %d\n", ret); + rz_debug_select(dbg, ret, ret); + } + + // TODO: switch status and handle reasons here + // FIXME: Remove linux handling from this function? +#if defined(PT_GETEVENTMSG) + reason = linux_ptrace_event(dbg, pid, status, true); +#endif + + /* propagate errors */ + if (reason == RZ_DEBUG_REASON_ERROR) { + return reason; + } + + /* we don't know what to do yet, let's try harder to figure it out. */ + if (reason == RZ_DEBUG_REASON_UNKNOWN) { + if (WIFEXITED(status)) { + eprintf("child exited with status %d\n", WEXITSTATUS(status)); + reason = RZ_DEBUG_REASON_DEAD; + } else if (WIFSIGNALED(status)) { + eprintf("child received signal %d\n", WTERMSIG(status)); + reason = RZ_DEBUG_REASON_SIGNAL; + } else if (WIFSTOPPED(status)) { + if (WSTOPSIG(status) != SIGTRAP && + WSTOPSIG(status) != SIGSTOP) { + eprintf("Child stopped with signal %d\n", WSTOPSIG(status)); + } + + /* the ptrace documentation says GETSIGINFO is only necessary for + * differentiating the various stops. + * + * this might modify dbg->reason.signum + */ + if (rz_debug_handle_signals(dbg) != 0) { + return RZ_DEBUG_REASON_ERROR; + } + reason = dbg->reason.type; +#ifdef WIFCONTINUED + } else if (WIFCONTINUED(status)) { + eprintf("child continued...\n"); + reason = RZ_DEBUG_REASON_NONE; +#endif + } else if (status == 1) { + /* XXX(jjd): does this actually happen? */ + eprintf("debugger is dead with status 1!\n"); + reason = RZ_DEBUG_REASON_DEAD; + } else if (status == 0) { + /* XXX(jjd): does this actually happen? */ + eprintf("debugger is dead with status 0\n"); + reason = RZ_DEBUG_REASON_DEAD; + } else { + if (ret != pid) { + reason = RZ_DEBUG_REASON_NEW_PID; + } else { + /* ugh. still don't know :-/ */ + eprintf("returning from wait without knowing why...\n"); + } + } + } + + /* if we still don't know what to do, we have a problem... */ + if (reason == RZ_DEBUG_REASON_UNKNOWN) { + eprintf("%s: no idea what happened...\n", __func__); + reason = RZ_DEBUG_REASON_ERROR; + } + dbg->reason.tid = pid; + dbg->reason.type = reason; + return reason; +} +#else +static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { + RzDebugReasonType reason = RZ_DEBUG_REASON_UNKNOWN; + if (pid == -1) { + eprintf("ERROR: rz_debug_native_wait called with pid -1\n"); + return RZ_DEBUG_REASON_ERROR; + } + + reason = linux_dbg_wait(dbg, dbg->tid); + dbg->reason.type = reason; + return reason; +} +#endif + +#undef MAXPID +#define MAXPID 99999 + +static RzList /**/ *rz_debug_native_pids(RzDebug *dbg, int pid) { + RzList *list = rz_list_new(); + if (!list) { + return NULL; + } + return linux_pid_list(pid, list); +} + +RZ_API RZ_OWN RzList /**/ *rz_debug_native_threads(RzDebug *dbg, int pid) { + RzList *list = rz_list_new(); + if (!list) { + eprintf("No list?\n"); + return NULL; + } + return linux_thread_list(dbg, pid, list); +} + +RZ_API ut64 rz_debug_get_tls(RZ_NONNULL RzDebug *dbg, int tid) { + rz_return_val_if_fail(dbg, 0); + return get_linux_tls_val(dbg, tid); +} + +static int rz_debug_native_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { + if (size < 1) { + return false; + } + return linux_reg_read(dbg, type, buf, size); +} + +static int rz_debug_native_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size) { + // XXX use switch or so + if (type == RZ_REG_TYPE_DRX) { + return false; + } else if (type == RZ_REG_TYPE_GPR) { + return linux_reg_write(dbg, type, buf, size); + } else if (type == RZ_REG_TYPE_FPU) { + return linux_reg_write(dbg, type, buf, size); + } // else eprintf ("TODO: reg_write_non-gpr (%d)\n", type); + return false; +} + +static int io_perms_to_prot(int io_perms) { + int prot_perms = PROT_NONE; + + if (io_perms & RZ_PERM_R) { + prot_perms |= PROT_READ; + } + if (io_perms & RZ_PERM_W) { + prot_perms |= PROT_WRITE; + } + if (io_perms & RZ_PERM_X) { + prot_perms |= PROT_EXEC; + } + return prot_perms; +} + +static int linux_map_thp(RzDebug *dbg, ut64 addr, int size) { +return false; +} + +static RzDebugMap *linux_map_alloc(RzDebug *dbg, ut64 addr, int size, bool thp) { + RzBuffer *buf = NULL; + RzDebugMap *map = NULL; + char code[1024], *sc_name; + int num; + /* force to usage of x86.as, not yet working x86.nz */ + char *asm_list[] = { + "x86", "x86.as", + "x64", "x86.as", + NULL + }; + + /* NOTE: Since kernel 2.4, that system call has been superseded by + mmap2(2 and nowadays the glibc mmap() wrapper function invokes + mmap2(2)). If arch is x86_32 then usage mmap2() */ + if (!strcmp(dbg->arch, "x86") && dbg->bits == 4) { + sc_name = "mmap2"; + } else { + sc_name = "mmap"; + } + num = rz_syscall_get_num(dbg->analysis->syscall, sc_name); +#ifndef MAP_ANONYMOUS +#define MAP_ANONYMOUS 0x20 +#endif + snprintf(code, sizeof(code), + "sc_mmap@syscall(%d);\n" + "main@naked(0) { .rarg0 = sc_mmap(0x%08" PFMT64x ",%d,%d,%d,%d,%d);break;\n" + "}\n", + num, addr, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + rz_egg_reset(dbg->egg); + rz_egg_setup(dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); + rz_egg_load(dbg->egg, code, 0); + if (!rz_egg_compile(dbg->egg)) { + eprintf("Cannot compile.\n"); + goto err_linux_map_alloc; + } + if (!rz_egg_assemble_asm(dbg->egg, asm_list)) { + eprintf("rz_egg_assemble: invalid assembly\n"); + goto err_linux_map_alloc; + } + buf = rz_egg_get_bin(dbg->egg); + if (buf) { + ut64 map_addr; + + rz_reg_arena_push(dbg->reg); + ut64 tmpsz; + const ut8 *tmp = rz_buf_data(buf, &tmpsz); + map_addr = rz_debug_execute(dbg, tmp, tmpsz, 1); + rz_reg_arena_pop(dbg->reg); + if (map_addr != (ut64)-1) { + if (thp) { + if (!linux_map_thp(dbg, map_addr, size)) { + // Not overly dramatic + eprintf("map promotion to huge page failed\n"); + } + } + rz_debug_map_sync(dbg); + map = rz_debug_map_get(dbg, map_addr); + } + } +err_linux_map_alloc: + return map; +} + +static int linux_map_dealloc(RzDebug *dbg, ut64 addr, int size) { + RzBuffer *buf = NULL; + char code[1024]; + int ret = 0; + char *asm_list[] = { + "x86", "x86.as", + "x64", "x86.as", + NULL + }; + int num = rz_syscall_get_num(dbg->analysis->syscall, "munmap"); + + snprintf(code, sizeof(code), + "sc_munmap@syscall(%d);\n" + "main@naked(0) { .rarg0 = sc_munmap(0x%08" PFMT64x ",%d);break;\n" + "}\n", + num, addr, size); + rz_egg_reset(dbg->egg); + rz_egg_setup(dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); + rz_egg_load(dbg->egg, code, 0); + if (!rz_egg_compile(dbg->egg)) { + eprintf("Cannot compile.\n"); + goto err_linux_map_dealloc; + } + if (!rz_egg_assemble_asm(dbg->egg, asm_list)) { + eprintf("rz_egg_assemble: invalid assembly\n"); + goto err_linux_map_dealloc; + } + buf = rz_egg_get_bin(dbg->egg); + if (buf) { + rz_reg_arena_push(dbg->reg); + ut64 tmpsz; + const ut8 *tmp = rz_buf_data(buf, &tmpsz); + ret = rz_debug_execute(dbg, tmp, tmpsz, 1) == 0; + rz_reg_arena_pop(dbg->reg); + } +err_linux_map_dealloc: + return ret; +} + +static RzDebugMap *rz_debug_native_map_alloc(RzDebug *dbg, ut64 addr, int size, bool thp) { + return linux_map_alloc(dbg, addr, size, thp); +} + +static int rz_debug_native_map_dealloc(RzDebug *dbg, ut64 addr, int size) { + return linux_map_dealloc(dbg, addr, size); +} + +static void _map_free(RzDebugMap *map) { + if (!map) { + return; + } + free(map->name); + free(map->file); + free(map); +} + +static RzList /**/ *rz_debug_native_map_get(RzDebug *dbg) { + RzList *list = NULL; + RzDebugMap *map; + int i, perm, unk = 0; + char *pos_c; + char path[1024], line[1024], name[PROC_NAME_SZ + 1]; + char region[PROC_REGION_SZ + 1], region2[PROC_REGION_SZ + 1], perms[PROC_PERM_SZ + 1]; + FILE *fd; + if (dbg->pid == -1) { + // eprintf ("rz_debug_native_map_get: No selected pid (-1)\n"); + return NULL; + } + /* prepend 0x prefix */ + region[0] = region2[0] = '0'; + region[1] = region2[1] = 'x'; + + snprintf(path, sizeof(path), "/proc/%d/maps", dbg->pid); + + fd = rz_sys_fopen(path, "r"); + if (!fd) { + char *errmsg = rz_str_newf("Cannot open '%s'", path); + perror(errmsg); + free(errmsg); + return NULL; + } + + list = rz_list_new(); + if (!list) { + fclose(fd); + return NULL; + } + list->free = (RzListFree)_map_free; + while (!feof(fd)) { + size_t line_len; + bool map_is_shared = false; + ut64 map_start, map_end; + + if (!fgets(line, sizeof(line), fd)) { + break; + } + /* kill the newline if we got one */ + line_len = strlen(line); + if (line[line_len - 1] == '\n') { + line[line_len - 1] = '\0'; + line_len--; + } + /* maps files should not have empty lines */ + if (line_len == 0) { + break; + } + + ut64 offset = 0; + // 7fc8124c4000-7fc81278d000 r--p 00000000 fc:00 17043921 /usr/lib/locale/locale-archive + i = sscanf(line, "%" RZ_STR_DEF(PROC_REGION_LEFT_SZ) "s %" RZ_STR_DEF(PROC_PERM_SZ) "s %08" PFMT64x " %*s %*s %" RZ_STR_DEF(PROC_NAME_SZ) "[^\n]", ®ion[2], perms, &offset, name); + if (i == 3) { + name[0] = '\0'; + } else if (i != 4) { + eprintf("%s: Unable to parse \"%s\"\n", __func__, path); + eprintf("%s: problematic line: %s\n", __func__, line); + rz_list_free(list); + return NULL; + } + + /* split the region in two */ + pos_c = strchr(®ion[2], '-'); + if (!pos_c) { // should this be an error? + continue; + } + strncpy(®ion2[2], pos_c + 1, sizeof(region2) - 2 - 1); + + if (!*name) { + snprintf(name, sizeof(name), "unk%d", unk++); + } + perm = 0; + for (i = 0; i < 5 && perms[i]; i++) { + switch (perms[i]) { + case 'r': perm |= RZ_PERM_R; break; + case 'w': perm |= RZ_PERM_W; break; + case 'x': perm |= RZ_PERM_X; break; + case 'p': map_is_shared = false; break; + case 's': map_is_shared = true; break; + } + } + + map_start = rz_num_get(NULL, region); + map_end = rz_num_get(NULL, region2); + if (map_start == map_end || map_end == 0) { + eprintf("%s: ignoring invalid map size: %s - %s\n", __func__, region, region2); + continue; + } + map = rz_debug_map_new(name, map_start, map_end, perm, 0); + if (!map) { + break; + } + map->offset = offset; + map->shared = map_is_shared; + map->file = strdup(name); + rz_list_append(list, map); + } + fclose(fd); + return list; +} + +static RzList /**/ *rz_debug_native_modules_get(RzDebug *dbg) { + char *lastname = NULL; + RzDebugMap *map; + RzListIter *iter, *iter2; + RzList *list, *last; + bool must_delete; + if (!(list = rz_debug_native_map_get(dbg))) { + return NULL; + } + if (!(last = rz_list_newf((RzListFree)rz_debug_map_free))) { + rz_list_free(list); + return NULL; + } + rz_list_foreach_safe (list, iter, iter2, map) { + const char *file = map->file; + if (!map->file) { + file = map->file = strdup(map->name); + } + must_delete = true; + if (file && *file == '/') { + if (!lastname || strcmp(lastname, file)) { + must_delete = false; + } + } + if (must_delete) { + rz_list_delete(list, iter); + } else { + rz_list_append(last, map); + free(lastname); + lastname = strdup(file); + } + } + list->free = NULL; + free(lastname); + rz_list_free(list); + return last; +} + +static bool rz_debug_native_kill(RzDebug *dbg, int pid, int tid, int sig) { + bool ret = false; + if (pid == 0) { + pid = dbg->pid; + } + if (sig == SIGKILL && dbg->threads) { + rz_list_free(dbg->threads); + dbg->threads = NULL; + } + if ((rz_sys_kill(pid, sig) != -1)) { + ret = true; + } + if (errno == 1) { + ret = -true; // EPERM + } + return ret; +} + +struct rz_debug_desc_plugin_t rz_debug_desc_plugin_native; +static bool rz_debug_native_init(RzDebug *dbg, void **user) { + dbg->cur->desc = rz_debug_desc_plugin_native; + return true; +} + +static void rz_debug_native_fini(RzDebug *dbg, void *user) { +} + + +static int rz_debug_native_drx(RzDebug *dbg, int n, ut64 addr, int sz, int rwx, int g, int api_type) { + eprintf("drx: Unsupported platform\n"); + return -1; +} + +#include +#include + +#define NT_ARM_VFP 0x400 /* ARM VFP/NEON registers */ +#define NT_ARM_TLS 0x401 /* ARM TLS register */ +#define NT_ARM_HW_BREAK 0x402 /* ARM hardware breakpoint registers */ +#define NT_ARM_HW_WATCH 0x403 /* ARM hardware watchpoint registers */ +#define NT_ARM_SYSTEM_CALL 0x404 /* ARM system call number */ + +#ifndef PTRACE_GETHBPREGS +#define PTRACE_GETHBPREGS 29 +#define PTRACE_SETHBPREGS 30 +#endif + + +static bool ll_arm32_hwbp_set(pid_t pid, ut64 addr, int size, int wp, int type) { + const unsigned byte_mask = (1 << size) - 1; + // const unsigned type = 2; // Write. + const unsigned enable = 1; + const unsigned control = byte_mask << 5 | type << 3 | enable; + (void)ptrace(PTRACE_SETHBPREGS, pid, -1, (void *)(size_t)addr); + return ptrace(PTRACE_SETHBPREGS, pid, -2, &control) != -1; +} + +static bool arm32_hwbp_add(RzDebug *dbg, RzBreakpoint *bp, RzBreakpointItem *b) { + return ll_arm32_hwbp_set(dbg->pid, b->addr, b->size, 0, 1 | 2 | 4); +} + +static bool arm32_hwbp_del(RzDebug *dbg, RzBreakpoint *bp, RzBreakpointItem *b) { + return false; // TODO: hwbp.del not yetimplemented +} + + +static int rz_debug_native_bp(RzBreakpoint *bp, RzBreakpointItem *b, bool set) { + if (b && b->hw) { + return set + ? arm32_hwbp_add((RzDebug *)bp->user, bp, b) + : arm32_hwbp_del((RzDebug *)bp->user, bp, b); + } + return false; +} + +static RzList /**/ *rz_debug_desc_native_list(int pid) { + return linux_desc_list(pid); +} + +static int rz_debug_native_map_protect(RzDebug *dbg, ut64 addr, int size, int perms) { + RzBuffer *buf = NULL; + char code[1024]; + int num; + + num = rz_syscall_get_num(dbg->analysis->syscall, "mprotect"); + snprintf(code, sizeof(code), + "sc@syscall(%d);\n" + "main@global(0) { sc(%p,%d,%d);\n" + ":int3\n" + "}\n", + num, (void *)(size_t)addr, size, io_perms_to_prot(perms)); + + rz_egg_reset(dbg->egg); + rz_egg_setup(dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); + rz_egg_load(dbg->egg, code, 0); + if (!rz_egg_compile(dbg->egg)) { + eprintf("Cannot compile.\n"); + return false; + } + if (!rz_egg_assemble(dbg->egg)) { + eprintf("rz_egg_assemble: invalid assembly\n"); + return false; + } + buf = rz_egg_get_bin(dbg->egg); + if (buf) { + rz_reg_arena_push(dbg->reg); + ut64 tmpsz; + const ut8 *tmp = rz_buf_data(buf, &tmpsz); + rz_debug_execute(dbg, tmp, tmpsz, 1); + rz_reg_arena_pop(dbg->reg); + return true; + } + + return false; +} + +static int rz_debug_desc_native_open(const char *path) { + return 0; +} + +static bool rz_debug_gcore(RzDebug *dbg, char *path, RzBuffer *dest) { + (void)path; + return false; +} \ No newline at end of file diff --git a/librz/debug/p/android_arm64.c b/librz/debug/p/android_arm64.c new file mode 100644 index 00000000000..d1e260f962e --- /dev/null +++ b/librz/debug/p/android_arm64.c @@ -0,0 +1,711 @@ +#include +#if !defined(__HAIKU__) && !defined(__sun) +#include +#endif +#include +#include + +#include +#include "native/linux/linux_debug.h" +#include "native/procfs.h" +#define WAIT_ANY -1 +#ifndef WIFCONTINUED +#define WIFCONTINUED(s) ((s) == 0xffff) +#endif + +#ifdef __WALL +#define WAITPID_FLAGS __WALL +#else +#define WAITPID_FLAGS 0 +#endif + +#define PROC_NAME_SZ 1024 +#define PROC_REGION_SZ 100 +// PROC_REGION_SZ - 2 (used for `0x`). Due to how RZ_STR_DEF works this can't be +// computed. +#define PROC_REGION_LEFT_SZ 98 +#define PROC_PERM_SZ 5 +#define PROC_UNKSTR_SZ 128 + +#if WAIT_ON_ALL_CHILDREN +static int rz_debug_handle_signals(RzDebug *dbg) { + eprintf("Warning: signal handling is not supported on this platform\n"); + return 0; +} +#endif + +static char *rz_debug_native_reg_profile(RzDebug *dbg) { + return linux_reg_profile(dbg); +} + +#include "native/reg.c" + +static bool rz_debug_native_step(RzDebug *dbg) { + return linux_step(dbg); +} + +static int rz_debug_native_attach(RzDebug *dbg, int pid) { + return linux_attach(dbg, pid); +} + +static int rz_debug_native_detach(RzDebug *dbg, int pid) { + return rz_debug_ptrace(dbg, PTRACE_DETACH, pid, NULL, (rz_ptrace_data_t)(size_t)0); +} + +static int rz_debug_native_select(RzDebug *dbg, int pid, int tid) { + return linux_select(dbg, pid, tid); +} + +static int rz_debug_native_continue_syscall(RzDebug *dbg, int pid, int num) { + linux_set_options(dbg, pid); + return rz_debug_ptrace(dbg, PTRACE_SYSCALL, pid, 0, 0); +} + +static void interrupt_process(RzDebug *dbg) { + rz_debug_kill(dbg, dbg->pid, dbg->tid, SIGINT); + rz_cons_break_pop(); +} + +static int rz_debug_native_stop(RzDebug *dbg) { + return linux_stop_threads(dbg, dbg->reason.tid); +} + +static int rz_debug_native_continue(RzDebug *dbg, int pid, int tid, int sig) { + int contsig = dbg->reason.signum; + int ret = -1; + + if (sig != -1) { + contsig = sig; + } + /* SIGINT handler for attached processes: dbg.consbreak (disabled by default) */ + if (dbg->consbreak) { + rz_cons_break_push((RzConsBreak)interrupt_process, dbg); + } + + if (dbg->continue_all_threads && dbg->n_threads && dbg->threads) { + RzDebugPid *th; + RzListIter *it; + rz_list_foreach (dbg->threads, it, th) { + ret = rz_debug_ptrace(dbg, PTRACE_CONT, th->pid, 0, 0); + if (ret) { + eprintf("Error: (%d) is running or dead.\n", th->pid); + } + } + } else { + ret = rz_debug_ptrace(dbg, PTRACE_CONT, tid, NULL, (rz_ptrace_data_t)(size_t)contsig); + if (ret) { + rz_sys_perror("PTRACE_CONT"); + } + } + // return ret >= 0 ? tid : false; + return tid; +} + +static RzDebugInfo *rz_debug_native_info(RzDebug *dbg, const char *arg) { + return linux_info(dbg, arg); +} + +#ifdef WAIT_ON_ALL_CHILDREN +static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { + RzDebugReasonType reason = RZ_DEBUG_REASON_UNKNOWN; + + if (pid == -1) { + eprintf("ERROR: rz_debug_native_wait called with pid -1\n"); + return RZ_DEBUG_REASON_ERROR; + } + int status = -1; + // XXX: this is blocking, ^C will be ignored + int ret = waitpid(-1, &status, WAITPID_FLAGS); + if (ret == -1) { + rz_sys_perror("waitpid"); + return RZ_DEBUG_REASON_ERROR; + } + + // eprintf ("rz_debug_native_wait: status=%d (0x%x) (return=%d)\n", status, status, ret); + + if (ret != pid) { + reason = RZ_DEBUG_REASON_NEW_PID; + eprintf("switching to pid %d\n", ret); + rz_debug_select(dbg, ret, ret); + } + + // TODO: switch status and handle reasons here + // FIXME: Remove linux handling from this function? +#if defined(PT_GETEVENTMSG) + reason = linux_ptrace_event(dbg, pid, status, true); +#endif + + /* propagate errors */ + if (reason == RZ_DEBUG_REASON_ERROR) { + return reason; + } + + /* we don't know what to do yet, let's try harder to figure it out. */ + if (reason == RZ_DEBUG_REASON_UNKNOWN) { + if (WIFEXITED(status)) { + eprintf("child exited with status %d\n", WEXITSTATUS(status)); + reason = RZ_DEBUG_REASON_DEAD; + } else if (WIFSIGNALED(status)) { + eprintf("child received signal %d\n", WTERMSIG(status)); + reason = RZ_DEBUG_REASON_SIGNAL; + } else if (WIFSTOPPED(status)) { + if (WSTOPSIG(status) != SIGTRAP && + WSTOPSIG(status) != SIGSTOP) { + eprintf("Child stopped with signal %d\n", WSTOPSIG(status)); + } + + /* the ptrace documentation says GETSIGINFO is only necessary for + * differentiating the various stops. + * + * this might modify dbg->reason.signum + */ + if (rz_debug_handle_signals(dbg) != 0) { + return RZ_DEBUG_REASON_ERROR; + } + reason = dbg->reason.type; +#ifdef WIFCONTINUED + } else if (WIFCONTINUED(status)) { + eprintf("child continued...\n"); + reason = RZ_DEBUG_REASON_NONE; +#endif + } else if (status == 1) { + /* XXX(jjd): does this actually happen? */ + eprintf("debugger is dead with status 1!\n"); + reason = RZ_DEBUG_REASON_DEAD; + } else if (status == 0) { + /* XXX(jjd): does this actually happen? */ + eprintf("debugger is dead with status 0\n"); + reason = RZ_DEBUG_REASON_DEAD; + } else { + if (ret != pid) { + reason = RZ_DEBUG_REASON_NEW_PID; + } else { + /* ugh. still don't know :-/ */ + eprintf("returning from wait without knowing why...\n"); + } + } + } + + /* if we still don't know what to do, we have a problem... */ + if (reason == RZ_DEBUG_REASON_UNKNOWN) { + eprintf("%s: no idea what happened...\n", __func__); + reason = RZ_DEBUG_REASON_ERROR; + } + dbg->reason.tid = pid; + dbg->reason.type = reason; + return reason; +} +#else +static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { + RzDebugReasonType reason = RZ_DEBUG_REASON_UNKNOWN; + if (pid == -1) { + eprintf("ERROR: rz_debug_native_wait called with pid -1\n"); + return RZ_DEBUG_REASON_ERROR; + } + + reason = linux_dbg_wait(dbg, dbg->tid); + dbg->reason.type = reason; + return reason; +} +#endif + +#undef MAXPID +#define MAXPID 99999 + +static RzList /**/ *rz_debug_native_pids(RzDebug *dbg, int pid) { + RzList *list = rz_list_new(); + if (!list) { + return NULL; + } + return linux_pid_list(pid, list); +} + +RZ_API RZ_OWN RzList /**/ *rz_debug_native_threads(RzDebug *dbg, int pid) { + RzList *list = rz_list_new(); + if (!list) { + eprintf("No list?\n"); + return NULL; + } + return linux_thread_list(dbg, pid, list); +} + +RZ_API ut64 rz_debug_get_tls(RZ_NONNULL RzDebug *dbg, int tid) { + rz_return_val_if_fail(dbg, 0); + return get_linux_tls_val(dbg, tid); +} + +static int rz_debug_native_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { + if (size < 1) { + return false; + } + return linux_reg_read(dbg, type, buf, size); +} + +static int rz_debug_native_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size) { + // XXX use switch or so + if (type == RZ_REG_TYPE_DRX) { + return false; + } else if (type == RZ_REG_TYPE_GPR) { + return linux_reg_write(dbg, type, buf, size); + } else if (type == RZ_REG_TYPE_FPU) { + return linux_reg_write(dbg, type, buf, size); + } // else eprintf ("TODO: reg_write_non-gpr (%d)\n", type); + return false; +} + +static int io_perms_to_prot(int io_perms) { + int prot_perms = PROT_NONE; + + if (io_perms & RZ_PERM_R) { + prot_perms |= PROT_READ; + } + if (io_perms & RZ_PERM_W) { + prot_perms |= PROT_WRITE; + } + if (io_perms & RZ_PERM_X) { + prot_perms |= PROT_EXEC; + } + return prot_perms; +} + +static int linux_map_thp(RzDebug *dbg, ut64 addr, int size) { +return false; +} + +static RzDebugMap *linux_map_alloc(RzDebug *dbg, ut64 addr, int size, bool thp) { + RzBuffer *buf = NULL; + RzDebugMap *map = NULL; + char code[1024], *sc_name; + int num; + /* force to usage of x86.as, not yet working x86.nz */ + char *asm_list[] = { + "x86", "x86.as", + "x64", "x86.as", + NULL + }; + + /* NOTE: Since kernel 2.4, that system call has been superseded by + mmap2(2 and nowadays the glibc mmap() wrapper function invokes + mmap2(2)). If arch is x86_32 then usage mmap2() */ + if (!strcmp(dbg->arch, "x86") && dbg->bits == 4) { + sc_name = "mmap2"; + } else { + sc_name = "mmap"; + } + num = rz_syscall_get_num(dbg->analysis->syscall, sc_name); +#ifndef MAP_ANONYMOUS +#define MAP_ANONYMOUS 0x20 +#endif + snprintf(code, sizeof(code), + "sc_mmap@syscall(%d);\n" + "main@naked(0) { .rarg0 = sc_mmap(0x%08" PFMT64x ",%d,%d,%d,%d,%d);break;\n" + "}\n", + num, addr, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + rz_egg_reset(dbg->egg); + rz_egg_setup(dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); + rz_egg_load(dbg->egg, code, 0); + if (!rz_egg_compile(dbg->egg)) { + eprintf("Cannot compile.\n"); + goto err_linux_map_alloc; + } + if (!rz_egg_assemble_asm(dbg->egg, asm_list)) { + eprintf("rz_egg_assemble: invalid assembly\n"); + goto err_linux_map_alloc; + } + buf = rz_egg_get_bin(dbg->egg); + if (buf) { + ut64 map_addr; + + rz_reg_arena_push(dbg->reg); + ut64 tmpsz; + const ut8 *tmp = rz_buf_data(buf, &tmpsz); + map_addr = rz_debug_execute(dbg, tmp, tmpsz, 1); + rz_reg_arena_pop(dbg->reg); + if (map_addr != (ut64)-1) { + if (thp) { + if (!linux_map_thp(dbg, map_addr, size)) { + // Not overly dramatic + eprintf("map promotion to huge page failed\n"); + } + } + rz_debug_map_sync(dbg); + map = rz_debug_map_get(dbg, map_addr); + } + } +err_linux_map_alloc: + return map; +} + +static int linux_map_dealloc(RzDebug *dbg, ut64 addr, int size) { + RzBuffer *buf = NULL; + char code[1024]; + int ret = 0; + char *asm_list[] = { + "x86", "x86.as", + "x64", "x86.as", + NULL + }; + int num = rz_syscall_get_num(dbg->analysis->syscall, "munmap"); + + snprintf(code, sizeof(code), + "sc_munmap@syscall(%d);\n" + "main@naked(0) { .rarg0 = sc_munmap(0x%08" PFMT64x ",%d);break;\n" + "}\n", + num, addr, size); + rz_egg_reset(dbg->egg); + rz_egg_setup(dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); + rz_egg_load(dbg->egg, code, 0); + if (!rz_egg_compile(dbg->egg)) { + eprintf("Cannot compile.\n"); + goto err_linux_map_dealloc; + } + if (!rz_egg_assemble_asm(dbg->egg, asm_list)) { + eprintf("rz_egg_assemble: invalid assembly\n"); + goto err_linux_map_dealloc; + } + buf = rz_egg_get_bin(dbg->egg); + if (buf) { + rz_reg_arena_push(dbg->reg); + ut64 tmpsz; + const ut8 *tmp = rz_buf_data(buf, &tmpsz); + ret = rz_debug_execute(dbg, tmp, tmpsz, 1) == 0; + rz_reg_arena_pop(dbg->reg); + } +err_linux_map_dealloc: + return ret; +} + +static RzDebugMap *rz_debug_native_map_alloc(RzDebug *dbg, ut64 addr, int size, bool thp) { + return linux_map_alloc(dbg, addr, size, thp); +} + +static int rz_debug_native_map_dealloc(RzDebug *dbg, ut64 addr, int size) { + return linux_map_dealloc(dbg, addr, size); +} + +static void _map_free(RzDebugMap *map) { + if (!map) { + return; + } + free(map->name); + free(map->file); + free(map); +} + +static RzList /**/ *rz_debug_native_map_get(RzDebug *dbg) { + RzList *list = NULL; + RzDebugMap *map; + int i, perm, unk = 0; + char *pos_c; + char path[1024], line[1024], name[PROC_NAME_SZ + 1]; + char region[PROC_REGION_SZ + 1], region2[PROC_REGION_SZ + 1], perms[PROC_PERM_SZ + 1]; + FILE *fd; + if (dbg->pid == -1) { + // eprintf ("rz_debug_native_map_get: No selected pid (-1)\n"); + return NULL; + } + /* prepend 0x prefix */ + region[0] = region2[0] = '0'; + region[1] = region2[1] = 'x'; + + snprintf(path, sizeof(path), "/proc/%d/maps", dbg->pid); + + fd = rz_sys_fopen(path, "r"); + if (!fd) { + char *errmsg = rz_str_newf("Cannot open '%s'", path); + perror(errmsg); + free(errmsg); + return NULL; + } + + list = rz_list_new(); + if (!list) { + fclose(fd); + return NULL; + } + list->free = (RzListFree)_map_free; + while (!feof(fd)) { + size_t line_len; + bool map_is_shared = false; + ut64 map_start, map_end; + + if (!fgets(line, sizeof(line), fd)) { + break; + } + /* kill the newline if we got one */ + line_len = strlen(line); + if (line[line_len - 1] == '\n') { + line[line_len - 1] = '\0'; + line_len--; + } + /* maps files should not have empty lines */ + if (line_len == 0) { + break; + } + + ut64 offset = 0; + // 7fc8124c4000-7fc81278d000 r--p 00000000 fc:00 17043921 /usr/lib/locale/locale-archive + i = sscanf(line, "%" RZ_STR_DEF(PROC_REGION_LEFT_SZ) "s %" RZ_STR_DEF(PROC_PERM_SZ) "s %08" PFMT64x " %*s %*s %" RZ_STR_DEF(PROC_NAME_SZ) "[^\n]", ®ion[2], perms, &offset, name); + if (i == 3) { + name[0] = '\0'; + } else if (i != 4) { + eprintf("%s: Unable to parse \"%s\"\n", __func__, path); + eprintf("%s: problematic line: %s\n", __func__, line); + rz_list_free(list); + return NULL; + } + + /* split the region in two */ + pos_c = strchr(®ion[2], '-'); + if (!pos_c) { // should this be an error? + continue; + } + strncpy(®ion2[2], pos_c + 1, sizeof(region2) - 2 - 1); + + if (!*name) { + snprintf(name, sizeof(name), "unk%d", unk++); + } + perm = 0; + for (i = 0; i < 5 && perms[i]; i++) { + switch (perms[i]) { + case 'r': perm |= RZ_PERM_R; break; + case 'w': perm |= RZ_PERM_W; break; + case 'x': perm |= RZ_PERM_X; break; + case 'p': map_is_shared = false; break; + case 's': map_is_shared = true; break; + } + } + + map_start = rz_num_get(NULL, region); + map_end = rz_num_get(NULL, region2); + if (map_start == map_end || map_end == 0) { + eprintf("%s: ignoring invalid map size: %s - %s\n", __func__, region, region2); + continue; + } + map = rz_debug_map_new(name, map_start, map_end, perm, 0); + if (!map) { + break; + } + map->offset = offset; + map->shared = map_is_shared; + map->file = strdup(name); + rz_list_append(list, map); + } + fclose(fd); + return list; +} + +static RzList /**/ *rz_debug_native_modules_get(RzDebug *dbg) { + char *lastname = NULL; + RzDebugMap *map; + RzListIter *iter, *iter2; + RzList *list, *last; + bool must_delete; + if (!(list = rz_debug_native_map_get(dbg))) { + return NULL; + } + if (!(last = rz_list_newf((RzListFree)rz_debug_map_free))) { + rz_list_free(list); + return NULL; + } + rz_list_foreach_safe (list, iter, iter2, map) { + const char *file = map->file; + if (!map->file) { + file = map->file = strdup(map->name); + } + must_delete = true; + if (file && *file == '/') { + if (!lastname || strcmp(lastname, file)) { + must_delete = false; + } + } + if (must_delete) { + rz_list_delete(list, iter); + } else { + rz_list_append(last, map); + free(lastname); + lastname = strdup(file); + } + } + list->free = NULL; + free(lastname); + rz_list_free(list); + return last; +} + +static bool rz_debug_native_kill(RzDebug *dbg, int pid, int tid, int sig) { + bool ret = false; + if (pid == 0) { + pid = dbg->pid; + } + if (sig == SIGKILL && dbg->threads) { + rz_list_free(dbg->threads); + dbg->threads = NULL; + } + if ((rz_sys_kill(pid, sig) != -1)) { + ret = true; + } + if (errno == 1) { + ret = -true; // EPERM + } + return ret; +} + +struct rz_debug_desc_plugin_t rz_debug_desc_plugin_native; +static bool rz_debug_native_init(RzDebug *dbg, void **user) { + dbg->cur->desc = rz_debug_desc_plugin_native; + return true; +} + +static void rz_debug_native_fini(RzDebug *dbg, void *user) { +} + + +static int rz_debug_native_drx(RzDebug *dbg, int n, ut64 addr, int sz, int rwx, int g, int api_type) { + eprintf("drx: Unsupported platform\n"); + return -1; +} + +#include +#include + +#define NT_ARM_VFP 0x400 /* ARM VFP/NEON registers */ +#define NT_ARM_TLS 0x401 /* ARM TLS register */ +#define NT_ARM_HW_BREAK 0x402 /* ARM hardware breakpoint registers */ +#define NT_ARM_HW_WATCH 0x403 /* ARM hardware watchpoint registers */ +#define NT_ARM_SYSTEM_CALL 0x404 /* ARM system call number */ + +#ifndef PTRACE_GETHBPREGS +#define PTRACE_GETHBPREGS 29 +#define PTRACE_SETHBPREGS 30 +#endif + + +#if PTRACE_GETREGSET +// type = 2 = write +// static volatile uint8_t var[96] __attribute__((__aligned__(32))); + +static bool ll_arm64_hwbp_set(pid_t pid, ut64 _addr, int size, int wp, ut32 type) { + const volatile uint8_t *addr = (void *)(size_t)_addr; //&var[32 + wp]; + const unsigned int offset = (uintptr_t)addr % 8; + const ut32 byte_mask = ((1 << size) - 1) << offset; + const ut32 enable = 1; + const ut32 control = byte_mask << 5 | type << 3 | enable; + + struct user_hwdebug_state dreg_state = { 0 }; + struct iovec iov = { 0 }; + iov.iov_base = &dreg_state; + iov.iov_len = sizeof(dreg_state); + + if (ptrace(PTRACE_GETREGSET, pid, NT_ARM_HW_WATCH, &iov) == -1) { + // error reading regs + } + memcpy(&dreg_state, iov.iov_base, sizeof(dreg_state)); + // wp is not honored here i think... we can't have more than one wp for now.. + dreg_state.dbg_regs[0].addr = (uintptr_t)(addr - offset); + dreg_state.dbg_regs[0].ctrl = control; + iov.iov_base = &dreg_state; + iov.iov_len = rz_offsetof(struct user_hwdebug_state, dbg_regs) + + sizeof(dreg_state.dbg_regs[0]); + if (ptrace(PTRACE_SETREGSET, pid, NT_ARM_HW_WATCH, &iov) == 0) { + return true; + } + + if (errno == EIO) { + eprintf("ptrace(PTRACE_SETREGSET, NT_ARM_HW_WATCH) not supported on this hardware: %s\n", + strerror(errno)); + } + + eprintf("ptrace(PTRACE_SETREGSET, NT_ARM_HW_WATCH) failed: %s\n", strerror(errno)); + return false; +} + +static bool ll_arm64_hwbp_del(pid_t pid, ut64 _addr, int size, int wp, ut32 type) { + // const volatile uint8_t *addr = &var[32 + wp]; + // TODO: support multiple watchpoints and find + struct user_hwdebug_state dreg_state = { 0 }; + struct iovec iov = { 0 }; + iov.iov_base = &dreg_state; + // only delete 1 bp for now + iov.iov_len = rz_offsetof(struct user_hwdebug_state, dbg_regs) + + sizeof(dreg_state.dbg_regs[0]); + if (ptrace(PTRACE_SETREGSET, pid, NT_ARM_HW_WATCH, &iov) == 0) { + return true; + } + if (errno == EIO) { + eprintf("ptrace(PTRACE_SETREGSET, NT_ARM_HW_WATCH) not supported on this hardware: %s\n", + strerror(errno)); + } + + eprintf("ptrace(PTRACE_SETREGSET, NT_ARM_HW_WATCH) failed: %s\n", strerror(errno)); + return false; +} + +static bool arm64_hwbp_add(RzDebug *dbg, RzBreakpoint *bp, RzBreakpointItem *b) { + return ll_arm64_hwbp_set(dbg->pid, b->addr, b->size, 0, 1 | 2 | 4); +} + +static bool arm64_hwbp_del(RzDebug *dbg, RzBreakpoint *bp, RzBreakpointItem *b) { + return ll_arm64_hwbp_del(dbg->pid, b->addr, b->size, 0, 1 | 2 | 4); +} + +#endif + +static int rz_debug_native_bp(RzBreakpoint *bp, RzBreakpointItem *b, bool set) { + if (b && b->hw) { + return set + ? arm64_hwbp_add((RzDebug *)bp->user, bp, b) + : arm64_hwbp_del((RzDebug *)bp->user, bp, b); + } + return false; +} + +static RzList /**/ *rz_debug_desc_native_list(int pid) { + return linux_desc_list(pid); +} + +static int rz_debug_native_map_protect(RzDebug *dbg, ut64 addr, int size, int perms) { + RzBuffer *buf = NULL; + char code[1024]; + int num; + + num = rz_syscall_get_num(dbg->analysis->syscall, "mprotect"); + snprintf(code, sizeof(code), + "sc@syscall(%d);\n" + "main@global(0) { sc(%p,%d,%d);\n" + ":int3\n" + "}\n", + num, (void *)(size_t)addr, size, io_perms_to_prot(perms)); + + rz_egg_reset(dbg->egg); + rz_egg_setup(dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); + rz_egg_load(dbg->egg, code, 0); + if (!rz_egg_compile(dbg->egg)) { + eprintf("Cannot compile.\n"); + return false; + } + if (!rz_egg_assemble(dbg->egg)) { + eprintf("rz_egg_assemble: invalid assembly\n"); + return false; + } + buf = rz_egg_get_bin(dbg->egg); + if (buf) { + rz_reg_arena_push(dbg->reg); + ut64 tmpsz; + const ut8 *tmp = rz_buf_data(buf, &tmpsz); + rz_debug_execute(dbg, tmp, tmpsz, 1); + rz_reg_arena_pop(dbg->reg); + return true; + } + + return false; +} + +static int rz_debug_desc_native_open(const char *path) { + return 0; +} + +static bool rz_debug_gcore(RzDebug *dbg, char *path, RzBuffer *dest) { + (void)path; + return false; +} \ No newline at end of file diff --git a/librz/debug/p/android_x86_64.c b/librz/debug/p/android_x86_64.c new file mode 100644 index 00000000000..31db1cb1d5a --- /dev/null +++ b/librz/debug/p/android_x86_64.c @@ -0,0 +1,695 @@ +#include +#if !defined(__HAIKU__) && !defined(__sun) +#include +#endif +#include +#include + +#include +#include "native/linux/linux_debug.h" +#include "native/procfs.h" +#define WAIT_ANY -1 +#ifndef WIFCONTINUED +#define WIFCONTINUED(s) ((s) == 0xffff) +#endif + +#ifdef __WALL +#define WAITPID_FLAGS __WALL +#else +#define WAITPID_FLAGS 0 +#endif + +#define PROC_NAME_SZ 1024 +#define PROC_REGION_SZ 100 +// PROC_REGION_SZ - 2 (used for `0x`). Due to how RZ_STR_DEF works this can't be +// computed. +#define PROC_REGION_LEFT_SZ 98 +#define PROC_PERM_SZ 5 +#define PROC_UNKSTR_SZ 128 + +#if WAIT_ON_ALL_CHILDREN +static int rz_debug_handle_signals(RzDebug *dbg) { + eprintf("Warning: signal handling is not supported on this platform\n"); + return 0; +} +#endif + +static char *rz_debug_native_reg_profile(RzDebug *dbg) { + return linux_reg_profile(dbg); +} + +#include "native/reg.c" + +static bool rz_debug_native_step(RzDebug *dbg) { + return linux_step(dbg); +} + +static int rz_debug_native_attach(RzDebug *dbg, int pid) { + return linux_attach(dbg, pid); +} + +static int rz_debug_native_detach(RzDebug *dbg, int pid) { + return rz_debug_ptrace(dbg, PTRACE_DETACH, pid, NULL, (rz_ptrace_data_t)(size_t)0); +} + +static int rz_debug_native_select(RzDebug *dbg, int pid, int tid) { + return linux_select(dbg, pid, tid); +} + +static int rz_debug_native_continue_syscall(RzDebug *dbg, int pid, int num) { + linux_set_options(dbg, pid); + return rz_debug_ptrace(dbg, PTRACE_SYSCALL, pid, 0, 0); +} + +static void interrupt_process(RzDebug *dbg) { + rz_debug_kill(dbg, dbg->pid, dbg->tid, SIGINT); + rz_cons_break_pop(); +} + +static int rz_debug_native_stop(RzDebug *dbg) { + return linux_stop_threads(dbg, dbg->reason.tid); +} + +static int rz_debug_native_continue(RzDebug *dbg, int pid, int tid, int sig) { + int contsig = dbg->reason.signum; + int ret = -1; + + if (sig != -1) { + contsig = sig; + } + /* SIGINT handler for attached processes: dbg.consbreak (disabled by default) */ + if (dbg->consbreak) { + rz_cons_break_push((RzConsBreak)interrupt_process, dbg); + } + + if (dbg->continue_all_threads && dbg->n_threads && dbg->threads) { + RzDebugPid *th; + RzListIter *it; + rz_list_foreach (dbg->threads, it, th) { + ret = rz_debug_ptrace(dbg, PTRACE_CONT, th->pid, 0, 0); + if (ret) { + eprintf("Error: (%d) is running or dead.\n", th->pid); + } + } + } else { + ret = rz_debug_ptrace(dbg, PTRACE_CONT, tid, NULL, (rz_ptrace_data_t)(size_t)contsig); + if (ret) { + rz_sys_perror("PTRACE_CONT"); + } + } + // return ret >= 0 ? tid : false; + return tid; +} + +static RzDebugInfo *rz_debug_native_info(RzDebug *dbg, const char *arg) { + return linux_info(dbg, arg); +} + +#ifdef WAIT_ON_ALL_CHILDREN +static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { + RzDebugReasonType reason = RZ_DEBUG_REASON_UNKNOWN; + + if (pid == -1) { + eprintf("ERROR: rz_debug_native_wait called with pid -1\n"); + return RZ_DEBUG_REASON_ERROR; + } + int status = -1; + // XXX: this is blocking, ^C will be ignored + int ret = waitpid(-1, &status, WAITPID_FLAGS); + if (ret == -1) { + rz_sys_perror("waitpid"); + return RZ_DEBUG_REASON_ERROR; + } + + // eprintf ("rz_debug_native_wait: status=%d (0x%x) (return=%d)\n", status, status, ret); + + if (ret != pid) { + reason = RZ_DEBUG_REASON_NEW_PID; + eprintf("switching to pid %d\n", ret); + rz_debug_select(dbg, ret, ret); + } + + // TODO: switch status and handle reasons here + // FIXME: Remove linux handling from this function? +#if defined(PT_GETEVENTMSG) + reason = linux_ptrace_event(dbg, pid, status, true); +#endif + + /* propagate errors */ + if (reason == RZ_DEBUG_REASON_ERROR) { + return reason; + } + + /* we don't know what to do yet, let's try harder to figure it out. */ + if (reason == RZ_DEBUG_REASON_UNKNOWN) { + if (WIFEXITED(status)) { + eprintf("child exited with status %d\n", WEXITSTATUS(status)); + reason = RZ_DEBUG_REASON_DEAD; + } else if (WIFSIGNALED(status)) { + eprintf("child received signal %d\n", WTERMSIG(status)); + reason = RZ_DEBUG_REASON_SIGNAL; + } else if (WIFSTOPPED(status)) { + if (WSTOPSIG(status) != SIGTRAP && + WSTOPSIG(status) != SIGSTOP) { + eprintf("Child stopped with signal %d\n", WSTOPSIG(status)); + } + + /* the ptrace documentation says GETSIGINFO is only necessary for + * differentiating the various stops. + * + * this might modify dbg->reason.signum + */ + if (rz_debug_handle_signals(dbg) != 0) { + return RZ_DEBUG_REASON_ERROR; + } + reason = dbg->reason.type; +#ifdef WIFCONTINUED + } else if (WIFCONTINUED(status)) { + eprintf("child continued...\n"); + reason = RZ_DEBUG_REASON_NONE; +#endif + } else if (status == 1) { + /* XXX(jjd): does this actually happen? */ + eprintf("debugger is dead with status 1!\n"); + reason = RZ_DEBUG_REASON_DEAD; + } else if (status == 0) { + /* XXX(jjd): does this actually happen? */ + eprintf("debugger is dead with status 0\n"); + reason = RZ_DEBUG_REASON_DEAD; + } else { + if (ret != pid) { + reason = RZ_DEBUG_REASON_NEW_PID; + } else { + /* ugh. still don't know :-/ */ + eprintf("returning from wait without knowing why...\n"); + } + } + } + + /* if we still don't know what to do, we have a problem... */ + if (reason == RZ_DEBUG_REASON_UNKNOWN) { + eprintf("%s: no idea what happened...\n", __func__); + reason = RZ_DEBUG_REASON_ERROR; + } + dbg->reason.tid = pid; + dbg->reason.type = reason; + return reason; +} +#else +static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { + RzDebugReasonType reason = RZ_DEBUG_REASON_UNKNOWN; + if (pid == -1) { + eprintf("ERROR: rz_debug_native_wait called with pid -1\n"); + return RZ_DEBUG_REASON_ERROR; + } + + reason = linux_dbg_wait(dbg, dbg->tid); + dbg->reason.type = reason; + return reason; +} +#endif + +#undef MAXPID +#define MAXPID 99999 + +static RzList /**/ *rz_debug_native_pids(RzDebug *dbg, int pid) { + RzList *list = rz_list_new(); + if (!list) { + return NULL; + } + return linux_pid_list(pid, list); +} + +RZ_API RZ_OWN RzList /**/ *rz_debug_native_threads(RzDebug *dbg, int pid) { + RzList *list = rz_list_new(); + if (!list) { + eprintf("No list?\n"); + return NULL; + } + return linux_thread_list(dbg, pid, list); +} + +RZ_API ut64 rz_debug_get_tls(RZ_NONNULL RzDebug *dbg, int tid) { + rz_return_val_if_fail(dbg, 0); + return get_linux_tls_val(dbg, tid); +} + +static int rz_debug_native_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { + if (size < 1) { + return false; + } + return linux_reg_read(dbg, type, buf, size); +} + +static int rz_debug_native_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size) { + // XXX use switch or so + if (type == RZ_REG_TYPE_DRX) { + return linux_reg_write(dbg, type, buf, size); + } else if (type == RZ_REG_TYPE_GPR) { + return linux_reg_write(dbg, type, buf, size); + } else if (type == RZ_REG_TYPE_FPU) { + return linux_reg_write(dbg, type, buf, size); + } // else eprintf ("TODO: reg_write_non-gpr (%d)\n", type); + return false; +} + +static int io_perms_to_prot(int io_perms) { + int prot_perms = PROT_NONE; + + if (io_perms & RZ_PERM_R) { + prot_perms |= PROT_READ; + } + if (io_perms & RZ_PERM_W) { + prot_perms |= PROT_WRITE; + } + if (io_perms & RZ_PERM_X) { + prot_perms |= PROT_EXEC; + } + return prot_perms; +} + +static int linux_map_thp(RzDebug *dbg, ut64 addr, int size) { +return false; +} + +static RzDebugMap *linux_map_alloc(RzDebug *dbg, ut64 addr, int size, bool thp) { + RzBuffer *buf = NULL; + RzDebugMap *map = NULL; + char code[1024], *sc_name; + int num; + /* force to usage of x86.as, not yet working x86.nz */ + char *asm_list[] = { + "x86", "x86.as", + "x64", "x86.as", + NULL + }; + + /* NOTE: Since kernel 2.4, that system call has been superseded by + mmap2(2 and nowadays the glibc mmap() wrapper function invokes + mmap2(2)). If arch is x86_32 then usage mmap2() */ + if (!strcmp(dbg->arch, "x86") && dbg->bits == 4) { + sc_name = "mmap2"; + } else { + sc_name = "mmap"; + } + num = rz_syscall_get_num(dbg->analysis->syscall, sc_name); +#ifndef MAP_ANONYMOUS +#define MAP_ANONYMOUS 0x20 +#endif + snprintf(code, sizeof(code), + "sc_mmap@syscall(%d);\n" + "main@naked(0) { .rarg0 = sc_mmap(0x%08" PFMT64x ",%d,%d,%d,%d,%d);break;\n" + "}\n", + num, addr, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + rz_egg_reset(dbg->egg); + rz_egg_setup(dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); + rz_egg_load(dbg->egg, code, 0); + if (!rz_egg_compile(dbg->egg)) { + eprintf("Cannot compile.\n"); + goto err_linux_map_alloc; + } + if (!rz_egg_assemble_asm(dbg->egg, asm_list)) { + eprintf("rz_egg_assemble: invalid assembly\n"); + goto err_linux_map_alloc; + } + buf = rz_egg_get_bin(dbg->egg); + if (buf) { + ut64 map_addr; + + rz_reg_arena_push(dbg->reg); + ut64 tmpsz; + const ut8 *tmp = rz_buf_data(buf, &tmpsz); + map_addr = rz_debug_execute(dbg, tmp, tmpsz, 1); + rz_reg_arena_pop(dbg->reg); + if (map_addr != (ut64)-1) { + if (thp) { + if (!linux_map_thp(dbg, map_addr, size)) { + // Not overly dramatic + eprintf("map promotion to huge page failed\n"); + } + } + rz_debug_map_sync(dbg); + map = rz_debug_map_get(dbg, map_addr); + } + } +err_linux_map_alloc: + return map; +} + +static int linux_map_dealloc(RzDebug *dbg, ut64 addr, int size) { + RzBuffer *buf = NULL; + char code[1024]; + int ret = 0; + char *asm_list[] = { + "x86", "x86.as", + "x64", "x86.as", + NULL + }; + int num = rz_syscall_get_num(dbg->analysis->syscall, "munmap"); + + snprintf(code, sizeof(code), + "sc_munmap@syscall(%d);\n" + "main@naked(0) { .rarg0 = sc_munmap(0x%08" PFMT64x ",%d);break;\n" + "}\n", + num, addr, size); + rz_egg_reset(dbg->egg); + rz_egg_setup(dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); + rz_egg_load(dbg->egg, code, 0); + if (!rz_egg_compile(dbg->egg)) { + eprintf("Cannot compile.\n"); + goto err_linux_map_dealloc; + } + if (!rz_egg_assemble_asm(dbg->egg, asm_list)) { + eprintf("rz_egg_assemble: invalid assembly\n"); + goto err_linux_map_dealloc; + } + buf = rz_egg_get_bin(dbg->egg); + if (buf) { + rz_reg_arena_push(dbg->reg); + ut64 tmpsz; + const ut8 *tmp = rz_buf_data(buf, &tmpsz); + ret = rz_debug_execute(dbg, tmp, tmpsz, 1) == 0; + rz_reg_arena_pop(dbg->reg); + } +err_linux_map_dealloc: + return ret; +} + +static RzDebugMap *rz_debug_native_map_alloc(RzDebug *dbg, ut64 addr, int size, bool thp) { + return linux_map_alloc(dbg, addr, size, thp); +} + +static int rz_debug_native_map_dealloc(RzDebug *dbg, ut64 addr, int size) { + return linux_map_dealloc(dbg, addr, size); +} + +static void _map_free(RzDebugMap *map) { + if (!map) { + return; + } + free(map->name); + free(map->file); + free(map); +} + +static RzList /**/ *rz_debug_native_map_get(RzDebug *dbg) { + RzList *list = NULL; + RzDebugMap *map; + int i, perm, unk = 0; + char *pos_c; + char path[1024], line[1024], name[PROC_NAME_SZ + 1]; + char region[PROC_REGION_SZ + 1], region2[PROC_REGION_SZ + 1], perms[PROC_PERM_SZ + 1]; + FILE *fd; + if (dbg->pid == -1) { + // eprintf ("rz_debug_native_map_get: No selected pid (-1)\n"); + return NULL; + } + /* prepend 0x prefix */ + region[0] = region2[0] = '0'; + region[1] = region2[1] = 'x'; + + snprintf(path, sizeof(path), "/proc/%d/maps", dbg->pid); + + fd = rz_sys_fopen(path, "r"); + if (!fd) { + char *errmsg = rz_str_newf("Cannot open '%s'", path); + perror(errmsg); + free(errmsg); + return NULL; + } + + list = rz_list_new(); + if (!list) { + fclose(fd); + return NULL; + } + list->free = (RzListFree)_map_free; + while (!feof(fd)) { + size_t line_len; + bool map_is_shared = false; + ut64 map_start, map_end; + + if (!fgets(line, sizeof(line), fd)) { + break; + } + /* kill the newline if we got one */ + line_len = strlen(line); + if (line[line_len - 1] == '\n') { + line[line_len - 1] = '\0'; + line_len--; + } + /* maps files should not have empty lines */ + if (line_len == 0) { + break; + } + + ut64 offset = 0; + // 7fc8124c4000-7fc81278d000 r--p 00000000 fc:00 17043921 /usr/lib/locale/locale-archive + i = sscanf(line, "%" RZ_STR_DEF(PROC_REGION_LEFT_SZ) "s %" RZ_STR_DEF(PROC_PERM_SZ) "s %08" PFMT64x " %*s %*s %" RZ_STR_DEF(PROC_NAME_SZ) "[^\n]", ®ion[2], perms, &offset, name); + if (i == 3) { + name[0] = '\0'; + } else if (i != 4) { + eprintf("%s: Unable to parse \"%s\"\n", __func__, path); + eprintf("%s: problematic line: %s\n", __func__, line); + rz_list_free(list); + return NULL; + } + + /* split the region in two */ + pos_c = strchr(®ion[2], '-'); + if (!pos_c) { // should this be an error? + continue; + } + strncpy(®ion2[2], pos_c + 1, sizeof(region2) - 2 - 1); + + if (!*name) { + snprintf(name, sizeof(name), "unk%d", unk++); + } + perm = 0; + for (i = 0; i < 5 && perms[i]; i++) { + switch (perms[i]) { + case 'r': perm |= RZ_PERM_R; break; + case 'w': perm |= RZ_PERM_W; break; + case 'x': perm |= RZ_PERM_X; break; + case 'p': map_is_shared = false; break; + case 's': map_is_shared = true; break; + } + } + + map_start = rz_num_get(NULL, region); + map_end = rz_num_get(NULL, region2); + if (map_start == map_end || map_end == 0) { + eprintf("%s: ignoring invalid map size: %s - %s\n", __func__, region, region2); + continue; + } + map = rz_debug_map_new(name, map_start, map_end, perm, 0); + if (!map) { + break; + } + map->offset = offset; + map->shared = map_is_shared; + map->file = strdup(name); + rz_list_append(list, map); + } + fclose(fd); + return list; +} + +static RzList /**/ *rz_debug_native_modules_get(RzDebug *dbg) { + char *lastname = NULL; + RzDebugMap *map; + RzListIter *iter, *iter2; + RzList *list, *last; + bool must_delete; + if (!(list = rz_debug_native_map_get(dbg))) { + return NULL; + } + if (!(last = rz_list_newf((RzListFree)rz_debug_map_free))) { + rz_list_free(list); + return NULL; + } + rz_list_foreach_safe (list, iter, iter2, map) { + const char *file = map->file; + if (!map->file) { + file = map->file = strdup(map->name); + } + must_delete = true; + if (file && *file == '/') { + if (!lastname || strcmp(lastname, file)) { + must_delete = false; + } + } + if (must_delete) { + rz_list_delete(list, iter); + } else { + rz_list_append(last, map); + free(lastname); + lastname = strdup(file); + } + } + list->free = NULL; + free(lastname); + rz_list_free(list); + return last; +} + +static bool rz_debug_native_kill(RzDebug *dbg, int pid, int tid, int sig) { + bool ret = false; + if (pid == 0) { + pid = dbg->pid; + } + if (sig == SIGKILL && dbg->threads) { + rz_list_free(dbg->threads); + dbg->threads = NULL; + } + if ((rz_sys_kill(pid, sig) != -1)) { + ret = true; + } + if (errno == 1) { + ret = -true; // EPERM + } + return ret; +} + +struct rz_debug_desc_plugin_t rz_debug_desc_plugin_native; +static bool rz_debug_native_init(RzDebug *dbg, void **user) { + dbg->cur->desc = rz_debug_desc_plugin_native; + return true; +} + +static void rz_debug_native_fini(RzDebug *dbg, void *user) { +} + +static void sync_drx_regs(RzDebug *dbg, drxt *regs, size_t num_regs) { + /* sanity check, we rely on this assumption */ + if (num_regs != NUM_DRX_REGISTERS) { + eprintf("drx: Unsupported number of registers for get_debug_regs\n"); + return; + } + + // sync drx regs +#define R dbg->reg + regs[0] = rz_reg_getv(R, "dr0"); + regs[1] = rz_reg_getv(R, "dr1"); + regs[2] = rz_reg_getv(R, "dr2"); + regs[3] = rz_reg_getv(R, "dr3"); + /* + RESERVED + regs[4] = rz_reg_getv (R, "dr4"); + regs[5] = rz_reg_getv (R, "dr5"); +*/ + regs[6] = rz_reg_getv(R, "dr6"); + regs[7] = rz_reg_getv(R, "dr7"); +} + +static void set_drx_regs(RzDebug *dbg, drxt *regs, size_t num_regs) { + /* sanity check, we rely on this assumption */ + if (num_regs != NUM_DRX_REGISTERS) { + eprintf("drx: Unsupported number of registers for get_debug_regs\n"); + return; + } + +#define R dbg->reg + rz_reg_setv(R, "dr0", regs[0]); + rz_reg_setv(R, "dr1", regs[1]); + rz_reg_setv(R, "dr2", regs[2]); + rz_reg_setv(R, "dr3", regs[3]); + rz_reg_setv(R, "dr6", regs[6]); + rz_reg_setv(R, "dr7", regs[7]); +} + + +static int rz_debug_native_drx(RzDebug *dbg, int n, ut64 addr, int sz, int rwx, int g, int api_type) { + int retval = false; + drxt regs[NUM_DRX_REGISTERS] = { 0 }; + // sync drx regs + sync_drx_regs(dbg, regs, NUM_DRX_REGISTERS); + + switch (api_type) { + case DRX_API_LIST: + drx_list(regs); + retval = false; + break; + case DRX_API_GET_BP: + /* get the index of the breakpoint at addr */ + retval = drx_get_at(regs, addr); + break; + case DRX_API_REMOVE_BP: + /* remove hardware breakpoint */ + drx_set(regs, n, addr, -1, 0, 0); + retval = true; + break; + case DRX_API_SET_BP: + /* set hardware breakpoint */ + drx_set(regs, n, addr, sz, rwx, g); + retval = true; + break; + default: + /* this should not happen, someone misused the API */ + eprintf("drx: Unsupported api type in rz_debug_native_drx\n"); + retval = false; + } + + set_drx_regs(dbg, regs, NUM_DRX_REGISTERS); + + return retval; +} + +static int rz_debug_native_bp(RzBreakpoint *bp, RzBreakpointItem *b, bool set) { + if (b && b->hw) { + return set + ? drx_add((RzDebug *)bp->user, bp, b) + : drx_del((RzDebug *)bp->user, bp, b); + } + return false; +} + +static RzList /**/ *rz_debug_desc_native_list(int pid) { + return linux_desc_list(pid); +} + +static int rz_debug_native_map_protect(RzDebug *dbg, ut64 addr, int size, int perms) { + RzBuffer *buf = NULL; + char code[1024]; + int num; + + num = rz_syscall_get_num(dbg->analysis->syscall, "mprotect"); + snprintf(code, sizeof(code), + "sc@syscall(%d);\n" + "main@global(0) { sc(%p,%d,%d);\n" + ":int3\n" + "}\n", + num, (void *)(size_t)addr, size, io_perms_to_prot(perms)); + + rz_egg_reset(dbg->egg); + rz_egg_setup(dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); + rz_egg_load(dbg->egg, code, 0); + if (!rz_egg_compile(dbg->egg)) { + eprintf("Cannot compile.\n"); + return false; + } + if (!rz_egg_assemble(dbg->egg)) { + eprintf("rz_egg_assemble: invalid assembly\n"); + return false; + } + buf = rz_egg_get_bin(dbg->egg); + if (buf) { + rz_reg_arena_push(dbg->reg); + ut64 tmpsz; + const ut8 *tmp = rz_buf_data(buf, &tmpsz); + rz_debug_execute(dbg, tmp, tmpsz, 1); + rz_reg_arena_pop(dbg->reg); + return true; + } + + return false; +} + +static int rz_debug_desc_native_open(const char *path) { + return 0; +} + +static bool rz_debug_gcore(RzDebug *dbg, char *path, RzBuffer *dest) { + (void)path; + return false; +} \ No newline at end of file diff --git a/librz/debug/p/apple_aarch64.c b/librz/debug/p/apple_aarch64.c new file mode 100644 index 00000000000..28277bee2c9 --- /dev/null +++ b/librz/debug/p/apple_aarch64.c @@ -0,0 +1,300 @@ +#include +#if !defined(__HAIKU__) && !defined(__sun) +#include +#endif +#include +#include + +#include +#include "native/xnu/xnu_debug.h" + +#ifdef __WALL +#define WAITPID_FLAGS __WALL +#else +#define WAITPID_FLAGS 0 +#endif + +#define PROC_NAME_SZ 1024 +#define PROC_REGION_SZ 100 +// PROC_REGION_SZ - 2 (used for `0x`). Due to how RZ_STR_DEF works this can't be +// computed. +#define PROC_REGION_LEFT_SZ 98 +#define PROC_PERM_SZ 5 +#define PROC_UNKSTR_SZ 128 + +static char *rz_debug_native_reg_profile(RzDebug *dbg) { + return xnu_reg_profile(dbg); +} + +static bool rz_debug_native_step(RzDebug *dbg) { + return xnu_step(dbg); +} + +static int rz_debug_native_attach(RzDebug *dbg, int pid) { + return xnu_attach(dbg, pid); +} + +static int rz_debug_native_detach(RzDebug *dbg, int pid) { + return xnu_detach(dbg, pid); +} + +static int rz_debug_native_continue_syscall(RzDebug *dbg, int pid, int num) { + eprintf("TODO: continue syscall not implemented yet\n"); + return -1; +} + +static int rz_debug_native_stop(RzDebug *dbg) { + return 0; +} + +static int rz_debug_native_continue(RzDebug *dbg, int pid, int tid, int sig) { + bool ret = xnu_continue(dbg, pid, tid, sig); + if (!ret) { + return -1; + } + return tid; +} + +static RzDebugInfo *rz_debug_native_info(RzDebug *dbg, const char *arg) { + return xnu_info(dbg, arg); +} + +static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { + RzDebugReasonType reason = RZ_DEBUG_REASON_UNKNOWN; + + if (pid == -1) { + eprintf("ERROR: rz_debug_native_wait called with pid -1\n"); + return RZ_DEBUG_REASON_ERROR; + } + rz_cons_break_push(NULL, NULL); + do { + reason = xnu_wait(dbg, pid); + if (reason == RZ_DEBUG_REASON_MACH_RCV_INTERRUPTED) { + if (rz_cons_is_breaked()) { + // Perhaps check the inferior is still alive, + // otherwise xnu_stop will fail. + reason = xnu_stop(dbg, pid) + ? RZ_DEBUG_REASON_USERSUSP + : RZ_DEBUG_REASON_UNKNOWN; + } else { + // Weird; we'll retry the wait. + continue; + } + } + break; + } while (true); + rz_cons_break_pop(); + dbg->reason.tid = pid; + dbg->reason.type = reason; + return reason; +} + +#undef MAXPID +#define MAXPID 99999 + +static RzList /**/ *rz_debug_native_pids(RzDebug *dbg, int pid) { + RzList *list = rz_list_new(); + if (!list) { + return NULL; + } + if (pid) { + RzDebugPid *p = xnu_get_pid(pid); + if (p) { + rz_list_append(list, p); + } + } else { + int i; + for (i = 1; i < MAXPID; i++) { + RzDebugPid *p = xnu_get_pid(i); + if (p) { + rz_list_append(list, p); + } + } + } + return list; +} + +RZ_API RZ_OWN RzList /**/ *rz_debug_native_threads(RzDebug *dbg, int pid) { + RzList *list = rz_list_new(); + if (!list) { + eprintf("No list?\n"); + return NULL; + } + return xnu_thread_list(dbg, pid, list); +} + +RZ_API ut64 rz_debug_get_tls(RZ_NONNULL RzDebug *dbg, int tid) { + rz_return_val_if_fail(dbg, 0); + return 0; +} + +static int rz_debug_native_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { + if (size < 1) { + return false; + } + return xnu_reg_read(dbg, type, buf, size); +} + +static int rz_debug_native_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size) { + // XXX use switch or so + if (type == RZ_REG_TYPE_DRX) { + return false; + } else if (type == RZ_REG_TYPE_GPR) { + return xnu_reg_write(dbg, type, buf, size); + } else if (type == RZ_REG_TYPE_FPU) { + return false; + } // else eprintf ("TODO: reg_write_non-gpr (%d)\n", type); + return false; +} + +static RzDebugMap *rz_debug_native_map_alloc(RzDebug *dbg, ut64 addr, int size, bool thp) { + (void)thp; + return xnu_map_alloc(dbg, addr, size); +} + +static int rz_debug_native_map_dealloc(RzDebug *dbg, ut64 addr, int size) { + return xnu_map_dealloc(dbg, addr, size); +} + +static RzList /**/ *rz_debug_native_map_get(RzDebug *dbg) { + RzList *list = NULL; + list = xnu_dbg_maps(dbg, 0); + return list; +} + +static RzList /**/ *rz_debug_native_modules_get(RzDebug *dbg) { + char *lastname = NULL; + RzDebugMap *map; + RzListIter *iter, *iter2; + RzList *list, *last; + bool must_delete; + list = xnu_dbg_maps(dbg, 1); + if (list && !rz_list_empty(list)) { + return list; + } + if (!(list = rz_debug_native_map_get(dbg))) { + return NULL; + } + if (!(last = rz_list_newf((RzListFree)rz_debug_map_free))) { + rz_list_free(list); + return NULL; + } + rz_list_foreach_safe (list, iter, iter2, map) { + const char *file = map->file; + if (!map->file) { + file = map->file = strdup(map->name); + } + must_delete = true; + if (file && *file == '/') { + if (!lastname || strcmp(lastname, file)) { + must_delete = false; + } + } + if (must_delete) { + rz_list_delete(list, iter); + } else { + rz_list_append(last, map); + free(lastname); + lastname = strdup(file); + } + } + list->free = NULL; + free(lastname); + rz_list_free(list); + return last; +} + +static bool rz_debug_native_kill(RzDebug *dbg, int pid, int tid, int sig) { + bool ret = false; + if (pid == 0) { + pid = dbg->pid; + } + if (sig == SIGKILL && dbg->threads) { + rz_list_free(dbg->threads); + dbg->threads = NULL; + } + if ((rz_sys_kill(pid, sig) != -1)) { + ret = true; + } + if (errno == 1) { + ret = -true; // EPERM + } + return ret; +} + +struct rz_debug_desc_plugin_t rz_debug_desc_plugin_native; +static bool rz_debug_native_init(RzDebug *dbg, void **user) { + dbg->cur->desc = rz_debug_desc_plugin_native; + return rz_xnu_debug_init(dbg, user); +} + +static void rz_debug_native_fini(RzDebug *dbg, void *user) { + rz_xnu_debug_fini(dbg, user); +} + + +static int rz_debug_native_drx(RzDebug *dbg, int n, ut64 addr, int sz, int rwx, int g, int api_type) { + eprintf("drx: Unsupported platform\n"); + return -1; +} + +static int rz_debug_native_bp(RzBreakpoint *bp, RzBreakpointItem *b, bool set) { + return false; +} + +static int getMaxFiles(void) { + struct rlimit limit; + if (getrlimit(RLIMIT_NOFILE, &limit) != 0) { + return 1024; + } + return limit.rlim_cur; +} + +static RzList *xnu_desc_list(int pid) { +#if TARGET_OS_IPHONE || __POWERPC__ + return NULL; +#else +#define xwrz_testwx(x) ((x & 1) << 2) | (x & 2) | ((x & 4) >> 2) + RzDebugDesc *desc; + RzList *ret = rz_list_new(); + struct vnode_fdinfowithpath vi; + int i, nb, type = 0; + int maxfd = getMaxFiles(); + + for (i = 0; i < maxfd; i++) { + nb = proc_pidfdinfo(pid, i, PROC_PIDFDVNODEPATHINFO, &vi, sizeof(vi)); + if (nb < 1) { + continue; + } + if (nb < sizeof(vi)) { + perror("too few bytes"); + break; + } + // printf ("FD %d RWX %x ", i, vi.pfi.fi_openflags); + // printf ("PATH %s\n", vi.pvip.vip_path); + desc = rz_debug_desc_new(i, + vi.pvip.vip_path, + xwrz_testwx(vi.pfi.fi_openflags), + type, 0); + rz_list_append(ret, desc); + } + return ret; +#endif +} + +static RzList /**/ *rz_debug_desc_native_list(int pid) { + return xnu_desc_list(pid); +} + +static int rz_debug_native_map_protect(RzDebug *dbg, ut64 addr, int size, int perms) { + return xnu_map_protect(dbg, addr, size, perms); +} + +static int rz_debug_desc_native_open(const char *path) { + return 0; +} + +static bool rz_debug_gcore(RzDebug *dbg, char *path, RzBuffer *dest) { + (void)path; + return xnu_generate_corefile(dbg, dest); +} \ No newline at end of file diff --git a/librz/debug/p/apple_x86_64.c b/librz/debug/p/apple_x86_64.c new file mode 100644 index 00000000000..052e0bee4b1 --- /dev/null +++ b/librz/debug/p/apple_x86_64.c @@ -0,0 +1,373 @@ +#include +#if !defined(__HAIKU__) && !defined(__sun) +#include +#endif +#include +#include + +#include +#include "native/xnu/xnu_debug.h" + +#ifdef __WALL +#define WAITPID_FLAGS __WALL +#else +#define WAITPID_FLAGS 0 +#endif + +#define PROC_NAME_SZ 1024 +#define PROC_REGION_SZ 100 +// PROC_REGION_SZ - 2 (used for `0x`). Due to how RZ_STR_DEF works this can't be +// computed. +#define PROC_REGION_LEFT_SZ 98 +#define PROC_PERM_SZ 5 +#define PROC_UNKSTR_SZ 128 + +static char *rz_debug_native_reg_profile(RzDebug *dbg) { + return xnu_reg_profile(dbg); +} + +static bool rz_debug_native_step(RzDebug *dbg) { + return xnu_step(dbg); +} + +static int rz_debug_native_attach(RzDebug *dbg, int pid) { + return xnu_attach(dbg, pid); +} + +static int rz_debug_native_detach(RzDebug *dbg, int pid) { + return xnu_detach(dbg, pid); +} + +static int rz_debug_native_continue_syscall(RzDebug *dbg, int pid, int num) { + eprintf("TODO: continue syscall not implemented yet\n"); + return -1; +} + +static int rz_debug_native_stop(RzDebug *dbg) { + return 0; +} + +static int rz_debug_native_continue(RzDebug *dbg, int pid, int tid, int sig) { + bool ret = xnu_continue(dbg, pid, tid, sig); + if (!ret) { + return -1; + } + return tid; +} + +static RzDebugInfo *rz_debug_native_info(RzDebug *dbg, const char *arg) { + return xnu_info(dbg, arg); +} + +static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { + RzDebugReasonType reason = RZ_DEBUG_REASON_UNKNOWN; + + if (pid == -1) { + eprintf("ERROR: rz_debug_native_wait called with pid -1\n"); + return RZ_DEBUG_REASON_ERROR; + } + rz_cons_break_push(NULL, NULL); + do { + reason = xnu_wait(dbg, pid); + if (reason == RZ_DEBUG_REASON_MACH_RCV_INTERRUPTED) { + if (rz_cons_is_breaked()) { + // Perhaps check the inferior is still alive, + // otherwise xnu_stop will fail. + reason = xnu_stop(dbg, pid) + ? RZ_DEBUG_REASON_USERSUSP + : RZ_DEBUG_REASON_UNKNOWN; + } else { + // Weird; we'll retry the wait. + continue; + } + } + break; + } while (true); + rz_cons_break_pop(); + dbg->reason.tid = pid; + dbg->reason.type = reason; + return reason; +} + +#undef MAXPID +#define MAXPID 99999 + +static RzList /**/ *rz_debug_native_pids(RzDebug *dbg, int pid) { + RzList *list = rz_list_new(); + if (!list) { + return NULL; + } + if (pid) { + RzDebugPid *p = xnu_get_pid(pid); + if (p) { + rz_list_append(list, p); + } + } else { + int i; + for (i = 1; i < MAXPID; i++) { + RzDebugPid *p = xnu_get_pid(i); + if (p) { + rz_list_append(list, p); + } + } + } + return list; +} + +RZ_API RZ_OWN RzList /**/ *rz_debug_native_threads(RzDebug *dbg, int pid) { + RzList *list = rz_list_new(); + if (!list) { + eprintf("No list?\n"); + return NULL; + } + return xnu_thread_list(dbg, pid, list); +} + +RZ_API ut64 rz_debug_get_tls(RZ_NONNULL RzDebug *dbg, int tid) { + rz_return_val_if_fail(dbg, 0); + return 0; +} + +static int rz_debug_native_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { + if (size < 1) { + return false; + } + return xnu_reg_read(dbg, type, buf, size); +} + +static int rz_debug_native_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size) { + // XXX use switch or so + if (type == RZ_REG_TYPE_DRX) { + return xnu_reg_write(dbg, type, buf, size); + } else if (type == RZ_REG_TYPE_GPR) { + return xnu_reg_write(dbg, type, buf, size); + } else if (type == RZ_REG_TYPE_FPU) { + return false; + } // else eprintf ("TODO: reg_write_non-gpr (%d)\n", type); + return false; +} + +static RzDebugMap *rz_debug_native_map_alloc(RzDebug *dbg, ut64 addr, int size, bool thp) { + (void)thp; + return xnu_map_alloc(dbg, addr, size); +} + +static int rz_debug_native_map_dealloc(RzDebug *dbg, ut64 addr, int size) { + return xnu_map_dealloc(dbg, addr, size); +} + +static RzList /**/ *rz_debug_native_map_get(RzDebug *dbg) { + RzList *list = NULL; + list = xnu_dbg_maps(dbg, 0); + return list; +} + +static RzList /**/ *rz_debug_native_modules_get(RzDebug *dbg) { + char *lastname = NULL; + RzDebugMap *map; + RzListIter *iter, *iter2; + RzList *list, *last; + bool must_delete; + list = xnu_dbg_maps(dbg, 1); + if (list && !rz_list_empty(list)) { + return list; + } + if (!(list = rz_debug_native_map_get(dbg))) { + return NULL; + } + if (!(last = rz_list_newf((RzListFree)rz_debug_map_free))) { + rz_list_free(list); + return NULL; + } + rz_list_foreach_safe (list, iter, iter2, map) { + const char *file = map->file; + if (!map->file) { + file = map->file = strdup(map->name); + } + must_delete = true; + if (file && *file == '/') { + if (!lastname || strcmp(lastname, file)) { + must_delete = false; + } + } + if (must_delete) { + rz_list_delete(list, iter); + } else { + rz_list_append(last, map); + free(lastname); + lastname = strdup(file); + } + } + list->free = NULL; + free(lastname); + rz_list_free(list); + return last; +} + +static bool rz_debug_native_kill(RzDebug *dbg, int pid, int tid, int sig) { + bool ret = false; + if (pid == 0) { + pid = dbg->pid; + } + if (sig == SIGKILL && dbg->threads) { + rz_list_free(dbg->threads); + dbg->threads = NULL; + } + if ((rz_sys_kill(pid, sig) != -1)) { + ret = true; + } + if (errno == 1) { + ret = -true; // EPERM + } + return ret; +} + +struct rz_debug_desc_plugin_t rz_debug_desc_plugin_native; +static bool rz_debug_native_init(RzDebug *dbg, void **user) { + dbg->cur->desc = rz_debug_desc_plugin_native; + return rz_xnu_debug_init(dbg, user); +} + +static void rz_debug_native_fini(RzDebug *dbg, void *user) { + rz_xnu_debug_fini(dbg, user); +} + +static void sync_drx_regs(RzDebug *dbg, drxt *regs, size_t num_regs) { + /* sanity check, we rely on this assumption */ + if (num_regs != NUM_DRX_REGISTERS) { + eprintf("drx: Unsupported number of registers for get_debug_regs\n"); + return; + } + + // sync drx regs +#define R dbg->reg + regs[0] = rz_reg_getv(R, "dr0"); + regs[1] = rz_reg_getv(R, "dr1"); + regs[2] = rz_reg_getv(R, "dr2"); + regs[3] = rz_reg_getv(R, "dr3"); + /* + RESERVED + regs[4] = rz_reg_getv (R, "dr4"); + regs[5] = rz_reg_getv (R, "dr5"); +*/ + regs[6] = rz_reg_getv(R, "dr6"); + regs[7] = rz_reg_getv(R, "dr7"); +} + +static void set_drx_regs(RzDebug *dbg, drxt *regs, size_t num_regs) { + /* sanity check, we rely on this assumption */ + if (num_regs != NUM_DRX_REGISTERS) { + eprintf("drx: Unsupported number of registers for get_debug_regs\n"); + return; + } + +#define R dbg->reg + rz_reg_setv(R, "dr0", regs[0]); + rz_reg_setv(R, "dr1", regs[1]); + rz_reg_setv(R, "dr2", regs[2]); + rz_reg_setv(R, "dr3", regs[3]); + rz_reg_setv(R, "dr6", regs[6]); + rz_reg_setv(R, "dr7", regs[7]); +} + +static int rz_debug_native_drx(RzDebug *dbg, int n, ut64 addr, int sz, int rwx, int g, int api_type) { + int retval = false; + drxt regs[NUM_DRX_REGISTERS] = { 0 }; + // sync drx regs + sync_drx_regs(dbg, regs, NUM_DRX_REGISTERS); + + switch (api_type) { + case DRX_API_LIST: + drx_list(regs); + retval = false; + break; + case DRX_API_GET_BP: + /* get the index of the breakpoint at addr */ + retval = drx_get_at(regs, addr); + break; + case DRX_API_REMOVE_BP: + /* remove hardware breakpoint */ + drx_set(regs, n, addr, -1, 0, 0); + retval = true; + break; + case DRX_API_SET_BP: + /* set hardware breakpoint */ + drx_set(regs, n, addr, sz, rwx, g); + retval = true; + break; + default: + /* this should not happen, someone misused the API */ + eprintf("drx: Unsupported api type in rz_debug_native_drx\n"); + retval = false; + } + + set_drx_regs(dbg, regs, NUM_DRX_REGISTERS); + + return retval; +} + +static int rz_debug_native_bp(RzBreakpoint *bp, RzBreakpointItem *b, bool set) { + if (b && b->hw) { + return set + ? drx_add((RzDebug *)bp->user, bp, b) + : drx_del((RzDebug *)bp->user, bp, b); + } + return false; +} + +static int getMaxFiles(void) { + struct rlimit limit; + if (getrlimit(RLIMIT_NOFILE, &limit) != 0) { + return 1024; + } + return limit.rlim_cur; +} + +static RzList *xnu_desc_list(int pid) { +#if TARGET_OS_IPHONE || __POWERPC__ + return NULL; +#else +#define xwrz_testwx(x) ((x & 1) << 2) | (x & 2) | ((x & 4) >> 2) + RzDebugDesc *desc; + RzList *ret = rz_list_new(); + struct vnode_fdinfowithpath vi; + int i, nb, type = 0; + int maxfd = getMaxFiles(); + + for (i = 0; i < maxfd; i++) { + nb = proc_pidfdinfo(pid, i, PROC_PIDFDVNODEPATHINFO, &vi, sizeof(vi)); + if (nb < 1) { + continue; + } + if (nb < sizeof(vi)) { + perror("too few bytes"); + break; + } + // printf ("FD %d RWX %x ", i, vi.pfi.fi_openflags); + // printf ("PATH %s\n", vi.pvip.vip_path); + desc = rz_debug_desc_new(i, + vi.pvip.vip_path, + xwrz_testwx(vi.pfi.fi_openflags), + type, 0); + rz_list_append(ret, desc); + } + return ret; +#endif +} + +static RzList /**/ *rz_debug_desc_native_list(int pid) { + return xnu_desc_list(pid); +} + +static int rz_debug_native_map_protect(RzDebug *dbg, ut64 addr, int size, int perms) { + return xnu_map_protect(dbg, addr, size, perms); +} + +static int rz_debug_desc_native_open(const char *path) { + return 0; +} + +static bool rz_debug_gcore(RzDebug *dbg, char *path, RzBuffer *dest) { + (void)path; + return xnu_generate_corefile(dbg, dest); +} \ No newline at end of file diff --git a/librz/debug/p/debug_native.c b/librz/debug/p/debug_native.c index 7692ce0022b..e64eae75d5e 100644 --- a/librz/debug/p/debug_native.c +++ b/librz/debug/p/debug_native.c @@ -20,1596 +20,63 @@ static int rz_debug_native_reg_write(RzDebug *dbg, int type, const ut8 *buf, int #include "native/bt.c" -#if __UNIX__ -#include -#if !defined(__HAIKU__) && !defined(__sun) -#include -#endif -#include -#include -#endif - -#if __WINDOWS__ -#include "native/windows/windows_debug.h" -// TODO: Move these onto windows.h? -RZ_API RzList *rz_w32_dbg_modules(RzDebug *); // ugly! -RZ_API RzList *rz_w32_dbg_maps(RzDebug *); -#define RZ_DEBUG_REG_T CONTEXT -#ifdef NTSTATUS -#undef NTSTATUS -#endif -#ifndef NTSTATUS -#define NTSTATUS int -#endif - -#elif __BSD__ -#include "native/bsd/bsd_debug.h" -#include "native/procfs.h" - -#elif __APPLE__ -#include -#include "native/xnu/xnu_debug.h" - -#elif __sun - -#define RZ_DEBUG_REG_T gregset_t -#undef DEBUGGER -#define DEBUGGER 0 -#warning No debugger support for SunOS yet - -#elif __linux__ -#include -#include "native/linux/linux_debug.h" -#include "native/procfs.h" -#ifdef __ANDROID__ -#define WAIT_ANY -1 -#ifndef WIFCONTINUED -#define WIFCONTINUED(s) ((s) == 0xffff) -#endif -#endif -#if (__x86_64__ || __i386__ || __arm__ || __arm64__) && !defined(__ANDROID__) -#include "native/linux/linux_coredump.h" -#endif -#else // OS - -#warning Unsupported debugging platform -#undef DEBUGGER -#define DEBUGGER 0 -#endif // ARCH - -#ifdef __WALL -#define WAITPID_FLAGS __WALL -#else -#define WAITPID_FLAGS 0 -#endif - -/* begin of debugger code */ -#if DEBUGGER - -#define PROC_NAME_SZ 1024 -#define PROC_REGION_SZ 100 -// PROC_REGION_SZ - 2 (used for `0x`). Due to how RZ_STR_DEF works this can't be -// computed. -#define PROC_REGION_LEFT_SZ 98 -#define PROC_PERM_SZ 5 -#define PROC_UNKSTR_SZ 128 - -#if !__WINDOWS__ && !(__linux__ && !defined(WAIT_ON_ALL_CHILDREN)) && !__APPLE__ -static int rz_debug_handle_signals(RzDebug *dbg) { -#if __KFBSD__ || __NetBSD__ - return bsd_handle_signals(dbg); -#else - eprintf("Warning: signal handling is not supported on this platform\n"); - return 0; -#endif -} -#endif - -// this is temporal -#if __APPLE__ || __linux__ - -static char *rz_debug_native_reg_profile(RzDebug *dbg) { -#if __APPLE__ - return xnu_reg_profile(dbg); -#elif __linux__ - return linux_reg_profile(dbg); -#endif -} -#else - -#include "native/reg.c" // x86 specific - -#endif -static bool rz_debug_native_step(RzDebug *dbg) { -#if __APPLE__ - return xnu_step(dbg); -#elif __WINDOWS__ - return w32_step(dbg); -#elif __BSD__ - int ret = ptrace(PT_STEP, dbg->pid, (caddr_t)1, 0); - if (ret != 0) { - perror("native-singlestep"); - return false; - } - return true; -#elif __linux__ - return linux_step(dbg); -#else - return false; -#endif -} - -// return thread id -static int rz_debug_native_attach(RzDebug *dbg, int pid) { -#if __APPLE__ - return xnu_attach(dbg, pid); -#elif __WINDOWS__ - return w32_attach(dbg, pid); -#elif __linux__ || __ANDROID__ - return linux_attach(dbg, pid); -#elif __KFBSD__ - if (ptrace(PT_ATTACH, pid, 0, 0) != -1) { - perror("ptrace (PT_ATTACH)"); - } - return pid; -#else - int ret = ptrace(PTRACE_ATTACH, pid, 0, 0); - if (ret != -1) { - eprintf("Trying to attach to %d\n", pid); - perror("ptrace (PT_ATTACH)"); - } - return pid; -#endif -} - -static int rz_debug_native_detach(RzDebug *dbg, int pid) { -#if __APPLE__ - return xnu_detach(dbg, pid); -#elif __WINDOWS__ - return w32_detach(dbg, pid); -#elif __BSD__ - return ptrace(PT_DETACH, pid, NULL, 0); -#else - return rz_debug_ptrace(dbg, PTRACE_DETACH, pid, NULL, (rz_ptrace_data_t)(size_t)0); -#endif -} - -#if __WINDOWS__ -static int rz_debug_native_select(RzDebug *dbg, int pid, int tid) { - return w32_select(dbg, pid, tid); -} -#elif __linux__ -static int rz_debug_native_select(RzDebug *dbg, int pid, int tid) { - return linux_select(dbg, pid, tid); -} -#endif - -static int rz_debug_native_continue_syscall(RzDebug *dbg, int pid, int num) { -// XXX: num is ignored -#if __linux__ - linux_set_options(dbg, pid); - return rz_debug_ptrace(dbg, PTRACE_SYSCALL, pid, 0, 0); -#elif __BSD__ - ut64 pc = rz_debug_reg_get(dbg, "PC"); - errno = 0; - return ptrace(PTRACE_SYSCALL, pid, (void *)(size_t)pc, 0) == 0; -#else - eprintf("TODO: continue syscall not implemented yet\n"); - return -1; -#endif -} - -#if !__WINDOWS__ && !__APPLE__ && !__BSD__ -/* Callback to trigger SIGINT signal */ -static void interrupt_process(RzDebug *dbg) { - rz_debug_kill(dbg, dbg->pid, dbg->tid, SIGINT); - rz_cons_break_pop(); -} -#endif - -static int rz_debug_native_stop(RzDebug *dbg) { -#if __linux__ - // Stop all running threads except the thread reported by waitpid - return linux_stop_threads(dbg, dbg->reason.tid); -#else - return 0; -#endif -} - -/* TODO: specify thread? */ -/* TODO: must return true/false */ -static int rz_debug_native_continue(RzDebug *dbg, int pid, int tid, int sig) { -#if __APPLE__ - bool ret = xnu_continue(dbg, pid, tid, sig); - if (!ret) { - return -1; - } - return tid; -#elif __WINDOWS__ - return w32_continue(dbg, pid, tid, sig); -#elif __BSD__ - void *data = (void *)(size_t)((sig != -1) ? sig : dbg->reason.signum); - ut64 pc = rz_debug_reg_get(dbg, "PC"); - return ptrace(PTRACE_CONT, pid, (void *)(size_t)pc, (int)(size_t)data) == 0; -#else - int contsig = dbg->reason.signum; - int ret = -1; - - if (sig != -1) { - contsig = sig; - } - /* SIGINT handler for attached processes: dbg.consbreak (disabled by default) */ - if (dbg->consbreak) { - rz_cons_break_push((RzConsBreak)interrupt_process, dbg); - } - - if (dbg->continue_all_threads && dbg->n_threads && dbg->threads) { - RzDebugPid *th; - RzListIter *it; - rz_list_foreach (dbg->threads, it, th) { - ret = rz_debug_ptrace(dbg, PTRACE_CONT, th->pid, 0, 0); - if (ret) { - eprintf("Error: (%d) is running or dead.\n", th->pid); - } - } - } else { - ret = rz_debug_ptrace(dbg, PTRACE_CONT, tid, NULL, (rz_ptrace_data_t)(size_t)contsig); - if (ret) { - rz_sys_perror("PTRACE_CONT"); - } - } - // return ret >= 0 ? tid : false; - return tid; -#endif -} - -static RzDebugInfo *rz_debug_native_info(RzDebug *dbg, const char *arg) { -#if __APPLE__ - return xnu_info(dbg, arg); -#elif __WINDOWS__ - return w32_info(dbg, arg); -#elif __linux__ - return linux_info(dbg, arg); -#elif __KFBSD__ || __OpenBSD__ || __NetBSD__ - return bsd_info(dbg, arg); -#else - return NULL; -#endif -} - -#if __WINDOWS__ -static bool tracelib(RzDebug *dbg, const char *mode, PLIB_ITEM item) { - const char *needle = NULL; - int tmp = 0; - if (mode) { - switch (mode[0]) { - case 'l': needle = dbg->glob_libs; break; - case 'u': needle = dbg->glob_unlibs; break; - } - } - rz_cons_printf("(%d) %sing library at 0x%p (%s) %s\n", item->pid, mode, - item->BaseOfDll, item->Path, item->Name); - rz_cons_flush(); - if (needle && strlen(needle)) { - tmp = rz_str_glob(item->Name, needle); - } - return !mode || !needle || tmp; -} -#endif - -/* - * Wait for an event and start trying to figure out what to do with it. - * - * Returns RZ_DEBUG_REASON_* - */ -#if __WINDOWS__ -static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { - RzDebugReasonType reason = RZ_DEBUG_REASON_UNKNOWN; - // Store the original TID to attempt to switch back after handling events that - // require switching to the event's thread that shouldn't bother the user - int orig_tid = dbg->tid; - bool restore_thread = false; - W32DbgWInst *wrap = dbg->plugin_data; - - if (pid == -1) { - RZ_LOG_ERROR("rz_debug_native_wait called with pid -1\n"); - return RZ_DEBUG_REASON_ERROR; - } - - reason = w32_dbg_wait(dbg, pid); - RzDebugInfo *native_info = rz_debug_native_info(dbg, ""); - if (reason == RZ_DEBUG_REASON_NEW_LIB) { - if (native_info && native_info->lib) { - /* Check if autoload PDB is set, and load PDB information if yes */ - RzCore *core = dbg->corebind.core; - bool autoload_pdb = dbg->corebind.cfggeti(core, "pdb.autoload"); - if (autoload_pdb) { - PLIB_ITEM lib = native_info->lib; - if (rz_file_exists(lib->Path)) { - if (tracelib(dbg, "load", native_info->lib)) { - reason = RZ_DEBUG_REASON_TRAP; - } - RzBinOptions opts = { 0 }; - opts.obj_opts.baseaddr = (uintptr_t)lib->BaseOfDll; - RzBinFile *cur = rz_bin_cur(core->bin); - RzBinFile *bf = rz_bin_open(core->bin, lib->Path, &opts); - if (bf) { - const RzBinInfo *info = rz_bin_object_get_info(bf->o); - if (RZ_STR_ISNOTEMPTY(info->debug_file_name)) { - if (!rz_file_exists(info->debug_file_name)) { - dbg->corebind.cmdf(core, "idpd"); - } - dbg->corebind.cmd(core, "idp"); - } - rz_bin_file_set_cur_binfile(core->bin, cur); - } - } else { - RZ_LOG_ERROR("The library %s does not exist.\n", lib->Path); - } - } - } else { - RZ_LOG_WARN("Loading unknown library.\n"); - } - restore_thread = true; - } else if (reason == RZ_DEBUG_REASON_EXIT_LIB) { - RzDebugInfo *r = rz_debug_native_info(dbg, ""); - if (r && r->lib) { - if (tracelib(dbg, "unload", r->lib)) { - reason = RZ_DEBUG_REASON_TRAP; - } - } else { - RZ_LOG_WARN("Unloading unknown library.\n"); - } - restore_thread = true; - } else if (reason == RZ_DEBUG_REASON_NEW_PID) { - if (native_info && native_info->thread) { - PTHREAD_ITEM item = native_info->thread; - RZ_LOG_INFO("(%d) Created process %d (start @ %p) (teb @ %p)\n", item->pid, item->tid, item->lpStartAddress, item->lpThreadLocalBase); - } - } else if (reason == RZ_DEBUG_REASON_NEW_TID) { - if (native_info && native_info->thread) { - PTHREAD_ITEM item = native_info->thread; - RZ_LOG_INFO("(%d) Created thread %d (start @ %p) (teb @ %p)\n", item->pid, item->tid, item->lpStartAddress, item->lpThreadLocalBase); - } - restore_thread = true; - } else if (reason == RZ_DEBUG_REASON_EXIT_TID) { - PTHREAD_ITEM item = native_info->thread; - if (native_info && native_info->thread) { - RZ_LOG_INFO("(%d) Finished thread %d Exit code %lu\n", (ut32)item->pid, (ut32)item->tid, item->dwExitCode); - } - if (dbg->tid != orig_tid && item->tid != orig_tid) { - restore_thread = true; - } - } else if (reason == RZ_DEBUG_REASON_DEAD) { - if (native_info && native_info->thread) { - PTHREAD_ITEM item = native_info->thread; - RZ_LOG_INFO("(%d) Finished process with exit code %lu\n", dbg->main_pid, item->dwExitCode); - } - dbg->pid = -1; - dbg->tid = -1; - } else if (reason == RZ_DEBUG_REASON_USERSUSP && dbg->tid != orig_tid) { - if (native_info && native_info->thread) { - PTHREAD_ITEM item = native_info->thread; - RZ_LOG_INFO("(%d) Created DebugBreak thread %d (start @ %p)\n", item->pid, item->tid, item->lpStartAddress); - } - // DebugProcessBreak creates a new thread that will trigger a breakpoint. We record the - // tid here to ignore it once the breakpoint is hit. - wrap->break_tid = dbg->tid; - restore_thread = true; - } else if (reason == RZ_DEBUG_REASON_BREAKPOINT && dbg->tid == wrap->break_tid) { - wrap->break_tid = -2; - reason = RZ_DEBUG_REASON_NONE; - restore_thread = true; - } - rz_debug_info_free(native_info); - - if (restore_thread) { - // Attempt to return to the original thread after handling the event - dbg->tid = w32_select(dbg, dbg->pid, orig_tid); - if (dbg->tid == -1) { - dbg->pid = -1; - reason = RZ_DEBUG_REASON_DEAD; - } else { - if (dbg->tid != orig_tid) { - reason = RZ_DEBUG_REASON_UNKNOWN; - } - } - } - - dbg->reason.tid = pid; - dbg->reason.type = reason; - return reason; -} -// FIXME: Should WAIT_ON_ALL_CHILDREN be a compilation flag instead of runtime debug config? -#elif __linux__ && !defined(WAIT_ON_ALL_CHILDREN) // __WINDOWS__ -static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { - RzDebugReasonType reason = RZ_DEBUG_REASON_UNKNOWN; - - if (pid == -1) { - eprintf("ERROR: rz_debug_native_wait called with pid -1\n"); - return RZ_DEBUG_REASON_ERROR; - } - - reason = linux_dbg_wait(dbg, dbg->tid); - dbg->reason.type = reason; - return reason; -} -#else // if __WINDOWS__ & elif __linux__ && !defined (WAIT_ON_ALL_CHILDREN) -static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { - RzDebugReasonType reason = RZ_DEBUG_REASON_UNKNOWN; - - if (pid == -1) { - eprintf("ERROR: rz_debug_native_wait called with pid -1\n"); - return RZ_DEBUG_REASON_ERROR; - } - -#if __APPLE__ - rz_cons_break_push(NULL, NULL); - do { - reason = xnu_wait(dbg, pid); - if (reason == RZ_DEBUG_REASON_MACH_RCV_INTERRUPTED) { - if (rz_cons_is_breaked()) { - // Perhaps check the inferior is still alive, - // otherwise xnu_stop will fail. - reason = xnu_stop(dbg, pid) - ? RZ_DEBUG_REASON_USERSUSP - : RZ_DEBUG_REASON_UNKNOWN; - } else { - // Weird; we'll retry the wait. - continue; - } - } - break; - } while (true); - rz_cons_break_pop(); -#else - int status = -1; - // XXX: this is blocking, ^C will be ignored -#ifdef WAIT_ON_ALL_CHILDREN - int ret = waitpid(-1, &status, WAITPID_FLAGS); -#else - int ret = waitpid(-1, &status, 0); - if (ret != -1) { - reason = RZ_DEBUG_REASON_TRAP; - } -#endif // WAIT_ON_ALL_CHILDREN - if (ret == -1) { - rz_sys_perror("waitpid"); - return RZ_DEBUG_REASON_ERROR; - } - - // eprintf ("rz_debug_native_wait: status=%d (0x%x) (return=%d)\n", status, status, ret); - -#ifdef WAIT_ON_ALL_CHILDREN - if (ret != pid) { - reason = RZ_DEBUG_REASON_NEW_PID; - eprintf("switching to pid %d\n", ret); - rz_debug_select(dbg, ret, ret); - } -#endif // WAIT_ON_ALL_CHILDREN - - // TODO: switch status and handle reasons here - // FIXME: Remove linux handling from this function? -#if __linux__ && defined(PT_GETEVENTMSG) - reason = linux_ptrace_event(dbg, pid, status, true); -#endif // __linux__ - - /* propagate errors */ - if (reason == RZ_DEBUG_REASON_ERROR) { - return reason; - } - - /* we don't know what to do yet, let's try harder to figure it out. */ -#if __FreeBSD__ - if (reason == RZ_DEBUG_REASON_TRAP) { -#else - if (reason == RZ_DEBUG_REASON_UNKNOWN) { -#endif - if (WIFEXITED(status)) { - eprintf("child exited with status %d\n", WEXITSTATUS(status)); - reason = RZ_DEBUG_REASON_DEAD; - } else if (WIFSIGNALED(status)) { - eprintf("child received signal %d\n", WTERMSIG(status)); - reason = RZ_DEBUG_REASON_SIGNAL; - } else if (WIFSTOPPED(status)) { - if (WSTOPSIG(status) != SIGTRAP && - WSTOPSIG(status) != SIGSTOP) { - eprintf("Child stopped with signal %d\n", WSTOPSIG(status)); - } - - /* the ptrace documentation says GETSIGINFO is only necessary for - * differentiating the various stops. - * - * this might modify dbg->reason.signum - */ -#if __OpenBSD__ - reason = RZ_DEBUG_REASON_BREAKPOINT; -#else - if (rz_debug_handle_signals(dbg) != 0) { - return RZ_DEBUG_REASON_ERROR; - } - reason = dbg->reason.type; -#endif -#ifdef WIFCONTINUED - } else if (WIFCONTINUED(status)) { - eprintf("child continued...\n"); - reason = RZ_DEBUG_REASON_NONE; -#endif - } else if (status == 1) { - /* XXX(jjd): does this actually happen? */ - eprintf("debugger is dead with status 1!\n"); - reason = RZ_DEBUG_REASON_DEAD; - } else if (status == 0) { - /* XXX(jjd): does this actually happen? */ - eprintf("debugger is dead with status 0\n"); - reason = RZ_DEBUG_REASON_DEAD; - } else { - if (ret != pid) { - reason = RZ_DEBUG_REASON_NEW_PID; - } else { - /* ugh. still don't know :-/ */ - eprintf("returning from wait without knowing why...\n"); - } - } - } - - /* if we still don't know what to do, we have a problem... */ - if (reason == RZ_DEBUG_REASON_UNKNOWN) { - eprintf("%s: no idea what happened...\n", __func__); - reason = RZ_DEBUG_REASON_ERROR; - } -#endif // __APPLE__ - dbg->reason.tid = pid; - dbg->reason.type = reason; - return reason; -} -#endif // __WINDOWS__ - -#undef MAXPID -#define MAXPID 99999 - -static RzList /**/ *rz_debug_native_pids(RzDebug *dbg, int pid) { - RzList *list = rz_list_new(); - if (!list) { - return NULL; - } -#if __APPLE__ - if (pid) { - RzDebugPid *p = xnu_get_pid(pid); - if (p) { - rz_list_append(list, p); - } - } else { - int i; - for (i = 1; i < MAXPID; i++) { - RzDebugPid *p = xnu_get_pid(i); - if (p) { - rz_list_append(list, p); - } - } - } -#elif __WINDOWS__ - return w32_pid_list(dbg, pid, list); -#elif __linux__ - return linux_pid_list(pid, list); -#else /* rest is BSD */ - return bsd_pid_list(dbg, pid, list); -#endif - return list; -} - -RZ_API RZ_OWN RzList /**/ *rz_debug_native_threads(RzDebug *dbg, int pid) { - RzList *list = rz_list_new(); - if (!list) { - eprintf("No list?\n"); - return NULL; - } +// Native OS & Arch #if __APPLE__ - return xnu_thread_list(dbg, pid, list); -#elif __WINDOWS__ - return w32_thread_list(dbg, pid, list); -#elif __linux__ - return linux_thread_list(dbg, pid, list); -#else - return bsd_thread_list(dbg, pid, list); -#endif -} - -RZ_API ut64 rz_debug_get_tls(RZ_NONNULL RzDebug *dbg, int tid) { - rz_return_val_if_fail(dbg, 0); -#if __linux__ - return get_linux_tls_val(dbg, tid); -#else - return 0; -#endif -} - -#if __sun || __NetBSD__ || __KFBSD__ || __OpenBSD__ || __DragonFly__ - -// Function to read register from Linux, BSD, Android systems -static int bsd_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { - int showfpu = false; - int pid = dbg->pid; - int ret; - if (type < -1) { - showfpu = true; // hack for debugging - type = -type; - } - switch (type) { - case RZ_REG_TYPE_DRX: #if __i386__ || __x86_64__ -#if __KFBSD__ - { - // TODO - struct dbreg dbr; - ret = ptrace(PT_GETDBREGS, pid, (caddr_t)&dbr, sizeof(dbr)); - if (ret != 0) - return false; - // XXX: maybe the register map is not correct, must review - } -#endif -#endif - return true; - break; - case RZ_REG_TYPE_FPU: - case RZ_REG_TYPE_MMX: - case RZ_REG_TYPE_XMM: - break; - case RZ_REG_TYPE_SEG: - case RZ_REG_TYPE_FLG: - case RZ_REG_TYPE_GPR: { - RZ_DEBUG_REG_T regs; - memset(®s, 0, sizeof(regs)); - memset(buf, 0, size); -#if __NetBSD__ || __OpenBSD__ - ret = ptrace(PTRACE_GETREGS, pid, (caddr_t)®s, sizeof(regs)); -#elif __KFBSD__ - ret = ptrace(PT_GETREGS, pid, (caddr_t)®s, 0); +#include "apple_x86_64.c" #else -#warning not implemented for this platform - ret = 1; +#include "apple_aarch64.c" #endif - // if perror here says 'no such process' and the - // process exists still.. is because there's a - // missing call to 'wait'. and the process is not - // yet available to accept more ptrace queries. - if (ret != 0) - return false; - if (sizeof(regs) < size) - size = sizeof(regs); - memcpy(buf, ®s, size); - return sizeof(regs); - } break; - } - return true; -} -#endif // if __sun || __NetBSD__ || __KFBSD__ || __OpenBSD__ -// TODO: what about float and hardware regs here ??? -// TODO: add flag for type -static int rz_debug_native_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { - if (size < 1) { - return false; - } -#if __APPLE__ - return xnu_reg_read(dbg, type, buf, size); -#elif __WINDOWS__ - return w32_reg_read(dbg, type, buf, size); -#elif __linux__ - return linux_reg_read(dbg, type, buf, size); -#elif __sun || __NetBSD__ || __KFBSD__ || __OpenBSD__ || __DragonFly__ - return bsd_reg_read(dbg, type, buf, size); -#else -#warning dbg-native not supported for this platform - return false; -#endif -} - -static int rz_debug_native_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size) { - // XXX use switch or so - if (type == RZ_REG_TYPE_DRX) { +#elif __ANDROID__ #if __i386__ || __x86_64__ -#if __APPLE__ - return xnu_reg_write(dbg, type, buf, size); -#elif __WINDOWS__ - return w32_reg_write(dbg, type, buf, size); -#elif __linux__ - return linux_reg_write(dbg, type, buf, size); -#else - return bsd_reg_write(dbg, type, buf, size); -#endif -#else // i386/x86-64 - return false; -#endif - } else if (type == RZ_REG_TYPE_GPR) { -#if __APPLE__ - return xnu_reg_write(dbg, type, buf, size); -#elif __WINDOWS__ - return w32_reg_write(dbg, type, buf, size); -#elif __linux__ - return linux_reg_write(dbg, type, buf, size); -#elif __sun - int ret = ptrace(PTRACE_SETREGS, dbg->pid, - (void *)(size_t)buf, sizeof(RZ_DEBUG_REG_T)); - if (sizeof(RZ_DEBUG_REG_T) < size) - size = sizeof(RZ_DEBUG_REG_T); - return ret == 0; -#else - return bsd_reg_write(dbg, type, buf, size); -#endif - } else if (type == RZ_REG_TYPE_FPU) { -#if __linux__ - return linux_reg_write(dbg, type, buf, size); -#elif __APPLE__ - return false; -#elif __WINDOWS__ - return false; -#else - return bsd_reg_write(dbg, type, buf, size); -#endif - } // else eprintf ("TODO: reg_write_non-gpr (%d)\n", type); - return false; -} - -#if __linux__ -static int io_perms_to_prot(int io_perms) { - int prot_perms = PROT_NONE; - - if (io_perms & RZ_PERM_R) { - prot_perms |= PROT_READ; - } - if (io_perms & RZ_PERM_W) { - prot_perms |= PROT_WRITE; - } - if (io_perms & RZ_PERM_X) { - prot_perms |= PROT_EXEC; - } - return prot_perms; -} - -#if __linux__ && !__ANDROID__ -static int sys_thp_mode(void) { - size_t i; - const char *thp[] = { - "/sys/kernel/mm/transparent_hugepage/enabled", - "/sys/kernel/mm/redhat_transparent_hugepage/enabled", - }; - int ret = 0; - - for (i = 0; i < RZ_ARRAY_SIZE(thp); i++) { - char *val = rz_file_slurp(thp[i], NULL); - if (val) { - if (strstr(val, "[madvise]")) { - ret = 1; - } else if (strstr(val, "[always]")) { - ret = 2; - } - free(val); - break; - } - } - - return ret; -} -#endif - -static int linux_map_thp(RzDebug *dbg, ut64 addr, int size) { -#if !defined(__ANDROID__) && defined(MADV_HUGEPAGE) - RzBuffer *buf = NULL; - char code[1024]; - int ret = true; - char *asm_list[] = { - "x86", "x86.as", - "x64", "x86.as", - NULL - }; - // In architectures where rizin is supported, arm and x86, it is 2MB - const size_t thpsize = 1 << 21; - - if ((size % thpsize)) { - eprintf("size not a power of huge pages size\n"); - return false; - } - -#if __linux__ - // In always mode, is more into mmap syscall level - // even though the address might not have the 'hg' - // vmflags - if (sys_thp_mode() != 1) { - eprintf("transparent huge page mode is not in madvise mode\n"); - return false; - } -#endif - - int num = rz_syscall_get_num(dbg->analysis->syscall, "madvise"); - - snprintf(code, sizeof(code), - "sc_madvise@syscall(%d);\n" - "main@naked(0) { .rarg0 = sc_madvise(0x%08" PFMT64x ",%d, %d);break;\n" - "}\n", - num, addr, size, MADV_HUGEPAGE); - rz_egg_reset(dbg->egg); - rz_egg_setup(dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); - rz_egg_load(dbg->egg, code, 0); - if (!rz_egg_compile(dbg->egg)) { - eprintf("Cannot compile.\n"); - goto err_linux_map_thp; - } - if (!rz_egg_assemble_asm(dbg->egg, asm_list)) { - eprintf("rz_egg_assemble: invalid assembly\n"); - goto err_linux_map_thp; - } - buf = rz_egg_get_bin(dbg->egg); - if (buf) { - rz_reg_arena_push(dbg->reg); - ut64 tmpsz; - const ut8 *tmp = rz_buf_data(buf, &tmpsz); - ret = rz_debug_execute(dbg, tmp, tmpsz, 1) == 0; - rz_reg_arena_pop(dbg->reg); - } -err_linux_map_thp: - return ret; -#else - return false; -#endif -} - -static RzDebugMap *linux_map_alloc(RzDebug *dbg, ut64 addr, int size, bool thp) { - RzBuffer *buf = NULL; - RzDebugMap *map = NULL; - char code[1024], *sc_name; - int num; - /* force to usage of x86.as, not yet working x86.nz */ - char *asm_list[] = { - "x86", "x86.as", - "x64", "x86.as", - NULL - }; - - /* NOTE: Since kernel 2.4, that system call has been superseded by - mmap2(2 and nowadays the glibc mmap() wrapper function invokes - mmap2(2)). If arch is x86_32 then usage mmap2() */ - if (!strcmp(dbg->arch, "x86") && dbg->bits == 4) { - sc_name = "mmap2"; - } else { - sc_name = "mmap"; - } - num = rz_syscall_get_num(dbg->analysis->syscall, sc_name); -#ifndef MAP_ANONYMOUS -#define MAP_ANONYMOUS 0x20 -#endif - snprintf(code, sizeof(code), - "sc_mmap@syscall(%d);\n" - "main@naked(0) { .rarg0 = sc_mmap(0x%08" PFMT64x ",%d,%d,%d,%d,%d);break;\n" - "}\n", - num, addr, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); - rz_egg_reset(dbg->egg); - rz_egg_setup(dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); - rz_egg_load(dbg->egg, code, 0); - if (!rz_egg_compile(dbg->egg)) { - eprintf("Cannot compile.\n"); - goto err_linux_map_alloc; - } - if (!rz_egg_assemble_asm(dbg->egg, asm_list)) { - eprintf("rz_egg_assemble: invalid assembly\n"); - goto err_linux_map_alloc; - } - buf = rz_egg_get_bin(dbg->egg); - if (buf) { - ut64 map_addr; - - rz_reg_arena_push(dbg->reg); - ut64 tmpsz; - const ut8 *tmp = rz_buf_data(buf, &tmpsz); - map_addr = rz_debug_execute(dbg, tmp, tmpsz, 1); - rz_reg_arena_pop(dbg->reg); - if (map_addr != (ut64)-1) { - if (thp) { - if (!linux_map_thp(dbg, map_addr, size)) { - // Not overly dramatic - eprintf("map promotion to huge page failed\n"); - } - } - rz_debug_map_sync(dbg); - map = rz_debug_map_get(dbg, map_addr); - } - } -err_linux_map_alloc: - return map; -} - -static int linux_map_dealloc(RzDebug *dbg, ut64 addr, int size) { - RzBuffer *buf = NULL; - char code[1024]; - int ret = 0; - char *asm_list[] = { - "x86", "x86.as", - "x64", "x86.as", - NULL - }; - int num = rz_syscall_get_num(dbg->analysis->syscall, "munmap"); - - snprintf(code, sizeof(code), - "sc_munmap@syscall(%d);\n" - "main@naked(0) { .rarg0 = sc_munmap(0x%08" PFMT64x ",%d);break;\n" - "}\n", - num, addr, size); - rz_egg_reset(dbg->egg); - rz_egg_setup(dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); - rz_egg_load(dbg->egg, code, 0); - if (!rz_egg_compile(dbg->egg)) { - eprintf("Cannot compile.\n"); - goto err_linux_map_dealloc; - } - if (!rz_egg_assemble_asm(dbg->egg, asm_list)) { - eprintf("rz_egg_assemble: invalid assembly\n"); - goto err_linux_map_dealloc; - } - buf = rz_egg_get_bin(dbg->egg); - if (buf) { - rz_reg_arena_push(dbg->reg); - ut64 tmpsz; - const ut8 *tmp = rz_buf_data(buf, &tmpsz); - ret = rz_debug_execute(dbg, tmp, tmpsz, 1) == 0; - rz_reg_arena_pop(dbg->reg); - } -err_linux_map_dealloc: - return ret; -} -#endif - -static RzDebugMap *rz_debug_native_map_alloc(RzDebug *dbg, ut64 addr, int size, bool thp) { -#if __APPLE__ - (void)thp; - return xnu_map_alloc(dbg, addr, size); -#elif __WINDOWS__ - (void)thp; - return w32_map_alloc(dbg, addr, size); -#elif __linux__ - return linux_map_alloc(dbg, addr, size, thp); +#include "android_x86_64.c" +#elif __arm__ +#include "android_arm.c" #else - // malloc not implemented for this platform - return NULL; +#include "android_arm64.c" #endif -} -static int rz_debug_native_map_dealloc(RzDebug *dbg, ut64 addr, int size) { -#if __APPLE__ - return xnu_map_dealloc(dbg, addr, size); -#elif __WINDOWS__ - return w32_map_dealloc(dbg, addr, size); #elif __linux__ - return linux_map_dealloc(dbg, addr, size); -#else - // mdealloc not implemented for this platform - return false; -#endif -} - -#if !__WINDOWS__ && !__APPLE__ -static void _map_free(RzDebugMap *map) { - if (!map) { - return; - } - free(map->name); - free(map->file); - free(map); -} -#endif - -static RzList /**/ *rz_debug_native_map_get(RzDebug *dbg) { - RzList *list = NULL; -#if __KFBSD__ - int ign; - char unkstr[PROC_UNKSTR_SZ + 1]; -#endif -#if __APPLE__ - list = xnu_dbg_maps(dbg, 0); -#elif __WINDOWS__ - list = rz_w32_dbg_maps(dbg); -#else -#if __sun - char path[1024]; - /* TODO: On solaris parse /proc/%d/map */ - snprintf(path, sizeof(path) - 1, "pmap %d >&2", ps.tid); - rz_sys_xsystem(path); -#else - RzDebugMap *map; - int i, perm, unk = 0; - char *pos_c; - char path[1024], line[1024], name[PROC_NAME_SZ + 1]; - char region[PROC_REGION_SZ + 1], region2[PROC_REGION_SZ + 1], perms[PROC_PERM_SZ + 1]; - FILE *fd; - if (dbg->pid == -1) { - // eprintf ("rz_debug_native_map_get: No selected pid (-1)\n"); - return NULL; - } - /* prepend 0x prefix */ - region[0] = region2[0] = '0'; - region[1] = region2[1] = 'x'; - -#if __OpenBSD__ - /* OpenBSD has no procfs, so no idea trying. */ - return bsd_native_sysctl_map(dbg); -#endif - -#if __KFBSD__ - list = bsd_native_sysctl_map(dbg); - if (list) { - return list; - } - snprintf(path, sizeof(path), "/proc/%d/map", dbg->pid); -#else - snprintf(path, sizeof(path), "/proc/%d/maps", dbg->pid); -#endif - fd = rz_sys_fopen(path, "r"); - if (!fd) { - char *errmsg = rz_str_newf("Cannot open '%s'", path); - perror(errmsg); - free(errmsg); - return NULL; - } - - list = rz_list_new(); - if (!list) { - fclose(fd); - return NULL; - } - list->free = (RzListFree)_map_free; - while (!feof(fd)) { - size_t line_len; - bool map_is_shared = false; - ut64 map_start, map_end; - - if (!fgets(line, sizeof(line), fd)) { - break; - } - /* kill the newline if we got one */ - line_len = strlen(line); - if (line[line_len - 1] == '\n') { - line[line_len - 1] = '\0'; - line_len--; - } - /* maps files should not have empty lines */ - if (line_len == 0) { - break; - } -#if __KFBSD__ - // 0x8070000 0x8072000 2 0 0xc1fde948 rw- 1 0 0x2180 COW NC vnode /usr/bin/gcc - if (sscanf(line, "%" RZ_STR_DEF(PROC_REGION_LEFT_SZ) "s %" RZ_STR_DEF(PROC_REGION_LEFT_SZ) "s %d %d 0x%" RZ_STR_DEF(PROC_UNKSTR_SZ) "s %3s %d %d", - ®ion[2], ®ion2[2], &ign, &ign, - unkstr, perms, &ign, &ign) != 8) { - eprintf("%s: Unable to parse \"%s\"\n", __func__, path); - rz_list_free(list); - return NULL; - } - - /* snag the file name */ - pos_c = strchr(line, '/'); - if (pos_c) { - strncpy(name, pos_c, sizeof(name) - 1); - } else { - name[0] = '\0'; - } -#else - ut64 offset = 0; - // 7fc8124c4000-7fc81278d000 r--p 00000000 fc:00 17043921 /usr/lib/locale/locale-archive - i = sscanf(line, "%" RZ_STR_DEF(PROC_REGION_LEFT_SZ) "s %" RZ_STR_DEF(PROC_PERM_SZ) "s %08" PFMT64x " %*s %*s %" RZ_STR_DEF(PROC_NAME_SZ) "[^\n]", ®ion[2], perms, &offset, name); - if (i == 3) { - name[0] = '\0'; - } else if (i != 4) { - eprintf("%s: Unable to parse \"%s\"\n", __func__, path); - eprintf("%s: problematic line: %s\n", __func__, line); - rz_list_free(list); - return NULL; - } - - /* split the region in two */ - pos_c = strchr(®ion[2], '-'); - if (!pos_c) { // should this be an error? - continue; - } - strncpy(®ion2[2], pos_c + 1, sizeof(region2) - 2 - 1); -#endif // __KFBSD__ - if (!*name) { - snprintf(name, sizeof(name), "unk%d", unk++); - } - perm = 0; - for (i = 0; i < 5 && perms[i]; i++) { - switch (perms[i]) { - case 'r': perm |= RZ_PERM_R; break; - case 'w': perm |= RZ_PERM_W; break; - case 'x': perm |= RZ_PERM_X; break; - case 'p': map_is_shared = false; break; - case 's': map_is_shared = true; break; - } - } - - map_start = rz_num_get(NULL, region); - map_end = rz_num_get(NULL, region2); - if (map_start == map_end || map_end == 0) { - eprintf("%s: ignoring invalid map size: %s - %s\n", __func__, region, region2); - continue; - } - map = rz_debug_map_new(name, map_start, map_end, perm, 0); - if (!map) { - break; - } -#if __linux__ - map->offset = offset; - map->shared = map_is_shared; -#endif - map->file = strdup(name); - rz_list_append(list, map); - } - fclose(fd); -#endif // __sun -#endif // __APPLE__ - return list; -} - -static RzList /**/ *rz_debug_native_modules_get(RzDebug *dbg) { - char *lastname = NULL; - RzDebugMap *map; - RzListIter *iter, *iter2; - RzList *list, *last; - bool must_delete; -#if __APPLE__ - list = xnu_dbg_maps(dbg, 1); - if (list && !rz_list_empty(list)) { - return list; - } -#elif __WINDOWS__ - list = rz_w32_dbg_modules(dbg); - if (list && !rz_list_empty(list)) { - return list; - } -#endif - if (!(list = rz_debug_native_map_get(dbg))) { - return NULL; - } - if (!(last = rz_list_newf((RzListFree)rz_debug_map_free))) { - rz_list_free(list); - return NULL; - } - rz_list_foreach_safe (list, iter, iter2, map) { - const char *file = map->file; - if (!map->file) { - file = map->file = strdup(map->name); - } - must_delete = true; - if (file && *file == '/') { - if (!lastname || strcmp(lastname, file)) { - must_delete = false; - } - } - if (must_delete) { - rz_list_delete(list, iter); - } else { - rz_list_append(last, map); - free(lastname); - lastname = strdup(file); - } - } - list->free = NULL; - free(lastname); - rz_list_free(list); - return last; -} - -static bool rz_debug_native_kill(RzDebug *dbg, int pid, int tid, int sig) { - bool ret = false; - if (pid == 0) { - pid = dbg->pid; - } -#if __WINDOWS__ - ret = w32_kill(dbg, pid, tid, sig); -#else -#if 0 - if (thread) { -// XXX this is linux>2.5 specific..ugly - if (dbg->tid>0 && (ret = tgkill (dbg->pid, dbg->tid, sig))) { - if (ret != -1) - ret = true; - } - } else { -#endif - if (sig == SIGKILL && dbg->threads) { - rz_list_free(dbg->threads); - dbg->threads = NULL; - } - if ((rz_sys_kill(pid, sig) != -1)) { - ret = true; - } - if (errno == 1) { - ret = -true; // EPERM - } -#if 0 -// } -#endif -#endif - return ret; -} - -struct rz_debug_desc_plugin_t rz_debug_desc_plugin_native; -static bool rz_debug_native_init(RzDebug *dbg, void **user) { - dbg->cur->desc = rz_debug_desc_plugin_native; -#if __WINDOWS__ - return w32_init(dbg); -#elif __APPLE__ - return rz_xnu_debug_init(dbg, user); -#else - return true; -#endif -} - -static void rz_debug_native_fini(RzDebug *dbg, void *user) { -#if __APPLE__ - rz_xnu_debug_fini(dbg, user); -#endif -} - #if __i386__ || __x86_64__ -static void sync_drx_regs(RzDebug *dbg, drxt *regs, size_t num_regs) { - /* sanity check, we rely on this assumption */ - if (num_regs != NUM_DRX_REGISTERS) { - eprintf("drx: Unsupported number of registers for get_debug_regs\n"); - return; - } - - // sync drx regs -#define R dbg->reg - regs[0] = rz_reg_getv(R, "dr0"); - regs[1] = rz_reg_getv(R, "dr1"); - regs[2] = rz_reg_getv(R, "dr2"); - regs[3] = rz_reg_getv(R, "dr3"); - /* - RESERVED - regs[4] = rz_reg_getv (R, "dr4"); - regs[5] = rz_reg_getv (R, "dr5"); -*/ - regs[6] = rz_reg_getv(R, "dr6"); - regs[7] = rz_reg_getv(R, "dr7"); -} -#endif - -#if __i386__ || __x86_64__ -static void set_drx_regs(RzDebug *dbg, drxt *regs, size_t num_regs) { - /* sanity check, we rely on this assumption */ - if (num_regs != NUM_DRX_REGISTERS) { - eprintf("drx: Unsupported number of registers for get_debug_regs\n"); - return; - } - -#define R dbg->reg - rz_reg_setv(R, "dr0", regs[0]); - rz_reg_setv(R, "dr1", regs[1]); - rz_reg_setv(R, "dr2", regs[2]); - rz_reg_setv(R, "dr3", regs[3]); - rz_reg_setv(R, "dr6", regs[6]); - rz_reg_setv(R, "dr7", regs[7]); -} -#endif - -static int rz_debug_native_drx(RzDebug *dbg, int n, ut64 addr, int sz, int rwx, int g, int api_type) { -#if __i386__ || __x86_64__ - int retval = false; - drxt regs[NUM_DRX_REGISTERS] = { 0 }; - // sync drx regs - sync_drx_regs(dbg, regs, NUM_DRX_REGISTERS); - - switch (api_type) { - case DRX_API_LIST: - drx_list(regs); - retval = false; - break; - case DRX_API_GET_BP: - /* get the index of the breakpoint at addr */ - retval = drx_get_at(regs, addr); - break; - case DRX_API_REMOVE_BP: - /* remove hardware breakpoint */ - drx_set(regs, n, addr, -1, 0, 0); - retval = true; - break; - case DRX_API_SET_BP: - /* set hardware breakpoint */ - drx_set(regs, n, addr, sz, rwx, g); - retval = true; - break; - default: - /* this should not happen, someone misused the API */ - eprintf("drx: Unsupported api type in rz_debug_native_drx\n"); - retval = false; - } - - set_drx_regs(dbg, regs, NUM_DRX_REGISTERS); - - return retval; -#else - eprintf("drx: Unsupported platform\n"); -#endif - return -1; -} - -#if __linux__ - -#if __arm__ || __arm64__ || __aarch64__ -#include -#include - -#define NT_ARM_VFP 0x400 /* ARM VFP/NEON registers */ -#define NT_ARM_TLS 0x401 /* ARM TLS register */ -#define NT_ARM_HW_BREAK 0x402 /* ARM hardware breakpoint registers */ -#define NT_ARM_HW_WATCH 0x403 /* ARM hardware watchpoint registers */ -#define NT_ARM_SYSTEM_CALL 0x404 /* ARM system call number */ - -#ifndef PTRACE_GETHBPREGS -#define PTRACE_GETHBPREGS 29 -#define PTRACE_SETHBPREGS 30 -#endif - -#if __arm__ - -static bool ll_arm32_hwbp_set(pid_t pid, ut64 addr, int size, int wp, int type) { - const unsigned byte_mask = (1 << size) - 1; - // const unsigned type = 2; // Write. - const unsigned enable = 1; - const unsigned control = byte_mask << 5 | type << 3 | enable; - (void)ptrace(PTRACE_SETHBPREGS, pid, -1, (void *)(size_t)addr); - return ptrace(PTRACE_SETHBPREGS, pid, -2, &control) != -1; -} - -static bool arm32_hwbp_add(RzDebug *dbg, RzBreakpoint *bp, RzBreakpointItem *b) { - return ll_arm32_hwbp_set(dbg->pid, b->addr, b->size, 0, 1 | 2 | 4); -} - -static bool arm32_hwbp_del(RzDebug *dbg, RzBreakpoint *bp, RzBreakpointItem *b) { - return false; // TODO: hwbp.del not yetimplemented -} -#endif // PTRACE_GETHWBPREGS -#endif // __arm - -#if (__arm64__ || __aarch64__) && defined(PTRACE_GETREGSET) -// type = 2 = write -// static volatile uint8_t var[96] __attribute__((__aligned__(32))); - -static bool ll_arm64_hwbp_set(pid_t pid, ut64 _addr, int size, int wp, ut32 type) { - const volatile uint8_t *addr = (void *)(size_t)_addr; //&var[32 + wp]; - const unsigned int offset = (uintptr_t)addr % 8; - const ut32 byte_mask = ((1 << size) - 1) << offset; - const ut32 enable = 1; - const ut32 control = byte_mask << 5 | type << 3 | enable; - - struct user_hwdebug_state dreg_state = { 0 }; - struct iovec iov = { 0 }; - iov.iov_base = &dreg_state; - iov.iov_len = sizeof(dreg_state); - - if (ptrace(PTRACE_GETREGSET, pid, NT_ARM_HW_WATCH, &iov) == -1) { - // error reading regs - } - memcpy(&dreg_state, iov.iov_base, sizeof(dreg_state)); - // wp is not honored here i think... we can't have more than one wp for now.. - dreg_state.dbg_regs[0].addr = (uintptr_t)(addr - offset); - dreg_state.dbg_regs[0].ctrl = control; - iov.iov_base = &dreg_state; - iov.iov_len = rz_offsetof(struct user_hwdebug_state, dbg_regs) + - sizeof(dreg_state.dbg_regs[0]); - if (ptrace(PTRACE_SETREGSET, pid, NT_ARM_HW_WATCH, &iov) == 0) { - return true; - } - - if (errno == EIO) { - eprintf("ptrace(PTRACE_SETREGSET, NT_ARM_HW_WATCH) not supported on this hardware: %s\n", - strerror(errno)); - } - - eprintf("ptrace(PTRACE_SETREGSET, NT_ARM_HW_WATCH) failed: %s\n", strerror(errno)); - return false; -} - -static bool ll_arm64_hwbp_del(pid_t pid, ut64 _addr, int size, int wp, ut32 type) { - // const volatile uint8_t *addr = &var[32 + wp]; - // TODO: support multiple watchpoints and find - struct user_hwdebug_state dreg_state = { 0 }; - struct iovec iov = { 0 }; - iov.iov_base = &dreg_state; - // only delete 1 bp for now - iov.iov_len = rz_offsetof(struct user_hwdebug_state, dbg_regs) + - sizeof(dreg_state.dbg_regs[0]); - if (ptrace(PTRACE_SETREGSET, pid, NT_ARM_HW_WATCH, &iov) == 0) { - return true; - } - if (errno == EIO) { - eprintf("ptrace(PTRACE_SETREGSET, NT_ARM_HW_WATCH) not supported on this hardware: %s\n", - strerror(errno)); - } - - eprintf("ptrace(PTRACE_SETREGSET, NT_ARM_HW_WATCH) failed: %s\n", strerror(errno)); - return false; -} - -static bool arm64_hwbp_add(RzDebug *dbg, RzBreakpoint *bp, RzBreakpointItem *b) { - return ll_arm64_hwbp_set(dbg->pid, b->addr, b->size, 0, 1 | 2 | 4); -} - -static bool arm64_hwbp_del(RzDebug *dbg, RzBreakpoint *bp, RzBreakpointItem *b) { - return ll_arm64_hwbp_del(dbg->pid, b->addr, b->size, 0, 1 | 2 | 4); -} - -#endif // __arm64__ -#endif // __linux__ - -/* - * set or unset breakpoints... - * - * we only handle the case for hardware breakpoints here. otherwise, - * we let the caller handle the work. - */ -static int rz_debug_native_bp(RzBreakpoint *bp, RzBreakpointItem *b, bool set) { - if (b && b->hw) { -#if __i386__ || __x86_64__ - return set - ? drx_add((RzDebug *)bp->user, bp, b) - : drx_del((RzDebug *)bp->user, bp, b); -#elif (__arm64__ || __aarch64__) && __linux__ - return set - ? arm64_hwbp_add((RzDebug *)bp->user, bp, b) - : arm64_hwbp_del((RzDebug *)bp->user, bp, b); -#elif __WINDOWS__ - return set - ? w32_hwbp_arm_add((RzDebug *)bp->user, bp, b) - : w32_hwbp_arm_del((RzDebug *)bp->user, bp, b); -#elif __arm__ && __linux__ - return set - ? arm32_hwbp_add((RzDebug *)bp->user, bp, b) - : arm32_hwbp_del((RzDebug *)bp->user, bp, b); -#endif - } - return false; -} - -#if __APPLE__ - -static int getMaxFiles(void) { - struct rlimit limit; - if (getrlimit(RLIMIT_NOFILE, &limit) != 0) { - return 1024; - } - return limit.rlim_cur; -} - -static RzList *xnu_desc_list(int pid) { -#if TARGET_OS_IPHONE || __POWERPC__ - return NULL; -#else -#define xwrz_testwx(x) ((x & 1) << 2) | (x & 2) | ((x & 4) >> 2) - RzDebugDesc *desc; - RzList *ret = rz_list_new(); - struct vnode_fdinfowithpath vi; - int i, nb, type = 0; - int maxfd = getMaxFiles(); - - for (i = 0; i < maxfd; i++) { - nb = proc_pidfdinfo(pid, i, PROC_PIDFDVNODEPATHINFO, &vi, sizeof(vi)); - if (nb < 1) { - continue; - } - if (nb < sizeof(vi)) { - perror("too few bytes"); - break; - } - // printf ("FD %d RWX %x ", i, vi.pfi.fi_openflags); - // printf ("PATH %s\n", vi.pvip.vip_path); - desc = rz_debug_desc_new(i, - vi.pvip.vip_path, - xwrz_testwx(vi.pfi.fi_openflags), - type, 0); - rz_list_append(ret, desc); - } - return ret; -#endif -} -#endif - -static RzList /**/ *rz_debug_desc_native_list(int pid) { -#if __APPLE__ - return xnu_desc_list(pid); -#elif __WINDOWS__ - return w32_desc_list(pid); -#elif __KFBSD__ || __NetBSD__ - return bsd_desc_list(pid); -#elif __linux__ - return linux_desc_list(pid); +#include "linux_x86_64.c" +#elif __arm__ +#include "linux_arm.c" #else -#warning list filedescriptors not supported for this platform - return NULL; +#include "linux_arm64.c" #endif -} -static int rz_debug_native_map_protect(RzDebug *dbg, ut64 addr, int size, int perms) { -#if __WINDOWS__ - return w32_map_protect(dbg, addr, size, perms); -#elif __APPLE__ - return xnu_map_protect(dbg, addr, size, perms); -#elif __linux__ - RzBuffer *buf = NULL; - char code[1024]; - int num; - - num = rz_syscall_get_num(dbg->analysis->syscall, "mprotect"); - snprintf(code, sizeof(code), - "sc@syscall(%d);\n" - "main@global(0) { sc(%p,%d,%d);\n" - ":int3\n" - "}\n", - num, (void *)(size_t)addr, size, io_perms_to_prot(perms)); +#elif __WIDOWS__ +#include "windows.c" - rz_egg_reset(dbg->egg); - rz_egg_setup(dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); - rz_egg_load(dbg->egg, code, 0); - if (!rz_egg_compile(dbg->egg)) { - eprintf("Cannot compile.\n"); - return false; - } - if (!rz_egg_assemble(dbg->egg)) { - eprintf("rz_egg_assemble: invalid assembly\n"); - return false; - } - buf = rz_egg_get_bin(dbg->egg); - if (buf) { - rz_reg_arena_push(dbg->reg); - ut64 tmpsz; - const ut8 *tmp = rz_buf_data(buf, &tmpsz); - rz_debug_execute(dbg, tmp, tmpsz, 1); - rz_reg_arena_pop(dbg->reg); - return true; - } - - return false; +#elif __BSD__ +#if __KFBSD__ +#include "KFBSD.c" +#elif __OpenBSD__ +#include "OpenBSD.c" +#elif __NetBSD__ +#include "NetBSD.c" +#elif __DragonFly__ +#include "DragonFly.c" #else - // mprotect not implemented for this platform - return false; +#warning Unsupported debugging platform +#undef DEBUGGER +#define DEBUGGER 0 #endif -} -static int rz_debug_desc_native_open(const char *path) { - return 0; -} - -#if 0 -static int rz_debug_setup_ownership (int fd, RzDebug *dbg) { - RzDebugInfo *info = rz_debug_info (dbg, NULL); - - if (!info) { - eprintf ("Error while getting debug info.\n"); - return -1; - } - fchown (fd, info->uid, info->gid); - rz_debug_info_free (info); - return 0; -} -#endif +#elif __sun +#define RZ_DEBUG_REG_T gregset_t +#undef DEBUGGER +#define DEBUGGER 0 +#warning No debugger support for SunOS yet -static bool rz_debug_gcore(RzDebug *dbg, char *path, RzBuffer *dest) { -#if __APPLE__ - (void)path; - return xnu_generate_corefile(dbg, dest); -#elif __linux__ && (__x86_64__ || __i386__ || __arm__ || __arm64__) - (void)path; -#if __ANDROID__ - return false; #else - return linux_generate_corefile(dbg, dest); -#endif -#elif __KFBSD__ || __NetBSD__ - return bsd_generate_corefile(dbg, path, dest); -#else - return false; -#endif -} +#warning Unsupported debugging platform +#undef DEBUGGER +#define DEBUGGER 0 +#endif // Native OS & Arch +#if DEBUGGER struct rz_debug_desc_plugin_t rz_debug_desc_plugin_native = { .open = rz_debug_desc_native_open, .list = rz_debug_desc_native_list, @@ -1700,10 +167,9 @@ RZ_API RzLibStruct rizin_plugin = { }; #endif // RZ_PLUGIN_INCORE -// #endif -#else // DEBUGGER +#else RzDebugPlugin rz_debug_plugin_native = { NULL // .name = "native", }; -#endif // DEBUGGER +#endif // DEBUGGER \ No newline at end of file diff --git a/librz/debug/p/linux_arm.c b/librz/debug/p/linux_arm.c new file mode 100644 index 00000000000..d533298dcd6 --- /dev/null +++ b/librz/debug/p/linux_arm.c @@ -0,0 +1,731 @@ +#include +#if !defined(__HAIKU__) && !defined(__sun) +#include +#endif +#include +#include + +#include +#include "native/linux/linux_debug.h" +#include "native/procfs.h" +#include "native/linux/linux_coredump.h" + +#ifdef __WALL +#define WAITPID_FLAGS __WALL +#else +#define WAITPID_FLAGS 0 +#endif + +#define PROC_NAME_SZ 1024 +#define PROC_REGION_SZ 100 +// PROC_REGION_SZ - 2 (used for `0x`). Due to how RZ_STR_DEF works this can't be +// computed. +#define PROC_REGION_LEFT_SZ 98 +#define PROC_PERM_SZ 5 +#define PROC_UNKSTR_SZ 128 + +#if WAIT_ON_ALL_CHILDREN +static int rz_debug_handle_signals(RzDebug *dbg) { + eprintf("Warning: signal handling is not supported on this platform\n"); + return 0; +} +#endif + +static char *rz_debug_native_reg_profile(RzDebug *dbg) { + return linux_reg_profile(dbg); +} + +#include "native/reg.c" + +static bool rz_debug_native_step(RzDebug *dbg) { + return linux_step(dbg); +} + +static int rz_debug_native_attach(RzDebug *dbg, int pid) { + return linux_attach(dbg, pid); +} + +static int rz_debug_native_detach(RzDebug *dbg, int pid) { + return rz_debug_ptrace(dbg, PTRACE_DETACH, pid, NULL, (rz_ptrace_data_t)(size_t)0); +} + +static int rz_debug_native_select(RzDebug *dbg, int pid, int tid) { + return linux_select(dbg, pid, tid); +} + +static int rz_debug_native_continue_syscall(RzDebug *dbg, int pid, int num) { + linux_set_options(dbg, pid); + return rz_debug_ptrace(dbg, PTRACE_SYSCALL, pid, 0, 0); +} + +static void interrupt_process(RzDebug *dbg) { + rz_debug_kill(dbg, dbg->pid, dbg->tid, SIGINT); + rz_cons_break_pop(); +} + +static int rz_debug_native_stop(RzDebug *dbg) { + return linux_stop_threads(dbg, dbg->reason.tid); +} + +static int rz_debug_native_continue(RzDebug *dbg, int pid, int tid, int sig) { + int contsig = dbg->reason.signum; + int ret = -1; + + if (sig != -1) { + contsig = sig; + } + /* SIGINT handler for attached processes: dbg.consbreak (disabled by default) */ + if (dbg->consbreak) { + rz_cons_break_push((RzConsBreak)interrupt_process, dbg); + } + + if (dbg->continue_all_threads && dbg->n_threads && dbg->threads) { + RzDebugPid *th; + RzListIter *it; + rz_list_foreach (dbg->threads, it, th) { + ret = rz_debug_ptrace(dbg, PTRACE_CONT, th->pid, 0, 0); + if (ret) { + eprintf("Error: (%d) is running or dead.\n", th->pid); + } + } + } else { + ret = rz_debug_ptrace(dbg, PTRACE_CONT, tid, NULL, (rz_ptrace_data_t)(size_t)contsig); + if (ret) { + rz_sys_perror("PTRACE_CONT"); + } + } + // return ret >= 0 ? tid : false; + return tid; +} + +static RzDebugInfo *rz_debug_native_info(RzDebug *dbg, const char *arg) { + return linux_info(dbg, arg); +} + +#ifdef WAIT_ON_ALL_CHILDREN +static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { + RzDebugReasonType reason = RZ_DEBUG_REASON_UNKNOWN; + + if (pid == -1) { + eprintf("ERROR: rz_debug_native_wait called with pid -1\n"); + return RZ_DEBUG_REASON_ERROR; + } + int status = -1; + // XXX: this is blocking, ^C will be ignored + int ret = waitpid(-1, &status, WAITPID_FLAGS); + if (ret == -1) { + rz_sys_perror("waitpid"); + return RZ_DEBUG_REASON_ERROR; + } + + // eprintf ("rz_debug_native_wait: status=%d (0x%x) (return=%d)\n", status, status, ret); + + if (ret != pid) { + reason = RZ_DEBUG_REASON_NEW_PID; + eprintf("switching to pid %d\n", ret); + rz_debug_select(dbg, ret, ret); + } + + // TODO: switch status and handle reasons here + // FIXME: Remove linux handling from this function? +#if defined(PT_GETEVENTMSG) + reason = linux_ptrace_event(dbg, pid, status, true); +#endif + + /* propagate errors */ + if (reason == RZ_DEBUG_REASON_ERROR) { + return reason; + } + + /* we don't know what to do yet, let's try harder to figure it out. */ + if (reason == RZ_DEBUG_REASON_UNKNOWN) { + if (WIFEXITED(status)) { + eprintf("child exited with status %d\n", WEXITSTATUS(status)); + reason = RZ_DEBUG_REASON_DEAD; + } else if (WIFSIGNALED(status)) { + eprintf("child received signal %d\n", WTERMSIG(status)); + reason = RZ_DEBUG_REASON_SIGNAL; + } else if (WIFSTOPPED(status)) { + if (WSTOPSIG(status) != SIGTRAP && + WSTOPSIG(status) != SIGSTOP) { + eprintf("Child stopped with signal %d\n", WSTOPSIG(status)); + } + + /* the ptrace documentation says GETSIGINFO is only necessary for + * differentiating the various stops. + * + * this might modify dbg->reason.signum + */ + if (rz_debug_handle_signals(dbg) != 0) { + return RZ_DEBUG_REASON_ERROR; + } + reason = dbg->reason.type; +#ifdef WIFCONTINUED + } else if (WIFCONTINUED(status)) { + eprintf("child continued...\n"); + reason = RZ_DEBUG_REASON_NONE; +#endif + } else if (status == 1) { + /* XXX(jjd): does this actually happen? */ + eprintf("debugger is dead with status 1!\n"); + reason = RZ_DEBUG_REASON_DEAD; + } else if (status == 0) { + /* XXX(jjd): does this actually happen? */ + eprintf("debugger is dead with status 0\n"); + reason = RZ_DEBUG_REASON_DEAD; + } else { + if (ret != pid) { + reason = RZ_DEBUG_REASON_NEW_PID; + } else { + /* ugh. still don't know :-/ */ + eprintf("returning from wait without knowing why...\n"); + } + } + } + + /* if we still don't know what to do, we have a problem... */ + if (reason == RZ_DEBUG_REASON_UNKNOWN) { + eprintf("%s: no idea what happened...\n", __func__); + reason = RZ_DEBUG_REASON_ERROR; + } + dbg->reason.tid = pid; + dbg->reason.type = reason; + return reason; +} +#else +static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { + RzDebugReasonType reason = RZ_DEBUG_REASON_UNKNOWN; + if (pid == -1) { + eprintf("ERROR: rz_debug_native_wait called with pid -1\n"); + return RZ_DEBUG_REASON_ERROR; + } + + reason = linux_dbg_wait(dbg, dbg->tid); + dbg->reason.type = reason; + return reason; +} +#endif + +#undef MAXPID +#define MAXPID 99999 + +static RzList /**/ *rz_debug_native_pids(RzDebug *dbg, int pid) { + RzList *list = rz_list_new(); + if (!list) { + return NULL; + } + return linux_pid_list(pid, list); +} + +RZ_API RZ_OWN RzList /**/ *rz_debug_native_threads(RzDebug *dbg, int pid) { + RzList *list = rz_list_new(); + if (!list) { + eprintf("No list?\n"); + return NULL; + } + return linux_thread_list(dbg, pid, list); +} + +RZ_API ut64 rz_debug_get_tls(RZ_NONNULL RzDebug *dbg, int tid) { + rz_return_val_if_fail(dbg, 0); + return get_linux_tls_val(dbg, tid); +} + +static int rz_debug_native_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { + if (size < 1) { + return false; + } + return linux_reg_read(dbg, type, buf, size); +} + +static int rz_debug_native_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size) { + // XXX use switch or so + if (type == RZ_REG_TYPE_DRX) { + return false; + } else if (type == RZ_REG_TYPE_GPR) { + return linux_reg_write(dbg, type, buf, size); + } else if (type == RZ_REG_TYPE_FPU) { + return linux_reg_write(dbg, type, buf, size); + } // else eprintf ("TODO: reg_write_non-gpr (%d)\n", type); + return false; +} + +static int io_perms_to_prot(int io_perms) { + int prot_perms = PROT_NONE; + + if (io_perms & RZ_PERM_R) { + prot_perms |= PROT_READ; + } + if (io_perms & RZ_PERM_W) { + prot_perms |= PROT_WRITE; + } + if (io_perms & RZ_PERM_X) { + prot_perms |= PROT_EXEC; + } + return prot_perms; +} + +static int sys_thp_mode(void) { + size_t i; + const char *thp[] = { + "/sys/kernel/mm/transparent_hugepage/enabled", + "/sys/kernel/mm/redhat_transparent_hugepage/enabled", + }; + int ret = 0; + + for (i = 0; i < RZ_ARRAY_SIZE(thp); i++) { + char *val = rz_file_slurp(thp[i], NULL); + if (val) { + if (strstr(val, "[madvise]")) { + ret = 1; + } else if (strstr(val, "[always]")) { + ret = 2; + } + free(val); + break; + } + } + + return ret; +} + +static int linux_map_thp(RzDebug *dbg, ut64 addr, int size) { +#if defined(MADV_HUGEPAGE) + RzBuffer *buf = NULL; + char code[1024]; + int ret = true; + char *asm_list[] = { + "x86", "x86.as", + "x64", "x86.as", + NULL + }; + // In architectures where rizin is supported, arm and x86, it is 2MB + const size_t thpsize = 1 << 21; + + if ((size % thpsize)) { + eprintf("size not a power of huge pages size\n"); + return false; + } + // In always mode, is more into mmap syscall level + // even though the address might not have the 'hg' + // vmflags + if (sys_thp_mode() != 1) { + eprintf("transparent huge page mode is not in madvise mode\n"); + return false; + } + + int num = rz_syscall_get_num(dbg->analysis->syscall, "madvise"); + + snprintf(code, sizeof(code), + "sc_madvise@syscall(%d);\n" + "main@naked(0) { .rarg0 = sc_madvise(0x%08" PFMT64x ",%d, %d);break;\n" + "}\n", + num, addr, size, MADV_HUGEPAGE); + rz_egg_reset(dbg->egg); + rz_egg_setup(dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); + rz_egg_load(dbg->egg, code, 0); + if (!rz_egg_compile(dbg->egg)) { + eprintf("Cannot compile.\n"); + goto err_linux_map_thp; + } + if (!rz_egg_assemble_asm(dbg->egg, asm_list)) { + eprintf("rz_egg_assemble: invalid assembly\n"); + goto err_linux_map_thp; + } + buf = rz_egg_get_bin(dbg->egg); + if (buf) { + rz_reg_arena_push(dbg->reg); + ut64 tmpsz; + const ut8 *tmp = rz_buf_data(buf, &tmpsz); + ret = rz_debug_execute(dbg, tmp, tmpsz, 1) == 0; + rz_reg_arena_pop(dbg->reg); + } +err_linux_map_thp: + return ret; +#else + return false; +#endif +} + +static RzDebugMap *linux_map_alloc(RzDebug *dbg, ut64 addr, int size, bool thp) { + RzBuffer *buf = NULL; + RzDebugMap *map = NULL; + char code[1024], *sc_name; + int num; + /* force to usage of x86.as, not yet working x86.nz */ + char *asm_list[] = { + "x86", "x86.as", + "x64", "x86.as", + NULL + }; + + /* NOTE: Since kernel 2.4, that system call has been superseded by + mmap2(2 and nowadays the glibc mmap() wrapper function invokes + mmap2(2)). If arch is x86_32 then usage mmap2() */ + if (!strcmp(dbg->arch, "x86") && dbg->bits == 4) { + sc_name = "mmap2"; + } else { + sc_name = "mmap"; + } + num = rz_syscall_get_num(dbg->analysis->syscall, sc_name); +#ifndef MAP_ANONYMOUS +#define MAP_ANONYMOUS 0x20 +#endif + snprintf(code, sizeof(code), + "sc_mmap@syscall(%d);\n" + "main@naked(0) { .rarg0 = sc_mmap(0x%08" PFMT64x ",%d,%d,%d,%d,%d);break;\n" + "}\n", + num, addr, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + rz_egg_reset(dbg->egg); + rz_egg_setup(dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); + rz_egg_load(dbg->egg, code, 0); + if (!rz_egg_compile(dbg->egg)) { + eprintf("Cannot compile.\n"); + goto err_linux_map_alloc; + } + if (!rz_egg_assemble_asm(dbg->egg, asm_list)) { + eprintf("rz_egg_assemble: invalid assembly\n"); + goto err_linux_map_alloc; + } + buf = rz_egg_get_bin(dbg->egg); + if (buf) { + ut64 map_addr; + + rz_reg_arena_push(dbg->reg); + ut64 tmpsz; + const ut8 *tmp = rz_buf_data(buf, &tmpsz); + map_addr = rz_debug_execute(dbg, tmp, tmpsz, 1); + rz_reg_arena_pop(dbg->reg); + if (map_addr != (ut64)-1) { + if (thp) { + if (!linux_map_thp(dbg, map_addr, size)) { + // Not overly dramatic + eprintf("map promotion to huge page failed\n"); + } + } + rz_debug_map_sync(dbg); + map = rz_debug_map_get(dbg, map_addr); + } + } +err_linux_map_alloc: + return map; +} + +static int linux_map_dealloc(RzDebug *dbg, ut64 addr, int size) { + RzBuffer *buf = NULL; + char code[1024]; + int ret = 0; + char *asm_list[] = { + "x86", "x86.as", + "x64", "x86.as", + NULL + }; + int num = rz_syscall_get_num(dbg->analysis->syscall, "munmap"); + + snprintf(code, sizeof(code), + "sc_munmap@syscall(%d);\n" + "main@naked(0) { .rarg0 = sc_munmap(0x%08" PFMT64x ",%d);break;\n" + "}\n", + num, addr, size); + rz_egg_reset(dbg->egg); + rz_egg_setup(dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); + rz_egg_load(dbg->egg, code, 0); + if (!rz_egg_compile(dbg->egg)) { + eprintf("Cannot compile.\n"); + goto err_linux_map_dealloc; + } + if (!rz_egg_assemble_asm(dbg->egg, asm_list)) { + eprintf("rz_egg_assemble: invalid assembly\n"); + goto err_linux_map_dealloc; + } + buf = rz_egg_get_bin(dbg->egg); + if (buf) { + rz_reg_arena_push(dbg->reg); + ut64 tmpsz; + const ut8 *tmp = rz_buf_data(buf, &tmpsz); + ret = rz_debug_execute(dbg, tmp, tmpsz, 1) == 0; + rz_reg_arena_pop(dbg->reg); + } +err_linux_map_dealloc: + return ret; +} + +static RzDebugMap *rz_debug_native_map_alloc(RzDebug *dbg, ut64 addr, int size, bool thp) { + return linux_map_alloc(dbg, addr, size, thp); +} + +static int rz_debug_native_map_dealloc(RzDebug *dbg, ut64 addr, int size) { + return linux_map_dealloc(dbg, addr, size); +} + +static void _map_free(RzDebugMap *map) { + if (!map) { + return; + } + free(map->name); + free(map->file); + free(map); +} + +static RzList /**/ *rz_debug_native_map_get(RzDebug *dbg) { + RzList *list = NULL; + RzDebugMap *map; + int i, perm, unk = 0; + char *pos_c; + char path[1024], line[1024], name[PROC_NAME_SZ + 1]; + char region[PROC_REGION_SZ + 1], region2[PROC_REGION_SZ + 1], perms[PROC_PERM_SZ + 1]; + FILE *fd; + if (dbg->pid == -1) { + // eprintf ("rz_debug_native_map_get: No selected pid (-1)\n"); + return NULL; + } + /* prepend 0x prefix */ + region[0] = region2[0] = '0'; + region[1] = region2[1] = 'x'; + + snprintf(path, sizeof(path), "/proc/%d/maps", dbg->pid); + + fd = rz_sys_fopen(path, "r"); + if (!fd) { + char *errmsg = rz_str_newf("Cannot open '%s'", path); + perror(errmsg); + free(errmsg); + return NULL; + } + + list = rz_list_new(); + if (!list) { + fclose(fd); + return NULL; + } + list->free = (RzListFree)_map_free; + while (!feof(fd)) { + size_t line_len; + bool map_is_shared = false; + ut64 map_start, map_end; + + if (!fgets(line, sizeof(line), fd)) { + break; + } + /* kill the newline if we got one */ + line_len = strlen(line); + if (line[line_len - 1] == '\n') { + line[line_len - 1] = '\0'; + line_len--; + } + /* maps files should not have empty lines */ + if (line_len == 0) { + break; + } + + ut64 offset = 0; + // 7fc8124c4000-7fc81278d000 r--p 00000000 fc:00 17043921 /usr/lib/locale/locale-archive + i = sscanf(line, "%" RZ_STR_DEF(PROC_REGION_LEFT_SZ) "s %" RZ_STR_DEF(PROC_PERM_SZ) "s %08" PFMT64x " %*s %*s %" RZ_STR_DEF(PROC_NAME_SZ) "[^\n]", ®ion[2], perms, &offset, name); + if (i == 3) { + name[0] = '\0'; + } else if (i != 4) { + eprintf("%s: Unable to parse \"%s\"\n", __func__, path); + eprintf("%s: problematic line: %s\n", __func__, line); + rz_list_free(list); + return NULL; + } + + /* split the region in two */ + pos_c = strchr(®ion[2], '-'); + if (!pos_c) { // should this be an error? + continue; + } + strncpy(®ion2[2], pos_c + 1, sizeof(region2) - 2 - 1); + + if (!*name) { + snprintf(name, sizeof(name), "unk%d", unk++); + } + perm = 0; + for (i = 0; i < 5 && perms[i]; i++) { + switch (perms[i]) { + case 'r': perm |= RZ_PERM_R; break; + case 'w': perm |= RZ_PERM_W; break; + case 'x': perm |= RZ_PERM_X; break; + case 'p': map_is_shared = false; break; + case 's': map_is_shared = true; break; + } + } + + map_start = rz_num_get(NULL, region); + map_end = rz_num_get(NULL, region2); + if (map_start == map_end || map_end == 0) { + eprintf("%s: ignoring invalid map size: %s - %s\n", __func__, region, region2); + continue; + } + map = rz_debug_map_new(name, map_start, map_end, perm, 0); + if (!map) { + break; + } + map->offset = offset; + map->shared = map_is_shared; + map->file = strdup(name); + rz_list_append(list, map); + } + fclose(fd); + return list; +} + +static RzList /**/ *rz_debug_native_modules_get(RzDebug *dbg) { + char *lastname = NULL; + RzDebugMap *map; + RzListIter *iter, *iter2; + RzList *list, *last; + bool must_delete; + if (!(list = rz_debug_native_map_get(dbg))) { + return NULL; + } + if (!(last = rz_list_newf((RzListFree)rz_debug_map_free))) { + rz_list_free(list); + return NULL; + } + rz_list_foreach_safe (list, iter, iter2, map) { + const char *file = map->file; + if (!map->file) { + file = map->file = strdup(map->name); + } + must_delete = true; + if (file && *file == '/') { + if (!lastname || strcmp(lastname, file)) { + must_delete = false; + } + } + if (must_delete) { + rz_list_delete(list, iter); + } else { + rz_list_append(last, map); + free(lastname); + lastname = strdup(file); + } + } + list->free = NULL; + free(lastname); + rz_list_free(list); + return last; +} + +static bool rz_debug_native_kill(RzDebug *dbg, int pid, int tid, int sig) { + bool ret = false; + if (pid == 0) { + pid = dbg->pid; + } + if (sig == SIGKILL && dbg->threads) { + rz_list_free(dbg->threads); + dbg->threads = NULL; + } + if ((rz_sys_kill(pid, sig) != -1)) { + ret = true; + } + if (errno == 1) { + ret = -true; // EPERM + } + return ret; +} + +struct rz_debug_desc_plugin_t rz_debug_desc_plugin_native; +static bool rz_debug_native_init(RzDebug *dbg, void **user) { + dbg->cur->desc = rz_debug_desc_plugin_native; + return true; +} + +static void rz_debug_native_fini(RzDebug *dbg, void *user) { +} + +static int rz_debug_native_drx(RzDebug *dbg, int n, ut64 addr, int sz, int rwx, int g, int api_type) { + eprintf("drx: Unsupported platform\n"); + return -1; +} + +#include +#include + +#define NT_ARM_VFP 0x400 /* ARM VFP/NEON registers */ +#define NT_ARM_TLS 0x401 /* ARM TLS register */ +#define NT_ARM_HW_BREAK 0x402 /* ARM hardware breakpoint registers */ +#define NT_ARM_HW_WATCH 0x403 /* ARM hardware watchpoint registers */ +#define NT_ARM_SYSTEM_CALL 0x404 /* ARM system call number */ + +#ifndef PTRACE_GETHBPREGS +#define PTRACE_GETHBPREGS 29 +#define PTRACE_SETHBPREGS 30 +#endif + +static bool ll_arm32_hwbp_set(pid_t pid, ut64 addr, int size, int wp, int type) { + const unsigned byte_mask = (1 << size) - 1; + // const unsigned type = 2; // Write. + const unsigned enable = 1; + const unsigned control = byte_mask << 5 | type << 3 | enable; + (void)ptrace(PTRACE_SETHBPREGS, pid, -1, (void *)(size_t)addr); + return ptrace(PTRACE_SETHBPREGS, pid, -2, &control) != -1; +} + +static bool arm32_hwbp_add(RzDebug *dbg, RzBreakpoint *bp, RzBreakpointItem *b) { + return ll_arm32_hwbp_set(dbg->pid, b->addr, b->size, 0, 1 | 2 | 4); +} + +static bool arm32_hwbp_del(RzDebug *dbg, RzBreakpoint *bp, RzBreakpointItem *b) { + return false; // TODO: hwbp.del not yetimplemented +} + +static int rz_debug_native_bp(RzBreakpoint *bp, RzBreakpointItem *b, bool set) { + if (b && b->hw) { + return set + ? arm32_hwbp_add((RzDebug *)bp->user, bp, b) + : arm32_hwbp_del((RzDebug *)bp->user, bp, b); + } + return false; +} + +static RzList /**/ *rz_debug_desc_native_list(int pid) { + return linux_desc_list(pid); +} + +static int rz_debug_native_map_protect(RzDebug *dbg, ut64 addr, int size, int perms) { + RzBuffer *buf = NULL; + char code[1024]; + int num; + + num = rz_syscall_get_num(dbg->analysis->syscall, "mprotect"); + snprintf(code, sizeof(code), + "sc@syscall(%d);\n" + "main@global(0) { sc(%p,%d,%d);\n" + ":int3\n" + "}\n", + num, (void *)(size_t)addr, size, io_perms_to_prot(perms)); + + rz_egg_reset(dbg->egg); + rz_egg_setup(dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); + rz_egg_load(dbg->egg, code, 0); + if (!rz_egg_compile(dbg->egg)) { + eprintf("Cannot compile.\n"); + return false; + } + if (!rz_egg_assemble(dbg->egg)) { + eprintf("rz_egg_assemble: invalid assembly\n"); + return false; + } + buf = rz_egg_get_bin(dbg->egg); + if (buf) { + rz_reg_arena_push(dbg->reg); + ut64 tmpsz; + const ut8 *tmp = rz_buf_data(buf, &tmpsz); + rz_debug_execute(dbg, tmp, tmpsz, 1); + rz_reg_arena_pop(dbg->reg); + return true; + } + + return false; +} + +static int rz_debug_desc_native_open(const char *path) { + return 0; +} + +static bool rz_debug_gcore(RzDebug *dbg, char *path, RzBuffer *dest) { + (void)path; + return linux_generate_corefile(dbg, dest); +} \ No newline at end of file diff --git a/librz/debug/p/linux_x86_64.c b/librz/debug/p/linux_x86_64.c new file mode 100644 index 00000000000..925646f534f --- /dev/null +++ b/librz/debug/p/linux_x86_64.c @@ -0,0 +1,769 @@ +#include +#if !defined(__HAIKU__) && !defined(__sun) +#include +#endif +#include +#include + +#include +#include "native/linux/linux_debug.h" +#include "native/procfs.h" +#include "native/linux/linux_coredump.h" + +#ifdef __WALL +#define WAITPID_FLAGS __WALL +#else +#define WAITPID_FLAGS 0 +#endif + +#define PROC_NAME_SZ 1024 +#define PROC_REGION_SZ 100 +// PROC_REGION_SZ - 2 (used for `0x`). Due to how RZ_STR_DEF works this can't be +// computed. +#define PROC_REGION_LEFT_SZ 98 +#define PROC_PERM_SZ 5 +#define PROC_UNKSTR_SZ 128 + +#if WAIT_ON_ALL_CHILDREN +static int rz_debug_handle_signals(RzDebug *dbg) { + eprintf("Warning: signal handling is not supported on this platform\n"); + return 0; +} +#endif + +static char *rz_debug_native_reg_profile(RzDebug *dbg) { + return linux_reg_profile(dbg); +} + +#include "native/reg.c" + +static bool rz_debug_native_step(RzDebug *dbg) { + return linux_step(dbg); +} + +static int rz_debug_native_attach(RzDebug *dbg, int pid) { + return linux_attach(dbg, pid); +} + +static int rz_debug_native_detach(RzDebug *dbg, int pid) { + return rz_debug_ptrace(dbg, PTRACE_DETACH, pid, NULL, (rz_ptrace_data_t)(size_t)0); +} + +static int rz_debug_native_select(RzDebug *dbg, int pid, int tid) { + return linux_select(dbg, pid, tid); +} + +static int rz_debug_native_continue_syscall(RzDebug *dbg, int pid, int num) { + linux_set_options(dbg, pid); + return rz_debug_ptrace(dbg, PTRACE_SYSCALL, pid, 0, 0); +} + +static void interrupt_process(RzDebug *dbg) { + rz_debug_kill(dbg, dbg->pid, dbg->tid, SIGINT); + rz_cons_break_pop(); +} + +static int rz_debug_native_stop(RzDebug *dbg) { + return linux_stop_threads(dbg, dbg->reason.tid); +} + +static int rz_debug_native_continue(RzDebug *dbg, int pid, int tid, int sig) { + int contsig = dbg->reason.signum; + int ret = -1; + + if (sig != -1) { + contsig = sig; + } + /* SIGINT handler for attached processes: dbg.consbreak (disabled by default) */ + if (dbg->consbreak) { + rz_cons_break_push((RzConsBreak)interrupt_process, dbg); + } + + if (dbg->continue_all_threads && dbg->n_threads && dbg->threads) { + RzDebugPid *th; + RzListIter *it; + rz_list_foreach (dbg->threads, it, th) { + ret = rz_debug_ptrace(dbg, PTRACE_CONT, th->pid, 0, 0); + if (ret) { + eprintf("Error: (%d) is running or dead.\n", th->pid); + } + } + } else { + ret = rz_debug_ptrace(dbg, PTRACE_CONT, tid, NULL, (rz_ptrace_data_t)(size_t)contsig); + if (ret) { + rz_sys_perror("PTRACE_CONT"); + } + } + // return ret >= 0 ? tid : false; + return tid; +} + +static RzDebugInfo *rz_debug_native_info(RzDebug *dbg, const char *arg) { + return linux_info(dbg, arg); +} + +#ifdef WAIT_ON_ALL_CHILDREN +static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { + RzDebugReasonType reason = RZ_DEBUG_REASON_UNKNOWN; + + if (pid == -1) { + eprintf("ERROR: rz_debug_native_wait called with pid -1\n"); + return RZ_DEBUG_REASON_ERROR; + } + int status = -1; + // XXX: this is blocking, ^C will be ignored + int ret = waitpid(-1, &status, WAITPID_FLAGS); + if (ret == -1) { + rz_sys_perror("waitpid"); + return RZ_DEBUG_REASON_ERROR; + } + + // eprintf ("rz_debug_native_wait: status=%d (0x%x) (return=%d)\n", status, status, ret); + + if (ret != pid) { + reason = RZ_DEBUG_REASON_NEW_PID; + eprintf("switching to pid %d\n", ret); + rz_debug_select(dbg, ret, ret); + } + + // TODO: switch status and handle reasons here + // FIXME: Remove linux handling from this function? +#if defined(PT_GETEVENTMSG) + reason = linux_ptrace_event(dbg, pid, status, true); +#endif + + /* propagate errors */ + if (reason == RZ_DEBUG_REASON_ERROR) { + return reason; + } + + /* we don't know what to do yet, let's try harder to figure it out. */ + if (reason == RZ_DEBUG_REASON_UNKNOWN) { + if (WIFEXITED(status)) { + eprintf("child exited with status %d\n", WEXITSTATUS(status)); + reason = RZ_DEBUG_REASON_DEAD; + } else if (WIFSIGNALED(status)) { + eprintf("child received signal %d\n", WTERMSIG(status)); + reason = RZ_DEBUG_REASON_SIGNAL; + } else if (WIFSTOPPED(status)) { + if (WSTOPSIG(status) != SIGTRAP && + WSTOPSIG(status) != SIGSTOP) { + eprintf("Child stopped with signal %d\n", WSTOPSIG(status)); + } + + /* the ptrace documentation says GETSIGINFO is only necessary for + * differentiating the various stops. + * + * this might modify dbg->reason.signum + */ + if (rz_debug_handle_signals(dbg) != 0) { + return RZ_DEBUG_REASON_ERROR; + } + reason = dbg->reason.type; +#ifdef WIFCONTINUED + } else if (WIFCONTINUED(status)) { + eprintf("child continued...\n"); + reason = RZ_DEBUG_REASON_NONE; +#endif + } else if (status == 1) { + /* XXX(jjd): does this actually happen? */ + eprintf("debugger is dead with status 1!\n"); + reason = RZ_DEBUG_REASON_DEAD; + } else if (status == 0) { + /* XXX(jjd): does this actually happen? */ + eprintf("debugger is dead with status 0\n"); + reason = RZ_DEBUG_REASON_DEAD; + } else { + if (ret != pid) { + reason = RZ_DEBUG_REASON_NEW_PID; + } else { + /* ugh. still don't know :-/ */ + eprintf("returning from wait without knowing why...\n"); + } + } + } + + /* if we still don't know what to do, we have a problem... */ + if (reason == RZ_DEBUG_REASON_UNKNOWN) { + eprintf("%s: no idea what happened...\n", __func__); + reason = RZ_DEBUG_REASON_ERROR; + } + dbg->reason.tid = pid; + dbg->reason.type = reason; + return reason; +} +#else +static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { + RzDebugReasonType reason = RZ_DEBUG_REASON_UNKNOWN; + if (pid == -1) { + eprintf("ERROR: rz_debug_native_wait called with pid -1\n"); + return RZ_DEBUG_REASON_ERROR; + } + + reason = linux_dbg_wait(dbg, dbg->tid); + dbg->reason.type = reason; + return reason; +} +#endif + +#undef MAXPID +#define MAXPID 99999 + +static RzList /**/ *rz_debug_native_pids(RzDebug *dbg, int pid) { + RzList *list = rz_list_new(); + if (!list) { + return NULL; + } + return linux_pid_list(pid, list); +} + +RZ_API RZ_OWN RzList /**/ *rz_debug_native_threads(RzDebug *dbg, int pid) { + RzList *list = rz_list_new(); + if (!list) { + eprintf("No list?\n"); + return NULL; + } + return linux_thread_list(dbg, pid, list); +} + +RZ_API ut64 rz_debug_get_tls(RZ_NONNULL RzDebug *dbg, int tid) { + rz_return_val_if_fail(dbg, 0); + return get_linux_tls_val(dbg, tid); +} + +static int rz_debug_native_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { + if (size < 1) { + return false; + } + return linux_reg_read(dbg, type, buf, size); +} + +static int rz_debug_native_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size) { + // XXX use switch or so + if (type == RZ_REG_TYPE_DRX) { + return linux_reg_write(dbg, type, buf, size); + } else if (type == RZ_REG_TYPE_GPR) { + return linux_reg_write(dbg, type, buf, size); + } else if (type == RZ_REG_TYPE_FPU) { + return linux_reg_write(dbg, type, buf, size); + } // else eprintf ("TODO: reg_write_non-gpr (%d)\n", type); + return false; +} + +static int io_perms_to_prot(int io_perms) { + int prot_perms = PROT_NONE; + + if (io_perms & RZ_PERM_R) { + prot_perms |= PROT_READ; + } + if (io_perms & RZ_PERM_W) { + prot_perms |= PROT_WRITE; + } + if (io_perms & RZ_PERM_X) { + prot_perms |= PROT_EXEC; + } + return prot_perms; +} + +static int sys_thp_mode(void) { + size_t i; + const char *thp[] = { + "/sys/kernel/mm/transparent_hugepage/enabled", + "/sys/kernel/mm/redhat_transparent_hugepage/enabled", + }; + int ret = 0; + + for (i = 0; i < RZ_ARRAY_SIZE(thp); i++) { + char *val = rz_file_slurp(thp[i], NULL); + if (val) { + if (strstr(val, "[madvise]")) { + ret = 1; + } else if (strstr(val, "[always]")) { + ret = 2; + } + free(val); + break; + } + } + + return ret; +} + +static int linux_map_thp(RzDebug *dbg, ut64 addr, int size) { +#if defined(MADV_HUGEPAGE) + RzBuffer *buf = NULL; + char code[1024]; + int ret = true; + char *asm_list[] = { + "x86", "x86.as", + "x64", "x86.as", + NULL + }; + // In architectures where rizin is supported, arm and x86, it is 2MB + const size_t thpsize = 1 << 21; + + if ((size % thpsize)) { + eprintf("size not a power of huge pages size\n"); + return false; + } + // In always mode, is more into mmap syscall level + // even though the address might not have the 'hg' + // vmflags + if (sys_thp_mode() != 1) { + eprintf("transparent huge page mode is not in madvise mode\n"); + return false; + } + + int num = rz_syscall_get_num(dbg->analysis->syscall, "madvise"); + + snprintf(code, sizeof(code), + "sc_madvise@syscall(%d);\n" + "main@naked(0) { .rarg0 = sc_madvise(0x%08" PFMT64x ",%d, %d);break;\n" + "}\n", + num, addr, size, MADV_HUGEPAGE); + rz_egg_reset(dbg->egg); + rz_egg_setup(dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); + rz_egg_load(dbg->egg, code, 0); + if (!rz_egg_compile(dbg->egg)) { + eprintf("Cannot compile.\n"); + goto err_linux_map_thp; + } + if (!rz_egg_assemble_asm(dbg->egg, asm_list)) { + eprintf("rz_egg_assemble: invalid assembly\n"); + goto err_linux_map_thp; + } + buf = rz_egg_get_bin(dbg->egg); + if (buf) { + rz_reg_arena_push(dbg->reg); + ut64 tmpsz; + const ut8 *tmp = rz_buf_data(buf, &tmpsz); + ret = rz_debug_execute(dbg, tmp, tmpsz, 1) == 0; + rz_reg_arena_pop(dbg->reg); + } +err_linux_map_thp: + return ret; +#else + return false; +#endif +} + +static RzDebugMap *linux_map_alloc(RzDebug *dbg, ut64 addr, int size, bool thp) { + RzBuffer *buf = NULL; + RzDebugMap *map = NULL; + char code[1024], *sc_name; + int num; + /* force to usage of x86.as, not yet working x86.nz */ + char *asm_list[] = { + "x86", "x86.as", + "x64", "x86.as", + NULL + }; + + /* NOTE: Since kernel 2.4, that system call has been superseded by + mmap2(2 and nowadays the glibc mmap() wrapper function invokes + mmap2(2)). If arch is x86_32 then usage mmap2() */ + if (!strcmp(dbg->arch, "x86") && dbg->bits == 4) { + sc_name = "mmap2"; + } else { + sc_name = "mmap"; + } + num = rz_syscall_get_num(dbg->analysis->syscall, sc_name); +#ifndef MAP_ANONYMOUS +#define MAP_ANONYMOUS 0x20 +#endif + snprintf(code, sizeof(code), + "sc_mmap@syscall(%d);\n" + "main@naked(0) { .rarg0 = sc_mmap(0x%08" PFMT64x ",%d,%d,%d,%d,%d);break;\n" + "}\n", + num, addr, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + rz_egg_reset(dbg->egg); + rz_egg_setup(dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); + rz_egg_load(dbg->egg, code, 0); + if (!rz_egg_compile(dbg->egg)) { + eprintf("Cannot compile.\n"); + goto err_linux_map_alloc; + } + if (!rz_egg_assemble_asm(dbg->egg, asm_list)) { + eprintf("rz_egg_assemble: invalid assembly\n"); + goto err_linux_map_alloc; + } + buf = rz_egg_get_bin(dbg->egg); + if (buf) { + ut64 map_addr; + + rz_reg_arena_push(dbg->reg); + ut64 tmpsz; + const ut8 *tmp = rz_buf_data(buf, &tmpsz); + map_addr = rz_debug_execute(dbg, tmp, tmpsz, 1); + rz_reg_arena_pop(dbg->reg); + if (map_addr != (ut64)-1) { + if (thp) { + if (!linux_map_thp(dbg, map_addr, size)) { + // Not overly dramatic + eprintf("map promotion to huge page failed\n"); + } + } + rz_debug_map_sync(dbg); + map = rz_debug_map_get(dbg, map_addr); + } + } +err_linux_map_alloc: + return map; +} + +static int linux_map_dealloc(RzDebug *dbg, ut64 addr, int size) { + RzBuffer *buf = NULL; + char code[1024]; + int ret = 0; + char *asm_list[] = { + "x86", "x86.as", + "x64", "x86.as", + NULL + }; + int num = rz_syscall_get_num(dbg->analysis->syscall, "munmap"); + + snprintf(code, sizeof(code), + "sc_munmap@syscall(%d);\n" + "main@naked(0) { .rarg0 = sc_munmap(0x%08" PFMT64x ",%d);break;\n" + "}\n", + num, addr, size); + rz_egg_reset(dbg->egg); + rz_egg_setup(dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); + rz_egg_load(dbg->egg, code, 0); + if (!rz_egg_compile(dbg->egg)) { + eprintf("Cannot compile.\n"); + goto err_linux_map_dealloc; + } + if (!rz_egg_assemble_asm(dbg->egg, asm_list)) { + eprintf("rz_egg_assemble: invalid assembly\n"); + goto err_linux_map_dealloc; + } + buf = rz_egg_get_bin(dbg->egg); + if (buf) { + rz_reg_arena_push(dbg->reg); + ut64 tmpsz; + const ut8 *tmp = rz_buf_data(buf, &tmpsz); + ret = rz_debug_execute(dbg, tmp, tmpsz, 1) == 0; + rz_reg_arena_pop(dbg->reg); + } +err_linux_map_dealloc: + return ret; +} + +static RzDebugMap *rz_debug_native_map_alloc(RzDebug *dbg, ut64 addr, int size, bool thp) { + return linux_map_alloc(dbg, addr, size, thp); +} + +static int rz_debug_native_map_dealloc(RzDebug *dbg, ut64 addr, int size) { + return linux_map_dealloc(dbg, addr, size); +} + +static void _map_free(RzDebugMap *map) { + if (!map) { + return; + } + free(map->name); + free(map->file); + free(map); +} + +static RzList /**/ *rz_debug_native_map_get(RzDebug *dbg) { + RzList *list = NULL; + RzDebugMap *map; + int i, perm, unk = 0; + char *pos_c; + char path[1024], line[1024], name[PROC_NAME_SZ + 1]; + char region[PROC_REGION_SZ + 1], region2[PROC_REGION_SZ + 1], perms[PROC_PERM_SZ + 1]; + FILE *fd; + if (dbg->pid == -1) { + // eprintf ("rz_debug_native_map_get: No selected pid (-1)\n"); + return NULL; + } + /* prepend 0x prefix */ + region[0] = region2[0] = '0'; + region[1] = region2[1] = 'x'; + + snprintf(path, sizeof(path), "/proc/%d/maps", dbg->pid); + + fd = rz_sys_fopen(path, "r"); + if (!fd) { + char *errmsg = rz_str_newf("Cannot open '%s'", path); + perror(errmsg); + free(errmsg); + return NULL; + } + + list = rz_list_new(); + if (!list) { + fclose(fd); + return NULL; + } + list->free = (RzListFree)_map_free; + while (!feof(fd)) { + size_t line_len; + bool map_is_shared = false; + ut64 map_start, map_end; + + if (!fgets(line, sizeof(line), fd)) { + break; + } + /* kill the newline if we got one */ + line_len = strlen(line); + if (line[line_len - 1] == '\n') { + line[line_len - 1] = '\0'; + line_len--; + } + /* maps files should not have empty lines */ + if (line_len == 0) { + break; + } + + ut64 offset = 0; + // 7fc8124c4000-7fc81278d000 r--p 00000000 fc:00 17043921 /usr/lib/locale/locale-archive + i = sscanf(line, "%" RZ_STR_DEF(PROC_REGION_LEFT_SZ) "s %" RZ_STR_DEF(PROC_PERM_SZ) "s %08" PFMT64x " %*s %*s %" RZ_STR_DEF(PROC_NAME_SZ) "[^\n]", ®ion[2], perms, &offset, name); + if (i == 3) { + name[0] = '\0'; + } else if (i != 4) { + eprintf("%s: Unable to parse \"%s\"\n", __func__, path); + eprintf("%s: problematic line: %s\n", __func__, line); + rz_list_free(list); + return NULL; + } + + /* split the region in two */ + pos_c = strchr(®ion[2], '-'); + if (!pos_c) { // should this be an error? + continue; + } + strncpy(®ion2[2], pos_c + 1, sizeof(region2) - 2 - 1); + + if (!*name) { + snprintf(name, sizeof(name), "unk%d", unk++); + } + perm = 0; + for (i = 0; i < 5 && perms[i]; i++) { + switch (perms[i]) { + case 'r': perm |= RZ_PERM_R; break; + case 'w': perm |= RZ_PERM_W; break; + case 'x': perm |= RZ_PERM_X; break; + case 'p': map_is_shared = false; break; + case 's': map_is_shared = true; break; + } + } + + map_start = rz_num_get(NULL, region); + map_end = rz_num_get(NULL, region2); + if (map_start == map_end || map_end == 0) { + eprintf("%s: ignoring invalid map size: %s - %s\n", __func__, region, region2); + continue; + } + map = rz_debug_map_new(name, map_start, map_end, perm, 0); + if (!map) { + break; + } + map->offset = offset; + map->shared = map_is_shared; + map->file = strdup(name); + rz_list_append(list, map); + } + fclose(fd); + return list; +} + +static RzList /**/ *rz_debug_native_modules_get(RzDebug *dbg) { + char *lastname = NULL; + RzDebugMap *map; + RzListIter *iter, *iter2; + RzList *list, *last; + bool must_delete; + if (!(list = rz_debug_native_map_get(dbg))) { + return NULL; + } + if (!(last = rz_list_newf((RzListFree)rz_debug_map_free))) { + rz_list_free(list); + return NULL; + } + rz_list_foreach_safe (list, iter, iter2, map) { + const char *file = map->file; + if (!map->file) { + file = map->file = strdup(map->name); + } + must_delete = true; + if (file && *file == '/') { + if (!lastname || strcmp(lastname, file)) { + must_delete = false; + } + } + if (must_delete) { + rz_list_delete(list, iter); + } else { + rz_list_append(last, map); + free(lastname); + lastname = strdup(file); + } + } + list->free = NULL; + free(lastname); + rz_list_free(list); + return last; +} + +static bool rz_debug_native_kill(RzDebug *dbg, int pid, int tid, int sig) { + bool ret = false; + if (pid == 0) { + pid = dbg->pid; + } + if (sig == SIGKILL && dbg->threads) { + rz_list_free(dbg->threads); + dbg->threads = NULL; + } + if ((rz_sys_kill(pid, sig) != -1)) { + ret = true; + } + if (errno == 1) { + ret = -true; // EPERM + } + return ret; +} + +struct rz_debug_desc_plugin_t rz_debug_desc_plugin_native; +static bool rz_debug_native_init(RzDebug *dbg, void **user) { + dbg->cur->desc = rz_debug_desc_plugin_native; + return true; +} + +static void rz_debug_native_fini(RzDebug *dbg, void *user) { +} + +static void sync_drx_regs(RzDebug *dbg, drxt *regs, size_t num_regs) { + /* sanity check, we rely on this assumption */ + if (num_regs != NUM_DRX_REGISTERS) { + eprintf("drx: Unsupported number of registers for get_debug_regs\n"); + return; + } + + // sync drx regs +#define R dbg->reg + regs[0] = rz_reg_getv(R, "dr0"); + regs[1] = rz_reg_getv(R, "dr1"); + regs[2] = rz_reg_getv(R, "dr2"); + regs[3] = rz_reg_getv(R, "dr3"); + /* + RESERVED + regs[4] = rz_reg_getv (R, "dr4"); + regs[5] = rz_reg_getv (R, "dr5"); +*/ + regs[6] = rz_reg_getv(R, "dr6"); + regs[7] = rz_reg_getv(R, "dr7"); +} + +static void set_drx_regs(RzDebug *dbg, drxt *regs, size_t num_regs) { + /* sanity check, we rely on this assumption */ + if (num_regs != NUM_DRX_REGISTERS) { + eprintf("drx: Unsupported number of registers for get_debug_regs\n"); + return; + } + +#define R dbg->reg + rz_reg_setv(R, "dr0", regs[0]); + rz_reg_setv(R, "dr1", regs[1]); + rz_reg_setv(R, "dr2", regs[2]); + rz_reg_setv(R, "dr3", regs[3]); + rz_reg_setv(R, "dr6", regs[6]); + rz_reg_setv(R, "dr7", regs[7]); +} + +static int rz_debug_native_drx(RzDebug *dbg, int n, ut64 addr, int sz, int rwx, int g, int api_type) { + int retval = false; + drxt regs[NUM_DRX_REGISTERS] = { 0 }; + // sync drx regs + sync_drx_regs(dbg, regs, NUM_DRX_REGISTERS); + + switch (api_type) { + case DRX_API_LIST: + drx_list(regs); + retval = false; + break; + case DRX_API_GET_BP: + /* get the index of the breakpoint at addr */ + retval = drx_get_at(regs, addr); + break; + case DRX_API_REMOVE_BP: + /* remove hardware breakpoint */ + drx_set(regs, n, addr, -1, 0, 0); + retval = true; + break; + case DRX_API_SET_BP: + /* set hardware breakpoint */ + drx_set(regs, n, addr, sz, rwx, g); + retval = true; + break; + default: + /* this should not happen, someone misused the API */ + eprintf("drx: Unsupported api type in rz_debug_native_drx\n"); + retval = false; + } + + set_drx_regs(dbg, regs, NUM_DRX_REGISTERS); + + return retval; +} + +static int rz_debug_native_bp(RzBreakpoint *bp, RzBreakpointItem *b, bool set) { + if (b && b->hw) { + return set + ? drx_add((RzDebug *)bp->user, bp, b) + : drx_del((RzDebug *)bp->user, bp, b); + } + return false; +} + +static RzList /**/ *rz_debug_desc_native_list(int pid) { + return linux_desc_list(pid); +} + +static int rz_debug_native_map_protect(RzDebug *dbg, ut64 addr, int size, int perms) { + RzBuffer *buf = NULL; + char code[1024]; + int num; + + num = rz_syscall_get_num(dbg->analysis->syscall, "mprotect"); + snprintf(code, sizeof(code), + "sc@syscall(%d);\n" + "main@global(0) { sc(%p,%d,%d);\n" + ":int3\n" + "}\n", + num, (void *)(size_t)addr, size, io_perms_to_prot(perms)); + + rz_egg_reset(dbg->egg); + rz_egg_setup(dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); + rz_egg_load(dbg->egg, code, 0); + if (!rz_egg_compile(dbg->egg)) { + eprintf("Cannot compile.\n"); + return false; + } + if (!rz_egg_assemble(dbg->egg)) { + eprintf("rz_egg_assemble: invalid assembly\n"); + return false; + } + buf = rz_egg_get_bin(dbg->egg); + if (buf) { + rz_reg_arena_push(dbg->reg); + ut64 tmpsz; + const ut8 *tmp = rz_buf_data(buf, &tmpsz); + rz_debug_execute(dbg, tmp, tmpsz, 1); + rz_reg_arena_pop(dbg->reg); + return true; + } + + return false; +} + +static int rz_debug_desc_native_open(const char *path) { + return 0; +} + +static bool rz_debug_gcore(RzDebug *dbg, char *path, RzBuffer *dest) { + (void)path; + return linux_generate_corefile(dbg, dest); +} \ No newline at end of file diff --git a/librz/debug/p/windows.c b/librz/debug/p/windows.c new file mode 100644 index 00000000000..4ef577c4f9d --- /dev/null +++ b/librz/debug/p/windows.c @@ -0,0 +1,433 @@ +#include "native/windows/windows_debug.h" +// TODO: Move these onto windows.h? +RZ_API RzList *rz_w32_dbg_modules(RzDebug *); // ugly! +RZ_API RzList *rz_w32_dbg_maps(RzDebug *); +#define RZ_DEBUG_REG_T CONTEXT +#ifdef NTSTATUS +#undef NTSTATUS +#endif +#ifndef NTSTATUS +#define NTSTATUS int +#endif + +#ifdef __WALL +#define WAITPID_FLAGS __WALL +#else +#define WAITPID_FLAGS 0 +#endif + +#define PROC_NAME_SZ 1024 +#define PROC_REGION_SZ 100 +// PROC_REGION_SZ - 2 (used for `0x`). Due to how RZ_STR_DEF works this can't be +// computed. +#define PROC_REGION_LEFT_SZ 98 +#define PROC_PERM_SZ 5 +#define PROC_UNKSTR_SZ 128 + +#include "native/reg.c" + +static bool rz_debug_native_step(RzDebug *dbg) { + return w32_step(dbg); +} + +static int rz_debug_native_attach(RzDebug *dbg, int pid) { + return w32_attach(dbg, pid); +} + +static int rz_debug_native_detach(RzDebug *dbg, int pid) { + return w32_detach(dbg, pid); +} + +static int rz_debug_native_select(RzDebug *dbg, int pid, int tid) { + return w32_select(dbg, pid, tid); +} + +static int rz_debug_native_continue_syscall(RzDebug *dbg, int pid, int num) { + eprintf("TODO: continue syscall not implemented yet\n"); + return -1; +} + +static int rz_debug_native_stop(RzDebug *dbg) { + return 0; +} + +static int rz_debug_native_continue(RzDebug *dbg, int pid, int tid, int sig) { + return w32_continue(dbg, pid, tid, sig); +} + +static RzDebugInfo *rz_debug_native_info(RzDebug *dbg, const char *arg) { + return w32_info(dbg, arg); +} + +static bool tracelib(RzDebug *dbg, const char *mode, PLIB_ITEM item) { + const char *needle = NULL; + int tmp = 0; + if (mode) { + switch (mode[0]) { + case 'l': needle = dbg->glob_libs; break; + case 'u': needle = dbg->glob_unlibs; break; + } + } + rz_cons_printf("(%d) %sing library at 0x%p (%s) %s\n", item->pid, mode, + item->BaseOfDll, item->Path, item->Name); + rz_cons_flush(); + if (needle && strlen(needle)) { + tmp = rz_str_glob(item->Name, needle); + } + return !mode || !needle || tmp; +} + +static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { + RzDebugReasonType reason = RZ_DEBUG_REASON_UNKNOWN; + // Store the original TID to attempt to switch back after handling events that + // require switching to the event's thread that shouldn't bother the user + int orig_tid = dbg->tid; + bool restore_thread = false; + W32DbgWInst *wrap = dbg->plugin_data; + + if (pid == -1) { + RZ_LOG_ERROR("rz_debug_native_wait called with pid -1\n"); + return RZ_DEBUG_REASON_ERROR; + } + + reason = w32_dbg_wait(dbg, pid); + RzDebugInfo *native_info = rz_debug_native_info(dbg, ""); + if (reason == RZ_DEBUG_REASON_NEW_LIB) { + if (native_info && native_info->lib) { + /* Check if autoload PDB is set, and load PDB information if yes */ + RzCore *core = dbg->corebind.core; + bool autoload_pdb = dbg->corebind.cfggeti(core, "pdb.autoload"); + if (autoload_pdb) { + PLIB_ITEM lib = native_info->lib; + if (rz_file_exists(lib->Path)) { + if (tracelib(dbg, "load", native_info->lib)) { + reason = RZ_DEBUG_REASON_TRAP; + } + RzBinOptions opts = { 0 }; + opts.obj_opts.baseaddr = (uintptr_t)lib->BaseOfDll; + RzBinFile *cur = rz_bin_cur(core->bin); + RzBinFile *bf = rz_bin_open(core->bin, lib->Path, &opts); + if (bf) { + const RzBinInfo *info = rz_bin_object_get_info(bf->o); + if (RZ_STR_ISNOTEMPTY(info->debug_file_name)) { + if (!rz_file_exists(info->debug_file_name)) { + dbg->corebind.cmdf(core, "idpd"); + } + dbg->corebind.cmd(core, "idp"); + } + rz_bin_file_set_cur_binfile(core->bin, cur); + } + } else { + RZ_LOG_ERROR("The library %s does not exist.\n", lib->Path); + } + } + } else { + RZ_LOG_WARN("Loading unknown library.\n"); + } + restore_thread = true; + } else if (reason == RZ_DEBUG_REASON_EXIT_LIB) { + RzDebugInfo *r = rz_debug_native_info(dbg, ""); + if (r && r->lib) { + if (tracelib(dbg, "unload", r->lib)) { + reason = RZ_DEBUG_REASON_TRAP; + } + } else { + RZ_LOG_WARN("Unloading unknown library.\n"); + } + restore_thread = true; + } else if (reason == RZ_DEBUG_REASON_NEW_PID) { + if (native_info && native_info->thread) { + PTHREAD_ITEM item = native_info->thread; + RZ_LOG_INFO("(%d) Created process %d (start @ %p) (teb @ %p)\n", item->pid, item->tid, item->lpStartAddress, item->lpThreadLocalBase); + } + } else if (reason == RZ_DEBUG_REASON_NEW_TID) { + if (native_info && native_info->thread) { + PTHREAD_ITEM item = native_info->thread; + RZ_LOG_INFO("(%d) Created thread %d (start @ %p) (teb @ %p)\n", item->pid, item->tid, item->lpStartAddress, item->lpThreadLocalBase); + } + restore_thread = true; + } else if (reason == RZ_DEBUG_REASON_EXIT_TID) { + PTHREAD_ITEM item = native_info->thread; + if (native_info && native_info->thread) { + RZ_LOG_INFO("(%d) Finished thread %d Exit code %lu\n", (ut32)item->pid, (ut32)item->tid, item->dwExitCode); + } + if (dbg->tid != orig_tid && item->tid != orig_tid) { + restore_thread = true; + } + } else if (reason == RZ_DEBUG_REASON_DEAD) { + if (native_info && native_info->thread) { + PTHREAD_ITEM item = native_info->thread; + RZ_LOG_INFO("(%d) Finished process with exit code %lu\n", dbg->main_pid, item->dwExitCode); + } + dbg->pid = -1; + dbg->tid = -1; + } else if (reason == RZ_DEBUG_REASON_USERSUSP && dbg->tid != orig_tid) { + if (native_info && native_info->thread) { + PTHREAD_ITEM item = native_info->thread; + RZ_LOG_INFO("(%d) Created DebugBreak thread %d (start @ %p)\n", item->pid, item->tid, item->lpStartAddress); + } + // DebugProcessBreak creates a new thread that will trigger a breakpoint. We record the + // tid here to ignore it once the breakpoint is hit. + wrap->break_tid = dbg->tid; + restore_thread = true; + } else if (reason == RZ_DEBUG_REASON_BREAKPOINT && dbg->tid == wrap->break_tid) { + wrap->break_tid = -2; + reason = RZ_DEBUG_REASON_NONE; + restore_thread = true; + } + rz_debug_info_free(native_info); + + if (restore_thread) { + // Attempt to return to the original thread after handling the event + dbg->tid = w32_select(dbg, dbg->pid, orig_tid); + if (dbg->tid == -1) { + dbg->pid = -1; + reason = RZ_DEBUG_REASON_DEAD; + } else { + if (dbg->tid != orig_tid) { + reason = RZ_DEBUG_REASON_UNKNOWN; + } + } + } + + dbg->reason.tid = pid; + dbg->reason.type = reason; + return reason; +} + +#undef MAXPID +#define MAXPID 99999 + +static RzList /**/ *rz_debug_native_pids(RzDebug *dbg, int pid) { + RzList *list = rz_list_new(); + if (!list) { + return NULL; + } + return w32_pid_list(dbg, pid, list); +} + +RZ_API RZ_OWN RzList /**/ *rz_debug_native_threads(RzDebug *dbg, int pid) { + RzList *list = rz_list_new(); + if (!list) { + eprintf("No list?\n"); + return NULL; + } + return w32_thread_list(dbg, pid, list); +} + +RZ_API ut64 rz_debug_get_tls(RZ_NONNULL RzDebug *dbg, int tid) { + rz_return_val_if_fail(dbg, 0); + return 0; +} + +static int rz_debug_native_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { + if (size < 1) { + return false; + } + return w32_reg_read(dbg, type, buf, size); +} + +static int rz_debug_native_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size) { + // XXX use switch or so + if (type == RZ_REG_TYPE_DRX) { +#if __i386__ || __x86_64__ + return w32_reg_write(dbg, type, buf, size); +#else // i386/x86-64 + return false; +#endif + } else if (type == RZ_REG_TYPE_GPR) { + return w32_reg_write(dbg, type, buf, size); + } else if (type == RZ_REG_TYPE_FPU) { + return false; + } // else eprintf ("TODO: reg_write_non-gpr (%d)\n", type); + return false; +} + +static RzDebugMap *rz_debug_native_map_alloc(RzDebug *dbg, ut64 addr, int size, bool thp) { + (void)thp; + return w32_map_alloc(dbg, addr, size); +} + +static int rz_debug_native_map_dealloc(RzDebug *dbg, ut64 addr, int size) { + return w32_map_dealloc(dbg, addr, size); +} + +static RzList /**/ *rz_debug_native_map_get(RzDebug *dbg) { + RzList *list = NULL; + list = rz_w32_dbg_maps(dbg); + return list; +} + +static RzList /**/ *rz_debug_native_modules_get(RzDebug *dbg) { + char *lastname = NULL; + RzDebugMap *map; + RzListIter *iter, *iter2; + RzList *list, *last; + bool must_delete; + list = rz_w32_dbg_modules(dbg); + if (list && !rz_list_empty(list)) { + return list; + } + if (!(list = rz_debug_native_map_get(dbg))) { + return NULL; + } + if (!(last = rz_list_newf((RzListFree)rz_debug_map_free))) { + rz_list_free(list); + return NULL; + } + rz_list_foreach_safe (list, iter, iter2, map) { + const char *file = map->file; + if (!map->file) { + file = map->file = strdup(map->name); + } + must_delete = true; + if (file && *file == '/') { + if (!lastname || strcmp(lastname, file)) { + must_delete = false; + } + } + if (must_delete) { + rz_list_delete(list, iter); + } else { + rz_list_append(last, map); + free(lastname); + lastname = strdup(file); + } + } + list->free = NULL; + free(lastname); + rz_list_free(list); + return last; +} + +static bool rz_debug_native_kill(RzDebug *dbg, int pid, int tid, int sig) { + bool ret = false; + if (pid == 0) { + pid = dbg->pid; + } + ret = w32_kill(dbg, pid, tid, sig); + return ret; +} + +struct rz_debug_desc_plugin_t rz_debug_desc_plugin_native; +static bool rz_debug_native_init(RzDebug *dbg, void **user) { + dbg->cur->desc = rz_debug_desc_plugin_native; + return w32_init(dbg); +} + +static void rz_debug_native_fini(RzDebug *dbg, void *user) { +} + +#if __i386__ || __x86_64__ +static void sync_drx_regs(RzDebug *dbg, drxt *regs, size_t num_regs) { + /* sanity check, we rely on this assumption */ + if (num_regs != NUM_DRX_REGISTERS) { + eprintf("drx: Unsupported number of registers for get_debug_regs\n"); + return; + } + + // sync drx regs +#define R dbg->reg + regs[0] = rz_reg_getv(R, "dr0"); + regs[1] = rz_reg_getv(R, "dr1"); + regs[2] = rz_reg_getv(R, "dr2"); + regs[3] = rz_reg_getv(R, "dr3"); + /* + RESERVED + regs[4] = rz_reg_getv (R, "dr4"); + regs[5] = rz_reg_getv (R, "dr5"); +*/ + regs[6] = rz_reg_getv(R, "dr6"); + regs[7] = rz_reg_getv(R, "dr7"); +} +#endif + +#if __i386__ || __x86_64__ +static void set_drx_regs(RzDebug *dbg, drxt *regs, size_t num_regs) { + /* sanity check, we rely on this assumption */ + if (num_regs != NUM_DRX_REGISTERS) { + eprintf("drx: Unsupported number of registers for get_debug_regs\n"); + return; + } + +#define R dbg->reg + rz_reg_setv(R, "dr0", regs[0]); + rz_reg_setv(R, "dr1", regs[1]); + rz_reg_setv(R, "dr2", regs[2]); + rz_reg_setv(R, "dr3", regs[3]); + rz_reg_setv(R, "dr6", regs[6]); + rz_reg_setv(R, "dr7", regs[7]); +} +#endif + +static int rz_debug_native_drx(RzDebug *dbg, int n, ut64 addr, int sz, int rwx, int g, int api_type) { +#if __i386__ || __x86_64__ + int retval = false; + drxt regs[NUM_DRX_REGISTERS] = { 0 }; + // sync drx regs + sync_drx_regs(dbg, regs, NUM_DRX_REGISTERS); + + switch (api_type) { + case DRX_API_LIST: + drx_list(regs); + retval = false; + break; + case DRX_API_GET_BP: + /* get the index of the breakpoint at addr */ + retval = drx_get_at(regs, addr); + break; + case DRX_API_REMOVE_BP: + /* remove hardware breakpoint */ + drx_set(regs, n, addr, -1, 0, 0); + retval = true; + break; + case DRX_API_SET_BP: + /* set hardware breakpoint */ + drx_set(regs, n, addr, sz, rwx, g); + retval = true; + break; + default: + /* this should not happen, someone misused the API */ + eprintf("drx: Unsupported api type in rz_debug_native_drx\n"); + retval = false; + } + + set_drx_regs(dbg, regs, NUM_DRX_REGISTERS); + + return retval; +#else + eprintf("drx: Unsupported platform\n"); +#endif + return -1; +} + +static int rz_debug_native_bp(RzBreakpoint *bp, RzBreakpointItem *b, bool set) { + if (b && b->hw) { +#if __i386__ || __x86_64__ + return set + ? drx_add((RzDebug *)bp->user, bp, b) + : drx_del((RzDebug *)bp->user, bp, b); +#else + return set + ? w32_hwbp_arm_add((RzDebug *)bp->user, bp, b) + : w32_hwbp_arm_del((RzDebug *)bp->user, bp, b); +#endif + } + return false; +} + +static RzList /**/ *rz_debug_desc_native_list(int pid) { + return w32_desc_list(pid); +} + +static int rz_debug_native_map_protect(RzDebug *dbg, ut64 addr, int size, int perms) { + return w32_map_protect(dbg, addr, size, perms); +} + +static int rz_debug_desc_native_open(const char *path) { + return 0; +} + +static bool rz_debug_gcore(RzDebug *dbg, char *path, RzBuffer *dest) { + return false; +} \ No newline at end of file From 37ff747d2f6ae72810493abcc3748960f38ebceb Mon Sep 17 00:00:00 2001 From: tushar3q34 Date: Tue, 3 Sep 2024 10:57:02 +0530 Subject: [PATCH 2/4] Required changes and bug fixes --- librz/arch/isa/amd29k/amd29k.c | 2 +- librz/arch/isa/arm/armass.c | 6 +- librz/arch/isa/avr/assembler.c | 2 +- librz/arch/isa/avr/avr_esil.c | 4 +- librz/arch/isa/lh5801/lh5801.c | 4 +- librz/arch/isa/luac/v53/arch_53.h | 4 +- librz/arch/isa/luac/v54/arch_54.h | 6 +- librz/arch/isa/ppc/libps/libps_internal.h | 6 +- librz/arch/isa/rx/rx_opcode_detail.c | 5 +- librz/arch/isa/rx/rx_str.inc | 4 +- librz/arch/isa/v810/v810_disas.h | 12 +- librz/arch/p/analysis/analysis_i4004.c | 2 +- librz/arch/p/analysis/analysis_pyc.c | 2 +- librz/arch/p/analysis/analysis_sh.c | 214 +- .../arch/p_gnu/analysis/analysis_sparc_gnu.c | 2 +- librz/bin/format/elf/glibc_elf.h | 80 +- librz/bin/format/java/class_attribute.h | 2 +- librz/bin/format/mach0/mach0_defines.h | 2 +- librz/bin/format/objc/mach0_classes.c | 2 +- librz/bin/format/pe/pe_rsrc.c | 2 +- librz/bin/p/bin_avr.c | 8 +- librz/bin/p/bin_elf.inc | 2 +- librz/core/cbin.c | 14 +- librz/core/windows_heap.c | 6 +- librz/crypto/des.c | 4 +- librz/crypto/p/crypto_blowfish.c | 2 +- librz/debug/p/debug_native.c | 36 +- librz/debug/p/{ => native}/android_arm.c | 14 +- librz/debug/p/{ => native}/android_arm64.c | 13 +- librz/debug/p/{ => native}/android_x86_64.c | 12 +- librz/debug/p/{ => native}/apple_aarch64.c | 6 +- librz/debug/p/{ => native}/apple_x86_64.c | 5 +- .../p/{DragonFly.c => native/dragonfly.c} | 95 +- librz/debug/p/{KFBSD.c => native/kfbsd.c} | 92 +- librz/debug/p/{ => native}/linux_arm.c | 11 +- librz/debug/p/native/linux_arm64.c | 794 +++ librz/debug/p/{ => native}/linux_x86_64.c | 11 +- librz/debug/p/{NetBSD.c => native/netbsd.c} | 97 +- librz/debug/p/{OpenBSD.c => native/openbsd.c} | 97 +- librz/debug/p/{ => native}/windows.c | 7 +- librz/egg/emit_x86.c | 2 +- librz/hash/algorithms/sm3/sm3.c | 2 +- librz/hash/algorithms/ssdeep/fnv_hash.h | 4608 +++++++++++++++-- librz/include/rz_bin.h | 2 +- librz/include/rz_cons.h | 4 +- librz/include/rz_magic.h | 2 +- librz/include/rz_types.h | 2 +- librz/include/rz_types_base.h | 4 +- librz/magic/apprentice.c | 6 +- librz/magic/fsmagic.c | 2 +- librz/magic/magic.c | 6 +- librz/type/format.c | 2 +- librz/util/bitvector.c | 4 +- librz/util/sdb/src/cdb_make.c | 2 +- librz/util/unum.c | 2 +- 55 files changed, 5369 insertions(+), 970 deletions(-) rename librz/debug/p/{ => native}/android_arm.c (98%) rename librz/debug/p/{ => native}/android_arm64.c (99%) rename librz/debug/p/{ => native}/android_x86_64.c (98%) rename librz/debug/p/{ => native}/apple_aarch64.c (98%) rename librz/debug/p/{ => native}/apple_x86_64.c (98%) rename librz/debug/p/{DragonFly.c => native/dragonfly.c} (87%) rename librz/debug/p/{KFBSD.c => native/kfbsd.c} (88%) rename librz/debug/p/{ => native}/linux_arm.c (98%) create mode 100644 librz/debug/p/native/linux_arm64.c rename librz/debug/p/{ => native}/linux_x86_64.c (99%) rename librz/debug/p/{NetBSD.c => native/netbsd.c} (88%) rename librz/debug/p/{OpenBSD.c => native/openbsd.c} (87%) rename librz/debug/p/{ => native}/windows.c (98%) diff --git a/librz/arch/isa/amd29k/amd29k.c b/librz/arch/isa/amd29k/amd29k.c index cbb470312b0..22a0d297037 100644 --- a/librz/arch/isa/amd29k/amd29k.c +++ b/librz/arch/isa/amd29k/amd29k.c @@ -22,7 +22,7 @@ // Local registers #define AMD29K_IS_REG_LR(x) ((x) >= 128 && (x) < 256) #define AMD29K_REGNAME(x) (AMD29K_IS_REG_GR(x) ? "gr" : "lr") -#define AMD29K_LR(x) (AMD29K_IS_REG_GR(x) ? (x) : (x)-127) +#define AMD29K_LR(x) (AMD29K_IS_REG_GR(x) ? (x) : (x) - 127) static void decode_ra_rb_rci(amd29k_instr_t *instruction, const ut8 *buffer) { AMD29K_SET_VALUE(instruction, 0, buffer[1], AMD29K_TYPE_REG); diff --git a/librz/arch/isa/arm/armass.c b/librz/arch/isa/arm/armass.c index 76540ea9d7b..29c78ebed23 100644 --- a/librz/arch/isa/arm/armass.c +++ b/librz/arch/isa/arm/armass.c @@ -5813,7 +5813,7 @@ static int arm_assemble(ArmOpcode *ao, ut64 off, const char *str) { } ao->o |= ((ret >> 16) & 0xff) << 8; ao->o |= ((ret >> 8) & 0xff) << 16; - ao->o |= ((ret)&0xff) << 24; + ao->o |= ((ret) & 0xff) << 24; } else { RZ_LOG_ERROR("assembler: arm: %s: instruction does not accept a register as argument\n", ops[i].name); return 0; @@ -5839,7 +5839,7 @@ static int arm_assemble(ArmOpcode *ao, ut64 off, const char *str) { dst /= 4; ao->o |= ((dst >> 16) & 0xff) << 8; ao->o |= ((dst >> 8) & 0xff) << 16; - ao->o |= ((dst)&0xff) << 24; + ao->o |= ((dst) & 0xff) << 24; return 4; } else { ao->o |= (getreg(ao->a[0]) << 24); @@ -5850,7 +5850,7 @@ static int arm_assemble(ArmOpcode *ao, ut64 off, const char *str) { o |= ((n >> 12) & 0xf) << 8; o |= ((n >> 8) & 0xf) << 20; o |= ((n >> 4) & 0xf) << 16; - o |= ((n)&0xf) << 24; + o |= ((n) & 0xf) << 24; ao->o |= o; } break; case TYPE_SWI: diff --git a/librz/arch/isa/avr/assembler.c b/librz/arch/isa/avr/assembler.c index 12dd66af52a..df3dc3e2997 100644 --- a/librz/arch/isa/avr/assembler.c +++ b/librz/arch/isa/avr/assembler.c @@ -131,7 +131,7 @@ (rn) = abs - pc; \ } \ if ((rn) < 0) { \ - (rn) = ~(-((rn)-1)); \ + (rn) = ~(-((rn) - 1)); \ } else { \ (rn) -= 2; \ } \ diff --git a/librz/arch/isa/avr/avr_esil.c b/librz/arch/isa/avr/avr_esil.c index 47197c8b10e..04979a381c4 100644 --- a/librz/arch/isa/avr/avr_esil.c +++ b/librz/arch/isa/avr/avr_esil.c @@ -52,8 +52,8 @@ static OPCODE_DESC *avr_op_analyze(RzAnalysis *analysis, RzAnalysisOp *op, ut64 #define CPU_MODEL_DECL(model, pc, consts) \ { \ model, \ - pc, \ - consts \ + pc, \ + consts \ } #define MASK(bits) ((bits) == 32 ? 0xffffffff : (~((~((ut32)0)) << (bits)))) #define CPU_PC_MASK(cpu) MASK((cpu)->pc) diff --git a/librz/arch/isa/lh5801/lh5801.c b/librz/arch/isa/lh5801/lh5801.c index a8399444ace..ff61e3409c6 100644 --- a/librz/arch/isa/lh5801/lh5801.c +++ b/librz/arch/isa/lh5801/lh5801.c @@ -131,8 +131,8 @@ enum lh5801_insn_format { LH5801_IFMT_RMODE_MASK = 3 << 10, }; -#define LH5801_IFMT_IMMS(f) ((f)&LH5801_IFMT_IMM_MASK) -#define LH5801_IFMT_RMODE(f) ((f)&LH5801_IFMT_RMODE_MASK) +#define LH5801_IFMT_IMMS(f) ((f) & LH5801_IFMT_IMM_MASK) +#define LH5801_IFMT_RMODE(f) ((f) & LH5801_IFMT_RMODE_MASK) static bool lh5801_ifmt_fd_matches(enum lh5801_insn_format fmt, int fd) { switch (fmt & LH5801_IFMT_FD_MASK) { diff --git a/librz/arch/isa/luac/v53/arch_53.h b/librz/arch/isa/luac/v53/arch_53.h index 020bc92591f..85e217528bc 100644 --- a/librz/arch/isa/luac/v53/arch_53.h +++ b/librz/arch/isa/luac/v53/arch_53.h @@ -166,11 +166,11 @@ name args description #define cast(x, y) ((x)(y)) #define GET_OPCODE(i) (cast(LuaOpCode, ((i) >> POS_OP) & MASK1(SIZE_OP, 0))) -#define SET_OPCODE(i, o) ((i) = (((i)&MASK0(SIZE_OP, POS_OP)) | \ +#define SET_OPCODE(i, o) ((i) = (((i) & MASK0(SIZE_OP, POS_OP)) | \ ((cast(ut32, o) << POS_OP) & MASK1(SIZE_OP, POS_OP)))) #define getarg(i, pos, size) (cast(int, ((i) >> (pos)) & MASK1(size, 0))) -#define setarg(i, v, pos, size) ((i) = (((i)&MASK0(size, pos)) | \ +#define setarg(i, v, pos, size) ((i) = (((i) & MASK0(size, pos)) | \ ((cast(ut32, v) << (pos)) & MASK1(size, pos)))) #define GETARG_A(i) getarg(i, POS_A, SIZE_A) diff --git a/librz/arch/isa/luac/v54/arch_54.h b/librz/arch/isa/luac/v54/arch_54.h index 54c50a3138e..403637bcd1f 100644 --- a/librz/arch/isa/luac/v54/arch_54.h +++ b/librz/arch/isa/luac/v54/arch_54.h @@ -188,7 +188,7 @@ typedef enum { /* Macros Highlight the cast */ #define LUA_CAST(x, y) ((x)y) #define int2sC(i) ((i) + LUAOP_FIX_sC) -#define sC2int(i) ((i)-LUAOP_FIX_sC) +#define sC2int(i) ((i) - LUAOP_FIX_sC) /* creates a mask with 'n' 1/0 bits at position 'p' */ #define LUA_MASK1(n, p) ((~((~(LuaInstruction)0) << (n))) << (p)) @@ -196,12 +196,12 @@ typedef enum { /* OPCODE getter */ #define LUA_GET_OPCODE(i) (LUA_CAST(LuaOpCode, ((i) >> LUAOP_OP_OFFSET) & LUA_MASK1(LUAOP_OP_SIZE, 0))) -#define LUA_SET_OPCODE(i, o) ((i) = (((i)&LUA_MASK0(LUAOP_OP_SIZE, LUAOP_OP_OFFSET)) | \ +#define LUA_SET_OPCODE(i, o) ((i) = (((i) & LUA_MASK0(LUAOP_OP_SIZE, LUAOP_OP_OFFSET)) | \ ((LUA_CAST(LuaInstruction, o) << LUAOP_OP_OFFSET) & LUA_MASK1(LUAOP_OP_SIZE, LUAOP_OP_OFFSET)))) /* Arguments getter */ #define LUA_GETARG(i, offset, size) (LUA_CAST(int, ((i) >> (offset)) & LUA_MASK1(size, 0))) -#define LUA_SETARG(i, v, pos, size) ((i) = (((i)&LUA_MASK0(size, pos)) | \ +#define LUA_SETARG(i, v, pos, size) ((i) = (((i) & LUA_MASK0(size, pos)) | \ ((LUA_CAST(LuaInstruction, v) << (pos)) & LUA_MASK1(size, pos)))) #define LUA_GETARG_A(i) LUA_GETARG(i, LUAOP_A_OFFSET, LUAOP_A_SIZE) diff --git a/librz/arch/isa/ppc/libps/libps_internal.h b/librz/arch/isa/ppc/libps/libps_internal.h index bb42cf22216..95594fcb92a 100644 --- a/librz/arch/isa/ppc/libps/libps_internal.h +++ b/librz/arch/isa/ppc/libps/libps_internal.h @@ -15,16 +15,16 @@ #define OP_MASK OP(0x3f) #define OPS(op, xop) (OP(op) | ((((ut32)(xop)) & 0x1f) << 1)) -#define OPSC(op, xop, rc) (OPS((op), (xop)) | ((rc)&1)) +#define OPSC(op, xop, rc) (OPS((op), (xop)) | ((rc) & 1)) #define OPS_MASK OPSC(0x3f, 0x1f, 1) #define OPS_MASK_DOT OPSC(0x3f, 0x1f, 1) #define OPM(op, xop) (OP(op) | ((((ut32)(xop)) & 0x3f) << 1)) -#define OPMC(op, xop, rc) (OPM((op), (xop)) | ((rc)&1)) +#define OPMC(op, xop, rc) (OPM((op), (xop)) | ((rc) & 1)) #define OPM_MASK OPMC(0x3f, 0x3f, 0) #define OPL(op, xop) (OP(op) | ((((ut32)(xop)) & 0x3ff) << 1)) -#define OPLC(op, xop, rc) (OPL((op), (xop)) | ((rc)&1)) +#define OPLC(op, xop, rc) (OPL((op), (xop)) | ((rc) & 1)) #define OPL_MASK OPLC(0x3f, 0x3ff, 1) #define OPL_MASK_DOT OPLC(0x3f, 0x3ff, 1) diff --git a/librz/arch/isa/rx/rx_opcode_detail.c b/librz/arch/isa/rx/rx_opcode_detail.c index 8ab9f64ccf9..9b981dbe48d 100644 --- a/librz/arch/isa/rx/rx_opcode_detail.c +++ b/librz/arch/isa/rx/rx_opcode_detail.c @@ -33,7 +33,10 @@ { .type = RX_TOKEN_CB, .tk.cb.tk_len = (x) } #define RxDspSplit(x, v, it, xx) \ { .type = RX_TOKEN_DSP_SPLIT, \ - .tk.dsp_sp.tk_len = (x), .tk.dsp_sp.vid = (v), .tk.dsp_sp.tk_len_more = (xx), .tk.dsp_sp.interval = (it) } + .tk.dsp_sp.tk_len = (x), \ + .tk.dsp_sp.vid = (v), \ + .tk.dsp_sp.tk_len_more = (xx), \ + .tk.dsp_sp.interval = (it) } #define RxIgnore(x) \ { .type = RX_TOKEN_IGNORE, .tk.reserved.tk_len = (x) } diff --git a/librz/arch/isa/rx/rx_str.inc b/librz/arch/isa/rx/rx_str.inc index 1404cc14026..f820932cf34 100644 --- a/librz/arch/isa/rx/rx_str.inc +++ b/librz/arch/isa/rx/rx_str.inc @@ -165,7 +165,7 @@ const char *cond_names[RX_COND_RESERVED] = { }; #define RxNameOp(op) ((op) < _RX_OP_COUNT ? opnames[(op)] : "invalid") -#define RxNameExt(ext) ((ext) < _RX_EXT_COUNT ? extmark_names[((ext)-RX_EXT_B)] : "invalid") -#define RxNameReg(reg) ((reg) < RX_REG_RESERVED ? reg_names[(reg)-RX_REG_R0] : "invalid") +#define RxNameExt(ext) ((ext) < _RX_EXT_COUNT ? extmark_names[((ext) - RX_EXT_B)] : "invalid") +#define RxNameReg(reg) ((reg) < RX_REG_RESERVED ? reg_names[(reg) - RX_REG_R0] : "invalid") #define RxNameFlag(flag) ((flag) < 7 ? flag_names[(flag)] : "invalid") #define RxNameCond(cond) ((cond) < RX_COND_RESERVED ? cond_names[(cond)] : "invalid") \ No newline at end of file diff --git a/librz/arch/isa/v810/v810_disas.h b/librz/arch/isa/v810/v810_disas.h index 084081f44e0..eb93ad70580 100644 --- a/librz/arch/isa/v810/v810_disas.h +++ b/librz/arch/isa/v810/v810_disas.h @@ -7,17 +7,17 @@ #define V810_INSTR_MAXLEN 24 #define OPCODE(instr) (((instr) >> 10) & 0x3F) -#define REG1(instr) ((instr)&0x1F) +#define REG1(instr) ((instr) & 0x1F) #define REG2(instr) (((instr) >> 5) & 0x1F) #define IMM5(instr) REG1((instr)) #define COND(instr) (((instr) >> 9) & 0xF) -#define SIGN_EXT_T5(imm) (((imm)&0x10) ? (imm) | 0xE0 : (imm)) -#define SIGN_EXT_T9(imm) (((imm)&0x100) ? (imm) | 0xFFFFFE00 : (imm)) -#define SIGN_EXT_T26(imm) (((imm)&0x2000000) ? (imm) | 0xFC000000 : (imm)) +#define SIGN_EXT_T5(imm) (((imm) & 0x10) ? (imm) | 0xE0 : (imm)) +#define SIGN_EXT_T9(imm) (((imm) & 0x100) ? (imm) | 0xFFFFFE00 : (imm)) +#define SIGN_EXT_T26(imm) (((imm) & 0x2000000) ? (imm) | 0xFC000000 : (imm)) -#define DISP9(word1) SIGN_EXT_T9((word1)&0x1FE) -#define DISP26(word1, word2) SIGN_EXT_T26((((word1)&0x3FF) << 16) | (word2)) +#define DISP9(word1) SIGN_EXT_T9((word1) & 0x1FE) +#define DISP26(word1, word2) SIGN_EXT_T26((((word1) & 0x3FF) << 16) | (word2)) enum v810_cmd_opcodes { V810_MOV = 0x0, diff --git a/librz/arch/p/analysis/analysis_i4004.c b/librz/arch/p/analysis/analysis_i4004.c index 356c919dbd5..ee77e0fdd5d 100644 --- a/librz/arch/p/analysis/analysis_i4004.c +++ b/librz/arch/p/analysis/analysis_i4004.c @@ -9,7 +9,7 @@ #include #include -#define AVR_SOFTCAST(x, y) ((x) + ((y)*0x100)) +#define AVR_SOFTCAST(x, y) ((x) + ((y) * 0x100)) static char *get_reg_profile(RzAnalysis *analysis) { const char *p = diff --git a/librz/arch/p/analysis/analysis_pyc.c b/librz/arch/p/analysis/analysis_pyc.c index eedec2fe7d3..55df01ef9ff 100644 --- a/librz/arch/p/analysis/analysis_pyc.c +++ b/librz/arch/p/analysis/analysis_pyc.c @@ -8,7 +8,7 @@ #include "pyc/pyc_dis.h" -#define JMP_OFFSET(ops, v) ((ops)->jump_use_instruction_offset ? (v)*2 : (v)) +#define JMP_OFFSET(ops, v) ((ops)->jump_use_instruction_offset ? (v) * 2 : (v)) static int archinfo(RzAnalysis *analysis, RzAnalysisInfoType query) { if (!strcmp(analysis->cpu, "x86")) { diff --git a/librz/arch/p/analysis/analysis_sh.c b/librz/arch/p/analysis/analysis_sh.c index 23d60397f09..38d9ca8b3d5 100644 --- a/librz/arch/p/analysis/analysis_sh.c +++ b/librz/arch/p/analysis/analysis_sh.c @@ -38,138 +38,138 @@ #define IS_CLRMAC(x) x == 0x0028 #define IS_RTE(x) x == 0x002b -#define IS_STCSR1(x) (((x)&0xF0CF) == 0x0002) // mask stc Rn,{SR,gbr,VBR,SSR} -#define IS_BSRF(x) ((x)&0xf0ff) == 0x0003 -#define IS_BRAF(x) (((x)&0xf0ff) == 0x0023) -#define IS_MOVB_REG_TO_R0REL(x) (((x)&0xF00F) == 0x0004) -#define IS_MOVW_REG_TO_R0REL(x) (((x)&0xF00F) == 0x0005) -#define IS_MOVL_REG_TO_R0REL(x) (((x)&0xF00F) == 0x0006) -#define IS_MULL(x) (((x)&0xF00F) == 0x0007) -#define IS_MOVB_R0REL_TO_REG(x) (((x)&0xF00F) == 0x000C) -#define IS_MOVW_R0REL_TO_REG(x) (((x)&0xF00F) == 0x000D) -#define IS_MOVL_R0REL_TO_REG(x) (((x)&0xF00F) == 0x000E) -#define IS_MACL(x) (((x)&0xF00F) == 0x000F) -#define IS_MOVT(x) (((x)&0xF0FF) == 0x0029) -#define IS_STSMACH(x) (((x)&0xF0FF) == 0x000A) -#define IS_STSMACL(x) (((x)&0xF0FF) == 0x001A) -#define IS_STSPR(x) (((x)&0xF0FF) == 0x002A) +#define IS_STCSR1(x) (((x) & 0xF0CF) == 0x0002) // mask stc Rn,{SR,gbr,VBR,SSR} +#define IS_BSRF(x) ((x) & 0xf0ff) == 0x0003 +#define IS_BRAF(x) (((x) & 0xf0ff) == 0x0023) +#define IS_MOVB_REG_TO_R0REL(x) (((x) & 0xF00F) == 0x0004) +#define IS_MOVW_REG_TO_R0REL(x) (((x) & 0xF00F) == 0x0005) +#define IS_MOVL_REG_TO_R0REL(x) (((x) & 0xF00F) == 0x0006) +#define IS_MULL(x) (((x) & 0xF00F) == 0x0007) +#define IS_MOVB_R0REL_TO_REG(x) (((x) & 0xF00F) == 0x000C) +#define IS_MOVW_R0REL_TO_REG(x) (((x) & 0xF00F) == 0x000D) +#define IS_MOVL_R0REL_TO_REG(x) (((x) & 0xF00F) == 0x000E) +#define IS_MACL(x) (((x) & 0xF00F) == 0x000F) +#define IS_MOVT(x) (((x) & 0xF0FF) == 0x0029) +#define IS_STSMACH(x) (((x) & 0xF0FF) == 0x000A) +#define IS_STSMACL(x) (((x) & 0xF0FF) == 0x001A) +#define IS_STSPR(x) (((x) & 0xF0FF) == 0x002A) // #define IS_STSFPUL(x) (((x) & 0xF0FF) == 0x005A) //FP*: todo maybe someday // #define IS_STSFPSCR(x) (((x) & 0xF0FF) == 0x006A) -#define IS_MOVB_REG_TO_REGREF(x) (((x)&0xF00F) == 0x2000) -#define IS_MOVW_REG_TO_REGREF(x) (((x)&0xF00F) == 0x2001) -#define IS_MOVL_REG_TO_REGREF(x) (((x)&0xF00F) == 0x2002) +#define IS_MOVB_REG_TO_REGREF(x) (((x) & 0xF00F) == 0x2000) +#define IS_MOVW_REG_TO_REGREF(x) (((x) & 0xF00F) == 0x2001) +#define IS_MOVL_REG_TO_REGREF(x) (((x) & 0xF00F) == 0x2002) // #define invalid?(x) (((x) & 0xF00F) == 0x2003) //illegal on sh2e -#define IS_PUSHB(x) (((x)&0xF00F) == 0x2004) -#define IS_PUSHW(x) (((x)&0xF00F) == 0x2005) -#define IS_PUSHL(x) (((x)&0xF00F) == 0x2006) -#define IS_DIV0S(x) (((x)&0xF00F) == 0x2007) -#define IS_TSTRR(x) (((x)&0xF00F) == 0x2008) -#define IS_AND_REGS(x) (((x)&0xF00F) == 0x2009) -#define IS_XOR_REGS(x) (((x)&0xF00F) == 0x200A) -#define IS_OR_REGS(x) (((x)&0xF00F) == 0x200B) -#define IS_CMPSTR(x) (((x)&0xF00F) == 0x200C) -#define IS_XTRCT(x) (((x)&0xF00F) == 0x200D) -#define IS_MULUW(x) (((x)&0xF00F) == 0x200E) -#define IS_MULSW(x) (((x)&0xF00F) == 0x200F) -#define IS_CMPEQ(x) (((x)&0xF00F) == 0x3000) +#define IS_PUSHB(x) (((x) & 0xF00F) == 0x2004) +#define IS_PUSHW(x) (((x) & 0xF00F) == 0x2005) +#define IS_PUSHL(x) (((x) & 0xF00F) == 0x2006) +#define IS_DIV0S(x) (((x) & 0xF00F) == 0x2007) +#define IS_TSTRR(x) (((x) & 0xF00F) == 0x2008) +#define IS_AND_REGS(x) (((x) & 0xF00F) == 0x2009) +#define IS_XOR_REGS(x) (((x) & 0xF00F) == 0x200A) +#define IS_OR_REGS(x) (((x) & 0xF00F) == 0x200B) +#define IS_CMPSTR(x) (((x) & 0xF00F) == 0x200C) +#define IS_XTRCT(x) (((x) & 0xF00F) == 0x200D) +#define IS_MULUW(x) (((x) & 0xF00F) == 0x200E) +#define IS_MULSW(x) (((x) & 0xF00F) == 0x200F) +#define IS_CMPEQ(x) (((x) & 0xF00F) == 0x3000) // #define invalid?(x) (((x) & 0xF00F) == 0x3001) -#define IS_CMPHS(x) (((x)&0xF00F) == 0x3002) -#define IS_CMPGE(x) (((x)&0xF00F) == 0x3003) -#define IS_CMPHI(x) (((x)&0xF00F) == 0x3006) -#define IS_CMPGT(x) (((x)&0xF00F) == 0x3007) -#define IS_DIV1(x) (((x)&0xF00F) == 0x3004) -#define IS_DMULU(x) (((x)&0xF00F) == 0x3005) -#define IS_DMULS(x) (((x)&0xF00F) == 0x300D) -#define IS_SUB(x) (((x)&0xF00F) == 0x3008) +#define IS_CMPHS(x) (((x) & 0xF00F) == 0x3002) +#define IS_CMPGE(x) (((x) & 0xF00F) == 0x3003) +#define IS_CMPHI(x) (((x) & 0xF00F) == 0x3006) +#define IS_CMPGT(x) (((x) & 0xF00F) == 0x3007) +#define IS_DIV1(x) (((x) & 0xF00F) == 0x3004) +#define IS_DMULU(x) (((x) & 0xF00F) == 0x3005) +#define IS_DMULS(x) (((x) & 0xF00F) == 0x300D) +#define IS_SUB(x) (((x) & 0xF00F) == 0x3008) // #define invalid?(x) (((x) & 0xF00F) == 0x3009) -#define IS_SUBC(x) (((x)&0xF00F) == 0x300A) -#define IS_SUBV(x) (((x)&0xF00F) == 0x300B) -#define IS_ADD(x) (((x)&0xF00F) == 0x300C) -#define IS_ADDC(x) (((x)&0xF00F) == 0x300E) -#define IS_ADDV(x) (((x)&0xF00F) == 0x300F) -#define IS_MACW(x) (((x)&0xF00F) == 0x400F) -#define IS_JSR(x) (((x)&0xf0ff) == 0x400b) -#define IS_JMP(x) (((x)&0xf0ff) == 0x402b) -#define IS_CMPPL(x) (((x)&0xf0ff) == 0x4015) -#define IS_CMPPZ(x) (((x)&0xf0ff) == 0x4011) -#define IS_LDCSR(x) (((x)&0xF0FF) == 0x400E) -#define IS_LDCGBR(x) (((x)&0xF0FF) == 0x401E) -#define IS_LDCVBR(x) (((x)&0xF0FF) == 0x402E) -#define IS_LDCLSR(x) (((x)&0xF0FF) == 0x4007) -#define IS_LDCLSRGBR(x) (((x)&0xF0FF) == 0x4017) -#define IS_LDCLSRVBR(x) (((x)&0xF0FF) == 0x4027) -#define IS_LDSMACH(x) (((x)&0xF0FF) == 0x400A) -#define IS_LDSMACL(x) (((x)&0xF0FF) == 0x401A) -#define IS_LDSLMACH(x) (((x)&0xF0FF) == 0x4006) -#define IS_LDSLMACL(x) (((x)&0xF0FF) == 0x4016) -#define IS_LDSPR(x) (((x)&0xF0FF) == 0x402A) -#define IS_LDSLPR(x) (((x)&0xF0FF) == 0x4026) +#define IS_SUBC(x) (((x) & 0xF00F) == 0x300A) +#define IS_SUBV(x) (((x) & 0xF00F) == 0x300B) +#define IS_ADD(x) (((x) & 0xF00F) == 0x300C) +#define IS_ADDC(x) (((x) & 0xF00F) == 0x300E) +#define IS_ADDV(x) (((x) & 0xF00F) == 0x300F) +#define IS_MACW(x) (((x) & 0xF00F) == 0x400F) +#define IS_JSR(x) (((x) & 0xf0ff) == 0x400b) +#define IS_JMP(x) (((x) & 0xf0ff) == 0x402b) +#define IS_CMPPL(x) (((x) & 0xf0ff) == 0x4015) +#define IS_CMPPZ(x) (((x) & 0xf0ff) == 0x4011) +#define IS_LDCSR(x) (((x) & 0xF0FF) == 0x400E) +#define IS_LDCGBR(x) (((x) & 0xF0FF) == 0x401E) +#define IS_LDCVBR(x) (((x) & 0xF0FF) == 0x402E) +#define IS_LDCLSR(x) (((x) & 0xF0FF) == 0x4007) +#define IS_LDCLSRGBR(x) (((x) & 0xF0FF) == 0x4017) +#define IS_LDCLSRVBR(x) (((x) & 0xF0FF) == 0x4027) +#define IS_LDSMACH(x) (((x) & 0xF0FF) == 0x400A) +#define IS_LDSMACL(x) (((x) & 0xF0FF) == 0x401A) +#define IS_LDSLMACH(x) (((x) & 0xF0FF) == 0x4006) +#define IS_LDSLMACL(x) (((x) & 0xF0FF) == 0x4016) +#define IS_LDSPR(x) (((x) & 0xF0FF) == 0x402A) +#define IS_LDSLPR(x) (((x) & 0xF0FF) == 0x4026) // #define IS_LDSFPUL(x) (((x) & 0xF0FF) == 0x405A) //FP*: todo maybe someday // #define IS_LDSFPSCR(x) (((x) & 0xF0FF) == 0x406A) // #define IS_LDSLFPUL(x) (((x) & 0xF0FF) == 0x4066) // #define IS_LDSLFPSCR(x) (((x) & 0xF0FF) == 0x4056) -#define IS_ROTCR(x) (((x)&0xF0FF) == 0x4025) -#define IS_ROTCL(x) (((x)&0xF0FF) == 0x4024) -#define IS_ROTL(x) (((x)&0xF0FF) == 0x4004) -#define IS_ROTR(x) (((x)&0xF0FF) == 0x4005) +#define IS_ROTCR(x) (((x) & 0xF0FF) == 0x4025) +#define IS_ROTCL(x) (((x) & 0xF0FF) == 0x4024) +#define IS_ROTL(x) (((x) & 0xF0FF) == 0x4004) +#define IS_ROTR(x) (((x) & 0xF0FF) == 0x4005) // not on sh2e : shad, shld // #define IS_SHIFT1(x) (((x) & 0xF0DE) == 0x4000) //unused (treated as switch-case) // other shl{l,r}{,2,8,16} in switch case also. -#define IS_STSLMACL(x) (((x)&0xF0FF) == 0x4012) -#define IS_STSLMACH(x) (((x)&0xF0FF) == 0x4002) -#define IS_STCLSR(x) (((x)&0xF0FF) == 0x4003) -#define IS_STCLGBR(x) (((x)&0xF0FF) == 0x4013) -#define IS_STCLVBR(x) (((x)&0xF0FF) == 0x4023) +#define IS_STSLMACL(x) (((x) & 0xF0FF) == 0x4012) +#define IS_STSLMACH(x) (((x) & 0xF0FF) == 0x4002) +#define IS_STCLSR(x) (((x) & 0xF0FF) == 0x4003) +#define IS_STCLGBR(x) (((x) & 0xF0FF) == 0x4013) +#define IS_STCLVBR(x) (((x) & 0xF0FF) == 0x4023) // todo: other stc.l not on sh2e -#define IS_STSLPR(x) (((x)&0xF0FF) == 0x4022) +#define IS_STSLPR(x) (((x) & 0xF0FF) == 0x4022) // #define IS_STSLFPUL(x) (((x) & 0xF0FF) == 0x4052) // #define IS_STSLFPSCR(x) (((x) & 0xF0FF) == 0x4062) -#define IS_TASB(x) (((x)&0xF0FF) == 0x401B) -#define IS_DT(x) (((x)&0xF0FF) == 0x4010) +#define IS_TASB(x) (((x) & 0xF0FF) == 0x401B) +#define IS_DT(x) (((x) & 0xF0FF) == 0x4010) -#define IS_MOVB_REGREF_TO_REG(x) (((x)&0xF00F) == 0x6000) -#define IS_MOVW_REGREF_TO_REG(x) (((x)&0xF00F) == 0x6001) -#define IS_MOVL_REGREF_TO_REG(x) (((x)&0xF00F) == 0x6002) -#define IS_MOV_REGS(x) (((x)&0xf00f) == 0x6003) -#define IS_MOVB_POP(x) (((x)&0xF00F) == 0x6004) -#define IS_MOVW_POP(x) (((x)&0xF00F) == 0x6005) -#define IS_MOVL_POP(x) (((x)&0xF00F) == 0x6006) -#define IS_NOT(x) (((x)&0xF00F) == 0x6007) -#define IS_SWAPB(x) (((x)&0xF00F) == 0x6008) -#define IS_SWAPW(x) (((x)&0xF00F) == 0x6009) -#define IS_NEG(x) (((x)&0xF00F) == 0x600B) -#define IS_NEGC(x) (((x)&0xF00F) == 0x600A) -#define IS_EXT(x) (((x)&0xF00C) == 0x600C) // match ext{s,u}.{b,w} +#define IS_MOVB_REGREF_TO_REG(x) (((x) & 0xF00F) == 0x6000) +#define IS_MOVW_REGREF_TO_REG(x) (((x) & 0xF00F) == 0x6001) +#define IS_MOVL_REGREF_TO_REG(x) (((x) & 0xF00F) == 0x6002) +#define IS_MOV_REGS(x) (((x) & 0xf00f) == 0x6003) +#define IS_MOVB_POP(x) (((x) & 0xF00F) == 0x6004) +#define IS_MOVW_POP(x) (((x) & 0xF00F) == 0x6005) +#define IS_MOVL_POP(x) (((x) & 0xF00F) == 0x6006) +#define IS_NOT(x) (((x) & 0xF00F) == 0x6007) +#define IS_SWAPB(x) (((x) & 0xF00F) == 0x6008) +#define IS_SWAPW(x) (((x) & 0xF00F) == 0x6009) +#define IS_NEG(x) (((x) & 0xF00F) == 0x600B) +#define IS_NEGC(x) (((x) & 0xF00F) == 0x600A) +#define IS_EXT(x) (((x) & 0xF00C) == 0x600C) // match ext{s,u}.{b,w} -#define IS_MOVB_R0_REGDISP(x) (((x)&0xFF00) == 0x8000) -#define IS_MOVW_R0_REGDISP(x) (((x)&0xFF00) == 0x8100) +#define IS_MOVB_R0_REGDISP(x) (((x) & 0xFF00) == 0x8000) +#define IS_MOVW_R0_REGDISP(x) (((x) & 0xFF00) == 0x8100) // #define illegal?(x) (((x) & 0xF900) == 0x8000) //match 8{2,3,6,7}00 -#define IS_MOVB_REGDISP_R0(x) (((x)&0xFF00) == 0x8400) -#define IS_MOVW_REGDISP_R0(x) (((x)&0xFF00) == 0x8500) -#define IS_CMPIMM(x) (((x)&0xFF00) == 0x8800) +#define IS_MOVB_REGDISP_R0(x) (((x) & 0xFF00) == 0x8400) +#define IS_MOVW_REGDISP_R0(x) (((x) & 0xFF00) == 0x8500) +#define IS_CMPIMM(x) (((x) & 0xFF00) == 0x8800) // #define illegal?(x) (((x) & 0xFB00) == 0x8A00) //match 8{A,E}00 -#define IS_BT(x) (((x)&0xff00) == 0x8900) -#define IS_BF(x) (((x)&0xff00) == 0x8B00) -#define IS_BTS(x) (((x)&0xff00) == 0x8D00) -#define IS_BFS(x) (((x)&0xff00) == 0x8F00) +#define IS_BT(x) (((x) & 0xff00) == 0x8900) +#define IS_BF(x) (((x) & 0xff00) == 0x8B00) +#define IS_BTS(x) (((x) & 0xff00) == 0x8D00) +#define IS_BFS(x) (((x) & 0xff00) == 0x8F00) #define IS_BT_OR_BF(x) IS_BT(x) || IS_BTS(x) || IS_BF(x) || IS_BFS(x) -#define IS_MOVB_R0_GBRREF(x) (((x)&0xFF00) == 0xC000) -#define IS_MOVW_R0_GBRREF(x) (((x)&0xFF00) == 0xC100) -#define IS_MOVL_R0_GBRREF(x) (((x)&0xFF00) == 0xC200) -#define IS_TRAP(x) (((x)&0xFF00) == 0xC300) -#define IS_MOVB_GBRREF_R0(x) (((x)&0xFF00) == 0xC400) -#define IS_MOVW_GBRREF_R0(x) (((x)&0xFF00) == 0xC500) -#define IS_MOVL_GBRREF_R0(x) (((x)&0xFF00) == 0xC600) -#define IS_MOVA_PCREL_R0(x) (((x)&0xFF00) == 0xC700) -#define IS_BINLOGIC_IMM_R0(x) (((x)&0xFC00) == 0xC800) // match C{8,9,A,B}00 -#define IS_BINLOGIC_IMM_GBR(x) (((x)&0xFC00) == 0xCC00) // match C{C,D,E,F}00 : *.b #imm, @(R0,gbr) +#define IS_MOVB_R0_GBRREF(x) (((x) & 0xFF00) == 0xC000) +#define IS_MOVW_R0_GBRREF(x) (((x) & 0xFF00) == 0xC100) +#define IS_MOVL_R0_GBRREF(x) (((x) & 0xFF00) == 0xC200) +#define IS_TRAP(x) (((x) & 0xFF00) == 0xC300) +#define IS_MOVB_GBRREF_R0(x) (((x) & 0xFF00) == 0xC400) +#define IS_MOVW_GBRREF_R0(x) (((x) & 0xFF00) == 0xC500) +#define IS_MOVL_GBRREF_R0(x) (((x) & 0xFF00) == 0xC600) +#define IS_MOVA_PCREL_R0(x) (((x) & 0xFF00) == 0xC700) +#define IS_BINLOGIC_IMM_R0(x) (((x) & 0xFC00) == 0xC800) // match C{8,9,A,B}00 +#define IS_BINLOGIC_IMM_GBR(x) (((x) & 0xFC00) == 0xCC00) // match C{C,D,E,F}00 : *.b #imm, @(R0,gbr) /* Compute PC-relative displacement for branch instructions */ -#define GET_BRA_OFFSET(x) ((x)&0x0fff) -#define GET_BTF_OFFSET(x) ((x)&0x00ff) +#define GET_BRA_OFFSET(x) ((x) & 0x0fff) +#define GET_BTF_OFFSET(x) ((x) & 0x00ff) /* Compute reg nr for BRAF,BSR,BSRF,JMP,JSR */ #define GET_TARGET_REG(x) (((x) >> 8) & 0x0f) diff --git a/librz/arch/p_gnu/analysis/analysis_sparc_gnu.c b/librz/arch/p_gnu/analysis/analysis_sparc_gnu.c index 403981bd3cf..48dd6ba1941 100644 --- a/librz/arch/p_gnu/analysis/analysis_sparc_gnu.c +++ b/librz/arch/p_gnu/analysis/analysis_sparc_gnu.c @@ -159,7 +159,7 @@ static int fcc_to_r_cond(const int cond) { /* These are for v9. */ #define X_DISP16(i) (((((i) >> 20) & 3) << 14) | (((i) >> 0) & 0x3fff)) #define X_DISP19(i) (((i) >> 0) & 0x7ffff) -#define X_MEMBAR(i) ((i)&0x7f) +#define X_MEMBAR(i) ((i) & 0x7f) enum { OP_0 = 0, diff --git a/librz/bin/format/elf/glibc_elf.h b/librz/bin/format/elf/glibc_elf.h index 070db55d1ba..945e3dac832 100644 --- a/librz/bin/format/elf/glibc_elf.h +++ b/librz/bin/format/elf/glibc_elf.h @@ -418,7 +418,7 @@ typedef struct #define SHN_LORESERVE 0xff00 /* Start of reserved indices */ #define SHN_LOPROC 0xff00 /* Start of processor-specific */ #define SHN_BEFORE 0xff00 /* Order section before all others \ - (Solaris). */ + (Solaris). */ #define SHN_AFTER 0xff01 /* Order section after all others \ (Solaris). */ #define SHN_HIPROC 0xff1f /* End of processor-specific */ @@ -485,7 +485,7 @@ typedef struct #define SHF_MASKOS 0x0ff00000 /* OS-specific. */ #define SHF_MASKPROC 0xf0000000 /* Processor-specific */ #define SHF_ORDERED (1 << 30) /* Special ordering requirement \ - (Solaris). */ + (Solaris). */ #define SHF_EXCLUDE (1U << 31) /* Section is excluded unless \ referenced or allocated (Solaris).*/ @@ -573,8 +573,8 @@ typedef struct /* How to extract and insert information held in the st_info field. */ #define ELF32_ST_BIND(val) (((unsigned char)(val)) >> 4) -#define ELF32_ST_TYPE(val) ((val)&0xf) -#define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type)&0xf)) +#define ELF32_ST_TYPE(val) ((val) & 0xf) +#define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) /* Both Elf32_Sym and Elf64_Sym use the same one-byte st_info field. */ #define ELF64_ST_BIND(val) ELF32_ST_BIND(val) @@ -617,7 +617,7 @@ typedef struct /* How to extract and insert information held in the st_other field. */ -#define ELF32_ST_VISIBILITY(o) ((o)&0x03) +#define ELF32_ST_VISIBILITY(o) ((o) & 0x03) /* For ELF64 the definitions are the same. */ #define ELF64_ST_VISIBILITY(o) ELF32_ST_VISIBILITY(o) @@ -666,11 +666,11 @@ typedef struct /* How to extract and insert information held in the rz_info field. */ #define ELF32_R_SYM(val) ((val) >> 8) -#define ELF32_R_TYPE(val) ((val)&0xff) -#define ELF32_R_INFO(sym, type) (((sym) << 8) + ((type)&0xff)) +#define ELF32_R_TYPE(val) ((val) & 0xff) +#define ELF32_R_INFO(sym, type) (((sym) << 8) + ((type) & 0xff)) #define ELF64_R_SYM(i) ((i) >> 32) -#define ELF64_R_TYPE(i) ((i)&0xffffffff) +#define ELF64_R_TYPE(i) ((i) & 0xffffffff) #define ELF64_R_INFO(sym, type) ((((Elf64_Xword)(sym)) << 32) + (type)) /* Program segment header. */ @@ -741,7 +741,7 @@ typedef struct #define NT_PRSTATUS 1 /* Contains copy of prstatus struct */ #define NT_PRFPREG 2 /* Contains copy of fpregset \ - struct. */ + struct. */ #define NT_FPREGSET 2 /* Contains copy of fpregset struct */ #define NT_PRPSINFO 3 /* Contains copy of prpsinfo struct */ #define NT_PRXREG 4 /* Contains copy of prxregset struct */ @@ -758,7 +758,7 @@ typedef struct #define NT_LWPSINFO 17 /* Contains copy of lwpinfo struct */ #define NT_PRFPXREG 20 /* Contains copy of fprxregset struct */ #define NT_SIGINFO 0x53494749 /* Contains copy of siginfo_t, \ - size might increase */ + size might increase */ #define NT_FILE 0x46494c45 /* Contains information about mapped \ files */ #define NT_PRXFPREG 0x46e62b7f /* Contains copy of user_fxsr_struct */ @@ -796,11 +796,11 @@ typedef struct #define NT_S390_SYSTEM_CALL 0x307 /* s390 system call restart data */ #define NT_S390_TDB 0x308 /* s390 transaction diagnostic block */ #define NT_S390_VXRS_LOW 0x309 /* s390 vector registers 0-15 \ - upper half. */ + upper half. */ #define NT_S390_VXRS_HIGH 0x30a /* s390 vector registers 16-31. */ #define NT_S390_GS_CB 0x30b /* s390 guarded storage registers. */ #define NT_S390_GS_BC 0x30c /* s390 guarded storage \ - broadcast control block. */ + broadcast control block. */ #define NT_S390_RI_CB 0x30d /* s390 runtime instrumentation. */ #define NT_ARM_VFP 0x400 /* ARM VFP/NEON registers */ #define NT_ARM_TLS 0x401 /* ARM TLS register */ @@ -808,7 +808,7 @@ typedef struct #define NT_ARM_HW_WATCH 0x403 /* ARM hardware watchpoint registers */ #define NT_ARM_SYSTEM_CALL 0x404 /* ARM system call number */ #define NT_ARM_SVE 0x405 /* ARM Scalable Vector Extension \ - registers */ + registers */ #define NT_ARM_PAC_MASK 0x406 /* ARM pointer authentication \ code masks. */ #define NT_ARM_PACA_KEYS 0x407 /* ARM pointer authentication \ @@ -901,7 +901,7 @@ typedef struct #define DT_MOVESZ 0x6ffffdfb #define DT_FEATURE_1 0x6ffffdfc /* Feature selection (DTF_*). */ #define DT_POSFLAG_1 0x6ffffdfd /* Flags for DT_* entries, effecting \ - the following DT_* entry. */ + the following DT_* entry. */ #define DT_SYMINSZ 0x6ffffdfe /* Size of syminfo table (in bytes) */ #define DT_SYMINENT 0x6ffffdff /* Entry size of syminfo */ #define DT_VALRNGHI 0x6ffffdff @@ -939,10 +939,10 @@ typedef struct /* These were chosen by Sun. */ #define DT_FLAGS_1 0x6ffffffb /* State flags, see DF_1_* below. */ #define DT_VERDEF 0x6ffffffc /* Address of version definition \ - table */ + table */ #define DT_VERDEFNUM 0x6ffffffd /* Number of version definitions */ #define DT_VERNEED 0x6ffffffe /* Address of table with needed \ - versions */ + versions */ #define DT_VERNEEDNUM 0x6fffffff /* Number of needed versions */ #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */ #define DT_VERSIONTAGNUM 16 @@ -1168,7 +1168,7 @@ typedef struct /* Some more special a_type values describing the hardware. */ #define AT_PLATFORM 15 /* String identifying platform. */ #define AT_HWCAP 16 /* Machine-dependent hints about \ - processor capabilities. */ + processor capabilities. */ /* This entry gives some information about the FPU initialization performed by the kernel. */ @@ -1418,7 +1418,7 @@ typedef struct #define RZ_68K_TLS_IE16 35 /* 16 bit GOT offset for IE */ #define RZ_68K_TLS_IE8 36 /* 8 bit GOT offset for IE */ #define RZ_68K_TLS_LE32 37 /* 32 bit offset relative to \ - static TLS block */ + static TLS block */ #define RZ_68K_TLS_LE16 38 /* 16 bit offset relative to \ static TLS block */ #define RZ_68K_TLS_LE8 39 /* 8 bit offset relative to \ @@ -1447,7 +1447,7 @@ typedef struct #define RZ_386_32PLT 11 #define RZ_386_TLS_TPOFF 14 /* Offset in static TLS block */ #define RZ_386_TLS_IE 15 /* Address of GOT entry for static TLS \ - block offset */ + block offset */ #define RZ_386_TLS_GOTIE 16 /* GOT entry for static TLS block \ offset */ #define RZ_386_TLS_LE 17 /* Offset relative to static TLS \ @@ -1475,7 +1475,7 @@ typedef struct #define RZ_386_TLS_LDM_POP 31 /* Tag for popl in LDM TLS code */ #define RZ_386_TLS_LDO_32 32 /* Offset relative to TLS block */ #define RZ_386_TLS_IE_32 33 /* GOT entry for negated static TLS \ - block offset */ + block offset */ #define RZ_386_TLS_LE_32 34 /* Negated offset relative to static \ TLS block */ #define RZ_386_TLS_DTPMOD32 35 /* ID of module containing symbol */ @@ -1492,7 +1492,7 @@ typedef struct offset for the symbol. */ #define RZ_386_IRELATIVE 42 /* Adjust indirectly by program base */ #define RZ_386_GOT32X 43 /* Load from 32 bit GOT entry, \ - relaxable. */ + relaxable. */ /* Keep this the last entry. */ #define RZ_386_NUM 44 @@ -2649,7 +2649,7 @@ enum { #define STO_PPC64_LOCAL_BIT 5 #define STO_PPC64_LOCAL_MASK (7 << STO_PPC64_LOCAL_BIT) #define PPC64_LOCAL_ENTRY_OFFSET(other) \ - (((1 << (((other)&STO_PPC64_LOCAL_MASK) >> STO_PPC64_LOCAL_BIT)) >> 2) << 2) + (((1 << (((other) & STO_PPC64_LOCAL_MASK) >> STO_PPC64_LOCAL_BIT)) >> 2) << 2) /* ARM specific declarations */ @@ -2681,7 +2681,7 @@ enum { #define EF_ARM_BE8 0x00800000 #define EF_ARM_LE8 0x00400000 -#define EF_ARM_EABI_VERSION(flags) ((flags)&EF_ARM_EABIMASK) +#define EF_ARM_EABI_VERSION(flags) ((flags) & EF_ARM_EABIMASK) #define EF_ARM_EABI_UNKNOWN 0x00000000 #define EF_ARM_EABI_VER1 0x01000000 #define EF_ARM_EABI_VER2 0x02000000 @@ -2696,7 +2696,7 @@ enum { /* ARM-specific values for sh_flags */ #define SHF_ARM_ENTRYSECT 0x10000000 /* Section contains an entry point */ #define SHF_ARM_COMDEF 0x80000000 /* Section may be multiply defined \ - in the input to a link step. */ + in the input to a link step. */ /* ARM-specific program header flags */ #define PF_ARM_SB 0x10000000 /* Segment contains the location \ @@ -2874,7 +2874,7 @@ enum { #define RZ_ARM_SBREL32 9 #define RZ_ARM_THM_PC22 10 /* PC relative 24 bit (Thumb32 BL). */ #define RZ_ARM_THM_PC8 11 /* PC relative & 0x3FC \ - (Thumb16 LDR, ADD, ADR). */ + (Thumb16 LDR, ADD, ADR). */ #define RZ_ARM_AMP_VCALL9 12 #define RZ_ARM_SWI24 13 /* Obsolete static relocation. */ #define RZ_ARM_TLS_DESC 13 /* Dynamic relocation. */ @@ -2894,7 +2894,7 @@ enum { #define RZ_ARM_PLT32 27 /* Deprecated, 32 bit PLT address. */ #define RZ_ARM_CALL 28 /* PC relative 24 bit (BL, BLX). */ #define RZ_ARM_JUMP24 29 /* PC relative 24 bit \ - (B, BL). */ + (B, BL). */ #define RZ_ARM_THM_JUMP24 30 /* PC relative 24 bit (Thumb32 B.W). */ #define RZ_ARM_BASE_ABS 31 /* Adjust by program base. */ #define RZ_ARM_ALU_PCREL_7_0 32 /* Obsolete. */ @@ -2914,7 +2914,7 @@ enum { #define RZ_ARM_MOVT_PREL 46 /* PC relative (MOVT). */ #define RZ_ARM_THM_MOVW_ABS_NC 47 /* Direct 16 bit (Thumb32 MOVW). */ #define RZ_ARM_THM_MOVT_ABS 48 /* Direct high 16 bit \ - (Thumb32 MOVT). */ + (Thumb32 MOVT). */ #define RZ_ARM_THM_MOVW_PREL_NC 49 /* PC relative 16 bit \ (Thumb32 MOVW). */ #define RZ_ARM_THM_MOVT_PREL 50 /* PC relative high 16 bit \ @@ -2937,7 +2937,7 @@ enum { #define RZ_ARM_LDR_PC_G1 62 /* PC relative (LDR,STR,LDRB,STRB). */ #define RZ_ARM_LDR_PC_G2 63 /* PC relative (LDR,STR,LDRB,STRB). */ #define RZ_ARM_LDRS_PC_G0 64 /* PC relative (STR{D,H}, \ - LDR{D,SB,H,SH}). */ + LDR{D,SB,H,SH}). */ #define RZ_ARM_LDRS_PC_G1 65 /* PC relative (STR{D,H}, \ LDR{D,SB,H,SH}). */ #define RZ_ARM_LDRS_PC_G2 66 /* PC relative (STR{D,H}, \ @@ -2951,7 +2951,7 @@ enum { #define RZ_ARM_ALU_SB_G1 73 /* Program base relative (ADD,SUB). */ #define RZ_ARM_ALU_SB_G2 74 /* Program base relative (ADD,SUB). */ #define RZ_ARM_LDR_SB_G0 75 /* Program base relative (LDR, \ - STR, LDRB, STRB). */ + STR, LDRB, STRB). */ #define RZ_ARM_LDR_SB_G1 76 /* Program base relative \ (LDR, STR, LDRB, STRB). */ #define RZ_ARM_LDR_SB_G2 77 /* Program base relative \ @@ -2985,7 +2985,7 @@ enum { #define RZ_ARM_GOT_ABS 95 /* GOT entry. */ #define RZ_ARM_GOT_PREL 96 /* PC relative GOT entry. */ #define RZ_ARM_GOT_BREL12 97 /* GOT entry relative to GOT \ - origin (LDR). */ + origin (LDR). */ #define RZ_ARM_GOTOFF12 98 /* 12 bit, GOT entry relative \ to GOT origin (LDR, STR). */ #define RZ_ARM_GOTRELAX 99 @@ -2993,7 +2993,7 @@ enum { #define RZ_ARM_GNU_VTINHERIT 101 #define RZ_ARM_THM_PC11 102 /* PC relative & 0xFFE (Thumb16 B). */ #define RZ_ARM_THM_PC9 103 /* PC relative & 0x1FE \ - (Thumb16 B/B). */ + (Thumb16 B/B). */ #define RZ_ARM_TLS_GD32 104 /* PC-rel 32 bit for global dynamic \ thread local data */ #define RZ_ARM_TLS_LDM32 105 /* PC-rel 32 bit for local dynamic \ @@ -3015,7 +3015,7 @@ enum { #define RZ_ARM_THM_TLS_DESCSEQ16 129 #define RZ_ARM_THM_TLS_DESCSEQ32 130 #define RZ_ARM_THM_GOT_BREL12 131 /* GOT entry relative to GOT \ - origin, 12 bit (Thumb32 LDR). */ + origin, 12 bit (Thumb32 LDR). */ #define RZ_ARM_IRELATIVE 160 #define RZ_ARM_RXPC25 249 #define RZ_ARM_RSBREL32 250 @@ -3362,7 +3362,7 @@ enum { #define RZ_390_TLS_DTPMOD 54 /* ID of module containing symbol. */ #define RZ_390_TLS_DTPOFF 55 /* Offset in TLS block. */ #define RZ_390_TLS_TPOFF 56 /* Negated offset in static TLS \ - block. */ + block. */ #define RZ_390_20 57 /* Direct 20 bit. */ #define RZ_390_GOT20 58 /* 20 bit GOT offset. */ #define RZ_390_GOTPLT20 59 /* 20 bit offset to jump slot. */ @@ -3407,7 +3407,7 @@ enum { #define RZ_X86_64_JUMP_SLOT 7 /* Create PLT entry */ #define RZ_X86_64_RELATIVE 8 /* Adjust by program base */ #define RZ_X86_64_GOTPCREL 9 /* 32 bit signed PC relative \ - offset to GOT */ + offset to GOT */ #define RZ_X86_64_32 10 /* Direct 32 bit zero extended */ #define RZ_X86_64_32S 11 /* Direct 32 bit sign extended */ #define RZ_X86_64_16 12 /* Direct 16 bit zero extended */ @@ -3418,7 +3418,7 @@ enum { #define RZ_X86_64_DTPOFF64 17 /* Offset in module's TLS block */ #define RZ_X86_64_TPOFF64 18 /* Offset in initial TLS block */ #define RZ_X86_64_TLSGD 19 /* 32 bit signed PC relative offset \ - to two GOT entries for GD symbol */ + to two GOT entries for GD symbol */ #define RZ_X86_64_TLSLD 20 /* 32 bit signed PC relative offset \ to two GOT entries for LD symbol */ #define RZ_X86_64_DTPOFF32 21 /* Offset in TLS block */ @@ -3428,7 +3428,7 @@ enum { #define RZ_X86_64_PC64 24 /* PC relative 64 bit */ #define RZ_X86_64_GOTOFF64 25 /* 64 bit offset to GOT */ #define RZ_X86_64_GOTPC32 26 /* 32 bit signed pc relative \ - offset to GOT */ + offset to GOT */ #define RZ_X86_64_GOT64 27 /* 64-bit GOT entry offset */ #define RZ_X86_64_GOTPCREL64 28 /* 64-bit PC relative offset \ to GOT entry */ @@ -3440,7 +3440,7 @@ enum { #define RZ_X86_64_SIZE64 33 /* Size of symbol plus 64-bit addend */ #define RZ_X86_64_GOTPC32_TLSDESC 34 /* GOT offset for TLS descriptor. */ #define RZ_X86_64_TLSDESC_CALL 35 /* Marker for call through TLS \ - descriptor. */ + descriptor. */ #define RZ_X86_64_TLSDESC 36 /* TLS descriptor. */ #define RZ_X86_64_IRELATIVE 37 /* Adjust indirectly by program base */ #define RZ_X86_64_RELATIVE64 38 /* 64-bit adjust by program base */ @@ -3486,7 +3486,7 @@ enum { #define RZ_MN10300_TLS_LD 25 /* 32-bit offset for local dynamic. */ #define RZ_MN10300_TLS_LDO 26 /* Module-relative offset. */ #define RZ_MN10300_TLS_GOTIE 27 /* GOT offset for static TLS block \ - offset. */ + offset. */ #define RZ_MN10300_TLS_IE 28 /* GOT address for static TLS block \ offset. */ #define RZ_MN10300_TLS_LE 29 /* Offset relative to static TLS \ @@ -3495,7 +3495,7 @@ enum { #define RZ_MN10300_TLS_DTPOFF 31 /* Offset in module TLS block. */ #define RZ_MN10300_TLS_TPOFF 32 /* Offset in static TLS block. */ #define RZ_MN10300_SYM_DIFF 33 /* Adjustment for next reloc as needed \ - by linker relaxation. */ + by linker relaxation. */ #define RZ_MN10300_ALIGN 34 /* Alignment requirement for linker \ relaxation. */ #define RZ_MN10300_NUM 35 @@ -3613,7 +3613,7 @@ enum { #define RZ_NIOS2_CJMP 19 /* Conditional branch. */ #define RZ_NIOS2_CALLR 20 /* Indirect call through register. */ #define RZ_NIOS2_ALIGN 21 /* Alignment requirement for \ - linker relaxation. */ + linker relaxation. */ #define RZ_NIOS2_GOT16 22 /* 16 bit GOT entry. */ #define RZ_NIOS2_CALL16 23 /* 16 bit GOT entry for function. */ #define RZ_NIOS2_GOTOFF_LO 24 /* %lo of offset to GOT pointer. */ diff --git a/librz/bin/format/java/class_attribute.h b/librz/bin/format/java/class_attribute.h index 3e0fedfbbbd..b9550e4b1f1 100644 --- a/librz/bin/format/java/class_attribute.h +++ b/librz/bin/format/java/class_attribute.h @@ -102,7 +102,7 @@ typedef struct java_attribute_module_t { ut16 module_version_index; ut16 requires_count; - ModuleRequire *requires; + ModuleRequire * requires; ut16 exports_count; ModuleExport *exports; diff --git a/librz/bin/format/mach0/mach0_defines.h b/librz/bin/format/mach0/mach0_defines.h index a0417b5dd08..bd1485565bb 100644 --- a/librz/bin/format/mach0/mach0_defines.h +++ b/librz/bin/format/mach0/mach0_defines.h @@ -1055,7 +1055,7 @@ static inline uint16_t GET_LIBRARY_ORDINAL(uint16_t n_desc) { } static inline void SET_LIBRARY_ORDINAL(uint16_t *n_desc, uint8_t ordinal) { - *n_desc = (((*n_desc) & 0x00ff) | (((ordinal)&0xff) << 8)); + *n_desc = (((*n_desc) & 0x00ff) | (((ordinal) & 0xff) << 8)); } static inline uint8_t GET_COMM_ALIGN(uint16_t n_desc) { diff --git a/librz/bin/format/objc/mach0_classes.c b/librz/bin/format/objc/mach0_classes.c index 53c096c36eb..8e59e1fa8fa 100644 --- a/librz/bin/format/objc/mach0_classes.c +++ b/librz/bin/format/objc/mach0_classes.c @@ -18,7 +18,7 @@ #define METHOD_LIST_FLAG_IS_PREOPT 0x3 #define METHOD_LIST_ENTSIZE_FLAG_MASK 0xffff0003 -#define RO_DATA_PTR(x) ((x)&FAST_DATA_MASK) +#define RO_DATA_PTR(x) ((x) & FAST_DATA_MASK) #if RZ_BIN_MACH064 #define rz_buf_read_mach0_ut_offset rz_buf_read_ble64_offset diff --git a/librz/bin/format/pe/pe_rsrc.c b/librz/bin/format/pe/pe_rsrc.c index f15d1e1038d..eca92cdbbe4 100644 --- a/librz/bin/format/pe/pe_rsrc.c +++ b/librz/bin/format/pe/pe_rsrc.c @@ -129,7 +129,7 @@ static void free_StringFileInfo(StringFileInfo *stringFileInfo) { } } -#define align32(x) x = (((x)&0x3) == 0) ? (x) : ((x) & ~0x3) + 0x4; +#define align32(x) x = (((x) & 0x3) == 0) ? (x) : ((x) & ~0x3) + 0x4; static void free_VS_VERSIONINFO(PE_VS_VERSIONINFO *vs_VersionInfo) { if (vs_VersionInfo) { diff --git a/librz/bin/p/bin_avr.c b/librz/bin/p/bin_avr.c index 7f27b4aeeee..637f795b279 100644 --- a/librz/bin/p/bin_avr.c +++ b/librz/bin/p/bin_avr.c @@ -7,15 +7,15 @@ #define CHECK4INSTR(b, instr, size) \ if (!instr(b, 0) || \ !instr((b), (size)) || \ - !instr((b), (size)*2) || \ - !instr((b), (size)*3)) { \ + !instr((b), (size) * 2) || \ + !instr((b), (size) * 3)) { \ return false; \ } #define CHECK3INSTR(b, instr, size) \ if (!instr((b), (size)) || \ - !instr((b), (size)*2) || \ - !instr((b), (size)*3)) { \ + !instr((b), (size) * 2) || \ + !instr((b), (size) * 3)) { \ return false; \ } diff --git a/librz/bin/p/bin_elf.inc b/librz/bin/p/bin_elf.inc index c7382dba3cc..db2101a4a9b 100644 --- a/librz/bin/p/bin_elf.inc +++ b/librz/bin/p/bin_elf.inc @@ -1023,7 +1023,7 @@ static void patch_reloc_hexagon(RZ_INOUT RzBuffer *buf_patched, const ut64 patch // AARCH64-specific defines // Take the PAGE component of an address or offset. #define PG(x) ((x) & ~0xFFFULL) -#define PG_OFFSET(x) ((x)&0xFFFULL) +#define PG_OFFSET(x) ((x) & 0xFFFULL) #define ADR_IMM_MASK1 (((1U << 2) - 1) << 29) #define ADR_IMM_MASK2 (((1U << 19) - 1) << 5) #define ADR_IMM_MASK3 (((1U << 19) - 1) << 2) diff --git a/librz/core/cbin.c b/librz/core/cbin.c index e636ccc54ef..c9073165907 100644 --- a/librz/core/cbin.c +++ b/librz/core/cbin.c @@ -24,14 +24,14 @@ #define LOAD_BSS_MALLOC 0 -#define IS_MODE_SET(mode) ((mode)&RZ_MODE_SET) -#define IS_MODE_SIMPLE(mode) ((mode)&RZ_MODE_SIMPLE) -#define IS_MODE_SIMPLEST(mode) ((mode)&RZ_MODE_SIMPLEST) -#define IS_MODE_JSON(mode) ((mode)&RZ_MODE_JSON) -#define IS_MODE_RZCMD(mode) ((mode)&RZ_MODE_RIZINCMD) -#define IS_MODE_EQUAL(mode) ((mode)&RZ_MODE_EQUAL) +#define IS_MODE_SET(mode) ((mode) & RZ_MODE_SET) +#define IS_MODE_SIMPLE(mode) ((mode) & RZ_MODE_SIMPLE) +#define IS_MODE_SIMPLEST(mode) ((mode) & RZ_MODE_SIMPLEST) +#define IS_MODE_JSON(mode) ((mode) & RZ_MODE_JSON) +#define IS_MODE_RZCMD(mode) ((mode) & RZ_MODE_RIZINCMD) +#define IS_MODE_EQUAL(mode) ((mode) & RZ_MODE_EQUAL) #define IS_MODE_NORMAL(mode) (!(mode)) -#define IS_MODE_CLASSDUMP(mode) ((mode)&RZ_MODE_CLASSDUMP) +#define IS_MODE_CLASSDUMP(mode) ((mode) & RZ_MODE_CLASSDUMP) // dup from cmd_info #define PAIR_WIDTH "9" diff --git a/librz/core/windows_heap.c b/librz/core/windows_heap.c index 12c09ba817c..97cb0b61b02 100644 --- a/librz/core/windows_heap.c +++ b/librz/core/windows_heap.c @@ -79,11 +79,11 @@ static size_t RtlpLFHKeyOffset = 0; } #define UPDATE_FLAGS(hb, flags) \ - if (((flags)&0xf1) || ((flags)&0x0200)) { \ + if (((flags) & 0xf1) || ((flags) & 0x0200)) { \ hb->dwFlags = LF32_FIXED; \ - } else if ((flags)&0x20) { \ + } else if ((flags) & 0x20) { \ hb->dwFlags = LF32_MOVEABLE; \ - } else if ((flags)&0x0100) { \ + } else if ((flags) & 0x0100) { \ hb->dwFlags = LF32_FREE; \ } \ hb->dwFlags |= ((flags) >> SHIFT) << SHIFT; diff --git a/librz/crypto/des.c b/librz/crypto/des.c index 17d3107b707..82410457625 100644 --- a/librz/crypto/des.c +++ b/librz/crypto/des.c @@ -253,7 +253,7 @@ RZ_API void rz_des_pc2(RZ_OUT ut32 *keylo, RZ_OUT ut32 *keyhi, RZ_IN ut32 deslo, ((deslo << 2) & 0x00020000) | ((deslo >> 10) & 0x00010000) | ((deshi >> 13) & 0x00002000) | ((deshi >> 4) & 0x00001000) | ((deshi << 6) & 0x00000800) | ((deshi >> 1) & 0x00000400) | - ((deshi >> 14) & 0x00000200) | ((deshi)&0x00000100) | + ((deshi >> 14) & 0x00000200) | ((deshi) & 0x00000100) | ((deshi >> 5) & 0x00000020) | ((deshi >> 10) & 0x00000010) | ((deshi >> 3) & 0x00000008) | ((deshi >> 18) & 0x00000004) | ((deshi >> 26) & 0x00000002) | ((deshi >> 24) & 0x00000001); @@ -266,7 +266,7 @@ RZ_API void rz_des_pc2(RZ_OUT ut32 *keylo, RZ_OUT ut32 *keyhi, RZ_IN ut32 deslo, ((deslo << 15) & 0x00020000) | ((deslo >> 4) & 0x00010000) | ((deshi >> 2) & 0x00002000) | ((deshi << 8) & 0x00001000) | ((deshi >> 14) & 0x00000808) | ((deshi >> 9) & 0x00000400) | - ((deshi)&0x00000200) | ((deshi << 7) & 0x00000100) | + ((deshi) & 0x00000200) | ((deshi << 7) & 0x00000100) | ((deshi >> 7) & 0x00000020) | ((deshi >> 3) & 0x00000011) | ((deshi << 2) & 0x00000004) | ((deshi >> 21) & 0x00000002); } diff --git a/librz/crypto/p/crypto_blowfish.c b/librz/crypto/p/crypto_blowfish.c index 0d0462828ed..66729a73042 100644 --- a/librz/crypto/p/crypto_blowfish.c +++ b/librz/crypto/p/crypto_blowfish.c @@ -169,7 +169,7 @@ static ut32 F(struct blowfish_state *const state, const ut32 inbuf) { ut8 a = (inbuf >> 24) & 0xff; ut8 b = (inbuf >> 16) & 0xff; ut8 c = (inbuf >> 8) & 0xff; - ut8 d = (inbuf)&0xff; + ut8 d = (inbuf) & 0xff; return ((state->s[0][a] + state->s[1][b]) ^ state->s[2][c]) + state->s[3][d]; } diff --git a/librz/debug/p/debug_native.c b/librz/debug/p/debug_native.c index e64eae75d5e..90ab069ca92 100644 --- a/librz/debug/p/debug_native.c +++ b/librz/debug/p/debug_native.c @@ -23,43 +23,43 @@ static int rz_debug_native_reg_write(RzDebug *dbg, int type, const ut8 *buf, int // Native OS & Arch #if __APPLE__ #if __i386__ || __x86_64__ -#include "apple_x86_64.c" +#include "native/apple_x86_64.c" #else -#include "apple_aarch64.c" +#include "native/apple_aarch64.c" #endif #elif __ANDROID__ #if __i386__ || __x86_64__ -#include "android_x86_64.c" +#include "native/android_x86_64.c" #elif __arm__ -#include "android_arm.c" +#include "native/android_arm.c" #else -#include "android_arm64.c" +#include "native/android_arm64.c" #endif #elif __linux__ #if __i386__ || __x86_64__ -#include "linux_x86_64.c" +#include "native/linux_x86_64.c" #elif __arm__ -#include "linux_arm.c" +#include "native/linux_arm.c" #else -#include "linux_arm64.c" +#include "native/linux_arm64.c" #endif -#elif __WIDOWS__ -#include "windows.c" +#elif __WINDOWS__ +#include "native/windows.c" #elif __BSD__ #if __KFBSD__ -#include "KFBSD.c" +#include "native/kfbsd.c" #elif __OpenBSD__ -#include "OpenBSD.c" +#include "native/openbsd.c" #elif __NetBSD__ -#include "NetBSD.c" +#include "native/netbsd.c" #elif __DragonFly__ -#include "DragonFly.c" +#include "native/dragonfly.c" #else -#warning Unsupported debugging platform +#warning "Unsupported debugging platform" #undef DEBUGGER #define DEBUGGER 0 #endif @@ -68,10 +68,10 @@ static int rz_debug_native_reg_write(RzDebug *dbg, int type, const ut8 *buf, int #define RZ_DEBUG_REG_T gregset_t #undef DEBUGGER #define DEBUGGER 0 -#warning No debugger support for SunOS yet +#warning "No debugger support for SunOS yet" #else -#warning Unsupported debugging platform +#warning "Unsupported debugging platform" #undef DEBUGGER #define DEBUGGER 0 #endif // Native OS & Arch @@ -125,7 +125,7 @@ RzDebugPlugin rz_debug_plugin_native = { #ifdef _MSC_VER #pragma message("Unsupported architecture") #else -#warning Unsupported architecture +#warning "Unsupported architecture" #endif #endif .init = &rz_debug_native_init, diff --git a/librz/debug/p/android_arm.c b/librz/debug/p/native/android_arm.c similarity index 98% rename from librz/debug/p/android_arm.c rename to librz/debug/p/native/android_arm.c index 4fbc2349f4f..86041c04ebe 100644 --- a/librz/debug/p/android_arm.c +++ b/librz/debug/p/native/android_arm.c @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: 2009-2019 pancake +// SPDX-License-Identifier: LGPL-3.0-only + #include #if !defined(__HAIKU__) && !defined(__sun) #include @@ -6,8 +9,8 @@ #include #include -#include "native/linux/linux_debug.h" -#include "native/procfs.h" +#include "linux/linux_debug.h" +#include "procfs.h" #define WAIT_ANY -1 #ifndef WIFCONTINUED #define WIFCONTINUED(s) ((s) == 0xffff) @@ -38,7 +41,7 @@ static char *rz_debug_native_reg_profile(RzDebug *dbg) { return linux_reg_profile(dbg); } -#include "native/reg.c" +#include "reg.c" static bool rz_debug_native_step(RzDebug *dbg) { return linux_step(dbg); @@ -269,7 +272,7 @@ static int io_perms_to_prot(int io_perms) { } static int linux_map_thp(RzDebug *dbg, ut64 addr, int size) { -return false; + return false; } static RzDebugMap *linux_map_alloc(RzDebug *dbg, ut64 addr, int size, bool thp) { @@ -560,7 +563,6 @@ static bool rz_debug_native_init(RzDebug *dbg, void **user) { static void rz_debug_native_fini(RzDebug *dbg, void *user) { } - static int rz_debug_native_drx(RzDebug *dbg, int n, ut64 addr, int sz, int rwx, int g, int api_type) { eprintf("drx: Unsupported platform\n"); return -1; @@ -580,7 +582,6 @@ static int rz_debug_native_drx(RzDebug *dbg, int n, ut64 addr, int sz, int rwx, #define PTRACE_SETHBPREGS 30 #endif - static bool ll_arm32_hwbp_set(pid_t pid, ut64 addr, int size, int wp, int type) { const unsigned byte_mask = (1 << size) - 1; // const unsigned type = 2; // Write. @@ -598,7 +599,6 @@ static bool arm32_hwbp_del(RzDebug *dbg, RzBreakpoint *bp, RzBreakpointItem *b) return false; // TODO: hwbp.del not yetimplemented } - static int rz_debug_native_bp(RzBreakpoint *bp, RzBreakpointItem *b, bool set) { if (b && b->hw) { return set diff --git a/librz/debug/p/android_arm64.c b/librz/debug/p/native/android_arm64.c similarity index 99% rename from librz/debug/p/android_arm64.c rename to librz/debug/p/native/android_arm64.c index d1e260f962e..d5cf33ba8bf 100644 --- a/librz/debug/p/android_arm64.c +++ b/librz/debug/p/native/android_arm64.c @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: 2009-2019 pancake +// SPDX-License-Identifier: LGPL-3.0-only + #include #if !defined(__HAIKU__) && !defined(__sun) #include @@ -6,8 +9,8 @@ #include #include -#include "native/linux/linux_debug.h" -#include "native/procfs.h" +#include "linux/linux_debug.h" +#include "procfs.h" #define WAIT_ANY -1 #ifndef WIFCONTINUED #define WIFCONTINUED(s) ((s) == 0xffff) @@ -38,7 +41,7 @@ static char *rz_debug_native_reg_profile(RzDebug *dbg) { return linux_reg_profile(dbg); } -#include "native/reg.c" +#include "reg.c" static bool rz_debug_native_step(RzDebug *dbg) { return linux_step(dbg); @@ -269,7 +272,7 @@ static int io_perms_to_prot(int io_perms) { } static int linux_map_thp(RzDebug *dbg, ut64 addr, int size) { -return false; + return false; } static RzDebugMap *linux_map_alloc(RzDebug *dbg, ut64 addr, int size, bool thp) { @@ -560,7 +563,6 @@ static bool rz_debug_native_init(RzDebug *dbg, void **user) { static void rz_debug_native_fini(RzDebug *dbg, void *user) { } - static int rz_debug_native_drx(RzDebug *dbg, int n, ut64 addr, int sz, int rwx, int g, int api_type) { eprintf("drx: Unsupported platform\n"); return -1; @@ -580,7 +582,6 @@ static int rz_debug_native_drx(RzDebug *dbg, int n, ut64 addr, int sz, int rwx, #define PTRACE_SETHBPREGS 30 #endif - #if PTRACE_GETREGSET // type = 2 = write // static volatile uint8_t var[96] __attribute__((__aligned__(32))); diff --git a/librz/debug/p/android_x86_64.c b/librz/debug/p/native/android_x86_64.c similarity index 98% rename from librz/debug/p/android_x86_64.c rename to librz/debug/p/native/android_x86_64.c index 31db1cb1d5a..e7e90f4ad21 100644 --- a/librz/debug/p/android_x86_64.c +++ b/librz/debug/p/native/android_x86_64.c @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: 2009-2019 pancake +// SPDX-License-Identifier: LGPL-3.0-only + #include #if !defined(__HAIKU__) && !defined(__sun) #include @@ -6,8 +9,8 @@ #include #include -#include "native/linux/linux_debug.h" -#include "native/procfs.h" +#include "linux/linux_debug.h" +#include "procfs.h" #define WAIT_ANY -1 #ifndef WIFCONTINUED #define WIFCONTINUED(s) ((s) == 0xffff) @@ -38,7 +41,7 @@ static char *rz_debug_native_reg_profile(RzDebug *dbg) { return linux_reg_profile(dbg); } -#include "native/reg.c" +#include "reg.c" static bool rz_debug_native_step(RzDebug *dbg) { return linux_step(dbg); @@ -269,7 +272,7 @@ static int io_perms_to_prot(int io_perms) { } static int linux_map_thp(RzDebug *dbg, ut64 addr, int size) { -return false; + return false; } static RzDebugMap *linux_map_alloc(RzDebug *dbg, ut64 addr, int size, bool thp) { @@ -598,7 +601,6 @@ static void set_drx_regs(RzDebug *dbg, drxt *regs, size_t num_regs) { rz_reg_setv(R, "dr7", regs[7]); } - static int rz_debug_native_drx(RzDebug *dbg, int n, ut64 addr, int sz, int rwx, int g, int api_type) { int retval = false; drxt regs[NUM_DRX_REGISTERS] = { 0 }; diff --git a/librz/debug/p/apple_aarch64.c b/librz/debug/p/native/apple_aarch64.c similarity index 98% rename from librz/debug/p/apple_aarch64.c rename to librz/debug/p/native/apple_aarch64.c index 28277bee2c9..e899747a595 100644 --- a/librz/debug/p/apple_aarch64.c +++ b/librz/debug/p/native/apple_aarch64.c @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: 2009-2019 pancake +// SPDX-License-Identifier: LGPL-3.0-only + #include #if !defined(__HAIKU__) && !defined(__sun) #include @@ -6,7 +9,7 @@ #include #include -#include "native/xnu/xnu_debug.h" +#include "xnu/xnu_debug.h" #ifdef __WALL #define WAITPID_FLAGS __WALL @@ -232,7 +235,6 @@ static void rz_debug_native_fini(RzDebug *dbg, void *user) { rz_xnu_debug_fini(dbg, user); } - static int rz_debug_native_drx(RzDebug *dbg, int n, ut64 addr, int sz, int rwx, int g, int api_type) { eprintf("drx: Unsupported platform\n"); return -1; diff --git a/librz/debug/p/apple_x86_64.c b/librz/debug/p/native/apple_x86_64.c similarity index 98% rename from librz/debug/p/apple_x86_64.c rename to librz/debug/p/native/apple_x86_64.c index 052e0bee4b1..798d9542c21 100644 --- a/librz/debug/p/apple_x86_64.c +++ b/librz/debug/p/native/apple_x86_64.c @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: 2009-2019 pancake +// SPDX-License-Identifier: LGPL-3.0-only + #include #if !defined(__HAIKU__) && !defined(__sun) #include @@ -6,7 +9,7 @@ #include #include -#include "native/xnu/xnu_debug.h" +#include "xnu/xnu_debug.h" #ifdef __WALL #define WAITPID_FLAGS __WALL diff --git a/librz/debug/p/DragonFly.c b/librz/debug/p/native/dragonfly.c similarity index 87% rename from librz/debug/p/DragonFly.c rename to librz/debug/p/native/dragonfly.c index babe0d52075..cd6946e4908 100644 --- a/librz/debug/p/DragonFly.c +++ b/librz/debug/p/native/dragonfly.c @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: 2009-2019 pancake +// SPDX-License-Identifier: LGPL-3.0-only + #include #if !defined(__HAIKU__) && !defined(__sun) #include @@ -5,8 +8,8 @@ #include #include -#include "native/bsd/bsd_debug.h" -#include "native/procfs.h" +#include "bsd/bsd_debug.h" +#include "procfs.h" #ifdef __WALL #define WAITPID_FLAGS __WALL @@ -27,7 +30,7 @@ static int rz_debug_handle_signals(RzDebug *dbg) { return 0; } -#include "native/reg.c" +#include "reg.c" static bool rz_debug_native_step(RzDebug *dbg) { int ret = ptrace(PT_STEP, dbg->pid, (caddr_t)1, 0); @@ -98,58 +101,58 @@ static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { } /* we don't know what to do yet, let's try harder to figure it out. */ if (reason == RZ_DEBUG_REASON_UNKNOWN) { - if (WIFEXITED(status)) { - eprintf("child exited with status %d\n", WEXITSTATUS(status)); - reason = RZ_DEBUG_REASON_DEAD; - } else if (WIFSIGNALED(status)) { - eprintf("child received signal %d\n", WTERMSIG(status)); - reason = RZ_DEBUG_REASON_SIGNAL; - } else if (WIFSTOPPED(status)) { - if (WSTOPSIG(status) != SIGTRAP && - WSTOPSIG(status) != SIGSTOP) { - eprintf("Child stopped with signal %d\n", WSTOPSIG(status)); - } + if (WIFEXITED(status)) { + eprintf("child exited with status %d\n", WEXITSTATUS(status)); + reason = RZ_DEBUG_REASON_DEAD; + } else if (WIFSIGNALED(status)) { + eprintf("child received signal %d\n", WTERMSIG(status)); + reason = RZ_DEBUG_REASON_SIGNAL; + } else if (WIFSTOPPED(status)) { + if (WSTOPSIG(status) != SIGTRAP && + WSTOPSIG(status) != SIGSTOP) { + eprintf("Child stopped with signal %d\n", WSTOPSIG(status)); + } - /* the ptrace documentation says GETSIGINFO is only necessary for - * differentiating the various stops. - * - * this might modify dbg->reason.signum - */ + /* the ptrace documentation says GETSIGINFO is only necessary for + * differentiating the various stops. + * + * this might modify dbg->reason.signum + */ if (rz_debug_handle_signals(dbg) != 0) { return RZ_DEBUG_REASON_ERROR; } reason = dbg->reason.type; #ifdef WIFCONTINUED - } else if (WIFCONTINUED(status)) { - eprintf("child continued...\n"); - reason = RZ_DEBUG_REASON_NONE; + } else if (WIFCONTINUED(status)) { + eprintf("child continued...\n"); + reason = RZ_DEBUG_REASON_NONE; #endif - } else if (status == 1) { - /* XXX(jjd): does this actually happen? */ - eprintf("debugger is dead with status 1!\n"); - reason = RZ_DEBUG_REASON_DEAD; - } else if (status == 0) { - /* XXX(jjd): does this actually happen? */ - eprintf("debugger is dead with status 0\n"); - reason = RZ_DEBUG_REASON_DEAD; - } else { - if (ret != pid) { - reason = RZ_DEBUG_REASON_NEW_PID; + } else if (status == 1) { + /* XXX(jjd): does this actually happen? */ + eprintf("debugger is dead with status 1!\n"); + reason = RZ_DEBUG_REASON_DEAD; + } else if (status == 0) { + /* XXX(jjd): does this actually happen? */ + eprintf("debugger is dead with status 0\n"); + reason = RZ_DEBUG_REASON_DEAD; } else { - /* ugh. still don't know :-/ */ - eprintf("returning from wait without knowing why...\n"); + if (ret != pid) { + reason = RZ_DEBUG_REASON_NEW_PID; + } else { + /* ugh. still don't know :-/ */ + eprintf("returning from wait without knowing why...\n"); + } } } -} -/* if we still don't know what to do, we have a problem... */ -if (reason == RZ_DEBUG_REASON_UNKNOWN) { - eprintf("%s: no idea what happened...\n", __func__); - reason = RZ_DEBUG_REASON_ERROR; -} -dbg->reason.tid = pid; -dbg->reason.type = reason; -return reason; + /* if we still don't know what to do, we have a problem... */ + if (reason == RZ_DEBUG_REASON_UNKNOWN) { + eprintf("%s: no idea what happened...\n", __func__); + reason = RZ_DEBUG_REASON_ERROR; + } + dbg->reason.tid = pid; + dbg->reason.type = reason; + return reason; } #undef MAXPID @@ -200,7 +203,7 @@ static int bsd_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { RZ_DEBUG_REG_T regs; memset(®s, 0, sizeof(regs)); memset(buf, 0, size); -#warning not implemented for this platform +#warning "not implemented for this platform" ret = 1; // if perror here says 'no such process' and the // process exists still.. is because there's a @@ -520,7 +523,7 @@ static int rz_debug_native_bp(RzBreakpoint *bp, RzBreakpointItem *b, bool set) { } static RzList /**/ *rz_debug_desc_native_list(int pid) { -#warning list filedescriptors not supported for this platform +#warning "list filedescriptors not supported for this platform" return NULL; } diff --git a/librz/debug/p/KFBSD.c b/librz/debug/p/native/kfbsd.c similarity index 88% rename from librz/debug/p/KFBSD.c rename to librz/debug/p/native/kfbsd.c index 333dbee0bf4..75fa9d4b9a0 100644 --- a/librz/debug/p/KFBSD.c +++ b/librz/debug/p/native/kfbsd.c @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: 2009-2019 pancake +// SPDX-License-Identifier: LGPL-3.0-only + #include #if !defined(__HAIKU__) && !defined(__sun) #include @@ -5,8 +8,8 @@ #include #include -#include "native/bsd/bsd_debug.h" -#include "native/procfs.h" +#include "bsd/bsd_debug.h" +#include "procfs.h" #ifdef __WALL #define WAITPID_FLAGS __WALL @@ -26,7 +29,7 @@ static int rz_debug_handle_signals(RzDebug *dbg) { return bsd_handle_signals(dbg); } -#include "native/reg.c" +#include "reg.c" static bool rz_debug_native_step(RzDebug *dbg) { int ret = ptrace(PT_STEP, dbg->pid, (caddr_t)1, 0); @@ -95,57 +98,57 @@ static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { } /* we don't know what to do yet, let's try harder to figure it out. */ if (reason == RZ_DEBUG_REASON_UNKNOWN) { - if (WIFEXITED(status)) { - eprintf("child exited with status %d\n", WEXITSTATUS(status)); - reason = RZ_DEBUG_REASON_DEAD; - } else if (WIFSIGNALED(status)) { - eprintf("child received signal %d\n", WTERMSIG(status)); - reason = RZ_DEBUG_REASON_SIGNAL; - } else if (WIFSTOPPED(status)) { - if (WSTOPSIG(status) != SIGTRAP && - WSTOPSIG(status) != SIGSTOP) { - eprintf("Child stopped with signal %d\n", WSTOPSIG(status)); - } + if (WIFEXITED(status)) { + eprintf("child exited with status %d\n", WEXITSTATUS(status)); + reason = RZ_DEBUG_REASON_DEAD; + } else if (WIFSIGNALED(status)) { + eprintf("child received signal %d\n", WTERMSIG(status)); + reason = RZ_DEBUG_REASON_SIGNAL; + } else if (WIFSTOPPED(status)) { + if (WSTOPSIG(status) != SIGTRAP && + WSTOPSIG(status) != SIGSTOP) { + eprintf("Child stopped with signal %d\n", WSTOPSIG(status)); + } - /* the ptrace documentation says GETSIGINFO is only necessary for - * differentiating the various stops. - * - * this might modify dbg->reason.signum - */ + /* the ptrace documentation says GETSIGINFO is only necessary for + * differentiating the various stops. + * + * this might modify dbg->reason.signum + */ if (rz_debug_handle_signals(dbg) != 0) { return RZ_DEBUG_REASON_ERROR; } reason = dbg->reason.type; #ifdef WIFCONTINUED - } else if (WIFCONTINUED(status)) { - eprintf("child continued...\n"); - reason = RZ_DEBUG_REASON_NONE; + } else if (WIFCONTINUED(status)) { + eprintf("child continued...\n"); + reason = RZ_DEBUG_REASON_NONE; #endif - } else if (status == 1) { - /* XXX(jjd): does this actually happen? */ - eprintf("debugger is dead with status 1!\n"); - reason = RZ_DEBUG_REASON_DEAD; - } else if (status == 0) { - /* XXX(jjd): does this actually happen? */ - eprintf("debugger is dead with status 0\n"); - reason = RZ_DEBUG_REASON_DEAD; - } else { - if (ret != pid) { - reason = RZ_DEBUG_REASON_NEW_PID; + } else if (status == 1) { + /* XXX(jjd): does this actually happen? */ + eprintf("debugger is dead with status 1!\n"); + reason = RZ_DEBUG_REASON_DEAD; + } else if (status == 0) { + /* XXX(jjd): does this actually happen? */ + eprintf("debugger is dead with status 0\n"); + reason = RZ_DEBUG_REASON_DEAD; } else { - /* ugh. still don't know :-/ */ - eprintf("returning from wait without knowing why...\n"); + if (ret != pid) { + reason = RZ_DEBUG_REASON_NEW_PID; + } else { + /* ugh. still don't know :-/ */ + eprintf("returning from wait without knowing why...\n"); + } } } -} -/* if we still don't know what to do, we have a problem... */ -if (reason == RZ_DEBUG_REASON_UNKNOWN) { - eprintf("%s: no idea what happened...\n", __func__); - reason = RZ_DEBUG_REASON_ERROR; -} -dbg->reason.tid = pid; -dbg->reason.type = reason; -return reason; + /* if we still don't know what to do, we have a problem... */ + if (reason == RZ_DEBUG_REASON_UNKNOWN) { + eprintf("%s: no idea what happened...\n", __func__); + reason = RZ_DEBUG_REASON_ERROR; + } + dbg->reason.tid = pid; + dbg->reason.type = reason; + return reason; } #undef MAXPID @@ -281,7 +284,6 @@ static RzList /**/ *rz_debug_native_map_get(RzDebug *dbg) { region[0] = region2[0] = '0'; region[1] = region2[1] = 'x'; - list = bsd_native_sysctl_map(dbg); if (list) { return list; diff --git a/librz/debug/p/linux_arm.c b/librz/debug/p/native/linux_arm.c similarity index 98% rename from librz/debug/p/linux_arm.c rename to librz/debug/p/native/linux_arm.c index d533298dcd6..c91385538c0 100644 --- a/librz/debug/p/linux_arm.c +++ b/librz/debug/p/native/linux_arm.c @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: 2009-2019 pancake +// SPDX-License-Identifier: LGPL-3.0-only + #include #if !defined(__HAIKU__) && !defined(__sun) #include @@ -6,9 +9,9 @@ #include #include -#include "native/linux/linux_debug.h" -#include "native/procfs.h" -#include "native/linux/linux_coredump.h" +#include "linux/linux_debug.h" +#include "procfs.h" +#include "linux/linux_coredump.h" #ifdef __WALL #define WAITPID_FLAGS __WALL @@ -35,8 +38,6 @@ static char *rz_debug_native_reg_profile(RzDebug *dbg) { return linux_reg_profile(dbg); } -#include "native/reg.c" - static bool rz_debug_native_step(RzDebug *dbg) { return linux_step(dbg); } diff --git a/librz/debug/p/native/linux_arm64.c b/librz/debug/p/native/linux_arm64.c new file mode 100644 index 00000000000..85236cc8e06 --- /dev/null +++ b/librz/debug/p/native/linux_arm64.c @@ -0,0 +1,794 @@ +// SPDX-FileCopyrightText: 2009-2019 pancake +// SPDX-License-Identifier: LGPL-3.0-only + +#include +#if !defined(__HAIKU__) && !defined(__sun) +#include +#endif +#include +#include + +#include +#include "linux/linux_debug.h" +#include "procfs.h" +#include "linux/linux_coredump.h" + +#ifdef __WALL +#define WAITPID_FLAGS __WALL +#else +#define WAITPID_FLAGS 0 +#endif + +#define PROC_NAME_SZ 1024 +#define PROC_REGION_SZ 100 +// PROC_REGION_SZ - 2 (used for `0x`). Due to how RZ_STR_DEF works this can't be +// computed. +#define PROC_REGION_LEFT_SZ 98 +#define PROC_PERM_SZ 5 +#define PROC_UNKSTR_SZ 128 + +#if WAIT_ON_ALL_CHILDREN +static int rz_debug_handle_signals(RzDebug *dbg) { + eprintf("Warning: signal handling is not supported on this platform\n"); + return 0; +} +#endif + +static char *rz_debug_native_reg_profile(RzDebug *dbg) { + return linux_reg_profile(dbg); +} + +static bool rz_debug_native_step(RzDebug *dbg) { + return linux_step(dbg); +} + +static int rz_debug_native_attach(RzDebug *dbg, int pid) { + return linux_attach(dbg, pid); +} + +static int rz_debug_native_detach(RzDebug *dbg, int pid) { + return rz_debug_ptrace(dbg, PTRACE_DETACH, pid, NULL, (rz_ptrace_data_t)(size_t)0); +} + +static int rz_debug_native_select(RzDebug *dbg, int pid, int tid) { + return linux_select(dbg, pid, tid); +} + +static int rz_debug_native_continue_syscall(RzDebug *dbg, int pid, int num) { + linux_set_options(dbg, pid); + return rz_debug_ptrace(dbg, PTRACE_SYSCALL, pid, 0, 0); +} + +static void interrupt_process(RzDebug *dbg) { + rz_debug_kill(dbg, dbg->pid, dbg->tid, SIGINT); + rz_cons_break_pop(); +} + +static int rz_debug_native_stop(RzDebug *dbg) { + return linux_stop_threads(dbg, dbg->reason.tid); +} + +static int rz_debug_native_continue(RzDebug *dbg, int pid, int tid, int sig) { + int contsig = dbg->reason.signum; + int ret = -1; + + if (sig != -1) { + contsig = sig; + } + /* SIGINT handler for attached processes: dbg.consbreak (disabled by default) */ + if (dbg->consbreak) { + rz_cons_break_push((RzConsBreak)interrupt_process, dbg); + } + + if (dbg->continue_all_threads && dbg->n_threads && dbg->threads) { + RzDebugPid *th; + RzListIter *it; + rz_list_foreach (dbg->threads, it, th) { + ret = rz_debug_ptrace(dbg, PTRACE_CONT, th->pid, 0, 0); + if (ret) { + eprintf("Error: (%d) is running or dead.\n", th->pid); + } + } + } else { + ret = rz_debug_ptrace(dbg, PTRACE_CONT, tid, NULL, (rz_ptrace_data_t)(size_t)contsig); + if (ret) { + rz_sys_perror("PTRACE_CONT"); + } + } + // return ret >= 0 ? tid : false; + return tid; +} + +static RzDebugInfo *rz_debug_native_info(RzDebug *dbg, const char *arg) { + return linux_info(dbg, arg); +} + +#ifdef WAIT_ON_ALL_CHILDREN +static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { + RzDebugReasonType reason = RZ_DEBUG_REASON_UNKNOWN; + + if (pid == -1) { + eprintf("ERROR: rz_debug_native_wait called with pid -1\n"); + return RZ_DEBUG_REASON_ERROR; + } + int status = -1; + // XXX: this is blocking, ^C will be ignored + int ret = waitpid(-1, &status, WAITPID_FLAGS); + if (ret == -1) { + rz_sys_perror("waitpid"); + return RZ_DEBUG_REASON_ERROR; + } + + // eprintf ("rz_debug_native_wait: status=%d (0x%x) (return=%d)\n", status, status, ret); + + if (ret != pid) { + reason = RZ_DEBUG_REASON_NEW_PID; + eprintf("switching to pid %d\n", ret); + rz_debug_select(dbg, ret, ret); + } + + // TODO: switch status and handle reasons here + // FIXME: Remove linux handling from this function? +#if defined(PT_GETEVENTMSG) + reason = linux_ptrace_event(dbg, pid, status, true); +#endif + + /* propagate errors */ + if (reason == RZ_DEBUG_REASON_ERROR) { + return reason; + } + + /* we don't know what to do yet, let's try harder to figure it out. */ + if (reason == RZ_DEBUG_REASON_UNKNOWN) { + if (WIFEXITED(status)) { + eprintf("child exited with status %d\n", WEXITSTATUS(status)); + reason = RZ_DEBUG_REASON_DEAD; + } else if (WIFSIGNALED(status)) { + eprintf("child received signal %d\n", WTERMSIG(status)); + reason = RZ_DEBUG_REASON_SIGNAL; + } else if (WIFSTOPPED(status)) { + if (WSTOPSIG(status) != SIGTRAP && + WSTOPSIG(status) != SIGSTOP) { + eprintf("Child stopped with signal %d\n", WSTOPSIG(status)); + } + + /* the ptrace documentation says GETSIGINFO is only necessary for + * differentiating the various stops. + * + * this might modify dbg->reason.signum + */ + if (rz_debug_handle_signals(dbg) != 0) { + return RZ_DEBUG_REASON_ERROR; + } + reason = dbg->reason.type; +#ifdef WIFCONTINUED + } else if (WIFCONTINUED(status)) { + eprintf("child continued...\n"); + reason = RZ_DEBUG_REASON_NONE; +#endif + } else if (status == 1) { + /* XXX(jjd): does this actually happen? */ + eprintf("debugger is dead with status 1!\n"); + reason = RZ_DEBUG_REASON_DEAD; + } else if (status == 0) { + /* XXX(jjd): does this actually happen? */ + eprintf("debugger is dead with status 0\n"); + reason = RZ_DEBUG_REASON_DEAD; + } else { + if (ret != pid) { + reason = RZ_DEBUG_REASON_NEW_PID; + } else { + /* ugh. still don't know :-/ */ + eprintf("returning from wait without knowing why...\n"); + } + } + } + + /* if we still don't know what to do, we have a problem... */ + if (reason == RZ_DEBUG_REASON_UNKNOWN) { + eprintf("%s: no idea what happened...\n", __func__); + reason = RZ_DEBUG_REASON_ERROR; + } + dbg->reason.tid = pid; + dbg->reason.type = reason; + return reason; +} +#else +static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { + RzDebugReasonType reason = RZ_DEBUG_REASON_UNKNOWN; + if (pid == -1) { + eprintf("ERROR: rz_debug_native_wait called with pid -1\n"); + return RZ_DEBUG_REASON_ERROR; + } + + reason = linux_dbg_wait(dbg, dbg->tid); + dbg->reason.type = reason; + return reason; +} +#endif + +#undef MAXPID +#define MAXPID 99999 + +static RzList /**/ *rz_debug_native_pids(RzDebug *dbg, int pid) { + RzList *list = rz_list_new(); + if (!list) { + return NULL; + } + return linux_pid_list(pid, list); +} + +RZ_API RZ_OWN RzList /**/ *rz_debug_native_threads(RzDebug *dbg, int pid) { + RzList *list = rz_list_new(); + if (!list) { + eprintf("No list?\n"); + return NULL; + } + return linux_thread_list(dbg, pid, list); +} + +RZ_API ut64 rz_debug_get_tls(RZ_NONNULL RzDebug *dbg, int tid) { + rz_return_val_if_fail(dbg, 0); + return get_linux_tls_val(dbg, tid); +} + +static int rz_debug_native_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { + if (size < 1) { + return false; + } + return linux_reg_read(dbg, type, buf, size); +} + +static int rz_debug_native_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size) { + // XXX use switch or so + if (type == RZ_REG_TYPE_DRX) { + return false; + } else if (type == RZ_REG_TYPE_GPR) { + return linux_reg_write(dbg, type, buf, size); + } else if (type == RZ_REG_TYPE_FPU) { + return linux_reg_write(dbg, type, buf, size); + } // else eprintf ("TODO: reg_write_non-gpr (%d)\n", type); + return false; +} + +static int io_perms_to_prot(int io_perms) { + int prot_perms = PROT_NONE; + + if (io_perms & RZ_PERM_R) { + prot_perms |= PROT_READ; + } + if (io_perms & RZ_PERM_W) { + prot_perms |= PROT_WRITE; + } + if (io_perms & RZ_PERM_X) { + prot_perms |= PROT_EXEC; + } + return prot_perms; +} + +static int sys_thp_mode(void) { + size_t i; + const char *thp[] = { + "/sys/kernel/mm/transparent_hugepage/enabled", + "/sys/kernel/mm/redhat_transparent_hugepage/enabled", + }; + int ret = 0; + + for (i = 0; i < RZ_ARRAY_SIZE(thp); i++) { + char *val = rz_file_slurp(thp[i], NULL); + if (val) { + if (strstr(val, "[madvise]")) { + ret = 1; + } else if (strstr(val, "[always]")) { + ret = 2; + } + free(val); + break; + } + } + + return ret; +} + +static int linux_map_thp(RzDebug *dbg, ut64 addr, int size) { +#if defined(MADV_HUGEPAGE) + RzBuffer *buf = NULL; + char code[1024]; + int ret = true; + char *asm_list[] = { + "x86", "x86.as", + "x64", "x86.as", + NULL + }; + // In architectures where rizin is supported, arm and x86, it is 2MB + const size_t thpsize = 1 << 21; + + if ((size % thpsize)) { + eprintf("size not a power of huge pages size\n"); + return false; + } + // In always mode, is more into mmap syscall level + // even though the address might not have the 'hg' + // vmflags + if (sys_thp_mode() != 1) { + eprintf("transparent huge page mode is not in madvise mode\n"); + return false; + } + + int num = rz_syscall_get_num(dbg->analysis->syscall, "madvise"); + + snprintf(code, sizeof(code), + "sc_madvise@syscall(%d);\n" + "main@naked(0) { .rarg0 = sc_madvise(0x%08" PFMT64x ",%d, %d);break;\n" + "}\n", + num, addr, size, MADV_HUGEPAGE); + rz_egg_reset(dbg->egg); + rz_egg_setup(dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); + rz_egg_load(dbg->egg, code, 0); + if (!rz_egg_compile(dbg->egg)) { + eprintf("Cannot compile.\n"); + goto err_linux_map_thp; + } + if (!rz_egg_assemble_asm(dbg->egg, asm_list)) { + eprintf("rz_egg_assemble: invalid assembly\n"); + goto err_linux_map_thp; + } + buf = rz_egg_get_bin(dbg->egg); + if (buf) { + rz_reg_arena_push(dbg->reg); + ut64 tmpsz; + const ut8 *tmp = rz_buf_data(buf, &tmpsz); + ret = rz_debug_execute(dbg, tmp, tmpsz, 1) == 0; + rz_reg_arena_pop(dbg->reg); + } +err_linux_map_thp: + return ret; +#else + return false; +#endif +} + +static RzDebugMap *linux_map_alloc(RzDebug *dbg, ut64 addr, int size, bool thp) { + RzBuffer *buf = NULL; + RzDebugMap *map = NULL; + char code[1024], *sc_name; + int num; + /* force to usage of x86.as, not yet working x86.nz */ + char *asm_list[] = { + "x86", "x86.as", + "x64", "x86.as", + NULL + }; + + /* NOTE: Since kernel 2.4, that system call has been superseded by + mmap2(2 and nowadays the glibc mmap() wrapper function invokes + mmap2(2)). If arch is x86_32 then usage mmap2() */ + if (!strcmp(dbg->arch, "x86") && dbg->bits == 4) { + sc_name = "mmap2"; + } else { + sc_name = "mmap"; + } + num = rz_syscall_get_num(dbg->analysis->syscall, sc_name); +#ifndef MAP_ANONYMOUS +#define MAP_ANONYMOUS 0x20 +#endif + snprintf(code, sizeof(code), + "sc_mmap@syscall(%d);\n" + "main@naked(0) { .rarg0 = sc_mmap(0x%08" PFMT64x ",%d,%d,%d,%d,%d);break;\n" + "}\n", + num, addr, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + rz_egg_reset(dbg->egg); + rz_egg_setup(dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); + rz_egg_load(dbg->egg, code, 0); + if (!rz_egg_compile(dbg->egg)) { + eprintf("Cannot compile.\n"); + goto err_linux_map_alloc; + } + if (!rz_egg_assemble_asm(dbg->egg, asm_list)) { + eprintf("rz_egg_assemble: invalid assembly\n"); + goto err_linux_map_alloc; + } + buf = rz_egg_get_bin(dbg->egg); + if (buf) { + ut64 map_addr; + + rz_reg_arena_push(dbg->reg); + ut64 tmpsz; + const ut8 *tmp = rz_buf_data(buf, &tmpsz); + map_addr = rz_debug_execute(dbg, tmp, tmpsz, 1); + rz_reg_arena_pop(dbg->reg); + if (map_addr != (ut64)-1) { + if (thp) { + if (!linux_map_thp(dbg, map_addr, size)) { + // Not overly dramatic + eprintf("map promotion to huge page failed\n"); + } + } + rz_debug_map_sync(dbg); + map = rz_debug_map_get(dbg, map_addr); + } + } +err_linux_map_alloc: + return map; +} + +static int linux_map_dealloc(RzDebug *dbg, ut64 addr, int size) { + RzBuffer *buf = NULL; + char code[1024]; + int ret = 0; + char *asm_list[] = { + "x86", "x86.as", + "x64", "x86.as", + NULL + }; + int num = rz_syscall_get_num(dbg->analysis->syscall, "munmap"); + + snprintf(code, sizeof(code), + "sc_munmap@syscall(%d);\n" + "main@naked(0) { .rarg0 = sc_munmap(0x%08" PFMT64x ",%d);break;\n" + "}\n", + num, addr, size); + rz_egg_reset(dbg->egg); + rz_egg_setup(dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); + rz_egg_load(dbg->egg, code, 0); + if (!rz_egg_compile(dbg->egg)) { + eprintf("Cannot compile.\n"); + goto err_linux_map_dealloc; + } + if (!rz_egg_assemble_asm(dbg->egg, asm_list)) { + eprintf("rz_egg_assemble: invalid assembly\n"); + goto err_linux_map_dealloc; + } + buf = rz_egg_get_bin(dbg->egg); + if (buf) { + rz_reg_arena_push(dbg->reg); + ut64 tmpsz; + const ut8 *tmp = rz_buf_data(buf, &tmpsz); + ret = rz_debug_execute(dbg, tmp, tmpsz, 1) == 0; + rz_reg_arena_pop(dbg->reg); + } +err_linux_map_dealloc: + return ret; +} + +static RzDebugMap *rz_debug_native_map_alloc(RzDebug *dbg, ut64 addr, int size, bool thp) { + return linux_map_alloc(dbg, addr, size, thp); +} + +static int rz_debug_native_map_dealloc(RzDebug *dbg, ut64 addr, int size) { + return linux_map_dealloc(dbg, addr, size); +} + +static void _map_free(RzDebugMap *map) { + if (!map) { + return; + } + free(map->name); + free(map->file); + free(map); +} + +static RzList /**/ *rz_debug_native_map_get(RzDebug *dbg) { + RzList *list = NULL; + RzDebugMap *map; + int i, perm, unk = 0; + char *pos_c; + char path[1024], line[1024], name[PROC_NAME_SZ + 1]; + char region[PROC_REGION_SZ + 1], region2[PROC_REGION_SZ + 1], perms[PROC_PERM_SZ + 1]; + FILE *fd; + if (dbg->pid == -1) { + // eprintf ("rz_debug_native_map_get: No selected pid (-1)\n"); + return NULL; + } + /* prepend 0x prefix */ + region[0] = region2[0] = '0'; + region[1] = region2[1] = 'x'; + + snprintf(path, sizeof(path), "/proc/%d/maps", dbg->pid); + + fd = rz_sys_fopen(path, "r"); + if (!fd) { + char *errmsg = rz_str_newf("Cannot open '%s'", path); + perror(errmsg); + free(errmsg); + return NULL; + } + + list = rz_list_new(); + if (!list) { + fclose(fd); + return NULL; + } + list->free = (RzListFree)_map_free; + while (!feof(fd)) { + size_t line_len; + bool map_is_shared = false; + ut64 map_start, map_end; + + if (!fgets(line, sizeof(line), fd)) { + break; + } + /* kill the newline if we got one */ + line_len = strlen(line); + if (line[line_len - 1] == '\n') { + line[line_len - 1] = '\0'; + line_len--; + } + /* maps files should not have empty lines */ + if (line_len == 0) { + break; + } + + ut64 offset = 0; + // 7fc8124c4000-7fc81278d000 r--p 00000000 fc:00 17043921 /usr/lib/locale/locale-archive + i = sscanf(line, "%" RZ_STR_DEF(PROC_REGION_LEFT_SZ) "s %" RZ_STR_DEF(PROC_PERM_SZ) "s %08" PFMT64x " %*s %*s %" RZ_STR_DEF(PROC_NAME_SZ) "[^\n]", ®ion[2], perms, &offset, name); + if (i == 3) { + name[0] = '\0'; + } else if (i != 4) { + eprintf("%s: Unable to parse \"%s\"\n", __func__, path); + eprintf("%s: problematic line: %s\n", __func__, line); + rz_list_free(list); + return NULL; + } + + /* split the region in two */ + pos_c = strchr(®ion[2], '-'); + if (!pos_c) { // should this be an error? + continue; + } + strncpy(®ion2[2], pos_c + 1, sizeof(region2) - 2 - 1); + + if (!*name) { + snprintf(name, sizeof(name), "unk%d", unk++); + } + perm = 0; + for (i = 0; i < 5 && perms[i]; i++) { + switch (perms[i]) { + case 'r': perm |= RZ_PERM_R; break; + case 'w': perm |= RZ_PERM_W; break; + case 'x': perm |= RZ_PERM_X; break; + case 'p': map_is_shared = false; break; + case 's': map_is_shared = true; break; + } + } + + map_start = rz_num_get(NULL, region); + map_end = rz_num_get(NULL, region2); + if (map_start == map_end || map_end == 0) { + eprintf("%s: ignoring invalid map size: %s - %s\n", __func__, region, region2); + continue; + } + map = rz_debug_map_new(name, map_start, map_end, perm, 0); + if (!map) { + break; + } + map->offset = offset; + map->shared = map_is_shared; + map->file = strdup(name); + rz_list_append(list, map); + } + fclose(fd); + return list; +} + +static RzList /**/ *rz_debug_native_modules_get(RzDebug *dbg) { + char *lastname = NULL; + RzDebugMap *map; + RzListIter *iter, *iter2; + RzList *list, *last; + bool must_delete; + if (!(list = rz_debug_native_map_get(dbg))) { + return NULL; + } + if (!(last = rz_list_newf((RzListFree)rz_debug_map_free))) { + rz_list_free(list); + return NULL; + } + rz_list_foreach_safe (list, iter, iter2, map) { + const char *file = map->file; + if (!map->file) { + file = map->file = strdup(map->name); + } + must_delete = true; + if (file && *file == '/') { + if (!lastname || strcmp(lastname, file)) { + must_delete = false; + } + } + if (must_delete) { + rz_list_delete(list, iter); + } else { + rz_list_append(last, map); + free(lastname); + lastname = strdup(file); + } + } + list->free = NULL; + free(lastname); + rz_list_free(list); + return last; +} + +static bool rz_debug_native_kill(RzDebug *dbg, int pid, int tid, int sig) { + bool ret = false; + if (pid == 0) { + pid = dbg->pid; + } + if (sig == SIGKILL && dbg->threads) { + rz_list_free(dbg->threads); + dbg->threads = NULL; + } + if ((rz_sys_kill(pid, sig) != -1)) { + ret = true; + } + if (errno == 1) { + ret = -true; // EPERM + } + return ret; +} + +struct rz_debug_desc_plugin_t rz_debug_desc_plugin_native; +static bool rz_debug_native_init(RzDebug *dbg, void **user) { + dbg->cur->desc = rz_debug_desc_plugin_native; + return true; +} + +static void rz_debug_native_fini(RzDebug *dbg, void *user) { +} + +static int rz_debug_native_drx(RzDebug *dbg, int n, ut64 addr, int sz, int rwx, int g, int api_type) { + eprintf("drx: Unsupported platform\n"); + return -1; +} + +#include +#include + +#define NT_ARM_VFP 0x400 /* ARM VFP/NEON registers */ +#define NT_ARM_TLS 0x401 /* ARM TLS register */ +#define NT_ARM_HW_BREAK 0x402 /* ARM hardware breakpoint registers */ +#define NT_ARM_HW_WATCH 0x403 /* ARM hardware watchpoint registers */ +#define NT_ARM_SYSTEM_CALL 0x404 /* ARM system call number */ + +#ifndef PTRACE_GETHBPREGS +#define PTRACE_GETHBPREGS 29 +#define PTRACE_SETHBPREGS 30 +#endif + +static bool ll_arm32_hwbp_set(pid_t pid, ut64 addr, int size, int wp, int type) { + const unsigned byte_mask = (1 << size) - 1; + // const unsigned type = 2; // Write. + const unsigned enable = 1; + const unsigned control = byte_mask << 5 | type << 3 | enable; + (void)ptrace(PTRACE_SETHBPREGS, pid, -1, (void *)(size_t)addr); + return ptrace(PTRACE_SETHBPREGS, pid, -2, &control) != -1; +} + +#if PTRACE_GETREGSET +// type = 2 = write +// static volatile uint8_t var[96] __attribute__((__aligned__(32))); + +static bool ll_arm64_hwbp_set(pid_t pid, ut64 _addr, int size, int wp, ut32 type) { + const volatile uint8_t *addr = (void *)(size_t)_addr; //&var[32 + wp]; + const unsigned int offset = (uintptr_t)addr % 8; + const ut32 byte_mask = ((1 << size) - 1) << offset; + const ut32 enable = 1; + const ut32 control = byte_mask << 5 | type << 3 | enable; + + struct user_hwdebug_state dreg_state = { 0 }; + struct iovec iov = { 0 }; + iov.iov_base = &dreg_state; + iov.iov_len = sizeof(dreg_state); + + if (ptrace(PTRACE_GETREGSET, pid, NT_ARM_HW_WATCH, &iov) == -1) { + // error reading regs + } + memcpy(&dreg_state, iov.iov_base, sizeof(dreg_state)); + // wp is not honored here i think... we can't have more than one wp for now.. + dreg_state.dbg_regs[0].addr = (uintptr_t)(addr - offset); + dreg_state.dbg_regs[0].ctrl = control; + iov.iov_base = &dreg_state; + iov.iov_len = rz_offsetof(struct user_hwdebug_state, dbg_regs) + + sizeof(dreg_state.dbg_regs[0]); + if (ptrace(PTRACE_SETREGSET, pid, NT_ARM_HW_WATCH, &iov) == 0) { + return true; + } + + if (errno == EIO) { + eprintf("ptrace(PTRACE_SETREGSET, NT_ARM_HW_WATCH) not supported on this hardware: %s\n", + strerror(errno)); + } + + eprintf("ptrace(PTRACE_SETREGSET, NT_ARM_HW_WATCH) failed: %s\n", strerror(errno)); + return false; +} + +static bool ll_arm64_hwbp_del(pid_t pid, ut64 _addr, int size, int wp, ut32 type) { + // const volatile uint8_t *addr = &var[32 + wp]; + // TODO: support multiple watchpoints and find + struct user_hwdebug_state dreg_state = { 0 }; + struct iovec iov = { 0 }; + iov.iov_base = &dreg_state; + // only delete 1 bp for now + iov.iov_len = rz_offsetof(struct user_hwdebug_state, dbg_regs) + + sizeof(dreg_state.dbg_regs[0]); + if (ptrace(PTRACE_SETREGSET, pid, NT_ARM_HW_WATCH, &iov) == 0) { + return true; + } + if (errno == EIO) { + eprintf("ptrace(PTRACE_SETREGSET, NT_ARM_HW_WATCH) not supported on this hardware: %s\n", + strerror(errno)); + } + + eprintf("ptrace(PTRACE_SETREGSET, NT_ARM_HW_WATCH) failed: %s\n", strerror(errno)); + return false; +} + +static bool arm64_hwbp_add(RzDebug *dbg, RzBreakpoint *bp, RzBreakpointItem *b) { + return ll_arm64_hwbp_set(dbg->pid, b->addr, b->size, 0, 1 | 2 | 4); +} + +static bool arm64_hwbp_del(RzDebug *dbg, RzBreakpoint *bp, RzBreakpointItem *b) { + return ll_arm64_hwbp_del(dbg->pid, b->addr, b->size, 0, 1 | 2 | 4); +} + +#endif + +static int rz_debug_native_bp(RzBreakpoint *bp, RzBreakpointItem *b, bool set) { + if (b && b->hw) { + return set + ? arm64_hwbp_add((RzDebug *)bp->user, bp, b) + : arm64_hwbp_del((RzDebug *)bp->user, bp, b); + } + return false; +} + +static RzList /**/ *rz_debug_desc_native_list(int pid) { + return linux_desc_list(pid); +} + +static int rz_debug_native_map_protect(RzDebug *dbg, ut64 addr, int size, int perms) { + RzBuffer *buf = NULL; + char code[1024]; + int num; + + num = rz_syscall_get_num(dbg->analysis->syscall, "mprotect"); + snprintf(code, sizeof(code), + "sc@syscall(%d);\n" + "main@global(0) { sc(%p,%d,%d);\n" + ":int3\n" + "}\n", + num, (void *)(size_t)addr, size, io_perms_to_prot(perms)); + + rz_egg_reset(dbg->egg); + rz_egg_setup(dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); + rz_egg_load(dbg->egg, code, 0); + if (!rz_egg_compile(dbg->egg)) { + eprintf("Cannot compile.\n"); + return false; + } + if (!rz_egg_assemble(dbg->egg)) { + eprintf("rz_egg_assemble: invalid assembly\n"); + return false; + } + buf = rz_egg_get_bin(dbg->egg); + if (buf) { + rz_reg_arena_push(dbg->reg); + ut64 tmpsz; + const ut8 *tmp = rz_buf_data(buf, &tmpsz); + rz_debug_execute(dbg, tmp, tmpsz, 1); + rz_reg_arena_pop(dbg->reg); + return true; + } + + return false; +} + +static int rz_debug_desc_native_open(const char *path) { + return 0; +} + +static bool rz_debug_gcore(RzDebug *dbg, char *path, RzBuffer *dest) { + (void)path; + return linux_generate_corefile(dbg, dest); +} \ No newline at end of file diff --git a/librz/debug/p/linux_x86_64.c b/librz/debug/p/native/linux_x86_64.c similarity index 99% rename from librz/debug/p/linux_x86_64.c rename to librz/debug/p/native/linux_x86_64.c index 925646f534f..b5f5881a38e 100644 --- a/librz/debug/p/linux_x86_64.c +++ b/librz/debug/p/native/linux_x86_64.c @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: 2009-2019 pancake +// SPDX-License-Identifier: LGPL-3.0-only + #include #if !defined(__HAIKU__) && !defined(__sun) #include @@ -6,9 +9,9 @@ #include #include -#include "native/linux/linux_debug.h" -#include "native/procfs.h" -#include "native/linux/linux_coredump.h" +#include "linux/linux_debug.h" +#include "procfs.h" +#include "linux/linux_coredump.h" #ifdef __WALL #define WAITPID_FLAGS __WALL @@ -35,8 +38,6 @@ static char *rz_debug_native_reg_profile(RzDebug *dbg) { return linux_reg_profile(dbg); } -#include "native/reg.c" - static bool rz_debug_native_step(RzDebug *dbg) { return linux_step(dbg); } diff --git a/librz/debug/p/NetBSD.c b/librz/debug/p/native/netbsd.c similarity index 88% rename from librz/debug/p/NetBSD.c rename to librz/debug/p/native/netbsd.c index 85ee6740cb8..942bf7ed53f 100644 --- a/librz/debug/p/NetBSD.c +++ b/librz/debug/p/native/netbsd.c @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: 2009-2019 pancake +// SPDX-License-Identifier: LGPL-3.0-only + #include #if !defined(__HAIKU__) && !defined(__sun) #include @@ -5,8 +8,8 @@ #include #include -#include "native/bsd/bsd_debug.h" -#include "native/procfs.h" +#include "bsd/bsd_debug.h" +#include "procfs.h" #ifdef __WALL #define WAITPID_FLAGS __WALL @@ -23,15 +26,10 @@ #define PROC_UNKSTR_SZ 128 static int rz_debug_handle_signals(RzDebug *dbg) { -#if __KFBSD__ || __NetBSD__ return bsd_handle_signals(dbg); -#else - eprintf("Warning: signal handling is not supported on this platform\n"); - return 0; -#endif } -#include "native/reg.c" +#include "reg.c" static bool rz_debug_native_step(RzDebug *dbg) { int ret = ptrace(PT_STEP, dbg->pid, (caddr_t)1, 0); @@ -102,57 +100,57 @@ static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { } /* we don't know what to do yet, let's try harder to figure it out. */ if (reason == RZ_DEBUG_REASON_UNKNOWN) { - if (WIFEXITED(status)) { - eprintf("child exited with status %d\n", WEXITSTATUS(status)); - reason = RZ_DEBUG_REASON_DEAD; - } else if (WIFSIGNALED(status)) { - eprintf("child received signal %d\n", WTERMSIG(status)); - reason = RZ_DEBUG_REASON_SIGNAL; - } else if (WIFSTOPPED(status)) { - if (WSTOPSIG(status) != SIGTRAP && - WSTOPSIG(status) != SIGSTOP) { - eprintf("Child stopped with signal %d\n", WSTOPSIG(status)); - } + if (WIFEXITED(status)) { + eprintf("child exited with status %d\n", WEXITSTATUS(status)); + reason = RZ_DEBUG_REASON_DEAD; + } else if (WIFSIGNALED(status)) { + eprintf("child received signal %d\n", WTERMSIG(status)); + reason = RZ_DEBUG_REASON_SIGNAL; + } else if (WIFSTOPPED(status)) { + if (WSTOPSIG(status) != SIGTRAP && + WSTOPSIG(status) != SIGSTOP) { + eprintf("Child stopped with signal %d\n", WSTOPSIG(status)); + } - /* the ptrace documentation says GETSIGINFO is only necessary for - * differentiating the various stops. - * - * this might modify dbg->reason.signum - */ + /* the ptrace documentation says GETSIGINFO is only necessary for + * differentiating the various stops. + * + * this might modify dbg->reason.signum + */ if (rz_debug_handle_signals(dbg) != 0) { return RZ_DEBUG_REASON_ERROR; } reason = dbg->reason.type; #ifdef WIFCONTINUED - } else if (WIFCONTINUED(status)) { - eprintf("child continued...\n"); - reason = RZ_DEBUG_REASON_NONE; + } else if (WIFCONTINUED(status)) { + eprintf("child continued...\n"); + reason = RZ_DEBUG_REASON_NONE; #endif - } else if (status == 1) { - /* XXX(jjd): does this actually happen? */ - eprintf("debugger is dead with status 1!\n"); - reason = RZ_DEBUG_REASON_DEAD; - } else if (status == 0) { - /* XXX(jjd): does this actually happen? */ - eprintf("debugger is dead with status 0\n"); - reason = RZ_DEBUG_REASON_DEAD; - } else { - if (ret != pid) { - reason = RZ_DEBUG_REASON_NEW_PID; + } else if (status == 1) { + /* XXX(jjd): does this actually happen? */ + eprintf("debugger is dead with status 1!\n"); + reason = RZ_DEBUG_REASON_DEAD; + } else if (status == 0) { + /* XXX(jjd): does this actually happen? */ + eprintf("debugger is dead with status 0\n"); + reason = RZ_DEBUG_REASON_DEAD; } else { - /* ugh. still don't know :-/ */ - eprintf("returning from wait without knowing why...\n"); + if (ret != pid) { + reason = RZ_DEBUG_REASON_NEW_PID; + } else { + /* ugh. still don't know :-/ */ + eprintf("returning from wait without knowing why...\n"); + } } } -} -/* if we still don't know what to do, we have a problem... */ -if (reason == RZ_DEBUG_REASON_UNKNOWN) { - eprintf("%s: no idea what happened...\n", __func__); - reason = RZ_DEBUG_REASON_ERROR; -} -dbg->reason.tid = pid; -dbg->reason.type = reason; -return reason; + /* if we still don't know what to do, we have a problem... */ + if (reason == RZ_DEBUG_REASON_UNKNOWN) { + eprintf("%s: no idea what happened...\n", __func__); + reason = RZ_DEBUG_REASON_ERROR; + } + dbg->reason.tid = pid; + dbg->reason.type = reason; + return reason; } #undef MAXPID @@ -276,7 +274,6 @@ static RzList /**/ *rz_debug_native_map_get(RzDebug *dbg) { region[0] = region2[0] = '0'; region[1] = region2[1] = 'x'; - snprintf(path, sizeof(path), "/proc/%d/maps", dbg->pid); fd = rz_sys_fopen(path, "r"); diff --git a/librz/debug/p/OpenBSD.c b/librz/debug/p/native/openbsd.c similarity index 87% rename from librz/debug/p/OpenBSD.c rename to librz/debug/p/native/openbsd.c index d03dbf3c2b0..09822877c98 100644 --- a/librz/debug/p/OpenBSD.c +++ b/librz/debug/p/native/openbsd.c @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: 2009-2019 pancake +// SPDX-License-Identifier: LGPL-3.0-only + #include #if !defined(__HAIKU__) && !defined(__sun) #include @@ -5,8 +8,8 @@ #include #include -#include "native/bsd/bsd_debug.h" -#include "native/procfs.h" +#include "bsd/bsd_debug.h" +#include "procfs.h" #ifdef __WALL #define WAITPID_FLAGS __WALL @@ -27,7 +30,7 @@ static int rz_debug_handle_signals(RzDebug *dbg) { return 0; } -#include "native/reg.c" +#include "reg.c" static bool rz_debug_native_step(RzDebug *dbg) { int ret = ptrace(PT_STEP, dbg->pid, (caddr_t)1, 0); @@ -98,54 +101,54 @@ static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { } /* we don't know what to do yet, let's try harder to figure it out. */ if (reason == RZ_DEBUG_REASON_UNKNOWN) { - if (WIFEXITED(status)) { - eprintf("child exited with status %d\n", WEXITSTATUS(status)); - reason = RZ_DEBUG_REASON_DEAD; - } else if (WIFSIGNALED(status)) { - eprintf("child received signal %d\n", WTERMSIG(status)); - reason = RZ_DEBUG_REASON_SIGNAL; - } else if (WIFSTOPPED(status)) { - if (WSTOPSIG(status) != SIGTRAP && - WSTOPSIG(status) != SIGSTOP) { - eprintf("Child stopped with signal %d\n", WSTOPSIG(status)); - } + if (WIFEXITED(status)) { + eprintf("child exited with status %d\n", WEXITSTATUS(status)); + reason = RZ_DEBUG_REASON_DEAD; + } else if (WIFSIGNALED(status)) { + eprintf("child received signal %d\n", WTERMSIG(status)); + reason = RZ_DEBUG_REASON_SIGNAL; + } else if (WIFSTOPPED(status)) { + if (WSTOPSIG(status) != SIGTRAP && + WSTOPSIG(status) != SIGSTOP) { + eprintf("Child stopped with signal %d\n", WSTOPSIG(status)); + } - /* the ptrace documentation says GETSIGINFO is only necessary for - * differentiating the various stops. - * - * this might modify dbg->reason.signum - */ - reason = RZ_DEBUG_REASON_BREAKPOINT; + /* the ptrace documentation says GETSIGINFO is only necessary for + * differentiating the various stops. + * + * this might modify dbg->reason.signum + */ + reason = RZ_DEBUG_REASON_BREAKPOINT; #ifdef WIFCONTINUED - } else if (WIFCONTINUED(status)) { - eprintf("child continued...\n"); - reason = RZ_DEBUG_REASON_NONE; + } else if (WIFCONTINUED(status)) { + eprintf("child continued...\n"); + reason = RZ_DEBUG_REASON_NONE; #endif - } else if (status == 1) { - /* XXX(jjd): does this actually happen? */ - eprintf("debugger is dead with status 1!\n"); - reason = RZ_DEBUG_REASON_DEAD; - } else if (status == 0) { - /* XXX(jjd): does this actually happen? */ - eprintf("debugger is dead with status 0\n"); - reason = RZ_DEBUG_REASON_DEAD; - } else { - if (ret != pid) { - reason = RZ_DEBUG_REASON_NEW_PID; + } else if (status == 1) { + /* XXX(jjd): does this actually happen? */ + eprintf("debugger is dead with status 1!\n"); + reason = RZ_DEBUG_REASON_DEAD; + } else if (status == 0) { + /* XXX(jjd): does this actually happen? */ + eprintf("debugger is dead with status 0\n"); + reason = RZ_DEBUG_REASON_DEAD; } else { - /* ugh. still don't know :-/ */ - eprintf("returning from wait without knowing why...\n"); + if (ret != pid) { + reason = RZ_DEBUG_REASON_NEW_PID; + } else { + /* ugh. still don't know :-/ */ + eprintf("returning from wait without knowing why...\n"); + } } } -} -/* if we still don't know what to do, we have a problem... */ -if (reason == RZ_DEBUG_REASON_UNKNOWN) { - eprintf("%s: no idea what happened...\n", __func__); - reason = RZ_DEBUG_REASON_ERROR; -} -dbg->reason.tid = pid; -dbg->reason.type = reason; -return reason; + /* if we still don't know what to do, we have a problem... */ + if (reason == RZ_DEBUG_REASON_UNKNOWN) { + eprintf("%s: no idea what happened...\n", __func__); + reason = RZ_DEBUG_REASON_ERROR; + } + dbg->reason.tid = pid; + dbg->reason.type = reason; + return reason; } #undef MAXPID @@ -195,7 +198,7 @@ static int bsd_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { RZ_DEBUG_REG_T regs; memset(®s, 0, sizeof(regs)); memset(buf, 0, size); -#warning not implemented for this platform +#warning "not implemented for this platform" ret = 1; // if perror here says 'no such process' and the // process exists still.. is because there's a @@ -517,7 +520,7 @@ static int rz_debug_native_bp(RzBreakpoint *bp, RzBreakpointItem *b, bool set) { } static RzList /**/ *rz_debug_desc_native_list(int pid) { -#warning list filedescriptors not supported for this platform +#warning "list filedescriptors not supported for this platform" return NULL; } diff --git a/librz/debug/p/windows.c b/librz/debug/p/native/windows.c similarity index 98% rename from librz/debug/p/windows.c rename to librz/debug/p/native/windows.c index 4ef577c4f9d..1a77778c7bc 100644 --- a/librz/debug/p/windows.c +++ b/librz/debug/p/native/windows.c @@ -1,4 +1,7 @@ -#include "native/windows/windows_debug.h" +// SPDX-FileCopyrightText: 2009-2019 pancake +// SPDX-License-Identifier: LGPL-3.0-only + +#include "windows/windows_debug.h" // TODO: Move these onto windows.h? RZ_API RzList *rz_w32_dbg_modules(RzDebug *); // ugly! RZ_API RzList *rz_w32_dbg_maps(RzDebug *); @@ -24,7 +27,7 @@ RZ_API RzList *rz_w32_dbg_maps(RzDebug *); #define PROC_PERM_SZ 5 #define PROC_UNKSTR_SZ 128 -#include "native/reg.c" +#include "reg.c" static bool rz_debug_native_step(RzDebug *dbg) { return w32_step(dbg); diff --git a/librz/egg/emit_x86.c b/librz/egg/emit_x86.c index 6924d8a8fb4..5fd83b7917d 100644 --- a/librz/egg/emit_x86.c +++ b/librz/egg/emit_x86.c @@ -170,7 +170,7 @@ static void emit_string(RzEgg *egg, const char *dstvar, const char *str, int j) /* XXX: Hack: Adjust offset in RZ_BP correctly for 64b addresses */ #define BPOFF (RZ_SZ - 4) -#define M32(x) (unsigned int)((x)&0xffffffff) +#define M32(x) (unsigned int)((x) & 0xffffffff) /* XXX: Assumes sizeof(ut32) == 4 */ for (i = 4; i <= oj; i += 4) { /* XXX endian issues (non-portable asm) */ diff --git a/librz/hash/algorithms/sm3/sm3.c b/librz/hash/algorithms/sm3/sm3.c index 81153ddaaf2..1317998bca7 100644 --- a/librz/hash/algorithms/sm3/sm3.c +++ b/librz/hash/algorithms/sm3/sm3.c @@ -182,7 +182,7 @@ static void sm3_process_block(const void *buffer, ut64 len, sm3_ctx_t *ctx) { ctx->total[0] += low_len; ctx->total[1] += (len >> 31 >> 1) + (ctx->total[0] < low_len); -#define rol(x, n) (((x) << ((n)&31)) | ((x) >> ((32 - (n)) & 31))) +#define rol(x, n) (((x) << ((n) & 31)) | ((x) >> ((32 - (n)) & 31))) #define P0(x) ((x) ^ rol(x, 9) ^ rol(x, 17)) #define P1(x) ((x) ^ rol(x, 15) ^ rol(x, 23)) diff --git a/librz/hash/algorithms/ssdeep/fnv_hash.h b/librz/hash/algorithms/ssdeep/fnv_hash.h index 117a66235f0..ce5eaa85545 100644 --- a/librz/hash/algorithms/ssdeep/fnv_hash.h +++ b/librz/hash/algorithms/ssdeep/fnv_hash.h @@ -40,707 +40,4291 @@ #define FNV_B64_00 \ { \ - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \ - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, \ - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, \ - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, \ - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, \ - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, \ - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, \ - 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, \ + 0x00, \ + 0x01, \ + 0x02, \ + 0x03, \ + 0x04, \ + 0x05, \ + 0x06, \ + 0x07, \ + 0x08, \ + 0x09, \ + 0x0a, \ + 0x0b, \ + 0x0c, \ + 0x0d, \ + 0x0e, \ + 0x0f, \ + 0x10, \ + 0x11, \ + 0x12, \ + 0x13, \ + 0x14, \ + 0x15, \ + 0x16, \ + 0x17, \ + 0x18, \ + 0x19, \ + 0x1a, \ + 0x1b, \ + 0x1c, \ + 0x1d, \ + 0x1e, \ + 0x1f, \ + 0x20, \ + 0x21, \ + 0x22, \ + 0x23, \ + 0x24, \ + 0x25, \ + 0x26, \ + 0x27, \ + 0x28, \ + 0x29, \ + 0x2a, \ + 0x2b, \ + 0x2c, \ + 0x2d, \ + 0x2e, \ + 0x2f, \ + 0x30, \ + 0x31, \ + 0x32, \ + 0x33, \ + 0x34, \ + 0x35, \ + 0x36, \ + 0x37, \ + 0x38, \ + 0x39, \ + 0x3a, \ + 0x3b, \ + 0x3c, \ + 0x3d, \ + 0x3e, \ + 0x3f, \ } #define FNV_B64_01 \ { \ - 0x13, 0x12, 0x11, 0x10, 0x17, 0x16, 0x15, 0x14, \ - 0x1b, 0x1a, 0x19, 0x18, 0x1f, 0x1e, 0x1d, 0x1c, \ - 0x03, 0x02, 0x01, 0x00, 0x07, 0x06, 0x05, 0x04, \ - 0x0b, 0x0a, 0x09, 0x08, 0x0f, 0x0e, 0x0d, 0x0c, \ - 0x33, 0x32, 0x31, 0x30, 0x37, 0x36, 0x35, 0x34, \ - 0x3b, 0x3a, 0x39, 0x38, 0x3f, 0x3e, 0x3d, 0x3c, \ - 0x23, 0x22, 0x21, 0x20, 0x27, 0x26, 0x25, 0x24, \ - 0x2b, 0x2a, 0x29, 0x28, 0x2f, 0x2e, 0x2d, 0x2c, \ + 0x13, \ + 0x12, \ + 0x11, \ + 0x10, \ + 0x17, \ + 0x16, \ + 0x15, \ + 0x14, \ + 0x1b, \ + 0x1a, \ + 0x19, \ + 0x18, \ + 0x1f, \ + 0x1e, \ + 0x1d, \ + 0x1c, \ + 0x03, \ + 0x02, \ + 0x01, \ + 0x00, \ + 0x07, \ + 0x06, \ + 0x05, \ + 0x04, \ + 0x0b, \ + 0x0a, \ + 0x09, \ + 0x08, \ + 0x0f, \ + 0x0e, \ + 0x0d, \ + 0x0c, \ + 0x33, \ + 0x32, \ + 0x31, \ + 0x30, \ + 0x37, \ + 0x36, \ + 0x35, \ + 0x34, \ + 0x3b, \ + 0x3a, \ + 0x39, \ + 0x38, \ + 0x3f, \ + 0x3e, \ + 0x3d, \ + 0x3c, \ + 0x23, \ + 0x22, \ + 0x21, \ + 0x20, \ + 0x27, \ + 0x26, \ + 0x25, \ + 0x24, \ + 0x2b, \ + 0x2a, \ + 0x29, \ + 0x28, \ + 0x2f, \ + 0x2e, \ + 0x2d, \ + 0x2c, \ } #define FNV_B64_02 \ { \ - 0x26, 0x27, 0x24, 0x25, 0x22, 0x23, 0x20, 0x21, \ - 0x2e, 0x2f, 0x2c, 0x2d, 0x2a, 0x2b, 0x28, 0x29, \ - 0x36, 0x37, 0x34, 0x35, 0x32, 0x33, 0x30, 0x31, \ - 0x3e, 0x3f, 0x3c, 0x3d, 0x3a, 0x3b, 0x38, 0x39, \ - 0x06, 0x07, 0x04, 0x05, 0x02, 0x03, 0x00, 0x01, \ - 0x0e, 0x0f, 0x0c, 0x0d, 0x0a, 0x0b, 0x08, 0x09, \ - 0x16, 0x17, 0x14, 0x15, 0x12, 0x13, 0x10, 0x11, \ - 0x1e, 0x1f, 0x1c, 0x1d, 0x1a, 0x1b, 0x18, 0x19, \ + 0x26, \ + 0x27, \ + 0x24, \ + 0x25, \ + 0x22, \ + 0x23, \ + 0x20, \ + 0x21, \ + 0x2e, \ + 0x2f, \ + 0x2c, \ + 0x2d, \ + 0x2a, \ + 0x2b, \ + 0x28, \ + 0x29, \ + 0x36, \ + 0x37, \ + 0x34, \ + 0x35, \ + 0x32, \ + 0x33, \ + 0x30, \ + 0x31, \ + 0x3e, \ + 0x3f, \ + 0x3c, \ + 0x3d, \ + 0x3a, \ + 0x3b, \ + 0x38, \ + 0x39, \ + 0x06, \ + 0x07, \ + 0x04, \ + 0x05, \ + 0x02, \ + 0x03, \ + 0x00, \ + 0x01, \ + 0x0e, \ + 0x0f, \ + 0x0c, \ + 0x0d, \ + 0x0a, \ + 0x0b, \ + 0x08, \ + 0x09, \ + 0x16, \ + 0x17, \ + 0x14, \ + 0x15, \ + 0x12, \ + 0x13, \ + 0x10, \ + 0x11, \ + 0x1e, \ + 0x1f, \ + 0x1c, \ + 0x1d, \ + 0x1a, \ + 0x1b, \ + 0x18, \ + 0x19, \ } #define FNV_B64_03 \ { \ - 0x39, 0x38, 0x3b, 0x3a, 0x3d, 0x3c, 0x3f, 0x3e, \ - 0x31, 0x30, 0x33, 0x32, 0x35, 0x34, 0x37, 0x36, \ - 0x29, 0x28, 0x2b, 0x2a, 0x2d, 0x2c, 0x2f, 0x2e, \ - 0x21, 0x20, 0x23, 0x22, 0x25, 0x24, 0x27, 0x26, \ - 0x19, 0x18, 0x1b, 0x1a, 0x1d, 0x1c, 0x1f, 0x1e, \ - 0x11, 0x10, 0x13, 0x12, 0x15, 0x14, 0x17, 0x16, \ - 0x09, 0x08, 0x0b, 0x0a, 0x0d, 0x0c, 0x0f, 0x0e, \ - 0x01, 0x00, 0x03, 0x02, 0x05, 0x04, 0x07, 0x06, \ + 0x39, \ + 0x38, \ + 0x3b, \ + 0x3a, \ + 0x3d, \ + 0x3c, \ + 0x3f, \ + 0x3e, \ + 0x31, \ + 0x30, \ + 0x33, \ + 0x32, \ + 0x35, \ + 0x34, \ + 0x37, \ + 0x36, \ + 0x29, \ + 0x28, \ + 0x2b, \ + 0x2a, \ + 0x2d, \ + 0x2c, \ + 0x2f, \ + 0x2e, \ + 0x21, \ + 0x20, \ + 0x23, \ + 0x22, \ + 0x25, \ + 0x24, \ + 0x27, \ + 0x26, \ + 0x19, \ + 0x18, \ + 0x1b, \ + 0x1a, \ + 0x1d, \ + 0x1c, \ + 0x1f, \ + 0x1e, \ + 0x11, \ + 0x10, \ + 0x13, \ + 0x12, \ + 0x15, \ + 0x14, \ + 0x17, \ + 0x16, \ + 0x09, \ + 0x08, \ + 0x0b, \ + 0x0a, \ + 0x0d, \ + 0x0c, \ + 0x0f, \ + 0x0e, \ + 0x01, \ + 0x00, \ + 0x03, \ + 0x02, \ + 0x05, \ + 0x04, \ + 0x07, \ + 0x06, \ } #define FNV_B64_04 \ { \ - 0x0c, 0x0d, 0x0e, 0x0f, 0x08, 0x09, 0x0a, 0x0b, \ - 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, \ - 0x1c, 0x1d, 0x1e, 0x1f, 0x18, 0x19, 0x1a, 0x1b, \ - 0x14, 0x15, 0x16, 0x17, 0x10, 0x11, 0x12, 0x13, \ - 0x2c, 0x2d, 0x2e, 0x2f, 0x28, 0x29, 0x2a, 0x2b, \ - 0x24, 0x25, 0x26, 0x27, 0x20, 0x21, 0x22, 0x23, \ - 0x3c, 0x3d, 0x3e, 0x3f, 0x38, 0x39, 0x3a, 0x3b, \ - 0x34, 0x35, 0x36, 0x37, 0x30, 0x31, 0x32, 0x33, \ + 0x0c, \ + 0x0d, \ + 0x0e, \ + 0x0f, \ + 0x08, \ + 0x09, \ + 0x0a, \ + 0x0b, \ + 0x04, \ + 0x05, \ + 0x06, \ + 0x07, \ + 0x00, \ + 0x01, \ + 0x02, \ + 0x03, \ + 0x1c, \ + 0x1d, \ + 0x1e, \ + 0x1f, \ + 0x18, \ + 0x19, \ + 0x1a, \ + 0x1b, \ + 0x14, \ + 0x15, \ + 0x16, \ + 0x17, \ + 0x10, \ + 0x11, \ + 0x12, \ + 0x13, \ + 0x2c, \ + 0x2d, \ + 0x2e, \ + 0x2f, \ + 0x28, \ + 0x29, \ + 0x2a, \ + 0x2b, \ + 0x24, \ + 0x25, \ + 0x26, \ + 0x27, \ + 0x20, \ + 0x21, \ + 0x22, \ + 0x23, \ + 0x3c, \ + 0x3d, \ + 0x3e, \ + 0x3f, \ + 0x38, \ + 0x39, \ + 0x3a, \ + 0x3b, \ + 0x34, \ + 0x35, \ + 0x36, \ + 0x37, \ + 0x30, \ + 0x31, \ + 0x32, \ + 0x33, \ } #define FNV_B64_05 \ { \ - 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, \ - 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, \ - 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, \ - 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, \ - 0x3f, 0x3e, 0x3d, 0x3c, 0x3b, 0x3a, 0x39, 0x38, \ - 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x30, \ - 0x2f, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x28, \ - 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x20, \ + 0x1f, \ + 0x1e, \ + 0x1d, \ + 0x1c, \ + 0x1b, \ + 0x1a, \ + 0x19, \ + 0x18, \ + 0x17, \ + 0x16, \ + 0x15, \ + 0x14, \ + 0x13, \ + 0x12, \ + 0x11, \ + 0x10, \ + 0x0f, \ + 0x0e, \ + 0x0d, \ + 0x0c, \ + 0x0b, \ + 0x0a, \ + 0x09, \ + 0x08, \ + 0x07, \ + 0x06, \ + 0x05, \ + 0x04, \ + 0x03, \ + 0x02, \ + 0x01, \ + 0x00, \ + 0x3f, \ + 0x3e, \ + 0x3d, \ + 0x3c, \ + 0x3b, \ + 0x3a, \ + 0x39, \ + 0x38, \ + 0x37, \ + 0x36, \ + 0x35, \ + 0x34, \ + 0x33, \ + 0x32, \ + 0x31, \ + 0x30, \ + 0x2f, \ + 0x2e, \ + 0x2d, \ + 0x2c, \ + 0x2b, \ + 0x2a, \ + 0x29, \ + 0x28, \ + 0x27, \ + 0x26, \ + 0x25, \ + 0x24, \ + 0x23, \ + 0x22, \ + 0x21, \ + 0x20, \ } #define FNV_B64_06 \ { \ - 0x32, 0x33, 0x30, 0x31, 0x36, 0x37, 0x34, 0x35, \ - 0x3a, 0x3b, 0x38, 0x39, 0x3e, 0x3f, 0x3c, 0x3d, \ - 0x22, 0x23, 0x20, 0x21, 0x26, 0x27, 0x24, 0x25, \ - 0x2a, 0x2b, 0x28, 0x29, 0x2e, 0x2f, 0x2c, 0x2d, \ - 0x12, 0x13, 0x10, 0x11, 0x16, 0x17, 0x14, 0x15, \ - 0x1a, 0x1b, 0x18, 0x19, 0x1e, 0x1f, 0x1c, 0x1d, \ - 0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05, \ - 0x0a, 0x0b, 0x08, 0x09, 0x0e, 0x0f, 0x0c, 0x0d, \ + 0x32, \ + 0x33, \ + 0x30, \ + 0x31, \ + 0x36, \ + 0x37, \ + 0x34, \ + 0x35, \ + 0x3a, \ + 0x3b, \ + 0x38, \ + 0x39, \ + 0x3e, \ + 0x3f, \ + 0x3c, \ + 0x3d, \ + 0x22, \ + 0x23, \ + 0x20, \ + 0x21, \ + 0x26, \ + 0x27, \ + 0x24, \ + 0x25, \ + 0x2a, \ + 0x2b, \ + 0x28, \ + 0x29, \ + 0x2e, \ + 0x2f, \ + 0x2c, \ + 0x2d, \ + 0x12, \ + 0x13, \ + 0x10, \ + 0x11, \ + 0x16, \ + 0x17, \ + 0x14, \ + 0x15, \ + 0x1a, \ + 0x1b, \ + 0x18, \ + 0x19, \ + 0x1e, \ + 0x1f, \ + 0x1c, \ + 0x1d, \ + 0x02, \ + 0x03, \ + 0x00, \ + 0x01, \ + 0x06, \ + 0x07, \ + 0x04, \ + 0x05, \ + 0x0a, \ + 0x0b, \ + 0x08, \ + 0x09, \ + 0x0e, \ + 0x0f, \ + 0x0c, \ + 0x0d, \ } #define FNV_B64_07 \ { \ - 0x05, 0x04, 0x07, 0x06, 0x01, 0x00, 0x03, 0x02, \ - 0x0d, 0x0c, 0x0f, 0x0e, 0x09, 0x08, 0x0b, 0x0a, \ - 0x15, 0x14, 0x17, 0x16, 0x11, 0x10, 0x13, 0x12, \ - 0x1d, 0x1c, 0x1f, 0x1e, 0x19, 0x18, 0x1b, 0x1a, \ - 0x25, 0x24, 0x27, 0x26, 0x21, 0x20, 0x23, 0x22, \ - 0x2d, 0x2c, 0x2f, 0x2e, 0x29, 0x28, 0x2b, 0x2a, \ - 0x35, 0x34, 0x37, 0x36, 0x31, 0x30, 0x33, 0x32, \ - 0x3d, 0x3c, 0x3f, 0x3e, 0x39, 0x38, 0x3b, 0x3a, \ + 0x05, \ + 0x04, \ + 0x07, \ + 0x06, \ + 0x01, \ + 0x00, \ + 0x03, \ + 0x02, \ + 0x0d, \ + 0x0c, \ + 0x0f, \ + 0x0e, \ + 0x09, \ + 0x08, \ + 0x0b, \ + 0x0a, \ + 0x15, \ + 0x14, \ + 0x17, \ + 0x16, \ + 0x11, \ + 0x10, \ + 0x13, \ + 0x12, \ + 0x1d, \ + 0x1c, \ + 0x1f, \ + 0x1e, \ + 0x19, \ + 0x18, \ + 0x1b, \ + 0x1a, \ + 0x25, \ + 0x24, \ + 0x27, \ + 0x26, \ + 0x21, \ + 0x20, \ + 0x23, \ + 0x22, \ + 0x2d, \ + 0x2c, \ + 0x2f, \ + 0x2e, \ + 0x29, \ + 0x28, \ + 0x2b, \ + 0x2a, \ + 0x35, \ + 0x34, \ + 0x37, \ + 0x36, \ + 0x31, \ + 0x30, \ + 0x33, \ + 0x32, \ + 0x3d, \ + 0x3c, \ + 0x3f, \ + 0x3e, \ + 0x39, \ + 0x38, \ + 0x3b, \ + 0x3a, \ } #define FNV_B64_08 \ { \ - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, \ - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, \ - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, \ - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \ - 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, \ - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, \ - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, \ - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, \ + 0x18, \ + 0x19, \ + 0x1a, \ + 0x1b, \ + 0x1c, \ + 0x1d, \ + 0x1e, \ + 0x1f, \ + 0x10, \ + 0x11, \ + 0x12, \ + 0x13, \ + 0x14, \ + 0x15, \ + 0x16, \ + 0x17, \ + 0x08, \ + 0x09, \ + 0x0a, \ + 0x0b, \ + 0x0c, \ + 0x0d, \ + 0x0e, \ + 0x0f, \ + 0x00, \ + 0x01, \ + 0x02, \ + 0x03, \ + 0x04, \ + 0x05, \ + 0x06, \ + 0x07, \ + 0x38, \ + 0x39, \ + 0x3a, \ + 0x3b, \ + 0x3c, \ + 0x3d, \ + 0x3e, \ + 0x3f, \ + 0x30, \ + 0x31, \ + 0x32, \ + 0x33, \ + 0x34, \ + 0x35, \ + 0x36, \ + 0x37, \ + 0x28, \ + 0x29, \ + 0x2a, \ + 0x2b, \ + 0x2c, \ + 0x2d, \ + 0x2e, \ + 0x2f, \ + 0x20, \ + 0x21, \ + 0x22, \ + 0x23, \ + 0x24, \ + 0x25, \ + 0x26, \ + 0x27, \ } #define FNV_B64_09 \ { \ - 0x2b, 0x2a, 0x29, 0x28, 0x2f, 0x2e, 0x2d, 0x2c, \ - 0x23, 0x22, 0x21, 0x20, 0x27, 0x26, 0x25, 0x24, \ - 0x3b, 0x3a, 0x39, 0x38, 0x3f, 0x3e, 0x3d, 0x3c, \ - 0x33, 0x32, 0x31, 0x30, 0x37, 0x36, 0x35, 0x34, \ - 0x0b, 0x0a, 0x09, 0x08, 0x0f, 0x0e, 0x0d, 0x0c, \ - 0x03, 0x02, 0x01, 0x00, 0x07, 0x06, 0x05, 0x04, \ - 0x1b, 0x1a, 0x19, 0x18, 0x1f, 0x1e, 0x1d, 0x1c, \ - 0x13, 0x12, 0x11, 0x10, 0x17, 0x16, 0x15, 0x14, \ + 0x2b, \ + 0x2a, \ + 0x29, \ + 0x28, \ + 0x2f, \ + 0x2e, \ + 0x2d, \ + 0x2c, \ + 0x23, \ + 0x22, \ + 0x21, \ + 0x20, \ + 0x27, \ + 0x26, \ + 0x25, \ + 0x24, \ + 0x3b, \ + 0x3a, \ + 0x39, \ + 0x38, \ + 0x3f, \ + 0x3e, \ + 0x3d, \ + 0x3c, \ + 0x33, \ + 0x32, \ + 0x31, \ + 0x30, \ + 0x37, \ + 0x36, \ + 0x35, \ + 0x34, \ + 0x0b, \ + 0x0a, \ + 0x09, \ + 0x08, \ + 0x0f, \ + 0x0e, \ + 0x0d, \ + 0x0c, \ + 0x03, \ + 0x02, \ + 0x01, \ + 0x00, \ + 0x07, \ + 0x06, \ + 0x05, \ + 0x04, \ + 0x1b, \ + 0x1a, \ + 0x19, \ + 0x18, \ + 0x1f, \ + 0x1e, \ + 0x1d, \ + 0x1c, \ + 0x13, \ + 0x12, \ + 0x11, \ + 0x10, \ + 0x17, \ + 0x16, \ + 0x15, \ + 0x14, \ } #define FNV_B64_0A \ { \ - 0x3e, 0x3f, 0x3c, 0x3d, 0x3a, 0x3b, 0x38, 0x39, \ - 0x36, 0x37, 0x34, 0x35, 0x32, 0x33, 0x30, 0x31, \ - 0x2e, 0x2f, 0x2c, 0x2d, 0x2a, 0x2b, 0x28, 0x29, \ - 0x26, 0x27, 0x24, 0x25, 0x22, 0x23, 0x20, 0x21, \ - 0x1e, 0x1f, 0x1c, 0x1d, 0x1a, 0x1b, 0x18, 0x19, \ - 0x16, 0x17, 0x14, 0x15, 0x12, 0x13, 0x10, 0x11, \ - 0x0e, 0x0f, 0x0c, 0x0d, 0x0a, 0x0b, 0x08, 0x09, \ - 0x06, 0x07, 0x04, 0x05, 0x02, 0x03, 0x00, 0x01, \ + 0x3e, \ + 0x3f, \ + 0x3c, \ + 0x3d, \ + 0x3a, \ + 0x3b, \ + 0x38, \ + 0x39, \ + 0x36, \ + 0x37, \ + 0x34, \ + 0x35, \ + 0x32, \ + 0x33, \ + 0x30, \ + 0x31, \ + 0x2e, \ + 0x2f, \ + 0x2c, \ + 0x2d, \ + 0x2a, \ + 0x2b, \ + 0x28, \ + 0x29, \ + 0x26, \ + 0x27, \ + 0x24, \ + 0x25, \ + 0x22, \ + 0x23, \ + 0x20, \ + 0x21, \ + 0x1e, \ + 0x1f, \ + 0x1c, \ + 0x1d, \ + 0x1a, \ + 0x1b, \ + 0x18, \ + 0x19, \ + 0x16, \ + 0x17, \ + 0x14, \ + 0x15, \ + 0x12, \ + 0x13, \ + 0x10, \ + 0x11, \ + 0x0e, \ + 0x0f, \ + 0x0c, \ + 0x0d, \ + 0x0a, \ + 0x0b, \ + 0x08, \ + 0x09, \ + 0x06, \ + 0x07, \ + 0x04, \ + 0x05, \ + 0x02, \ + 0x03, \ + 0x00, \ + 0x01, \ } #define FNV_B64_0B \ { \ - 0x11, 0x10, 0x13, 0x12, 0x15, 0x14, 0x17, 0x16, \ - 0x19, 0x18, 0x1b, 0x1a, 0x1d, 0x1c, 0x1f, 0x1e, \ - 0x01, 0x00, 0x03, 0x02, 0x05, 0x04, 0x07, 0x06, \ - 0x09, 0x08, 0x0b, 0x0a, 0x0d, 0x0c, 0x0f, 0x0e, \ - 0x31, 0x30, 0x33, 0x32, 0x35, 0x34, 0x37, 0x36, \ - 0x39, 0x38, 0x3b, 0x3a, 0x3d, 0x3c, 0x3f, 0x3e, \ - 0x21, 0x20, 0x23, 0x22, 0x25, 0x24, 0x27, 0x26, \ - 0x29, 0x28, 0x2b, 0x2a, 0x2d, 0x2c, 0x2f, 0x2e, \ + 0x11, \ + 0x10, \ + 0x13, \ + 0x12, \ + 0x15, \ + 0x14, \ + 0x17, \ + 0x16, \ + 0x19, \ + 0x18, \ + 0x1b, \ + 0x1a, \ + 0x1d, \ + 0x1c, \ + 0x1f, \ + 0x1e, \ + 0x01, \ + 0x00, \ + 0x03, \ + 0x02, \ + 0x05, \ + 0x04, \ + 0x07, \ + 0x06, \ + 0x09, \ + 0x08, \ + 0x0b, \ + 0x0a, \ + 0x0d, \ + 0x0c, \ + 0x0f, \ + 0x0e, \ + 0x31, \ + 0x30, \ + 0x33, \ + 0x32, \ + 0x35, \ + 0x34, \ + 0x37, \ + 0x36, \ + 0x39, \ + 0x38, \ + 0x3b, \ + 0x3a, \ + 0x3d, \ + 0x3c, \ + 0x3f, \ + 0x3e, \ + 0x21, \ + 0x20, \ + 0x23, \ + 0x22, \ + 0x25, \ + 0x24, \ + 0x27, \ + 0x26, \ + 0x29, \ + 0x28, \ + 0x2b, \ + 0x2a, \ + 0x2d, \ + 0x2c, \ + 0x2f, \ + 0x2e, \ } #define FNV_B64_0C \ { \ - 0x24, 0x25, 0x26, 0x27, 0x20, 0x21, 0x22, 0x23, \ - 0x2c, 0x2d, 0x2e, 0x2f, 0x28, 0x29, 0x2a, 0x2b, \ - 0x34, 0x35, 0x36, 0x37, 0x30, 0x31, 0x32, 0x33, \ - 0x3c, 0x3d, 0x3e, 0x3f, 0x38, 0x39, 0x3a, 0x3b, \ - 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, \ - 0x0c, 0x0d, 0x0e, 0x0f, 0x08, 0x09, 0x0a, 0x0b, \ - 0x14, 0x15, 0x16, 0x17, 0x10, 0x11, 0x12, 0x13, \ - 0x1c, 0x1d, 0x1e, 0x1f, 0x18, 0x19, 0x1a, 0x1b, \ + 0x24, \ + 0x25, \ + 0x26, \ + 0x27, \ + 0x20, \ + 0x21, \ + 0x22, \ + 0x23, \ + 0x2c, \ + 0x2d, \ + 0x2e, \ + 0x2f, \ + 0x28, \ + 0x29, \ + 0x2a, \ + 0x2b, \ + 0x34, \ + 0x35, \ + 0x36, \ + 0x37, \ + 0x30, \ + 0x31, \ + 0x32, \ + 0x33, \ + 0x3c, \ + 0x3d, \ + 0x3e, \ + 0x3f, \ + 0x38, \ + 0x39, \ + 0x3a, \ + 0x3b, \ + 0x04, \ + 0x05, \ + 0x06, \ + 0x07, \ + 0x00, \ + 0x01, \ + 0x02, \ + 0x03, \ + 0x0c, \ + 0x0d, \ + 0x0e, \ + 0x0f, \ + 0x08, \ + 0x09, \ + 0x0a, \ + 0x0b, \ + 0x14, \ + 0x15, \ + 0x16, \ + 0x17, \ + 0x10, \ + 0x11, \ + 0x12, \ + 0x13, \ + 0x1c, \ + 0x1d, \ + 0x1e, \ + 0x1f, \ + 0x18, \ + 0x19, \ + 0x1a, \ + 0x1b, \ } #define FNV_B64_0D \ { \ - 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x30, \ - 0x3f, 0x3e, 0x3d, 0x3c, 0x3b, 0x3a, 0x39, 0x38, \ - 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x20, \ - 0x2f, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x28, \ - 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, \ - 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, \ - 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, \ - 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, \ + 0x37, \ + 0x36, \ + 0x35, \ + 0x34, \ + 0x33, \ + 0x32, \ + 0x31, \ + 0x30, \ + 0x3f, \ + 0x3e, \ + 0x3d, \ + 0x3c, \ + 0x3b, \ + 0x3a, \ + 0x39, \ + 0x38, \ + 0x27, \ + 0x26, \ + 0x25, \ + 0x24, \ + 0x23, \ + 0x22, \ + 0x21, \ + 0x20, \ + 0x2f, \ + 0x2e, \ + 0x2d, \ + 0x2c, \ + 0x2b, \ + 0x2a, \ + 0x29, \ + 0x28, \ + 0x17, \ + 0x16, \ + 0x15, \ + 0x14, \ + 0x13, \ + 0x12, \ + 0x11, \ + 0x10, \ + 0x1f, \ + 0x1e, \ + 0x1d, \ + 0x1c, \ + 0x1b, \ + 0x1a, \ + 0x19, \ + 0x18, \ + 0x07, \ + 0x06, \ + 0x05, \ + 0x04, \ + 0x03, \ + 0x02, \ + 0x01, \ + 0x00, \ + 0x0f, \ + 0x0e, \ + 0x0d, \ + 0x0c, \ + 0x0b, \ + 0x0a, \ + 0x09, \ + 0x08, \ } #define FNV_B64_0E \ { \ - 0x0a, 0x0b, 0x08, 0x09, 0x0e, 0x0f, 0x0c, 0x0d, \ - 0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05, \ - 0x1a, 0x1b, 0x18, 0x19, 0x1e, 0x1f, 0x1c, 0x1d, \ - 0x12, 0x13, 0x10, 0x11, 0x16, 0x17, 0x14, 0x15, \ - 0x2a, 0x2b, 0x28, 0x29, 0x2e, 0x2f, 0x2c, 0x2d, \ - 0x22, 0x23, 0x20, 0x21, 0x26, 0x27, 0x24, 0x25, \ - 0x3a, 0x3b, 0x38, 0x39, 0x3e, 0x3f, 0x3c, 0x3d, \ - 0x32, 0x33, 0x30, 0x31, 0x36, 0x37, 0x34, 0x35, \ + 0x0a, \ + 0x0b, \ + 0x08, \ + 0x09, \ + 0x0e, \ + 0x0f, \ + 0x0c, \ + 0x0d, \ + 0x02, \ + 0x03, \ + 0x00, \ + 0x01, \ + 0x06, \ + 0x07, \ + 0x04, \ + 0x05, \ + 0x1a, \ + 0x1b, \ + 0x18, \ + 0x19, \ + 0x1e, \ + 0x1f, \ + 0x1c, \ + 0x1d, \ + 0x12, \ + 0x13, \ + 0x10, \ + 0x11, \ + 0x16, \ + 0x17, \ + 0x14, \ + 0x15, \ + 0x2a, \ + 0x2b, \ + 0x28, \ + 0x29, \ + 0x2e, \ + 0x2f, \ + 0x2c, \ + 0x2d, \ + 0x22, \ + 0x23, \ + 0x20, \ + 0x21, \ + 0x26, \ + 0x27, \ + 0x24, \ + 0x25, \ + 0x3a, \ + 0x3b, \ + 0x38, \ + 0x39, \ + 0x3e, \ + 0x3f, \ + 0x3c, \ + 0x3d, \ + 0x32, \ + 0x33, \ + 0x30, \ + 0x31, \ + 0x36, \ + 0x37, \ + 0x34, \ + 0x35, \ } #define FNV_B64_0F \ { \ - 0x1d, 0x1c, 0x1f, 0x1e, 0x19, 0x18, 0x1b, 0x1a, \ - 0x15, 0x14, 0x17, 0x16, 0x11, 0x10, 0x13, 0x12, \ - 0x0d, 0x0c, 0x0f, 0x0e, 0x09, 0x08, 0x0b, 0x0a, \ - 0x05, 0x04, 0x07, 0x06, 0x01, 0x00, 0x03, 0x02, \ - 0x3d, 0x3c, 0x3f, 0x3e, 0x39, 0x38, 0x3b, 0x3a, \ - 0x35, 0x34, 0x37, 0x36, 0x31, 0x30, 0x33, 0x32, \ - 0x2d, 0x2c, 0x2f, 0x2e, 0x29, 0x28, 0x2b, 0x2a, \ - 0x25, 0x24, 0x27, 0x26, 0x21, 0x20, 0x23, 0x22, \ + 0x1d, \ + 0x1c, \ + 0x1f, \ + 0x1e, \ + 0x19, \ + 0x18, \ + 0x1b, \ + 0x1a, \ + 0x15, \ + 0x14, \ + 0x17, \ + 0x16, \ + 0x11, \ + 0x10, \ + 0x13, \ + 0x12, \ + 0x0d, \ + 0x0c, \ + 0x0f, \ + 0x0e, \ + 0x09, \ + 0x08, \ + 0x0b, \ + 0x0a, \ + 0x05, \ + 0x04, \ + 0x07, \ + 0x06, \ + 0x01, \ + 0x00, \ + 0x03, \ + 0x02, \ + 0x3d, \ + 0x3c, \ + 0x3f, \ + 0x3e, \ + 0x39, \ + 0x38, \ + 0x3b, \ + 0x3a, \ + 0x35, \ + 0x34, \ + 0x37, \ + 0x36, \ + 0x31, \ + 0x30, \ + 0x33, \ + 0x32, \ + 0x2d, \ + 0x2c, \ + 0x2f, \ + 0x2e, \ + 0x29, \ + 0x28, \ + 0x2b, \ + 0x2a, \ + 0x25, \ + 0x24, \ + 0x27, \ + 0x26, \ + 0x21, \ + 0x20, \ + 0x23, \ + 0x22, \ } #define FNV_B64_10 \ { \ - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, \ - 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, \ - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, \ - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, \ - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, \ - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, \ - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \ - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, \ + 0x30, \ + 0x31, \ + 0x32, \ + 0x33, \ + 0x34, \ + 0x35, \ + 0x36, \ + 0x37, \ + 0x38, \ + 0x39, \ + 0x3a, \ + 0x3b, \ + 0x3c, \ + 0x3d, \ + 0x3e, \ + 0x3f, \ + 0x20, \ + 0x21, \ + 0x22, \ + 0x23, \ + 0x24, \ + 0x25, \ + 0x26, \ + 0x27, \ + 0x28, \ + 0x29, \ + 0x2a, \ + 0x2b, \ + 0x2c, \ + 0x2d, \ + 0x2e, \ + 0x2f, \ + 0x10, \ + 0x11, \ + 0x12, \ + 0x13, \ + 0x14, \ + 0x15, \ + 0x16, \ + 0x17, \ + 0x18, \ + 0x19, \ + 0x1a, \ + 0x1b, \ + 0x1c, \ + 0x1d, \ + 0x1e, \ + 0x1f, \ + 0x00, \ + 0x01, \ + 0x02, \ + 0x03, \ + 0x04, \ + 0x05, \ + 0x06, \ + 0x07, \ + 0x08, \ + 0x09, \ + 0x0a, \ + 0x0b, \ + 0x0c, \ + 0x0d, \ + 0x0e, \ + 0x0f, \ } #define FNV_B64_11 \ { \ - 0x03, 0x02, 0x01, 0x00, 0x07, 0x06, 0x05, 0x04, \ - 0x0b, 0x0a, 0x09, 0x08, 0x0f, 0x0e, 0x0d, 0x0c, \ - 0x13, 0x12, 0x11, 0x10, 0x17, 0x16, 0x15, 0x14, \ - 0x1b, 0x1a, 0x19, 0x18, 0x1f, 0x1e, 0x1d, 0x1c, \ - 0x23, 0x22, 0x21, 0x20, 0x27, 0x26, 0x25, 0x24, \ - 0x2b, 0x2a, 0x29, 0x28, 0x2f, 0x2e, 0x2d, 0x2c, \ - 0x33, 0x32, 0x31, 0x30, 0x37, 0x36, 0x35, 0x34, \ - 0x3b, 0x3a, 0x39, 0x38, 0x3f, 0x3e, 0x3d, 0x3c, \ + 0x03, \ + 0x02, \ + 0x01, \ + 0x00, \ + 0x07, \ + 0x06, \ + 0x05, \ + 0x04, \ + 0x0b, \ + 0x0a, \ + 0x09, \ + 0x08, \ + 0x0f, \ + 0x0e, \ + 0x0d, \ + 0x0c, \ + 0x13, \ + 0x12, \ + 0x11, \ + 0x10, \ + 0x17, \ + 0x16, \ + 0x15, \ + 0x14, \ + 0x1b, \ + 0x1a, \ + 0x19, \ + 0x18, \ + 0x1f, \ + 0x1e, \ + 0x1d, \ + 0x1c, \ + 0x23, \ + 0x22, \ + 0x21, \ + 0x20, \ + 0x27, \ + 0x26, \ + 0x25, \ + 0x24, \ + 0x2b, \ + 0x2a, \ + 0x29, \ + 0x28, \ + 0x2f, \ + 0x2e, \ + 0x2d, \ + 0x2c, \ + 0x33, \ + 0x32, \ + 0x31, \ + 0x30, \ + 0x37, \ + 0x36, \ + 0x35, \ + 0x34, \ + 0x3b, \ + 0x3a, \ + 0x39, \ + 0x38, \ + 0x3f, \ + 0x3e, \ + 0x3d, \ + 0x3c, \ } #define FNV_B64_12 \ { \ - 0x16, 0x17, 0x14, 0x15, 0x12, 0x13, 0x10, 0x11, \ - 0x1e, 0x1f, 0x1c, 0x1d, 0x1a, 0x1b, 0x18, 0x19, \ - 0x06, 0x07, 0x04, 0x05, 0x02, 0x03, 0x00, 0x01, \ - 0x0e, 0x0f, 0x0c, 0x0d, 0x0a, 0x0b, 0x08, 0x09, \ - 0x36, 0x37, 0x34, 0x35, 0x32, 0x33, 0x30, 0x31, \ - 0x3e, 0x3f, 0x3c, 0x3d, 0x3a, 0x3b, 0x38, 0x39, \ - 0x26, 0x27, 0x24, 0x25, 0x22, 0x23, 0x20, 0x21, \ - 0x2e, 0x2f, 0x2c, 0x2d, 0x2a, 0x2b, 0x28, 0x29, \ + 0x16, \ + 0x17, \ + 0x14, \ + 0x15, \ + 0x12, \ + 0x13, \ + 0x10, \ + 0x11, \ + 0x1e, \ + 0x1f, \ + 0x1c, \ + 0x1d, \ + 0x1a, \ + 0x1b, \ + 0x18, \ + 0x19, \ + 0x06, \ + 0x07, \ + 0x04, \ + 0x05, \ + 0x02, \ + 0x03, \ + 0x00, \ + 0x01, \ + 0x0e, \ + 0x0f, \ + 0x0c, \ + 0x0d, \ + 0x0a, \ + 0x0b, \ + 0x08, \ + 0x09, \ + 0x36, \ + 0x37, \ + 0x34, \ + 0x35, \ + 0x32, \ + 0x33, \ + 0x30, \ + 0x31, \ + 0x3e, \ + 0x3f, \ + 0x3c, \ + 0x3d, \ + 0x3a, \ + 0x3b, \ + 0x38, \ + 0x39, \ + 0x26, \ + 0x27, \ + 0x24, \ + 0x25, \ + 0x22, \ + 0x23, \ + 0x20, \ + 0x21, \ + 0x2e, \ + 0x2f, \ + 0x2c, \ + 0x2d, \ + 0x2a, \ + 0x2b, \ + 0x28, \ + 0x29, \ } #define FNV_B64_13 \ { \ - 0x29, 0x28, 0x2b, 0x2a, 0x2d, 0x2c, 0x2f, 0x2e, \ - 0x21, 0x20, 0x23, 0x22, 0x25, 0x24, 0x27, 0x26, \ - 0x39, 0x38, 0x3b, 0x3a, 0x3d, 0x3c, 0x3f, 0x3e, \ - 0x31, 0x30, 0x33, 0x32, 0x35, 0x34, 0x37, 0x36, \ - 0x09, 0x08, 0x0b, 0x0a, 0x0d, 0x0c, 0x0f, 0x0e, \ - 0x01, 0x00, 0x03, 0x02, 0x05, 0x04, 0x07, 0x06, \ - 0x19, 0x18, 0x1b, 0x1a, 0x1d, 0x1c, 0x1f, 0x1e, \ - 0x11, 0x10, 0x13, 0x12, 0x15, 0x14, 0x17, 0x16, \ + 0x29, \ + 0x28, \ + 0x2b, \ + 0x2a, \ + 0x2d, \ + 0x2c, \ + 0x2f, \ + 0x2e, \ + 0x21, \ + 0x20, \ + 0x23, \ + 0x22, \ + 0x25, \ + 0x24, \ + 0x27, \ + 0x26, \ + 0x39, \ + 0x38, \ + 0x3b, \ + 0x3a, \ + 0x3d, \ + 0x3c, \ + 0x3f, \ + 0x3e, \ + 0x31, \ + 0x30, \ + 0x33, \ + 0x32, \ + 0x35, \ + 0x34, \ + 0x37, \ + 0x36, \ + 0x09, \ + 0x08, \ + 0x0b, \ + 0x0a, \ + 0x0d, \ + 0x0c, \ + 0x0f, \ + 0x0e, \ + 0x01, \ + 0x00, \ + 0x03, \ + 0x02, \ + 0x05, \ + 0x04, \ + 0x07, \ + 0x06, \ + 0x19, \ + 0x18, \ + 0x1b, \ + 0x1a, \ + 0x1d, \ + 0x1c, \ + 0x1f, \ + 0x1e, \ + 0x11, \ + 0x10, \ + 0x13, \ + 0x12, \ + 0x15, \ + 0x14, \ + 0x17, \ + 0x16, \ } #define FNV_B64_14 \ { \ - 0x3c, 0x3d, 0x3e, 0x3f, 0x38, 0x39, 0x3a, 0x3b, \ - 0x34, 0x35, 0x36, 0x37, 0x30, 0x31, 0x32, 0x33, \ - 0x2c, 0x2d, 0x2e, 0x2f, 0x28, 0x29, 0x2a, 0x2b, \ - 0x24, 0x25, 0x26, 0x27, 0x20, 0x21, 0x22, 0x23, \ - 0x1c, 0x1d, 0x1e, 0x1f, 0x18, 0x19, 0x1a, 0x1b, \ - 0x14, 0x15, 0x16, 0x17, 0x10, 0x11, 0x12, 0x13, \ - 0x0c, 0x0d, 0x0e, 0x0f, 0x08, 0x09, 0x0a, 0x0b, \ - 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, \ + 0x3c, \ + 0x3d, \ + 0x3e, \ + 0x3f, \ + 0x38, \ + 0x39, \ + 0x3a, \ + 0x3b, \ + 0x34, \ + 0x35, \ + 0x36, \ + 0x37, \ + 0x30, \ + 0x31, \ + 0x32, \ + 0x33, \ + 0x2c, \ + 0x2d, \ + 0x2e, \ + 0x2f, \ + 0x28, \ + 0x29, \ + 0x2a, \ + 0x2b, \ + 0x24, \ + 0x25, \ + 0x26, \ + 0x27, \ + 0x20, \ + 0x21, \ + 0x22, \ + 0x23, \ + 0x1c, \ + 0x1d, \ + 0x1e, \ + 0x1f, \ + 0x18, \ + 0x19, \ + 0x1a, \ + 0x1b, \ + 0x14, \ + 0x15, \ + 0x16, \ + 0x17, \ + 0x10, \ + 0x11, \ + 0x12, \ + 0x13, \ + 0x0c, \ + 0x0d, \ + 0x0e, \ + 0x0f, \ + 0x08, \ + 0x09, \ + 0x0a, \ + 0x0b, \ + 0x04, \ + 0x05, \ + 0x06, \ + 0x07, \ + 0x00, \ + 0x01, \ + 0x02, \ + 0x03, \ } #define FNV_B64_15 \ { \ - 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, \ - 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, \ - 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, \ - 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, \ - 0x2f, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x28, \ - 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x20, \ - 0x3f, 0x3e, 0x3d, 0x3c, 0x3b, 0x3a, 0x39, 0x38, \ - 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x30, \ + 0x0f, \ + 0x0e, \ + 0x0d, \ + 0x0c, \ + 0x0b, \ + 0x0a, \ + 0x09, \ + 0x08, \ + 0x07, \ + 0x06, \ + 0x05, \ + 0x04, \ + 0x03, \ + 0x02, \ + 0x01, \ + 0x00, \ + 0x1f, \ + 0x1e, \ + 0x1d, \ + 0x1c, \ + 0x1b, \ + 0x1a, \ + 0x19, \ + 0x18, \ + 0x17, \ + 0x16, \ + 0x15, \ + 0x14, \ + 0x13, \ + 0x12, \ + 0x11, \ + 0x10, \ + 0x2f, \ + 0x2e, \ + 0x2d, \ + 0x2c, \ + 0x2b, \ + 0x2a, \ + 0x29, \ + 0x28, \ + 0x27, \ + 0x26, \ + 0x25, \ + 0x24, \ + 0x23, \ + 0x22, \ + 0x21, \ + 0x20, \ + 0x3f, \ + 0x3e, \ + 0x3d, \ + 0x3c, \ + 0x3b, \ + 0x3a, \ + 0x39, \ + 0x38, \ + 0x37, \ + 0x36, \ + 0x35, \ + 0x34, \ + 0x33, \ + 0x32, \ + 0x31, \ + 0x30, \ } #define FNV_B64_16 \ { \ - 0x22, 0x23, 0x20, 0x21, 0x26, 0x27, 0x24, 0x25, \ - 0x2a, 0x2b, 0x28, 0x29, 0x2e, 0x2f, 0x2c, 0x2d, \ - 0x32, 0x33, 0x30, 0x31, 0x36, 0x37, 0x34, 0x35, \ - 0x3a, 0x3b, 0x38, 0x39, 0x3e, 0x3f, 0x3c, 0x3d, \ - 0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05, \ - 0x0a, 0x0b, 0x08, 0x09, 0x0e, 0x0f, 0x0c, 0x0d, \ - 0x12, 0x13, 0x10, 0x11, 0x16, 0x17, 0x14, 0x15, \ - 0x1a, 0x1b, 0x18, 0x19, 0x1e, 0x1f, 0x1c, 0x1d, \ + 0x22, \ + 0x23, \ + 0x20, \ + 0x21, \ + 0x26, \ + 0x27, \ + 0x24, \ + 0x25, \ + 0x2a, \ + 0x2b, \ + 0x28, \ + 0x29, \ + 0x2e, \ + 0x2f, \ + 0x2c, \ + 0x2d, \ + 0x32, \ + 0x33, \ + 0x30, \ + 0x31, \ + 0x36, \ + 0x37, \ + 0x34, \ + 0x35, \ + 0x3a, \ + 0x3b, \ + 0x38, \ + 0x39, \ + 0x3e, \ + 0x3f, \ + 0x3c, \ + 0x3d, \ + 0x02, \ + 0x03, \ + 0x00, \ + 0x01, \ + 0x06, \ + 0x07, \ + 0x04, \ + 0x05, \ + 0x0a, \ + 0x0b, \ + 0x08, \ + 0x09, \ + 0x0e, \ + 0x0f, \ + 0x0c, \ + 0x0d, \ + 0x12, \ + 0x13, \ + 0x10, \ + 0x11, \ + 0x16, \ + 0x17, \ + 0x14, \ + 0x15, \ + 0x1a, \ + 0x1b, \ + 0x18, \ + 0x19, \ + 0x1e, \ + 0x1f, \ + 0x1c, \ + 0x1d, \ } #define FNV_B64_17 \ { \ - 0x35, 0x34, 0x37, 0x36, 0x31, 0x30, 0x33, 0x32, \ - 0x3d, 0x3c, 0x3f, 0x3e, 0x39, 0x38, 0x3b, 0x3a, \ - 0x25, 0x24, 0x27, 0x26, 0x21, 0x20, 0x23, 0x22, \ - 0x2d, 0x2c, 0x2f, 0x2e, 0x29, 0x28, 0x2b, 0x2a, \ - 0x15, 0x14, 0x17, 0x16, 0x11, 0x10, 0x13, 0x12, \ - 0x1d, 0x1c, 0x1f, 0x1e, 0x19, 0x18, 0x1b, 0x1a, \ - 0x05, 0x04, 0x07, 0x06, 0x01, 0x00, 0x03, 0x02, \ - 0x0d, 0x0c, 0x0f, 0x0e, 0x09, 0x08, 0x0b, 0x0a, \ + 0x35, \ + 0x34, \ + 0x37, \ + 0x36, \ + 0x31, \ + 0x30, \ + 0x33, \ + 0x32, \ + 0x3d, \ + 0x3c, \ + 0x3f, \ + 0x3e, \ + 0x39, \ + 0x38, \ + 0x3b, \ + 0x3a, \ + 0x25, \ + 0x24, \ + 0x27, \ + 0x26, \ + 0x21, \ + 0x20, \ + 0x23, \ + 0x22, \ + 0x2d, \ + 0x2c, \ + 0x2f, \ + 0x2e, \ + 0x29, \ + 0x28, \ + 0x2b, \ + 0x2a, \ + 0x15, \ + 0x14, \ + 0x17, \ + 0x16, \ + 0x11, \ + 0x10, \ + 0x13, \ + 0x12, \ + 0x1d, \ + 0x1c, \ + 0x1f, \ + 0x1e, \ + 0x19, \ + 0x18, \ + 0x1b, \ + 0x1a, \ + 0x05, \ + 0x04, \ + 0x07, \ + 0x06, \ + 0x01, \ + 0x00, \ + 0x03, \ + 0x02, \ + 0x0d, \ + 0x0c, \ + 0x0f, \ + 0x0e, \ + 0x09, \ + 0x08, \ + 0x0b, \ + 0x0a, \ } #define FNV_B64_18 \ { \ - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, \ - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \ - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, \ - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, \ - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, \ - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, \ - 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, \ - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, \ + 0x08, \ + 0x09, \ + 0x0a, \ + 0x0b, \ + 0x0c, \ + 0x0d, \ + 0x0e, \ + 0x0f, \ + 0x00, \ + 0x01, \ + 0x02, \ + 0x03, \ + 0x04, \ + 0x05, \ + 0x06, \ + 0x07, \ + 0x18, \ + 0x19, \ + 0x1a, \ + 0x1b, \ + 0x1c, \ + 0x1d, \ + 0x1e, \ + 0x1f, \ + 0x10, \ + 0x11, \ + 0x12, \ + 0x13, \ + 0x14, \ + 0x15, \ + 0x16, \ + 0x17, \ + 0x28, \ + 0x29, \ + 0x2a, \ + 0x2b, \ + 0x2c, \ + 0x2d, \ + 0x2e, \ + 0x2f, \ + 0x20, \ + 0x21, \ + 0x22, \ + 0x23, \ + 0x24, \ + 0x25, \ + 0x26, \ + 0x27, \ + 0x38, \ + 0x39, \ + 0x3a, \ + 0x3b, \ + 0x3c, \ + 0x3d, \ + 0x3e, \ + 0x3f, \ + 0x30, \ + 0x31, \ + 0x32, \ + 0x33, \ + 0x34, \ + 0x35, \ + 0x36, \ + 0x37, \ } #define FNV_B64_19 \ { \ - 0x1b, 0x1a, 0x19, 0x18, 0x1f, 0x1e, 0x1d, 0x1c, \ - 0x13, 0x12, 0x11, 0x10, 0x17, 0x16, 0x15, 0x14, \ - 0x0b, 0x0a, 0x09, 0x08, 0x0f, 0x0e, 0x0d, 0x0c, \ - 0x03, 0x02, 0x01, 0x00, 0x07, 0x06, 0x05, 0x04, \ - 0x3b, 0x3a, 0x39, 0x38, 0x3f, 0x3e, 0x3d, 0x3c, \ - 0x33, 0x32, 0x31, 0x30, 0x37, 0x36, 0x35, 0x34, \ - 0x2b, 0x2a, 0x29, 0x28, 0x2f, 0x2e, 0x2d, 0x2c, \ - 0x23, 0x22, 0x21, 0x20, 0x27, 0x26, 0x25, 0x24, \ + 0x1b, \ + 0x1a, \ + 0x19, \ + 0x18, \ + 0x1f, \ + 0x1e, \ + 0x1d, \ + 0x1c, \ + 0x13, \ + 0x12, \ + 0x11, \ + 0x10, \ + 0x17, \ + 0x16, \ + 0x15, \ + 0x14, \ + 0x0b, \ + 0x0a, \ + 0x09, \ + 0x08, \ + 0x0f, \ + 0x0e, \ + 0x0d, \ + 0x0c, \ + 0x03, \ + 0x02, \ + 0x01, \ + 0x00, \ + 0x07, \ + 0x06, \ + 0x05, \ + 0x04, \ + 0x3b, \ + 0x3a, \ + 0x39, \ + 0x38, \ + 0x3f, \ + 0x3e, \ + 0x3d, \ + 0x3c, \ + 0x33, \ + 0x32, \ + 0x31, \ + 0x30, \ + 0x37, \ + 0x36, \ + 0x35, \ + 0x34, \ + 0x2b, \ + 0x2a, \ + 0x29, \ + 0x28, \ + 0x2f, \ + 0x2e, \ + 0x2d, \ + 0x2c, \ + 0x23, \ + 0x22, \ + 0x21, \ + 0x20, \ + 0x27, \ + 0x26, \ + 0x25, \ + 0x24, \ } #define FNV_B64_1A \ { \ - 0x2e, 0x2f, 0x2c, 0x2d, 0x2a, 0x2b, 0x28, 0x29, \ - 0x26, 0x27, 0x24, 0x25, 0x22, 0x23, 0x20, 0x21, \ - 0x3e, 0x3f, 0x3c, 0x3d, 0x3a, 0x3b, 0x38, 0x39, \ - 0x36, 0x37, 0x34, 0x35, 0x32, 0x33, 0x30, 0x31, \ - 0x0e, 0x0f, 0x0c, 0x0d, 0x0a, 0x0b, 0x08, 0x09, \ - 0x06, 0x07, 0x04, 0x05, 0x02, 0x03, 0x00, 0x01, \ - 0x1e, 0x1f, 0x1c, 0x1d, 0x1a, 0x1b, 0x18, 0x19, \ - 0x16, 0x17, 0x14, 0x15, 0x12, 0x13, 0x10, 0x11, \ + 0x2e, \ + 0x2f, \ + 0x2c, \ + 0x2d, \ + 0x2a, \ + 0x2b, \ + 0x28, \ + 0x29, \ + 0x26, \ + 0x27, \ + 0x24, \ + 0x25, \ + 0x22, \ + 0x23, \ + 0x20, \ + 0x21, \ + 0x3e, \ + 0x3f, \ + 0x3c, \ + 0x3d, \ + 0x3a, \ + 0x3b, \ + 0x38, \ + 0x39, \ + 0x36, \ + 0x37, \ + 0x34, \ + 0x35, \ + 0x32, \ + 0x33, \ + 0x30, \ + 0x31, \ + 0x0e, \ + 0x0f, \ + 0x0c, \ + 0x0d, \ + 0x0a, \ + 0x0b, \ + 0x08, \ + 0x09, \ + 0x06, \ + 0x07, \ + 0x04, \ + 0x05, \ + 0x02, \ + 0x03, \ + 0x00, \ + 0x01, \ + 0x1e, \ + 0x1f, \ + 0x1c, \ + 0x1d, \ + 0x1a, \ + 0x1b, \ + 0x18, \ + 0x19, \ + 0x16, \ + 0x17, \ + 0x14, \ + 0x15, \ + 0x12, \ + 0x13, \ + 0x10, \ + 0x11, \ } #define FNV_B64_1B \ { \ - 0x01, 0x00, 0x03, 0x02, 0x05, 0x04, 0x07, 0x06, \ - 0x09, 0x08, 0x0b, 0x0a, 0x0d, 0x0c, 0x0f, 0x0e, \ - 0x11, 0x10, 0x13, 0x12, 0x15, 0x14, 0x17, 0x16, \ - 0x19, 0x18, 0x1b, 0x1a, 0x1d, 0x1c, 0x1f, 0x1e, \ - 0x21, 0x20, 0x23, 0x22, 0x25, 0x24, 0x27, 0x26, \ - 0x29, 0x28, 0x2b, 0x2a, 0x2d, 0x2c, 0x2f, 0x2e, \ - 0x31, 0x30, 0x33, 0x32, 0x35, 0x34, 0x37, 0x36, \ - 0x39, 0x38, 0x3b, 0x3a, 0x3d, 0x3c, 0x3f, 0x3e, \ + 0x01, \ + 0x00, \ + 0x03, \ + 0x02, \ + 0x05, \ + 0x04, \ + 0x07, \ + 0x06, \ + 0x09, \ + 0x08, \ + 0x0b, \ + 0x0a, \ + 0x0d, \ + 0x0c, \ + 0x0f, \ + 0x0e, \ + 0x11, \ + 0x10, \ + 0x13, \ + 0x12, \ + 0x15, \ + 0x14, \ + 0x17, \ + 0x16, \ + 0x19, \ + 0x18, \ + 0x1b, \ + 0x1a, \ + 0x1d, \ + 0x1c, \ + 0x1f, \ + 0x1e, \ + 0x21, \ + 0x20, \ + 0x23, \ + 0x22, \ + 0x25, \ + 0x24, \ + 0x27, \ + 0x26, \ + 0x29, \ + 0x28, \ + 0x2b, \ + 0x2a, \ + 0x2d, \ + 0x2c, \ + 0x2f, \ + 0x2e, \ + 0x31, \ + 0x30, \ + 0x33, \ + 0x32, \ + 0x35, \ + 0x34, \ + 0x37, \ + 0x36, \ + 0x39, \ + 0x38, \ + 0x3b, \ + 0x3a, \ + 0x3d, \ + 0x3c, \ + 0x3f, \ + 0x3e, \ } #define FNV_B64_1C \ { \ - 0x14, 0x15, 0x16, 0x17, 0x10, 0x11, 0x12, 0x13, \ - 0x1c, 0x1d, 0x1e, 0x1f, 0x18, 0x19, 0x1a, 0x1b, \ - 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, \ - 0x0c, 0x0d, 0x0e, 0x0f, 0x08, 0x09, 0x0a, 0x0b, \ - 0x34, 0x35, 0x36, 0x37, 0x30, 0x31, 0x32, 0x33, \ - 0x3c, 0x3d, 0x3e, 0x3f, 0x38, 0x39, 0x3a, 0x3b, \ - 0x24, 0x25, 0x26, 0x27, 0x20, 0x21, 0x22, 0x23, \ - 0x2c, 0x2d, 0x2e, 0x2f, 0x28, 0x29, 0x2a, 0x2b, \ + 0x14, \ + 0x15, \ + 0x16, \ + 0x17, \ + 0x10, \ + 0x11, \ + 0x12, \ + 0x13, \ + 0x1c, \ + 0x1d, \ + 0x1e, \ + 0x1f, \ + 0x18, \ + 0x19, \ + 0x1a, \ + 0x1b, \ + 0x04, \ + 0x05, \ + 0x06, \ + 0x07, \ + 0x00, \ + 0x01, \ + 0x02, \ + 0x03, \ + 0x0c, \ + 0x0d, \ + 0x0e, \ + 0x0f, \ + 0x08, \ + 0x09, \ + 0x0a, \ + 0x0b, \ + 0x34, \ + 0x35, \ + 0x36, \ + 0x37, \ + 0x30, \ + 0x31, \ + 0x32, \ + 0x33, \ + 0x3c, \ + 0x3d, \ + 0x3e, \ + 0x3f, \ + 0x38, \ + 0x39, \ + 0x3a, \ + 0x3b, \ + 0x24, \ + 0x25, \ + 0x26, \ + 0x27, \ + 0x20, \ + 0x21, \ + 0x22, \ + 0x23, \ + 0x2c, \ + 0x2d, \ + 0x2e, \ + 0x2f, \ + 0x28, \ + 0x29, \ + 0x2a, \ + 0x2b, \ } #define FNV_B64_1D \ { \ - 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x20, \ - 0x2f, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x28, \ - 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x30, \ - 0x3f, 0x3e, 0x3d, 0x3c, 0x3b, 0x3a, 0x39, 0x38, \ - 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, \ - 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, \ - 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, \ - 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, \ + 0x27, \ + 0x26, \ + 0x25, \ + 0x24, \ + 0x23, \ + 0x22, \ + 0x21, \ + 0x20, \ + 0x2f, \ + 0x2e, \ + 0x2d, \ + 0x2c, \ + 0x2b, \ + 0x2a, \ + 0x29, \ + 0x28, \ + 0x37, \ + 0x36, \ + 0x35, \ + 0x34, \ + 0x33, \ + 0x32, \ + 0x31, \ + 0x30, \ + 0x3f, \ + 0x3e, \ + 0x3d, \ + 0x3c, \ + 0x3b, \ + 0x3a, \ + 0x39, \ + 0x38, \ + 0x07, \ + 0x06, \ + 0x05, \ + 0x04, \ + 0x03, \ + 0x02, \ + 0x01, \ + 0x00, \ + 0x0f, \ + 0x0e, \ + 0x0d, \ + 0x0c, \ + 0x0b, \ + 0x0a, \ + 0x09, \ + 0x08, \ + 0x17, \ + 0x16, \ + 0x15, \ + 0x14, \ + 0x13, \ + 0x12, \ + 0x11, \ + 0x10, \ + 0x1f, \ + 0x1e, \ + 0x1d, \ + 0x1c, \ + 0x1b, \ + 0x1a, \ + 0x19, \ + 0x18, \ } #define FNV_B64_1E \ { \ - 0x3a, 0x3b, 0x38, 0x39, 0x3e, 0x3f, 0x3c, 0x3d, \ - 0x32, 0x33, 0x30, 0x31, 0x36, 0x37, 0x34, 0x35, \ - 0x2a, 0x2b, 0x28, 0x29, 0x2e, 0x2f, 0x2c, 0x2d, \ - 0x22, 0x23, 0x20, 0x21, 0x26, 0x27, 0x24, 0x25, \ - 0x1a, 0x1b, 0x18, 0x19, 0x1e, 0x1f, 0x1c, 0x1d, \ - 0x12, 0x13, 0x10, 0x11, 0x16, 0x17, 0x14, 0x15, \ - 0x0a, 0x0b, 0x08, 0x09, 0x0e, 0x0f, 0x0c, 0x0d, \ - 0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05, \ + 0x3a, \ + 0x3b, \ + 0x38, \ + 0x39, \ + 0x3e, \ + 0x3f, \ + 0x3c, \ + 0x3d, \ + 0x32, \ + 0x33, \ + 0x30, \ + 0x31, \ + 0x36, \ + 0x37, \ + 0x34, \ + 0x35, \ + 0x2a, \ + 0x2b, \ + 0x28, \ + 0x29, \ + 0x2e, \ + 0x2f, \ + 0x2c, \ + 0x2d, \ + 0x22, \ + 0x23, \ + 0x20, \ + 0x21, \ + 0x26, \ + 0x27, \ + 0x24, \ + 0x25, \ + 0x1a, \ + 0x1b, \ + 0x18, \ + 0x19, \ + 0x1e, \ + 0x1f, \ + 0x1c, \ + 0x1d, \ + 0x12, \ + 0x13, \ + 0x10, \ + 0x11, \ + 0x16, \ + 0x17, \ + 0x14, \ + 0x15, \ + 0x0a, \ + 0x0b, \ + 0x08, \ + 0x09, \ + 0x0e, \ + 0x0f, \ + 0x0c, \ + 0x0d, \ + 0x02, \ + 0x03, \ + 0x00, \ + 0x01, \ + 0x06, \ + 0x07, \ + 0x04, \ + 0x05, \ } #define FNV_B64_1F \ { \ - 0x0d, 0x0c, 0x0f, 0x0e, 0x09, 0x08, 0x0b, 0x0a, \ - 0x05, 0x04, 0x07, 0x06, 0x01, 0x00, 0x03, 0x02, \ - 0x1d, 0x1c, 0x1f, 0x1e, 0x19, 0x18, 0x1b, 0x1a, \ - 0x15, 0x14, 0x17, 0x16, 0x11, 0x10, 0x13, 0x12, \ - 0x2d, 0x2c, 0x2f, 0x2e, 0x29, 0x28, 0x2b, 0x2a, \ - 0x25, 0x24, 0x27, 0x26, 0x21, 0x20, 0x23, 0x22, \ - 0x3d, 0x3c, 0x3f, 0x3e, 0x39, 0x38, 0x3b, 0x3a, \ - 0x35, 0x34, 0x37, 0x36, 0x31, 0x30, 0x33, 0x32, \ + 0x0d, \ + 0x0c, \ + 0x0f, \ + 0x0e, \ + 0x09, \ + 0x08, \ + 0x0b, \ + 0x0a, \ + 0x05, \ + 0x04, \ + 0x07, \ + 0x06, \ + 0x01, \ + 0x00, \ + 0x03, \ + 0x02, \ + 0x1d, \ + 0x1c, \ + 0x1f, \ + 0x1e, \ + 0x19, \ + 0x18, \ + 0x1b, \ + 0x1a, \ + 0x15, \ + 0x14, \ + 0x17, \ + 0x16, \ + 0x11, \ + 0x10, \ + 0x13, \ + 0x12, \ + 0x2d, \ + 0x2c, \ + 0x2f, \ + 0x2e, \ + 0x29, \ + 0x28, \ + 0x2b, \ + 0x2a, \ + 0x25, \ + 0x24, \ + 0x27, \ + 0x26, \ + 0x21, \ + 0x20, \ + 0x23, \ + 0x22, \ + 0x3d, \ + 0x3c, \ + 0x3f, \ + 0x3e, \ + 0x39, \ + 0x38, \ + 0x3b, \ + 0x3a, \ + 0x35, \ + 0x34, \ + 0x37, \ + 0x36, \ + 0x31, \ + 0x30, \ + 0x33, \ + 0x32, \ } #define FNV_B64_20 \ { \ - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, \ - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, \ - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, \ - 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, \ - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \ - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, \ - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, \ - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, \ + 0x20, \ + 0x21, \ + 0x22, \ + 0x23, \ + 0x24, \ + 0x25, \ + 0x26, \ + 0x27, \ + 0x28, \ + 0x29, \ + 0x2a, \ + 0x2b, \ + 0x2c, \ + 0x2d, \ + 0x2e, \ + 0x2f, \ + 0x30, \ + 0x31, \ + 0x32, \ + 0x33, \ + 0x34, \ + 0x35, \ + 0x36, \ + 0x37, \ + 0x38, \ + 0x39, \ + 0x3a, \ + 0x3b, \ + 0x3c, \ + 0x3d, \ + 0x3e, \ + 0x3f, \ + 0x00, \ + 0x01, \ + 0x02, \ + 0x03, \ + 0x04, \ + 0x05, \ + 0x06, \ + 0x07, \ + 0x08, \ + 0x09, \ + 0x0a, \ + 0x0b, \ + 0x0c, \ + 0x0d, \ + 0x0e, \ + 0x0f, \ + 0x10, \ + 0x11, \ + 0x12, \ + 0x13, \ + 0x14, \ + 0x15, \ + 0x16, \ + 0x17, \ + 0x18, \ + 0x19, \ + 0x1a, \ + 0x1b, \ + 0x1c, \ + 0x1d, \ + 0x1e, \ + 0x1f, \ } #define FNV_B64_21 \ { \ - 0x33, 0x32, 0x31, 0x30, 0x37, 0x36, 0x35, 0x34, \ - 0x3b, 0x3a, 0x39, 0x38, 0x3f, 0x3e, 0x3d, 0x3c, \ - 0x23, 0x22, 0x21, 0x20, 0x27, 0x26, 0x25, 0x24, \ - 0x2b, 0x2a, 0x29, 0x28, 0x2f, 0x2e, 0x2d, 0x2c, \ - 0x13, 0x12, 0x11, 0x10, 0x17, 0x16, 0x15, 0x14, \ - 0x1b, 0x1a, 0x19, 0x18, 0x1f, 0x1e, 0x1d, 0x1c, \ - 0x03, 0x02, 0x01, 0x00, 0x07, 0x06, 0x05, 0x04, \ - 0x0b, 0x0a, 0x09, 0x08, 0x0f, 0x0e, 0x0d, 0x0c, \ + 0x33, \ + 0x32, \ + 0x31, \ + 0x30, \ + 0x37, \ + 0x36, \ + 0x35, \ + 0x34, \ + 0x3b, \ + 0x3a, \ + 0x39, \ + 0x38, \ + 0x3f, \ + 0x3e, \ + 0x3d, \ + 0x3c, \ + 0x23, \ + 0x22, \ + 0x21, \ + 0x20, \ + 0x27, \ + 0x26, \ + 0x25, \ + 0x24, \ + 0x2b, \ + 0x2a, \ + 0x29, \ + 0x28, \ + 0x2f, \ + 0x2e, \ + 0x2d, \ + 0x2c, \ + 0x13, \ + 0x12, \ + 0x11, \ + 0x10, \ + 0x17, \ + 0x16, \ + 0x15, \ + 0x14, \ + 0x1b, \ + 0x1a, \ + 0x19, \ + 0x18, \ + 0x1f, \ + 0x1e, \ + 0x1d, \ + 0x1c, \ + 0x03, \ + 0x02, \ + 0x01, \ + 0x00, \ + 0x07, \ + 0x06, \ + 0x05, \ + 0x04, \ + 0x0b, \ + 0x0a, \ + 0x09, \ + 0x08, \ + 0x0f, \ + 0x0e, \ + 0x0d, \ + 0x0c, \ } #define FNV_B64_22 \ { \ - 0x06, 0x07, 0x04, 0x05, 0x02, 0x03, 0x00, 0x01, \ - 0x0e, 0x0f, 0x0c, 0x0d, 0x0a, 0x0b, 0x08, 0x09, \ - 0x16, 0x17, 0x14, 0x15, 0x12, 0x13, 0x10, 0x11, \ - 0x1e, 0x1f, 0x1c, 0x1d, 0x1a, 0x1b, 0x18, 0x19, \ - 0x26, 0x27, 0x24, 0x25, 0x22, 0x23, 0x20, 0x21, \ - 0x2e, 0x2f, 0x2c, 0x2d, 0x2a, 0x2b, 0x28, 0x29, \ - 0x36, 0x37, 0x34, 0x35, 0x32, 0x33, 0x30, 0x31, \ - 0x3e, 0x3f, 0x3c, 0x3d, 0x3a, 0x3b, 0x38, 0x39, \ + 0x06, \ + 0x07, \ + 0x04, \ + 0x05, \ + 0x02, \ + 0x03, \ + 0x00, \ + 0x01, \ + 0x0e, \ + 0x0f, \ + 0x0c, \ + 0x0d, \ + 0x0a, \ + 0x0b, \ + 0x08, \ + 0x09, \ + 0x16, \ + 0x17, \ + 0x14, \ + 0x15, \ + 0x12, \ + 0x13, \ + 0x10, \ + 0x11, \ + 0x1e, \ + 0x1f, \ + 0x1c, \ + 0x1d, \ + 0x1a, \ + 0x1b, \ + 0x18, \ + 0x19, \ + 0x26, \ + 0x27, \ + 0x24, \ + 0x25, \ + 0x22, \ + 0x23, \ + 0x20, \ + 0x21, \ + 0x2e, \ + 0x2f, \ + 0x2c, \ + 0x2d, \ + 0x2a, \ + 0x2b, \ + 0x28, \ + 0x29, \ + 0x36, \ + 0x37, \ + 0x34, \ + 0x35, \ + 0x32, \ + 0x33, \ + 0x30, \ + 0x31, \ + 0x3e, \ + 0x3f, \ + 0x3c, \ + 0x3d, \ + 0x3a, \ + 0x3b, \ + 0x38, \ + 0x39, \ } #define FNV_B64_23 \ { \ - 0x19, 0x18, 0x1b, 0x1a, 0x1d, 0x1c, 0x1f, 0x1e, \ - 0x11, 0x10, 0x13, 0x12, 0x15, 0x14, 0x17, 0x16, \ - 0x09, 0x08, 0x0b, 0x0a, 0x0d, 0x0c, 0x0f, 0x0e, \ - 0x01, 0x00, 0x03, 0x02, 0x05, 0x04, 0x07, 0x06, \ - 0x39, 0x38, 0x3b, 0x3a, 0x3d, 0x3c, 0x3f, 0x3e, \ - 0x31, 0x30, 0x33, 0x32, 0x35, 0x34, 0x37, 0x36, \ - 0x29, 0x28, 0x2b, 0x2a, 0x2d, 0x2c, 0x2f, 0x2e, \ - 0x21, 0x20, 0x23, 0x22, 0x25, 0x24, 0x27, 0x26, \ + 0x19, \ + 0x18, \ + 0x1b, \ + 0x1a, \ + 0x1d, \ + 0x1c, \ + 0x1f, \ + 0x1e, \ + 0x11, \ + 0x10, \ + 0x13, \ + 0x12, \ + 0x15, \ + 0x14, \ + 0x17, \ + 0x16, \ + 0x09, \ + 0x08, \ + 0x0b, \ + 0x0a, \ + 0x0d, \ + 0x0c, \ + 0x0f, \ + 0x0e, \ + 0x01, \ + 0x00, \ + 0x03, \ + 0x02, \ + 0x05, \ + 0x04, \ + 0x07, \ + 0x06, \ + 0x39, \ + 0x38, \ + 0x3b, \ + 0x3a, \ + 0x3d, \ + 0x3c, \ + 0x3f, \ + 0x3e, \ + 0x31, \ + 0x30, \ + 0x33, \ + 0x32, \ + 0x35, \ + 0x34, \ + 0x37, \ + 0x36, \ + 0x29, \ + 0x28, \ + 0x2b, \ + 0x2a, \ + 0x2d, \ + 0x2c, \ + 0x2f, \ + 0x2e, \ + 0x21, \ + 0x20, \ + 0x23, \ + 0x22, \ + 0x25, \ + 0x24, \ + 0x27, \ + 0x26, \ } #define FNV_B64_24 \ { \ - 0x2c, 0x2d, 0x2e, 0x2f, 0x28, 0x29, 0x2a, 0x2b, \ - 0x24, 0x25, 0x26, 0x27, 0x20, 0x21, 0x22, 0x23, \ - 0x3c, 0x3d, 0x3e, 0x3f, 0x38, 0x39, 0x3a, 0x3b, \ - 0x34, 0x35, 0x36, 0x37, 0x30, 0x31, 0x32, 0x33, \ - 0x0c, 0x0d, 0x0e, 0x0f, 0x08, 0x09, 0x0a, 0x0b, \ - 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, \ - 0x1c, 0x1d, 0x1e, 0x1f, 0x18, 0x19, 0x1a, 0x1b, \ - 0x14, 0x15, 0x16, 0x17, 0x10, 0x11, 0x12, 0x13, \ + 0x2c, \ + 0x2d, \ + 0x2e, \ + 0x2f, \ + 0x28, \ + 0x29, \ + 0x2a, \ + 0x2b, \ + 0x24, \ + 0x25, \ + 0x26, \ + 0x27, \ + 0x20, \ + 0x21, \ + 0x22, \ + 0x23, \ + 0x3c, \ + 0x3d, \ + 0x3e, \ + 0x3f, \ + 0x38, \ + 0x39, \ + 0x3a, \ + 0x3b, \ + 0x34, \ + 0x35, \ + 0x36, \ + 0x37, \ + 0x30, \ + 0x31, \ + 0x32, \ + 0x33, \ + 0x0c, \ + 0x0d, \ + 0x0e, \ + 0x0f, \ + 0x08, \ + 0x09, \ + 0x0a, \ + 0x0b, \ + 0x04, \ + 0x05, \ + 0x06, \ + 0x07, \ + 0x00, \ + 0x01, \ + 0x02, \ + 0x03, \ + 0x1c, \ + 0x1d, \ + 0x1e, \ + 0x1f, \ + 0x18, \ + 0x19, \ + 0x1a, \ + 0x1b, \ + 0x14, \ + 0x15, \ + 0x16, \ + 0x17, \ + 0x10, \ + 0x11, \ + 0x12, \ + 0x13, \ } #define FNV_B64_25 \ { \ - 0x3f, 0x3e, 0x3d, 0x3c, 0x3b, 0x3a, 0x39, 0x38, \ - 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x30, \ - 0x2f, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x28, \ - 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x20, \ - 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, \ - 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, \ - 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, \ - 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, \ + 0x3f, \ + 0x3e, \ + 0x3d, \ + 0x3c, \ + 0x3b, \ + 0x3a, \ + 0x39, \ + 0x38, \ + 0x37, \ + 0x36, \ + 0x35, \ + 0x34, \ + 0x33, \ + 0x32, \ + 0x31, \ + 0x30, \ + 0x2f, \ + 0x2e, \ + 0x2d, \ + 0x2c, \ + 0x2b, \ + 0x2a, \ + 0x29, \ + 0x28, \ + 0x27, \ + 0x26, \ + 0x25, \ + 0x24, \ + 0x23, \ + 0x22, \ + 0x21, \ + 0x20, \ + 0x1f, \ + 0x1e, \ + 0x1d, \ + 0x1c, \ + 0x1b, \ + 0x1a, \ + 0x19, \ + 0x18, \ + 0x17, \ + 0x16, \ + 0x15, \ + 0x14, \ + 0x13, \ + 0x12, \ + 0x11, \ + 0x10, \ + 0x0f, \ + 0x0e, \ + 0x0d, \ + 0x0c, \ + 0x0b, \ + 0x0a, \ + 0x09, \ + 0x08, \ + 0x07, \ + 0x06, \ + 0x05, \ + 0x04, \ + 0x03, \ + 0x02, \ + 0x01, \ + 0x00, \ } #define FNV_B64_26 \ { \ - 0x12, 0x13, 0x10, 0x11, 0x16, 0x17, 0x14, 0x15, \ - 0x1a, 0x1b, 0x18, 0x19, 0x1e, 0x1f, 0x1c, 0x1d, \ - 0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05, \ - 0x0a, 0x0b, 0x08, 0x09, 0x0e, 0x0f, 0x0c, 0x0d, \ - 0x32, 0x33, 0x30, 0x31, 0x36, 0x37, 0x34, 0x35, \ - 0x3a, 0x3b, 0x38, 0x39, 0x3e, 0x3f, 0x3c, 0x3d, \ - 0x22, 0x23, 0x20, 0x21, 0x26, 0x27, 0x24, 0x25, \ - 0x2a, 0x2b, 0x28, 0x29, 0x2e, 0x2f, 0x2c, 0x2d, \ + 0x12, \ + 0x13, \ + 0x10, \ + 0x11, \ + 0x16, \ + 0x17, \ + 0x14, \ + 0x15, \ + 0x1a, \ + 0x1b, \ + 0x18, \ + 0x19, \ + 0x1e, \ + 0x1f, \ + 0x1c, \ + 0x1d, \ + 0x02, \ + 0x03, \ + 0x00, \ + 0x01, \ + 0x06, \ + 0x07, \ + 0x04, \ + 0x05, \ + 0x0a, \ + 0x0b, \ + 0x08, \ + 0x09, \ + 0x0e, \ + 0x0f, \ + 0x0c, \ + 0x0d, \ + 0x32, \ + 0x33, \ + 0x30, \ + 0x31, \ + 0x36, \ + 0x37, \ + 0x34, \ + 0x35, \ + 0x3a, \ + 0x3b, \ + 0x38, \ + 0x39, \ + 0x3e, \ + 0x3f, \ + 0x3c, \ + 0x3d, \ + 0x22, \ + 0x23, \ + 0x20, \ + 0x21, \ + 0x26, \ + 0x27, \ + 0x24, \ + 0x25, \ + 0x2a, \ + 0x2b, \ + 0x28, \ + 0x29, \ + 0x2e, \ + 0x2f, \ + 0x2c, \ + 0x2d, \ } #define FNV_B64_27 \ { \ - 0x25, 0x24, 0x27, 0x26, 0x21, 0x20, 0x23, 0x22, \ - 0x2d, 0x2c, 0x2f, 0x2e, 0x29, 0x28, 0x2b, 0x2a, \ - 0x35, 0x34, 0x37, 0x36, 0x31, 0x30, 0x33, 0x32, \ - 0x3d, 0x3c, 0x3f, 0x3e, 0x39, 0x38, 0x3b, 0x3a, \ - 0x05, 0x04, 0x07, 0x06, 0x01, 0x00, 0x03, 0x02, \ - 0x0d, 0x0c, 0x0f, 0x0e, 0x09, 0x08, 0x0b, 0x0a, \ - 0x15, 0x14, 0x17, 0x16, 0x11, 0x10, 0x13, 0x12, \ - 0x1d, 0x1c, 0x1f, 0x1e, 0x19, 0x18, 0x1b, 0x1a, \ + 0x25, \ + 0x24, \ + 0x27, \ + 0x26, \ + 0x21, \ + 0x20, \ + 0x23, \ + 0x22, \ + 0x2d, \ + 0x2c, \ + 0x2f, \ + 0x2e, \ + 0x29, \ + 0x28, \ + 0x2b, \ + 0x2a, \ + 0x35, \ + 0x34, \ + 0x37, \ + 0x36, \ + 0x31, \ + 0x30, \ + 0x33, \ + 0x32, \ + 0x3d, \ + 0x3c, \ + 0x3f, \ + 0x3e, \ + 0x39, \ + 0x38, \ + 0x3b, \ + 0x3a, \ + 0x05, \ + 0x04, \ + 0x07, \ + 0x06, \ + 0x01, \ + 0x00, \ + 0x03, \ + 0x02, \ + 0x0d, \ + 0x0c, \ + 0x0f, \ + 0x0e, \ + 0x09, \ + 0x08, \ + 0x0b, \ + 0x0a, \ + 0x15, \ + 0x14, \ + 0x17, \ + 0x16, \ + 0x11, \ + 0x10, \ + 0x13, \ + 0x12, \ + 0x1d, \ + 0x1c, \ + 0x1f, \ + 0x1e, \ + 0x19, \ + 0x18, \ + 0x1b, \ + 0x1a, \ } #define FNV_B64_28 \ { \ - 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, \ - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, \ - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, \ - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, \ - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, \ - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, \ - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, \ - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \ + 0x38, \ + 0x39, \ + 0x3a, \ + 0x3b, \ + 0x3c, \ + 0x3d, \ + 0x3e, \ + 0x3f, \ + 0x30, \ + 0x31, \ + 0x32, \ + 0x33, \ + 0x34, \ + 0x35, \ + 0x36, \ + 0x37, \ + 0x28, \ + 0x29, \ + 0x2a, \ + 0x2b, \ + 0x2c, \ + 0x2d, \ + 0x2e, \ + 0x2f, \ + 0x20, \ + 0x21, \ + 0x22, \ + 0x23, \ + 0x24, \ + 0x25, \ + 0x26, \ + 0x27, \ + 0x18, \ + 0x19, \ + 0x1a, \ + 0x1b, \ + 0x1c, \ + 0x1d, \ + 0x1e, \ + 0x1f, \ + 0x10, \ + 0x11, \ + 0x12, \ + 0x13, \ + 0x14, \ + 0x15, \ + 0x16, \ + 0x17, \ + 0x08, \ + 0x09, \ + 0x0a, \ + 0x0b, \ + 0x0c, \ + 0x0d, \ + 0x0e, \ + 0x0f, \ + 0x00, \ + 0x01, \ + 0x02, \ + 0x03, \ + 0x04, \ + 0x05, \ + 0x06, \ + 0x07, \ } #define FNV_B64_29 \ { \ - 0x0b, 0x0a, 0x09, 0x08, 0x0f, 0x0e, 0x0d, 0x0c, \ - 0x03, 0x02, 0x01, 0x00, 0x07, 0x06, 0x05, 0x04, \ - 0x1b, 0x1a, 0x19, 0x18, 0x1f, 0x1e, 0x1d, 0x1c, \ - 0x13, 0x12, 0x11, 0x10, 0x17, 0x16, 0x15, 0x14, \ - 0x2b, 0x2a, 0x29, 0x28, 0x2f, 0x2e, 0x2d, 0x2c, \ - 0x23, 0x22, 0x21, 0x20, 0x27, 0x26, 0x25, 0x24, \ - 0x3b, 0x3a, 0x39, 0x38, 0x3f, 0x3e, 0x3d, 0x3c, \ - 0x33, 0x32, 0x31, 0x30, 0x37, 0x36, 0x35, 0x34, \ + 0x0b, \ + 0x0a, \ + 0x09, \ + 0x08, \ + 0x0f, \ + 0x0e, \ + 0x0d, \ + 0x0c, \ + 0x03, \ + 0x02, \ + 0x01, \ + 0x00, \ + 0x07, \ + 0x06, \ + 0x05, \ + 0x04, \ + 0x1b, \ + 0x1a, \ + 0x19, \ + 0x18, \ + 0x1f, \ + 0x1e, \ + 0x1d, \ + 0x1c, \ + 0x13, \ + 0x12, \ + 0x11, \ + 0x10, \ + 0x17, \ + 0x16, \ + 0x15, \ + 0x14, \ + 0x2b, \ + 0x2a, \ + 0x29, \ + 0x28, \ + 0x2f, \ + 0x2e, \ + 0x2d, \ + 0x2c, \ + 0x23, \ + 0x22, \ + 0x21, \ + 0x20, \ + 0x27, \ + 0x26, \ + 0x25, \ + 0x24, \ + 0x3b, \ + 0x3a, \ + 0x39, \ + 0x38, \ + 0x3f, \ + 0x3e, \ + 0x3d, \ + 0x3c, \ + 0x33, \ + 0x32, \ + 0x31, \ + 0x30, \ + 0x37, \ + 0x36, \ + 0x35, \ + 0x34, \ } #define FNV_B64_2A \ { \ - 0x1e, 0x1f, 0x1c, 0x1d, 0x1a, 0x1b, 0x18, 0x19, \ - 0x16, 0x17, 0x14, 0x15, 0x12, 0x13, 0x10, 0x11, \ - 0x0e, 0x0f, 0x0c, 0x0d, 0x0a, 0x0b, 0x08, 0x09, \ - 0x06, 0x07, 0x04, 0x05, 0x02, 0x03, 0x00, 0x01, \ - 0x3e, 0x3f, 0x3c, 0x3d, 0x3a, 0x3b, 0x38, 0x39, \ - 0x36, 0x37, 0x34, 0x35, 0x32, 0x33, 0x30, 0x31, \ - 0x2e, 0x2f, 0x2c, 0x2d, 0x2a, 0x2b, 0x28, 0x29, \ - 0x26, 0x27, 0x24, 0x25, 0x22, 0x23, 0x20, 0x21, \ + 0x1e, \ + 0x1f, \ + 0x1c, \ + 0x1d, \ + 0x1a, \ + 0x1b, \ + 0x18, \ + 0x19, \ + 0x16, \ + 0x17, \ + 0x14, \ + 0x15, \ + 0x12, \ + 0x13, \ + 0x10, \ + 0x11, \ + 0x0e, \ + 0x0f, \ + 0x0c, \ + 0x0d, \ + 0x0a, \ + 0x0b, \ + 0x08, \ + 0x09, \ + 0x06, \ + 0x07, \ + 0x04, \ + 0x05, \ + 0x02, \ + 0x03, \ + 0x00, \ + 0x01, \ + 0x3e, \ + 0x3f, \ + 0x3c, \ + 0x3d, \ + 0x3a, \ + 0x3b, \ + 0x38, \ + 0x39, \ + 0x36, \ + 0x37, \ + 0x34, \ + 0x35, \ + 0x32, \ + 0x33, \ + 0x30, \ + 0x31, \ + 0x2e, \ + 0x2f, \ + 0x2c, \ + 0x2d, \ + 0x2a, \ + 0x2b, \ + 0x28, \ + 0x29, \ + 0x26, \ + 0x27, \ + 0x24, \ + 0x25, \ + 0x22, \ + 0x23, \ + 0x20, \ + 0x21, \ } #define FNV_B64_2B \ { \ - 0x31, 0x30, 0x33, 0x32, 0x35, 0x34, 0x37, 0x36, \ - 0x39, 0x38, 0x3b, 0x3a, 0x3d, 0x3c, 0x3f, 0x3e, \ - 0x21, 0x20, 0x23, 0x22, 0x25, 0x24, 0x27, 0x26, \ - 0x29, 0x28, 0x2b, 0x2a, 0x2d, 0x2c, 0x2f, 0x2e, \ - 0x11, 0x10, 0x13, 0x12, 0x15, 0x14, 0x17, 0x16, \ - 0x19, 0x18, 0x1b, 0x1a, 0x1d, 0x1c, 0x1f, 0x1e, \ - 0x01, 0x00, 0x03, 0x02, 0x05, 0x04, 0x07, 0x06, \ - 0x09, 0x08, 0x0b, 0x0a, 0x0d, 0x0c, 0x0f, 0x0e, \ + 0x31, \ + 0x30, \ + 0x33, \ + 0x32, \ + 0x35, \ + 0x34, \ + 0x37, \ + 0x36, \ + 0x39, \ + 0x38, \ + 0x3b, \ + 0x3a, \ + 0x3d, \ + 0x3c, \ + 0x3f, \ + 0x3e, \ + 0x21, \ + 0x20, \ + 0x23, \ + 0x22, \ + 0x25, \ + 0x24, \ + 0x27, \ + 0x26, \ + 0x29, \ + 0x28, \ + 0x2b, \ + 0x2a, \ + 0x2d, \ + 0x2c, \ + 0x2f, \ + 0x2e, \ + 0x11, \ + 0x10, \ + 0x13, \ + 0x12, \ + 0x15, \ + 0x14, \ + 0x17, \ + 0x16, \ + 0x19, \ + 0x18, \ + 0x1b, \ + 0x1a, \ + 0x1d, \ + 0x1c, \ + 0x1f, \ + 0x1e, \ + 0x01, \ + 0x00, \ + 0x03, \ + 0x02, \ + 0x05, \ + 0x04, \ + 0x07, \ + 0x06, \ + 0x09, \ + 0x08, \ + 0x0b, \ + 0x0a, \ + 0x0d, \ + 0x0c, \ + 0x0f, \ + 0x0e, \ } #define FNV_B64_2C \ { \ - 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, \ - 0x0c, 0x0d, 0x0e, 0x0f, 0x08, 0x09, 0x0a, 0x0b, \ - 0x14, 0x15, 0x16, 0x17, 0x10, 0x11, 0x12, 0x13, \ - 0x1c, 0x1d, 0x1e, 0x1f, 0x18, 0x19, 0x1a, 0x1b, \ - 0x24, 0x25, 0x26, 0x27, 0x20, 0x21, 0x22, 0x23, \ - 0x2c, 0x2d, 0x2e, 0x2f, 0x28, 0x29, 0x2a, 0x2b, \ - 0x34, 0x35, 0x36, 0x37, 0x30, 0x31, 0x32, 0x33, \ - 0x3c, 0x3d, 0x3e, 0x3f, 0x38, 0x39, 0x3a, 0x3b, \ + 0x04, \ + 0x05, \ + 0x06, \ + 0x07, \ + 0x00, \ + 0x01, \ + 0x02, \ + 0x03, \ + 0x0c, \ + 0x0d, \ + 0x0e, \ + 0x0f, \ + 0x08, \ + 0x09, \ + 0x0a, \ + 0x0b, \ + 0x14, \ + 0x15, \ + 0x16, \ + 0x17, \ + 0x10, \ + 0x11, \ + 0x12, \ + 0x13, \ + 0x1c, \ + 0x1d, \ + 0x1e, \ + 0x1f, \ + 0x18, \ + 0x19, \ + 0x1a, \ + 0x1b, \ + 0x24, \ + 0x25, \ + 0x26, \ + 0x27, \ + 0x20, \ + 0x21, \ + 0x22, \ + 0x23, \ + 0x2c, \ + 0x2d, \ + 0x2e, \ + 0x2f, \ + 0x28, \ + 0x29, \ + 0x2a, \ + 0x2b, \ + 0x34, \ + 0x35, \ + 0x36, \ + 0x37, \ + 0x30, \ + 0x31, \ + 0x32, \ + 0x33, \ + 0x3c, \ + 0x3d, \ + 0x3e, \ + 0x3f, \ + 0x38, \ + 0x39, \ + 0x3a, \ + 0x3b, \ } #define FNV_B64_2D \ { \ - 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, \ - 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, \ - 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, \ - 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, \ - 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x30, \ - 0x3f, 0x3e, 0x3d, 0x3c, 0x3b, 0x3a, 0x39, 0x38, \ - 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x20, \ - 0x2f, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x28, \ + 0x17, \ + 0x16, \ + 0x15, \ + 0x14, \ + 0x13, \ + 0x12, \ + 0x11, \ + 0x10, \ + 0x1f, \ + 0x1e, \ + 0x1d, \ + 0x1c, \ + 0x1b, \ + 0x1a, \ + 0x19, \ + 0x18, \ + 0x07, \ + 0x06, \ + 0x05, \ + 0x04, \ + 0x03, \ + 0x02, \ + 0x01, \ + 0x00, \ + 0x0f, \ + 0x0e, \ + 0x0d, \ + 0x0c, \ + 0x0b, \ + 0x0a, \ + 0x09, \ + 0x08, \ + 0x37, \ + 0x36, \ + 0x35, \ + 0x34, \ + 0x33, \ + 0x32, \ + 0x31, \ + 0x30, \ + 0x3f, \ + 0x3e, \ + 0x3d, \ + 0x3c, \ + 0x3b, \ + 0x3a, \ + 0x39, \ + 0x38, \ + 0x27, \ + 0x26, \ + 0x25, \ + 0x24, \ + 0x23, \ + 0x22, \ + 0x21, \ + 0x20, \ + 0x2f, \ + 0x2e, \ + 0x2d, \ + 0x2c, \ + 0x2b, \ + 0x2a, \ + 0x29, \ + 0x28, \ } #define FNV_B64_2E \ { \ - 0x2a, 0x2b, 0x28, 0x29, 0x2e, 0x2f, 0x2c, 0x2d, \ - 0x22, 0x23, 0x20, 0x21, 0x26, 0x27, 0x24, 0x25, \ - 0x3a, 0x3b, 0x38, 0x39, 0x3e, 0x3f, 0x3c, 0x3d, \ - 0x32, 0x33, 0x30, 0x31, 0x36, 0x37, 0x34, 0x35, \ - 0x0a, 0x0b, 0x08, 0x09, 0x0e, 0x0f, 0x0c, 0x0d, \ - 0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05, \ - 0x1a, 0x1b, 0x18, 0x19, 0x1e, 0x1f, 0x1c, 0x1d, \ - 0x12, 0x13, 0x10, 0x11, 0x16, 0x17, 0x14, 0x15, \ + 0x2a, \ + 0x2b, \ + 0x28, \ + 0x29, \ + 0x2e, \ + 0x2f, \ + 0x2c, \ + 0x2d, \ + 0x22, \ + 0x23, \ + 0x20, \ + 0x21, \ + 0x26, \ + 0x27, \ + 0x24, \ + 0x25, \ + 0x3a, \ + 0x3b, \ + 0x38, \ + 0x39, \ + 0x3e, \ + 0x3f, \ + 0x3c, \ + 0x3d, \ + 0x32, \ + 0x33, \ + 0x30, \ + 0x31, \ + 0x36, \ + 0x37, \ + 0x34, \ + 0x35, \ + 0x0a, \ + 0x0b, \ + 0x08, \ + 0x09, \ + 0x0e, \ + 0x0f, \ + 0x0c, \ + 0x0d, \ + 0x02, \ + 0x03, \ + 0x00, \ + 0x01, \ + 0x06, \ + 0x07, \ + 0x04, \ + 0x05, \ + 0x1a, \ + 0x1b, \ + 0x18, \ + 0x19, \ + 0x1e, \ + 0x1f, \ + 0x1c, \ + 0x1d, \ + 0x12, \ + 0x13, \ + 0x10, \ + 0x11, \ + 0x16, \ + 0x17, \ + 0x14, \ + 0x15, \ } #define FNV_B64_2F \ { \ - 0x3d, 0x3c, 0x3f, 0x3e, 0x39, 0x38, 0x3b, 0x3a, \ - 0x35, 0x34, 0x37, 0x36, 0x31, 0x30, 0x33, 0x32, \ - 0x2d, 0x2c, 0x2f, 0x2e, 0x29, 0x28, 0x2b, 0x2a, \ - 0x25, 0x24, 0x27, 0x26, 0x21, 0x20, 0x23, 0x22, \ - 0x1d, 0x1c, 0x1f, 0x1e, 0x19, 0x18, 0x1b, 0x1a, \ - 0x15, 0x14, 0x17, 0x16, 0x11, 0x10, 0x13, 0x12, \ - 0x0d, 0x0c, 0x0f, 0x0e, 0x09, 0x08, 0x0b, 0x0a, \ - 0x05, 0x04, 0x07, 0x06, 0x01, 0x00, 0x03, 0x02, \ + 0x3d, \ + 0x3c, \ + 0x3f, \ + 0x3e, \ + 0x39, \ + 0x38, \ + 0x3b, \ + 0x3a, \ + 0x35, \ + 0x34, \ + 0x37, \ + 0x36, \ + 0x31, \ + 0x30, \ + 0x33, \ + 0x32, \ + 0x2d, \ + 0x2c, \ + 0x2f, \ + 0x2e, \ + 0x29, \ + 0x28, \ + 0x2b, \ + 0x2a, \ + 0x25, \ + 0x24, \ + 0x27, \ + 0x26, \ + 0x21, \ + 0x20, \ + 0x23, \ + 0x22, \ + 0x1d, \ + 0x1c, \ + 0x1f, \ + 0x1e, \ + 0x19, \ + 0x18, \ + 0x1b, \ + 0x1a, \ + 0x15, \ + 0x14, \ + 0x17, \ + 0x16, \ + 0x11, \ + 0x10, \ + 0x13, \ + 0x12, \ + 0x0d, \ + 0x0c, \ + 0x0f, \ + 0x0e, \ + 0x09, \ + 0x08, \ + 0x0b, \ + 0x0a, \ + 0x05, \ + 0x04, \ + 0x07, \ + 0x06, \ + 0x01, \ + 0x00, \ + 0x03, \ + 0x02, \ } #define FNV_B64_30 \ { \ - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, \ - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, \ - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \ - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, \ - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, \ - 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, \ - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, \ - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, \ + 0x10, \ + 0x11, \ + 0x12, \ + 0x13, \ + 0x14, \ + 0x15, \ + 0x16, \ + 0x17, \ + 0x18, \ + 0x19, \ + 0x1a, \ + 0x1b, \ + 0x1c, \ + 0x1d, \ + 0x1e, \ + 0x1f, \ + 0x00, \ + 0x01, \ + 0x02, \ + 0x03, \ + 0x04, \ + 0x05, \ + 0x06, \ + 0x07, \ + 0x08, \ + 0x09, \ + 0x0a, \ + 0x0b, \ + 0x0c, \ + 0x0d, \ + 0x0e, \ + 0x0f, \ + 0x30, \ + 0x31, \ + 0x32, \ + 0x33, \ + 0x34, \ + 0x35, \ + 0x36, \ + 0x37, \ + 0x38, \ + 0x39, \ + 0x3a, \ + 0x3b, \ + 0x3c, \ + 0x3d, \ + 0x3e, \ + 0x3f, \ + 0x20, \ + 0x21, \ + 0x22, \ + 0x23, \ + 0x24, \ + 0x25, \ + 0x26, \ + 0x27, \ + 0x28, \ + 0x29, \ + 0x2a, \ + 0x2b, \ + 0x2c, \ + 0x2d, \ + 0x2e, \ + 0x2f, \ } #define FNV_B64_31 \ { \ - 0x23, 0x22, 0x21, 0x20, 0x27, 0x26, 0x25, 0x24, \ - 0x2b, 0x2a, 0x29, 0x28, 0x2f, 0x2e, 0x2d, 0x2c, \ - 0x33, 0x32, 0x31, 0x30, 0x37, 0x36, 0x35, 0x34, \ - 0x3b, 0x3a, 0x39, 0x38, 0x3f, 0x3e, 0x3d, 0x3c, \ - 0x03, 0x02, 0x01, 0x00, 0x07, 0x06, 0x05, 0x04, \ - 0x0b, 0x0a, 0x09, 0x08, 0x0f, 0x0e, 0x0d, 0x0c, \ - 0x13, 0x12, 0x11, 0x10, 0x17, 0x16, 0x15, 0x14, \ - 0x1b, 0x1a, 0x19, 0x18, 0x1f, 0x1e, 0x1d, 0x1c, \ + 0x23, \ + 0x22, \ + 0x21, \ + 0x20, \ + 0x27, \ + 0x26, \ + 0x25, \ + 0x24, \ + 0x2b, \ + 0x2a, \ + 0x29, \ + 0x28, \ + 0x2f, \ + 0x2e, \ + 0x2d, \ + 0x2c, \ + 0x33, \ + 0x32, \ + 0x31, \ + 0x30, \ + 0x37, \ + 0x36, \ + 0x35, \ + 0x34, \ + 0x3b, \ + 0x3a, \ + 0x39, \ + 0x38, \ + 0x3f, \ + 0x3e, \ + 0x3d, \ + 0x3c, \ + 0x03, \ + 0x02, \ + 0x01, \ + 0x00, \ + 0x07, \ + 0x06, \ + 0x05, \ + 0x04, \ + 0x0b, \ + 0x0a, \ + 0x09, \ + 0x08, \ + 0x0f, \ + 0x0e, \ + 0x0d, \ + 0x0c, \ + 0x13, \ + 0x12, \ + 0x11, \ + 0x10, \ + 0x17, \ + 0x16, \ + 0x15, \ + 0x14, \ + 0x1b, \ + 0x1a, \ + 0x19, \ + 0x18, \ + 0x1f, \ + 0x1e, \ + 0x1d, \ + 0x1c, \ } #define FNV_B64_32 \ { \ - 0x36, 0x37, 0x34, 0x35, 0x32, 0x33, 0x30, 0x31, \ - 0x3e, 0x3f, 0x3c, 0x3d, 0x3a, 0x3b, 0x38, 0x39, \ - 0x26, 0x27, 0x24, 0x25, 0x22, 0x23, 0x20, 0x21, \ - 0x2e, 0x2f, 0x2c, 0x2d, 0x2a, 0x2b, 0x28, 0x29, \ - 0x16, 0x17, 0x14, 0x15, 0x12, 0x13, 0x10, 0x11, \ - 0x1e, 0x1f, 0x1c, 0x1d, 0x1a, 0x1b, 0x18, 0x19, \ - 0x06, 0x07, 0x04, 0x05, 0x02, 0x03, 0x00, 0x01, \ - 0x0e, 0x0f, 0x0c, 0x0d, 0x0a, 0x0b, 0x08, 0x09, \ + 0x36, \ + 0x37, \ + 0x34, \ + 0x35, \ + 0x32, \ + 0x33, \ + 0x30, \ + 0x31, \ + 0x3e, \ + 0x3f, \ + 0x3c, \ + 0x3d, \ + 0x3a, \ + 0x3b, \ + 0x38, \ + 0x39, \ + 0x26, \ + 0x27, \ + 0x24, \ + 0x25, \ + 0x22, \ + 0x23, \ + 0x20, \ + 0x21, \ + 0x2e, \ + 0x2f, \ + 0x2c, \ + 0x2d, \ + 0x2a, \ + 0x2b, \ + 0x28, \ + 0x29, \ + 0x16, \ + 0x17, \ + 0x14, \ + 0x15, \ + 0x12, \ + 0x13, \ + 0x10, \ + 0x11, \ + 0x1e, \ + 0x1f, \ + 0x1c, \ + 0x1d, \ + 0x1a, \ + 0x1b, \ + 0x18, \ + 0x19, \ + 0x06, \ + 0x07, \ + 0x04, \ + 0x05, \ + 0x02, \ + 0x03, \ + 0x00, \ + 0x01, \ + 0x0e, \ + 0x0f, \ + 0x0c, \ + 0x0d, \ + 0x0a, \ + 0x0b, \ + 0x08, \ + 0x09, \ } #define FNV_B64_33 \ { \ - 0x09, 0x08, 0x0b, 0x0a, 0x0d, 0x0c, 0x0f, 0x0e, \ - 0x01, 0x00, 0x03, 0x02, 0x05, 0x04, 0x07, 0x06, \ - 0x19, 0x18, 0x1b, 0x1a, 0x1d, 0x1c, 0x1f, 0x1e, \ - 0x11, 0x10, 0x13, 0x12, 0x15, 0x14, 0x17, 0x16, \ - 0x29, 0x28, 0x2b, 0x2a, 0x2d, 0x2c, 0x2f, 0x2e, \ - 0x21, 0x20, 0x23, 0x22, 0x25, 0x24, 0x27, 0x26, \ - 0x39, 0x38, 0x3b, 0x3a, 0x3d, 0x3c, 0x3f, 0x3e, \ - 0x31, 0x30, 0x33, 0x32, 0x35, 0x34, 0x37, 0x36, \ + 0x09, \ + 0x08, \ + 0x0b, \ + 0x0a, \ + 0x0d, \ + 0x0c, \ + 0x0f, \ + 0x0e, \ + 0x01, \ + 0x00, \ + 0x03, \ + 0x02, \ + 0x05, \ + 0x04, \ + 0x07, \ + 0x06, \ + 0x19, \ + 0x18, \ + 0x1b, \ + 0x1a, \ + 0x1d, \ + 0x1c, \ + 0x1f, \ + 0x1e, \ + 0x11, \ + 0x10, \ + 0x13, \ + 0x12, \ + 0x15, \ + 0x14, \ + 0x17, \ + 0x16, \ + 0x29, \ + 0x28, \ + 0x2b, \ + 0x2a, \ + 0x2d, \ + 0x2c, \ + 0x2f, \ + 0x2e, \ + 0x21, \ + 0x20, \ + 0x23, \ + 0x22, \ + 0x25, \ + 0x24, \ + 0x27, \ + 0x26, \ + 0x39, \ + 0x38, \ + 0x3b, \ + 0x3a, \ + 0x3d, \ + 0x3c, \ + 0x3f, \ + 0x3e, \ + 0x31, \ + 0x30, \ + 0x33, \ + 0x32, \ + 0x35, \ + 0x34, \ + 0x37, \ + 0x36, \ } #define FNV_B64_34 \ { \ - 0x1c, 0x1d, 0x1e, 0x1f, 0x18, 0x19, 0x1a, 0x1b, \ - 0x14, 0x15, 0x16, 0x17, 0x10, 0x11, 0x12, 0x13, \ - 0x0c, 0x0d, 0x0e, 0x0f, 0x08, 0x09, 0x0a, 0x0b, \ - 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, \ - 0x3c, 0x3d, 0x3e, 0x3f, 0x38, 0x39, 0x3a, 0x3b, \ - 0x34, 0x35, 0x36, 0x37, 0x30, 0x31, 0x32, 0x33, \ - 0x2c, 0x2d, 0x2e, 0x2f, 0x28, 0x29, 0x2a, 0x2b, \ - 0x24, 0x25, 0x26, 0x27, 0x20, 0x21, 0x22, 0x23, \ + 0x1c, \ + 0x1d, \ + 0x1e, \ + 0x1f, \ + 0x18, \ + 0x19, \ + 0x1a, \ + 0x1b, \ + 0x14, \ + 0x15, \ + 0x16, \ + 0x17, \ + 0x10, \ + 0x11, \ + 0x12, \ + 0x13, \ + 0x0c, \ + 0x0d, \ + 0x0e, \ + 0x0f, \ + 0x08, \ + 0x09, \ + 0x0a, \ + 0x0b, \ + 0x04, \ + 0x05, \ + 0x06, \ + 0x07, \ + 0x00, \ + 0x01, \ + 0x02, \ + 0x03, \ + 0x3c, \ + 0x3d, \ + 0x3e, \ + 0x3f, \ + 0x38, \ + 0x39, \ + 0x3a, \ + 0x3b, \ + 0x34, \ + 0x35, \ + 0x36, \ + 0x37, \ + 0x30, \ + 0x31, \ + 0x32, \ + 0x33, \ + 0x2c, \ + 0x2d, \ + 0x2e, \ + 0x2f, \ + 0x28, \ + 0x29, \ + 0x2a, \ + 0x2b, \ + 0x24, \ + 0x25, \ + 0x26, \ + 0x27, \ + 0x20, \ + 0x21, \ + 0x22, \ + 0x23, \ } #define FNV_B64_35 \ { \ - 0x2f, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x28, \ - 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x20, \ - 0x3f, 0x3e, 0x3d, 0x3c, 0x3b, 0x3a, 0x39, 0x38, \ - 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x30, \ - 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, \ - 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, \ - 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, \ - 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, \ + 0x2f, \ + 0x2e, \ + 0x2d, \ + 0x2c, \ + 0x2b, \ + 0x2a, \ + 0x29, \ + 0x28, \ + 0x27, \ + 0x26, \ + 0x25, \ + 0x24, \ + 0x23, \ + 0x22, \ + 0x21, \ + 0x20, \ + 0x3f, \ + 0x3e, \ + 0x3d, \ + 0x3c, \ + 0x3b, \ + 0x3a, \ + 0x39, \ + 0x38, \ + 0x37, \ + 0x36, \ + 0x35, \ + 0x34, \ + 0x33, \ + 0x32, \ + 0x31, \ + 0x30, \ + 0x0f, \ + 0x0e, \ + 0x0d, \ + 0x0c, \ + 0x0b, \ + 0x0a, \ + 0x09, \ + 0x08, \ + 0x07, \ + 0x06, \ + 0x05, \ + 0x04, \ + 0x03, \ + 0x02, \ + 0x01, \ + 0x00, \ + 0x1f, \ + 0x1e, \ + 0x1d, \ + 0x1c, \ + 0x1b, \ + 0x1a, \ + 0x19, \ + 0x18, \ + 0x17, \ + 0x16, \ + 0x15, \ + 0x14, \ + 0x13, \ + 0x12, \ + 0x11, \ + 0x10, \ } #define FNV_B64_36 \ { \ - 0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05, \ - 0x0a, 0x0b, 0x08, 0x09, 0x0e, 0x0f, 0x0c, 0x0d, \ - 0x12, 0x13, 0x10, 0x11, 0x16, 0x17, 0x14, 0x15, \ - 0x1a, 0x1b, 0x18, 0x19, 0x1e, 0x1f, 0x1c, 0x1d, \ - 0x22, 0x23, 0x20, 0x21, 0x26, 0x27, 0x24, 0x25, \ - 0x2a, 0x2b, 0x28, 0x29, 0x2e, 0x2f, 0x2c, 0x2d, \ - 0x32, 0x33, 0x30, 0x31, 0x36, 0x37, 0x34, 0x35, \ - 0x3a, 0x3b, 0x38, 0x39, 0x3e, 0x3f, 0x3c, 0x3d, \ + 0x02, \ + 0x03, \ + 0x00, \ + 0x01, \ + 0x06, \ + 0x07, \ + 0x04, \ + 0x05, \ + 0x0a, \ + 0x0b, \ + 0x08, \ + 0x09, \ + 0x0e, \ + 0x0f, \ + 0x0c, \ + 0x0d, \ + 0x12, \ + 0x13, \ + 0x10, \ + 0x11, \ + 0x16, \ + 0x17, \ + 0x14, \ + 0x15, \ + 0x1a, \ + 0x1b, \ + 0x18, \ + 0x19, \ + 0x1e, \ + 0x1f, \ + 0x1c, \ + 0x1d, \ + 0x22, \ + 0x23, \ + 0x20, \ + 0x21, \ + 0x26, \ + 0x27, \ + 0x24, \ + 0x25, \ + 0x2a, \ + 0x2b, \ + 0x28, \ + 0x29, \ + 0x2e, \ + 0x2f, \ + 0x2c, \ + 0x2d, \ + 0x32, \ + 0x33, \ + 0x30, \ + 0x31, \ + 0x36, \ + 0x37, \ + 0x34, \ + 0x35, \ + 0x3a, \ + 0x3b, \ + 0x38, \ + 0x39, \ + 0x3e, \ + 0x3f, \ + 0x3c, \ + 0x3d, \ } #define FNV_B64_37 \ { \ - 0x15, 0x14, 0x17, 0x16, 0x11, 0x10, 0x13, 0x12, \ - 0x1d, 0x1c, 0x1f, 0x1e, 0x19, 0x18, 0x1b, 0x1a, \ - 0x05, 0x04, 0x07, 0x06, 0x01, 0x00, 0x03, 0x02, \ - 0x0d, 0x0c, 0x0f, 0x0e, 0x09, 0x08, 0x0b, 0x0a, \ - 0x35, 0x34, 0x37, 0x36, 0x31, 0x30, 0x33, 0x32, \ - 0x3d, 0x3c, 0x3f, 0x3e, 0x39, 0x38, 0x3b, 0x3a, \ - 0x25, 0x24, 0x27, 0x26, 0x21, 0x20, 0x23, 0x22, \ - 0x2d, 0x2c, 0x2f, 0x2e, 0x29, 0x28, 0x2b, 0x2a, \ + 0x15, \ + 0x14, \ + 0x17, \ + 0x16, \ + 0x11, \ + 0x10, \ + 0x13, \ + 0x12, \ + 0x1d, \ + 0x1c, \ + 0x1f, \ + 0x1e, \ + 0x19, \ + 0x18, \ + 0x1b, \ + 0x1a, \ + 0x05, \ + 0x04, \ + 0x07, \ + 0x06, \ + 0x01, \ + 0x00, \ + 0x03, \ + 0x02, \ + 0x0d, \ + 0x0c, \ + 0x0f, \ + 0x0e, \ + 0x09, \ + 0x08, \ + 0x0b, \ + 0x0a, \ + 0x35, \ + 0x34, \ + 0x37, \ + 0x36, \ + 0x31, \ + 0x30, \ + 0x33, \ + 0x32, \ + 0x3d, \ + 0x3c, \ + 0x3f, \ + 0x3e, \ + 0x39, \ + 0x38, \ + 0x3b, \ + 0x3a, \ + 0x25, \ + 0x24, \ + 0x27, \ + 0x26, \ + 0x21, \ + 0x20, \ + 0x23, \ + 0x22, \ + 0x2d, \ + 0x2c, \ + 0x2f, \ + 0x2e, \ + 0x29, \ + 0x28, \ + 0x2b, \ + 0x2a, \ } #define FNV_B64_38 \ { \ - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, \ - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, \ - 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, \ - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, \ - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, \ - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \ - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, \ - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, \ + 0x28, \ + 0x29, \ + 0x2a, \ + 0x2b, \ + 0x2c, \ + 0x2d, \ + 0x2e, \ + 0x2f, \ + 0x20, \ + 0x21, \ + 0x22, \ + 0x23, \ + 0x24, \ + 0x25, \ + 0x26, \ + 0x27, \ + 0x38, \ + 0x39, \ + 0x3a, \ + 0x3b, \ + 0x3c, \ + 0x3d, \ + 0x3e, \ + 0x3f, \ + 0x30, \ + 0x31, \ + 0x32, \ + 0x33, \ + 0x34, \ + 0x35, \ + 0x36, \ + 0x37, \ + 0x08, \ + 0x09, \ + 0x0a, \ + 0x0b, \ + 0x0c, \ + 0x0d, \ + 0x0e, \ + 0x0f, \ + 0x00, \ + 0x01, \ + 0x02, \ + 0x03, \ + 0x04, \ + 0x05, \ + 0x06, \ + 0x07, \ + 0x18, \ + 0x19, \ + 0x1a, \ + 0x1b, \ + 0x1c, \ + 0x1d, \ + 0x1e, \ + 0x1f, \ + 0x10, \ + 0x11, \ + 0x12, \ + 0x13, \ + 0x14, \ + 0x15, \ + 0x16, \ + 0x17, \ } #define FNV_B64_39 \ { \ - 0x3b, 0x3a, 0x39, 0x38, 0x3f, 0x3e, 0x3d, 0x3c, \ - 0x33, 0x32, 0x31, 0x30, 0x37, 0x36, 0x35, 0x34, \ - 0x2b, 0x2a, 0x29, 0x28, 0x2f, 0x2e, 0x2d, 0x2c, \ - 0x23, 0x22, 0x21, 0x20, 0x27, 0x26, 0x25, 0x24, \ - 0x1b, 0x1a, 0x19, 0x18, 0x1f, 0x1e, 0x1d, 0x1c, \ - 0x13, 0x12, 0x11, 0x10, 0x17, 0x16, 0x15, 0x14, \ - 0x0b, 0x0a, 0x09, 0x08, 0x0f, 0x0e, 0x0d, 0x0c, \ - 0x03, 0x02, 0x01, 0x00, 0x07, 0x06, 0x05, 0x04, \ + 0x3b, \ + 0x3a, \ + 0x39, \ + 0x38, \ + 0x3f, \ + 0x3e, \ + 0x3d, \ + 0x3c, \ + 0x33, \ + 0x32, \ + 0x31, \ + 0x30, \ + 0x37, \ + 0x36, \ + 0x35, \ + 0x34, \ + 0x2b, \ + 0x2a, \ + 0x29, \ + 0x28, \ + 0x2f, \ + 0x2e, \ + 0x2d, \ + 0x2c, \ + 0x23, \ + 0x22, \ + 0x21, \ + 0x20, \ + 0x27, \ + 0x26, \ + 0x25, \ + 0x24, \ + 0x1b, \ + 0x1a, \ + 0x19, \ + 0x18, \ + 0x1f, \ + 0x1e, \ + 0x1d, \ + 0x1c, \ + 0x13, \ + 0x12, \ + 0x11, \ + 0x10, \ + 0x17, \ + 0x16, \ + 0x15, \ + 0x14, \ + 0x0b, \ + 0x0a, \ + 0x09, \ + 0x08, \ + 0x0f, \ + 0x0e, \ + 0x0d, \ + 0x0c, \ + 0x03, \ + 0x02, \ + 0x01, \ + 0x00, \ + 0x07, \ + 0x06, \ + 0x05, \ + 0x04, \ } #define FNV_B64_3A \ { \ - 0x0e, 0x0f, 0x0c, 0x0d, 0x0a, 0x0b, 0x08, 0x09, \ - 0x06, 0x07, 0x04, 0x05, 0x02, 0x03, 0x00, 0x01, \ - 0x1e, 0x1f, 0x1c, 0x1d, 0x1a, 0x1b, 0x18, 0x19, \ - 0x16, 0x17, 0x14, 0x15, 0x12, 0x13, 0x10, 0x11, \ - 0x2e, 0x2f, 0x2c, 0x2d, 0x2a, 0x2b, 0x28, 0x29, \ - 0x26, 0x27, 0x24, 0x25, 0x22, 0x23, 0x20, 0x21, \ - 0x3e, 0x3f, 0x3c, 0x3d, 0x3a, 0x3b, 0x38, 0x39, \ - 0x36, 0x37, 0x34, 0x35, 0x32, 0x33, 0x30, 0x31, \ + 0x0e, \ + 0x0f, \ + 0x0c, \ + 0x0d, \ + 0x0a, \ + 0x0b, \ + 0x08, \ + 0x09, \ + 0x06, \ + 0x07, \ + 0x04, \ + 0x05, \ + 0x02, \ + 0x03, \ + 0x00, \ + 0x01, \ + 0x1e, \ + 0x1f, \ + 0x1c, \ + 0x1d, \ + 0x1a, \ + 0x1b, \ + 0x18, \ + 0x19, \ + 0x16, \ + 0x17, \ + 0x14, \ + 0x15, \ + 0x12, \ + 0x13, \ + 0x10, \ + 0x11, \ + 0x2e, \ + 0x2f, \ + 0x2c, \ + 0x2d, \ + 0x2a, \ + 0x2b, \ + 0x28, \ + 0x29, \ + 0x26, \ + 0x27, \ + 0x24, \ + 0x25, \ + 0x22, \ + 0x23, \ + 0x20, \ + 0x21, \ + 0x3e, \ + 0x3f, \ + 0x3c, \ + 0x3d, \ + 0x3a, \ + 0x3b, \ + 0x38, \ + 0x39, \ + 0x36, \ + 0x37, \ + 0x34, \ + 0x35, \ + 0x32, \ + 0x33, \ + 0x30, \ + 0x31, \ } #define FNV_B64_3B \ { \ - 0x21, 0x20, 0x23, 0x22, 0x25, 0x24, 0x27, 0x26, \ - 0x29, 0x28, 0x2b, 0x2a, 0x2d, 0x2c, 0x2f, 0x2e, \ - 0x31, 0x30, 0x33, 0x32, 0x35, 0x34, 0x37, 0x36, \ - 0x39, 0x38, 0x3b, 0x3a, 0x3d, 0x3c, 0x3f, 0x3e, \ - 0x01, 0x00, 0x03, 0x02, 0x05, 0x04, 0x07, 0x06, \ - 0x09, 0x08, 0x0b, 0x0a, 0x0d, 0x0c, 0x0f, 0x0e, \ - 0x11, 0x10, 0x13, 0x12, 0x15, 0x14, 0x17, 0x16, \ - 0x19, 0x18, 0x1b, 0x1a, 0x1d, 0x1c, 0x1f, 0x1e, \ + 0x21, \ + 0x20, \ + 0x23, \ + 0x22, \ + 0x25, \ + 0x24, \ + 0x27, \ + 0x26, \ + 0x29, \ + 0x28, \ + 0x2b, \ + 0x2a, \ + 0x2d, \ + 0x2c, \ + 0x2f, \ + 0x2e, \ + 0x31, \ + 0x30, \ + 0x33, \ + 0x32, \ + 0x35, \ + 0x34, \ + 0x37, \ + 0x36, \ + 0x39, \ + 0x38, \ + 0x3b, \ + 0x3a, \ + 0x3d, \ + 0x3c, \ + 0x3f, \ + 0x3e, \ + 0x01, \ + 0x00, \ + 0x03, \ + 0x02, \ + 0x05, \ + 0x04, \ + 0x07, \ + 0x06, \ + 0x09, \ + 0x08, \ + 0x0b, \ + 0x0a, \ + 0x0d, \ + 0x0c, \ + 0x0f, \ + 0x0e, \ + 0x11, \ + 0x10, \ + 0x13, \ + 0x12, \ + 0x15, \ + 0x14, \ + 0x17, \ + 0x16, \ + 0x19, \ + 0x18, \ + 0x1b, \ + 0x1a, \ + 0x1d, \ + 0x1c, \ + 0x1f, \ + 0x1e, \ } #define FNV_B64_3C \ { \ - 0x34, 0x35, 0x36, 0x37, 0x30, 0x31, 0x32, 0x33, \ - 0x3c, 0x3d, 0x3e, 0x3f, 0x38, 0x39, 0x3a, 0x3b, \ - 0x24, 0x25, 0x26, 0x27, 0x20, 0x21, 0x22, 0x23, \ - 0x2c, 0x2d, 0x2e, 0x2f, 0x28, 0x29, 0x2a, 0x2b, \ - 0x14, 0x15, 0x16, 0x17, 0x10, 0x11, 0x12, 0x13, \ - 0x1c, 0x1d, 0x1e, 0x1f, 0x18, 0x19, 0x1a, 0x1b, \ - 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, \ - 0x0c, 0x0d, 0x0e, 0x0f, 0x08, 0x09, 0x0a, 0x0b, \ + 0x34, \ + 0x35, \ + 0x36, \ + 0x37, \ + 0x30, \ + 0x31, \ + 0x32, \ + 0x33, \ + 0x3c, \ + 0x3d, \ + 0x3e, \ + 0x3f, \ + 0x38, \ + 0x39, \ + 0x3a, \ + 0x3b, \ + 0x24, \ + 0x25, \ + 0x26, \ + 0x27, \ + 0x20, \ + 0x21, \ + 0x22, \ + 0x23, \ + 0x2c, \ + 0x2d, \ + 0x2e, \ + 0x2f, \ + 0x28, \ + 0x29, \ + 0x2a, \ + 0x2b, \ + 0x14, \ + 0x15, \ + 0x16, \ + 0x17, \ + 0x10, \ + 0x11, \ + 0x12, \ + 0x13, \ + 0x1c, \ + 0x1d, \ + 0x1e, \ + 0x1f, \ + 0x18, \ + 0x19, \ + 0x1a, \ + 0x1b, \ + 0x04, \ + 0x05, \ + 0x06, \ + 0x07, \ + 0x00, \ + 0x01, \ + 0x02, \ + 0x03, \ + 0x0c, \ + 0x0d, \ + 0x0e, \ + 0x0f, \ + 0x08, \ + 0x09, \ + 0x0a, \ + 0x0b, \ } #define FNV_B64_3D \ { \ - 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, \ - 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, \ - 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, \ - 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, \ - 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x20, \ - 0x2f, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x28, \ - 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x30, \ - 0x3f, 0x3e, 0x3d, 0x3c, 0x3b, 0x3a, 0x39, 0x38, \ + 0x07, \ + 0x06, \ + 0x05, \ + 0x04, \ + 0x03, \ + 0x02, \ + 0x01, \ + 0x00, \ + 0x0f, \ + 0x0e, \ + 0x0d, \ + 0x0c, \ + 0x0b, \ + 0x0a, \ + 0x09, \ + 0x08, \ + 0x17, \ + 0x16, \ + 0x15, \ + 0x14, \ + 0x13, \ + 0x12, \ + 0x11, \ + 0x10, \ + 0x1f, \ + 0x1e, \ + 0x1d, \ + 0x1c, \ + 0x1b, \ + 0x1a, \ + 0x19, \ + 0x18, \ + 0x27, \ + 0x26, \ + 0x25, \ + 0x24, \ + 0x23, \ + 0x22, \ + 0x21, \ + 0x20, \ + 0x2f, \ + 0x2e, \ + 0x2d, \ + 0x2c, \ + 0x2b, \ + 0x2a, \ + 0x29, \ + 0x28, \ + 0x37, \ + 0x36, \ + 0x35, \ + 0x34, \ + 0x33, \ + 0x32, \ + 0x31, \ + 0x30, \ + 0x3f, \ + 0x3e, \ + 0x3d, \ + 0x3c, \ + 0x3b, \ + 0x3a, \ + 0x39, \ + 0x38, \ } #define FNV_B64_3E \ { \ - 0x1a, 0x1b, 0x18, 0x19, 0x1e, 0x1f, 0x1c, 0x1d, \ - 0x12, 0x13, 0x10, 0x11, 0x16, 0x17, 0x14, 0x15, \ - 0x0a, 0x0b, 0x08, 0x09, 0x0e, 0x0f, 0x0c, 0x0d, \ - 0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05, \ - 0x3a, 0x3b, 0x38, 0x39, 0x3e, 0x3f, 0x3c, 0x3d, \ - 0x32, 0x33, 0x30, 0x31, 0x36, 0x37, 0x34, 0x35, \ - 0x2a, 0x2b, 0x28, 0x29, 0x2e, 0x2f, 0x2c, 0x2d, \ - 0x22, 0x23, 0x20, 0x21, 0x26, 0x27, 0x24, 0x25, \ + 0x1a, \ + 0x1b, \ + 0x18, \ + 0x19, \ + 0x1e, \ + 0x1f, \ + 0x1c, \ + 0x1d, \ + 0x12, \ + 0x13, \ + 0x10, \ + 0x11, \ + 0x16, \ + 0x17, \ + 0x14, \ + 0x15, \ + 0x0a, \ + 0x0b, \ + 0x08, \ + 0x09, \ + 0x0e, \ + 0x0f, \ + 0x0c, \ + 0x0d, \ + 0x02, \ + 0x03, \ + 0x00, \ + 0x01, \ + 0x06, \ + 0x07, \ + 0x04, \ + 0x05, \ + 0x3a, \ + 0x3b, \ + 0x38, \ + 0x39, \ + 0x3e, \ + 0x3f, \ + 0x3c, \ + 0x3d, \ + 0x32, \ + 0x33, \ + 0x30, \ + 0x31, \ + 0x36, \ + 0x37, \ + 0x34, \ + 0x35, \ + 0x2a, \ + 0x2b, \ + 0x28, \ + 0x29, \ + 0x2e, \ + 0x2f, \ + 0x2c, \ + 0x2d, \ + 0x22, \ + 0x23, \ + 0x20, \ + 0x21, \ + 0x26, \ + 0x27, \ + 0x24, \ + 0x25, \ } #define FNV_B64_3F \ { \ - 0x2d, 0x2c, 0x2f, 0x2e, 0x29, 0x28, 0x2b, 0x2a, \ - 0x25, 0x24, 0x27, 0x26, 0x21, 0x20, 0x23, 0x22, \ - 0x3d, 0x3c, 0x3f, 0x3e, 0x39, 0x38, 0x3b, 0x3a, \ - 0x35, 0x34, 0x37, 0x36, 0x31, 0x30, 0x33, 0x32, \ - 0x0d, 0x0c, 0x0f, 0x0e, 0x09, 0x08, 0x0b, 0x0a, \ - 0x05, 0x04, 0x07, 0x06, 0x01, 0x00, 0x03, 0x02, \ - 0x1d, 0x1c, 0x1f, 0x1e, 0x19, 0x18, 0x1b, 0x1a, \ - 0x15, 0x14, 0x17, 0x16, 0x11, 0x10, 0x13, 0x12, \ + 0x2d, \ + 0x2c, \ + 0x2f, \ + 0x2e, \ + 0x29, \ + 0x28, \ + 0x2b, \ + 0x2a, \ + 0x25, \ + 0x24, \ + 0x27, \ + 0x26, \ + 0x21, \ + 0x20, \ + 0x23, \ + 0x22, \ + 0x3d, \ + 0x3c, \ + 0x3f, \ + 0x3e, \ + 0x39, \ + 0x38, \ + 0x3b, \ + 0x3a, \ + 0x35, \ + 0x34, \ + 0x37, \ + 0x36, \ + 0x31, \ + 0x30, \ + 0x33, \ + 0x32, \ + 0x0d, \ + 0x0c, \ + 0x0f, \ + 0x0e, \ + 0x09, \ + 0x08, \ + 0x0b, \ + 0x0a, \ + 0x05, \ + 0x04, \ + 0x07, \ + 0x06, \ + 0x01, \ + 0x00, \ + 0x03, \ + 0x02, \ + 0x1d, \ + 0x1c, \ + 0x1f, \ + 0x1e, \ + 0x19, \ + 0x18, \ + 0x1b, \ + 0x1a, \ + 0x15, \ + 0x14, \ + 0x17, \ + 0x16, \ + 0x11, \ + 0x10, \ + 0x13, \ + 0x12, \ } #endif /* FNV_HASH_H */ diff --git a/librz/include/rz_bin.h b/librz/include/rz_bin.h index 592981a30fa..828966f56a5 100644 --- a/librz/include/rz_bin.h +++ b/librz/include/rz_bin.h @@ -165,7 +165,7 @@ typedef enum { } RzBinLanguage; #define RZ_BIN_LANGUAGE_MASK(x) ((x) & ~RZ_BIN_LANGUAGE_BLOCKS) -#define RZ_BIN_LANGUAGE_HAS_BLOCKS(x) ((x)&RZ_BIN_LANGUAGE_BLOCKS) +#define RZ_BIN_LANGUAGE_HAS_BLOCKS(x) ((x) & RZ_BIN_LANGUAGE_BLOCKS) enum { RZ_BIN_CLASS_PRIVATE, diff --git a/librz/include/rz_cons.h b/librz/include/rz_cons.h index 0e2bee4438a..a3b7e904e3e 100644 --- a/librz/include/rz_cons.h +++ b/librz/include/rz_cons.h @@ -761,8 +761,8 @@ typedef struct rz_cons_t { #define Colors_PLAIN \ { \ Color_BLACK, Color_RED, Color_WHITE, \ - Color_GREEN, Color_MAGENTA, Color_YELLOW, \ - Color_CYAN, Color_BLUE, Color_GRAY \ + Color_GREEN, Color_MAGENTA, Color_YELLOW, \ + Color_CYAN, Color_BLUE, Color_GRAY \ } enum { diff --git a/librz/include/rz_magic.h b/librz/include/rz_magic.h index a8802d2504e..6367b6350b3 100644 --- a/librz/include/rz_magic.h +++ b/librz/include/rz_magic.h @@ -66,7 +66,7 @@ struct rz_magic { #define UNSIGNED 0x08 /* comparison is unsigned */ #define NOSPACE 0x10 /* suppress space character before output */ #define BINTEST 0x20 /* test is for a binary type (set only \ - for top-level tests) */ + for top-level tests) */ #define TEXTTEST 0 /* for passing to file_softmagic */ ut8 dummy1; diff --git a/librz/include/rz_types.h b/librz/include/rz_types.h index f1c758adc79..8fe3c581b0c 100644 --- a/librz/include/rz_types.h +++ b/librz/include/rz_types.h @@ -632,7 +632,7 @@ static inline void rz_run_call10(void *fcn, void *arg1, void *arg2, void *arg3, #ifndef container_of #ifdef _MSC_VER -#define container_of(ptr, type, member) ((type *)((char *)(ptr)-offsetof(type, member))) +#define container_of(ptr, type, member) ((type *)((char *)(ptr) - offsetof(type, member))) #else #define container_of(ptr, type, member) ((type *)((char *)(__typeof__(((type *)0)->member) *){ ptr } - offsetof(type, member))) #endif diff --git a/librz/include/rz_types_base.h b/librz/include/rz_types_base.h index 7cd3bc70a51..8f7501e6425 100644 --- a/librz/include/rz_types_base.h +++ b/librz/include/rz_types_base.h @@ -112,7 +112,7 @@ typedef struct _utX { #define UT32_ALIGN(x) (x + (x - (x % sizeof(ut32)))) #define UT16_ALIGN(x) (x + (x - (x % sizeof(ut16)))) -#define UT32_LO(x) ((ut32)((x)&UT32_MAX)) +#define UT32_LO(x) ((ut32)((x) & UT32_MAX)) #define UT32_HI(x) ((ut32)(((ut64)(x)) >> 32) & UT32_MAX) #define RZ_BETWEEN(x, y, z) (((y) >= (x)) && ((y) <= (z))) @@ -135,7 +135,7 @@ typedef struct _utX { /* copied from bithacks.h */ #define B_IS_SET(x, n) (((x) & (1ULL << (n))) ? 1 : 0) #define B_SET(x, n) ((x) |= (1ULL << (n))) -#define B_EVEN(x) (((x)&1) == 0) +#define B_EVEN(x) (((x) & 1) == 0) #define B_ODD(x) (!B_EVEN((x))) #define B_UNSET(x, n) ((x) &= ~(1ULL << (n))) #define B_TOGGLE(x, n) ((x) ^= (1ULL << (n))) diff --git a/librz/magic/apprentice.c b/librz/magic/apprentice.c index 275e6d50798..6721078809c 100644 --- a/librz/magic/apprentice.c +++ b/librz/magic/apprentice.c @@ -49,14 +49,14 @@ #ifdef _MSC_VER #include #include -#define S_ISREG(m) (((m)&S_IFMT) == S_IFREG) -#define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) +#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) #define MAXPATHLEN 255 #endif #define EATAB \ { \ - while (isascii((ut8)*l) && isspace((ut8)*l)) { \ + while (isascii((ut8) * l) && isspace((ut8) * l)) { \ l++; \ } \ } diff --git a/librz/magic/fsmagic.c b/librz/magic/fsmagic.c index 697f8eef951..8e35fa7cf77 100644 --- a/librz/magic/fsmagic.c +++ b/librz/magic/fsmagic.c @@ -54,7 +54,7 @@ #ifndef HAVE_MAJOR #define major(dev) (((dev) >> 8) & 0xff) -#define minor(dev) ((dev)&0xff) +#define minor(dev) ((dev) & 0xff) #endif #undef HAVE_MAJOR diff --git a/librz/magic/magic.c b/librz/magic/magic.c index 278a250bfb8..06751548faa 100644 --- a/librz/magic/magic.c +++ b/librz/magic/magic.c @@ -10,10 +10,10 @@ RZ_LIB_VERSION(rz_magic); #ifdef _MSC_VER #include #include -#define S_ISREG(m) (((m)&S_IFMT) == S_IFREG) -#define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) +#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) #define S_IFIFO (-1) -#define S_ISFIFO(m) (((m)&S_IFIFO) == S_IFIFO) +#define S_ISFIFO(m) (((m) & S_IFIFO) == S_IFIFO) #define MAXPATHLEN 255 #endif diff --git a/librz/type/format.c b/librz/type/format.c index faf6763fade..2a27e372ebc 100644 --- a/librz/type/format.c +++ b/librz/type/format.c @@ -1895,7 +1895,7 @@ static char *get_format_type(const char fmt, const char arg) { return type; } -#define MINUSONE ((void *)(size_t)-1) +#define MINUSONE ((void *)(size_t) - 1) #define ISSTRUCT (tmp == '?' || (tmp == '*' && *(arg + 1) == '?')) RZ_API const char *rz_type_db_format_get(const RzTypeDB *typedb, const char *name) { diff --git a/librz/util/bitvector.c b/librz/util/bitvector.c index fb4655182ff..044e7b8070a 100644 --- a/librz/util/bitvector.c +++ b/librz/util/bitvector.c @@ -5,12 +5,12 @@ #include #include -#define NELEM(N, ELEMPER) ((N + (ELEMPER)-1) / (ELEMPER)) +#define NELEM(N, ELEMPER) ((N + (ELEMPER) - 1) / (ELEMPER)) #define BV_ELEM_SIZE 8U // optimization for reversing 8 bits which uses 32 bits // https://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith32Bits -#define reverse_byte(x) ((((x)*0x0802LU & 0x22110LU) | ((x)*0x8020LU & 0x88440LU)) * 0x10101LU >> 16) +#define reverse_byte(x) ((((x) * 0x0802LU & 0x22110LU) | ((x) * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16) // https://graphics.stanford.edu/~seander/bithacks.html#BitReverseObvious // With changes. diff --git a/librz/util/sdb/src/cdb_make.c b/librz/util/sdb/src/cdb_make.c index 8f39bfe91a3..f7486a860c1 100644 --- a/librz/util/sdb/src/cdb_make.c +++ b/librz/util/sdb/src/cdb_make.c @@ -69,7 +69,7 @@ static int pack_kvlen(ut8 *buf, ut32 klen, ut32 vlen) { return 0; } buf[0] = (ut8)klen; - buf[1] = (ut8)((vlen)&0xff); + buf[1] = (ut8)((vlen) & 0xff); buf[2] = (ut8)((vlen >> 8) & 0xff); buf[3] = (ut8)((vlen >> 16) & 0xff); return 1; diff --git a/librz/util/unum.c b/librz/util/unum.c index e0a87203cff..5a29a648fbc 100644 --- a/librz/util/unum.c +++ b/librz/util/unum.c @@ -637,7 +637,7 @@ RZ_API ut64 rz_num_get_input_value(RzNum *num, const char *input_value) { return value; } -#define NIBBLE_TO_HEX(n) (((n)&0xf) > 9 ? 'a' + ((n)&0xf) - 10 : '0' + ((n)&0xf)) +#define NIBBLE_TO_HEX(n) (((n) & 0xf) > 9 ? 'a' + ((n) & 0xf) - 10 : '0' + ((n) & 0xf)) static int escape_char(char *dst, char byte) { const char escape_map[] = "abtnvfr"; if (byte >= 7 && byte <= 13) { From e8cd52372e394583ee4f2bdd5e1dff293eb21563 Mon Sep 17 00:00:00 2001 From: tushar3q34 Date: Tue, 3 Sep 2024 13:50:26 +0530 Subject: [PATCH 3/4] Formatting Corrected --- librz/arch/isa/amd29k/amd29k.c | 2 +- librz/arch/isa/arm/armass.c | 6 +- librz/arch/isa/avr/assembler.c | 2 +- librz/arch/isa/avr/avr_esil.c | 4 +- librz/arch/isa/lh5801/lh5801.c | 4 +- librz/arch/isa/luac/v53/arch_53.h | 4 +- librz/arch/isa/luac/v54/arch_54.h | 6 +- librz/arch/isa/ppc/libps/libps_internal.h | 6 +- librz/arch/isa/rx/rx_opcode_detail.c | 5 +- librz/arch/isa/rx/rx_str.inc | 4 +- librz/arch/isa/v810/v810_disas.h | 12 +- librz/arch/p/analysis/analysis_i4004.c | 2 +- librz/arch/p/analysis/analysis_pyc.c | 2 +- librz/arch/p/analysis/analysis_sh.c | 214 +- .../arch/p_gnu/analysis/analysis_sparc_gnu.c | 2 +- librz/bin/format/elf/glibc_elf.h | 80 +- librz/bin/format/java/class_attribute.h | 2 +- librz/bin/format/mach0/mach0_defines.h | 2 +- librz/bin/format/objc/mach0_classes.c | 2 +- librz/bin/format/pe/pe_rsrc.c | 2 +- librz/bin/p/bin_avr.c | 8 +- librz/bin/p/bin_elf.inc | 2 +- librz/core/cbin.c | 14 +- librz/core/windows_heap.c | 6 +- librz/crypto/des.c | 4 +- librz/crypto/p/crypto_blowfish.c | 2 +- librz/egg/emit_x86.c | 2 +- librz/hash/algorithms/sm3/sm3.c | 2 +- librz/hash/algorithms/ssdeep/fnv_hash.h | 4608 ++--------------- librz/include/rz_bin.h | 2 +- librz/include/rz_cons.h | 4 +- librz/include/rz_magic.h | 2 +- librz/include/rz_types.h | 2 +- librz/include/rz_types_base.h | 4 +- librz/magic/apprentice.c | 6 +- librz/magic/fsmagic.c | 2 +- librz/magic/magic.c | 6 +- librz/type/format.c | 2 +- librz/util/bitvector.c | 4 +- librz/util/sdb/src/cdb_make.c | 2 +- librz/util/unum.c | 2 +- 41 files changed, 731 insertions(+), 4318 deletions(-) diff --git a/librz/arch/isa/amd29k/amd29k.c b/librz/arch/isa/amd29k/amd29k.c index 22a0d297037..cbb470312b0 100644 --- a/librz/arch/isa/amd29k/amd29k.c +++ b/librz/arch/isa/amd29k/amd29k.c @@ -22,7 +22,7 @@ // Local registers #define AMD29K_IS_REG_LR(x) ((x) >= 128 && (x) < 256) #define AMD29K_REGNAME(x) (AMD29K_IS_REG_GR(x) ? "gr" : "lr") -#define AMD29K_LR(x) (AMD29K_IS_REG_GR(x) ? (x) : (x) - 127) +#define AMD29K_LR(x) (AMD29K_IS_REG_GR(x) ? (x) : (x)-127) static void decode_ra_rb_rci(amd29k_instr_t *instruction, const ut8 *buffer) { AMD29K_SET_VALUE(instruction, 0, buffer[1], AMD29K_TYPE_REG); diff --git a/librz/arch/isa/arm/armass.c b/librz/arch/isa/arm/armass.c index 29c78ebed23..76540ea9d7b 100644 --- a/librz/arch/isa/arm/armass.c +++ b/librz/arch/isa/arm/armass.c @@ -5813,7 +5813,7 @@ static int arm_assemble(ArmOpcode *ao, ut64 off, const char *str) { } ao->o |= ((ret >> 16) & 0xff) << 8; ao->o |= ((ret >> 8) & 0xff) << 16; - ao->o |= ((ret) & 0xff) << 24; + ao->o |= ((ret)&0xff) << 24; } else { RZ_LOG_ERROR("assembler: arm: %s: instruction does not accept a register as argument\n", ops[i].name); return 0; @@ -5839,7 +5839,7 @@ static int arm_assemble(ArmOpcode *ao, ut64 off, const char *str) { dst /= 4; ao->o |= ((dst >> 16) & 0xff) << 8; ao->o |= ((dst >> 8) & 0xff) << 16; - ao->o |= ((dst) & 0xff) << 24; + ao->o |= ((dst)&0xff) << 24; return 4; } else { ao->o |= (getreg(ao->a[0]) << 24); @@ -5850,7 +5850,7 @@ static int arm_assemble(ArmOpcode *ao, ut64 off, const char *str) { o |= ((n >> 12) & 0xf) << 8; o |= ((n >> 8) & 0xf) << 20; o |= ((n >> 4) & 0xf) << 16; - o |= ((n) & 0xf) << 24; + o |= ((n)&0xf) << 24; ao->o |= o; } break; case TYPE_SWI: diff --git a/librz/arch/isa/avr/assembler.c b/librz/arch/isa/avr/assembler.c index df3dc3e2997..12dd66af52a 100644 --- a/librz/arch/isa/avr/assembler.c +++ b/librz/arch/isa/avr/assembler.c @@ -131,7 +131,7 @@ (rn) = abs - pc; \ } \ if ((rn) < 0) { \ - (rn) = ~(-((rn) - 1)); \ + (rn) = ~(-((rn)-1)); \ } else { \ (rn) -= 2; \ } \ diff --git a/librz/arch/isa/avr/avr_esil.c b/librz/arch/isa/avr/avr_esil.c index 04979a381c4..47197c8b10e 100644 --- a/librz/arch/isa/avr/avr_esil.c +++ b/librz/arch/isa/avr/avr_esil.c @@ -52,8 +52,8 @@ static OPCODE_DESC *avr_op_analyze(RzAnalysis *analysis, RzAnalysisOp *op, ut64 #define CPU_MODEL_DECL(model, pc, consts) \ { \ model, \ - pc, \ - consts \ + pc, \ + consts \ } #define MASK(bits) ((bits) == 32 ? 0xffffffff : (~((~((ut32)0)) << (bits)))) #define CPU_PC_MASK(cpu) MASK((cpu)->pc) diff --git a/librz/arch/isa/lh5801/lh5801.c b/librz/arch/isa/lh5801/lh5801.c index ff61e3409c6..a8399444ace 100644 --- a/librz/arch/isa/lh5801/lh5801.c +++ b/librz/arch/isa/lh5801/lh5801.c @@ -131,8 +131,8 @@ enum lh5801_insn_format { LH5801_IFMT_RMODE_MASK = 3 << 10, }; -#define LH5801_IFMT_IMMS(f) ((f) & LH5801_IFMT_IMM_MASK) -#define LH5801_IFMT_RMODE(f) ((f) & LH5801_IFMT_RMODE_MASK) +#define LH5801_IFMT_IMMS(f) ((f)&LH5801_IFMT_IMM_MASK) +#define LH5801_IFMT_RMODE(f) ((f)&LH5801_IFMT_RMODE_MASK) static bool lh5801_ifmt_fd_matches(enum lh5801_insn_format fmt, int fd) { switch (fmt & LH5801_IFMT_FD_MASK) { diff --git a/librz/arch/isa/luac/v53/arch_53.h b/librz/arch/isa/luac/v53/arch_53.h index 85e217528bc..020bc92591f 100644 --- a/librz/arch/isa/luac/v53/arch_53.h +++ b/librz/arch/isa/luac/v53/arch_53.h @@ -166,11 +166,11 @@ name args description #define cast(x, y) ((x)(y)) #define GET_OPCODE(i) (cast(LuaOpCode, ((i) >> POS_OP) & MASK1(SIZE_OP, 0))) -#define SET_OPCODE(i, o) ((i) = (((i) & MASK0(SIZE_OP, POS_OP)) | \ +#define SET_OPCODE(i, o) ((i) = (((i)&MASK0(SIZE_OP, POS_OP)) | \ ((cast(ut32, o) << POS_OP) & MASK1(SIZE_OP, POS_OP)))) #define getarg(i, pos, size) (cast(int, ((i) >> (pos)) & MASK1(size, 0))) -#define setarg(i, v, pos, size) ((i) = (((i) & MASK0(size, pos)) | \ +#define setarg(i, v, pos, size) ((i) = (((i)&MASK0(size, pos)) | \ ((cast(ut32, v) << (pos)) & MASK1(size, pos)))) #define GETARG_A(i) getarg(i, POS_A, SIZE_A) diff --git a/librz/arch/isa/luac/v54/arch_54.h b/librz/arch/isa/luac/v54/arch_54.h index 403637bcd1f..54c50a3138e 100644 --- a/librz/arch/isa/luac/v54/arch_54.h +++ b/librz/arch/isa/luac/v54/arch_54.h @@ -188,7 +188,7 @@ typedef enum { /* Macros Highlight the cast */ #define LUA_CAST(x, y) ((x)y) #define int2sC(i) ((i) + LUAOP_FIX_sC) -#define sC2int(i) ((i) - LUAOP_FIX_sC) +#define sC2int(i) ((i)-LUAOP_FIX_sC) /* creates a mask with 'n' 1/0 bits at position 'p' */ #define LUA_MASK1(n, p) ((~((~(LuaInstruction)0) << (n))) << (p)) @@ -196,12 +196,12 @@ typedef enum { /* OPCODE getter */ #define LUA_GET_OPCODE(i) (LUA_CAST(LuaOpCode, ((i) >> LUAOP_OP_OFFSET) & LUA_MASK1(LUAOP_OP_SIZE, 0))) -#define LUA_SET_OPCODE(i, o) ((i) = (((i) & LUA_MASK0(LUAOP_OP_SIZE, LUAOP_OP_OFFSET)) | \ +#define LUA_SET_OPCODE(i, o) ((i) = (((i)&LUA_MASK0(LUAOP_OP_SIZE, LUAOP_OP_OFFSET)) | \ ((LUA_CAST(LuaInstruction, o) << LUAOP_OP_OFFSET) & LUA_MASK1(LUAOP_OP_SIZE, LUAOP_OP_OFFSET)))) /* Arguments getter */ #define LUA_GETARG(i, offset, size) (LUA_CAST(int, ((i) >> (offset)) & LUA_MASK1(size, 0))) -#define LUA_SETARG(i, v, pos, size) ((i) = (((i) & LUA_MASK0(size, pos)) | \ +#define LUA_SETARG(i, v, pos, size) ((i) = (((i)&LUA_MASK0(size, pos)) | \ ((LUA_CAST(LuaInstruction, v) << (pos)) & LUA_MASK1(size, pos)))) #define LUA_GETARG_A(i) LUA_GETARG(i, LUAOP_A_OFFSET, LUAOP_A_SIZE) diff --git a/librz/arch/isa/ppc/libps/libps_internal.h b/librz/arch/isa/ppc/libps/libps_internal.h index 95594fcb92a..bb42cf22216 100644 --- a/librz/arch/isa/ppc/libps/libps_internal.h +++ b/librz/arch/isa/ppc/libps/libps_internal.h @@ -15,16 +15,16 @@ #define OP_MASK OP(0x3f) #define OPS(op, xop) (OP(op) | ((((ut32)(xop)) & 0x1f) << 1)) -#define OPSC(op, xop, rc) (OPS((op), (xop)) | ((rc) & 1)) +#define OPSC(op, xop, rc) (OPS((op), (xop)) | ((rc)&1)) #define OPS_MASK OPSC(0x3f, 0x1f, 1) #define OPS_MASK_DOT OPSC(0x3f, 0x1f, 1) #define OPM(op, xop) (OP(op) | ((((ut32)(xop)) & 0x3f) << 1)) -#define OPMC(op, xop, rc) (OPM((op), (xop)) | ((rc) & 1)) +#define OPMC(op, xop, rc) (OPM((op), (xop)) | ((rc)&1)) #define OPM_MASK OPMC(0x3f, 0x3f, 0) #define OPL(op, xop) (OP(op) | ((((ut32)(xop)) & 0x3ff) << 1)) -#define OPLC(op, xop, rc) (OPL((op), (xop)) | ((rc) & 1)) +#define OPLC(op, xop, rc) (OPL((op), (xop)) | ((rc)&1)) #define OPL_MASK OPLC(0x3f, 0x3ff, 1) #define OPL_MASK_DOT OPLC(0x3f, 0x3ff, 1) diff --git a/librz/arch/isa/rx/rx_opcode_detail.c b/librz/arch/isa/rx/rx_opcode_detail.c index 9b981dbe48d..8ab9f64ccf9 100644 --- a/librz/arch/isa/rx/rx_opcode_detail.c +++ b/librz/arch/isa/rx/rx_opcode_detail.c @@ -33,10 +33,7 @@ { .type = RX_TOKEN_CB, .tk.cb.tk_len = (x) } #define RxDspSplit(x, v, it, xx) \ { .type = RX_TOKEN_DSP_SPLIT, \ - .tk.dsp_sp.tk_len = (x), \ - .tk.dsp_sp.vid = (v), \ - .tk.dsp_sp.tk_len_more = (xx), \ - .tk.dsp_sp.interval = (it) } + .tk.dsp_sp.tk_len = (x), .tk.dsp_sp.vid = (v), .tk.dsp_sp.tk_len_more = (xx), .tk.dsp_sp.interval = (it) } #define RxIgnore(x) \ { .type = RX_TOKEN_IGNORE, .tk.reserved.tk_len = (x) } diff --git a/librz/arch/isa/rx/rx_str.inc b/librz/arch/isa/rx/rx_str.inc index f820932cf34..1404cc14026 100644 --- a/librz/arch/isa/rx/rx_str.inc +++ b/librz/arch/isa/rx/rx_str.inc @@ -165,7 +165,7 @@ const char *cond_names[RX_COND_RESERVED] = { }; #define RxNameOp(op) ((op) < _RX_OP_COUNT ? opnames[(op)] : "invalid") -#define RxNameExt(ext) ((ext) < _RX_EXT_COUNT ? extmark_names[((ext) - RX_EXT_B)] : "invalid") -#define RxNameReg(reg) ((reg) < RX_REG_RESERVED ? reg_names[(reg) - RX_REG_R0] : "invalid") +#define RxNameExt(ext) ((ext) < _RX_EXT_COUNT ? extmark_names[((ext)-RX_EXT_B)] : "invalid") +#define RxNameReg(reg) ((reg) < RX_REG_RESERVED ? reg_names[(reg)-RX_REG_R0] : "invalid") #define RxNameFlag(flag) ((flag) < 7 ? flag_names[(flag)] : "invalid") #define RxNameCond(cond) ((cond) < RX_COND_RESERVED ? cond_names[(cond)] : "invalid") \ No newline at end of file diff --git a/librz/arch/isa/v810/v810_disas.h b/librz/arch/isa/v810/v810_disas.h index eb93ad70580..084081f44e0 100644 --- a/librz/arch/isa/v810/v810_disas.h +++ b/librz/arch/isa/v810/v810_disas.h @@ -7,17 +7,17 @@ #define V810_INSTR_MAXLEN 24 #define OPCODE(instr) (((instr) >> 10) & 0x3F) -#define REG1(instr) ((instr) & 0x1F) +#define REG1(instr) ((instr)&0x1F) #define REG2(instr) (((instr) >> 5) & 0x1F) #define IMM5(instr) REG1((instr)) #define COND(instr) (((instr) >> 9) & 0xF) -#define SIGN_EXT_T5(imm) (((imm) & 0x10) ? (imm) | 0xE0 : (imm)) -#define SIGN_EXT_T9(imm) (((imm) & 0x100) ? (imm) | 0xFFFFFE00 : (imm)) -#define SIGN_EXT_T26(imm) (((imm) & 0x2000000) ? (imm) | 0xFC000000 : (imm)) +#define SIGN_EXT_T5(imm) (((imm)&0x10) ? (imm) | 0xE0 : (imm)) +#define SIGN_EXT_T9(imm) (((imm)&0x100) ? (imm) | 0xFFFFFE00 : (imm)) +#define SIGN_EXT_T26(imm) (((imm)&0x2000000) ? (imm) | 0xFC000000 : (imm)) -#define DISP9(word1) SIGN_EXT_T9((word1) & 0x1FE) -#define DISP26(word1, word2) SIGN_EXT_T26((((word1) & 0x3FF) << 16) | (word2)) +#define DISP9(word1) SIGN_EXT_T9((word1)&0x1FE) +#define DISP26(word1, word2) SIGN_EXT_T26((((word1)&0x3FF) << 16) | (word2)) enum v810_cmd_opcodes { V810_MOV = 0x0, diff --git a/librz/arch/p/analysis/analysis_i4004.c b/librz/arch/p/analysis/analysis_i4004.c index ee77e0fdd5d..356c919dbd5 100644 --- a/librz/arch/p/analysis/analysis_i4004.c +++ b/librz/arch/p/analysis/analysis_i4004.c @@ -9,7 +9,7 @@ #include #include -#define AVR_SOFTCAST(x, y) ((x) + ((y) * 0x100)) +#define AVR_SOFTCAST(x, y) ((x) + ((y)*0x100)) static char *get_reg_profile(RzAnalysis *analysis) { const char *p = diff --git a/librz/arch/p/analysis/analysis_pyc.c b/librz/arch/p/analysis/analysis_pyc.c index 55df01ef9ff..eedec2fe7d3 100644 --- a/librz/arch/p/analysis/analysis_pyc.c +++ b/librz/arch/p/analysis/analysis_pyc.c @@ -8,7 +8,7 @@ #include "pyc/pyc_dis.h" -#define JMP_OFFSET(ops, v) ((ops)->jump_use_instruction_offset ? (v) * 2 : (v)) +#define JMP_OFFSET(ops, v) ((ops)->jump_use_instruction_offset ? (v)*2 : (v)) static int archinfo(RzAnalysis *analysis, RzAnalysisInfoType query) { if (!strcmp(analysis->cpu, "x86")) { diff --git a/librz/arch/p/analysis/analysis_sh.c b/librz/arch/p/analysis/analysis_sh.c index 38d9ca8b3d5..23d60397f09 100644 --- a/librz/arch/p/analysis/analysis_sh.c +++ b/librz/arch/p/analysis/analysis_sh.c @@ -38,138 +38,138 @@ #define IS_CLRMAC(x) x == 0x0028 #define IS_RTE(x) x == 0x002b -#define IS_STCSR1(x) (((x) & 0xF0CF) == 0x0002) // mask stc Rn,{SR,gbr,VBR,SSR} -#define IS_BSRF(x) ((x) & 0xf0ff) == 0x0003 -#define IS_BRAF(x) (((x) & 0xf0ff) == 0x0023) -#define IS_MOVB_REG_TO_R0REL(x) (((x) & 0xF00F) == 0x0004) -#define IS_MOVW_REG_TO_R0REL(x) (((x) & 0xF00F) == 0x0005) -#define IS_MOVL_REG_TO_R0REL(x) (((x) & 0xF00F) == 0x0006) -#define IS_MULL(x) (((x) & 0xF00F) == 0x0007) -#define IS_MOVB_R0REL_TO_REG(x) (((x) & 0xF00F) == 0x000C) -#define IS_MOVW_R0REL_TO_REG(x) (((x) & 0xF00F) == 0x000D) -#define IS_MOVL_R0REL_TO_REG(x) (((x) & 0xF00F) == 0x000E) -#define IS_MACL(x) (((x) & 0xF00F) == 0x000F) -#define IS_MOVT(x) (((x) & 0xF0FF) == 0x0029) -#define IS_STSMACH(x) (((x) & 0xF0FF) == 0x000A) -#define IS_STSMACL(x) (((x) & 0xF0FF) == 0x001A) -#define IS_STSPR(x) (((x) & 0xF0FF) == 0x002A) +#define IS_STCSR1(x) (((x)&0xF0CF) == 0x0002) // mask stc Rn,{SR,gbr,VBR,SSR} +#define IS_BSRF(x) ((x)&0xf0ff) == 0x0003 +#define IS_BRAF(x) (((x)&0xf0ff) == 0x0023) +#define IS_MOVB_REG_TO_R0REL(x) (((x)&0xF00F) == 0x0004) +#define IS_MOVW_REG_TO_R0REL(x) (((x)&0xF00F) == 0x0005) +#define IS_MOVL_REG_TO_R0REL(x) (((x)&0xF00F) == 0x0006) +#define IS_MULL(x) (((x)&0xF00F) == 0x0007) +#define IS_MOVB_R0REL_TO_REG(x) (((x)&0xF00F) == 0x000C) +#define IS_MOVW_R0REL_TO_REG(x) (((x)&0xF00F) == 0x000D) +#define IS_MOVL_R0REL_TO_REG(x) (((x)&0xF00F) == 0x000E) +#define IS_MACL(x) (((x)&0xF00F) == 0x000F) +#define IS_MOVT(x) (((x)&0xF0FF) == 0x0029) +#define IS_STSMACH(x) (((x)&0xF0FF) == 0x000A) +#define IS_STSMACL(x) (((x)&0xF0FF) == 0x001A) +#define IS_STSPR(x) (((x)&0xF0FF) == 0x002A) // #define IS_STSFPUL(x) (((x) & 0xF0FF) == 0x005A) //FP*: todo maybe someday // #define IS_STSFPSCR(x) (((x) & 0xF0FF) == 0x006A) -#define IS_MOVB_REG_TO_REGREF(x) (((x) & 0xF00F) == 0x2000) -#define IS_MOVW_REG_TO_REGREF(x) (((x) & 0xF00F) == 0x2001) -#define IS_MOVL_REG_TO_REGREF(x) (((x) & 0xF00F) == 0x2002) +#define IS_MOVB_REG_TO_REGREF(x) (((x)&0xF00F) == 0x2000) +#define IS_MOVW_REG_TO_REGREF(x) (((x)&0xF00F) == 0x2001) +#define IS_MOVL_REG_TO_REGREF(x) (((x)&0xF00F) == 0x2002) // #define invalid?(x) (((x) & 0xF00F) == 0x2003) //illegal on sh2e -#define IS_PUSHB(x) (((x) & 0xF00F) == 0x2004) -#define IS_PUSHW(x) (((x) & 0xF00F) == 0x2005) -#define IS_PUSHL(x) (((x) & 0xF00F) == 0x2006) -#define IS_DIV0S(x) (((x) & 0xF00F) == 0x2007) -#define IS_TSTRR(x) (((x) & 0xF00F) == 0x2008) -#define IS_AND_REGS(x) (((x) & 0xF00F) == 0x2009) -#define IS_XOR_REGS(x) (((x) & 0xF00F) == 0x200A) -#define IS_OR_REGS(x) (((x) & 0xF00F) == 0x200B) -#define IS_CMPSTR(x) (((x) & 0xF00F) == 0x200C) -#define IS_XTRCT(x) (((x) & 0xF00F) == 0x200D) -#define IS_MULUW(x) (((x) & 0xF00F) == 0x200E) -#define IS_MULSW(x) (((x) & 0xF00F) == 0x200F) -#define IS_CMPEQ(x) (((x) & 0xF00F) == 0x3000) +#define IS_PUSHB(x) (((x)&0xF00F) == 0x2004) +#define IS_PUSHW(x) (((x)&0xF00F) == 0x2005) +#define IS_PUSHL(x) (((x)&0xF00F) == 0x2006) +#define IS_DIV0S(x) (((x)&0xF00F) == 0x2007) +#define IS_TSTRR(x) (((x)&0xF00F) == 0x2008) +#define IS_AND_REGS(x) (((x)&0xF00F) == 0x2009) +#define IS_XOR_REGS(x) (((x)&0xF00F) == 0x200A) +#define IS_OR_REGS(x) (((x)&0xF00F) == 0x200B) +#define IS_CMPSTR(x) (((x)&0xF00F) == 0x200C) +#define IS_XTRCT(x) (((x)&0xF00F) == 0x200D) +#define IS_MULUW(x) (((x)&0xF00F) == 0x200E) +#define IS_MULSW(x) (((x)&0xF00F) == 0x200F) +#define IS_CMPEQ(x) (((x)&0xF00F) == 0x3000) // #define invalid?(x) (((x) & 0xF00F) == 0x3001) -#define IS_CMPHS(x) (((x) & 0xF00F) == 0x3002) -#define IS_CMPGE(x) (((x) & 0xF00F) == 0x3003) -#define IS_CMPHI(x) (((x) & 0xF00F) == 0x3006) -#define IS_CMPGT(x) (((x) & 0xF00F) == 0x3007) -#define IS_DIV1(x) (((x) & 0xF00F) == 0x3004) -#define IS_DMULU(x) (((x) & 0xF00F) == 0x3005) -#define IS_DMULS(x) (((x) & 0xF00F) == 0x300D) -#define IS_SUB(x) (((x) & 0xF00F) == 0x3008) +#define IS_CMPHS(x) (((x)&0xF00F) == 0x3002) +#define IS_CMPGE(x) (((x)&0xF00F) == 0x3003) +#define IS_CMPHI(x) (((x)&0xF00F) == 0x3006) +#define IS_CMPGT(x) (((x)&0xF00F) == 0x3007) +#define IS_DIV1(x) (((x)&0xF00F) == 0x3004) +#define IS_DMULU(x) (((x)&0xF00F) == 0x3005) +#define IS_DMULS(x) (((x)&0xF00F) == 0x300D) +#define IS_SUB(x) (((x)&0xF00F) == 0x3008) // #define invalid?(x) (((x) & 0xF00F) == 0x3009) -#define IS_SUBC(x) (((x) & 0xF00F) == 0x300A) -#define IS_SUBV(x) (((x) & 0xF00F) == 0x300B) -#define IS_ADD(x) (((x) & 0xF00F) == 0x300C) -#define IS_ADDC(x) (((x) & 0xF00F) == 0x300E) -#define IS_ADDV(x) (((x) & 0xF00F) == 0x300F) -#define IS_MACW(x) (((x) & 0xF00F) == 0x400F) -#define IS_JSR(x) (((x) & 0xf0ff) == 0x400b) -#define IS_JMP(x) (((x) & 0xf0ff) == 0x402b) -#define IS_CMPPL(x) (((x) & 0xf0ff) == 0x4015) -#define IS_CMPPZ(x) (((x) & 0xf0ff) == 0x4011) -#define IS_LDCSR(x) (((x) & 0xF0FF) == 0x400E) -#define IS_LDCGBR(x) (((x) & 0xF0FF) == 0x401E) -#define IS_LDCVBR(x) (((x) & 0xF0FF) == 0x402E) -#define IS_LDCLSR(x) (((x) & 0xF0FF) == 0x4007) -#define IS_LDCLSRGBR(x) (((x) & 0xF0FF) == 0x4017) -#define IS_LDCLSRVBR(x) (((x) & 0xF0FF) == 0x4027) -#define IS_LDSMACH(x) (((x) & 0xF0FF) == 0x400A) -#define IS_LDSMACL(x) (((x) & 0xF0FF) == 0x401A) -#define IS_LDSLMACH(x) (((x) & 0xF0FF) == 0x4006) -#define IS_LDSLMACL(x) (((x) & 0xF0FF) == 0x4016) -#define IS_LDSPR(x) (((x) & 0xF0FF) == 0x402A) -#define IS_LDSLPR(x) (((x) & 0xF0FF) == 0x4026) +#define IS_SUBC(x) (((x)&0xF00F) == 0x300A) +#define IS_SUBV(x) (((x)&0xF00F) == 0x300B) +#define IS_ADD(x) (((x)&0xF00F) == 0x300C) +#define IS_ADDC(x) (((x)&0xF00F) == 0x300E) +#define IS_ADDV(x) (((x)&0xF00F) == 0x300F) +#define IS_MACW(x) (((x)&0xF00F) == 0x400F) +#define IS_JSR(x) (((x)&0xf0ff) == 0x400b) +#define IS_JMP(x) (((x)&0xf0ff) == 0x402b) +#define IS_CMPPL(x) (((x)&0xf0ff) == 0x4015) +#define IS_CMPPZ(x) (((x)&0xf0ff) == 0x4011) +#define IS_LDCSR(x) (((x)&0xF0FF) == 0x400E) +#define IS_LDCGBR(x) (((x)&0xF0FF) == 0x401E) +#define IS_LDCVBR(x) (((x)&0xF0FF) == 0x402E) +#define IS_LDCLSR(x) (((x)&0xF0FF) == 0x4007) +#define IS_LDCLSRGBR(x) (((x)&0xF0FF) == 0x4017) +#define IS_LDCLSRVBR(x) (((x)&0xF0FF) == 0x4027) +#define IS_LDSMACH(x) (((x)&0xF0FF) == 0x400A) +#define IS_LDSMACL(x) (((x)&0xF0FF) == 0x401A) +#define IS_LDSLMACH(x) (((x)&0xF0FF) == 0x4006) +#define IS_LDSLMACL(x) (((x)&0xF0FF) == 0x4016) +#define IS_LDSPR(x) (((x)&0xF0FF) == 0x402A) +#define IS_LDSLPR(x) (((x)&0xF0FF) == 0x4026) // #define IS_LDSFPUL(x) (((x) & 0xF0FF) == 0x405A) //FP*: todo maybe someday // #define IS_LDSFPSCR(x) (((x) & 0xF0FF) == 0x406A) // #define IS_LDSLFPUL(x) (((x) & 0xF0FF) == 0x4066) // #define IS_LDSLFPSCR(x) (((x) & 0xF0FF) == 0x4056) -#define IS_ROTCR(x) (((x) & 0xF0FF) == 0x4025) -#define IS_ROTCL(x) (((x) & 0xF0FF) == 0x4024) -#define IS_ROTL(x) (((x) & 0xF0FF) == 0x4004) -#define IS_ROTR(x) (((x) & 0xF0FF) == 0x4005) +#define IS_ROTCR(x) (((x)&0xF0FF) == 0x4025) +#define IS_ROTCL(x) (((x)&0xF0FF) == 0x4024) +#define IS_ROTL(x) (((x)&0xF0FF) == 0x4004) +#define IS_ROTR(x) (((x)&0xF0FF) == 0x4005) // not on sh2e : shad, shld // #define IS_SHIFT1(x) (((x) & 0xF0DE) == 0x4000) //unused (treated as switch-case) // other shl{l,r}{,2,8,16} in switch case also. -#define IS_STSLMACL(x) (((x) & 0xF0FF) == 0x4012) -#define IS_STSLMACH(x) (((x) & 0xF0FF) == 0x4002) -#define IS_STCLSR(x) (((x) & 0xF0FF) == 0x4003) -#define IS_STCLGBR(x) (((x) & 0xF0FF) == 0x4013) -#define IS_STCLVBR(x) (((x) & 0xF0FF) == 0x4023) +#define IS_STSLMACL(x) (((x)&0xF0FF) == 0x4012) +#define IS_STSLMACH(x) (((x)&0xF0FF) == 0x4002) +#define IS_STCLSR(x) (((x)&0xF0FF) == 0x4003) +#define IS_STCLGBR(x) (((x)&0xF0FF) == 0x4013) +#define IS_STCLVBR(x) (((x)&0xF0FF) == 0x4023) // todo: other stc.l not on sh2e -#define IS_STSLPR(x) (((x) & 0xF0FF) == 0x4022) +#define IS_STSLPR(x) (((x)&0xF0FF) == 0x4022) // #define IS_STSLFPUL(x) (((x) & 0xF0FF) == 0x4052) // #define IS_STSLFPSCR(x) (((x) & 0xF0FF) == 0x4062) -#define IS_TASB(x) (((x) & 0xF0FF) == 0x401B) -#define IS_DT(x) (((x) & 0xF0FF) == 0x4010) +#define IS_TASB(x) (((x)&0xF0FF) == 0x401B) +#define IS_DT(x) (((x)&0xF0FF) == 0x4010) -#define IS_MOVB_REGREF_TO_REG(x) (((x) & 0xF00F) == 0x6000) -#define IS_MOVW_REGREF_TO_REG(x) (((x) & 0xF00F) == 0x6001) -#define IS_MOVL_REGREF_TO_REG(x) (((x) & 0xF00F) == 0x6002) -#define IS_MOV_REGS(x) (((x) & 0xf00f) == 0x6003) -#define IS_MOVB_POP(x) (((x) & 0xF00F) == 0x6004) -#define IS_MOVW_POP(x) (((x) & 0xF00F) == 0x6005) -#define IS_MOVL_POP(x) (((x) & 0xF00F) == 0x6006) -#define IS_NOT(x) (((x) & 0xF00F) == 0x6007) -#define IS_SWAPB(x) (((x) & 0xF00F) == 0x6008) -#define IS_SWAPW(x) (((x) & 0xF00F) == 0x6009) -#define IS_NEG(x) (((x) & 0xF00F) == 0x600B) -#define IS_NEGC(x) (((x) & 0xF00F) == 0x600A) -#define IS_EXT(x) (((x) & 0xF00C) == 0x600C) // match ext{s,u}.{b,w} +#define IS_MOVB_REGREF_TO_REG(x) (((x)&0xF00F) == 0x6000) +#define IS_MOVW_REGREF_TO_REG(x) (((x)&0xF00F) == 0x6001) +#define IS_MOVL_REGREF_TO_REG(x) (((x)&0xF00F) == 0x6002) +#define IS_MOV_REGS(x) (((x)&0xf00f) == 0x6003) +#define IS_MOVB_POP(x) (((x)&0xF00F) == 0x6004) +#define IS_MOVW_POP(x) (((x)&0xF00F) == 0x6005) +#define IS_MOVL_POP(x) (((x)&0xF00F) == 0x6006) +#define IS_NOT(x) (((x)&0xF00F) == 0x6007) +#define IS_SWAPB(x) (((x)&0xF00F) == 0x6008) +#define IS_SWAPW(x) (((x)&0xF00F) == 0x6009) +#define IS_NEG(x) (((x)&0xF00F) == 0x600B) +#define IS_NEGC(x) (((x)&0xF00F) == 0x600A) +#define IS_EXT(x) (((x)&0xF00C) == 0x600C) // match ext{s,u}.{b,w} -#define IS_MOVB_R0_REGDISP(x) (((x) & 0xFF00) == 0x8000) -#define IS_MOVW_R0_REGDISP(x) (((x) & 0xFF00) == 0x8100) +#define IS_MOVB_R0_REGDISP(x) (((x)&0xFF00) == 0x8000) +#define IS_MOVW_R0_REGDISP(x) (((x)&0xFF00) == 0x8100) // #define illegal?(x) (((x) & 0xF900) == 0x8000) //match 8{2,3,6,7}00 -#define IS_MOVB_REGDISP_R0(x) (((x) & 0xFF00) == 0x8400) -#define IS_MOVW_REGDISP_R0(x) (((x) & 0xFF00) == 0x8500) -#define IS_CMPIMM(x) (((x) & 0xFF00) == 0x8800) +#define IS_MOVB_REGDISP_R0(x) (((x)&0xFF00) == 0x8400) +#define IS_MOVW_REGDISP_R0(x) (((x)&0xFF00) == 0x8500) +#define IS_CMPIMM(x) (((x)&0xFF00) == 0x8800) // #define illegal?(x) (((x) & 0xFB00) == 0x8A00) //match 8{A,E}00 -#define IS_BT(x) (((x) & 0xff00) == 0x8900) -#define IS_BF(x) (((x) & 0xff00) == 0x8B00) -#define IS_BTS(x) (((x) & 0xff00) == 0x8D00) -#define IS_BFS(x) (((x) & 0xff00) == 0x8F00) +#define IS_BT(x) (((x)&0xff00) == 0x8900) +#define IS_BF(x) (((x)&0xff00) == 0x8B00) +#define IS_BTS(x) (((x)&0xff00) == 0x8D00) +#define IS_BFS(x) (((x)&0xff00) == 0x8F00) #define IS_BT_OR_BF(x) IS_BT(x) || IS_BTS(x) || IS_BF(x) || IS_BFS(x) -#define IS_MOVB_R0_GBRREF(x) (((x) & 0xFF00) == 0xC000) -#define IS_MOVW_R0_GBRREF(x) (((x) & 0xFF00) == 0xC100) -#define IS_MOVL_R0_GBRREF(x) (((x) & 0xFF00) == 0xC200) -#define IS_TRAP(x) (((x) & 0xFF00) == 0xC300) -#define IS_MOVB_GBRREF_R0(x) (((x) & 0xFF00) == 0xC400) -#define IS_MOVW_GBRREF_R0(x) (((x) & 0xFF00) == 0xC500) -#define IS_MOVL_GBRREF_R0(x) (((x) & 0xFF00) == 0xC600) -#define IS_MOVA_PCREL_R0(x) (((x) & 0xFF00) == 0xC700) -#define IS_BINLOGIC_IMM_R0(x) (((x) & 0xFC00) == 0xC800) // match C{8,9,A,B}00 -#define IS_BINLOGIC_IMM_GBR(x) (((x) & 0xFC00) == 0xCC00) // match C{C,D,E,F}00 : *.b #imm, @(R0,gbr) +#define IS_MOVB_R0_GBRREF(x) (((x)&0xFF00) == 0xC000) +#define IS_MOVW_R0_GBRREF(x) (((x)&0xFF00) == 0xC100) +#define IS_MOVL_R0_GBRREF(x) (((x)&0xFF00) == 0xC200) +#define IS_TRAP(x) (((x)&0xFF00) == 0xC300) +#define IS_MOVB_GBRREF_R0(x) (((x)&0xFF00) == 0xC400) +#define IS_MOVW_GBRREF_R0(x) (((x)&0xFF00) == 0xC500) +#define IS_MOVL_GBRREF_R0(x) (((x)&0xFF00) == 0xC600) +#define IS_MOVA_PCREL_R0(x) (((x)&0xFF00) == 0xC700) +#define IS_BINLOGIC_IMM_R0(x) (((x)&0xFC00) == 0xC800) // match C{8,9,A,B}00 +#define IS_BINLOGIC_IMM_GBR(x) (((x)&0xFC00) == 0xCC00) // match C{C,D,E,F}00 : *.b #imm, @(R0,gbr) /* Compute PC-relative displacement for branch instructions */ -#define GET_BRA_OFFSET(x) ((x) & 0x0fff) -#define GET_BTF_OFFSET(x) ((x) & 0x00ff) +#define GET_BRA_OFFSET(x) ((x)&0x0fff) +#define GET_BTF_OFFSET(x) ((x)&0x00ff) /* Compute reg nr for BRAF,BSR,BSRF,JMP,JSR */ #define GET_TARGET_REG(x) (((x) >> 8) & 0x0f) diff --git a/librz/arch/p_gnu/analysis/analysis_sparc_gnu.c b/librz/arch/p_gnu/analysis/analysis_sparc_gnu.c index 48dd6ba1941..403981bd3cf 100644 --- a/librz/arch/p_gnu/analysis/analysis_sparc_gnu.c +++ b/librz/arch/p_gnu/analysis/analysis_sparc_gnu.c @@ -159,7 +159,7 @@ static int fcc_to_r_cond(const int cond) { /* These are for v9. */ #define X_DISP16(i) (((((i) >> 20) & 3) << 14) | (((i) >> 0) & 0x3fff)) #define X_DISP19(i) (((i) >> 0) & 0x7ffff) -#define X_MEMBAR(i) ((i) & 0x7f) +#define X_MEMBAR(i) ((i)&0x7f) enum { OP_0 = 0, diff --git a/librz/bin/format/elf/glibc_elf.h b/librz/bin/format/elf/glibc_elf.h index 945e3dac832..070db55d1ba 100644 --- a/librz/bin/format/elf/glibc_elf.h +++ b/librz/bin/format/elf/glibc_elf.h @@ -418,7 +418,7 @@ typedef struct #define SHN_LORESERVE 0xff00 /* Start of reserved indices */ #define SHN_LOPROC 0xff00 /* Start of processor-specific */ #define SHN_BEFORE 0xff00 /* Order section before all others \ - (Solaris). */ + (Solaris). */ #define SHN_AFTER 0xff01 /* Order section after all others \ (Solaris). */ #define SHN_HIPROC 0xff1f /* End of processor-specific */ @@ -485,7 +485,7 @@ typedef struct #define SHF_MASKOS 0x0ff00000 /* OS-specific. */ #define SHF_MASKPROC 0xf0000000 /* Processor-specific */ #define SHF_ORDERED (1 << 30) /* Special ordering requirement \ - (Solaris). */ + (Solaris). */ #define SHF_EXCLUDE (1U << 31) /* Section is excluded unless \ referenced or allocated (Solaris).*/ @@ -573,8 +573,8 @@ typedef struct /* How to extract and insert information held in the st_info field. */ #define ELF32_ST_BIND(val) (((unsigned char)(val)) >> 4) -#define ELF32_ST_TYPE(val) ((val) & 0xf) -#define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) +#define ELF32_ST_TYPE(val) ((val)&0xf) +#define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type)&0xf)) /* Both Elf32_Sym and Elf64_Sym use the same one-byte st_info field. */ #define ELF64_ST_BIND(val) ELF32_ST_BIND(val) @@ -617,7 +617,7 @@ typedef struct /* How to extract and insert information held in the st_other field. */ -#define ELF32_ST_VISIBILITY(o) ((o) & 0x03) +#define ELF32_ST_VISIBILITY(o) ((o)&0x03) /* For ELF64 the definitions are the same. */ #define ELF64_ST_VISIBILITY(o) ELF32_ST_VISIBILITY(o) @@ -666,11 +666,11 @@ typedef struct /* How to extract and insert information held in the rz_info field. */ #define ELF32_R_SYM(val) ((val) >> 8) -#define ELF32_R_TYPE(val) ((val) & 0xff) -#define ELF32_R_INFO(sym, type) (((sym) << 8) + ((type) & 0xff)) +#define ELF32_R_TYPE(val) ((val)&0xff) +#define ELF32_R_INFO(sym, type) (((sym) << 8) + ((type)&0xff)) #define ELF64_R_SYM(i) ((i) >> 32) -#define ELF64_R_TYPE(i) ((i) & 0xffffffff) +#define ELF64_R_TYPE(i) ((i)&0xffffffff) #define ELF64_R_INFO(sym, type) ((((Elf64_Xword)(sym)) << 32) + (type)) /* Program segment header. */ @@ -741,7 +741,7 @@ typedef struct #define NT_PRSTATUS 1 /* Contains copy of prstatus struct */ #define NT_PRFPREG 2 /* Contains copy of fpregset \ - struct. */ + struct. */ #define NT_FPREGSET 2 /* Contains copy of fpregset struct */ #define NT_PRPSINFO 3 /* Contains copy of prpsinfo struct */ #define NT_PRXREG 4 /* Contains copy of prxregset struct */ @@ -758,7 +758,7 @@ typedef struct #define NT_LWPSINFO 17 /* Contains copy of lwpinfo struct */ #define NT_PRFPXREG 20 /* Contains copy of fprxregset struct */ #define NT_SIGINFO 0x53494749 /* Contains copy of siginfo_t, \ - size might increase */ + size might increase */ #define NT_FILE 0x46494c45 /* Contains information about mapped \ files */ #define NT_PRXFPREG 0x46e62b7f /* Contains copy of user_fxsr_struct */ @@ -796,11 +796,11 @@ typedef struct #define NT_S390_SYSTEM_CALL 0x307 /* s390 system call restart data */ #define NT_S390_TDB 0x308 /* s390 transaction diagnostic block */ #define NT_S390_VXRS_LOW 0x309 /* s390 vector registers 0-15 \ - upper half. */ + upper half. */ #define NT_S390_VXRS_HIGH 0x30a /* s390 vector registers 16-31. */ #define NT_S390_GS_CB 0x30b /* s390 guarded storage registers. */ #define NT_S390_GS_BC 0x30c /* s390 guarded storage \ - broadcast control block. */ + broadcast control block. */ #define NT_S390_RI_CB 0x30d /* s390 runtime instrumentation. */ #define NT_ARM_VFP 0x400 /* ARM VFP/NEON registers */ #define NT_ARM_TLS 0x401 /* ARM TLS register */ @@ -808,7 +808,7 @@ typedef struct #define NT_ARM_HW_WATCH 0x403 /* ARM hardware watchpoint registers */ #define NT_ARM_SYSTEM_CALL 0x404 /* ARM system call number */ #define NT_ARM_SVE 0x405 /* ARM Scalable Vector Extension \ - registers */ + registers */ #define NT_ARM_PAC_MASK 0x406 /* ARM pointer authentication \ code masks. */ #define NT_ARM_PACA_KEYS 0x407 /* ARM pointer authentication \ @@ -901,7 +901,7 @@ typedef struct #define DT_MOVESZ 0x6ffffdfb #define DT_FEATURE_1 0x6ffffdfc /* Feature selection (DTF_*). */ #define DT_POSFLAG_1 0x6ffffdfd /* Flags for DT_* entries, effecting \ - the following DT_* entry. */ + the following DT_* entry. */ #define DT_SYMINSZ 0x6ffffdfe /* Size of syminfo table (in bytes) */ #define DT_SYMINENT 0x6ffffdff /* Entry size of syminfo */ #define DT_VALRNGHI 0x6ffffdff @@ -939,10 +939,10 @@ typedef struct /* These were chosen by Sun. */ #define DT_FLAGS_1 0x6ffffffb /* State flags, see DF_1_* below. */ #define DT_VERDEF 0x6ffffffc /* Address of version definition \ - table */ + table */ #define DT_VERDEFNUM 0x6ffffffd /* Number of version definitions */ #define DT_VERNEED 0x6ffffffe /* Address of table with needed \ - versions */ + versions */ #define DT_VERNEEDNUM 0x6fffffff /* Number of needed versions */ #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */ #define DT_VERSIONTAGNUM 16 @@ -1168,7 +1168,7 @@ typedef struct /* Some more special a_type values describing the hardware. */ #define AT_PLATFORM 15 /* String identifying platform. */ #define AT_HWCAP 16 /* Machine-dependent hints about \ - processor capabilities. */ + processor capabilities. */ /* This entry gives some information about the FPU initialization performed by the kernel. */ @@ -1418,7 +1418,7 @@ typedef struct #define RZ_68K_TLS_IE16 35 /* 16 bit GOT offset for IE */ #define RZ_68K_TLS_IE8 36 /* 8 bit GOT offset for IE */ #define RZ_68K_TLS_LE32 37 /* 32 bit offset relative to \ - static TLS block */ + static TLS block */ #define RZ_68K_TLS_LE16 38 /* 16 bit offset relative to \ static TLS block */ #define RZ_68K_TLS_LE8 39 /* 8 bit offset relative to \ @@ -1447,7 +1447,7 @@ typedef struct #define RZ_386_32PLT 11 #define RZ_386_TLS_TPOFF 14 /* Offset in static TLS block */ #define RZ_386_TLS_IE 15 /* Address of GOT entry for static TLS \ - block offset */ + block offset */ #define RZ_386_TLS_GOTIE 16 /* GOT entry for static TLS block \ offset */ #define RZ_386_TLS_LE 17 /* Offset relative to static TLS \ @@ -1475,7 +1475,7 @@ typedef struct #define RZ_386_TLS_LDM_POP 31 /* Tag for popl in LDM TLS code */ #define RZ_386_TLS_LDO_32 32 /* Offset relative to TLS block */ #define RZ_386_TLS_IE_32 33 /* GOT entry for negated static TLS \ - block offset */ + block offset */ #define RZ_386_TLS_LE_32 34 /* Negated offset relative to static \ TLS block */ #define RZ_386_TLS_DTPMOD32 35 /* ID of module containing symbol */ @@ -1492,7 +1492,7 @@ typedef struct offset for the symbol. */ #define RZ_386_IRELATIVE 42 /* Adjust indirectly by program base */ #define RZ_386_GOT32X 43 /* Load from 32 bit GOT entry, \ - relaxable. */ + relaxable. */ /* Keep this the last entry. */ #define RZ_386_NUM 44 @@ -2649,7 +2649,7 @@ enum { #define STO_PPC64_LOCAL_BIT 5 #define STO_PPC64_LOCAL_MASK (7 << STO_PPC64_LOCAL_BIT) #define PPC64_LOCAL_ENTRY_OFFSET(other) \ - (((1 << (((other) & STO_PPC64_LOCAL_MASK) >> STO_PPC64_LOCAL_BIT)) >> 2) << 2) + (((1 << (((other)&STO_PPC64_LOCAL_MASK) >> STO_PPC64_LOCAL_BIT)) >> 2) << 2) /* ARM specific declarations */ @@ -2681,7 +2681,7 @@ enum { #define EF_ARM_BE8 0x00800000 #define EF_ARM_LE8 0x00400000 -#define EF_ARM_EABI_VERSION(flags) ((flags) & EF_ARM_EABIMASK) +#define EF_ARM_EABI_VERSION(flags) ((flags)&EF_ARM_EABIMASK) #define EF_ARM_EABI_UNKNOWN 0x00000000 #define EF_ARM_EABI_VER1 0x01000000 #define EF_ARM_EABI_VER2 0x02000000 @@ -2696,7 +2696,7 @@ enum { /* ARM-specific values for sh_flags */ #define SHF_ARM_ENTRYSECT 0x10000000 /* Section contains an entry point */ #define SHF_ARM_COMDEF 0x80000000 /* Section may be multiply defined \ - in the input to a link step. */ + in the input to a link step. */ /* ARM-specific program header flags */ #define PF_ARM_SB 0x10000000 /* Segment contains the location \ @@ -2874,7 +2874,7 @@ enum { #define RZ_ARM_SBREL32 9 #define RZ_ARM_THM_PC22 10 /* PC relative 24 bit (Thumb32 BL). */ #define RZ_ARM_THM_PC8 11 /* PC relative & 0x3FC \ - (Thumb16 LDR, ADD, ADR). */ + (Thumb16 LDR, ADD, ADR). */ #define RZ_ARM_AMP_VCALL9 12 #define RZ_ARM_SWI24 13 /* Obsolete static relocation. */ #define RZ_ARM_TLS_DESC 13 /* Dynamic relocation. */ @@ -2894,7 +2894,7 @@ enum { #define RZ_ARM_PLT32 27 /* Deprecated, 32 bit PLT address. */ #define RZ_ARM_CALL 28 /* PC relative 24 bit (BL, BLX). */ #define RZ_ARM_JUMP24 29 /* PC relative 24 bit \ - (B, BL). */ + (B, BL). */ #define RZ_ARM_THM_JUMP24 30 /* PC relative 24 bit (Thumb32 B.W). */ #define RZ_ARM_BASE_ABS 31 /* Adjust by program base. */ #define RZ_ARM_ALU_PCREL_7_0 32 /* Obsolete. */ @@ -2914,7 +2914,7 @@ enum { #define RZ_ARM_MOVT_PREL 46 /* PC relative (MOVT). */ #define RZ_ARM_THM_MOVW_ABS_NC 47 /* Direct 16 bit (Thumb32 MOVW). */ #define RZ_ARM_THM_MOVT_ABS 48 /* Direct high 16 bit \ - (Thumb32 MOVT). */ + (Thumb32 MOVT). */ #define RZ_ARM_THM_MOVW_PREL_NC 49 /* PC relative 16 bit \ (Thumb32 MOVW). */ #define RZ_ARM_THM_MOVT_PREL 50 /* PC relative high 16 bit \ @@ -2937,7 +2937,7 @@ enum { #define RZ_ARM_LDR_PC_G1 62 /* PC relative (LDR,STR,LDRB,STRB). */ #define RZ_ARM_LDR_PC_G2 63 /* PC relative (LDR,STR,LDRB,STRB). */ #define RZ_ARM_LDRS_PC_G0 64 /* PC relative (STR{D,H}, \ - LDR{D,SB,H,SH}). */ + LDR{D,SB,H,SH}). */ #define RZ_ARM_LDRS_PC_G1 65 /* PC relative (STR{D,H}, \ LDR{D,SB,H,SH}). */ #define RZ_ARM_LDRS_PC_G2 66 /* PC relative (STR{D,H}, \ @@ -2951,7 +2951,7 @@ enum { #define RZ_ARM_ALU_SB_G1 73 /* Program base relative (ADD,SUB). */ #define RZ_ARM_ALU_SB_G2 74 /* Program base relative (ADD,SUB). */ #define RZ_ARM_LDR_SB_G0 75 /* Program base relative (LDR, \ - STR, LDRB, STRB). */ + STR, LDRB, STRB). */ #define RZ_ARM_LDR_SB_G1 76 /* Program base relative \ (LDR, STR, LDRB, STRB). */ #define RZ_ARM_LDR_SB_G2 77 /* Program base relative \ @@ -2985,7 +2985,7 @@ enum { #define RZ_ARM_GOT_ABS 95 /* GOT entry. */ #define RZ_ARM_GOT_PREL 96 /* PC relative GOT entry. */ #define RZ_ARM_GOT_BREL12 97 /* GOT entry relative to GOT \ - origin (LDR). */ + origin (LDR). */ #define RZ_ARM_GOTOFF12 98 /* 12 bit, GOT entry relative \ to GOT origin (LDR, STR). */ #define RZ_ARM_GOTRELAX 99 @@ -2993,7 +2993,7 @@ enum { #define RZ_ARM_GNU_VTINHERIT 101 #define RZ_ARM_THM_PC11 102 /* PC relative & 0xFFE (Thumb16 B). */ #define RZ_ARM_THM_PC9 103 /* PC relative & 0x1FE \ - (Thumb16 B/B). */ + (Thumb16 B/B). */ #define RZ_ARM_TLS_GD32 104 /* PC-rel 32 bit for global dynamic \ thread local data */ #define RZ_ARM_TLS_LDM32 105 /* PC-rel 32 bit for local dynamic \ @@ -3015,7 +3015,7 @@ enum { #define RZ_ARM_THM_TLS_DESCSEQ16 129 #define RZ_ARM_THM_TLS_DESCSEQ32 130 #define RZ_ARM_THM_GOT_BREL12 131 /* GOT entry relative to GOT \ - origin, 12 bit (Thumb32 LDR). */ + origin, 12 bit (Thumb32 LDR). */ #define RZ_ARM_IRELATIVE 160 #define RZ_ARM_RXPC25 249 #define RZ_ARM_RSBREL32 250 @@ -3362,7 +3362,7 @@ enum { #define RZ_390_TLS_DTPMOD 54 /* ID of module containing symbol. */ #define RZ_390_TLS_DTPOFF 55 /* Offset in TLS block. */ #define RZ_390_TLS_TPOFF 56 /* Negated offset in static TLS \ - block. */ + block. */ #define RZ_390_20 57 /* Direct 20 bit. */ #define RZ_390_GOT20 58 /* 20 bit GOT offset. */ #define RZ_390_GOTPLT20 59 /* 20 bit offset to jump slot. */ @@ -3407,7 +3407,7 @@ enum { #define RZ_X86_64_JUMP_SLOT 7 /* Create PLT entry */ #define RZ_X86_64_RELATIVE 8 /* Adjust by program base */ #define RZ_X86_64_GOTPCREL 9 /* 32 bit signed PC relative \ - offset to GOT */ + offset to GOT */ #define RZ_X86_64_32 10 /* Direct 32 bit zero extended */ #define RZ_X86_64_32S 11 /* Direct 32 bit sign extended */ #define RZ_X86_64_16 12 /* Direct 16 bit zero extended */ @@ -3418,7 +3418,7 @@ enum { #define RZ_X86_64_DTPOFF64 17 /* Offset in module's TLS block */ #define RZ_X86_64_TPOFF64 18 /* Offset in initial TLS block */ #define RZ_X86_64_TLSGD 19 /* 32 bit signed PC relative offset \ - to two GOT entries for GD symbol */ + to two GOT entries for GD symbol */ #define RZ_X86_64_TLSLD 20 /* 32 bit signed PC relative offset \ to two GOT entries for LD symbol */ #define RZ_X86_64_DTPOFF32 21 /* Offset in TLS block */ @@ -3428,7 +3428,7 @@ enum { #define RZ_X86_64_PC64 24 /* PC relative 64 bit */ #define RZ_X86_64_GOTOFF64 25 /* 64 bit offset to GOT */ #define RZ_X86_64_GOTPC32 26 /* 32 bit signed pc relative \ - offset to GOT */ + offset to GOT */ #define RZ_X86_64_GOT64 27 /* 64-bit GOT entry offset */ #define RZ_X86_64_GOTPCREL64 28 /* 64-bit PC relative offset \ to GOT entry */ @@ -3440,7 +3440,7 @@ enum { #define RZ_X86_64_SIZE64 33 /* Size of symbol plus 64-bit addend */ #define RZ_X86_64_GOTPC32_TLSDESC 34 /* GOT offset for TLS descriptor. */ #define RZ_X86_64_TLSDESC_CALL 35 /* Marker for call through TLS \ - descriptor. */ + descriptor. */ #define RZ_X86_64_TLSDESC 36 /* TLS descriptor. */ #define RZ_X86_64_IRELATIVE 37 /* Adjust indirectly by program base */ #define RZ_X86_64_RELATIVE64 38 /* 64-bit adjust by program base */ @@ -3486,7 +3486,7 @@ enum { #define RZ_MN10300_TLS_LD 25 /* 32-bit offset for local dynamic. */ #define RZ_MN10300_TLS_LDO 26 /* Module-relative offset. */ #define RZ_MN10300_TLS_GOTIE 27 /* GOT offset for static TLS block \ - offset. */ + offset. */ #define RZ_MN10300_TLS_IE 28 /* GOT address for static TLS block \ offset. */ #define RZ_MN10300_TLS_LE 29 /* Offset relative to static TLS \ @@ -3495,7 +3495,7 @@ enum { #define RZ_MN10300_TLS_DTPOFF 31 /* Offset in module TLS block. */ #define RZ_MN10300_TLS_TPOFF 32 /* Offset in static TLS block. */ #define RZ_MN10300_SYM_DIFF 33 /* Adjustment for next reloc as needed \ - by linker relaxation. */ + by linker relaxation. */ #define RZ_MN10300_ALIGN 34 /* Alignment requirement for linker \ relaxation. */ #define RZ_MN10300_NUM 35 @@ -3613,7 +3613,7 @@ enum { #define RZ_NIOS2_CJMP 19 /* Conditional branch. */ #define RZ_NIOS2_CALLR 20 /* Indirect call through register. */ #define RZ_NIOS2_ALIGN 21 /* Alignment requirement for \ - linker relaxation. */ + linker relaxation. */ #define RZ_NIOS2_GOT16 22 /* 16 bit GOT entry. */ #define RZ_NIOS2_CALL16 23 /* 16 bit GOT entry for function. */ #define RZ_NIOS2_GOTOFF_LO 24 /* %lo of offset to GOT pointer. */ diff --git a/librz/bin/format/java/class_attribute.h b/librz/bin/format/java/class_attribute.h index b9550e4b1f1..3e0fedfbbbd 100644 --- a/librz/bin/format/java/class_attribute.h +++ b/librz/bin/format/java/class_attribute.h @@ -102,7 +102,7 @@ typedef struct java_attribute_module_t { ut16 module_version_index; ut16 requires_count; - ModuleRequire * requires; + ModuleRequire *requires; ut16 exports_count; ModuleExport *exports; diff --git a/librz/bin/format/mach0/mach0_defines.h b/librz/bin/format/mach0/mach0_defines.h index bd1485565bb..a0417b5dd08 100644 --- a/librz/bin/format/mach0/mach0_defines.h +++ b/librz/bin/format/mach0/mach0_defines.h @@ -1055,7 +1055,7 @@ static inline uint16_t GET_LIBRARY_ORDINAL(uint16_t n_desc) { } static inline void SET_LIBRARY_ORDINAL(uint16_t *n_desc, uint8_t ordinal) { - *n_desc = (((*n_desc) & 0x00ff) | (((ordinal) & 0xff) << 8)); + *n_desc = (((*n_desc) & 0x00ff) | (((ordinal)&0xff) << 8)); } static inline uint8_t GET_COMM_ALIGN(uint16_t n_desc) { diff --git a/librz/bin/format/objc/mach0_classes.c b/librz/bin/format/objc/mach0_classes.c index 8e59e1fa8fa..53c096c36eb 100644 --- a/librz/bin/format/objc/mach0_classes.c +++ b/librz/bin/format/objc/mach0_classes.c @@ -18,7 +18,7 @@ #define METHOD_LIST_FLAG_IS_PREOPT 0x3 #define METHOD_LIST_ENTSIZE_FLAG_MASK 0xffff0003 -#define RO_DATA_PTR(x) ((x) & FAST_DATA_MASK) +#define RO_DATA_PTR(x) ((x)&FAST_DATA_MASK) #if RZ_BIN_MACH064 #define rz_buf_read_mach0_ut_offset rz_buf_read_ble64_offset diff --git a/librz/bin/format/pe/pe_rsrc.c b/librz/bin/format/pe/pe_rsrc.c index eca92cdbbe4..f15d1e1038d 100644 --- a/librz/bin/format/pe/pe_rsrc.c +++ b/librz/bin/format/pe/pe_rsrc.c @@ -129,7 +129,7 @@ static void free_StringFileInfo(StringFileInfo *stringFileInfo) { } } -#define align32(x) x = (((x) & 0x3) == 0) ? (x) : ((x) & ~0x3) + 0x4; +#define align32(x) x = (((x)&0x3) == 0) ? (x) : ((x) & ~0x3) + 0x4; static void free_VS_VERSIONINFO(PE_VS_VERSIONINFO *vs_VersionInfo) { if (vs_VersionInfo) { diff --git a/librz/bin/p/bin_avr.c b/librz/bin/p/bin_avr.c index 637f795b279..7f27b4aeeee 100644 --- a/librz/bin/p/bin_avr.c +++ b/librz/bin/p/bin_avr.c @@ -7,15 +7,15 @@ #define CHECK4INSTR(b, instr, size) \ if (!instr(b, 0) || \ !instr((b), (size)) || \ - !instr((b), (size) * 2) || \ - !instr((b), (size) * 3)) { \ + !instr((b), (size)*2) || \ + !instr((b), (size)*3)) { \ return false; \ } #define CHECK3INSTR(b, instr, size) \ if (!instr((b), (size)) || \ - !instr((b), (size) * 2) || \ - !instr((b), (size) * 3)) { \ + !instr((b), (size)*2) || \ + !instr((b), (size)*3)) { \ return false; \ } diff --git a/librz/bin/p/bin_elf.inc b/librz/bin/p/bin_elf.inc index db2101a4a9b..c7382dba3cc 100644 --- a/librz/bin/p/bin_elf.inc +++ b/librz/bin/p/bin_elf.inc @@ -1023,7 +1023,7 @@ static void patch_reloc_hexagon(RZ_INOUT RzBuffer *buf_patched, const ut64 patch // AARCH64-specific defines // Take the PAGE component of an address or offset. #define PG(x) ((x) & ~0xFFFULL) -#define PG_OFFSET(x) ((x) & 0xFFFULL) +#define PG_OFFSET(x) ((x)&0xFFFULL) #define ADR_IMM_MASK1 (((1U << 2) - 1) << 29) #define ADR_IMM_MASK2 (((1U << 19) - 1) << 5) #define ADR_IMM_MASK3 (((1U << 19) - 1) << 2) diff --git a/librz/core/cbin.c b/librz/core/cbin.c index c9073165907..e636ccc54ef 100644 --- a/librz/core/cbin.c +++ b/librz/core/cbin.c @@ -24,14 +24,14 @@ #define LOAD_BSS_MALLOC 0 -#define IS_MODE_SET(mode) ((mode) & RZ_MODE_SET) -#define IS_MODE_SIMPLE(mode) ((mode) & RZ_MODE_SIMPLE) -#define IS_MODE_SIMPLEST(mode) ((mode) & RZ_MODE_SIMPLEST) -#define IS_MODE_JSON(mode) ((mode) & RZ_MODE_JSON) -#define IS_MODE_RZCMD(mode) ((mode) & RZ_MODE_RIZINCMD) -#define IS_MODE_EQUAL(mode) ((mode) & RZ_MODE_EQUAL) +#define IS_MODE_SET(mode) ((mode)&RZ_MODE_SET) +#define IS_MODE_SIMPLE(mode) ((mode)&RZ_MODE_SIMPLE) +#define IS_MODE_SIMPLEST(mode) ((mode)&RZ_MODE_SIMPLEST) +#define IS_MODE_JSON(mode) ((mode)&RZ_MODE_JSON) +#define IS_MODE_RZCMD(mode) ((mode)&RZ_MODE_RIZINCMD) +#define IS_MODE_EQUAL(mode) ((mode)&RZ_MODE_EQUAL) #define IS_MODE_NORMAL(mode) (!(mode)) -#define IS_MODE_CLASSDUMP(mode) ((mode) & RZ_MODE_CLASSDUMP) +#define IS_MODE_CLASSDUMP(mode) ((mode)&RZ_MODE_CLASSDUMP) // dup from cmd_info #define PAIR_WIDTH "9" diff --git a/librz/core/windows_heap.c b/librz/core/windows_heap.c index 97cb0b61b02..12c09ba817c 100644 --- a/librz/core/windows_heap.c +++ b/librz/core/windows_heap.c @@ -79,11 +79,11 @@ static size_t RtlpLFHKeyOffset = 0; } #define UPDATE_FLAGS(hb, flags) \ - if (((flags) & 0xf1) || ((flags) & 0x0200)) { \ + if (((flags)&0xf1) || ((flags)&0x0200)) { \ hb->dwFlags = LF32_FIXED; \ - } else if ((flags) & 0x20) { \ + } else if ((flags)&0x20) { \ hb->dwFlags = LF32_MOVEABLE; \ - } else if ((flags) & 0x0100) { \ + } else if ((flags)&0x0100) { \ hb->dwFlags = LF32_FREE; \ } \ hb->dwFlags |= ((flags) >> SHIFT) << SHIFT; diff --git a/librz/crypto/des.c b/librz/crypto/des.c index 82410457625..17d3107b707 100644 --- a/librz/crypto/des.c +++ b/librz/crypto/des.c @@ -253,7 +253,7 @@ RZ_API void rz_des_pc2(RZ_OUT ut32 *keylo, RZ_OUT ut32 *keyhi, RZ_IN ut32 deslo, ((deslo << 2) & 0x00020000) | ((deslo >> 10) & 0x00010000) | ((deshi >> 13) & 0x00002000) | ((deshi >> 4) & 0x00001000) | ((deshi << 6) & 0x00000800) | ((deshi >> 1) & 0x00000400) | - ((deshi >> 14) & 0x00000200) | ((deshi) & 0x00000100) | + ((deshi >> 14) & 0x00000200) | ((deshi)&0x00000100) | ((deshi >> 5) & 0x00000020) | ((deshi >> 10) & 0x00000010) | ((deshi >> 3) & 0x00000008) | ((deshi >> 18) & 0x00000004) | ((deshi >> 26) & 0x00000002) | ((deshi >> 24) & 0x00000001); @@ -266,7 +266,7 @@ RZ_API void rz_des_pc2(RZ_OUT ut32 *keylo, RZ_OUT ut32 *keyhi, RZ_IN ut32 deslo, ((deslo << 15) & 0x00020000) | ((deslo >> 4) & 0x00010000) | ((deshi >> 2) & 0x00002000) | ((deshi << 8) & 0x00001000) | ((deshi >> 14) & 0x00000808) | ((deshi >> 9) & 0x00000400) | - ((deshi) & 0x00000200) | ((deshi << 7) & 0x00000100) | + ((deshi)&0x00000200) | ((deshi << 7) & 0x00000100) | ((deshi >> 7) & 0x00000020) | ((deshi >> 3) & 0x00000011) | ((deshi << 2) & 0x00000004) | ((deshi >> 21) & 0x00000002); } diff --git a/librz/crypto/p/crypto_blowfish.c b/librz/crypto/p/crypto_blowfish.c index 66729a73042..0d0462828ed 100644 --- a/librz/crypto/p/crypto_blowfish.c +++ b/librz/crypto/p/crypto_blowfish.c @@ -169,7 +169,7 @@ static ut32 F(struct blowfish_state *const state, const ut32 inbuf) { ut8 a = (inbuf >> 24) & 0xff; ut8 b = (inbuf >> 16) & 0xff; ut8 c = (inbuf >> 8) & 0xff; - ut8 d = (inbuf) & 0xff; + ut8 d = (inbuf)&0xff; return ((state->s[0][a] + state->s[1][b]) ^ state->s[2][c]) + state->s[3][d]; } diff --git a/librz/egg/emit_x86.c b/librz/egg/emit_x86.c index 5fd83b7917d..6924d8a8fb4 100644 --- a/librz/egg/emit_x86.c +++ b/librz/egg/emit_x86.c @@ -170,7 +170,7 @@ static void emit_string(RzEgg *egg, const char *dstvar, const char *str, int j) /* XXX: Hack: Adjust offset in RZ_BP correctly for 64b addresses */ #define BPOFF (RZ_SZ - 4) -#define M32(x) (unsigned int)((x) & 0xffffffff) +#define M32(x) (unsigned int)((x)&0xffffffff) /* XXX: Assumes sizeof(ut32) == 4 */ for (i = 4; i <= oj; i += 4) { /* XXX endian issues (non-portable asm) */ diff --git a/librz/hash/algorithms/sm3/sm3.c b/librz/hash/algorithms/sm3/sm3.c index 1317998bca7..81153ddaaf2 100644 --- a/librz/hash/algorithms/sm3/sm3.c +++ b/librz/hash/algorithms/sm3/sm3.c @@ -182,7 +182,7 @@ static void sm3_process_block(const void *buffer, ut64 len, sm3_ctx_t *ctx) { ctx->total[0] += low_len; ctx->total[1] += (len >> 31 >> 1) + (ctx->total[0] < low_len); -#define rol(x, n) (((x) << ((n) & 31)) | ((x) >> ((32 - (n)) & 31))) +#define rol(x, n) (((x) << ((n)&31)) | ((x) >> ((32 - (n)) & 31))) #define P0(x) ((x) ^ rol(x, 9) ^ rol(x, 17)) #define P1(x) ((x) ^ rol(x, 15) ^ rol(x, 23)) diff --git a/librz/hash/algorithms/ssdeep/fnv_hash.h b/librz/hash/algorithms/ssdeep/fnv_hash.h index ce5eaa85545..117a66235f0 100644 --- a/librz/hash/algorithms/ssdeep/fnv_hash.h +++ b/librz/hash/algorithms/ssdeep/fnv_hash.h @@ -40,4291 +40,707 @@ #define FNV_B64_00 \ { \ - 0x00, \ - 0x01, \ - 0x02, \ - 0x03, \ - 0x04, \ - 0x05, \ - 0x06, \ - 0x07, \ - 0x08, \ - 0x09, \ - 0x0a, \ - 0x0b, \ - 0x0c, \ - 0x0d, \ - 0x0e, \ - 0x0f, \ - 0x10, \ - 0x11, \ - 0x12, \ - 0x13, \ - 0x14, \ - 0x15, \ - 0x16, \ - 0x17, \ - 0x18, \ - 0x19, \ - 0x1a, \ - 0x1b, \ - 0x1c, \ - 0x1d, \ - 0x1e, \ - 0x1f, \ - 0x20, \ - 0x21, \ - 0x22, \ - 0x23, \ - 0x24, \ - 0x25, \ - 0x26, \ - 0x27, \ - 0x28, \ - 0x29, \ - 0x2a, \ - 0x2b, \ - 0x2c, \ - 0x2d, \ - 0x2e, \ - 0x2f, \ - 0x30, \ - 0x31, \ - 0x32, \ - 0x33, \ - 0x34, \ - 0x35, \ - 0x36, \ - 0x37, \ - 0x38, \ - 0x39, \ - 0x3a, \ - 0x3b, \ - 0x3c, \ - 0x3d, \ - 0x3e, \ - 0x3f, \ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \ + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, \ + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, \ + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, \ + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, \ + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, \ + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, \ + 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, \ } #define FNV_B64_01 \ { \ - 0x13, \ - 0x12, \ - 0x11, \ - 0x10, \ - 0x17, \ - 0x16, \ - 0x15, \ - 0x14, \ - 0x1b, \ - 0x1a, \ - 0x19, \ - 0x18, \ - 0x1f, \ - 0x1e, \ - 0x1d, \ - 0x1c, \ - 0x03, \ - 0x02, \ - 0x01, \ - 0x00, \ - 0x07, \ - 0x06, \ - 0x05, \ - 0x04, \ - 0x0b, \ - 0x0a, \ - 0x09, \ - 0x08, \ - 0x0f, \ - 0x0e, \ - 0x0d, \ - 0x0c, \ - 0x33, \ - 0x32, \ - 0x31, \ - 0x30, \ - 0x37, \ - 0x36, \ - 0x35, \ - 0x34, \ - 0x3b, \ - 0x3a, \ - 0x39, \ - 0x38, \ - 0x3f, \ - 0x3e, \ - 0x3d, \ - 0x3c, \ - 0x23, \ - 0x22, \ - 0x21, \ - 0x20, \ - 0x27, \ - 0x26, \ - 0x25, \ - 0x24, \ - 0x2b, \ - 0x2a, \ - 0x29, \ - 0x28, \ - 0x2f, \ - 0x2e, \ - 0x2d, \ - 0x2c, \ + 0x13, 0x12, 0x11, 0x10, 0x17, 0x16, 0x15, 0x14, \ + 0x1b, 0x1a, 0x19, 0x18, 0x1f, 0x1e, 0x1d, 0x1c, \ + 0x03, 0x02, 0x01, 0x00, 0x07, 0x06, 0x05, 0x04, \ + 0x0b, 0x0a, 0x09, 0x08, 0x0f, 0x0e, 0x0d, 0x0c, \ + 0x33, 0x32, 0x31, 0x30, 0x37, 0x36, 0x35, 0x34, \ + 0x3b, 0x3a, 0x39, 0x38, 0x3f, 0x3e, 0x3d, 0x3c, \ + 0x23, 0x22, 0x21, 0x20, 0x27, 0x26, 0x25, 0x24, \ + 0x2b, 0x2a, 0x29, 0x28, 0x2f, 0x2e, 0x2d, 0x2c, \ } #define FNV_B64_02 \ { \ - 0x26, \ - 0x27, \ - 0x24, \ - 0x25, \ - 0x22, \ - 0x23, \ - 0x20, \ - 0x21, \ - 0x2e, \ - 0x2f, \ - 0x2c, \ - 0x2d, \ - 0x2a, \ - 0x2b, \ - 0x28, \ - 0x29, \ - 0x36, \ - 0x37, \ - 0x34, \ - 0x35, \ - 0x32, \ - 0x33, \ - 0x30, \ - 0x31, \ - 0x3e, \ - 0x3f, \ - 0x3c, \ - 0x3d, \ - 0x3a, \ - 0x3b, \ - 0x38, \ - 0x39, \ - 0x06, \ - 0x07, \ - 0x04, \ - 0x05, \ - 0x02, \ - 0x03, \ - 0x00, \ - 0x01, \ - 0x0e, \ - 0x0f, \ - 0x0c, \ - 0x0d, \ - 0x0a, \ - 0x0b, \ - 0x08, \ - 0x09, \ - 0x16, \ - 0x17, \ - 0x14, \ - 0x15, \ - 0x12, \ - 0x13, \ - 0x10, \ - 0x11, \ - 0x1e, \ - 0x1f, \ - 0x1c, \ - 0x1d, \ - 0x1a, \ - 0x1b, \ - 0x18, \ - 0x19, \ + 0x26, 0x27, 0x24, 0x25, 0x22, 0x23, 0x20, 0x21, \ + 0x2e, 0x2f, 0x2c, 0x2d, 0x2a, 0x2b, 0x28, 0x29, \ + 0x36, 0x37, 0x34, 0x35, 0x32, 0x33, 0x30, 0x31, \ + 0x3e, 0x3f, 0x3c, 0x3d, 0x3a, 0x3b, 0x38, 0x39, \ + 0x06, 0x07, 0x04, 0x05, 0x02, 0x03, 0x00, 0x01, \ + 0x0e, 0x0f, 0x0c, 0x0d, 0x0a, 0x0b, 0x08, 0x09, \ + 0x16, 0x17, 0x14, 0x15, 0x12, 0x13, 0x10, 0x11, \ + 0x1e, 0x1f, 0x1c, 0x1d, 0x1a, 0x1b, 0x18, 0x19, \ } #define FNV_B64_03 \ { \ - 0x39, \ - 0x38, \ - 0x3b, \ - 0x3a, \ - 0x3d, \ - 0x3c, \ - 0x3f, \ - 0x3e, \ - 0x31, \ - 0x30, \ - 0x33, \ - 0x32, \ - 0x35, \ - 0x34, \ - 0x37, \ - 0x36, \ - 0x29, \ - 0x28, \ - 0x2b, \ - 0x2a, \ - 0x2d, \ - 0x2c, \ - 0x2f, \ - 0x2e, \ - 0x21, \ - 0x20, \ - 0x23, \ - 0x22, \ - 0x25, \ - 0x24, \ - 0x27, \ - 0x26, \ - 0x19, \ - 0x18, \ - 0x1b, \ - 0x1a, \ - 0x1d, \ - 0x1c, \ - 0x1f, \ - 0x1e, \ - 0x11, \ - 0x10, \ - 0x13, \ - 0x12, \ - 0x15, \ - 0x14, \ - 0x17, \ - 0x16, \ - 0x09, \ - 0x08, \ - 0x0b, \ - 0x0a, \ - 0x0d, \ - 0x0c, \ - 0x0f, \ - 0x0e, \ - 0x01, \ - 0x00, \ - 0x03, \ - 0x02, \ - 0x05, \ - 0x04, \ - 0x07, \ - 0x06, \ + 0x39, 0x38, 0x3b, 0x3a, 0x3d, 0x3c, 0x3f, 0x3e, \ + 0x31, 0x30, 0x33, 0x32, 0x35, 0x34, 0x37, 0x36, \ + 0x29, 0x28, 0x2b, 0x2a, 0x2d, 0x2c, 0x2f, 0x2e, \ + 0x21, 0x20, 0x23, 0x22, 0x25, 0x24, 0x27, 0x26, \ + 0x19, 0x18, 0x1b, 0x1a, 0x1d, 0x1c, 0x1f, 0x1e, \ + 0x11, 0x10, 0x13, 0x12, 0x15, 0x14, 0x17, 0x16, \ + 0x09, 0x08, 0x0b, 0x0a, 0x0d, 0x0c, 0x0f, 0x0e, \ + 0x01, 0x00, 0x03, 0x02, 0x05, 0x04, 0x07, 0x06, \ } #define FNV_B64_04 \ { \ - 0x0c, \ - 0x0d, \ - 0x0e, \ - 0x0f, \ - 0x08, \ - 0x09, \ - 0x0a, \ - 0x0b, \ - 0x04, \ - 0x05, \ - 0x06, \ - 0x07, \ - 0x00, \ - 0x01, \ - 0x02, \ - 0x03, \ - 0x1c, \ - 0x1d, \ - 0x1e, \ - 0x1f, \ - 0x18, \ - 0x19, \ - 0x1a, \ - 0x1b, \ - 0x14, \ - 0x15, \ - 0x16, \ - 0x17, \ - 0x10, \ - 0x11, \ - 0x12, \ - 0x13, \ - 0x2c, \ - 0x2d, \ - 0x2e, \ - 0x2f, \ - 0x28, \ - 0x29, \ - 0x2a, \ - 0x2b, \ - 0x24, \ - 0x25, \ - 0x26, \ - 0x27, \ - 0x20, \ - 0x21, \ - 0x22, \ - 0x23, \ - 0x3c, \ - 0x3d, \ - 0x3e, \ - 0x3f, \ - 0x38, \ - 0x39, \ - 0x3a, \ - 0x3b, \ - 0x34, \ - 0x35, \ - 0x36, \ - 0x37, \ - 0x30, \ - 0x31, \ - 0x32, \ - 0x33, \ + 0x0c, 0x0d, 0x0e, 0x0f, 0x08, 0x09, 0x0a, 0x0b, \ + 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, \ + 0x1c, 0x1d, 0x1e, 0x1f, 0x18, 0x19, 0x1a, 0x1b, \ + 0x14, 0x15, 0x16, 0x17, 0x10, 0x11, 0x12, 0x13, \ + 0x2c, 0x2d, 0x2e, 0x2f, 0x28, 0x29, 0x2a, 0x2b, \ + 0x24, 0x25, 0x26, 0x27, 0x20, 0x21, 0x22, 0x23, \ + 0x3c, 0x3d, 0x3e, 0x3f, 0x38, 0x39, 0x3a, 0x3b, \ + 0x34, 0x35, 0x36, 0x37, 0x30, 0x31, 0x32, 0x33, \ } #define FNV_B64_05 \ { \ - 0x1f, \ - 0x1e, \ - 0x1d, \ - 0x1c, \ - 0x1b, \ - 0x1a, \ - 0x19, \ - 0x18, \ - 0x17, \ - 0x16, \ - 0x15, \ - 0x14, \ - 0x13, \ - 0x12, \ - 0x11, \ - 0x10, \ - 0x0f, \ - 0x0e, \ - 0x0d, \ - 0x0c, \ - 0x0b, \ - 0x0a, \ - 0x09, \ - 0x08, \ - 0x07, \ - 0x06, \ - 0x05, \ - 0x04, \ - 0x03, \ - 0x02, \ - 0x01, \ - 0x00, \ - 0x3f, \ - 0x3e, \ - 0x3d, \ - 0x3c, \ - 0x3b, \ - 0x3a, \ - 0x39, \ - 0x38, \ - 0x37, \ - 0x36, \ - 0x35, \ - 0x34, \ - 0x33, \ - 0x32, \ - 0x31, \ - 0x30, \ - 0x2f, \ - 0x2e, \ - 0x2d, \ - 0x2c, \ - 0x2b, \ - 0x2a, \ - 0x29, \ - 0x28, \ - 0x27, \ - 0x26, \ - 0x25, \ - 0x24, \ - 0x23, \ - 0x22, \ - 0x21, \ - 0x20, \ + 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, \ + 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, \ + 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, \ + 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, \ + 0x3f, 0x3e, 0x3d, 0x3c, 0x3b, 0x3a, 0x39, 0x38, \ + 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x30, \ + 0x2f, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x28, \ + 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x20, \ } #define FNV_B64_06 \ { \ - 0x32, \ - 0x33, \ - 0x30, \ - 0x31, \ - 0x36, \ - 0x37, \ - 0x34, \ - 0x35, \ - 0x3a, \ - 0x3b, \ - 0x38, \ - 0x39, \ - 0x3e, \ - 0x3f, \ - 0x3c, \ - 0x3d, \ - 0x22, \ - 0x23, \ - 0x20, \ - 0x21, \ - 0x26, \ - 0x27, \ - 0x24, \ - 0x25, \ - 0x2a, \ - 0x2b, \ - 0x28, \ - 0x29, \ - 0x2e, \ - 0x2f, \ - 0x2c, \ - 0x2d, \ - 0x12, \ - 0x13, \ - 0x10, \ - 0x11, \ - 0x16, \ - 0x17, \ - 0x14, \ - 0x15, \ - 0x1a, \ - 0x1b, \ - 0x18, \ - 0x19, \ - 0x1e, \ - 0x1f, \ - 0x1c, \ - 0x1d, \ - 0x02, \ - 0x03, \ - 0x00, \ - 0x01, \ - 0x06, \ - 0x07, \ - 0x04, \ - 0x05, \ - 0x0a, \ - 0x0b, \ - 0x08, \ - 0x09, \ - 0x0e, \ - 0x0f, \ - 0x0c, \ - 0x0d, \ + 0x32, 0x33, 0x30, 0x31, 0x36, 0x37, 0x34, 0x35, \ + 0x3a, 0x3b, 0x38, 0x39, 0x3e, 0x3f, 0x3c, 0x3d, \ + 0x22, 0x23, 0x20, 0x21, 0x26, 0x27, 0x24, 0x25, \ + 0x2a, 0x2b, 0x28, 0x29, 0x2e, 0x2f, 0x2c, 0x2d, \ + 0x12, 0x13, 0x10, 0x11, 0x16, 0x17, 0x14, 0x15, \ + 0x1a, 0x1b, 0x18, 0x19, 0x1e, 0x1f, 0x1c, 0x1d, \ + 0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05, \ + 0x0a, 0x0b, 0x08, 0x09, 0x0e, 0x0f, 0x0c, 0x0d, \ } #define FNV_B64_07 \ { \ - 0x05, \ - 0x04, \ - 0x07, \ - 0x06, \ - 0x01, \ - 0x00, \ - 0x03, \ - 0x02, \ - 0x0d, \ - 0x0c, \ - 0x0f, \ - 0x0e, \ - 0x09, \ - 0x08, \ - 0x0b, \ - 0x0a, \ - 0x15, \ - 0x14, \ - 0x17, \ - 0x16, \ - 0x11, \ - 0x10, \ - 0x13, \ - 0x12, \ - 0x1d, \ - 0x1c, \ - 0x1f, \ - 0x1e, \ - 0x19, \ - 0x18, \ - 0x1b, \ - 0x1a, \ - 0x25, \ - 0x24, \ - 0x27, \ - 0x26, \ - 0x21, \ - 0x20, \ - 0x23, \ - 0x22, \ - 0x2d, \ - 0x2c, \ - 0x2f, \ - 0x2e, \ - 0x29, \ - 0x28, \ - 0x2b, \ - 0x2a, \ - 0x35, \ - 0x34, \ - 0x37, \ - 0x36, \ - 0x31, \ - 0x30, \ - 0x33, \ - 0x32, \ - 0x3d, \ - 0x3c, \ - 0x3f, \ - 0x3e, \ - 0x39, \ - 0x38, \ - 0x3b, \ - 0x3a, \ + 0x05, 0x04, 0x07, 0x06, 0x01, 0x00, 0x03, 0x02, \ + 0x0d, 0x0c, 0x0f, 0x0e, 0x09, 0x08, 0x0b, 0x0a, \ + 0x15, 0x14, 0x17, 0x16, 0x11, 0x10, 0x13, 0x12, \ + 0x1d, 0x1c, 0x1f, 0x1e, 0x19, 0x18, 0x1b, 0x1a, \ + 0x25, 0x24, 0x27, 0x26, 0x21, 0x20, 0x23, 0x22, \ + 0x2d, 0x2c, 0x2f, 0x2e, 0x29, 0x28, 0x2b, 0x2a, \ + 0x35, 0x34, 0x37, 0x36, 0x31, 0x30, 0x33, 0x32, \ + 0x3d, 0x3c, 0x3f, 0x3e, 0x39, 0x38, 0x3b, 0x3a, \ } #define FNV_B64_08 \ { \ - 0x18, \ - 0x19, \ - 0x1a, \ - 0x1b, \ - 0x1c, \ - 0x1d, \ - 0x1e, \ - 0x1f, \ - 0x10, \ - 0x11, \ - 0x12, \ - 0x13, \ - 0x14, \ - 0x15, \ - 0x16, \ - 0x17, \ - 0x08, \ - 0x09, \ - 0x0a, \ - 0x0b, \ - 0x0c, \ - 0x0d, \ - 0x0e, \ - 0x0f, \ - 0x00, \ - 0x01, \ - 0x02, \ - 0x03, \ - 0x04, \ - 0x05, \ - 0x06, \ - 0x07, \ - 0x38, \ - 0x39, \ - 0x3a, \ - 0x3b, \ - 0x3c, \ - 0x3d, \ - 0x3e, \ - 0x3f, \ - 0x30, \ - 0x31, \ - 0x32, \ - 0x33, \ - 0x34, \ - 0x35, \ - 0x36, \ - 0x37, \ - 0x28, \ - 0x29, \ - 0x2a, \ - 0x2b, \ - 0x2c, \ - 0x2d, \ - 0x2e, \ - 0x2f, \ - 0x20, \ - 0x21, \ - 0x22, \ - 0x23, \ - 0x24, \ - 0x25, \ - 0x26, \ - 0x27, \ + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, \ + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, \ + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, \ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \ + 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, \ + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, \ + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, \ + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, \ } #define FNV_B64_09 \ { \ - 0x2b, \ - 0x2a, \ - 0x29, \ - 0x28, \ - 0x2f, \ - 0x2e, \ - 0x2d, \ - 0x2c, \ - 0x23, \ - 0x22, \ - 0x21, \ - 0x20, \ - 0x27, \ - 0x26, \ - 0x25, \ - 0x24, \ - 0x3b, \ - 0x3a, \ - 0x39, \ - 0x38, \ - 0x3f, \ - 0x3e, \ - 0x3d, \ - 0x3c, \ - 0x33, \ - 0x32, \ - 0x31, \ - 0x30, \ - 0x37, \ - 0x36, \ - 0x35, \ - 0x34, \ - 0x0b, \ - 0x0a, \ - 0x09, \ - 0x08, \ - 0x0f, \ - 0x0e, \ - 0x0d, \ - 0x0c, \ - 0x03, \ - 0x02, \ - 0x01, \ - 0x00, \ - 0x07, \ - 0x06, \ - 0x05, \ - 0x04, \ - 0x1b, \ - 0x1a, \ - 0x19, \ - 0x18, \ - 0x1f, \ - 0x1e, \ - 0x1d, \ - 0x1c, \ - 0x13, \ - 0x12, \ - 0x11, \ - 0x10, \ - 0x17, \ - 0x16, \ - 0x15, \ - 0x14, \ + 0x2b, 0x2a, 0x29, 0x28, 0x2f, 0x2e, 0x2d, 0x2c, \ + 0x23, 0x22, 0x21, 0x20, 0x27, 0x26, 0x25, 0x24, \ + 0x3b, 0x3a, 0x39, 0x38, 0x3f, 0x3e, 0x3d, 0x3c, \ + 0x33, 0x32, 0x31, 0x30, 0x37, 0x36, 0x35, 0x34, \ + 0x0b, 0x0a, 0x09, 0x08, 0x0f, 0x0e, 0x0d, 0x0c, \ + 0x03, 0x02, 0x01, 0x00, 0x07, 0x06, 0x05, 0x04, \ + 0x1b, 0x1a, 0x19, 0x18, 0x1f, 0x1e, 0x1d, 0x1c, \ + 0x13, 0x12, 0x11, 0x10, 0x17, 0x16, 0x15, 0x14, \ } #define FNV_B64_0A \ { \ - 0x3e, \ - 0x3f, \ - 0x3c, \ - 0x3d, \ - 0x3a, \ - 0x3b, \ - 0x38, \ - 0x39, \ - 0x36, \ - 0x37, \ - 0x34, \ - 0x35, \ - 0x32, \ - 0x33, \ - 0x30, \ - 0x31, \ - 0x2e, \ - 0x2f, \ - 0x2c, \ - 0x2d, \ - 0x2a, \ - 0x2b, \ - 0x28, \ - 0x29, \ - 0x26, \ - 0x27, \ - 0x24, \ - 0x25, \ - 0x22, \ - 0x23, \ - 0x20, \ - 0x21, \ - 0x1e, \ - 0x1f, \ - 0x1c, \ - 0x1d, \ - 0x1a, \ - 0x1b, \ - 0x18, \ - 0x19, \ - 0x16, \ - 0x17, \ - 0x14, \ - 0x15, \ - 0x12, \ - 0x13, \ - 0x10, \ - 0x11, \ - 0x0e, \ - 0x0f, \ - 0x0c, \ - 0x0d, \ - 0x0a, \ - 0x0b, \ - 0x08, \ - 0x09, \ - 0x06, \ - 0x07, \ - 0x04, \ - 0x05, \ - 0x02, \ - 0x03, \ - 0x00, \ - 0x01, \ + 0x3e, 0x3f, 0x3c, 0x3d, 0x3a, 0x3b, 0x38, 0x39, \ + 0x36, 0x37, 0x34, 0x35, 0x32, 0x33, 0x30, 0x31, \ + 0x2e, 0x2f, 0x2c, 0x2d, 0x2a, 0x2b, 0x28, 0x29, \ + 0x26, 0x27, 0x24, 0x25, 0x22, 0x23, 0x20, 0x21, \ + 0x1e, 0x1f, 0x1c, 0x1d, 0x1a, 0x1b, 0x18, 0x19, \ + 0x16, 0x17, 0x14, 0x15, 0x12, 0x13, 0x10, 0x11, \ + 0x0e, 0x0f, 0x0c, 0x0d, 0x0a, 0x0b, 0x08, 0x09, \ + 0x06, 0x07, 0x04, 0x05, 0x02, 0x03, 0x00, 0x01, \ } #define FNV_B64_0B \ { \ - 0x11, \ - 0x10, \ - 0x13, \ - 0x12, \ - 0x15, \ - 0x14, \ - 0x17, \ - 0x16, \ - 0x19, \ - 0x18, \ - 0x1b, \ - 0x1a, \ - 0x1d, \ - 0x1c, \ - 0x1f, \ - 0x1e, \ - 0x01, \ - 0x00, \ - 0x03, \ - 0x02, \ - 0x05, \ - 0x04, \ - 0x07, \ - 0x06, \ - 0x09, \ - 0x08, \ - 0x0b, \ - 0x0a, \ - 0x0d, \ - 0x0c, \ - 0x0f, \ - 0x0e, \ - 0x31, \ - 0x30, \ - 0x33, \ - 0x32, \ - 0x35, \ - 0x34, \ - 0x37, \ - 0x36, \ - 0x39, \ - 0x38, \ - 0x3b, \ - 0x3a, \ - 0x3d, \ - 0x3c, \ - 0x3f, \ - 0x3e, \ - 0x21, \ - 0x20, \ - 0x23, \ - 0x22, \ - 0x25, \ - 0x24, \ - 0x27, \ - 0x26, \ - 0x29, \ - 0x28, \ - 0x2b, \ - 0x2a, \ - 0x2d, \ - 0x2c, \ - 0x2f, \ - 0x2e, \ + 0x11, 0x10, 0x13, 0x12, 0x15, 0x14, 0x17, 0x16, \ + 0x19, 0x18, 0x1b, 0x1a, 0x1d, 0x1c, 0x1f, 0x1e, \ + 0x01, 0x00, 0x03, 0x02, 0x05, 0x04, 0x07, 0x06, \ + 0x09, 0x08, 0x0b, 0x0a, 0x0d, 0x0c, 0x0f, 0x0e, \ + 0x31, 0x30, 0x33, 0x32, 0x35, 0x34, 0x37, 0x36, \ + 0x39, 0x38, 0x3b, 0x3a, 0x3d, 0x3c, 0x3f, 0x3e, \ + 0x21, 0x20, 0x23, 0x22, 0x25, 0x24, 0x27, 0x26, \ + 0x29, 0x28, 0x2b, 0x2a, 0x2d, 0x2c, 0x2f, 0x2e, \ } #define FNV_B64_0C \ { \ - 0x24, \ - 0x25, \ - 0x26, \ - 0x27, \ - 0x20, \ - 0x21, \ - 0x22, \ - 0x23, \ - 0x2c, \ - 0x2d, \ - 0x2e, \ - 0x2f, \ - 0x28, \ - 0x29, \ - 0x2a, \ - 0x2b, \ - 0x34, \ - 0x35, \ - 0x36, \ - 0x37, \ - 0x30, \ - 0x31, \ - 0x32, \ - 0x33, \ - 0x3c, \ - 0x3d, \ - 0x3e, \ - 0x3f, \ - 0x38, \ - 0x39, \ - 0x3a, \ - 0x3b, \ - 0x04, \ - 0x05, \ - 0x06, \ - 0x07, \ - 0x00, \ - 0x01, \ - 0x02, \ - 0x03, \ - 0x0c, \ - 0x0d, \ - 0x0e, \ - 0x0f, \ - 0x08, \ - 0x09, \ - 0x0a, \ - 0x0b, \ - 0x14, \ - 0x15, \ - 0x16, \ - 0x17, \ - 0x10, \ - 0x11, \ - 0x12, \ - 0x13, \ - 0x1c, \ - 0x1d, \ - 0x1e, \ - 0x1f, \ - 0x18, \ - 0x19, \ - 0x1a, \ - 0x1b, \ + 0x24, 0x25, 0x26, 0x27, 0x20, 0x21, 0x22, 0x23, \ + 0x2c, 0x2d, 0x2e, 0x2f, 0x28, 0x29, 0x2a, 0x2b, \ + 0x34, 0x35, 0x36, 0x37, 0x30, 0x31, 0x32, 0x33, \ + 0x3c, 0x3d, 0x3e, 0x3f, 0x38, 0x39, 0x3a, 0x3b, \ + 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, \ + 0x0c, 0x0d, 0x0e, 0x0f, 0x08, 0x09, 0x0a, 0x0b, \ + 0x14, 0x15, 0x16, 0x17, 0x10, 0x11, 0x12, 0x13, \ + 0x1c, 0x1d, 0x1e, 0x1f, 0x18, 0x19, 0x1a, 0x1b, \ } #define FNV_B64_0D \ { \ - 0x37, \ - 0x36, \ - 0x35, \ - 0x34, \ - 0x33, \ - 0x32, \ - 0x31, \ - 0x30, \ - 0x3f, \ - 0x3e, \ - 0x3d, \ - 0x3c, \ - 0x3b, \ - 0x3a, \ - 0x39, \ - 0x38, \ - 0x27, \ - 0x26, \ - 0x25, \ - 0x24, \ - 0x23, \ - 0x22, \ - 0x21, \ - 0x20, \ - 0x2f, \ - 0x2e, \ - 0x2d, \ - 0x2c, \ - 0x2b, \ - 0x2a, \ - 0x29, \ - 0x28, \ - 0x17, \ - 0x16, \ - 0x15, \ - 0x14, \ - 0x13, \ - 0x12, \ - 0x11, \ - 0x10, \ - 0x1f, \ - 0x1e, \ - 0x1d, \ - 0x1c, \ - 0x1b, \ - 0x1a, \ - 0x19, \ - 0x18, \ - 0x07, \ - 0x06, \ - 0x05, \ - 0x04, \ - 0x03, \ - 0x02, \ - 0x01, \ - 0x00, \ - 0x0f, \ - 0x0e, \ - 0x0d, \ - 0x0c, \ - 0x0b, \ - 0x0a, \ - 0x09, \ - 0x08, \ + 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x30, \ + 0x3f, 0x3e, 0x3d, 0x3c, 0x3b, 0x3a, 0x39, 0x38, \ + 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x20, \ + 0x2f, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x28, \ + 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, \ + 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, \ + 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, \ + 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, \ } #define FNV_B64_0E \ { \ - 0x0a, \ - 0x0b, \ - 0x08, \ - 0x09, \ - 0x0e, \ - 0x0f, \ - 0x0c, \ - 0x0d, \ - 0x02, \ - 0x03, \ - 0x00, \ - 0x01, \ - 0x06, \ - 0x07, \ - 0x04, \ - 0x05, \ - 0x1a, \ - 0x1b, \ - 0x18, \ - 0x19, \ - 0x1e, \ - 0x1f, \ - 0x1c, \ - 0x1d, \ - 0x12, \ - 0x13, \ - 0x10, \ - 0x11, \ - 0x16, \ - 0x17, \ - 0x14, \ - 0x15, \ - 0x2a, \ - 0x2b, \ - 0x28, \ - 0x29, \ - 0x2e, \ - 0x2f, \ - 0x2c, \ - 0x2d, \ - 0x22, \ - 0x23, \ - 0x20, \ - 0x21, \ - 0x26, \ - 0x27, \ - 0x24, \ - 0x25, \ - 0x3a, \ - 0x3b, \ - 0x38, \ - 0x39, \ - 0x3e, \ - 0x3f, \ - 0x3c, \ - 0x3d, \ - 0x32, \ - 0x33, \ - 0x30, \ - 0x31, \ - 0x36, \ - 0x37, \ - 0x34, \ - 0x35, \ + 0x0a, 0x0b, 0x08, 0x09, 0x0e, 0x0f, 0x0c, 0x0d, \ + 0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05, \ + 0x1a, 0x1b, 0x18, 0x19, 0x1e, 0x1f, 0x1c, 0x1d, \ + 0x12, 0x13, 0x10, 0x11, 0x16, 0x17, 0x14, 0x15, \ + 0x2a, 0x2b, 0x28, 0x29, 0x2e, 0x2f, 0x2c, 0x2d, \ + 0x22, 0x23, 0x20, 0x21, 0x26, 0x27, 0x24, 0x25, \ + 0x3a, 0x3b, 0x38, 0x39, 0x3e, 0x3f, 0x3c, 0x3d, \ + 0x32, 0x33, 0x30, 0x31, 0x36, 0x37, 0x34, 0x35, \ } #define FNV_B64_0F \ { \ - 0x1d, \ - 0x1c, \ - 0x1f, \ - 0x1e, \ - 0x19, \ - 0x18, \ - 0x1b, \ - 0x1a, \ - 0x15, \ - 0x14, \ - 0x17, \ - 0x16, \ - 0x11, \ - 0x10, \ - 0x13, \ - 0x12, \ - 0x0d, \ - 0x0c, \ - 0x0f, \ - 0x0e, \ - 0x09, \ - 0x08, \ - 0x0b, \ - 0x0a, \ - 0x05, \ - 0x04, \ - 0x07, \ - 0x06, \ - 0x01, \ - 0x00, \ - 0x03, \ - 0x02, \ - 0x3d, \ - 0x3c, \ - 0x3f, \ - 0x3e, \ - 0x39, \ - 0x38, \ - 0x3b, \ - 0x3a, \ - 0x35, \ - 0x34, \ - 0x37, \ - 0x36, \ - 0x31, \ - 0x30, \ - 0x33, \ - 0x32, \ - 0x2d, \ - 0x2c, \ - 0x2f, \ - 0x2e, \ - 0x29, \ - 0x28, \ - 0x2b, \ - 0x2a, \ - 0x25, \ - 0x24, \ - 0x27, \ - 0x26, \ - 0x21, \ - 0x20, \ - 0x23, \ - 0x22, \ + 0x1d, 0x1c, 0x1f, 0x1e, 0x19, 0x18, 0x1b, 0x1a, \ + 0x15, 0x14, 0x17, 0x16, 0x11, 0x10, 0x13, 0x12, \ + 0x0d, 0x0c, 0x0f, 0x0e, 0x09, 0x08, 0x0b, 0x0a, \ + 0x05, 0x04, 0x07, 0x06, 0x01, 0x00, 0x03, 0x02, \ + 0x3d, 0x3c, 0x3f, 0x3e, 0x39, 0x38, 0x3b, 0x3a, \ + 0x35, 0x34, 0x37, 0x36, 0x31, 0x30, 0x33, 0x32, \ + 0x2d, 0x2c, 0x2f, 0x2e, 0x29, 0x28, 0x2b, 0x2a, \ + 0x25, 0x24, 0x27, 0x26, 0x21, 0x20, 0x23, 0x22, \ } #define FNV_B64_10 \ { \ - 0x30, \ - 0x31, \ - 0x32, \ - 0x33, \ - 0x34, \ - 0x35, \ - 0x36, \ - 0x37, \ - 0x38, \ - 0x39, \ - 0x3a, \ - 0x3b, \ - 0x3c, \ - 0x3d, \ - 0x3e, \ - 0x3f, \ - 0x20, \ - 0x21, \ - 0x22, \ - 0x23, \ - 0x24, \ - 0x25, \ - 0x26, \ - 0x27, \ - 0x28, \ - 0x29, \ - 0x2a, \ - 0x2b, \ - 0x2c, \ - 0x2d, \ - 0x2e, \ - 0x2f, \ - 0x10, \ - 0x11, \ - 0x12, \ - 0x13, \ - 0x14, \ - 0x15, \ - 0x16, \ - 0x17, \ - 0x18, \ - 0x19, \ - 0x1a, \ - 0x1b, \ - 0x1c, \ - 0x1d, \ - 0x1e, \ - 0x1f, \ - 0x00, \ - 0x01, \ - 0x02, \ - 0x03, \ - 0x04, \ - 0x05, \ - 0x06, \ - 0x07, \ - 0x08, \ - 0x09, \ - 0x0a, \ - 0x0b, \ - 0x0c, \ - 0x0d, \ - 0x0e, \ - 0x0f, \ + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, \ + 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, \ + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, \ + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, \ + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, \ + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, \ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \ + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, \ } #define FNV_B64_11 \ { \ - 0x03, \ - 0x02, \ - 0x01, \ - 0x00, \ - 0x07, \ - 0x06, \ - 0x05, \ - 0x04, \ - 0x0b, \ - 0x0a, \ - 0x09, \ - 0x08, \ - 0x0f, \ - 0x0e, \ - 0x0d, \ - 0x0c, \ - 0x13, \ - 0x12, \ - 0x11, \ - 0x10, \ - 0x17, \ - 0x16, \ - 0x15, \ - 0x14, \ - 0x1b, \ - 0x1a, \ - 0x19, \ - 0x18, \ - 0x1f, \ - 0x1e, \ - 0x1d, \ - 0x1c, \ - 0x23, \ - 0x22, \ - 0x21, \ - 0x20, \ - 0x27, \ - 0x26, \ - 0x25, \ - 0x24, \ - 0x2b, \ - 0x2a, \ - 0x29, \ - 0x28, \ - 0x2f, \ - 0x2e, \ - 0x2d, \ - 0x2c, \ - 0x33, \ - 0x32, \ - 0x31, \ - 0x30, \ - 0x37, \ - 0x36, \ - 0x35, \ - 0x34, \ - 0x3b, \ - 0x3a, \ - 0x39, \ - 0x38, \ - 0x3f, \ - 0x3e, \ - 0x3d, \ - 0x3c, \ + 0x03, 0x02, 0x01, 0x00, 0x07, 0x06, 0x05, 0x04, \ + 0x0b, 0x0a, 0x09, 0x08, 0x0f, 0x0e, 0x0d, 0x0c, \ + 0x13, 0x12, 0x11, 0x10, 0x17, 0x16, 0x15, 0x14, \ + 0x1b, 0x1a, 0x19, 0x18, 0x1f, 0x1e, 0x1d, 0x1c, \ + 0x23, 0x22, 0x21, 0x20, 0x27, 0x26, 0x25, 0x24, \ + 0x2b, 0x2a, 0x29, 0x28, 0x2f, 0x2e, 0x2d, 0x2c, \ + 0x33, 0x32, 0x31, 0x30, 0x37, 0x36, 0x35, 0x34, \ + 0x3b, 0x3a, 0x39, 0x38, 0x3f, 0x3e, 0x3d, 0x3c, \ } #define FNV_B64_12 \ { \ - 0x16, \ - 0x17, \ - 0x14, \ - 0x15, \ - 0x12, \ - 0x13, \ - 0x10, \ - 0x11, \ - 0x1e, \ - 0x1f, \ - 0x1c, \ - 0x1d, \ - 0x1a, \ - 0x1b, \ - 0x18, \ - 0x19, \ - 0x06, \ - 0x07, \ - 0x04, \ - 0x05, \ - 0x02, \ - 0x03, \ - 0x00, \ - 0x01, \ - 0x0e, \ - 0x0f, \ - 0x0c, \ - 0x0d, \ - 0x0a, \ - 0x0b, \ - 0x08, \ - 0x09, \ - 0x36, \ - 0x37, \ - 0x34, \ - 0x35, \ - 0x32, \ - 0x33, \ - 0x30, \ - 0x31, \ - 0x3e, \ - 0x3f, \ - 0x3c, \ - 0x3d, \ - 0x3a, \ - 0x3b, \ - 0x38, \ - 0x39, \ - 0x26, \ - 0x27, \ - 0x24, \ - 0x25, \ - 0x22, \ - 0x23, \ - 0x20, \ - 0x21, \ - 0x2e, \ - 0x2f, \ - 0x2c, \ - 0x2d, \ - 0x2a, \ - 0x2b, \ - 0x28, \ - 0x29, \ + 0x16, 0x17, 0x14, 0x15, 0x12, 0x13, 0x10, 0x11, \ + 0x1e, 0x1f, 0x1c, 0x1d, 0x1a, 0x1b, 0x18, 0x19, \ + 0x06, 0x07, 0x04, 0x05, 0x02, 0x03, 0x00, 0x01, \ + 0x0e, 0x0f, 0x0c, 0x0d, 0x0a, 0x0b, 0x08, 0x09, \ + 0x36, 0x37, 0x34, 0x35, 0x32, 0x33, 0x30, 0x31, \ + 0x3e, 0x3f, 0x3c, 0x3d, 0x3a, 0x3b, 0x38, 0x39, \ + 0x26, 0x27, 0x24, 0x25, 0x22, 0x23, 0x20, 0x21, \ + 0x2e, 0x2f, 0x2c, 0x2d, 0x2a, 0x2b, 0x28, 0x29, \ } #define FNV_B64_13 \ { \ - 0x29, \ - 0x28, \ - 0x2b, \ - 0x2a, \ - 0x2d, \ - 0x2c, \ - 0x2f, \ - 0x2e, \ - 0x21, \ - 0x20, \ - 0x23, \ - 0x22, \ - 0x25, \ - 0x24, \ - 0x27, \ - 0x26, \ - 0x39, \ - 0x38, \ - 0x3b, \ - 0x3a, \ - 0x3d, \ - 0x3c, \ - 0x3f, \ - 0x3e, \ - 0x31, \ - 0x30, \ - 0x33, \ - 0x32, \ - 0x35, \ - 0x34, \ - 0x37, \ - 0x36, \ - 0x09, \ - 0x08, \ - 0x0b, \ - 0x0a, \ - 0x0d, \ - 0x0c, \ - 0x0f, \ - 0x0e, \ - 0x01, \ - 0x00, \ - 0x03, \ - 0x02, \ - 0x05, \ - 0x04, \ - 0x07, \ - 0x06, \ - 0x19, \ - 0x18, \ - 0x1b, \ - 0x1a, \ - 0x1d, \ - 0x1c, \ - 0x1f, \ - 0x1e, \ - 0x11, \ - 0x10, \ - 0x13, \ - 0x12, \ - 0x15, \ - 0x14, \ - 0x17, \ - 0x16, \ + 0x29, 0x28, 0x2b, 0x2a, 0x2d, 0x2c, 0x2f, 0x2e, \ + 0x21, 0x20, 0x23, 0x22, 0x25, 0x24, 0x27, 0x26, \ + 0x39, 0x38, 0x3b, 0x3a, 0x3d, 0x3c, 0x3f, 0x3e, \ + 0x31, 0x30, 0x33, 0x32, 0x35, 0x34, 0x37, 0x36, \ + 0x09, 0x08, 0x0b, 0x0a, 0x0d, 0x0c, 0x0f, 0x0e, \ + 0x01, 0x00, 0x03, 0x02, 0x05, 0x04, 0x07, 0x06, \ + 0x19, 0x18, 0x1b, 0x1a, 0x1d, 0x1c, 0x1f, 0x1e, \ + 0x11, 0x10, 0x13, 0x12, 0x15, 0x14, 0x17, 0x16, \ } #define FNV_B64_14 \ { \ - 0x3c, \ - 0x3d, \ - 0x3e, \ - 0x3f, \ - 0x38, \ - 0x39, \ - 0x3a, \ - 0x3b, \ - 0x34, \ - 0x35, \ - 0x36, \ - 0x37, \ - 0x30, \ - 0x31, \ - 0x32, \ - 0x33, \ - 0x2c, \ - 0x2d, \ - 0x2e, \ - 0x2f, \ - 0x28, \ - 0x29, \ - 0x2a, \ - 0x2b, \ - 0x24, \ - 0x25, \ - 0x26, \ - 0x27, \ - 0x20, \ - 0x21, \ - 0x22, \ - 0x23, \ - 0x1c, \ - 0x1d, \ - 0x1e, \ - 0x1f, \ - 0x18, \ - 0x19, \ - 0x1a, \ - 0x1b, \ - 0x14, \ - 0x15, \ - 0x16, \ - 0x17, \ - 0x10, \ - 0x11, \ - 0x12, \ - 0x13, \ - 0x0c, \ - 0x0d, \ - 0x0e, \ - 0x0f, \ - 0x08, \ - 0x09, \ - 0x0a, \ - 0x0b, \ - 0x04, \ - 0x05, \ - 0x06, \ - 0x07, \ - 0x00, \ - 0x01, \ - 0x02, \ - 0x03, \ + 0x3c, 0x3d, 0x3e, 0x3f, 0x38, 0x39, 0x3a, 0x3b, \ + 0x34, 0x35, 0x36, 0x37, 0x30, 0x31, 0x32, 0x33, \ + 0x2c, 0x2d, 0x2e, 0x2f, 0x28, 0x29, 0x2a, 0x2b, \ + 0x24, 0x25, 0x26, 0x27, 0x20, 0x21, 0x22, 0x23, \ + 0x1c, 0x1d, 0x1e, 0x1f, 0x18, 0x19, 0x1a, 0x1b, \ + 0x14, 0x15, 0x16, 0x17, 0x10, 0x11, 0x12, 0x13, \ + 0x0c, 0x0d, 0x0e, 0x0f, 0x08, 0x09, 0x0a, 0x0b, \ + 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, \ } #define FNV_B64_15 \ { \ - 0x0f, \ - 0x0e, \ - 0x0d, \ - 0x0c, \ - 0x0b, \ - 0x0a, \ - 0x09, \ - 0x08, \ - 0x07, \ - 0x06, \ - 0x05, \ - 0x04, \ - 0x03, \ - 0x02, \ - 0x01, \ - 0x00, \ - 0x1f, \ - 0x1e, \ - 0x1d, \ - 0x1c, \ - 0x1b, \ - 0x1a, \ - 0x19, \ - 0x18, \ - 0x17, \ - 0x16, \ - 0x15, \ - 0x14, \ - 0x13, \ - 0x12, \ - 0x11, \ - 0x10, \ - 0x2f, \ - 0x2e, \ - 0x2d, \ - 0x2c, \ - 0x2b, \ - 0x2a, \ - 0x29, \ - 0x28, \ - 0x27, \ - 0x26, \ - 0x25, \ - 0x24, \ - 0x23, \ - 0x22, \ - 0x21, \ - 0x20, \ - 0x3f, \ - 0x3e, \ - 0x3d, \ - 0x3c, \ - 0x3b, \ - 0x3a, \ - 0x39, \ - 0x38, \ - 0x37, \ - 0x36, \ - 0x35, \ - 0x34, \ - 0x33, \ - 0x32, \ - 0x31, \ - 0x30, \ + 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, \ + 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, \ + 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, \ + 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, \ + 0x2f, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x28, \ + 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x20, \ + 0x3f, 0x3e, 0x3d, 0x3c, 0x3b, 0x3a, 0x39, 0x38, \ + 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x30, \ } #define FNV_B64_16 \ { \ - 0x22, \ - 0x23, \ - 0x20, \ - 0x21, \ - 0x26, \ - 0x27, \ - 0x24, \ - 0x25, \ - 0x2a, \ - 0x2b, \ - 0x28, \ - 0x29, \ - 0x2e, \ - 0x2f, \ - 0x2c, \ - 0x2d, \ - 0x32, \ - 0x33, \ - 0x30, \ - 0x31, \ - 0x36, \ - 0x37, \ - 0x34, \ - 0x35, \ - 0x3a, \ - 0x3b, \ - 0x38, \ - 0x39, \ - 0x3e, \ - 0x3f, \ - 0x3c, \ - 0x3d, \ - 0x02, \ - 0x03, \ - 0x00, \ - 0x01, \ - 0x06, \ - 0x07, \ - 0x04, \ - 0x05, \ - 0x0a, \ - 0x0b, \ - 0x08, \ - 0x09, \ - 0x0e, \ - 0x0f, \ - 0x0c, \ - 0x0d, \ - 0x12, \ - 0x13, \ - 0x10, \ - 0x11, \ - 0x16, \ - 0x17, \ - 0x14, \ - 0x15, \ - 0x1a, \ - 0x1b, \ - 0x18, \ - 0x19, \ - 0x1e, \ - 0x1f, \ - 0x1c, \ - 0x1d, \ + 0x22, 0x23, 0x20, 0x21, 0x26, 0x27, 0x24, 0x25, \ + 0x2a, 0x2b, 0x28, 0x29, 0x2e, 0x2f, 0x2c, 0x2d, \ + 0x32, 0x33, 0x30, 0x31, 0x36, 0x37, 0x34, 0x35, \ + 0x3a, 0x3b, 0x38, 0x39, 0x3e, 0x3f, 0x3c, 0x3d, \ + 0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05, \ + 0x0a, 0x0b, 0x08, 0x09, 0x0e, 0x0f, 0x0c, 0x0d, \ + 0x12, 0x13, 0x10, 0x11, 0x16, 0x17, 0x14, 0x15, \ + 0x1a, 0x1b, 0x18, 0x19, 0x1e, 0x1f, 0x1c, 0x1d, \ } #define FNV_B64_17 \ { \ - 0x35, \ - 0x34, \ - 0x37, \ - 0x36, \ - 0x31, \ - 0x30, \ - 0x33, \ - 0x32, \ - 0x3d, \ - 0x3c, \ - 0x3f, \ - 0x3e, \ - 0x39, \ - 0x38, \ - 0x3b, \ - 0x3a, \ - 0x25, \ - 0x24, \ - 0x27, \ - 0x26, \ - 0x21, \ - 0x20, \ - 0x23, \ - 0x22, \ - 0x2d, \ - 0x2c, \ - 0x2f, \ - 0x2e, \ - 0x29, \ - 0x28, \ - 0x2b, \ - 0x2a, \ - 0x15, \ - 0x14, \ - 0x17, \ - 0x16, \ - 0x11, \ - 0x10, \ - 0x13, \ - 0x12, \ - 0x1d, \ - 0x1c, \ - 0x1f, \ - 0x1e, \ - 0x19, \ - 0x18, \ - 0x1b, \ - 0x1a, \ - 0x05, \ - 0x04, \ - 0x07, \ - 0x06, \ - 0x01, \ - 0x00, \ - 0x03, \ - 0x02, \ - 0x0d, \ - 0x0c, \ - 0x0f, \ - 0x0e, \ - 0x09, \ - 0x08, \ - 0x0b, \ - 0x0a, \ + 0x35, 0x34, 0x37, 0x36, 0x31, 0x30, 0x33, 0x32, \ + 0x3d, 0x3c, 0x3f, 0x3e, 0x39, 0x38, 0x3b, 0x3a, \ + 0x25, 0x24, 0x27, 0x26, 0x21, 0x20, 0x23, 0x22, \ + 0x2d, 0x2c, 0x2f, 0x2e, 0x29, 0x28, 0x2b, 0x2a, \ + 0x15, 0x14, 0x17, 0x16, 0x11, 0x10, 0x13, 0x12, \ + 0x1d, 0x1c, 0x1f, 0x1e, 0x19, 0x18, 0x1b, 0x1a, \ + 0x05, 0x04, 0x07, 0x06, 0x01, 0x00, 0x03, 0x02, \ + 0x0d, 0x0c, 0x0f, 0x0e, 0x09, 0x08, 0x0b, 0x0a, \ } #define FNV_B64_18 \ { \ - 0x08, \ - 0x09, \ - 0x0a, \ - 0x0b, \ - 0x0c, \ - 0x0d, \ - 0x0e, \ - 0x0f, \ - 0x00, \ - 0x01, \ - 0x02, \ - 0x03, \ - 0x04, \ - 0x05, \ - 0x06, \ - 0x07, \ - 0x18, \ - 0x19, \ - 0x1a, \ - 0x1b, \ - 0x1c, \ - 0x1d, \ - 0x1e, \ - 0x1f, \ - 0x10, \ - 0x11, \ - 0x12, \ - 0x13, \ - 0x14, \ - 0x15, \ - 0x16, \ - 0x17, \ - 0x28, \ - 0x29, \ - 0x2a, \ - 0x2b, \ - 0x2c, \ - 0x2d, \ - 0x2e, \ - 0x2f, \ - 0x20, \ - 0x21, \ - 0x22, \ - 0x23, \ - 0x24, \ - 0x25, \ - 0x26, \ - 0x27, \ - 0x38, \ - 0x39, \ - 0x3a, \ - 0x3b, \ - 0x3c, \ - 0x3d, \ - 0x3e, \ - 0x3f, \ - 0x30, \ - 0x31, \ - 0x32, \ - 0x33, \ - 0x34, \ - 0x35, \ - 0x36, \ - 0x37, \ + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, \ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \ + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, \ + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, \ + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, \ + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, \ + 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, \ + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, \ } #define FNV_B64_19 \ { \ - 0x1b, \ - 0x1a, \ - 0x19, \ - 0x18, \ - 0x1f, \ - 0x1e, \ - 0x1d, \ - 0x1c, \ - 0x13, \ - 0x12, \ - 0x11, \ - 0x10, \ - 0x17, \ - 0x16, \ - 0x15, \ - 0x14, \ - 0x0b, \ - 0x0a, \ - 0x09, \ - 0x08, \ - 0x0f, \ - 0x0e, \ - 0x0d, \ - 0x0c, \ - 0x03, \ - 0x02, \ - 0x01, \ - 0x00, \ - 0x07, \ - 0x06, \ - 0x05, \ - 0x04, \ - 0x3b, \ - 0x3a, \ - 0x39, \ - 0x38, \ - 0x3f, \ - 0x3e, \ - 0x3d, \ - 0x3c, \ - 0x33, \ - 0x32, \ - 0x31, \ - 0x30, \ - 0x37, \ - 0x36, \ - 0x35, \ - 0x34, \ - 0x2b, \ - 0x2a, \ - 0x29, \ - 0x28, \ - 0x2f, \ - 0x2e, \ - 0x2d, \ - 0x2c, \ - 0x23, \ - 0x22, \ - 0x21, \ - 0x20, \ - 0x27, \ - 0x26, \ - 0x25, \ - 0x24, \ + 0x1b, 0x1a, 0x19, 0x18, 0x1f, 0x1e, 0x1d, 0x1c, \ + 0x13, 0x12, 0x11, 0x10, 0x17, 0x16, 0x15, 0x14, \ + 0x0b, 0x0a, 0x09, 0x08, 0x0f, 0x0e, 0x0d, 0x0c, \ + 0x03, 0x02, 0x01, 0x00, 0x07, 0x06, 0x05, 0x04, \ + 0x3b, 0x3a, 0x39, 0x38, 0x3f, 0x3e, 0x3d, 0x3c, \ + 0x33, 0x32, 0x31, 0x30, 0x37, 0x36, 0x35, 0x34, \ + 0x2b, 0x2a, 0x29, 0x28, 0x2f, 0x2e, 0x2d, 0x2c, \ + 0x23, 0x22, 0x21, 0x20, 0x27, 0x26, 0x25, 0x24, \ } #define FNV_B64_1A \ { \ - 0x2e, \ - 0x2f, \ - 0x2c, \ - 0x2d, \ - 0x2a, \ - 0x2b, \ - 0x28, \ - 0x29, \ - 0x26, \ - 0x27, \ - 0x24, \ - 0x25, \ - 0x22, \ - 0x23, \ - 0x20, \ - 0x21, \ - 0x3e, \ - 0x3f, \ - 0x3c, \ - 0x3d, \ - 0x3a, \ - 0x3b, \ - 0x38, \ - 0x39, \ - 0x36, \ - 0x37, \ - 0x34, \ - 0x35, \ - 0x32, \ - 0x33, \ - 0x30, \ - 0x31, \ - 0x0e, \ - 0x0f, \ - 0x0c, \ - 0x0d, \ - 0x0a, \ - 0x0b, \ - 0x08, \ - 0x09, \ - 0x06, \ - 0x07, \ - 0x04, \ - 0x05, \ - 0x02, \ - 0x03, \ - 0x00, \ - 0x01, \ - 0x1e, \ - 0x1f, \ - 0x1c, \ - 0x1d, \ - 0x1a, \ - 0x1b, \ - 0x18, \ - 0x19, \ - 0x16, \ - 0x17, \ - 0x14, \ - 0x15, \ - 0x12, \ - 0x13, \ - 0x10, \ - 0x11, \ + 0x2e, 0x2f, 0x2c, 0x2d, 0x2a, 0x2b, 0x28, 0x29, \ + 0x26, 0x27, 0x24, 0x25, 0x22, 0x23, 0x20, 0x21, \ + 0x3e, 0x3f, 0x3c, 0x3d, 0x3a, 0x3b, 0x38, 0x39, \ + 0x36, 0x37, 0x34, 0x35, 0x32, 0x33, 0x30, 0x31, \ + 0x0e, 0x0f, 0x0c, 0x0d, 0x0a, 0x0b, 0x08, 0x09, \ + 0x06, 0x07, 0x04, 0x05, 0x02, 0x03, 0x00, 0x01, \ + 0x1e, 0x1f, 0x1c, 0x1d, 0x1a, 0x1b, 0x18, 0x19, \ + 0x16, 0x17, 0x14, 0x15, 0x12, 0x13, 0x10, 0x11, \ } #define FNV_B64_1B \ { \ - 0x01, \ - 0x00, \ - 0x03, \ - 0x02, \ - 0x05, \ - 0x04, \ - 0x07, \ - 0x06, \ - 0x09, \ - 0x08, \ - 0x0b, \ - 0x0a, \ - 0x0d, \ - 0x0c, \ - 0x0f, \ - 0x0e, \ - 0x11, \ - 0x10, \ - 0x13, \ - 0x12, \ - 0x15, \ - 0x14, \ - 0x17, \ - 0x16, \ - 0x19, \ - 0x18, \ - 0x1b, \ - 0x1a, \ - 0x1d, \ - 0x1c, \ - 0x1f, \ - 0x1e, \ - 0x21, \ - 0x20, \ - 0x23, \ - 0x22, \ - 0x25, \ - 0x24, \ - 0x27, \ - 0x26, \ - 0x29, \ - 0x28, \ - 0x2b, \ - 0x2a, \ - 0x2d, \ - 0x2c, \ - 0x2f, \ - 0x2e, \ - 0x31, \ - 0x30, \ - 0x33, \ - 0x32, \ - 0x35, \ - 0x34, \ - 0x37, \ - 0x36, \ - 0x39, \ - 0x38, \ - 0x3b, \ - 0x3a, \ - 0x3d, \ - 0x3c, \ - 0x3f, \ - 0x3e, \ + 0x01, 0x00, 0x03, 0x02, 0x05, 0x04, 0x07, 0x06, \ + 0x09, 0x08, 0x0b, 0x0a, 0x0d, 0x0c, 0x0f, 0x0e, \ + 0x11, 0x10, 0x13, 0x12, 0x15, 0x14, 0x17, 0x16, \ + 0x19, 0x18, 0x1b, 0x1a, 0x1d, 0x1c, 0x1f, 0x1e, \ + 0x21, 0x20, 0x23, 0x22, 0x25, 0x24, 0x27, 0x26, \ + 0x29, 0x28, 0x2b, 0x2a, 0x2d, 0x2c, 0x2f, 0x2e, \ + 0x31, 0x30, 0x33, 0x32, 0x35, 0x34, 0x37, 0x36, \ + 0x39, 0x38, 0x3b, 0x3a, 0x3d, 0x3c, 0x3f, 0x3e, \ } #define FNV_B64_1C \ { \ - 0x14, \ - 0x15, \ - 0x16, \ - 0x17, \ - 0x10, \ - 0x11, \ - 0x12, \ - 0x13, \ - 0x1c, \ - 0x1d, \ - 0x1e, \ - 0x1f, \ - 0x18, \ - 0x19, \ - 0x1a, \ - 0x1b, \ - 0x04, \ - 0x05, \ - 0x06, \ - 0x07, \ - 0x00, \ - 0x01, \ - 0x02, \ - 0x03, \ - 0x0c, \ - 0x0d, \ - 0x0e, \ - 0x0f, \ - 0x08, \ - 0x09, \ - 0x0a, \ - 0x0b, \ - 0x34, \ - 0x35, \ - 0x36, \ - 0x37, \ - 0x30, \ - 0x31, \ - 0x32, \ - 0x33, \ - 0x3c, \ - 0x3d, \ - 0x3e, \ - 0x3f, \ - 0x38, \ - 0x39, \ - 0x3a, \ - 0x3b, \ - 0x24, \ - 0x25, \ - 0x26, \ - 0x27, \ - 0x20, \ - 0x21, \ - 0x22, \ - 0x23, \ - 0x2c, \ - 0x2d, \ - 0x2e, \ - 0x2f, \ - 0x28, \ - 0x29, \ - 0x2a, \ - 0x2b, \ + 0x14, 0x15, 0x16, 0x17, 0x10, 0x11, 0x12, 0x13, \ + 0x1c, 0x1d, 0x1e, 0x1f, 0x18, 0x19, 0x1a, 0x1b, \ + 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, \ + 0x0c, 0x0d, 0x0e, 0x0f, 0x08, 0x09, 0x0a, 0x0b, \ + 0x34, 0x35, 0x36, 0x37, 0x30, 0x31, 0x32, 0x33, \ + 0x3c, 0x3d, 0x3e, 0x3f, 0x38, 0x39, 0x3a, 0x3b, \ + 0x24, 0x25, 0x26, 0x27, 0x20, 0x21, 0x22, 0x23, \ + 0x2c, 0x2d, 0x2e, 0x2f, 0x28, 0x29, 0x2a, 0x2b, \ } #define FNV_B64_1D \ { \ - 0x27, \ - 0x26, \ - 0x25, \ - 0x24, \ - 0x23, \ - 0x22, \ - 0x21, \ - 0x20, \ - 0x2f, \ - 0x2e, \ - 0x2d, \ - 0x2c, \ - 0x2b, \ - 0x2a, \ - 0x29, \ - 0x28, \ - 0x37, \ - 0x36, \ - 0x35, \ - 0x34, \ - 0x33, \ - 0x32, \ - 0x31, \ - 0x30, \ - 0x3f, \ - 0x3e, \ - 0x3d, \ - 0x3c, \ - 0x3b, \ - 0x3a, \ - 0x39, \ - 0x38, \ - 0x07, \ - 0x06, \ - 0x05, \ - 0x04, \ - 0x03, \ - 0x02, \ - 0x01, \ - 0x00, \ - 0x0f, \ - 0x0e, \ - 0x0d, \ - 0x0c, \ - 0x0b, \ - 0x0a, \ - 0x09, \ - 0x08, \ - 0x17, \ - 0x16, \ - 0x15, \ - 0x14, \ - 0x13, \ - 0x12, \ - 0x11, \ - 0x10, \ - 0x1f, \ - 0x1e, \ - 0x1d, \ - 0x1c, \ - 0x1b, \ - 0x1a, \ - 0x19, \ - 0x18, \ + 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x20, \ + 0x2f, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x28, \ + 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x30, \ + 0x3f, 0x3e, 0x3d, 0x3c, 0x3b, 0x3a, 0x39, 0x38, \ + 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, \ + 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, \ + 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, \ + 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, \ } #define FNV_B64_1E \ { \ - 0x3a, \ - 0x3b, \ - 0x38, \ - 0x39, \ - 0x3e, \ - 0x3f, \ - 0x3c, \ - 0x3d, \ - 0x32, \ - 0x33, \ - 0x30, \ - 0x31, \ - 0x36, \ - 0x37, \ - 0x34, \ - 0x35, \ - 0x2a, \ - 0x2b, \ - 0x28, \ - 0x29, \ - 0x2e, \ - 0x2f, \ - 0x2c, \ - 0x2d, \ - 0x22, \ - 0x23, \ - 0x20, \ - 0x21, \ - 0x26, \ - 0x27, \ - 0x24, \ - 0x25, \ - 0x1a, \ - 0x1b, \ - 0x18, \ - 0x19, \ - 0x1e, \ - 0x1f, \ - 0x1c, \ - 0x1d, \ - 0x12, \ - 0x13, \ - 0x10, \ - 0x11, \ - 0x16, \ - 0x17, \ - 0x14, \ - 0x15, \ - 0x0a, \ - 0x0b, \ - 0x08, \ - 0x09, \ - 0x0e, \ - 0x0f, \ - 0x0c, \ - 0x0d, \ - 0x02, \ - 0x03, \ - 0x00, \ - 0x01, \ - 0x06, \ - 0x07, \ - 0x04, \ - 0x05, \ + 0x3a, 0x3b, 0x38, 0x39, 0x3e, 0x3f, 0x3c, 0x3d, \ + 0x32, 0x33, 0x30, 0x31, 0x36, 0x37, 0x34, 0x35, \ + 0x2a, 0x2b, 0x28, 0x29, 0x2e, 0x2f, 0x2c, 0x2d, \ + 0x22, 0x23, 0x20, 0x21, 0x26, 0x27, 0x24, 0x25, \ + 0x1a, 0x1b, 0x18, 0x19, 0x1e, 0x1f, 0x1c, 0x1d, \ + 0x12, 0x13, 0x10, 0x11, 0x16, 0x17, 0x14, 0x15, \ + 0x0a, 0x0b, 0x08, 0x09, 0x0e, 0x0f, 0x0c, 0x0d, \ + 0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05, \ } #define FNV_B64_1F \ { \ - 0x0d, \ - 0x0c, \ - 0x0f, \ - 0x0e, \ - 0x09, \ - 0x08, \ - 0x0b, \ - 0x0a, \ - 0x05, \ - 0x04, \ - 0x07, \ - 0x06, \ - 0x01, \ - 0x00, \ - 0x03, \ - 0x02, \ - 0x1d, \ - 0x1c, \ - 0x1f, \ - 0x1e, \ - 0x19, \ - 0x18, \ - 0x1b, \ - 0x1a, \ - 0x15, \ - 0x14, \ - 0x17, \ - 0x16, \ - 0x11, \ - 0x10, \ - 0x13, \ - 0x12, \ - 0x2d, \ - 0x2c, \ - 0x2f, \ - 0x2e, \ - 0x29, \ - 0x28, \ - 0x2b, \ - 0x2a, \ - 0x25, \ - 0x24, \ - 0x27, \ - 0x26, \ - 0x21, \ - 0x20, \ - 0x23, \ - 0x22, \ - 0x3d, \ - 0x3c, \ - 0x3f, \ - 0x3e, \ - 0x39, \ - 0x38, \ - 0x3b, \ - 0x3a, \ - 0x35, \ - 0x34, \ - 0x37, \ - 0x36, \ - 0x31, \ - 0x30, \ - 0x33, \ - 0x32, \ + 0x0d, 0x0c, 0x0f, 0x0e, 0x09, 0x08, 0x0b, 0x0a, \ + 0x05, 0x04, 0x07, 0x06, 0x01, 0x00, 0x03, 0x02, \ + 0x1d, 0x1c, 0x1f, 0x1e, 0x19, 0x18, 0x1b, 0x1a, \ + 0x15, 0x14, 0x17, 0x16, 0x11, 0x10, 0x13, 0x12, \ + 0x2d, 0x2c, 0x2f, 0x2e, 0x29, 0x28, 0x2b, 0x2a, \ + 0x25, 0x24, 0x27, 0x26, 0x21, 0x20, 0x23, 0x22, \ + 0x3d, 0x3c, 0x3f, 0x3e, 0x39, 0x38, 0x3b, 0x3a, \ + 0x35, 0x34, 0x37, 0x36, 0x31, 0x30, 0x33, 0x32, \ } #define FNV_B64_20 \ { \ - 0x20, \ - 0x21, \ - 0x22, \ - 0x23, \ - 0x24, \ - 0x25, \ - 0x26, \ - 0x27, \ - 0x28, \ - 0x29, \ - 0x2a, \ - 0x2b, \ - 0x2c, \ - 0x2d, \ - 0x2e, \ - 0x2f, \ - 0x30, \ - 0x31, \ - 0x32, \ - 0x33, \ - 0x34, \ - 0x35, \ - 0x36, \ - 0x37, \ - 0x38, \ - 0x39, \ - 0x3a, \ - 0x3b, \ - 0x3c, \ - 0x3d, \ - 0x3e, \ - 0x3f, \ - 0x00, \ - 0x01, \ - 0x02, \ - 0x03, \ - 0x04, \ - 0x05, \ - 0x06, \ - 0x07, \ - 0x08, \ - 0x09, \ - 0x0a, \ - 0x0b, \ - 0x0c, \ - 0x0d, \ - 0x0e, \ - 0x0f, \ - 0x10, \ - 0x11, \ - 0x12, \ - 0x13, \ - 0x14, \ - 0x15, \ - 0x16, \ - 0x17, \ - 0x18, \ - 0x19, \ - 0x1a, \ - 0x1b, \ - 0x1c, \ - 0x1d, \ - 0x1e, \ - 0x1f, \ + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, \ + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, \ + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, \ + 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, \ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \ + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, \ + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, \ + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, \ } #define FNV_B64_21 \ { \ - 0x33, \ - 0x32, \ - 0x31, \ - 0x30, \ - 0x37, \ - 0x36, \ - 0x35, \ - 0x34, \ - 0x3b, \ - 0x3a, \ - 0x39, \ - 0x38, \ - 0x3f, \ - 0x3e, \ - 0x3d, \ - 0x3c, \ - 0x23, \ - 0x22, \ - 0x21, \ - 0x20, \ - 0x27, \ - 0x26, \ - 0x25, \ - 0x24, \ - 0x2b, \ - 0x2a, \ - 0x29, \ - 0x28, \ - 0x2f, \ - 0x2e, \ - 0x2d, \ - 0x2c, \ - 0x13, \ - 0x12, \ - 0x11, \ - 0x10, \ - 0x17, \ - 0x16, \ - 0x15, \ - 0x14, \ - 0x1b, \ - 0x1a, \ - 0x19, \ - 0x18, \ - 0x1f, \ - 0x1e, \ - 0x1d, \ - 0x1c, \ - 0x03, \ - 0x02, \ - 0x01, \ - 0x00, \ - 0x07, \ - 0x06, \ - 0x05, \ - 0x04, \ - 0x0b, \ - 0x0a, \ - 0x09, \ - 0x08, \ - 0x0f, \ - 0x0e, \ - 0x0d, \ - 0x0c, \ + 0x33, 0x32, 0x31, 0x30, 0x37, 0x36, 0x35, 0x34, \ + 0x3b, 0x3a, 0x39, 0x38, 0x3f, 0x3e, 0x3d, 0x3c, \ + 0x23, 0x22, 0x21, 0x20, 0x27, 0x26, 0x25, 0x24, \ + 0x2b, 0x2a, 0x29, 0x28, 0x2f, 0x2e, 0x2d, 0x2c, \ + 0x13, 0x12, 0x11, 0x10, 0x17, 0x16, 0x15, 0x14, \ + 0x1b, 0x1a, 0x19, 0x18, 0x1f, 0x1e, 0x1d, 0x1c, \ + 0x03, 0x02, 0x01, 0x00, 0x07, 0x06, 0x05, 0x04, \ + 0x0b, 0x0a, 0x09, 0x08, 0x0f, 0x0e, 0x0d, 0x0c, \ } #define FNV_B64_22 \ { \ - 0x06, \ - 0x07, \ - 0x04, \ - 0x05, \ - 0x02, \ - 0x03, \ - 0x00, \ - 0x01, \ - 0x0e, \ - 0x0f, \ - 0x0c, \ - 0x0d, \ - 0x0a, \ - 0x0b, \ - 0x08, \ - 0x09, \ - 0x16, \ - 0x17, \ - 0x14, \ - 0x15, \ - 0x12, \ - 0x13, \ - 0x10, \ - 0x11, \ - 0x1e, \ - 0x1f, \ - 0x1c, \ - 0x1d, \ - 0x1a, \ - 0x1b, \ - 0x18, \ - 0x19, \ - 0x26, \ - 0x27, \ - 0x24, \ - 0x25, \ - 0x22, \ - 0x23, \ - 0x20, \ - 0x21, \ - 0x2e, \ - 0x2f, \ - 0x2c, \ - 0x2d, \ - 0x2a, \ - 0x2b, \ - 0x28, \ - 0x29, \ - 0x36, \ - 0x37, \ - 0x34, \ - 0x35, \ - 0x32, \ - 0x33, \ - 0x30, \ - 0x31, \ - 0x3e, \ - 0x3f, \ - 0x3c, \ - 0x3d, \ - 0x3a, \ - 0x3b, \ - 0x38, \ - 0x39, \ + 0x06, 0x07, 0x04, 0x05, 0x02, 0x03, 0x00, 0x01, \ + 0x0e, 0x0f, 0x0c, 0x0d, 0x0a, 0x0b, 0x08, 0x09, \ + 0x16, 0x17, 0x14, 0x15, 0x12, 0x13, 0x10, 0x11, \ + 0x1e, 0x1f, 0x1c, 0x1d, 0x1a, 0x1b, 0x18, 0x19, \ + 0x26, 0x27, 0x24, 0x25, 0x22, 0x23, 0x20, 0x21, \ + 0x2e, 0x2f, 0x2c, 0x2d, 0x2a, 0x2b, 0x28, 0x29, \ + 0x36, 0x37, 0x34, 0x35, 0x32, 0x33, 0x30, 0x31, \ + 0x3e, 0x3f, 0x3c, 0x3d, 0x3a, 0x3b, 0x38, 0x39, \ } #define FNV_B64_23 \ { \ - 0x19, \ - 0x18, \ - 0x1b, \ - 0x1a, \ - 0x1d, \ - 0x1c, \ - 0x1f, \ - 0x1e, \ - 0x11, \ - 0x10, \ - 0x13, \ - 0x12, \ - 0x15, \ - 0x14, \ - 0x17, \ - 0x16, \ - 0x09, \ - 0x08, \ - 0x0b, \ - 0x0a, \ - 0x0d, \ - 0x0c, \ - 0x0f, \ - 0x0e, \ - 0x01, \ - 0x00, \ - 0x03, \ - 0x02, \ - 0x05, \ - 0x04, \ - 0x07, \ - 0x06, \ - 0x39, \ - 0x38, \ - 0x3b, \ - 0x3a, \ - 0x3d, \ - 0x3c, \ - 0x3f, \ - 0x3e, \ - 0x31, \ - 0x30, \ - 0x33, \ - 0x32, \ - 0x35, \ - 0x34, \ - 0x37, \ - 0x36, \ - 0x29, \ - 0x28, \ - 0x2b, \ - 0x2a, \ - 0x2d, \ - 0x2c, \ - 0x2f, \ - 0x2e, \ - 0x21, \ - 0x20, \ - 0x23, \ - 0x22, \ - 0x25, \ - 0x24, \ - 0x27, \ - 0x26, \ + 0x19, 0x18, 0x1b, 0x1a, 0x1d, 0x1c, 0x1f, 0x1e, \ + 0x11, 0x10, 0x13, 0x12, 0x15, 0x14, 0x17, 0x16, \ + 0x09, 0x08, 0x0b, 0x0a, 0x0d, 0x0c, 0x0f, 0x0e, \ + 0x01, 0x00, 0x03, 0x02, 0x05, 0x04, 0x07, 0x06, \ + 0x39, 0x38, 0x3b, 0x3a, 0x3d, 0x3c, 0x3f, 0x3e, \ + 0x31, 0x30, 0x33, 0x32, 0x35, 0x34, 0x37, 0x36, \ + 0x29, 0x28, 0x2b, 0x2a, 0x2d, 0x2c, 0x2f, 0x2e, \ + 0x21, 0x20, 0x23, 0x22, 0x25, 0x24, 0x27, 0x26, \ } #define FNV_B64_24 \ { \ - 0x2c, \ - 0x2d, \ - 0x2e, \ - 0x2f, \ - 0x28, \ - 0x29, \ - 0x2a, \ - 0x2b, \ - 0x24, \ - 0x25, \ - 0x26, \ - 0x27, \ - 0x20, \ - 0x21, \ - 0x22, \ - 0x23, \ - 0x3c, \ - 0x3d, \ - 0x3e, \ - 0x3f, \ - 0x38, \ - 0x39, \ - 0x3a, \ - 0x3b, \ - 0x34, \ - 0x35, \ - 0x36, \ - 0x37, \ - 0x30, \ - 0x31, \ - 0x32, \ - 0x33, \ - 0x0c, \ - 0x0d, \ - 0x0e, \ - 0x0f, \ - 0x08, \ - 0x09, \ - 0x0a, \ - 0x0b, \ - 0x04, \ - 0x05, \ - 0x06, \ - 0x07, \ - 0x00, \ - 0x01, \ - 0x02, \ - 0x03, \ - 0x1c, \ - 0x1d, \ - 0x1e, \ - 0x1f, \ - 0x18, \ - 0x19, \ - 0x1a, \ - 0x1b, \ - 0x14, \ - 0x15, \ - 0x16, \ - 0x17, \ - 0x10, \ - 0x11, \ - 0x12, \ - 0x13, \ + 0x2c, 0x2d, 0x2e, 0x2f, 0x28, 0x29, 0x2a, 0x2b, \ + 0x24, 0x25, 0x26, 0x27, 0x20, 0x21, 0x22, 0x23, \ + 0x3c, 0x3d, 0x3e, 0x3f, 0x38, 0x39, 0x3a, 0x3b, \ + 0x34, 0x35, 0x36, 0x37, 0x30, 0x31, 0x32, 0x33, \ + 0x0c, 0x0d, 0x0e, 0x0f, 0x08, 0x09, 0x0a, 0x0b, \ + 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, \ + 0x1c, 0x1d, 0x1e, 0x1f, 0x18, 0x19, 0x1a, 0x1b, \ + 0x14, 0x15, 0x16, 0x17, 0x10, 0x11, 0x12, 0x13, \ } #define FNV_B64_25 \ { \ - 0x3f, \ - 0x3e, \ - 0x3d, \ - 0x3c, \ - 0x3b, \ - 0x3a, \ - 0x39, \ - 0x38, \ - 0x37, \ - 0x36, \ - 0x35, \ - 0x34, \ - 0x33, \ - 0x32, \ - 0x31, \ - 0x30, \ - 0x2f, \ - 0x2e, \ - 0x2d, \ - 0x2c, \ - 0x2b, \ - 0x2a, \ - 0x29, \ - 0x28, \ - 0x27, \ - 0x26, \ - 0x25, \ - 0x24, \ - 0x23, \ - 0x22, \ - 0x21, \ - 0x20, \ - 0x1f, \ - 0x1e, \ - 0x1d, \ - 0x1c, \ - 0x1b, \ - 0x1a, \ - 0x19, \ - 0x18, \ - 0x17, \ - 0x16, \ - 0x15, \ - 0x14, \ - 0x13, \ - 0x12, \ - 0x11, \ - 0x10, \ - 0x0f, \ - 0x0e, \ - 0x0d, \ - 0x0c, \ - 0x0b, \ - 0x0a, \ - 0x09, \ - 0x08, \ - 0x07, \ - 0x06, \ - 0x05, \ - 0x04, \ - 0x03, \ - 0x02, \ - 0x01, \ - 0x00, \ + 0x3f, 0x3e, 0x3d, 0x3c, 0x3b, 0x3a, 0x39, 0x38, \ + 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x30, \ + 0x2f, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x28, \ + 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x20, \ + 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, \ + 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, \ + 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, \ + 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, \ } #define FNV_B64_26 \ { \ - 0x12, \ - 0x13, \ - 0x10, \ - 0x11, \ - 0x16, \ - 0x17, \ - 0x14, \ - 0x15, \ - 0x1a, \ - 0x1b, \ - 0x18, \ - 0x19, \ - 0x1e, \ - 0x1f, \ - 0x1c, \ - 0x1d, \ - 0x02, \ - 0x03, \ - 0x00, \ - 0x01, \ - 0x06, \ - 0x07, \ - 0x04, \ - 0x05, \ - 0x0a, \ - 0x0b, \ - 0x08, \ - 0x09, \ - 0x0e, \ - 0x0f, \ - 0x0c, \ - 0x0d, \ - 0x32, \ - 0x33, \ - 0x30, \ - 0x31, \ - 0x36, \ - 0x37, \ - 0x34, \ - 0x35, \ - 0x3a, \ - 0x3b, \ - 0x38, \ - 0x39, \ - 0x3e, \ - 0x3f, \ - 0x3c, \ - 0x3d, \ - 0x22, \ - 0x23, \ - 0x20, \ - 0x21, \ - 0x26, \ - 0x27, \ - 0x24, \ - 0x25, \ - 0x2a, \ - 0x2b, \ - 0x28, \ - 0x29, \ - 0x2e, \ - 0x2f, \ - 0x2c, \ - 0x2d, \ + 0x12, 0x13, 0x10, 0x11, 0x16, 0x17, 0x14, 0x15, \ + 0x1a, 0x1b, 0x18, 0x19, 0x1e, 0x1f, 0x1c, 0x1d, \ + 0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05, \ + 0x0a, 0x0b, 0x08, 0x09, 0x0e, 0x0f, 0x0c, 0x0d, \ + 0x32, 0x33, 0x30, 0x31, 0x36, 0x37, 0x34, 0x35, \ + 0x3a, 0x3b, 0x38, 0x39, 0x3e, 0x3f, 0x3c, 0x3d, \ + 0x22, 0x23, 0x20, 0x21, 0x26, 0x27, 0x24, 0x25, \ + 0x2a, 0x2b, 0x28, 0x29, 0x2e, 0x2f, 0x2c, 0x2d, \ } #define FNV_B64_27 \ { \ - 0x25, \ - 0x24, \ - 0x27, \ - 0x26, \ - 0x21, \ - 0x20, \ - 0x23, \ - 0x22, \ - 0x2d, \ - 0x2c, \ - 0x2f, \ - 0x2e, \ - 0x29, \ - 0x28, \ - 0x2b, \ - 0x2a, \ - 0x35, \ - 0x34, \ - 0x37, \ - 0x36, \ - 0x31, \ - 0x30, \ - 0x33, \ - 0x32, \ - 0x3d, \ - 0x3c, \ - 0x3f, \ - 0x3e, \ - 0x39, \ - 0x38, \ - 0x3b, \ - 0x3a, \ - 0x05, \ - 0x04, \ - 0x07, \ - 0x06, \ - 0x01, \ - 0x00, \ - 0x03, \ - 0x02, \ - 0x0d, \ - 0x0c, \ - 0x0f, \ - 0x0e, \ - 0x09, \ - 0x08, \ - 0x0b, \ - 0x0a, \ - 0x15, \ - 0x14, \ - 0x17, \ - 0x16, \ - 0x11, \ - 0x10, \ - 0x13, \ - 0x12, \ - 0x1d, \ - 0x1c, \ - 0x1f, \ - 0x1e, \ - 0x19, \ - 0x18, \ - 0x1b, \ - 0x1a, \ + 0x25, 0x24, 0x27, 0x26, 0x21, 0x20, 0x23, 0x22, \ + 0x2d, 0x2c, 0x2f, 0x2e, 0x29, 0x28, 0x2b, 0x2a, \ + 0x35, 0x34, 0x37, 0x36, 0x31, 0x30, 0x33, 0x32, \ + 0x3d, 0x3c, 0x3f, 0x3e, 0x39, 0x38, 0x3b, 0x3a, \ + 0x05, 0x04, 0x07, 0x06, 0x01, 0x00, 0x03, 0x02, \ + 0x0d, 0x0c, 0x0f, 0x0e, 0x09, 0x08, 0x0b, 0x0a, \ + 0x15, 0x14, 0x17, 0x16, 0x11, 0x10, 0x13, 0x12, \ + 0x1d, 0x1c, 0x1f, 0x1e, 0x19, 0x18, 0x1b, 0x1a, \ } #define FNV_B64_28 \ { \ - 0x38, \ - 0x39, \ - 0x3a, \ - 0x3b, \ - 0x3c, \ - 0x3d, \ - 0x3e, \ - 0x3f, \ - 0x30, \ - 0x31, \ - 0x32, \ - 0x33, \ - 0x34, \ - 0x35, \ - 0x36, \ - 0x37, \ - 0x28, \ - 0x29, \ - 0x2a, \ - 0x2b, \ - 0x2c, \ - 0x2d, \ - 0x2e, \ - 0x2f, \ - 0x20, \ - 0x21, \ - 0x22, \ - 0x23, \ - 0x24, \ - 0x25, \ - 0x26, \ - 0x27, \ - 0x18, \ - 0x19, \ - 0x1a, \ - 0x1b, \ - 0x1c, \ - 0x1d, \ - 0x1e, \ - 0x1f, \ - 0x10, \ - 0x11, \ - 0x12, \ - 0x13, \ - 0x14, \ - 0x15, \ - 0x16, \ - 0x17, \ - 0x08, \ - 0x09, \ - 0x0a, \ - 0x0b, \ - 0x0c, \ - 0x0d, \ - 0x0e, \ - 0x0f, \ - 0x00, \ - 0x01, \ - 0x02, \ - 0x03, \ - 0x04, \ - 0x05, \ - 0x06, \ - 0x07, \ + 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, \ + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, \ + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, \ + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, \ + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, \ + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, \ + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, \ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \ } #define FNV_B64_29 \ { \ - 0x0b, \ - 0x0a, \ - 0x09, \ - 0x08, \ - 0x0f, \ - 0x0e, \ - 0x0d, \ - 0x0c, \ - 0x03, \ - 0x02, \ - 0x01, \ - 0x00, \ - 0x07, \ - 0x06, \ - 0x05, \ - 0x04, \ - 0x1b, \ - 0x1a, \ - 0x19, \ - 0x18, \ - 0x1f, \ - 0x1e, \ - 0x1d, \ - 0x1c, \ - 0x13, \ - 0x12, \ - 0x11, \ - 0x10, \ - 0x17, \ - 0x16, \ - 0x15, \ - 0x14, \ - 0x2b, \ - 0x2a, \ - 0x29, \ - 0x28, \ - 0x2f, \ - 0x2e, \ - 0x2d, \ - 0x2c, \ - 0x23, \ - 0x22, \ - 0x21, \ - 0x20, \ - 0x27, \ - 0x26, \ - 0x25, \ - 0x24, \ - 0x3b, \ - 0x3a, \ - 0x39, \ - 0x38, \ - 0x3f, \ - 0x3e, \ - 0x3d, \ - 0x3c, \ - 0x33, \ - 0x32, \ - 0x31, \ - 0x30, \ - 0x37, \ - 0x36, \ - 0x35, \ - 0x34, \ + 0x0b, 0x0a, 0x09, 0x08, 0x0f, 0x0e, 0x0d, 0x0c, \ + 0x03, 0x02, 0x01, 0x00, 0x07, 0x06, 0x05, 0x04, \ + 0x1b, 0x1a, 0x19, 0x18, 0x1f, 0x1e, 0x1d, 0x1c, \ + 0x13, 0x12, 0x11, 0x10, 0x17, 0x16, 0x15, 0x14, \ + 0x2b, 0x2a, 0x29, 0x28, 0x2f, 0x2e, 0x2d, 0x2c, \ + 0x23, 0x22, 0x21, 0x20, 0x27, 0x26, 0x25, 0x24, \ + 0x3b, 0x3a, 0x39, 0x38, 0x3f, 0x3e, 0x3d, 0x3c, \ + 0x33, 0x32, 0x31, 0x30, 0x37, 0x36, 0x35, 0x34, \ } #define FNV_B64_2A \ { \ - 0x1e, \ - 0x1f, \ - 0x1c, \ - 0x1d, \ - 0x1a, \ - 0x1b, \ - 0x18, \ - 0x19, \ - 0x16, \ - 0x17, \ - 0x14, \ - 0x15, \ - 0x12, \ - 0x13, \ - 0x10, \ - 0x11, \ - 0x0e, \ - 0x0f, \ - 0x0c, \ - 0x0d, \ - 0x0a, \ - 0x0b, \ - 0x08, \ - 0x09, \ - 0x06, \ - 0x07, \ - 0x04, \ - 0x05, \ - 0x02, \ - 0x03, \ - 0x00, \ - 0x01, \ - 0x3e, \ - 0x3f, \ - 0x3c, \ - 0x3d, \ - 0x3a, \ - 0x3b, \ - 0x38, \ - 0x39, \ - 0x36, \ - 0x37, \ - 0x34, \ - 0x35, \ - 0x32, \ - 0x33, \ - 0x30, \ - 0x31, \ - 0x2e, \ - 0x2f, \ - 0x2c, \ - 0x2d, \ - 0x2a, \ - 0x2b, \ - 0x28, \ - 0x29, \ - 0x26, \ - 0x27, \ - 0x24, \ - 0x25, \ - 0x22, \ - 0x23, \ - 0x20, \ - 0x21, \ + 0x1e, 0x1f, 0x1c, 0x1d, 0x1a, 0x1b, 0x18, 0x19, \ + 0x16, 0x17, 0x14, 0x15, 0x12, 0x13, 0x10, 0x11, \ + 0x0e, 0x0f, 0x0c, 0x0d, 0x0a, 0x0b, 0x08, 0x09, \ + 0x06, 0x07, 0x04, 0x05, 0x02, 0x03, 0x00, 0x01, \ + 0x3e, 0x3f, 0x3c, 0x3d, 0x3a, 0x3b, 0x38, 0x39, \ + 0x36, 0x37, 0x34, 0x35, 0x32, 0x33, 0x30, 0x31, \ + 0x2e, 0x2f, 0x2c, 0x2d, 0x2a, 0x2b, 0x28, 0x29, \ + 0x26, 0x27, 0x24, 0x25, 0x22, 0x23, 0x20, 0x21, \ } #define FNV_B64_2B \ { \ - 0x31, \ - 0x30, \ - 0x33, \ - 0x32, \ - 0x35, \ - 0x34, \ - 0x37, \ - 0x36, \ - 0x39, \ - 0x38, \ - 0x3b, \ - 0x3a, \ - 0x3d, \ - 0x3c, \ - 0x3f, \ - 0x3e, \ - 0x21, \ - 0x20, \ - 0x23, \ - 0x22, \ - 0x25, \ - 0x24, \ - 0x27, \ - 0x26, \ - 0x29, \ - 0x28, \ - 0x2b, \ - 0x2a, \ - 0x2d, \ - 0x2c, \ - 0x2f, \ - 0x2e, \ - 0x11, \ - 0x10, \ - 0x13, \ - 0x12, \ - 0x15, \ - 0x14, \ - 0x17, \ - 0x16, \ - 0x19, \ - 0x18, \ - 0x1b, \ - 0x1a, \ - 0x1d, \ - 0x1c, \ - 0x1f, \ - 0x1e, \ - 0x01, \ - 0x00, \ - 0x03, \ - 0x02, \ - 0x05, \ - 0x04, \ - 0x07, \ - 0x06, \ - 0x09, \ - 0x08, \ - 0x0b, \ - 0x0a, \ - 0x0d, \ - 0x0c, \ - 0x0f, \ - 0x0e, \ + 0x31, 0x30, 0x33, 0x32, 0x35, 0x34, 0x37, 0x36, \ + 0x39, 0x38, 0x3b, 0x3a, 0x3d, 0x3c, 0x3f, 0x3e, \ + 0x21, 0x20, 0x23, 0x22, 0x25, 0x24, 0x27, 0x26, \ + 0x29, 0x28, 0x2b, 0x2a, 0x2d, 0x2c, 0x2f, 0x2e, \ + 0x11, 0x10, 0x13, 0x12, 0x15, 0x14, 0x17, 0x16, \ + 0x19, 0x18, 0x1b, 0x1a, 0x1d, 0x1c, 0x1f, 0x1e, \ + 0x01, 0x00, 0x03, 0x02, 0x05, 0x04, 0x07, 0x06, \ + 0x09, 0x08, 0x0b, 0x0a, 0x0d, 0x0c, 0x0f, 0x0e, \ } #define FNV_B64_2C \ { \ - 0x04, \ - 0x05, \ - 0x06, \ - 0x07, \ - 0x00, \ - 0x01, \ - 0x02, \ - 0x03, \ - 0x0c, \ - 0x0d, \ - 0x0e, \ - 0x0f, \ - 0x08, \ - 0x09, \ - 0x0a, \ - 0x0b, \ - 0x14, \ - 0x15, \ - 0x16, \ - 0x17, \ - 0x10, \ - 0x11, \ - 0x12, \ - 0x13, \ - 0x1c, \ - 0x1d, \ - 0x1e, \ - 0x1f, \ - 0x18, \ - 0x19, \ - 0x1a, \ - 0x1b, \ - 0x24, \ - 0x25, \ - 0x26, \ - 0x27, \ - 0x20, \ - 0x21, \ - 0x22, \ - 0x23, \ - 0x2c, \ - 0x2d, \ - 0x2e, \ - 0x2f, \ - 0x28, \ - 0x29, \ - 0x2a, \ - 0x2b, \ - 0x34, \ - 0x35, \ - 0x36, \ - 0x37, \ - 0x30, \ - 0x31, \ - 0x32, \ - 0x33, \ - 0x3c, \ - 0x3d, \ - 0x3e, \ - 0x3f, \ - 0x38, \ - 0x39, \ - 0x3a, \ - 0x3b, \ + 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, \ + 0x0c, 0x0d, 0x0e, 0x0f, 0x08, 0x09, 0x0a, 0x0b, \ + 0x14, 0x15, 0x16, 0x17, 0x10, 0x11, 0x12, 0x13, \ + 0x1c, 0x1d, 0x1e, 0x1f, 0x18, 0x19, 0x1a, 0x1b, \ + 0x24, 0x25, 0x26, 0x27, 0x20, 0x21, 0x22, 0x23, \ + 0x2c, 0x2d, 0x2e, 0x2f, 0x28, 0x29, 0x2a, 0x2b, \ + 0x34, 0x35, 0x36, 0x37, 0x30, 0x31, 0x32, 0x33, \ + 0x3c, 0x3d, 0x3e, 0x3f, 0x38, 0x39, 0x3a, 0x3b, \ } #define FNV_B64_2D \ { \ - 0x17, \ - 0x16, \ - 0x15, \ - 0x14, \ - 0x13, \ - 0x12, \ - 0x11, \ - 0x10, \ - 0x1f, \ - 0x1e, \ - 0x1d, \ - 0x1c, \ - 0x1b, \ - 0x1a, \ - 0x19, \ - 0x18, \ - 0x07, \ - 0x06, \ - 0x05, \ - 0x04, \ - 0x03, \ - 0x02, \ - 0x01, \ - 0x00, \ - 0x0f, \ - 0x0e, \ - 0x0d, \ - 0x0c, \ - 0x0b, \ - 0x0a, \ - 0x09, \ - 0x08, \ - 0x37, \ - 0x36, \ - 0x35, \ - 0x34, \ - 0x33, \ - 0x32, \ - 0x31, \ - 0x30, \ - 0x3f, \ - 0x3e, \ - 0x3d, \ - 0x3c, \ - 0x3b, \ - 0x3a, \ - 0x39, \ - 0x38, \ - 0x27, \ - 0x26, \ - 0x25, \ - 0x24, \ - 0x23, \ - 0x22, \ - 0x21, \ - 0x20, \ - 0x2f, \ - 0x2e, \ - 0x2d, \ - 0x2c, \ - 0x2b, \ - 0x2a, \ - 0x29, \ - 0x28, \ + 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, \ + 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, \ + 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, \ + 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, \ + 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x30, \ + 0x3f, 0x3e, 0x3d, 0x3c, 0x3b, 0x3a, 0x39, 0x38, \ + 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x20, \ + 0x2f, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x28, \ } #define FNV_B64_2E \ { \ - 0x2a, \ - 0x2b, \ - 0x28, \ - 0x29, \ - 0x2e, \ - 0x2f, \ - 0x2c, \ - 0x2d, \ - 0x22, \ - 0x23, \ - 0x20, \ - 0x21, \ - 0x26, \ - 0x27, \ - 0x24, \ - 0x25, \ - 0x3a, \ - 0x3b, \ - 0x38, \ - 0x39, \ - 0x3e, \ - 0x3f, \ - 0x3c, \ - 0x3d, \ - 0x32, \ - 0x33, \ - 0x30, \ - 0x31, \ - 0x36, \ - 0x37, \ - 0x34, \ - 0x35, \ - 0x0a, \ - 0x0b, \ - 0x08, \ - 0x09, \ - 0x0e, \ - 0x0f, \ - 0x0c, \ - 0x0d, \ - 0x02, \ - 0x03, \ - 0x00, \ - 0x01, \ - 0x06, \ - 0x07, \ - 0x04, \ - 0x05, \ - 0x1a, \ - 0x1b, \ - 0x18, \ - 0x19, \ - 0x1e, \ - 0x1f, \ - 0x1c, \ - 0x1d, \ - 0x12, \ - 0x13, \ - 0x10, \ - 0x11, \ - 0x16, \ - 0x17, \ - 0x14, \ - 0x15, \ + 0x2a, 0x2b, 0x28, 0x29, 0x2e, 0x2f, 0x2c, 0x2d, \ + 0x22, 0x23, 0x20, 0x21, 0x26, 0x27, 0x24, 0x25, \ + 0x3a, 0x3b, 0x38, 0x39, 0x3e, 0x3f, 0x3c, 0x3d, \ + 0x32, 0x33, 0x30, 0x31, 0x36, 0x37, 0x34, 0x35, \ + 0x0a, 0x0b, 0x08, 0x09, 0x0e, 0x0f, 0x0c, 0x0d, \ + 0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05, \ + 0x1a, 0x1b, 0x18, 0x19, 0x1e, 0x1f, 0x1c, 0x1d, \ + 0x12, 0x13, 0x10, 0x11, 0x16, 0x17, 0x14, 0x15, \ } #define FNV_B64_2F \ { \ - 0x3d, \ - 0x3c, \ - 0x3f, \ - 0x3e, \ - 0x39, \ - 0x38, \ - 0x3b, \ - 0x3a, \ - 0x35, \ - 0x34, \ - 0x37, \ - 0x36, \ - 0x31, \ - 0x30, \ - 0x33, \ - 0x32, \ - 0x2d, \ - 0x2c, \ - 0x2f, \ - 0x2e, \ - 0x29, \ - 0x28, \ - 0x2b, \ - 0x2a, \ - 0x25, \ - 0x24, \ - 0x27, \ - 0x26, \ - 0x21, \ - 0x20, \ - 0x23, \ - 0x22, \ - 0x1d, \ - 0x1c, \ - 0x1f, \ - 0x1e, \ - 0x19, \ - 0x18, \ - 0x1b, \ - 0x1a, \ - 0x15, \ - 0x14, \ - 0x17, \ - 0x16, \ - 0x11, \ - 0x10, \ - 0x13, \ - 0x12, \ - 0x0d, \ - 0x0c, \ - 0x0f, \ - 0x0e, \ - 0x09, \ - 0x08, \ - 0x0b, \ - 0x0a, \ - 0x05, \ - 0x04, \ - 0x07, \ - 0x06, \ - 0x01, \ - 0x00, \ - 0x03, \ - 0x02, \ + 0x3d, 0x3c, 0x3f, 0x3e, 0x39, 0x38, 0x3b, 0x3a, \ + 0x35, 0x34, 0x37, 0x36, 0x31, 0x30, 0x33, 0x32, \ + 0x2d, 0x2c, 0x2f, 0x2e, 0x29, 0x28, 0x2b, 0x2a, \ + 0x25, 0x24, 0x27, 0x26, 0x21, 0x20, 0x23, 0x22, \ + 0x1d, 0x1c, 0x1f, 0x1e, 0x19, 0x18, 0x1b, 0x1a, \ + 0x15, 0x14, 0x17, 0x16, 0x11, 0x10, 0x13, 0x12, \ + 0x0d, 0x0c, 0x0f, 0x0e, 0x09, 0x08, 0x0b, 0x0a, \ + 0x05, 0x04, 0x07, 0x06, 0x01, 0x00, 0x03, 0x02, \ } #define FNV_B64_30 \ { \ - 0x10, \ - 0x11, \ - 0x12, \ - 0x13, \ - 0x14, \ - 0x15, \ - 0x16, \ - 0x17, \ - 0x18, \ - 0x19, \ - 0x1a, \ - 0x1b, \ - 0x1c, \ - 0x1d, \ - 0x1e, \ - 0x1f, \ - 0x00, \ - 0x01, \ - 0x02, \ - 0x03, \ - 0x04, \ - 0x05, \ - 0x06, \ - 0x07, \ - 0x08, \ - 0x09, \ - 0x0a, \ - 0x0b, \ - 0x0c, \ - 0x0d, \ - 0x0e, \ - 0x0f, \ - 0x30, \ - 0x31, \ - 0x32, \ - 0x33, \ - 0x34, \ - 0x35, \ - 0x36, \ - 0x37, \ - 0x38, \ - 0x39, \ - 0x3a, \ - 0x3b, \ - 0x3c, \ - 0x3d, \ - 0x3e, \ - 0x3f, \ - 0x20, \ - 0x21, \ - 0x22, \ - 0x23, \ - 0x24, \ - 0x25, \ - 0x26, \ - 0x27, \ - 0x28, \ - 0x29, \ - 0x2a, \ - 0x2b, \ - 0x2c, \ - 0x2d, \ - 0x2e, \ - 0x2f, \ + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, \ + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, \ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \ + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, \ + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, \ + 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, \ + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, \ + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, \ } #define FNV_B64_31 \ { \ - 0x23, \ - 0x22, \ - 0x21, \ - 0x20, \ - 0x27, \ - 0x26, \ - 0x25, \ - 0x24, \ - 0x2b, \ - 0x2a, \ - 0x29, \ - 0x28, \ - 0x2f, \ - 0x2e, \ - 0x2d, \ - 0x2c, \ - 0x33, \ - 0x32, \ - 0x31, \ - 0x30, \ - 0x37, \ - 0x36, \ - 0x35, \ - 0x34, \ - 0x3b, \ - 0x3a, \ - 0x39, \ - 0x38, \ - 0x3f, \ - 0x3e, \ - 0x3d, \ - 0x3c, \ - 0x03, \ - 0x02, \ - 0x01, \ - 0x00, \ - 0x07, \ - 0x06, \ - 0x05, \ - 0x04, \ - 0x0b, \ - 0x0a, \ - 0x09, \ - 0x08, \ - 0x0f, \ - 0x0e, \ - 0x0d, \ - 0x0c, \ - 0x13, \ - 0x12, \ - 0x11, \ - 0x10, \ - 0x17, \ - 0x16, \ - 0x15, \ - 0x14, \ - 0x1b, \ - 0x1a, \ - 0x19, \ - 0x18, \ - 0x1f, \ - 0x1e, \ - 0x1d, \ - 0x1c, \ + 0x23, 0x22, 0x21, 0x20, 0x27, 0x26, 0x25, 0x24, \ + 0x2b, 0x2a, 0x29, 0x28, 0x2f, 0x2e, 0x2d, 0x2c, \ + 0x33, 0x32, 0x31, 0x30, 0x37, 0x36, 0x35, 0x34, \ + 0x3b, 0x3a, 0x39, 0x38, 0x3f, 0x3e, 0x3d, 0x3c, \ + 0x03, 0x02, 0x01, 0x00, 0x07, 0x06, 0x05, 0x04, \ + 0x0b, 0x0a, 0x09, 0x08, 0x0f, 0x0e, 0x0d, 0x0c, \ + 0x13, 0x12, 0x11, 0x10, 0x17, 0x16, 0x15, 0x14, \ + 0x1b, 0x1a, 0x19, 0x18, 0x1f, 0x1e, 0x1d, 0x1c, \ } #define FNV_B64_32 \ { \ - 0x36, \ - 0x37, \ - 0x34, \ - 0x35, \ - 0x32, \ - 0x33, \ - 0x30, \ - 0x31, \ - 0x3e, \ - 0x3f, \ - 0x3c, \ - 0x3d, \ - 0x3a, \ - 0x3b, \ - 0x38, \ - 0x39, \ - 0x26, \ - 0x27, \ - 0x24, \ - 0x25, \ - 0x22, \ - 0x23, \ - 0x20, \ - 0x21, \ - 0x2e, \ - 0x2f, \ - 0x2c, \ - 0x2d, \ - 0x2a, \ - 0x2b, \ - 0x28, \ - 0x29, \ - 0x16, \ - 0x17, \ - 0x14, \ - 0x15, \ - 0x12, \ - 0x13, \ - 0x10, \ - 0x11, \ - 0x1e, \ - 0x1f, \ - 0x1c, \ - 0x1d, \ - 0x1a, \ - 0x1b, \ - 0x18, \ - 0x19, \ - 0x06, \ - 0x07, \ - 0x04, \ - 0x05, \ - 0x02, \ - 0x03, \ - 0x00, \ - 0x01, \ - 0x0e, \ - 0x0f, \ - 0x0c, \ - 0x0d, \ - 0x0a, \ - 0x0b, \ - 0x08, \ - 0x09, \ + 0x36, 0x37, 0x34, 0x35, 0x32, 0x33, 0x30, 0x31, \ + 0x3e, 0x3f, 0x3c, 0x3d, 0x3a, 0x3b, 0x38, 0x39, \ + 0x26, 0x27, 0x24, 0x25, 0x22, 0x23, 0x20, 0x21, \ + 0x2e, 0x2f, 0x2c, 0x2d, 0x2a, 0x2b, 0x28, 0x29, \ + 0x16, 0x17, 0x14, 0x15, 0x12, 0x13, 0x10, 0x11, \ + 0x1e, 0x1f, 0x1c, 0x1d, 0x1a, 0x1b, 0x18, 0x19, \ + 0x06, 0x07, 0x04, 0x05, 0x02, 0x03, 0x00, 0x01, \ + 0x0e, 0x0f, 0x0c, 0x0d, 0x0a, 0x0b, 0x08, 0x09, \ } #define FNV_B64_33 \ { \ - 0x09, \ - 0x08, \ - 0x0b, \ - 0x0a, \ - 0x0d, \ - 0x0c, \ - 0x0f, \ - 0x0e, \ - 0x01, \ - 0x00, \ - 0x03, \ - 0x02, \ - 0x05, \ - 0x04, \ - 0x07, \ - 0x06, \ - 0x19, \ - 0x18, \ - 0x1b, \ - 0x1a, \ - 0x1d, \ - 0x1c, \ - 0x1f, \ - 0x1e, \ - 0x11, \ - 0x10, \ - 0x13, \ - 0x12, \ - 0x15, \ - 0x14, \ - 0x17, \ - 0x16, \ - 0x29, \ - 0x28, \ - 0x2b, \ - 0x2a, \ - 0x2d, \ - 0x2c, \ - 0x2f, \ - 0x2e, \ - 0x21, \ - 0x20, \ - 0x23, \ - 0x22, \ - 0x25, \ - 0x24, \ - 0x27, \ - 0x26, \ - 0x39, \ - 0x38, \ - 0x3b, \ - 0x3a, \ - 0x3d, \ - 0x3c, \ - 0x3f, \ - 0x3e, \ - 0x31, \ - 0x30, \ - 0x33, \ - 0x32, \ - 0x35, \ - 0x34, \ - 0x37, \ - 0x36, \ + 0x09, 0x08, 0x0b, 0x0a, 0x0d, 0x0c, 0x0f, 0x0e, \ + 0x01, 0x00, 0x03, 0x02, 0x05, 0x04, 0x07, 0x06, \ + 0x19, 0x18, 0x1b, 0x1a, 0x1d, 0x1c, 0x1f, 0x1e, \ + 0x11, 0x10, 0x13, 0x12, 0x15, 0x14, 0x17, 0x16, \ + 0x29, 0x28, 0x2b, 0x2a, 0x2d, 0x2c, 0x2f, 0x2e, \ + 0x21, 0x20, 0x23, 0x22, 0x25, 0x24, 0x27, 0x26, \ + 0x39, 0x38, 0x3b, 0x3a, 0x3d, 0x3c, 0x3f, 0x3e, \ + 0x31, 0x30, 0x33, 0x32, 0x35, 0x34, 0x37, 0x36, \ } #define FNV_B64_34 \ { \ - 0x1c, \ - 0x1d, \ - 0x1e, \ - 0x1f, \ - 0x18, \ - 0x19, \ - 0x1a, \ - 0x1b, \ - 0x14, \ - 0x15, \ - 0x16, \ - 0x17, \ - 0x10, \ - 0x11, \ - 0x12, \ - 0x13, \ - 0x0c, \ - 0x0d, \ - 0x0e, \ - 0x0f, \ - 0x08, \ - 0x09, \ - 0x0a, \ - 0x0b, \ - 0x04, \ - 0x05, \ - 0x06, \ - 0x07, \ - 0x00, \ - 0x01, \ - 0x02, \ - 0x03, \ - 0x3c, \ - 0x3d, \ - 0x3e, \ - 0x3f, \ - 0x38, \ - 0x39, \ - 0x3a, \ - 0x3b, \ - 0x34, \ - 0x35, \ - 0x36, \ - 0x37, \ - 0x30, \ - 0x31, \ - 0x32, \ - 0x33, \ - 0x2c, \ - 0x2d, \ - 0x2e, \ - 0x2f, \ - 0x28, \ - 0x29, \ - 0x2a, \ - 0x2b, \ - 0x24, \ - 0x25, \ - 0x26, \ - 0x27, \ - 0x20, \ - 0x21, \ - 0x22, \ - 0x23, \ + 0x1c, 0x1d, 0x1e, 0x1f, 0x18, 0x19, 0x1a, 0x1b, \ + 0x14, 0x15, 0x16, 0x17, 0x10, 0x11, 0x12, 0x13, \ + 0x0c, 0x0d, 0x0e, 0x0f, 0x08, 0x09, 0x0a, 0x0b, \ + 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, \ + 0x3c, 0x3d, 0x3e, 0x3f, 0x38, 0x39, 0x3a, 0x3b, \ + 0x34, 0x35, 0x36, 0x37, 0x30, 0x31, 0x32, 0x33, \ + 0x2c, 0x2d, 0x2e, 0x2f, 0x28, 0x29, 0x2a, 0x2b, \ + 0x24, 0x25, 0x26, 0x27, 0x20, 0x21, 0x22, 0x23, \ } #define FNV_B64_35 \ { \ - 0x2f, \ - 0x2e, \ - 0x2d, \ - 0x2c, \ - 0x2b, \ - 0x2a, \ - 0x29, \ - 0x28, \ - 0x27, \ - 0x26, \ - 0x25, \ - 0x24, \ - 0x23, \ - 0x22, \ - 0x21, \ - 0x20, \ - 0x3f, \ - 0x3e, \ - 0x3d, \ - 0x3c, \ - 0x3b, \ - 0x3a, \ - 0x39, \ - 0x38, \ - 0x37, \ - 0x36, \ - 0x35, \ - 0x34, \ - 0x33, \ - 0x32, \ - 0x31, \ - 0x30, \ - 0x0f, \ - 0x0e, \ - 0x0d, \ - 0x0c, \ - 0x0b, \ - 0x0a, \ - 0x09, \ - 0x08, \ - 0x07, \ - 0x06, \ - 0x05, \ - 0x04, \ - 0x03, \ - 0x02, \ - 0x01, \ - 0x00, \ - 0x1f, \ - 0x1e, \ - 0x1d, \ - 0x1c, \ - 0x1b, \ - 0x1a, \ - 0x19, \ - 0x18, \ - 0x17, \ - 0x16, \ - 0x15, \ - 0x14, \ - 0x13, \ - 0x12, \ - 0x11, \ - 0x10, \ + 0x2f, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x28, \ + 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x20, \ + 0x3f, 0x3e, 0x3d, 0x3c, 0x3b, 0x3a, 0x39, 0x38, \ + 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x30, \ + 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, \ + 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, \ + 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, \ + 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, \ } #define FNV_B64_36 \ { \ - 0x02, \ - 0x03, \ - 0x00, \ - 0x01, \ - 0x06, \ - 0x07, \ - 0x04, \ - 0x05, \ - 0x0a, \ - 0x0b, \ - 0x08, \ - 0x09, \ - 0x0e, \ - 0x0f, \ - 0x0c, \ - 0x0d, \ - 0x12, \ - 0x13, \ - 0x10, \ - 0x11, \ - 0x16, \ - 0x17, \ - 0x14, \ - 0x15, \ - 0x1a, \ - 0x1b, \ - 0x18, \ - 0x19, \ - 0x1e, \ - 0x1f, \ - 0x1c, \ - 0x1d, \ - 0x22, \ - 0x23, \ - 0x20, \ - 0x21, \ - 0x26, \ - 0x27, \ - 0x24, \ - 0x25, \ - 0x2a, \ - 0x2b, \ - 0x28, \ - 0x29, \ - 0x2e, \ - 0x2f, \ - 0x2c, \ - 0x2d, \ - 0x32, \ - 0x33, \ - 0x30, \ - 0x31, \ - 0x36, \ - 0x37, \ - 0x34, \ - 0x35, \ - 0x3a, \ - 0x3b, \ - 0x38, \ - 0x39, \ - 0x3e, \ - 0x3f, \ - 0x3c, \ - 0x3d, \ + 0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05, \ + 0x0a, 0x0b, 0x08, 0x09, 0x0e, 0x0f, 0x0c, 0x0d, \ + 0x12, 0x13, 0x10, 0x11, 0x16, 0x17, 0x14, 0x15, \ + 0x1a, 0x1b, 0x18, 0x19, 0x1e, 0x1f, 0x1c, 0x1d, \ + 0x22, 0x23, 0x20, 0x21, 0x26, 0x27, 0x24, 0x25, \ + 0x2a, 0x2b, 0x28, 0x29, 0x2e, 0x2f, 0x2c, 0x2d, \ + 0x32, 0x33, 0x30, 0x31, 0x36, 0x37, 0x34, 0x35, \ + 0x3a, 0x3b, 0x38, 0x39, 0x3e, 0x3f, 0x3c, 0x3d, \ } #define FNV_B64_37 \ { \ - 0x15, \ - 0x14, \ - 0x17, \ - 0x16, \ - 0x11, \ - 0x10, \ - 0x13, \ - 0x12, \ - 0x1d, \ - 0x1c, \ - 0x1f, \ - 0x1e, \ - 0x19, \ - 0x18, \ - 0x1b, \ - 0x1a, \ - 0x05, \ - 0x04, \ - 0x07, \ - 0x06, \ - 0x01, \ - 0x00, \ - 0x03, \ - 0x02, \ - 0x0d, \ - 0x0c, \ - 0x0f, \ - 0x0e, \ - 0x09, \ - 0x08, \ - 0x0b, \ - 0x0a, \ - 0x35, \ - 0x34, \ - 0x37, \ - 0x36, \ - 0x31, \ - 0x30, \ - 0x33, \ - 0x32, \ - 0x3d, \ - 0x3c, \ - 0x3f, \ - 0x3e, \ - 0x39, \ - 0x38, \ - 0x3b, \ - 0x3a, \ - 0x25, \ - 0x24, \ - 0x27, \ - 0x26, \ - 0x21, \ - 0x20, \ - 0x23, \ - 0x22, \ - 0x2d, \ - 0x2c, \ - 0x2f, \ - 0x2e, \ - 0x29, \ - 0x28, \ - 0x2b, \ - 0x2a, \ + 0x15, 0x14, 0x17, 0x16, 0x11, 0x10, 0x13, 0x12, \ + 0x1d, 0x1c, 0x1f, 0x1e, 0x19, 0x18, 0x1b, 0x1a, \ + 0x05, 0x04, 0x07, 0x06, 0x01, 0x00, 0x03, 0x02, \ + 0x0d, 0x0c, 0x0f, 0x0e, 0x09, 0x08, 0x0b, 0x0a, \ + 0x35, 0x34, 0x37, 0x36, 0x31, 0x30, 0x33, 0x32, \ + 0x3d, 0x3c, 0x3f, 0x3e, 0x39, 0x38, 0x3b, 0x3a, \ + 0x25, 0x24, 0x27, 0x26, 0x21, 0x20, 0x23, 0x22, \ + 0x2d, 0x2c, 0x2f, 0x2e, 0x29, 0x28, 0x2b, 0x2a, \ } #define FNV_B64_38 \ { \ - 0x28, \ - 0x29, \ - 0x2a, \ - 0x2b, \ - 0x2c, \ - 0x2d, \ - 0x2e, \ - 0x2f, \ - 0x20, \ - 0x21, \ - 0x22, \ - 0x23, \ - 0x24, \ - 0x25, \ - 0x26, \ - 0x27, \ - 0x38, \ - 0x39, \ - 0x3a, \ - 0x3b, \ - 0x3c, \ - 0x3d, \ - 0x3e, \ - 0x3f, \ - 0x30, \ - 0x31, \ - 0x32, \ - 0x33, \ - 0x34, \ - 0x35, \ - 0x36, \ - 0x37, \ - 0x08, \ - 0x09, \ - 0x0a, \ - 0x0b, \ - 0x0c, \ - 0x0d, \ - 0x0e, \ - 0x0f, \ - 0x00, \ - 0x01, \ - 0x02, \ - 0x03, \ - 0x04, \ - 0x05, \ - 0x06, \ - 0x07, \ - 0x18, \ - 0x19, \ - 0x1a, \ - 0x1b, \ - 0x1c, \ - 0x1d, \ - 0x1e, \ - 0x1f, \ - 0x10, \ - 0x11, \ - 0x12, \ - 0x13, \ - 0x14, \ - 0x15, \ - 0x16, \ - 0x17, \ + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, \ + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, \ + 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, \ + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, \ + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, \ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \ + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, \ + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, \ } #define FNV_B64_39 \ { \ - 0x3b, \ - 0x3a, \ - 0x39, \ - 0x38, \ - 0x3f, \ - 0x3e, \ - 0x3d, \ - 0x3c, \ - 0x33, \ - 0x32, \ - 0x31, \ - 0x30, \ - 0x37, \ - 0x36, \ - 0x35, \ - 0x34, \ - 0x2b, \ - 0x2a, \ - 0x29, \ - 0x28, \ - 0x2f, \ - 0x2e, \ - 0x2d, \ - 0x2c, \ - 0x23, \ - 0x22, \ - 0x21, \ - 0x20, \ - 0x27, \ - 0x26, \ - 0x25, \ - 0x24, \ - 0x1b, \ - 0x1a, \ - 0x19, \ - 0x18, \ - 0x1f, \ - 0x1e, \ - 0x1d, \ - 0x1c, \ - 0x13, \ - 0x12, \ - 0x11, \ - 0x10, \ - 0x17, \ - 0x16, \ - 0x15, \ - 0x14, \ - 0x0b, \ - 0x0a, \ - 0x09, \ - 0x08, \ - 0x0f, \ - 0x0e, \ - 0x0d, \ - 0x0c, \ - 0x03, \ - 0x02, \ - 0x01, \ - 0x00, \ - 0x07, \ - 0x06, \ - 0x05, \ - 0x04, \ + 0x3b, 0x3a, 0x39, 0x38, 0x3f, 0x3e, 0x3d, 0x3c, \ + 0x33, 0x32, 0x31, 0x30, 0x37, 0x36, 0x35, 0x34, \ + 0x2b, 0x2a, 0x29, 0x28, 0x2f, 0x2e, 0x2d, 0x2c, \ + 0x23, 0x22, 0x21, 0x20, 0x27, 0x26, 0x25, 0x24, \ + 0x1b, 0x1a, 0x19, 0x18, 0x1f, 0x1e, 0x1d, 0x1c, \ + 0x13, 0x12, 0x11, 0x10, 0x17, 0x16, 0x15, 0x14, \ + 0x0b, 0x0a, 0x09, 0x08, 0x0f, 0x0e, 0x0d, 0x0c, \ + 0x03, 0x02, 0x01, 0x00, 0x07, 0x06, 0x05, 0x04, \ } #define FNV_B64_3A \ { \ - 0x0e, \ - 0x0f, \ - 0x0c, \ - 0x0d, \ - 0x0a, \ - 0x0b, \ - 0x08, \ - 0x09, \ - 0x06, \ - 0x07, \ - 0x04, \ - 0x05, \ - 0x02, \ - 0x03, \ - 0x00, \ - 0x01, \ - 0x1e, \ - 0x1f, \ - 0x1c, \ - 0x1d, \ - 0x1a, \ - 0x1b, \ - 0x18, \ - 0x19, \ - 0x16, \ - 0x17, \ - 0x14, \ - 0x15, \ - 0x12, \ - 0x13, \ - 0x10, \ - 0x11, \ - 0x2e, \ - 0x2f, \ - 0x2c, \ - 0x2d, \ - 0x2a, \ - 0x2b, \ - 0x28, \ - 0x29, \ - 0x26, \ - 0x27, \ - 0x24, \ - 0x25, \ - 0x22, \ - 0x23, \ - 0x20, \ - 0x21, \ - 0x3e, \ - 0x3f, \ - 0x3c, \ - 0x3d, \ - 0x3a, \ - 0x3b, \ - 0x38, \ - 0x39, \ - 0x36, \ - 0x37, \ - 0x34, \ - 0x35, \ - 0x32, \ - 0x33, \ - 0x30, \ - 0x31, \ + 0x0e, 0x0f, 0x0c, 0x0d, 0x0a, 0x0b, 0x08, 0x09, \ + 0x06, 0x07, 0x04, 0x05, 0x02, 0x03, 0x00, 0x01, \ + 0x1e, 0x1f, 0x1c, 0x1d, 0x1a, 0x1b, 0x18, 0x19, \ + 0x16, 0x17, 0x14, 0x15, 0x12, 0x13, 0x10, 0x11, \ + 0x2e, 0x2f, 0x2c, 0x2d, 0x2a, 0x2b, 0x28, 0x29, \ + 0x26, 0x27, 0x24, 0x25, 0x22, 0x23, 0x20, 0x21, \ + 0x3e, 0x3f, 0x3c, 0x3d, 0x3a, 0x3b, 0x38, 0x39, \ + 0x36, 0x37, 0x34, 0x35, 0x32, 0x33, 0x30, 0x31, \ } #define FNV_B64_3B \ { \ - 0x21, \ - 0x20, \ - 0x23, \ - 0x22, \ - 0x25, \ - 0x24, \ - 0x27, \ - 0x26, \ - 0x29, \ - 0x28, \ - 0x2b, \ - 0x2a, \ - 0x2d, \ - 0x2c, \ - 0x2f, \ - 0x2e, \ - 0x31, \ - 0x30, \ - 0x33, \ - 0x32, \ - 0x35, \ - 0x34, \ - 0x37, \ - 0x36, \ - 0x39, \ - 0x38, \ - 0x3b, \ - 0x3a, \ - 0x3d, \ - 0x3c, \ - 0x3f, \ - 0x3e, \ - 0x01, \ - 0x00, \ - 0x03, \ - 0x02, \ - 0x05, \ - 0x04, \ - 0x07, \ - 0x06, \ - 0x09, \ - 0x08, \ - 0x0b, \ - 0x0a, \ - 0x0d, \ - 0x0c, \ - 0x0f, \ - 0x0e, \ - 0x11, \ - 0x10, \ - 0x13, \ - 0x12, \ - 0x15, \ - 0x14, \ - 0x17, \ - 0x16, \ - 0x19, \ - 0x18, \ - 0x1b, \ - 0x1a, \ - 0x1d, \ - 0x1c, \ - 0x1f, \ - 0x1e, \ + 0x21, 0x20, 0x23, 0x22, 0x25, 0x24, 0x27, 0x26, \ + 0x29, 0x28, 0x2b, 0x2a, 0x2d, 0x2c, 0x2f, 0x2e, \ + 0x31, 0x30, 0x33, 0x32, 0x35, 0x34, 0x37, 0x36, \ + 0x39, 0x38, 0x3b, 0x3a, 0x3d, 0x3c, 0x3f, 0x3e, \ + 0x01, 0x00, 0x03, 0x02, 0x05, 0x04, 0x07, 0x06, \ + 0x09, 0x08, 0x0b, 0x0a, 0x0d, 0x0c, 0x0f, 0x0e, \ + 0x11, 0x10, 0x13, 0x12, 0x15, 0x14, 0x17, 0x16, \ + 0x19, 0x18, 0x1b, 0x1a, 0x1d, 0x1c, 0x1f, 0x1e, \ } #define FNV_B64_3C \ { \ - 0x34, \ - 0x35, \ - 0x36, \ - 0x37, \ - 0x30, \ - 0x31, \ - 0x32, \ - 0x33, \ - 0x3c, \ - 0x3d, \ - 0x3e, \ - 0x3f, \ - 0x38, \ - 0x39, \ - 0x3a, \ - 0x3b, \ - 0x24, \ - 0x25, \ - 0x26, \ - 0x27, \ - 0x20, \ - 0x21, \ - 0x22, \ - 0x23, \ - 0x2c, \ - 0x2d, \ - 0x2e, \ - 0x2f, \ - 0x28, \ - 0x29, \ - 0x2a, \ - 0x2b, \ - 0x14, \ - 0x15, \ - 0x16, \ - 0x17, \ - 0x10, \ - 0x11, \ - 0x12, \ - 0x13, \ - 0x1c, \ - 0x1d, \ - 0x1e, \ - 0x1f, \ - 0x18, \ - 0x19, \ - 0x1a, \ - 0x1b, \ - 0x04, \ - 0x05, \ - 0x06, \ - 0x07, \ - 0x00, \ - 0x01, \ - 0x02, \ - 0x03, \ - 0x0c, \ - 0x0d, \ - 0x0e, \ - 0x0f, \ - 0x08, \ - 0x09, \ - 0x0a, \ - 0x0b, \ + 0x34, 0x35, 0x36, 0x37, 0x30, 0x31, 0x32, 0x33, \ + 0x3c, 0x3d, 0x3e, 0x3f, 0x38, 0x39, 0x3a, 0x3b, \ + 0x24, 0x25, 0x26, 0x27, 0x20, 0x21, 0x22, 0x23, \ + 0x2c, 0x2d, 0x2e, 0x2f, 0x28, 0x29, 0x2a, 0x2b, \ + 0x14, 0x15, 0x16, 0x17, 0x10, 0x11, 0x12, 0x13, \ + 0x1c, 0x1d, 0x1e, 0x1f, 0x18, 0x19, 0x1a, 0x1b, \ + 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, \ + 0x0c, 0x0d, 0x0e, 0x0f, 0x08, 0x09, 0x0a, 0x0b, \ } #define FNV_B64_3D \ { \ - 0x07, \ - 0x06, \ - 0x05, \ - 0x04, \ - 0x03, \ - 0x02, \ - 0x01, \ - 0x00, \ - 0x0f, \ - 0x0e, \ - 0x0d, \ - 0x0c, \ - 0x0b, \ - 0x0a, \ - 0x09, \ - 0x08, \ - 0x17, \ - 0x16, \ - 0x15, \ - 0x14, \ - 0x13, \ - 0x12, \ - 0x11, \ - 0x10, \ - 0x1f, \ - 0x1e, \ - 0x1d, \ - 0x1c, \ - 0x1b, \ - 0x1a, \ - 0x19, \ - 0x18, \ - 0x27, \ - 0x26, \ - 0x25, \ - 0x24, \ - 0x23, \ - 0x22, \ - 0x21, \ - 0x20, \ - 0x2f, \ - 0x2e, \ - 0x2d, \ - 0x2c, \ - 0x2b, \ - 0x2a, \ - 0x29, \ - 0x28, \ - 0x37, \ - 0x36, \ - 0x35, \ - 0x34, \ - 0x33, \ - 0x32, \ - 0x31, \ - 0x30, \ - 0x3f, \ - 0x3e, \ - 0x3d, \ - 0x3c, \ - 0x3b, \ - 0x3a, \ - 0x39, \ - 0x38, \ + 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00, \ + 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, \ + 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, \ + 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, \ + 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x20, \ + 0x2f, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x28, \ + 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x30, \ + 0x3f, 0x3e, 0x3d, 0x3c, 0x3b, 0x3a, 0x39, 0x38, \ } #define FNV_B64_3E \ { \ - 0x1a, \ - 0x1b, \ - 0x18, \ - 0x19, \ - 0x1e, \ - 0x1f, \ - 0x1c, \ - 0x1d, \ - 0x12, \ - 0x13, \ - 0x10, \ - 0x11, \ - 0x16, \ - 0x17, \ - 0x14, \ - 0x15, \ - 0x0a, \ - 0x0b, \ - 0x08, \ - 0x09, \ - 0x0e, \ - 0x0f, \ - 0x0c, \ - 0x0d, \ - 0x02, \ - 0x03, \ - 0x00, \ - 0x01, \ - 0x06, \ - 0x07, \ - 0x04, \ - 0x05, \ - 0x3a, \ - 0x3b, \ - 0x38, \ - 0x39, \ - 0x3e, \ - 0x3f, \ - 0x3c, \ - 0x3d, \ - 0x32, \ - 0x33, \ - 0x30, \ - 0x31, \ - 0x36, \ - 0x37, \ - 0x34, \ - 0x35, \ - 0x2a, \ - 0x2b, \ - 0x28, \ - 0x29, \ - 0x2e, \ - 0x2f, \ - 0x2c, \ - 0x2d, \ - 0x22, \ - 0x23, \ - 0x20, \ - 0x21, \ - 0x26, \ - 0x27, \ - 0x24, \ - 0x25, \ + 0x1a, 0x1b, 0x18, 0x19, 0x1e, 0x1f, 0x1c, 0x1d, \ + 0x12, 0x13, 0x10, 0x11, 0x16, 0x17, 0x14, 0x15, \ + 0x0a, 0x0b, 0x08, 0x09, 0x0e, 0x0f, 0x0c, 0x0d, \ + 0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05, \ + 0x3a, 0x3b, 0x38, 0x39, 0x3e, 0x3f, 0x3c, 0x3d, \ + 0x32, 0x33, 0x30, 0x31, 0x36, 0x37, 0x34, 0x35, \ + 0x2a, 0x2b, 0x28, 0x29, 0x2e, 0x2f, 0x2c, 0x2d, \ + 0x22, 0x23, 0x20, 0x21, 0x26, 0x27, 0x24, 0x25, \ } #define FNV_B64_3F \ { \ - 0x2d, \ - 0x2c, \ - 0x2f, \ - 0x2e, \ - 0x29, \ - 0x28, \ - 0x2b, \ - 0x2a, \ - 0x25, \ - 0x24, \ - 0x27, \ - 0x26, \ - 0x21, \ - 0x20, \ - 0x23, \ - 0x22, \ - 0x3d, \ - 0x3c, \ - 0x3f, \ - 0x3e, \ - 0x39, \ - 0x38, \ - 0x3b, \ - 0x3a, \ - 0x35, \ - 0x34, \ - 0x37, \ - 0x36, \ - 0x31, \ - 0x30, \ - 0x33, \ - 0x32, \ - 0x0d, \ - 0x0c, \ - 0x0f, \ - 0x0e, \ - 0x09, \ - 0x08, \ - 0x0b, \ - 0x0a, \ - 0x05, \ - 0x04, \ - 0x07, \ - 0x06, \ - 0x01, \ - 0x00, \ - 0x03, \ - 0x02, \ - 0x1d, \ - 0x1c, \ - 0x1f, \ - 0x1e, \ - 0x19, \ - 0x18, \ - 0x1b, \ - 0x1a, \ - 0x15, \ - 0x14, \ - 0x17, \ - 0x16, \ - 0x11, \ - 0x10, \ - 0x13, \ - 0x12, \ + 0x2d, 0x2c, 0x2f, 0x2e, 0x29, 0x28, 0x2b, 0x2a, \ + 0x25, 0x24, 0x27, 0x26, 0x21, 0x20, 0x23, 0x22, \ + 0x3d, 0x3c, 0x3f, 0x3e, 0x39, 0x38, 0x3b, 0x3a, \ + 0x35, 0x34, 0x37, 0x36, 0x31, 0x30, 0x33, 0x32, \ + 0x0d, 0x0c, 0x0f, 0x0e, 0x09, 0x08, 0x0b, 0x0a, \ + 0x05, 0x04, 0x07, 0x06, 0x01, 0x00, 0x03, 0x02, \ + 0x1d, 0x1c, 0x1f, 0x1e, 0x19, 0x18, 0x1b, 0x1a, \ + 0x15, 0x14, 0x17, 0x16, 0x11, 0x10, 0x13, 0x12, \ } #endif /* FNV_HASH_H */ diff --git a/librz/include/rz_bin.h b/librz/include/rz_bin.h index 828966f56a5..592981a30fa 100644 --- a/librz/include/rz_bin.h +++ b/librz/include/rz_bin.h @@ -165,7 +165,7 @@ typedef enum { } RzBinLanguage; #define RZ_BIN_LANGUAGE_MASK(x) ((x) & ~RZ_BIN_LANGUAGE_BLOCKS) -#define RZ_BIN_LANGUAGE_HAS_BLOCKS(x) ((x) & RZ_BIN_LANGUAGE_BLOCKS) +#define RZ_BIN_LANGUAGE_HAS_BLOCKS(x) ((x)&RZ_BIN_LANGUAGE_BLOCKS) enum { RZ_BIN_CLASS_PRIVATE, diff --git a/librz/include/rz_cons.h b/librz/include/rz_cons.h index a3b7e904e3e..0e2bee4438a 100644 --- a/librz/include/rz_cons.h +++ b/librz/include/rz_cons.h @@ -761,8 +761,8 @@ typedef struct rz_cons_t { #define Colors_PLAIN \ { \ Color_BLACK, Color_RED, Color_WHITE, \ - Color_GREEN, Color_MAGENTA, Color_YELLOW, \ - Color_CYAN, Color_BLUE, Color_GRAY \ + Color_GREEN, Color_MAGENTA, Color_YELLOW, \ + Color_CYAN, Color_BLUE, Color_GRAY \ } enum { diff --git a/librz/include/rz_magic.h b/librz/include/rz_magic.h index 6367b6350b3..a8802d2504e 100644 --- a/librz/include/rz_magic.h +++ b/librz/include/rz_magic.h @@ -66,7 +66,7 @@ struct rz_magic { #define UNSIGNED 0x08 /* comparison is unsigned */ #define NOSPACE 0x10 /* suppress space character before output */ #define BINTEST 0x20 /* test is for a binary type (set only \ - for top-level tests) */ + for top-level tests) */ #define TEXTTEST 0 /* for passing to file_softmagic */ ut8 dummy1; diff --git a/librz/include/rz_types.h b/librz/include/rz_types.h index 8fe3c581b0c..f1c758adc79 100644 --- a/librz/include/rz_types.h +++ b/librz/include/rz_types.h @@ -632,7 +632,7 @@ static inline void rz_run_call10(void *fcn, void *arg1, void *arg2, void *arg3, #ifndef container_of #ifdef _MSC_VER -#define container_of(ptr, type, member) ((type *)((char *)(ptr) - offsetof(type, member))) +#define container_of(ptr, type, member) ((type *)((char *)(ptr)-offsetof(type, member))) #else #define container_of(ptr, type, member) ((type *)((char *)(__typeof__(((type *)0)->member) *){ ptr } - offsetof(type, member))) #endif diff --git a/librz/include/rz_types_base.h b/librz/include/rz_types_base.h index 8f7501e6425..7cd3bc70a51 100644 --- a/librz/include/rz_types_base.h +++ b/librz/include/rz_types_base.h @@ -112,7 +112,7 @@ typedef struct _utX { #define UT32_ALIGN(x) (x + (x - (x % sizeof(ut32)))) #define UT16_ALIGN(x) (x + (x - (x % sizeof(ut16)))) -#define UT32_LO(x) ((ut32)((x) & UT32_MAX)) +#define UT32_LO(x) ((ut32)((x)&UT32_MAX)) #define UT32_HI(x) ((ut32)(((ut64)(x)) >> 32) & UT32_MAX) #define RZ_BETWEEN(x, y, z) (((y) >= (x)) && ((y) <= (z))) @@ -135,7 +135,7 @@ typedef struct _utX { /* copied from bithacks.h */ #define B_IS_SET(x, n) (((x) & (1ULL << (n))) ? 1 : 0) #define B_SET(x, n) ((x) |= (1ULL << (n))) -#define B_EVEN(x) (((x) & 1) == 0) +#define B_EVEN(x) (((x)&1) == 0) #define B_ODD(x) (!B_EVEN((x))) #define B_UNSET(x, n) ((x) &= ~(1ULL << (n))) #define B_TOGGLE(x, n) ((x) ^= (1ULL << (n))) diff --git a/librz/magic/apprentice.c b/librz/magic/apprentice.c index 6721078809c..275e6d50798 100644 --- a/librz/magic/apprentice.c +++ b/librz/magic/apprentice.c @@ -49,14 +49,14 @@ #ifdef _MSC_VER #include #include -#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) -#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +#define S_ISREG(m) (((m)&S_IFMT) == S_IFREG) +#define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) #define MAXPATHLEN 255 #endif #define EATAB \ { \ - while (isascii((ut8) * l) && isspace((ut8) * l)) { \ + while (isascii((ut8)*l) && isspace((ut8)*l)) { \ l++; \ } \ } diff --git a/librz/magic/fsmagic.c b/librz/magic/fsmagic.c index 8e35fa7cf77..697f8eef951 100644 --- a/librz/magic/fsmagic.c +++ b/librz/magic/fsmagic.c @@ -54,7 +54,7 @@ #ifndef HAVE_MAJOR #define major(dev) (((dev) >> 8) & 0xff) -#define minor(dev) ((dev) & 0xff) +#define minor(dev) ((dev)&0xff) #endif #undef HAVE_MAJOR diff --git a/librz/magic/magic.c b/librz/magic/magic.c index 06751548faa..278a250bfb8 100644 --- a/librz/magic/magic.c +++ b/librz/magic/magic.c @@ -10,10 +10,10 @@ RZ_LIB_VERSION(rz_magic); #ifdef _MSC_VER #include #include -#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) -#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +#define S_ISREG(m) (((m)&S_IFMT) == S_IFREG) +#define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) #define S_IFIFO (-1) -#define S_ISFIFO(m) (((m) & S_IFIFO) == S_IFIFO) +#define S_ISFIFO(m) (((m)&S_IFIFO) == S_IFIFO) #define MAXPATHLEN 255 #endif diff --git a/librz/type/format.c b/librz/type/format.c index 2a27e372ebc..faf6763fade 100644 --- a/librz/type/format.c +++ b/librz/type/format.c @@ -1895,7 +1895,7 @@ static char *get_format_type(const char fmt, const char arg) { return type; } -#define MINUSONE ((void *)(size_t) - 1) +#define MINUSONE ((void *)(size_t)-1) #define ISSTRUCT (tmp == '?' || (tmp == '*' && *(arg + 1) == '?')) RZ_API const char *rz_type_db_format_get(const RzTypeDB *typedb, const char *name) { diff --git a/librz/util/bitvector.c b/librz/util/bitvector.c index 044e7b8070a..fb4655182ff 100644 --- a/librz/util/bitvector.c +++ b/librz/util/bitvector.c @@ -5,12 +5,12 @@ #include #include -#define NELEM(N, ELEMPER) ((N + (ELEMPER) - 1) / (ELEMPER)) +#define NELEM(N, ELEMPER) ((N + (ELEMPER)-1) / (ELEMPER)) #define BV_ELEM_SIZE 8U // optimization for reversing 8 bits which uses 32 bits // https://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith32Bits -#define reverse_byte(x) ((((x) * 0x0802LU & 0x22110LU) | ((x) * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16) +#define reverse_byte(x) ((((x)*0x0802LU & 0x22110LU) | ((x)*0x8020LU & 0x88440LU)) * 0x10101LU >> 16) // https://graphics.stanford.edu/~seander/bithacks.html#BitReverseObvious // With changes. diff --git a/librz/util/sdb/src/cdb_make.c b/librz/util/sdb/src/cdb_make.c index f7486a860c1..8f39bfe91a3 100644 --- a/librz/util/sdb/src/cdb_make.c +++ b/librz/util/sdb/src/cdb_make.c @@ -69,7 +69,7 @@ static int pack_kvlen(ut8 *buf, ut32 klen, ut32 vlen) { return 0; } buf[0] = (ut8)klen; - buf[1] = (ut8)((vlen) & 0xff); + buf[1] = (ut8)((vlen)&0xff); buf[2] = (ut8)((vlen >> 8) & 0xff); buf[3] = (ut8)((vlen >> 16) & 0xff); return 1; diff --git a/librz/util/unum.c b/librz/util/unum.c index 5a29a648fbc..e0a87203cff 100644 --- a/librz/util/unum.c +++ b/librz/util/unum.c @@ -637,7 +637,7 @@ RZ_API ut64 rz_num_get_input_value(RzNum *num, const char *input_value) { return value; } -#define NIBBLE_TO_HEX(n) (((n) & 0xf) > 9 ? 'a' + ((n) & 0xf) - 10 : '0' + ((n) & 0xf)) +#define NIBBLE_TO_HEX(n) (((n)&0xf) > 9 ? 'a' + ((n)&0xf) - 10 : '0' + ((n)&0xf)) static int escape_char(char *dst, char byte) { const char escape_map[] = "abtnvfr"; if (byte >= 7 && byte <= 13) { From 2b729c6ea51d890f2598b7a568ee2fa67f30d22f Mon Sep 17 00:00:00 2001 From: tushar3q34 Date: Wed, 4 Sep 2024 20:47:21 +0530 Subject: [PATCH 4/4] Android Build Fixes --- librz/debug/p/native/android_arm.c | 2 -- librz/debug/p/native/android_arm64.c | 2 -- librz/debug/p/native/android_x86_64.c | 2 -- 3 files changed, 6 deletions(-) diff --git a/librz/debug/p/native/android_arm.c b/librz/debug/p/native/android_arm.c index 86041c04ebe..7fc17519e6d 100644 --- a/librz/debug/p/native/android_arm.c +++ b/librz/debug/p/native/android_arm.c @@ -41,8 +41,6 @@ static char *rz_debug_native_reg_profile(RzDebug *dbg) { return linux_reg_profile(dbg); } -#include "reg.c" - static bool rz_debug_native_step(RzDebug *dbg) { return linux_step(dbg); } diff --git a/librz/debug/p/native/android_arm64.c b/librz/debug/p/native/android_arm64.c index d5cf33ba8bf..e27046fbc6c 100644 --- a/librz/debug/p/native/android_arm64.c +++ b/librz/debug/p/native/android_arm64.c @@ -41,8 +41,6 @@ static char *rz_debug_native_reg_profile(RzDebug *dbg) { return linux_reg_profile(dbg); } -#include "reg.c" - static bool rz_debug_native_step(RzDebug *dbg) { return linux_step(dbg); } diff --git a/librz/debug/p/native/android_x86_64.c b/librz/debug/p/native/android_x86_64.c index e7e90f4ad21..0551fafbf22 100644 --- a/librz/debug/p/native/android_x86_64.c +++ b/librz/debug/p/native/android_x86_64.c @@ -41,8 +41,6 @@ static char *rz_debug_native_reg_profile(RzDebug *dbg) { return linux_reg_profile(dbg); } -#include "reg.c" - static bool rz_debug_native_step(RzDebug *dbg) { return linux_step(dbg); }