Skip to content

Commit

Permalink
Use packed RSysBits everywhere and deprecate R_SYS_BITS_X ##util
Browse files Browse the repository at this point in the history
  • Loading branch information
trufae authored Jan 3, 2025
1 parent 077f9bb commit 2e68499
Show file tree
Hide file tree
Showing 62 changed files with 446 additions and 479 deletions.
5 changes: 3 additions & 2 deletions binr/r2r/load.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ static bool database_load(R2RTestDatabase *db, const char *path, int depth) {
return false;
}
if (r_file_is_directory (path)) {
const char *archos = getarchos ();
RList *dir = r_sys_dir (path);
if (!dir) {
return false;
Expand All @@ -619,8 +620,8 @@ static bool database_load(R2RTestDatabase *db, const char *path, int depth) {
continue;
}
bool is_archos_folder = !strcmp (path, "archos") || r_str_endswith (path, R_SYS_DIR"archos");
if (is_archos_folder && (skip_archos || strcmp (subname, R2R_ARCH_OS))) {
R_LOG_ERROR ("Skipping %s"R_SYS_DIR"%s because it does not match the current platform \"%s\"", path, subname, R2R_ARCH_OS);
if (is_archos_folder && (skip_archos || strcmp (subname, archos))) {
R_LOG_ERROR ("Skipping %s"R_SYS_DIR"%s because it does not match the current platform \"%s\"", path, subname, archos);
continue;
}
r_strbuf_setf (&subpath, "%s%s%s", path, R_SYS_DIR, subname);
Expand Down
11 changes: 10 additions & 1 deletion binr/r2r/r2r.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ static void interact_break(R2RTestResultInfo *result, RPVector *fixup_results);
static void interact_commands(R2RTestResultInfo *result, RPVector *fixup_results);
static void interact_diffchar(R2RTestResultInfo *result);

R_IPI const char *getarchos(void) {
if (R_SYS_BITS_CHECK (R_SYS_BITS, 64)) {
return R_SYS_OS "-"R_SYS_ARCH "_64";
} else if (R_SYS_BITS_CHECK (R_SYS_BITS, 32)) {
return R_SYS_OS "-"R_SYS_ARCH "_32";
}
return R_SYS_OS "-"R_SYS_ARCH;
}

static void parse_skip(const char *arg) {
if (strstr (arg, "arch")) {
r_sys_setenv ("R2R_SKIP_ARCHOS", "1");
Expand Down Expand Up @@ -104,7 +113,7 @@ static int help(bool verbose, int workers_count) {
helpvars (workers_count);
printf ("\n"
"Supported test types: @asm @json @unit @fuzz @arch @cmd\n"
"OS/Arch for archos tests: "R2R_ARCH_OS"\n");
"OS/Arch for archos tests: %s\n", getarchos ());
}
return 1;
}
Expand Down
9 changes: 1 addition & 8 deletions binr/r2r/r2r.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@

#include <r_util.h>

#if R_SYS_BITS & R_SYS_BITS_64
#define R2R_ARCH_OS R_SYS_OS "-"R_SYS_ARCH "_64"
#elif R_SYS_BITS & R_SYS_BITS_32
#define R2R_ARCH_OS R_SYS_OS "-"R_SYS_ARCH "_32"
#elif
#define R2R_ARCH_OS R_SYS_OS "-"R_SYS_ARCH
#endif

typedef struct r2r_cmd_test_string_record {
char *value;
ut64 line_begin; // inclusive
Expand Down Expand Up @@ -217,5 +209,6 @@ R_API char *r2r_test_name(R2RTest *test);
R_API bool r2r_test_broken(R2RTest *test);
R_API R2RTestResultInfo *r2r_run_test(R2RRunConfig *config, R2RTest *test);
R_API void r2r_test_result_info_free(R2RTestResultInfo *result);
R_IPI const char *getarchos(void);

#endif //RADARE2_R2R_H
8 changes: 1 addition & 7 deletions libr/arch/arch_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,7 @@ R_API RArchConfig *r_arch_config_new(void) {
return NULL;
}
ac->arch = strdup (R_SYS_ARCH);
#if R_SYS_BITS == R_SYS_BITS_32
ac->bits = 32;
#elif R_SYS_BITS == R_SYS_BITS_64
ac->bits = 64;
#else
ac->bits = 64;
#endif
ac->bits = R_SYS_BITS_CHECK (R_SYS_BITS, 64)? 64: 32;
ac->bitshift = 0;
ac->syntax = R_ARCH_SYNTAX_INTEL;
r_ref_init (ac, &_ac_free);
Expand Down
25 changes: 5 additions & 20 deletions libr/arch/p/arm/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,13 @@

static bool encode(RArchSession *s, RAnalOp *op, ut32 mask) {
int bits = s->config->bits;
if (bits & R_SYS_BITS_32) {
bits = 32;
} else if (bits & R_SYS_BITS_16) {
bits = 16;
}
#if 0
if (s->config->bits & R_SYS_BITS_64) {
if (R_SYS_BITS_CHECK (bits, 64)) {
bits = 64;
} else if (s->config->bits & R_SYS_BITS_32) {
} else if (R_SYS_BITS_CHECK (bits, 32)) {
bits = 32;
} else if (s->config->bits & R_SYS_BITS_16) {
} else if (R_SYS_BITS_CHECK (bits, 16)) {
bits = 16;
}
#endif
const bool is_thumb = (bits == 16);
int opsize;
ut32 opcode = UT32_MAX;
Expand Down Expand Up @@ -51,19 +44,11 @@ static bool encode(RArchSession *s, RAnalOp *op, ut32 mask) {
r_write_be32 (opbuf, opcode);
}
} else if (opsize == 2) {
if (be) {
r_write_le16 (opbuf, opcode & UT16_MAX);
} else {
r_write_be16 (opbuf, opcode & UT16_MAX);
}
r_write_ble16 (opbuf, opcode & UT16_MAX, !be);
}
} else {
opsize = 4;
if (be) {
r_write_le32 (opbuf, opcode);
} else {
r_write_be32 (opbuf, opcode);
}
r_write_ble32 (opbuf, opcode, !be);
}
r_anal_op_set_bytes (op, op->addr, opbuf, opsize);
// r_strbuf_setbin (&op->buf, opbuf, opsize);
Expand Down
4 changes: 2 additions & 2 deletions libr/bin/format/le/le.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,9 @@ R_IPI RList *r_bin_le_get_sections(RBinLEObj *bin) {
sec->perm |= R_PERM_X;
}
if (entry->flags & O_BIG_BIT) {
sec->bits = R_SYS_BITS_32;
sec->bits = R_SYS_BITS_PACK (32);
} else {
sec->bits = R_SYS_BITS_16;
sec->bits = R_SYS_BITS_PACK (16);
}
sec->is_data = (entry->flags & O_RESOURCE) || !(sec->perm & R_PERM_X);
if (!entry->page_tbl_entries) {
Expand Down
4 changes: 2 additions & 2 deletions libr/bin/format/ne/ne.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2019-2022 - GustavoLCR */
/* radare - LGPL - Copyright 2019-2024 - GustavoLCR */

#include "ne.h"

Expand Down Expand Up @@ -89,7 +89,7 @@ RList *r_bin_ne_get_segments(r_bin_ne_obj_t *bin) {
NE_image_segment_entry *se = &bin->segment_entries[i];
bs->size = se->length;
bs->vsize = se->minAllocSz ? se->minAllocSz : 64000;
bs->bits = R_SYS_BITS_16;
bs->bits = R_SYS_BITS_PACK (16);
bs->is_data = se->flags & IS_DATA;
bs->perm = __translate_perms (se->flags);
bs->paddr = (ut64)se->offset * bin->alignment;
Expand Down
Loading

0 comments on commit 2e68499

Please sign in to comment.