Fix and move failing tests, reorder lib build ##arch

This commit is contained in:
pancake 2022-11-30 00:46:52 +01:00 committed by pancake
parent 7ca2004fc9
commit 19a377bbda
26 changed files with 146 additions and 113 deletions

View File

@ -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

View File

@ -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)

View File

@ -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,

View File

@ -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);

View File

@ -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;

View File

@ -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,

View File

@ -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

View File

@ -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

View File

@ -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) {

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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'

View File

@ -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

View File

@ -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"]

View File

@ -1069,3 +1069,59 @@ EXPECT=<<EOF
size: 20
EOF
RUN
NAME=raw aac with maps (using a PIC bin)
FILE=bins/elf/libmagic.so
ARGS=-n -m 0x80000 -a arm -b 16 -e cfg.bigendian=false
CMDS=<<EOF
aac
e search.in=io.maps
afl~?
EOF
EXPECT=<<EOF
94
EOF
RUN
NAME=aav thumb detection
FILE=bins/firmware/armthumb.bin
ARGS=-aarm -b32
CMDS=<<EOF
aav
f
EOF
EXPECT=<<EOF
0x0000000d 4 aav.0x0000000d
EOF
RUN
NAME=Function definition
FILE=bins/elf/arm1.bin
CMDS=<<EOF
afr @ main
s 0x000082cc
pd 1~?*xmalloc
EOF
EXPECT=<<EOF
1
EOF
RUN
NAME=no string on cbz
FILE=malloc://8096
CMDS=<<EOF
e asm.arch=arm
e asm.bits=64
e cfg.bigendian=false
e emu.str=true
wv 0x52800015
wv 0x340000b5 @ 4
w hello @ 0x18
pd 2
EOF
EXPECT=<<EOF
0x00000000 15008052 mov w21, 0
,=< 0x00000004 b5000034 cbz w21, 0x18 ; likely
EOF
RUN

View File

@ -729,19 +729,6 @@ EXPECT=<<EOF
EOF
RUN
NAME=raw aac with maps (using a PIC bin)
FILE=bins/elf/libmagic.so
ARGS=-n -m 0x80000 -a arm -b 16 -e cfg.bigendian=false
CMDS=<<EOF
aac
e search.in=io.maps
afl~?
EOF
EXPECT=<<EOF
94
EOF
RUN
NAME=aav without vinfun
FILE=bins/elf/analysis/mipsbe-busybox
CMDS=<<EOF
@ -768,19 +755,6 @@ EXPECT=<<EOF
EOF
RUN
NAME=aav thumb detection
FILE=bins/firmware/armthumb.bin
ARGS=-aarm -b32
CMDS=<<EOF
aav
f
EOF
EXPECT=<<EOF
0x0000000d 4 aav.0x0000000d
EOF
RUN
NAME=sym is not fcn
FILE=bins/mach0/mach0-i386
CMDS=<<EOF
@ -1697,25 +1671,6 @@ EXPECT=<<EOF
EOF
RUN
NAME=no string on cbz
FILE=malloc://8096
CMDS=<<EOF
e asm.arch=arm
e asm.bits=64
e cfg.bigendian=false
e emu.str=true
wv 0x52800015
wv 0x340000b5 @ 4
w hello @ 0x18
pd 2
EOF
EXPECT=<<EOF
0x00000000 15008052 mov w21, 0
,=< 0x00000004 b5000034 cbz w21, 0x18 ; likely
EOF
RUN
NAME=No function
FILE=malloc://0x50
CMDS=aftm
@ -1839,18 +1794,6 @@ unsigned long request
EOF
RUN
NAME=Function definition
FILE=bins/elf/arm1.bin
CMDS=<<EOF
afr @ main
s 0x000082cc
pd 1~?*xmalloc
EOF
EXPECT=<<EOF
1
EOF
RUN
NAME=Function definition (autorename)
FILE=bins/pe/hello-mingw32
CMDS=<<EOF

View File

@ -1295,5 +1295,5 @@ aB "ror byte[rax-0x2a], 0x2a" c048d62a
aB "ror byte[rax], 0x2a" c048d62a
aB "ror byte[r15-0x2a], 1" 41d04fd6
ad "mov rdx, [rip+0x17792]" 488b0592770100
ad "mov rax, qword [rip + 0x17792]" 488b0592770100
a "mov rdx, [0x17792+rip]" 488b0592770100

View File

@ -135,7 +135,9 @@ bool test_file_slurp(void) {
f = open (test_file, O_WRONLY, S_IRWXU);
mu_assert_neq (f, -1, "cannot reopen empty file");
write (f, some_words, strlen (some_words));
size_t len = strlen (some_words);
size_t res = write (f, some_words, len);
mu_assert_eq (res, len, "size and length must be the same");
close (f);
content = r_file_slurp (test_file, &s);