Skip to content

Commit

Permalink
Update perl plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Oct 21, 2024
1 parent ac8d4f7 commit b2f4a2f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
37 changes: 21 additions & 16 deletions perl/perl.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2017 - pancake, nibble */
/* radare - LGPL - Copyright 2009-2024 - pancake, nibble */
/* perl extension for libr (radare2) */

#include "r_lib.h"
Expand Down Expand Up @@ -36,9 +36,9 @@ static void xs_init(pTHX) {
newXS ("r", perl_radare_cmd, __FILE__);
}

static bool init(RLang *lang) {
static bool init(RLangSession *ls) {
char *perl_embed[] = { "", "-e", "0" };
core = lang->user;
core = ls->lang->user;
my_perl = perl_alloc ();
if (!my_perl) {
fprintf (stderr, "Cannot init perl module\n");
Expand Down Expand Up @@ -67,23 +67,26 @@ static int setargv(void *user, int argc, char **argv) {
return true;
}

static bool setup(RLang *lang) {
static bool setup(RLangSession *ls) {
RListIter *iter;
RLangDef *def;
char cmd[128];
// Segfault if already initialized ?
//PyRun_SimpleString ("require r2/r_core.pl");
#warning TODO: implement setup in lang/perl
core = lang->user;
r_list_foreach (lang->defs, iter, def) {
if (!def->type || !def->name)
core = ls->lang->user;
r_list_foreach (ls->lang->defs, iter, def) {
if (!def->type || !def->name) {
continue;
if (!strcmp (def->type, "int"))
}
if (!strcmp (def->type, "int")) {
snprintf (cmd, sizeof (cmd), "%s=%d", def->name, (int)(size_t)def->value);
else if (!strcmp (def->type, "string"))
} else if (!strcmp (def->type, "string")) {
snprintf (cmd, sizeof (cmd), "%s=\"%s\"", def->name, (char *)def->value);
else snprintf (cmd, sizeof (cmd), "%s=%s.cast(%p)",
def->name, def->type, def->value);
} else {
snprintf (cmd, sizeof (cmd), "%s=%s.cast(%p)",
def->name, def->type, def->value);
}
// PyRun_SimpleString (cmd);
}
return true;
Expand All @@ -94,12 +97,14 @@ static const char *help =
" print \"r(\"pd 10\")\\n\";\n";

static RLangPlugin r_lang_plugin_perl = {
.name = "perl",
.meta = {
.name = "perl",
.desc = "Perl language extension",
},
.ext = "pl",
.desc = "Perl language extension",
.init = &init,
.setup = &setup,
.fini = (void *)&fini,
.init = init,
.setup = setup,
.fini = (void *)fini,
.help = (void *)&help,
.prompt = NULL,
.run = (void *)&run,
Expand Down
2 changes: 1 addition & 1 deletion tcl/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static bool runfile(RLangSession *s, const char *file) {
static RLangPlugin r_lang_plugin_tcl = {
.meta = {
.name = "tcl",
.license = "LGPL",
.license = "MIT",
.desc = "TCL/TK scripting for radare2",
.author = "pancake"
},
Expand Down

0 comments on commit b2f4a2f

Please sign in to comment.