Add dummy parse.evm plugin to fix portability of test ##disasm

This commit is contained in:
pancake 2022-10-06 20:02:12 +02:00 committed by pancake
parent ccd79d9e36
commit f7bde37f60
9 changed files with 127 additions and 2 deletions

View File

@ -248,6 +248,7 @@ lang.spp
lang.vala
lang.pipe
lang.cpipe
parse.evm_pseudo
parse.bpf_pseudo
parse.6502_pseudo
parse.tms320_pseudo

View File

@ -94,6 +94,7 @@ extern RParsePlugin r_parse_plugin_z80_pseudo;
extern RParsePlugin r_parse_plugin_tms320_pseudo;
extern RParsePlugin r_parse_plugin_v850_pseudo;
extern RParsePlugin r_parse_plugin_bpf_pseudo;
extern RParsePlugin r_parse_plugin_evm_pseudo;
#endif
#ifdef __cplusplus

View File

@ -143,7 +143,6 @@ anal_plugins += [
'bpf_cs',
'chip8',
'cr16',
'bpf',
'cris',
'dalvik',
'ebc',
@ -413,6 +412,7 @@ endif
parse_plugins += [
'6502_pseudo',
'bpf_pseudo',
'evm_pseudo',
'arm_pseudo',
'avr_pseudo',
'chip8_pseudo',

View File

@ -24,6 +24,7 @@ r_parse_sources = [
'parse.c',
'p/parse_6502_pseudo.c',
'p/parse_arm_pseudo.c',
'p/parse_evm_pseudo.c',
'p/parse_bpf_pseudo.c',
'p/parse_att2intel.c',
'p/parse_avr_pseudo.c',

View File

@ -0,0 +1,18 @@
OBJ_EVM_PSEUDO+=parse_evm_pseudo.o
TARGET_EVM_PSEUDO=parse_evm_pseudo.${EXT_SO}
STATIC_OBJ+=${OBJ_EVM_PSEUDO}
ifeq ($(CC),cccl)
LIBDEPS=-L../../util -llibr_util
LIBDEPS+=-L../../flag -llibr_flag
else
LIBDEPS=-L../../util -lr_util
LIBDEPS+=-L../../flag -lr_flag
endif
ifeq ($(WITHPIC),1)
ALL_TARGETS+=${TARGET_EVM_PSEUDO}
${TARGET_EVM_PSEUDO}: ${OBJ_EVM_PSEUDO}
${CC} $(call libname,parse_evm_pseudo) ${LIBDEPS} $(LDFLAGS) \
$(LDFLAGS_SHARED) ${CFLAGS} -o ${TARGET_EVM_PSEUDO} ${OBJ_EVM_PSEUDO}
endif

View File

@ -30,8 +30,8 @@ static int replace(int argc, char *argv[], char *newstr, size_t len) {
const char *op;
const char **res;
} ops[] = {
#if 0
{ "add", (const char*[]){ argv[1], " += ", argv[2], NULL } },
#if 0
{ "subn", (const char*[]){ argv[1], " = ", argv[2], " - ", argv[1], NULL } },
{ "xor", (const char*[]){ argv[1], " ^= ", argv[2], NULL } },
#endif

View File

@ -0,0 +1,101 @@
/* radare - LGPL - Copyright 2022 - pancake */
#include <r_lib.h>
#include <r_util.h>
#include <r_flag.h>
#include <r_anal.h>
#include <r_parse.h>
#define MAXARGS 4
#define BUFSIZE 64
static void concat(char *buf, size_t len, const char** args) {
const char *arg;
char *dest = buf;
int arg_len;
while ((arg = *args++)) {
if (snprintf (dest, len, "%s", arg) >= len) {
break;
}
arg_len = strlen (arg);
dest += arg_len;
len -= arg_len;
}
}
static int replace(int argc, char *argv[], char *newstr, size_t len) {
int i;
struct {
const char *op;
const char **res;
} ops[] = {
#if 0
{ "add", (const char*[]){ argv[1], " += ", argv[2], NULL } },
{ "subn", (const char*[]){ argv[1], " = ", argv[2], " - ", argv[1], NULL } },
{ "xor", (const char*[]){ argv[1], " ^= ", argv[2], NULL } },
#endif
{ NULL }
};
for (i = 0; ops[i].op; i++) {
if (!strcmp (ops[i].op, argv[0]) && newstr) {
concat (newstr, len, ops[i].res);
return true;
}
}
return false;
}
static int tokenize(const char* in, char* out[]) {
int len = strlen (in), count = 0, i = 0, tokenlen = 0, seplen = 0;
char *token, *buf = (char*) in;
const char* tokcharset = ", \t\n";
while (i < len) {
tokenlen = strcspn (buf, tokcharset);
token = calloc (tokenlen + 1, sizeof (char));
memcpy (token, buf, tokenlen);
out[count] = token;
i += tokenlen;
buf += tokenlen;
count++;
seplen = strspn (buf, tokcharset);
i += seplen;
buf += seplen;
}
return count;
}
static int parse(RParse *p, const char *data, char *str) {
int i;
char *argv[MAXARGS] = { NULL, NULL, NULL, NULL };
int argc = tokenize (data, argv);
if (!replace (argc, argv, str, BUFSIZE)) {
strcpy (str, data);
}
for (i = 0; i < MAXARGS; i++) {
free (argv[i]);
}
r_str_fixspaces (str);
return true;
}
RParsePlugin r_parse_plugin_evm_pseudo = {
.name = "evm.pseudo",
.desc = "evm pseudo syntax",
.parse = parse,
};
#ifndef R2_PLUGIN_INCORE
R_API RLibStruct radare_plugin = {
.type = R_LIB_TYPE_PARSE,
.data = &r_parse_plugin_evm_pseudo,
.version = R2_VERSION
};
#endif

View File

@ -29,6 +29,7 @@ address: 0x4
opcode: jump
esilcost: 1
disasm: jump
pseudo: jump
mnemonic: jump
mask: ff
prefix: 0

View File

@ -8,8 +8,10 @@ EXPECT=<<EOF
arm.pseudo
att2intel
avr.pseudo
bpf.pseudo
chip8.pseudo
dalvik.pseudo
evm.pseudo
m68k.pseudo
mips.pseudo
ppc.pseudo