static int cmd_hash(void *data, const char *input) { RCore *core = (RCore *)data; if (*input == '!') { return cmd_hash_bang (core, input); } if (*input == '?') { const char *helpmsg3[] = { "Usage #!interpreter [<args>] [<file] [<<eof]","","", " #", "", "comment - do nothing", " #!","","list all available interpreters", " #!python","","run python commandline", " #!python"," foo.py","run foo.py python script (same as '. foo.py')", //" #!python <<EOF get python code until 'EOF' mark\n" " #!python"," arg0 a1 <<q","set arg0 and arg1 and read until 'q'", NULL}; r_core_cmd_help (core, helpmsg3); return false; } /* this is a comment - captain obvious should not be reached, see r_core_cmd_subst() */ return 0; }
static int cmd_hash(void *data, const char *input) { char algo[32]; RCore *core = (RCore *)data; ut32 osize = 0, len = core->blocksize; const char *ptr; int pos = 0, handled_cmd = R_FALSE; switch (*input) { case '\t': case ' ': return 0; case '#': if (!input[1]) { algolist (1); return R_TRUE; } case '!': return cmd_hash_bang (core, input); } ptr = strchr (input, ' '); sscanf (input, "%31s", algo); if (ptr && *(ptr+1) && r_num_is_valid_input (core->num, ptr+1)) { int nlen = r_num_math (core->num, ptr+1); if (nlen>0) len = nlen; osize = core->blocksize; if (nlen>core->blocksize) { r_core_block_size (core, nlen); if (nlen != core->blocksize) { eprintf ("Invalid block size\n"); r_core_block_size (core, osize); return R_TRUE; } } } else if (!ptr || !*(ptr+1)) osize = len; /* TODO: Simplify this spaguetti monster */ while (osize > 0 && HASH_HANDLERS[pos].name != NULL) { if (!r_str_ccmp (input, HASH_HANDLERS[pos].name, ' ')) { HASH_HANDLERS[pos].handler (core->block, len); handled_cmd = R_TRUE; break; } pos++; } if (!osize) { eprintf ("Error: provided size must be size > 0\n"); } if (*input == '?') { const char *helpmsg[] = { "Usage: #algo <size> @ addr", "", "", " #"," comment","note the space after the sharp sign", " ##","","List hash/checksum algorithms.", " #sha256", " 10K @ 33","calculate sha256 of 10K at 33", NULL }; const char *helpmsg2[] = { "Hashes:","","", NULL }; const char *helpmsg3[] = { "Usage #!interpreter [<args>] [<file] [<<eof]","","", " #!","","list all available interpreters", " #!python","","run python commandline", " #!python"," foo.py","run foo.py python script (same as '. foo.py')", //" #!python <<EOF get python code until 'EOF' mark\n" " #!python"," arg0 a1 <<q","set arg0 and arg1 and read until 'q'", NULL}; r_core_cmd_help (core, helpmsg); r_core_cmd_help (core, helpmsg2); algolist (0); r_core_cmd_help (core, helpmsg3); } if (osize) r_core_block_size (core, osize); return handled_cmd; }