Skip to content

Commit

Permalink
Store plugin's by name rather than path. Relates to #22445
Browse files Browse the repository at this point in the history
- Make parse/bp plugins use RPluginMeta
- Print plugin path with Lcj
- Use plugin name as opposed to the filename to detect if a plugin has
  already been loaded.
- Refactor r_lib_close and allow L- (remove plugin) to work with name
in addition to file names
  • Loading branch information
MewtR committed Oct 20, 2024
1 parent 6e7be05 commit cd02b7f
Show file tree
Hide file tree
Showing 42 changed files with 284 additions and 140 deletions.
8 changes: 6 additions & 2 deletions libr/arch/p/6502/pseudo.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,12 @@ 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",
.author = "pancake",
.license = "LGPL-3.0-only",
},
.parse = parse,
};

Expand Down
8 changes: 6 additions & 2 deletions libr/arch/p/arm/pseudo.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,12 @@ 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",
.author = "pancake",
.license = "LGPL-3.0-only",
},
.parse = parse,
.subvar = &subvar,
};
Expand Down
8 changes: 6 additions & 2 deletions libr/arch/p/avr/pseudo.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,12 @@ 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",
.author = "pancake",
.license = "LGPL-3.0-only",
},
.parse = parse
};

Expand Down
8 changes: 6 additions & 2 deletions libr/arch/p/bpf/pseudo.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,12 @@ 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",
.author = "pancake",
.license = "LGPL-3.0-only",
},
.parse = parse,
};

Expand Down
8 changes: 6 additions & 2 deletions libr/arch/p/chip8/pseudo.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,12 @@ 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",
.author = "pancake",
.license = "LGPL-3.0-only",
},
.parse = parse,
};

Expand Down
8 changes: 6 additions & 2 deletions libr/arch/p/dalvik/pseudo.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,12 @@ static int parse(RParse *p, const char *data, char *str) {
}

RParsePlugin r_parse_plugin_dalvik_pseudo = {
.name = "dalvik.pseudo",
.desc = "DALVIK pseudo syntax",
.meta = {
.name = "dalvik.pseudo",
.desc = "DALVIK pseudo syntax",
.author = "pancake",
.license = "LGPL-3.0-only",
},
.init = NULL,
.fini = NULL,
.parse = parse,
Expand Down
8 changes: 6 additions & 2 deletions libr/arch/p/evm/pseudo.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,12 @@ 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",
.author = "pancake",
.license = "LGPL-3.0-only",
},
.parse = parse,
};

Expand Down
8 changes: 6 additions & 2 deletions libr/arch/p/m68k_cs/pseudo.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,12 @@ 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",
.author = "pancake",
.license = "LGPL-3.0-only",
},
.parse = parse,
};

Expand Down
8 changes: 6 additions & 2 deletions libr/arch/p/mips/pseudo.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,12 @@ 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",
.meta = {
.name = "mips.pseudo",
.desc = "MIPS pseudo syntax",
.author = "pancake",
.license = "LGPL-3.0-only",
},
.init = NULL,
.fini = NULL,
.parse = parse,
Expand Down
8 changes: 6 additions & 2 deletions libr/arch/p/null/pseudo.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
#include <r_parse.h>

RParsePlugin r_parse_plugin_null_pseudo = {
.name = "null.pseudo",
.desc = "pseudo nothing",
.meta = {
.name = "null.pseudo",
.desc = "pseudo nothing",
.author = "pancake",
.license = "LGPL-3.0-only",
},
};

#ifndef R2_PLUGIN_INCORE
Expand Down
8 changes: 6 additions & 2 deletions libr/arch/p/ppc/pseudo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1746,8 +1746,12 @@ 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",
.author = "pancake",
.license = "LGPL-3.0-only",
},
.parse = parse,
};

Expand Down
8 changes: 6 additions & 2 deletions libr/arch/p/riscv/pseudo.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,12 @@ 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",
.author = "pancake",
.license = "LGPL-3.0-only",
},
.parse = parse,
};

Expand Down
8 changes: 6 additions & 2 deletions libr/arch/p/sh/pseudo.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,12 @@ 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",
.author = "pancake",
.license = "LGPL-3.0-only",
},
.parse = parse
};

