Use RPluginMeta in RParse plugins ##refactor

This commit is contained in:
pancake 2024-11-22 18:53:01 +01:00 committed by GitHub
parent b60135be09
commit 8965dc6f16
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
27 changed files with 112 additions and 84 deletions

View File

@ -1,12 +1,6 @@
/* radare - LGPL - Copyright 2015-2021 - pancake, qnix */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* radare - LGPL - Copyright 2015-2024 - pancake, qnix */
#include <r_lib.h>
#include <r_util.h>
#include <r_flag.h>
#include <r_anal.h>
#include <r_parse.h>
@ -183,8 +177,10 @@ static int parse(RParse *p, const char *data, char *str) {
}
RParsePlugin r_parse_plugin_6502_pseudo = {
.name = "6502.pseudo",
.desc = "6502 pseudo syntax",
.meta = {
.name = "6502.pseudo",
.desc = "6502 pseudo syntax",
},
.parse = parse,
};

View File

@ -484,8 +484,10 @@ static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data
}
RParsePlugin r_parse_plugin_arm_pseudo = {
.name = "arm.pseudo",
.desc = "ARM/ARM64 pseudo syntax",
.meta = {
.name = "arm.pseudo",
.desc = "ARM/ARM64 pseudo syntax",
},
.parse = parse,
.subvar = &subvar,
};

View File

@ -209,8 +209,10 @@ static int parse(RParse *p, const char *data, char *str) {
}
RParsePlugin r_parse_plugin_avr_pseudo = {
.name = "avr.pseudo",
.desc = "AVR pseudo syntax",
.meta = {
.name = "avr.pseudo",
.desc = "AVR pseudo syntax",
},
.parse = parse
};

View File

@ -83,8 +83,10 @@ static int parse(RParse *p, const char *data, char *str) {
}
RParsePlugin r_parse_plugin_bpf_pseudo = {
.name = "bpf.pseudo",
.desc = "bpf pseudo syntax",
.meta = {
.name = "bpf.pseudo",
.desc = "bpf pseudo syntax",
},
.parse = parse,
};

View File

@ -105,8 +105,10 @@ static int parse(RParse *p, const char *data, char *str) {
}
RParsePlugin r_parse_plugin_chip8_pseudo = {
.name = "chip8.pseudo",
.desc = "chip8 pseudo syntax",
.meta = {
.name = "chip8.pseudo",
.desc = "chip8 pseudo syntax",
},
.parse = parse,
};

View File

@ -357,10 +357,10 @@ static int parse(RParse *p, const char *data, char *str) {
}
RParsePlugin r_parse_plugin_dalvik_pseudo = {
.name = "dalvik.pseudo",
.desc = "DALVIK pseudo syntax",
.init = NULL,
.fini = NULL,
.meta = {
.name = "dalvik.pseudo",
.desc = "DALVIK pseudo syntax",
},
.parse = parse,
};

View File

@ -87,8 +87,10 @@ static int parse(RParse *p, const char *data, char *str) {
}
RParsePlugin r_parse_plugin_evm_pseudo = {
.name = "evm.pseudo",
.desc = "evm pseudo syntax",
.meta = {
.name = "evm.pseudo",
.desc = "evm pseudo syntax",
},
.parse = parse,
};

View File

@ -193,8 +193,10 @@ static int parse(RParse *p, const char *data, char *str) {
}
RParsePlugin r_parse_plugin_m68k_pseudo = {
.name = "m68k.pseudo",
.desc = "M68K pseudo syntax",
.meta = {
.name = "m68k.pseudo",
.desc = "M68K pseudo syntax",
},
.parse = parse,
};

View File

@ -365,10 +365,10 @@ static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data
}
RParsePlugin r_parse_plugin_mips_pseudo = {
.name = "mips.pseudo",
.desc = "MIPS pseudo syntax",
.init = NULL,
.fini = NULL,
.meta = {
.name = "mips.pseudo",
.desc = "MIPS pseudo syntax",
},
.parse = parse,
.subvar = subvar,
};

View File

@ -3,8 +3,10 @@
#include <r_parse.h>
RParsePlugin r_parse_plugin_null_pseudo = {
.name = "null.pseudo",
.desc = "pseudo nothing",
.meta = {
.name = "null.pseudo",
.desc = "pseudo nothing",
}
};
#ifndef R2_PLUGIN_INCORE

View File

