Add asm.parser.null.pseudo plugin ##arch

This commit is contained in:
pancake 2024-08-26 09:08:11 +02:00 committed by GitHub
parent 4adde5fa53
commit 2c718ab8a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
32 changed files with 155 additions and 88 deletions

View File

@ -88,6 +88,7 @@ io.r2web
io.r2pipe
io.zip
lang.vala
parse.null_pseudo
parse.att2intel
parse.mips_pseudo
parse.dalvik_pseudo

View File

@ -104,6 +104,7 @@ io.sparse
io.w32
io.w32dbg
io.zip
parse.null_pseudo
parse.6502_pseudo
parse.att2intel
parse.dalvik_pseudo

View File

@ -257,6 +257,7 @@ lang.spp
lang.v
lang.vala
lang.zig
parse.null_pseudo
parse.6502_pseudo
parse.arm_pseudo
parse.att2intel

View File

@ -298,5 +298,6 @@ parse.v850_pseudo
parse.wasm_pseudo
parse.x86_pseudo
parse.z80_pseudo
parse.null_pseudo
"
SHARED="io.shm"

View File

@ -82,6 +82,7 @@ io.w32
io.w32dbg
io.shm
io.zip
parse.null_pseudo
parse.6502_pseudo
parse.att2intel
parse.dalvik_pseudo

View File

@ -72,6 +72,7 @@ io.ihex
io.procpid
io.zip
lang.vala
parse.null_pseudo
parse.att2intel
parse.mips_pseudo
parse.dalvik_pseudo

View File

@ -83,6 +83,7 @@ io.r2pipe
io.zip
lang.vala
parse.att2intel
parse.null_pseudo
parse.mips_pseudo
parse.dalvik_pseudo
parse.x86_pseudo"

View File

@ -232,6 +232,7 @@ lang.spp
lang.vala
lang.pipe
lang.cpipe
parse.null_pseudo
parse.6502_pseudo
parse.tms320_pseudo
parse.v850_pseudo

View File

@ -220,6 +220,7 @@ lang.spp
lang.vala
lang.pipe
lang.cpipe
parse.null_pseudo
parse.6502_pseudo
parse.tms320_pseudo
parse.v850_pseudo

View File

@ -100,6 +100,7 @@ io.w32dbg
io.winkd
io.zip
lang.vala
parse.null_pseudo
parse.6502_pseudo
parse.arm_pseudo
parse.tms320_pseudo

View File

@ -192,6 +192,7 @@ io.r2k
io.ar
io.rbuf
lang.vala
parse.null_pseudo
parse.6502_pseudo
parse.arm_pseudo
parse.att2intel

View File

@ -159,6 +159,7 @@ io.r2k
io.ar
io.rbuf
lang.vala
parse.null_pseudo
parse.6502_pseudo
parse.arm_pseudo
parse.att2intel

View File

@ -214,6 +214,7 @@ lang.spp
lang.vala
lang.pipe
lang.cpipe
parse.null_pseudo
parse.6502_pseudo
parse.tms320_pseudo
parse.v850_pseudo

View File

@ -79,6 +79,7 @@ io.ptrace
io.procpid
io.zip
lang.vala
parse.null_pseudo
parse.att2intel
parse.mips_pseudo
parse.dalvik_pseudo

View File

@ -34,6 +34,7 @@ io.sparse
io.ihex
io.procpid
lang.vala
parse.null_pseudo
parse.att2intel
parse.x86_pseudo"
SHARED=""

View File

@ -67,6 +67,7 @@ io.http
io.tcpslurp
io.null
io.default
parse.null_pseudo
parse.arm_pseudo
parse.att2intel
parse.wasm_pseudo

View File

