Skip to content

Commit

Permalink
Update r2papi from git, use src from /tmp instead of npm ##r2js (#23082)
Browse files Browse the repository at this point in the history
* Dont uglify or minify, sed is more reliable
* Fix h<tab> help message
  • Loading branch information
trufae authored Jul 1, 2024
1 parent 14b4068 commit 762088e
Show file tree
Hide file tree
Showing 9 changed files with 2,335 additions and 1,668 deletions.
54 changes: 0 additions & 54 deletions libr/core/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,60 +693,6 @@ static int cmd_uniq(void *data, const char *input) { // "uniq"
return 0;
}

static int cmd_head(void *data, const char *_input) { // "head"
RCore *core = (RCore *)data;
int lines = 5;
char *input = strdup (_input);
char *arg = strchr (input, ' ');
char *tmp, *count;
static RCoreHelpMessage help_msg_h = {
"head", " [n] [file]", "Print first n lines in file (default n=5)",
NULL
};
if (arg) {
arg = (char *)r_str_trim_head_ro (arg + 1); // contains "count filename"
count = strchr (arg, ' ');
if (count) {
*count = 0; // split the count and file name
tmp = (char *)r_str_trim_head_ro (count + 1);
lines = atoi (arg);
arg = tmp;
}
}
switch (*input) {
case '?': // "head?"
r_core_cmd_help (core, help_msg_h);
break;
default: // "head"
if (!arg) {
arg = "";
}
if (r_fs_check (core->fs, arg)) {
r_core_cmdf (core, "md %s", arg);
} else {
char *res = r_syscmd_head (arg, lines);
if (res) {
r_cons_print (res);
free (res);
}
}
break;
}
free (input);
return 0;
}

static int cmd_h(void *data, const char *_input) { // "head"
if (r_str_startswith (_input, "ead")) {
return cmd_head (data, _input);
}
if (r_str_startswith (_input, "elp")) {
r_cons_printf ("%s\n", help_message);
return 0;
}
return -1; // invalid command
}