Expand Down
8 changes: 6 additions & 2 deletions libr/arch/p/stm8/pseudo.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,12 @@ 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",
.author = "pancake",
.license = "LGPL-3.0-only",
},
.parse = parse,
};

Expand Down
8 changes: 6 additions & 2 deletions libr/arch/p/tms320/pseudo.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,12 @@ 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",
.author = "pancake",
.license = "LGPL-3.0-only",
},
.parse = parse,
};

Expand Down
8 changes: 6 additions & 2 deletions libr/arch/p/tricore/pseudo.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,12 @@ 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",
.author = "pancake",
.license = "LGPL-3.0-only",
},
.parse = &parse,
.subvar = &subvar,
.fini = &fini,
Expand Down
8 changes: 6 additions & 2 deletions libr/arch/p/v850/pseudo.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,12 @@ 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",
.author = "pancake",
.license = "LGPL-3.0-only",
},
.parse = parse,
.subvar = &subvar,
};
Expand Down
8 changes: 6 additions & 2 deletions libr/arch/p/wasm/pseudo.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ 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",
.author = "pancake",
.license = "LGPL-3.0-only",
},
.subvar = &subvar,
};

Expand Down
8 changes: 6 additions & 2 deletions libr/arch/p/x86_nz/att2intel.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,12 @@ 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",
.author = "pancake",
.license = "LGPL-3.0-only",
},
.parse = &parse,
};

Expand Down
8 changes: 6 additions & 2 deletions libr/arch/p/x86_nz/pseudo.c
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,12 @@ 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",
.author = "pancake",
.license = "LGPL-3.0-only",
},
.parse = &parse,
.subvar = &subvar,
.fini = &fini,
Expand Down
8 changes: 6 additions & 2 deletions libr/arch/p/z80/pseudo.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@ static int parse(RParse *p, const char *data, char *str) {
}

RParsePlugin r_parse_plugin_z80_pseudo = {
.name = "z80.pseudo",
.desc = "z80 pseudo syntax",
.meta = {
.name = "z80.pseudo",
.desc = "z80 pseudo syntax",
.author = "pancake",
.license = "LGPL-3.0-only",
},
.parse = parse, // parse actually converts the string into asm.pseudo
};

Expand Down
2 changes: 1 addition & 1 deletion libr/asm/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,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 = (p && p->cur && p->cur->meta.name)? p->cur->meta.name: NULL;
if (pname) {
if (r_str_startswith (pname, "x86")) {
x86 = true;
Expand Down
10 changes: 5 additions & 5 deletions libr/asm/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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) {
Expand All @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions libr/bp/bp_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ R_API int r_bp_plugin_del(RBreakpoint *bp, const char *name) {
RBreakpointPlugin *h;
if (name && *name) {
r_list_foreach (bp->plugins, iter, h) {
if (!strcmp (h->name, name)) {
if (!strcmp (h->meta.name, name)) {
if (bp->cur == h) {
bp->cur = NULL;
}
Expand All @@ -29,7 +29,7 @@ R_API int r_bp_plugin_add(RBreakpoint *bp, RBreakpointPlugin *foo) {
}
/* avoid dupped plugins */
r_list_foreach (bp->bps, iter, h) {
if (!strcmp (h->name, foo->name)) {
if (!strcmp (h->meta.name, foo->meta.name)) {
return false;
}
}
Expand All @@ -48,7 +48,7 @@ R_API int r_bp_use(RBreakpoint *bp, const char *name, int bits) {
bp->bits = bits;
RBreakpointPlugin *h;
r_list_foreach (bp->plugins, iter, h) {
if (!strcmp (h->name, name)) {
if (!strcmp (h->meta.name, name)) {
bp->cur = h;
return true;
}
Expand All @@ -62,7 +62,7 @@ R_API void r_bp_plugin_list(RBreakpoint *bp) {
RBreakpointPlugin *b;
r_list_foreach (bp->plugins, iter, b) {
bp->cb_printf ("bp %c %s\n",
(bp->cur && !strcmp (bp->cur->name, b->name))? '*': '-',
b->name);
(bp->cur && !strcmp (bp->cur->meta.name, b->meta.name))? '*': '-',
b->meta.name);
}
}
Loading

0 comments on commit cd02b7f

Please sign in to comment.