@ -1,11 +1,8 @@
/* radare - LGPL - Copyright 2024 - pancake */
#include <r_lib.h>
#include <r_flag.h>
#include <r_anal.h>
#include <r_parse.h>
static int parse(RParse *p, const char *data, char *str) {
// Intentationally left blank
// because it's not yet implemented
@ -13,8 +10,10 @@ static int parse(RParse *p, const char *data, char *str) {
}
RParsePlugin r_parse_plugin_pickle_pseudo = {
.name = "pickle.pseudo",
.desc = "Pickle pseudo syntax",
.meta = {
.name = "pickle.pseudo",
.desc = "Pickle pseudo syntax",
},
.parse = parse, // parse actually converts the string into asm.pseudo
};

View File

@ -1746,8 +1746,10 @@ static int parse(RParse *p, const char *data, char *str) {
}
RParsePlugin r_parse_plugin_ppc_pseudo = {
.name = "ppc.pseudo",
.desc = "PowerPC pseudo syntax",
.meta = {
.name = "ppc.pseudo",
.desc = "PowerPC pseudo syntax",
},
.parse = parse,
};

View File

@ -1,8 +1,6 @@
/* radare - LGPL - Copyright 2020 - Aswin C (officialcjunior) */
/* radare - LGPL - Copyright 2020-2024 - Aswin C (officialcjunior) */
#include <r_lib.h>
#include <r_flag.h>
#include <r_anal.h>
#include <r_parse.h>
static int replace(int argc, const char *argv[], char *newstr) {
@ -217,8 +215,10 @@ static int parse(RParse *p, const char *data, char *str) {
}
RParsePlugin r_parse_plugin_riscv_pseudo = {
.name = "riscv.pseudo",
.desc = "riscv pseudo syntax",
.meta = {
.name = "riscv.pseudo",
.desc = "riscv pseudo syntax",
},
.parse = parse,
};

View File

@ -265,8 +265,10 @@ static int parse(RParse *p, const char *data, char *str) {
}
RParsePlugin r_parse_plugin_sh_pseudo = {
.name = "sh.pseudo",
.desc = "SH-4 pseudo syntax",
.meta = {
.name = "sh.pseudo",
.desc = "SH-4 pseudo syntax",
},
.parse = parse
};

View File

@ -224,8 +224,10 @@ static int parse(RParse *p, const char *data, char *str) {
}
RParsePlugin r_parse_plugin_stm8_pseudo = {
.name = "stm8.pseudo",
.desc = "STM8 pseudo syntax",
.meta = {
.name = "stm8.pseudo",
.desc = "STM8 pseudo syntax",
},
.parse = parse,
};

View File

@ -175,8 +175,10 @@ static int parse(RParse *p, const char *data, char *str) {
}
RParsePlugin r_parse_plugin_tms320_pseudo = {
.name = "tms320.pseudo",
.desc = "tms320 pseudo syntax",
.meta = {
.name = "tms320.pseudo",
.desc = "tms320 pseudo syntax",
},
.parse = parse,
};

View File

@ -462,8 +462,10 @@ static int fini(RParse *p, void *usr) {
}
RParsePlugin r_parse_plugin_tricore_pseudo = {
.name = "tricore.pseudo",
.desc = "TriCore pseudo syntax",
.meta = {
.name = "tricore.pseudo",
.desc = "TriCore pseudo syntax",
},
.parse = &parse,
.subvar = &subvar,
.fini = &fini,

View File

@ -221,8 +221,10 @@ static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data
}
RParsePlugin r_parse_plugin_v850_pseudo = {
.name = "v850.pseudo",
.desc = "v850 pseudo syntax",
.meta = {
.name = "v850.pseudo",
.desc = "v850 pseudo syntax",
},
.parse = parse,
.subvar = &subvar,
};

View File

@ -1,8 +1,5 @@
/* radare - LGPL - Copyright 2019 - deroad */
/* radare - LGPL - Copyright 2019-2024 - deroad */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <r_lib.h>
#include <r_util.h>
#include <r_flag.h>
@ -30,8 +27,10 @@ static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data
}
RParsePlugin r_parse_plugin_wasm_pseudo = {
.name = "wasm.pseudo",
.desc = "WASM pseudo syntax",
.meta = {
.name = "wasm.pseudo",
.desc = "WASM pseudo syntax",
},
.subvar = &subvar,
};

View File

@ -165,8 +165,10 @@ static int parse(RParse *p, const char *data, char *str) {
}
RParsePlugin r_parse_plugin_att2intel = {
.name = "att2intel",
.desc = "X86 att 2 intel plugin",
.meta = {
.name = "att2intel",
.desc = "X86 att 2 intel plugin",
},
.parse = &parse,
};

View File

@ -574,8 +574,10 @@ static int fini(RParse *p, void *usr) {
}
RParsePlugin r_parse_plugin_x86_pseudo = {
.name = "x86.pseudo",
.desc = "X86 pseudo syntax",
.meta = {
.name = "x86.pseudo",
.desc = "X86 pseudo syntax",
},
.parse = &parse,
.subvar = &subvar,
.fini = &fini,

View File

@ -80,14 +80,18 @@ static int parse(RParse *p, const char *data, char *str) {
#if Z80_IS_GB
RParsePlugin r_parse_plugin_gb_pseudo = {
.name = "gb.pseudo",
.desc = "GameBoy pseudo syntax",
.meta = {
.name = "gb.pseudo",
.desc = "GameBoy pseudo syntax",
},
.parse = parse, // parse actually converts the string into asm.pseudo
};
#else
RParsePlugin r_parse_plugin_z80_pseudo = {
.name = "z80.pseudo",
.desc = "Z80 pseudo syntax",
.meta = {
.name = "z80.pseudo",
.desc = "Z80 pseudo syntax",
},
.parse = parse, // parse actually converts the string into asm.pseudo
};
#endif

View File

@ -1,4 +1,4 @@
/* radare2 - LGPL - Copyright 2009-2023 - nibble, pancake, maijin */
/* radare2 - LGPL - Copyright 2009-2024 - nibble, pancake, maijin */
#include <r_parse.h>
@ -14,10 +14,11 @@ static bool isvalidflag(RFlagItem *flag) {
return false;
}
}
if (strstr (flag->name, "main") || strstr (flag->name, "entry")) {
const char *flag_name = flag->name;
if (strstr (flag_name, "main") || strstr (flag_name, "entry")) {
return true;
}
if (strchr (flag->name, '.')) {
if (strchr (flag_name, '.')) {
return true;
}
}
@ -148,7 +149,7 @@ static bool filter(RParse *p, ut64 addr, RFlag *f, RAnalHint *hint, char *data,
const int seggrn = p->analb.anal->config->seggrn;
bool x86 = false;
bool arm = false;
const char *pname = (p && p->cur && p->cur->name) ? p->cur->name: NULL;
const char *pname = R_UNWRAP3 (p, cur, meta.name);
if (pname) {
if (r_str_startswith (pname, "x86")) {
x86 = true;
@ -596,7 +597,7 @@ R_API bool r_parse_filter(RParse *p, ut64 addr, RFlag *f, RAnalHint *hint, char
// r_asm_subvar()
// r_asm_replace()
// R2_590 - easier to use, should replace r_asm_filter(), but its not using rflag, analhint, endian, etc
// R2_600 - easier to use, should replace r_asm_filter(), but its not using rflag, analhint, endian, etc
// this function is unused, but there's data we are missing, like the analhint.. that we must ensure that is called before calling this. so we need more tests for this.
R_API char *r_parse_filter_dup(RParse *p, ut64 addr, const char *opstr) {
const size_t out_len = 256;

View File

@ -111,7 +111,7 @@ R_API bool r_parse_use(RParse *p, const char *name) {
RListIter *iter;
RParsePlugin *h;
r_list_foreach (p->parsers, iter, h) {
if (!strcmp (h->name, name)) {
if (!strcmp (h->meta.name, name)) {
p->cur = h;
return true;
}
@ -120,7 +120,7 @@ R_API bool r_parse_use(RParse *p, const char *name) {
if (strchr (name, '.')) {
char *sname = predotname (name);
r_list_foreach (p->parsers, iter, h) {
char *shname = predotname (h->name);
char *shname = predotname (h->meta.name);
found = !strcmp (shname, sname);
free (shname);
if (found) {
@ -132,14 +132,14 @@ R_API bool r_parse_use(RParse *p, const char *name) {
}
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")) {
if (p->cur && p->cur->meta.name) {
if (r_str_startswith (p->cur->meta.name, "null")) {
return false;
}
}
// check if p->cur
r_list_foreach (p->parsers, iter, h) {
if (r_str_startswith (h->name, "null")) {
if (r_str_startswith (h->meta.name, "null")) {
R_LOG_INFO ("Fallback to null");
// R_LOG_INFO ("Fallback to null from %s", p->cur->name);
p->cur = h;

View File

@ -1048,7 +1048,7 @@ static void update_asmparser_options(RCore *core, RConfigNode *node) {
if (core && node && core->parser && core->parser->parsers) {
r_config_node_purge_options (node);
r_list_foreach (core->parser->parsers, iter, parser) {
SETOPTIONS (node, parser->name, NULL);
SETOPTIONS (node, parser->meta.name, NULL);
}
}
}

View File

@ -40,10 +40,9 @@ typedef struct r_parse_t {
RAnalLabelAt label_get;
} RParse; // TODO rename to RAsmParseState
// TODO Rename to asm plugins?
typedef struct r_parse_plugin_t {
// TODO R2_600 Use RPluginMeta instead
char *name;
char *desc;
RPluginMeta meta;
bool (*init)(RParse *p, void *user); // returns an RAsmParseState*
int (*fini)(RParse *p, void *user); // receives the asmparsestate

View File

@ -110,8 +110,8 @@ static JSValue r2plugin_parse_load(JSContext *ctx, JSValueConst this_val, int ar
};
memcpy ((void*)&ap->meta, &meta, sizeof (RPluginMeta));
#else
ap->name = strdup (nameptr);
ap->desc = descptr ? strdup (descptr) : NULL;
ap->meta.name = strdup (nameptr);
ap->meta.desc = descptr ? strdup (descptr) : NULL;
// ap->license = strdup (licenseptr);
#endif
@ -129,6 +129,6 @@ static JSValue r2plugin_parse_load(JSContext *ctx, JSValueConst this_val, int ar
lib->type = R_LIB_TYPE_PARSE;
lib->data = ap;
lib->version = R2_VERSION;
int ret = r_lib_open_ptr (pm->core->lib, ap->name, NULL, lib);
int ret = r_lib_open_ptr (pm->core->lib, ap->meta.name, NULL, lib);
return JS_NewBool (ctx, ret == 1);
}