diff --git a/Makefile b/Makefile index 9008c8a5ef..8f5cf03251 100644 --- a/Makefile +++ b/Makefile @@ -190,8 +190,8 @@ clean: distclean mrproper: clean rm -f `find . -type f -iname '*.d'` - rm -rf libr/asm/arch/arm/v35arm64/arch-arm64 - rm -rf libr/asm/arch/arm/v35arm64/arch-armv7 + rm -rf libr/arch/p/arm/v35arm64/arch-arm64 + rm -rf libr/arch/p/arm/v35arm64/arch-armv7 pkgcfg: cd libr && ${MAKE} pkgcfg diff --git a/libr/Makefile b/libr/Makefile index ccaae0794c..91125b9800 100644 --- a/libr/Makefile +++ b/libr/Makefile @@ -118,8 +118,8 @@ E+=../shlr/ar/libr_ar.${EXT_AR} E+=../shlr/winkd/libr_winkd.${EXT_AR} E+=../shlr/qnx/lib/libqnxr.${EXT_AR} E+=../shlr/bochs/lib/libbochs.${EXT_AR} -E+=../libr/asm/arch/arm/v35arm64/arm64dis.${EXT_AR} -E+=../libr/asm/arch/arm/v35arm64/armv7dis.${EXT_AR} +E+=../libr/arch/p/arm/v35arm64/arm64dis.${EXT_AR} +E+=../libr/arch/p/arm/v35arm64/armv7dis.${EXT_AR} ifeq ($(USE_CAPSTONE),1) E+=$(CAPSTONE_LDFLAGS) diff --git a/libr/arch/meson.build b/libr/arch/meson.build index 589f458497..4e208df10b 100644 --- a/libr/arch/meson.build +++ b/libr/arch/meson.build @@ -50,7 +50,7 @@ r_arch_static = static_library('r_arch_static', r_arch_sources, c_args: library_cflags, dependencies: [ r_util_static_dep, - capstone_static_dep, + capstone_dep, ], install: true, implicit_include_directories: false, diff --git a/libr/arch/p/arm/aarch64/aarch64-opc.c b/libr/arch/p/arm/aarch64/aarch64-opc.c index 48e2f6f046..733c27cff3 100644 --- a/libr/arch/p/arm/aarch64/aarch64-opc.c +++ b/libr/arch/p/arm/aarch64/aarch64-opc.c @@ -889,7 +889,7 @@ aarch64_find_best_match (const aarch64_inst *inst, stop_at = num_opnds - 1; /* For each pattern. */ - for (i = 0; i < AARCH64_MAX_QLF_SEQ_NUM; ++i, qualifiers_list++) + for (i = 0; i < AARCH64_MAX_QLF_SEQ_NUM; i++, qualifiers_list++) { int j; qualifiers = *qualifiers_list; @@ -997,14 +997,14 @@ match_operands_qualifier (aarch64_inst *inst, bfd_boolean update_p) { /* Require an exact qualifier match, even for NIL qualifiers. */ nops = aarch64_num_of_operands (inst->opcode); - for (i = 0; i < nops; ++i) + for (i = 0; i < nops; i++) if (inst->operands[i].qualifier != qualifiers[i]) return FALSE; } /* Update the qualifiers. */ if (update_p == TRUE) - for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i) + for (i = 0; i < AARCH64_MAX_OPND_NUM; i++) { if (inst->opcode->operands[i] == AARCH64_OPND_NIL) break; @@ -2675,7 +2675,7 @@ aarch64_match_operands_constraint (aarch64_inst *inst, } /* Match operands' constraint. */ - for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i) + for (i = 0; i < AARCH64_MAX_OPND_NUM; i++) { enum aarch64_opnd type = inst->opcode->operands[i]; if (type == AARCH64_OPND_NIL) @@ -2716,7 +2716,7 @@ aarch64_replace_opcode (aarch64_inst *inst, const aarch64_opcode *opcode) inst->opcode = opcode; /* Update the operand types. */ - for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i) + for (i = 0; i < AARCH64_MAX_OPND_NUM; i++) { inst->operands[i].type = opcode->operands[i]; if (opcode->operands[i] == AARCH64_OPND_NIL) @@ -2732,7 +2732,7 @@ int aarch64_operand_index (const enum aarch64_opnd *operands, enum aarch64_opnd operand) { int i; - for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i) + for (i = 0; i < AARCH64_MAX_OPND_NUM; i++) if (operands[i] == operand) return i; else if (operands[i] == AARCH64_OPND_NIL) @@ -3418,7 +3418,7 @@ aarch64_print_operand (char *buf, size_t size, bfd_vma pc, case AARCH64_OPND_COND1: snprintf (buf, size, "%s", opnd->cond->names[0]); num_conds = ARRAY_SIZE (opnd->cond->names); - for (i = 1; i < num_conds && opnd->cond->names[i]; ++i) + for (i = 1; i < num_conds && opnd->cond->names[i]; i++) { size_t len = strlen (buf); if (i == 1) @@ -3554,7 +3554,7 @@ aarch64_print_operand (char *buf, size_t size, bfd_vma pc, break; case AARCH64_OPND_SYSREG: - for (i = 0; aarch64_sys_regs[i].name; ++i) + for (i = 0; aarch64_sys_regs[i].name; i++) { bfd_boolean exact_match = (aarch64_sys_regs[i].flags & opnd->sysreg.flags) @@ -3598,7 +3598,7 @@ aarch64_print_operand (char *buf, size_t size, bfd_vma pc, break; case AARCH64_OPND_PSTATEFIELD: - for (i = 0; aarch64_pstatefields[i].name; ++i) + for (i = 0; aarch64_pstatefields[i].name; i++) if (aarch64_pstatefields[i].value == opnd->pstatefield) break; assert (aarch64_pstatefields[i].name); diff --git a/libr/arch/p/arm/aarch64/aarch64.h b/libr/arch/p/arm/aarch64/aarch64.h index 24af060ded..d07c3da44d 100644 --- a/libr/arch/p/arm/aarch64/aarch64.h +++ b/libr/arch/p/arm/aarch64/aarch64.h @@ -656,7 +656,7 @@ static inline bfd_boolean empty_qualifier_sequence_p (const aarch64_opnd_qualifier_t *qualifiers) { int i; - for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i) + for (i = 0; i < AARCH64_MAX_OPND_NUM; i++) if (qualifiers[i] != AARCH64_OPND_QLF_NIL) return FALSE; return TRUE; diff --git a/libr/arch/p/arm/plugin.c b/libr/arch/p/arm/plugin.c index dc0c7f26f8..8d3fe8e81f 100644 --- a/libr/arch/p/arm/plugin.c +++ b/libr/arch/p/arm/plugin.c @@ -114,12 +114,29 @@ static int assemble(RAsm *a, RAsmOp *op, const char *buf) { } #endif +static int archinfo(RArchSession *a, ut32 q) { + switch (q) { + case R_ANAL_ARCHINFO_DATA_ALIGN: + case R_ANAL_ARCHINFO_INV_OP_SIZE: + case R_ANAL_ARCHINFO_MAX_OP_SIZE: + break; + case R_ANAL_ARCHINFO_MIN_OP_SIZE: + case R_ANAL_ARCHINFO_ALIGN: + if (a->config && a->config->bits == 16) { + return 2; + } + break; + } + return 4; // XXX +} + RArchPlugin r_arch_plugin_arm = { .name = "arm", .desc = "custom thumb, arm32 and arm64 assembler", .author = "pancake", .license = "LGPL3", .arch = "arm", + .info = archinfo, .bits = R_SYS_BITS_PACK3 (16, 32, 64), .endian = R_SYS_ENDIAN_LITTLE | R_SYS_ENDIAN_BIG, .encode = &encode, diff --git a/libr/bin/Makefile b/libr/bin/Makefile index 74edb13800..963ef75c46 100644 --- a/libr/bin/Makefile +++ b/libr/bin/Makefile @@ -8,7 +8,7 @@ R2DEPS=r_util r_io r_socket r_magic r_syscall r_cons r_crypto r_fs pre: $(LIBSO) $(LIBAR) $(MAKE) -C p - -$(MAKE) -j4 -C d + $(MAKE) -C d CFLAGS+=-DR2_PLUGIN_INCORE -Iformat -Imangling diff --git a/libr/bin/d/Makefile b/libr/bin/d/Makefile index 25b343cd9b..b0112c9579 100644 --- a/libr/bin/d/Makefile +++ b/libr/bin/d/Makefile @@ -27,7 +27,7 @@ DLLS+=setup4 setupx shell sound spooler storage sysclass sysdetmg DLLS+=sysdm sysedit system systhunk tapi tapiaddr DLLS+=toolhelp typelib umdm16 user ver whlp16t win32s16 DLLS+=win87em winaspi winnet16 winoldap winsock winspl16 wpsapd wpsuni -# XXX DLLS+=wpsunire wsasrv +DLLS+=wpsunire wsasrv DLL_SDB=$(addsuffix .sdb,$(addprefix dll/,$(DLLS))) all: $(DLL_SDB) @@ -35,7 +35,7 @@ all: $(DLL_SDB) clean: rm -f dll/*.sdb -.PHONY: all clean install install-symlink symstall +.PHONY: all clean install install-symlink symstall uninstall FORMATS=dex macho elf32 elf64 elf_enums pe32 trx mz zip diff --git a/libr/core/cmd_anal.c b/libr/core/cmd_anal.c index 19ec0b0309..898de04081 100644 --- a/libr/core/cmd_anal.c +++ b/libr/core/cmd_anal.c @@ -11253,9 +11253,17 @@ static void cmd_anal_aad(RCore *core, const char *input) { } static bool archIsThumbable(RCore *core) { - RAsm *as = core ? core->rasm : NULL; - if (as && as->cur && as->config->bits <= 32 && as->cur->name) { - return strstr (as->cur->name, "arm"); + RArchConfig *ac = R_UNWRAP4 (core, anal, arch, cfg); + if (ac && ac->bits <= 32) { + // XXX for some reason this is null + if (!strcmp (ac->arch, "arm")) { + return true; + } + if (core->anal->cur) { + if (!strcmp (core->anal->cur->arch, "arm")) { + return true; + } + } } return false; } @@ -11263,7 +11271,7 @@ static bool archIsThumbable(RCore *core) { static void _CbInRangeAav(RCore *core, ut64 from, ut64 to, int vsize, void *user) { bool asterisk = user; int arch_align = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_ALIGN); - bool vinfun = r_config_get_i (core->config, "anal.vinfun"); + bool vinfun = r_config_get_b (core->config, "anal.vinfun"); int searchAlign = r_config_get_i (core->config, "search.align"); int align = (searchAlign > 0)? searchAlign: arch_align; if (align > 1) { diff --git a/libr/core/cmd_search.c b/libr/core/cmd_search.c index 2ff354371b..f6c2c40426 100644 --- a/libr/core/cmd_search.c +++ b/libr/core/cmd_search.c @@ -2308,7 +2308,7 @@ static void search_hit_at(RCore *core, struct search_parameters *param, RCoreAsm free (s); } } else { - r_cons_printf ("0x%08"PFMT64x " # %i: %s\n", hit->addr, hit->len, hit->code); + r_cons_printf ("0x%08"PFMT64x " # %i: %s\n", hit->addr, hit->len, r_str_get (hit->code)); } break; } diff --git a/libr/crypto/p/crypto_rc2.c b/libr/crypto/p/crypto_rc2.c index 538d6076b4..6dde3a921b 100644 --- a/libr/crypto/p/crypto_rc2.c +++ b/libr/crypto/p/crypto_rc2.c @@ -168,12 +168,10 @@ static void rc2_dcrypt(struct rc2_state *state, const ut8 *inbuf, ut8 *outbuf, i } static void rc2_crypt(struct rc2_state *state, const ut8 *inbuf, ut8 *outbuf, int buflen) { - int i; - char data_block[BLOCK_SIZE] = {0}; - int idx = 0; - char crypted_block[BLOCK_SIZE] = {0}; + char data_block[BLOCK_SIZE] = {0}; char *ptr = (char *) outbuf; + int i, idx = 0; // divide it into blocks of BLOCK_SIZE for (i = 0; i < buflen; i++) { @@ -187,12 +185,15 @@ static void rc2_crypt(struct rc2_state *state, const ut8 *inbuf, ut8 *outbuf, in } } - if (idx % 8) { - while (idx % 8) { - data_block[idx++] = 0; + size_t mod = idx % BLOCK_SIZE; + if (mod) { + while (idx % BLOCK_SIZE) { + mod = idx % BLOCK_SIZE; + data_block[mod] = 0; + idx++; } rc2_crypt8 (state, (const ut8 *) data_block, (ut8 *) crypted_block); - strncpy (ptr, crypted_block, 8); + r_str_ncpy (ptr, crypted_block, BLOCK_SIZE); } } diff --git a/libr/egg/Makefile b/libr/egg/Makefile index 20c8601e2d..cd01a473e3 100644 --- a/libr/egg/Makefile +++ b/libr/egg/Makefile @@ -1,8 +1,10 @@ include ../config.mk NAME=r_egg -R2DEPS=r_asm r_syscall r_util r_parse r_anal +R2DEPS=r_asm r_syscall r_util r_parse R2DEPS+=r_flag r_cons r_reg r_lang r_arch + +R2DEPS+=r_esil r_anal r_crypto r_search ## XXX r_anal is a temporary dependency to make r_asm work with r_arch OBJS=egg.o egg_lang.o diff --git a/libr/egg/meson.build b/libr/egg/meson.build index cafd8a54d5..30a8c2e139 100644 --- a/libr/egg/meson.build +++ b/libr/egg/meson.build @@ -20,6 +20,8 @@ r_egg = library('r_egg', r_egg_sources, dependencies: [ r_util_dep, r_anal_dep, + r_search_dep, + r_crypto_dep, r_arch_dep, r_asm_dep, r_syscall_dep, diff --git a/libr/io/Makefile b/libr/io/Makefile index e524747660..0cb4b6520f 100644 --- a/libr/io/Makefile +++ b/libr/io/Makefile @@ -7,8 +7,8 @@ R2DEPS+=r_crypto R2DEPS+=r_cons STATIC_OBJS=$(subst ..,p/..,$(subst io_,p/io_,$(STATIC_OBJ))) OBJS=${STATIC_OBJS} -OBJS+=io.o io_plugin.o io_map.o io_desc.o io_cache.o p_cache.o undo.o ioutils.o io_fd.o io_memory.o -OBJS+=io_bank.o io_submap.o +OBJS+=io.o io_plugin.o io_map.o io_desc.o io_cache.o p_cache.o +OBJS+=io_bank.o io_submap.o undo.o ioutils.o io_fd.o io_memory.o CFLAGS+=-Wall -DR2_PLUGIN_INCORE diff --git a/libr/io/p/shm.mk b/libr/io/p/shm.mk index f765b69b9b..06a8574f52 100644 --- a/libr/io/p/shm.mk +++ b/libr/io/p/shm.mk @@ -14,6 +14,7 @@ ifeq (${WITHPIC},0) LINKFLAGS+=../../util/libr_util.a LINKFLAGS+=../../io/libr_io.a else +LINKFLAGS+=-L../../cons -lr_cons LINKFLAGS+=-L../../util -lr_util LINKFLAGS+=-L.. -lr_io endif diff --git a/libr/libs.mk b/libr/libs.mk index c72aa6ca75..973a13b13d 100644 --- a/libr/libs.mk +++ b/libr/libs.mk @@ -2,9 +2,9 @@ ifeq ($(LIBS0),) LIBS0=util -LIBS1=socket reg cons magic bp config -LIBS2=syscall lang crypto flag arch esil -LIBS3=parse io search +LIBS1=socket reg cons magic bp config crypto +LIBS2=syscall lang search flag arch esil +LIBS3=parse io LIBS4=asm fs anal LIBS5=egg bin LIBS6=debug diff --git a/libr/search/Makefile b/libr/search/Makefile index ea21f30347..101f181ba4 100644 --- a/libr/search/Makefile +++ b/libr/search/Makefile @@ -1,9 +1,10 @@ include ../config.mk NAME=r_search -OBJS=search.o bytepat.o strings.o aes_find.o privkey_find.o sm4_find.o -OBJS+=regexp.o keyword.o uds.o rabin_karp.o -# OBJ+=rsakey.o + +OBJS=search.o bytepat.o strings.o aes_find.o privkey.o +OBJS+=regexp.o keyword.o uds.o karp.o sm4_find.o + R2DEPS=r_util r_crypto include ../rules.mk diff --git a/libr/search/rabin_karp.c b/libr/search/karp.c similarity index 100% rename from libr/search/rabin_karp.c rename to libr/search/karp.c diff --git a/libr/search/meson.build b/libr/search/meson.build index 4192c69a25..e52095c739 100644 --- a/libr/search/meson.build +++ b/libr/search/meson.build @@ -4,8 +4,8 @@ r_search_sources = [ 'keyword.c', 'regexp.c', 'uds.c', - 'privkey_find.c', - 'rabin_karp.c', + 'privkey.c', + 'karp.c', 'search.c', 'sm4_find.c', 'strings.c' diff --git a/libr/search/privkey_find.c b/libr/search/privkey.c similarity index 100% rename from libr/search/privkey_find.c rename to libr/search/privkey.c diff --git a/preconfigure b/preconfigure index 66ac2afdbd..73a064a26d 100755 --- a/preconfigure +++ b/preconfigure @@ -18,7 +18,7 @@ rm -rf shlr/capstone ${MAKE} -C shlr capstone > /dev/null 2>&1 || exit 1 echo OK -V35WD=libr/asm/arch/arm/v35arm64 +V35WD=libr/arch/p/arm/v35arm64 printf "[*] Checking out vector35-arm64... " if [ ! -d "${V35WD}/arch-arm64/.git" ]; then rm -rf ${V35WD}/arch-arm64 diff --git a/sys/clang-format.py b/sys/clang-format.py index 1b81141ffa..907bea9521 100755 --- a/sys/clang-format.py +++ b/sys/clang-format.py @@ -6,7 +6,7 @@ import sys dirlist = [ "binrz", - "librz", + "libr", "shlr/ar", "shlr/bochs", "shlr/gdb", @@ -21,16 +21,16 @@ dirlist = [ skiplist = [ "/gnu/", - "librz/anal/arch/vax/", - "librz/asm/arch/riscv/", - "librz/asm/arch/sh/gnu/", - "librz/asm/arch/i8080/", - "librz/asm/arch/z80/", - "librz/asm/arch/avr/", - "librz/asm/arch/arm/aarch64/", - "librz/hash/xxhash/", - "librz/bin/mangling/cxx/", - "librz/util/bdiff.c", + "libr/anal/arch/vax/", + "libr/asm/arch/riscv/", + "libr/asm/arch/sh/gnu/", + "libr/asm/arch/i8080/", + "libr/asm/arch/z80/", + "libr/asm/arch/avr/", + "libr/arch/p/arm/aarch64/", + "libr/hash/xxhash/", + "libr/bin/mangling/cxx/", + "libr/util/bdiff.c", ] pattern = ["*.c", "*.cpp", "*.h", "*.hpp", "*.inc"] diff --git a/test/db/anal/arm b/test/db/anal/arm index c62d371819..5f1fb6f938 100644 --- a/test/db/anal/arm +++ b/test/db/anal/arm @@ -1069,3 +1069,59 @@ EXPECT=<