static int cmd_undo(void *data, const char *input) {
RCore *core = (RCore *)data;
switch (input[0]) {
Expand Down
65 changes: 61 additions & 4 deletions libr/core/cmd_help.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ static int cmd_help(void *data, const char *input) {
}
break;
case 'o': // "?o"
n = r_num_math (core->num, input+1);
n = r_num_math (core->num, input + 1);
r_cons_printf ("0%"PFMT64o"\n", n);
break;
case 'T': // "?T"
Expand Down Expand Up @@ -1055,7 +1055,7 @@ static int cmd_help(void *data, const char *input) {
}
} else {
if (input[1]) { // ?=
r_num_math (core->num, input+1);
r_num_math (core->num, input + 1);
} else {
r_cons_printf ("0x%"PFMT64x"\n", core->num->value);
}
Expand Down Expand Up @@ -1403,7 +1403,7 @@ static int cmd_help(void *data, const char *input) {
}
break;
case ' ': {
const char *msg = r_str_trim_head_ro (input+1);
const char *msg = r_str_trim_head_ro (input + 1);
// TODO: replace all ${flagname} by its value in hexa
char *newmsg = filterFlags (core, msg);
r_str_unescape (newmsg);
Expand Down Expand Up @@ -1473,7 +1473,7 @@ static int cmd_help(void *data, const char *input) {
}
break;
case '_': // "?_" hud input
r_core_yank_hud_file (core, input+1);
r_core_yank_hud_file (core, input + 1);
break;
case 'i': // "?i" input num
r_cons_set_raw(0);
Expand Down Expand Up @@ -1589,4 +1589,61 @@ static int cmd_help(void *data, const char *input) {
}
return 0;
}

static RCoreHelpMessage help_msg_h = {
"help", "", "Show a friendly message",
"head", " [n] [file]", "Print first n lines in file (default n=5)",
NULL
};

static int cmd_head(void *data, const char *_input) { // "head"
RCore *core = (RCore *)data;
int lines = 5;
char *input = strdup (_input);
char *arg = strchr (input, ' ');
char *tmp, *count;
if (arg) {
arg = (char *)r_str_trim_head_ro (arg + 1); // contains "count filename"
count = strchr (arg, ' ');
if (count) {
*count = 0; // split the count and file name
tmp = (char *)r_str_trim_head_ro (count + 1);
lines = atoi (arg);
arg = tmp;
}
}
switch (*input) {
case '?': // "head?"
r_core_cmd_help (core, help_msg_h);
break;
default: // "head"
if (!arg) {
arg = "";
}
if (r_fs_check (core->fs, arg)) {
r_core_cmdf (core, "md %s", arg);
} else {
char *res = r_syscmd_head (arg, lines);
if (res) {
r_cons_print (res);
free (res);
}
}
break;
}
free (input);
return 0;
}

static int cmd_h(void *data, const char *_input) { // "head"
if (r_str_startswith (_input, "ead")) {
return cmd_head (data, _input);
}
if (r_str_startswith (_input, "elp")) {
r_cons_printf ("%s\n", help_message);
return 0;
}
r_core_cmd_help ((RCore*)data, help_msg_h);
return -1; // invalid command
}
#endif
3 changes: 2 additions & 1 deletion libr/core/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,7 @@ static const char *radare_argv[] = {
"ft?", "ft", "ftn", "fV", "fx", "fq",
"fz?", "fz", "fz-", "fz.", "fz:", "fz*",
"g?", "g", "gw", "gc", "gl?", "gl", "gs", "gi", "gp", "ge", "gr", "gS",
"help",
"i?", "i", "ij", "iA", "ia", "ib", "ic", "icc", "iC",
"id?", "id", "idp", "idpi", "idpi*", "idpd", "iD", "ie", "iee", "iE", "iE.",
"ih", "iHH", "ii", "iI", "ik", "il", "iL", "im", "iM", "io", "iO?", "iO",
Expand Down Expand Up @@ -2790,7 +2791,7 @@ static void __init_autocomplete_default(RCore* core) {
};
const char *files[] = {
".", "..", ".*", "/F", "/m", "!", "!!", "#!c", "#!v", "#!cpipe", "#!qjs", "#!tiny", "#!vala", "v.",
"#!rust", "#!zig", "#!pipe", "#!python", "aeli", "arp", "arpg", "dmd", "drp", "drpg", "o", "oe", "ot", "o+", "o++", "on", "open",
"#!rust", "#!zig", "#!pipe", "#!python", "aeli", "arp", "arpg", "dmd", "drp", "drpg", "oe", "ot", "o+", "o++", "on", "open",
"idp", "idpi", "L", "obf", "o+", "o", "oc", "of", "r2", "rabin2", "rasm2", "rahash2", "rax2", "wff",
"rafind2", "cd", "ls", "lua", "on", "wf", "rm", "wF", "wp", "Sd", "Sl", "to", "pm",
"/m", "zos", "zfd", "zfs", "zfz", "cat", "wta", "wtf", "wxf", "dml", "dd", "dd+",
Expand Down
1 change: 1 addition & 0 deletions libr/lang/p/qjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ static void register_helpers(JSContext *ctx) {
free (custom_papi);
} else {
eval (ctx, js_r2papi_qjs);
// r_file_dump ("rapi.qjs", js_r2papi_qjs, strlen (js_r2papi_qjs), 0);
}
eval (ctx, "R=G.R=new R2Papi(r2);");
eval (ctx, "G.Process = new ProcessClass(r2);");
Expand Down
13 changes: 12 additions & 1 deletion shlr/qjs/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include deps.mk

USE_MINIFY=1
USE_MINIFY=0
USE_UGLIFY=0

ifeq ($(QJS_BRANCH),frida)
Expand Down Expand Up @@ -64,7 +64,12 @@ R2PAPI_FILES+=shell.js
R2PAPI_FILES+=esil.js
R2PAPI_FILES_JS=$(addprefix $(NM)/r2papi/,$(R2PAPI_FILES))

USE_CUSTOM_R2PAPI=1

js_r2papi.c: node_modules
ifeq ($(USE_CUSTOM_R2PAPI),1)
cp /tmp/r2papi.r2.js js_r2papi.qjs
else
# npm i js_r2papi
printf "Using r2papi version: "
-jq .version node_modules/r2papi/package.json
Expand All @@ -80,11 +85,17 @@ js_r2papi.c: node_modules
| grep -v 'r2pipe\.js' \
>> js_r2papi.qjs
echo 'const r2pipe_js_1 = G;' >> js_r2papi.qjs
endif
ifeq ($(USE_MINIFY),1)
npx minify --help > /dev/null npm i minify
npx minify --js < js_r2papi.qjs > js_r2papi.mini.qjs
else
cp -f js_r2papi.qjs js_r2papi.mini.qjs
# TODO remove multiline /* */ comments too
cat js_r2papi.qjs | sed \
-e 's, *, ,g' \
-e 's,\\/\\/.*/,,' \
> js_r2papi.mini.qjs
endif
ifeq ($(USE_UGLIFY),1)
npx uglify-js --help > /dev/null || npm i uglify-js
Expand Down
Loading

0 comments on commit 762088e

Please sign in to comment.