mirror of
https://github.com/radareorg/radare2.git
synced 2024-10-07 02:23:58 +00:00
Add chip8 pseudo support ##disasm
This commit is contained in:
parent
ebc1ccabc8
commit
c5d09f32e8
@ -74,6 +74,7 @@ extern RParsePlugin r_parse_plugin_6502_pseudo;
|
||||
extern RParsePlugin r_parse_plugin_arm_pseudo;
|
||||
extern RParsePlugin r_parse_plugin_att2intel;
|
||||
extern RParsePlugin r_parse_plugin_avr_pseudo;
|
||||
extern RParsePlugin r_parse_plugin_chip8_pseudo;
|
||||
extern RParsePlugin r_parse_plugin_dalvik_pseudo;
|
||||
extern RParsePlugin r_parse_plugin_dummy;
|
||||
extern RParsePlugin r_parse_plugin_m68k_pseudo;
|
||||
|
@ -300,6 +300,7 @@ parse_plugins = [
|
||||
'arm_pseudo',
|
||||
'att2intel',
|
||||
'avr_pseudo',
|
||||
'chip8_pseudo',
|
||||
'dalvik_pseudo',
|
||||
'm68k_pseudo',
|
||||
'mips_pseudo',
|
||||
|
@ -5,6 +5,7 @@ r_parse_sources = [
|
||||
'p/parse_arm_pseudo.c',
|
||||
'p/parse_att2intel.c',
|
||||
'p/parse_avr_pseudo.c',
|
||||
'p/parse_chip8_pseudo.c',
|
||||
'p/parse_dalvik_pseudo.c',
|
||||
'p/parse_m68k_pseudo.c',
|
||||
'p/parse_mips_pseudo.c',
|
||||
|
@ -11,7 +11,7 @@ ifeq ($(WITHPIC),1)
|
||||
all: ${ALL_TARGETS}
|
||||
|
||||
ALL_TARGETS=
|
||||
ARCHS=att2intel.mk x86_pseudo.mk mreplace.mk
|
||||
ARCHS=att2intel.mk x86_pseudo.mk mreplace.mk chip8_pseudo.mk
|
||||
ARCHS+=arm_pseudo.mk z80_pseudo.mk ppc_pseudo.mk 6502_pseudo.mk
|
||||
ARCHS+=m68k_pseudo.mk sh_pseudo.mk avr_pseudo.mk wasm_pseudo.mk
|
||||
include $(ARCHS)
|
||||
|
18
libr/parse/p/chip8_pseudo.mk
Normal file
18
libr/parse/p/chip8_pseudo.mk
Normal file
@ -0,0 +1,18 @@
|
||||
OBJ_CHIP8PSEUDO+=parse_chip8_pseudo.o
|
||||
|
||||
TARGET_CHIP8PSEUDO=parse_chip8_pseudo.${EXT_SO}
|
||||
STATIC_OBJ+=${OBJ_CHIP8PSEUDO}
|
||||
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_CHIP8PSEUDO}
|
||||
${TARGET_CHIP8PSEUDO}: ${OBJ_CHIP8PSEUDO}
|
||||
${CC} $(call libname,parse_chip8_pseudo) ${LIBDEPS} $(LDFLAGS) \
|
||||
$(LDFLAGS_SHARED) ${CFLAGS} -o ${TARGET_CHIP8PSEUDO} ${OBJ_CHIP8PSEUDO}
|
||||
endif
|
118
libr/parse/p/parse_chip8_pseudo.c
Normal file
118
libr/parse/p/parse_chip8_pseudo.c
Normal file
@ -0,0 +1,118 @@
|
||||
/* radare - LGPL - Copyright 2019 - Vasilij Schneidermann <mail@vasilij.de> */
|
||||
|
||||
#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, char** args) {
|
||||
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 {
|
||||
char *op;
|
||||
char **res;
|
||||
} ops[] = {
|
||||
{ "add", (char*[]){ argv[1], " += ", argv[2], NULL } },
|
||||
{ "and", (char*[]){ argv[1], " &= ", argv[2], NULL } },
|
||||
{ "cls", (char*[]){ "clear_screen()", NULL } },
|
||||
{ "drw", (char*[]){ "draw(", argv[1], ", ", argv[2], ", ", argv[3], ")", NULL } },
|
||||
{ "exit", (char*[]){ "exit()", NULL } },
|
||||
{ "high", (char*[]){ "high_res()", NULL } },
|
||||
{ "jp", (char*[]){ "goto ", argv[1], NULL } },
|
||||
{ "ld", (char*[]){ argv[1], " = ", argv[2], NULL } },
|
||||
{ "low", (char*[]){ "low_res()", NULL } },
|
||||
{ "or", (char*[]){ argv[1], " |= ", argv[2], NULL } },
|
||||
{ "rnd", (char*[]){ argv[1], " = random(256) & ", argv[2], NULL } },
|
||||
{ "scd", (char*[]){ "scroll_down(", argv[1], ")", NULL } },
|
||||
{ "scl", (char*[]){ "scroll_left()", NULL } },
|
||||
{ "scr", (char*[]){ "scroll_right()", NULL } },
|
||||
{ "se", (char*[]){ "skip_next_instr if ", argv[1], " == ", argv[2], NULL } },
|
||||
{ "shl", (char*[]){ argv[1], " <<= 1", NULL } },
|
||||
{ "shr", (char*[]){ argv[1], " >>= 1", NULL } },
|
||||
{ "sknp", (char*[]){ "skip_next_instr if !key_pressed(", argv[1], ")", NULL } },
|
||||
{ "skp", (char*[]){ "skip_next_instr if key_pressed(", argv[1], "))", NULL } },
|
||||
{ "sne", (char*[]){ "skip_next_instr if ", argv[1], " != ", argv[2], NULL } },
|
||||
{ "sub", (char*[]){ argv[1], " -= ", argv[2], NULL } },
|
||||
{ "subn", (char*[]){ argv[1], " = ", argv[1], " - ", argv[2], NULL } },
|
||||
{ "xor", (char*[]){ argv[1], " ^= ", argv[2], NULL } },
|
||||
{ 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;
|
||||
|
||||
while (i < len) {
|
||||
tokenlen = strcspn (buf, ", ");
|
||||
token = calloc (tokenlen + 1, sizeof(char));
|
||||
memcpy (token, buf, tokenlen);
|
||||
out[count] = token;
|
||||
i += tokenlen;
|
||||
buf += tokenlen;
|
||||
count++;
|
||||
|
||||
seplen = strspn (buf, ", ");
|
||||
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]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
RParsePlugin r_parse_plugin_chip8_pseudo = {
|
||||
.name = "chip8.pseudo",
|
||||
.desc = "chip8 pseudo syntax",
|
||||
.parse = parse,
|
||||
};
|
||||
|
||||
#ifndef CORELIB
|
||||
R_API RLibStruct radare_plugin = {
|
||||
.type = R_LIB_TYPE_PARSE,
|
||||
.data = &r_parse_plugin_chip8_pseudo,
|
||||
.version = R2_VERSION
|
||||
};
|
||||
#endif
|
@ -250,6 +250,7 @@ lang.vala
|
||||
parse.6502_pseudo
|
||||
parse.arm_pseudo
|
||||
parse.att2intel
|
||||
parse.chip8_pseudo
|
||||
parse.dalvik_pseudo
|
||||
parse.m68k_pseudo
|
||||
parse.mips_pseudo
|
||||
|
@ -213,6 +213,7 @@ parse.6502_pseudo
|
||||
parse.arm_pseudo
|
||||
parse.att2intel
|
||||
parse.avr_pseudo
|
||||
parse.chip8_pseudo
|
||||
parse.dalvik_pseudo
|
||||
parse.m68k_pseudo
|
||||
parse.mips_pseudo
|
||||
|
Loading…
Reference in New Issue
Block a user