Update r2papi from git, use src from /tmp instead of npm ##r2js (#23082)

* Dont uglify or minify, sed is more reliable
* Fix h<tab> help message
This commit is contained in:
pancake 2024-07-01 11:43:59 +02:00 committed by GitHub
parent 14b4068db4
commit 762088e87f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 2083 additions and 1416 deletions

View File

@ -693,60 +693,6 @@ static int cmd_uniq(void *data, const char *input) { // "uniq"
return 0; 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) { static int cmd_undo(void *data, const char *input) {
RCore *core = (RCore *)data; RCore *core = (RCore *)data;
switch (input[0]) { switch (input[0]) {

View File

@ -822,7 +822,7 @@ static int cmd_help(void *data, const char *input) {
} }
break; break;
case 'o': // "?o" 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); r_cons_printf ("0%"PFMT64o"\n", n);
break; break;
case 'T': // "?T" case 'T': // "?T"
@ -1055,7 +1055,7 @@ static int cmd_help(void *data, const char *input) {
} }
} else { } else {
if (input[1]) { // ?= if (input[1]) { // ?=
r_num_math (core->num, input+1); r_num_math (core->num, input + 1);
} else { } else {
r_cons_printf ("0x%"PFMT64x"\n", core->num->value); r_cons_printf ("0x%"PFMT64x"\n", core->num->value);
} }
@ -1403,7 +1403,7 @@ static int cmd_help(void *data, const char *input) {
} }
break; break;
case ' ': { 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 // TODO: replace all ${flagname} by its value in hexa
char *newmsg = filterFlags (core, msg); char *newmsg = filterFlags (core, msg);
r_str_unescape (newmsg); r_str_unescape (newmsg);
@ -1473,7 +1473,7 @@ static int cmd_help(void *data, const char *input) {
} }
break; break;
case '_': // "?_" hud input case '_': // "?_" hud input
r_core_yank_hud_file (core, input+1); r_core_yank_hud_file (core, input + 1);
break; break;
case 'i': // "?i" input num case 'i': // "?i" input num
r_cons_set_raw(0); r_cons_set_raw(0);
@ -1589,4 +1589,61 @@ static int cmd_help(void *data, const char *input) {
} }
return 0; 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 #endif

View File

@ -1076,6 +1076,7 @@ static const char *radare_argv[] = {
"ft?", "ft", "ftn", "fV", "fx", "fq", "ft?", "ft", "ftn", "fV", "fx", "fq",
"fz?", "fz", "fz-", "fz.", "fz:", "fz*", "fz?", "fz", "fz-", "fz.", "fz:", "fz*",
"g?", "g", "gw", "gc", "gl?", "gl", "gs", "gi", "gp", "ge", "gr", "gS", "g?", "g", "gw", "gc", "gl?", "gl", "gs", "gi", "gp", "ge", "gr", "gS",
"help",
"i?", "i", "ij", "iA", "ia", "ib", "ic", "icc", "iC", "i?", "i", "ij", "iA", "ia", "ib", "ic", "icc", "iC",
"id?", "id", "idp", "idpi", "idpi*", "idpd", "iD", "ie", "iee", "iE", "iE.", "id?", "id", "idp", "idpi", "idpi*", "idpd", "iD", "ie", "iee", "iE", "iE.",
"ih", "iHH", "ii", "iI", "ik", "il", "iL", "im", "iM", "io", "iO?", "iO", "ih", "iHH", "ii", "iI", "ik", "il", "iL", "im", "iM", "io", "iO?", "iO",
@ -2790,7 +2791,7 @@ static void __init_autocomplete_default(RCore* core) {
}; };
const char *files[] = { const char *files[] = {
".", "..", ".*", "/F", "/m", "!", "!!", "#!c", "#!v", "#!cpipe", "#!qjs", "#!tiny", "#!vala", "v.", ".", "..", ".*", "/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", "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", "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+", "/m", "zos", "zfd", "zfs", "zfz", "cat", "wta", "wtf", "wxf", "dml", "dd", "dd+",

View File

@ -765,6 +765,7 @@ static void register_helpers(JSContext *ctx) {
free (custom_papi); free (custom_papi);
} else { } else {
eval (ctx, js_r2papi_qjs); 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, "R=G.R=new R2Papi(r2);");
eval (ctx, "G.Process = new ProcessClass(r2);"); eval (ctx, "G.Process = new ProcessClass(r2);");

View File

@ -1,6 +1,6 @@
include deps.mk include deps.mk
USE_MINIFY=1 USE_MINIFY=0
USE_UGLIFY=0 USE_UGLIFY=0
ifeq ($(QJS_BRANCH),frida) ifeq ($(QJS_BRANCH),frida)
@ -64,7 +64,12 @@ R2PAPI_FILES+=shell.js
R2PAPI_FILES+=esil.js R2PAPI_FILES+=esil.js
R2PAPI_FILES_JS=$(addprefix $(NM)/r2papi/,$(R2PAPI_FILES)) R2PAPI_FILES_JS=$(addprefix $(NM)/r2papi/,$(R2PAPI_FILES))
USE_CUSTOM_R2PAPI=1
js_r2papi.c: node_modules js_r2papi.c: node_modules
ifeq ($(USE_CUSTOM_R2PAPI),1)
cp /tmp/r2papi.r2.js js_r2papi.qjs
else
# npm i js_r2papi # npm i js_r2papi
printf "Using r2papi version: " printf "Using r2papi version: "
-jq .version node_modules/r2papi/package.json -jq .version node_modules/r2papi/package.json
@ -80,11 +85,17 @@ js_r2papi.c: node_modules
| grep -v 'r2pipe\.js' \ | grep -v 'r2pipe\.js' \
>> js_r2papi.qjs >> js_r2papi.qjs
echo 'const r2pipe_js_1 = G;' >> js_r2papi.qjs echo 'const r2pipe_js_1 = G;' >> js_r2papi.qjs
endif
ifeq ($(USE_MINIFY),1) ifeq ($(USE_MINIFY),1)
npx minify --help > /dev/null npm i minify npx minify --help > /dev/null npm i minify
npx minify --js < js_r2papi.qjs > js_r2papi.mini.qjs npx minify --js < js_r2papi.qjs > js_r2papi.mini.qjs
else else
cp -f js_r2papi.qjs js_r2papi.mini.qjs 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 endif
ifeq ($(USE_UGLIFY),1) ifeq ($(USE_UGLIFY),1)
npx uglify-js --help > /dev/null || npm i uglify-js npx uglify-js --help > /dev/null || npm i uglify-js

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"dependencies": { "dependencies": {
"r2papi": "0.4.7" "r2papi": "0.4.9"
}, },
"devDependencies": { "devDependencies": {
"minify": "11.2.1", "minify": "11.2.1",

View File

@ -47,7 +47,8 @@ RebuildSpp() {
} }
RebuildQJS() { RebuildQJS() {
rm -f shlr/qjs/js_repl.c # rm -f shlr/qjs/js_repl.c
rm -f shlr/qjs/js_r2papi.c
make -C shlr/qjs make -C shlr/qjs
Rebuild libr/lang Rebuild libr/lang
touch libr/core/cmd.c touch libr/core/cmd.c