Implement Lij, Ltj and Lhj (via the new phj) ##shell

This commit is contained in:
pancake 2022-05-30 20:29:07 +02:00 committed by pancake
parent 2e48978a8f
commit f21f472198
2 changed files with 29 additions and 6 deletions

View File

@ -28,8 +28,8 @@ static const char *help_msg_L[] = {
"Le", "", "list esil plugins",
"Lg", "", "list egg plugins",
"Lh", "", "list hash plugins (ph)",
"Li", "", "list bin plugins (iL)",
"Lt", "", "list color themes (eco)",
"Li", "[j]", "list bin plugins (iL)",
"Lt", "[j]", "list color themes (eco)",
"Ll", "", "list lang plugins (#!)",
"LL", "", "lock screen",
"Lm", "", "list fs plugins (mL)",
@ -341,7 +341,11 @@ static int cmd_plugins(void *data, const char *input) {
r_core_cmd_help (core, help_msg_L);
break;
case 't': // "Lt"
r_core_cmd0 (core, "eco");
if (input[1] == 'j') {
r_core_cmd0 (core, "ecoj");
} else {
r_core_cmd0 (core, "eco");
}
break;
case 'm': // "Lm"
r_core_cmdf (core, "mL%s", input + 1);
@ -353,7 +357,11 @@ static int cmd_plugins(void *data, const char *input) {
r_core_cmdf (core, "dL%s", input + 1);
break;
case 'h': // "Lh"
r_core_cmd0 (core, "ph"); // rahash2 -L is more verbose
if (input[1] == 'j') { // "Lhj"
r_core_cmd0 (core, "phj");
} else {
r_core_cmd0 (core, "ph");
}
break;
case 'a': // "La"
if (input[1] == '?') {

View File

@ -282,6 +282,8 @@ static const char *help_msg_pdp[] = {
static const char *help_msg_ph[] = {
"Usage:", "ph", " [algorithm] ([size])",
"ph", " md5", "compute md5 hash of current block",
"ph", "", "list available hash plugins",
"phj", "", "list available hash plugins in json",
"ph.", " sha1 32 @ 0x1000", "calculate sha1 of 32 bytes starting at 0x1000",
NULL
};
@ -3299,18 +3301,27 @@ restore_conf:
static void algolist(int mode) {
int i;
PJ *pj = (mode == 'j')? pj_new (): NULL;
pj_a (pj);
for (i = 0; i < R_HASH_NBITS; i++) {
ut64 bits = 1ULL << i;
const char *name = r_hash_name (bits);
if (name && *name) {
if (mode) {
if (mode == 'j') {
pj_s (pj, name);
} else if (mode) {
r_cons_println (name);
} else {
r_cons_printf ("%s ", name);
}
}
}
if (!mode) {
if (pj) {
pj_end (pj);
char *s = pj_drain (pj);
r_cons_printf ("%s\n", s);
free (s);
} else if (!mode) {
r_cons_newline ();
}
}
@ -3329,6 +3340,10 @@ static bool cmd_print_ph(RCore *core, const char *input) {
algolist (1);
return true;
}
if (*input == 'j') {
algolist ('j');
return true;
}
if (*input == '=') {
algolist (0);
return true;