Skip to content

Commit

Permalink
Implement r2pm -R to reload plugins from radare2 ##r2pm
Browse files Browse the repository at this point in the history
  • Loading branch information
trufae authored Jan 24, 2025
1 parent 40fe8e8 commit a7952c1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 23 additions & 1 deletion libr/main/r2pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ static const char *helpmsg =
" -l list installed packages\n"
" -q be quiet\n"
" -r [cmd ...args] run shell command with R2PM_BINDIR in PATH\n"
" -R <pkgname> reload plugin (See R2PM_RELOAD code block package)\n"
" -s [<keyword>] search available packages in database matching a string\n"
" -t [YYYY-MM-DD] set a moment in time to pull the code from the git packages\n"
" -u <pkgname> uninstall package (see -f to force uninstall)\n"
Expand All @@ -53,6 +54,7 @@ typedef struct r_r2pm_t {
bool quiet;
bool run;
bool search;
bool reload;
bool uninstall;
bool upgrade;
bool version;
Expand Down Expand Up @@ -1177,7 +1179,7 @@ R_API int r_main_r2pm(int argc, const char **argv) {
0
};
RGetopt opt;
r_getopt_init (&opt, argc, argv, "aqecdiIhH:flgrpst:uUv");
r_getopt_init (&opt, argc, argv, "aqecdiIhH:flgrRpst:uUv");
int i, c;
bool action = false;
// -H option without argument
Expand Down Expand Up @@ -1243,6 +1245,10 @@ R_API int r_main_r2pm(int argc, const char **argv) {
case 't':
r2pm.time = opt.arg;
break;
case 'R':
r2pm.reload = true;
action = true;
break;
case 'r':
r2pm.run = true;
action = true;
Expand Down Expand Up @@ -1382,6 +1388,22 @@ R_API int r_main_r2pm(int argc, const char **argv) {
res = 1;
}
}
if (r2pm.reload) {
RListIter *iter;
const char *pkg;
r_list_foreach (targets, iter, pkg) {
char *s = r2pm_get (pkg, "\nR2PM_RELOAD() {", TT_CODEBLOCK);
if (s) {
char *t = r_str_trim_lines (s);
r_cons_print (t);
free (t);
free (s);
}
}
if (havetoflush) {
r_cons_flush ();
}
}
r_list_free (targets);
if (res != -1) {
return res;
Expand Down
2 changes: 2 additions & 0 deletions man/r2pm.1
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Search in database for packages matching keyword
Set the R2PM_TIME env var to tell the time to take package source from git
.It Fl r Ar command ...args
Run command with R2PM_BINDIR in PATH
.It Fl R Ar package...
Display commands to reload the plugin from radare2
.It Fl p
Requires -c to clean the R2PM_PLUGDIR
.It Fl v
Expand Down

0 comments on commit a7952c1

Please sign in to comment.