@ -1,9 +1,5 @@
/* radare - LGPL - Copyright 2015-2024 - pancake */
#include <r_lib.h>
#include <r_util.h>
#include <r_flag.h>
#include <r_anal.h>
#include <r_parse.h>
static int replace(int argc, const char *argv[], char *newstr) {

View File

@ -1,13 +1,5 @@
/* radare - LGPL - Copyright 2017-2019 - wargio */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <r_lib.h>
#include <r_util.h>
#include <r_flag.h>
#include <r_anal.h>
#include <r_parse.h>
static bool replace(int argc, const char *argv[], char *newstr) {

16
libr/arch/p/null/pseudo.c Normal file
View File

@ -0,0 +1,16 @@
/* radare - LGPL - Copyright 2024 - pancake */
#include <r_parse.h>
RParsePlugin r_parse_plugin_null_pseudo = {
.name = "null.pseudo",
.desc = "pseudo nothing",
};
#ifndef R2_PLUGIN_INCORE
R_API RLibStruct radare_plugin = {
.type = R_LIB_TYPE_PARSE,
.data = &r_parse_plugin_null_pseudo,
.version = R2_VERSION
};
#endif

View File

@ -34,6 +34,7 @@ static int replace(int argc, const char *argv[], char *newstr) {
{ 0, "srlw", "# >>= 1", { 1 } },
{ 0, "sraw", "# >>= 1", { 1 } },
{ 0, "add", "# += #", { 1, 2 } },
{ 0, "ret", "return", { 1, 2 } },
{ 0, NULL }
};
if (!newstr) {

View File

@ -1,12 +1,5 @@
/* radare - LGPL - Copyright 2009-2024 - nibble, pancake */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <r_lib.h>
#include <r_util.h>
#include <r_anal.h>
#include <r_parse.h>
// 16 bit examples
// 0x0001f3a4 9a67620eca call word 0xca0e:0x6267

View File

@ -7,6 +7,7 @@ r_asm_sources = [
'parse.c',
'filter.c',
'agperf.c',
'../arch/p/null/pseudo.c',
'../arch/p/pseudo/z80_pseudo.c',
'../arch/p/pseudo/wasm_pseudo.c',
'../arch/p/pseudo/v850_pseudo.c',

View File

@ -1,4 +1,4 @@
OBJ_AVRPSEUDO+=$(LIBR)/arch/p/pseudo/avr_pseudo.o
OBJ_AVRPSEUDO+=$(LIBR)/arch/p/avr/pseudo.o
TARGET_AVRPSEUDO=parse_avr_pseudo.${EXT_SO}
ALL_TARGETS+=${TARGET_AVRPSEUDO}

View File

@ -0,0 +1,4 @@
OBJ_NULLPSEUDO+=$(LIBR)/arch/p/null/pseudo.o
TARGET_NULLPSEUDO=parse_null_pseudo.${EXT_SO}
STATIC_OBJ+=${OBJ_NULLPSEUDO}

View File

@ -1,4 +1,4 @@
/* radare2 - LGPL - Copyright 2009-2022 - nibble, pancake, maijin */
/* radare2 - LGPL - Copyright 2009-2024 - nibble, pancake, maijin */
#include <r_parse.h>
#include <config.h>
@ -96,11 +96,19 @@ static char *predotname(const char *name) {
R_API bool r_parse_use(RParse *p, const char *name) {
R_RETURN_VAL_IF_FAIL (p && name, false);
if (r_str_startswith (name, "r2ghidra")) {
// This plugin uses asm.cpu as a hack, ignoring
return false;
}
// TODO: remove the alias workarounds because of missing pseudo plugins
// TODO: maybe we want to have a generic pseudo parser?
if (r_str_startswith (name, "s390.")) {
name = "x86.pseudo";
}
#if 0
if (r_str_startswith (name, "blackfin")) {
name = "arm.pseudo";
}
#endif
RListIter *iter;
RParsePlugin *h;
@ -110,55 +118,39 @@ R_API bool r_parse_use(RParse *p, const char *name) {
return true;
}
}
char *sname = predotname (name);
bool found = false;
r_list_foreach (p->parsers, iter, h) {
char *shname = predotname (h->name);
found = !strcmp (shname, sname);
free (shname);
if (found) {
p->cur = h;
break;
}
}
free (sname);
return false;
}
#if 0
// this function is a bit confussing, assembles C code into wat?, whehres theh input and wheres the output
// and its unused. so imho it sshould be DEPRECATED this conflicts with rasm.assemble imhoh
R_API bool r_parse_assemble(RParse *p, char *data, char *str) {
R_RETURN_VAL_IF_FAIL (p && data && str, false);
char *in = strdup (str);
bool ret = false;
char *s, *o;
data[0] = '\0';
if (p->cur && p->cur->assemble) {
o = data + strlen (data);
do {
s = strchr (str, ';');
if (s) {
*s = '\0';
}
ret = p->cur->assemble (p, o, str);
if (!ret) {
if (strchr (name, '.')) {
char *sname = predotname (name);
r_list_foreach (p->parsers, iter, h) {
char *shname = predotname (h->name);
found = !strcmp (shname, sname);
free (shname);
if (found) {
p->cur = h;
break;
}
if (s) {
str = s + 1;
o += strlen (data);
o[0] = '\n';
o[1] = '\0';
o++;
}
} while (s);
}
free (sname);
}
free (in);
return ret;
if (!found) {
R_LOG_WARN ("Cannot find asm.parser for %s", name);
if (p->cur && p->cur->name) {
if (r_str_startswith (p->cur->name, "null")) {
return false;
}
}
// check if p->cur
r_list_foreach (p->parsers, iter, h) {
if (r_str_startswith (h->name, "null")) {
R_LOG_INFO ("Fallback to null");
// R_LOG_INFO ("Fallback to null from %s", p->cur->name);
p->cur = h;
return false;
}
}
}
return false;
}
#endif
// data is input disasm, str is output pseudo
// TODO: refactoring, this should return char * instead
@ -176,14 +168,18 @@ R_API char *r_parse_instruction(RParse *p, const char *data) {
return NULL;
}
R_API bool r_parse_parse(RParse *p, const char *data, char *str) { // TODO deprecate. in R2_590 because r_parse_instruction is better
// TODO deprecate in R2_600 because r_parse_instruction is better
R_API bool r_parse_parse(RParse *p, const char *data, char *str) {
R_RETURN_VAL_IF_FAIL (p && data && str, false);
return (p && data && *data && p->cur && p->cur->parse)
? p->cur->parse (p, data, str) : false;
if (*data && p->cur && p->cur->parse) {
return p->cur->parse (p, data, str);
}
// causes pdc to be empty, we need that parser to be doing sthg
return false;
}
// R_API char *r_parse_immtrim(const char *_opstr)
R_API char *r_parse_immtrim(char *_opstr) {
// R_API char *r_parse_immtrim(const char *_opstr) {
if (R_STR_ISEMPTY (_opstr)) {
return NULL;
}

View File

@ -2012,7 +2012,7 @@ static void cmd_print_format(RCore *core, const char *_input, const ut8* block,
if (home) {
files = r_sys_dir (home);
r_list_foreach (files, iter, fn) {
if (*fn && *fn != '.') {
if (*fn != '.') {
r_cons_println (fn);
}
}
@ -2023,7 +2023,7 @@ static void cmd_print_format(RCore *core, const char *_input, const ut8* block,
if (path) {
files = r_sys_dir (path);
r_list_foreach (files, iter, fn) {
if (*fn && *fn != '.') {
if (*fn != '.') {
r_cons_println (fn);
}
}
@ -5075,7 +5075,6 @@ static void disasm_until_optype(RCore *core, ut64 addr, char type_print, int opt
char *mnem = op->mnemonic;
char *m = malloc ((strlen (mnem) * 2) + 32);
strcpy (m, mnem);
//r_parse_parse (core->parser, op->mnemonic, m);
if (type_print == 'q') {
r_cons_printf ("%s\n", m);
} else {

View File

@ -1203,9 +1203,10 @@ static void ds_build_op_str(RDisasmState *ds, bool print_color) {
}
}
if (ds->pseudo) {
r_parse_parse (core->parser, ds->opstr, ds->str);
free (ds->opstr);
ds->opstr = strdup (ds->str);
if (r_parse_parse (core->parser, ds->opstr, ds->str)) {
free (ds->opstr);
ds->opstr = strdup (ds->str);
}
}
if (ds->subjmp) {
char *input = strdup (ds->opstr? ds->opstr: ds->str);

View File

@ -96,6 +96,7 @@ extern RParsePlugin r_parse_plugin_v850_pseudo;
extern RParsePlugin r_parse_plugin_bpf_pseudo;
extern RParsePlugin r_parse_plugin_stm8_pseudo;
extern RParsePlugin r_parse_plugin_evm_pseudo;
extern RParsePlugin r_parse_plugin_null_pseudo;
#endif
#ifdef __cplusplus

View File

@ -409,7 +409,6 @@ EXPECT=<<EOF
{
"opcode": "adc 0xed",
"disasm": "adc 0xed",
"pseudo": "0xed +=",
"description": "add with carry register pair",
"srcs": [
{

View File

@ -14,6 +14,7 @@ dalvik.pseudo
evm.pseudo
m68k.pseudo
mips.pseudo
null.pseudo
ppc.pseudo
riscv.pseudo
sh.pseudo

View File

@ -26,7 +26,11 @@ bp = 0x00000000
a0 0x00000000 a1 0x00000000 a2 0x00000000 a3 0x00000000
r0 0x00000000 sp 0x00000000 pc 0x00000000 bp 0x00000000
EOF
EXPECT_ERR=
EXPECT_ERR=<<EOF
WARN: Cannot find asm.parser for pyc.pseudo
INFO: Fallback to null
WARN: Cannot find asm.parser for pyc.pseudo
EOF
RUN
NAME=pyc load version38
@ -37,7 +41,11 @@ EOF
EXPECT=<<EOF
machine Python v3.8.0 VM (rev 5d714034866ce1e9f89dc141fe4cc0b50cf20a8e)
EOF
EXPECT_ERR=
EXPECT_ERR=<<EOF
WARN: Cannot find asm.parser for pyc.pseudo
INFO: Fallback to null
WARN: Cannot find asm.parser for pyc.pseudo
EOF
RUN
NAME=pyc load version37
@ -48,7 +56,11 @@ EOF
EXPECT=<<EOF
machine Python v3.7.0 VM (rev ae1f6af15f3e4110616801e235873e47fd7d1977)
EOF
EXPECT_ERR=
EXPECT_ERR=<<EOF
WARN: Cannot find asm.parser for pyc.pseudo
INFO: Fallback to null
WARN: Cannot find asm.parser for pyc.pseudo
EOF
RUN
NAME=pyc load version36
@ -59,7 +71,11 @@ EOF
EXPECT=<<EOF
machine Python v3.6.0 VM (rev 5c4568a05a0a62b5947c55f68f9f2ecfb90a4f12)
EOF
EXPECT_ERR=
EXPECT_ERR=<<EOF
WARN: Cannot find asm.parser for pyc.pseudo
INFO: Fallback to null
WARN: Cannot find asm.parser for pyc.pseudo
EOF
RUN
NAME=pyc load version27
@ -70,7 +86,11 @@ EOF
EXPECT=<<EOF
machine Python 2.7a2 VM (rev edfed0e32cedf3b84c6e999052486a750a3f5bee)
EOF
EXPECT_ERR=
EXPECT_ERR=<<EOF
WARN: Cannot find asm.parser for pyc.pseudo
INFO: Fallback to null
WARN: Cannot find asm.parser for pyc.pseudo
EOF
RUN
NAME=pyc symbols
@ -81,7 +101,11 @@ EOF
EXPECT=<<EOF
9
EOF
EXPECT_ERR=
EXPECT_ERR=<<EOF
WARN: Cannot find asm.parser for pyc.pseudo
INFO: Fallback to null
WARN: Cannot find asm.parser for pyc.pseudo
EOF
RUN
NAME=pyc sections
@ -98,7 +122,11 @@ EXPECT=<<EOF
35 0x00002143 0x44 0x00002143 0x44 ---- ---- <module>.Batman.__init__
36 0x00002235 0x4 0x00002235 0x4 ---- ---- <module>.Batman.sing
EOF
EXPECT_ERR=
EXPECT_ERR=<<EOF
WARN: Cannot find asm.parser for pyc.pseudo
INFO: Fallback to null
WARN: Cannot find asm.parser for pyc.pseudo
EOF
RUN
NAME=pyc entry
@ -109,7 +137,11 @@ EOF
EXPECT=<<EOF
vaddr=0x0000002a paddr=0x0000002a haddr=-1 type=program
EOF
EXPECT_ERR=
EXPECT_ERR=<<EOF
WARN: Cannot find asm.parser for pyc.pseudo
INFO: Fallback to null
WARN: Cannot find asm.parser for pyc.pseudo
EOF
RUN
NAME=pyc disasm
@ -134,7 +166,11 @@ EXPECT=<<EOF
| 0x0000003a 6401 load_const True
`-> 0x0000003c 0100 pop_top
EOF
EXPECT_ERR=
EXPECT_ERR=<<EOF
WARN: Cannot find asm.parser for pyc.pseudo
INFO: Fallback to null
WARN: Cannot find asm.parser for pyc.pseudo
EOF
RUN
NAME=pyc symbols for pyc2.7
@ -145,7 +181,11 @@ EOF
EXPECT=<<EOF
1 0x00000052 0x00000052 NONE FUNC 9 <module>.hello_world
EOF
EXPECT_ERR=
EXPECT_ERR=<<EOF
WARN: Cannot find asm.parser for pyc.pseudo
INFO: Fallback to null
WARN: Cannot find asm.parser for pyc.pseudo
EOF
RUN
NAME=pyc disasm for 2.7
@ -168,7 +208,11 @@ EXPECT=<<EOF
0x00000032 01 pop_top
0x00000033 640200 load_const None
EOF
EXPECT_ERR=
EXPECT_ERR=<<EOF
WARN: Cannot find asm.parser for pyc.pseudo
INFO: Fallback to null
WARN: Cannot find asm.parser for pyc.pseudo
EOF
RUN
NAME=pyc function
@ -194,6 +238,9 @@ EXPECT=<<EOF
\ 0x00000036 53 return_value
EOF
EXPECT_ERR=<<EOF
WARN: Cannot find asm.parser for pyc.pseudo
INFO: Fallback to null
WARN: Cannot find asm.parser for pyc.pseudo
WARN: select the calling convention with `e anal.cc=?`
EOF
RUN

View File

@ -5,7 +5,11 @@ EXPECT=<<EOF
Reassembling 8051... OK
EOF
EXPECT_ERR=<<EOF
ERROR: r2pm -ci decai
WARN: Cannot find asm.parser for 8051.pseudo
INFO: Fallback to null
WARN: using oba to load the syminfo from different mapaddress
WARN: Cannot find asm.parser for 8051.pseudo
EOF
RUN