diff --git a/librz/include/rz_util/rz_print.h b/librz/include/rz_util/rz_print.h index fbc8e6fcaa5..32e607aa787 100644 --- a/librz/include/rz_util/rz_print.h +++ b/librz/include/rz_util/rz_print.h @@ -239,6 +239,7 @@ RZ_API char *rz_print_json_human(const char *s); RZ_API char *rz_print_json_path(const char *s, int pos); RZ_API RZ_OWN RzStrBuf *rz_print_colorize_asm_str(RZ_BORROW RzPrint *p, const RzAsmTokenString *toks); +RZ_API void rz_print_colored_help_option(const char *option, const char *arg, const char *description, size_t maxOptionAndArgLength); #endif #ifdef __cplusplus diff --git a/librz/main/rizin.c b/librz/main/rizin.c index bb74ea855ec..d7927a37f16 100644 --- a/librz/main/rizin.c +++ b/librz/main/rizin.c @@ -90,58 +90,77 @@ static int rz_main_version_verify(int show) { } static int main_help(int line) { + if (line < 2) { - printf("Usage: rizin [-ACdfLMnNqStuvwzX] [-P patch] [-p prj] [-a arch] [-b bits] [-i file]\n" - " [-s addr] [-B baddr] [-m maddr] [-c cmd] [-e k=v] file|pid|-|--|=\n"); + printf("%s%s", Color_CYAN, "Usage: "); + printf(Color_RESET "rizin [-ACdfLMnNqStuvwzX] [-P patch] [-p prj] [-a arch] [-b bits] [-i file]\n" + " [-s addr] [-B baddr] [-m maddr] [-c cmd] [-e k=v] file|pid|-|--|=\n"); } if (line != 1) { - printf( - " -- run rizin without opening any file\n" - " = same as 'rizin malloc://512'\n" - " - read file from stdin \n" - " -= perform R=! command to run all commands remotely\n" - " -0 print \\x00 after init and every command\n" - " -2 close stderr file descriptor (silent warning messages)\n" - " -a [arch] set asm.arch\n" - " -A run 'aaa' command to analyze all referenced code\n" - " -b [bits] set asm.bits\n" - " -B [baddr] set base address for PIE binaries\n" - " -c 'cmd..' execute rizin command\n" - " -C file is host:port (alias for -cR+http://%%s/cmd/)\n" - " -d debug the executable 'file' or running process 'pid'\n" - " -D [backend] enable debug mode (e cfg.debug=true)\n" - " -e k=v evaluate config var\n" - " -f block size = file size\n" - " -F [binplug] force to use that rbin plugin\n" - " -h, -hh show help message, -hh for long\n" - " -H ([var]) display variable\n" - " -i [file] run script file\n" - " -I [file] run script file before the file is opened\n" - " -k [OS/kern] set asm.os (linux, macos, w32, netbsd, ...)\n" - " -l [lib] load plugin file\n" - " -L list supported IO plugins\n" - " -m [addr] map file at given address (loadaddr)\n" - " -M do not demangle symbol names\n" - " -n, -nn do not load RzBin info (-nn only load bin structures)\n" - " -N do not load user settings and scripts\n" - " -NN do not load any script or plugin\n" - " -q quiet mode (no prompt) and quit after -i\n" - " -qq quit after running all -c and -i\n" - " -Q quiet mode (no prompt) and quit faster (quickLeak=true)\n" - " -p [p.rzdb] load project file\n" - " -r [rz-run] specify rz-run profile to load (same as -e dbg.profile=X)\n" - " -R [rule] specify custom rz-run directive\n" - " -s [addr] initial seek\n" -#if USE_THREADS && ALLOW_THREADED - " -t load rz-bin info in thread\n" -#endif - " -T do not compute file hashes\n" - " -u set bin.filter=false to get raw sym/sec/cls names\n" - " -v, -V show rizin version (-V show lib versions)\n" - " -w open file in write mode\n" - " -x open without exec-flag (asm.emu will not work), See io.exec\n" - " -X same as -e bin.usextr=false (useful for dyldcache)\n" - " -z, -zz do not load strings or load them even in raw\n"); + const char *options[] = { + // clang-format off + "--", "", "run rizin without opening any file", + "=", "", "same as 'rizin malloc://512", + "- ", "", "read file from stdin", + "-=", "", "perform R=! command to run all commands remotely", + "-0", "", "print \\x00 after init and every command", + "-2", "", "close stderr file descriptor (silent warning messages)", + "-a", "[arch]", "set asm.arch", + "-A", "", "run 'aaa' command to analyze all referenced code", + "-b", "[bits]", "set asm.bits", + "-B", "[baddr]", "set base address for PIE binaries", + "-c 'cmd..'", "", "execute rizin command", + "-C", "", "file is host:port (alias for -cR+http://%%s/cmd/)", + "-d", "", "debug the executable 'file' or running process 'pid", + "-D", "[backend]", "enable debug mode (e cfg.debug=true)", + "-e k=v", "", "evaluate config var", + "-f", "", "block size = file size", + "-F", "[binplug]", "force to use that rbin plugin", + "-h, -hh", "", "show help message, -hh for long", + "-H", "([var])", "display variable", + "-i", "[file]", "run script file", + "-I", "[file]", "run script file before the file is opened", + "-k", "[OS/kern]", "set asm.os (linux, macos, w32, netbsd, ...)", + "-l", "[lib]", "load plugin file", + "-L", "", "list supported IO plugins", + "-m", "[addr]", "map file at given address (loadaddr)", + "-M", "", "do not demangle symbol names", + "-n, -nn", "", "do not load RzBin info (-nn only load bin structures)", + "-N", "", "do not load user settings and scripts", + "-NN", "", "do not load any script or plugin", + "-q", "", "quiet mode (no prompt) and quit after -i", + "-qq", "", "quit after running all -c and -i", + "-Q", "", "quiet mode (no prompt) and quit faster (quickLeak=true)", + "-p", "[p.rzdb]", "load project file", + "-r", "[rz-run]", "specify rz-run profile to load (same as -e dbg.profile=X)", + "-R", "[rule]", "specify custom rz-run directive", + "-s", "[addr]", "initial seek", + #if USE_THREADS && ALLOW_THREADED + "-t", "", "load rz-bin info in thread", + #endif + "-T", "", "do not compute file hashes", + "-u", "", "set bin.filter=false to get raw sym/sec/cls names", + "-v, -V", "", "show rizin version (-V show lib versions)", + "-w", "", "open file in write mode", + "-x", "", "open without exec-flag (asm.emu will not work), See io.exec", + "-X", "", "same as -e bin.usextr=false (useful for dyldcache)", + "-z, -zz", "", "do not load strings or load them even in raw", + // clang-format on + }; + size_t maxOptionAndArgLength = 0; + for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) { + size_t optionLength = strlen(options[i]); + size_t argLength = strlen(options[i + 1]); + size_t totalLength = optionLength + argLength; + if (totalLength > maxOptionAndArgLength) { + maxOptionAndArgLength = totalLength; + } + } + for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) { + if (i + 1 < sizeof(options) / sizeof(options[0])) { + rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxOptionAndArgLength); + } + } } if (line == 2) { char *datahome = rz_path_home_prefix(RZ_DATADIR); diff --git a/librz/main/rz-asm.c b/librz/main/rz-asm.c index 143d9cc689a..42f937ebea7 100644 --- a/librz/main/rz-asm.c +++ b/librz/main/rz-asm.c @@ -169,46 +169,65 @@ static int show_analinfo(RzAsmState *as, const char *arg, ut64 offset) { static int rasm_show_help(int v) { if (v < 2) { - printf("Usage: rz-asm [-ACdDehLBvw] [-a arch] [-b bits] [-o addr] [-s syntax]\n" - " [-f file] [-F fil:ter] [-i skip] [-l len] 'code'|hex|-\n"); - } + printf("%s%s", Color_CYAN, "Usage: "); + printf(Color_RESET "rz-asm [-ACdDehLBvw] [-a arch] [-b bits] [-o addr] [-s syntax]\n" + " [-f file] [-F fil:ter] [-i skip] [-l len] 'code'|hex|-\n"); + } + const char *options[] = { + // clang-format off + "-a", "[arch]", "Set architecture to assemble/disassemble (see -L)", + "-A", "", "Show Analysis information from given hexpairs", + "-b", "[bits]", "Set cpu register size (8, 16, 32, 64) (RZ_ASM_BITS)", + "-B", "", "Binary input/output (-l is mandatory for binary input)", + "-c", "[cpu]", "Select specific CPU (depends on arch)", + "-C", "", "Output in C format", + "-d, -D", "", "Disassemble from hexpair bytes (-D show hexpairs)", + "-e", "", "Use big endian instead of little endian", + "-I", "", "Display lifted RzIL code (same input as in -d, IL is also validated)", + "-E", "", "Display ESIL expression (same input as in -d)", + "-f", "[file]", "Read data from file", + "-F", "[in:out]", "Specify input and/or output filters (att2intel, x86.pseudo, ...)", + "-h, -hh", "", "Show this help, -hh for long", + "-i", "[len]", "ignore/skip N bytes of the input buffer", + "-j", "", "output in json format", + "-k", "[kernel]", "Select operating system (linux, windows, darwin, ..)", + "-l", "[len]", "Input/Output length", + "-L", "", "List Asm plugins: (a=asm, d=disasm, A=analyze, e=ESIL)", + "-o, -@", "[addr]", "Set start address for code (default 0)", + "-O", "[file]", "Output file name (rz-asm -Bf a.asm -O a)", + "-p", "", "Run SPP over input for assembly", + "-q", "", "quiet mode", + "-r", "", "output in rizin commands", + "-s", "[syntax]", "Select syntax (intel, att)", + "-v", "", "Show version information", + "-x", "", "Use hex dwords instead of hex pairs when assembling.", + "-w", "", "What's this instruction for? describe opcode", + // clang-format on + }; if (v != 1) { - printf(" -a [arch] Set architecture to assemble/disassemble (see -L)\n" - " -A Show Analysis information from given hexpairs\n" - " -b [bits] Set cpu register size (8, 16, 32, 64) (RZ_ASM_BITS)\n" - " -B Binary input/output (-l is mandatory for binary input)\n" - " -c [cpu] Select specific CPU (depends on arch)\n" - " -C Output in C format\n" - " -d, -D Disassemble from hexpair bytes (-D show hexpairs)\n" - " -e Use big endian instead of little endian\n" - " -I Display lifted RzIL code (same input as in -d, IL is also validated)\n" - " -E Display ESIL expression (same input as in -d)\n" - " -f [file] Read data from file\n" - " -F [in:out] Specify input and/or output filters (att2intel, x86.pseudo, ...)\n" - " -h, -hh Show this help, -hh for long\n" - " -i [len] ignore/skip N bytes of the input buffer\n" - " -j output in json format\n" - " -k [kernel] Select operating system (linux, windows, darwin, ..)\n" - " -l [len] Input/Output length\n" - " -L List Asm plugins: (a=asm, d=disasm, A=analyze, e=ESIL)\n" - " -o,-@ [addr] Set start address for code (default 0)\n" - " -O [file] Output file name (rz-asm -Bf a.asm -O a)\n" - " -p Run SPP over input for assembly\n" - " -q quiet mode\n" - " -r output in rizin commands\n" - " -s [syntax] Select syntax (intel, att)\n" - " -v Show version information\n" - " -x Use hex dwords instead of hex pairs when assembling.\n" - " -w What's this instruction for? describe opcode\n" - " If '-l' value is greater than output length, output is padded with nops\n" - " If the last argument is '-' reads from stdin\n"); - printf("Environment:\n" - " RZ_NOPLUGINS do not load shared plugins (speedup loading)\n" - " RZ_ASM_ARCH same as rz-asm -a\n" - " RZ_ASM_BITS same as rz-asm -b\n" - " RZ_DEBUG if defined, show error messages and crash signal\n" - ""); + size_t maxOptionAndArgLength = 0; + for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) { + size_t optionLength = strlen(options[i]); + size_t argLength = strlen(options[i + 1]); + size_t totalLength = optionLength + argLength; + if (totalLength > maxOptionAndArgLength) { + maxOptionAndArgLength = totalLength; + } + } + for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) { + if (i + 1 < sizeof(options) / sizeof(options[0])) { + rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxOptionAndArgLength); + } + } } + printf(" If '-l' value is greater than output length, output is padded with nops\n" + " If the last argument is '-' reads from stdin\n" + "Environment:\n" + " RZ_NOPLUGINS do not load shared plugins (speedup loading)\n" + " RZ_ASM_ARCH same as rz-asm -a\n" + " RZ_ASM_BITS same as rz-asm -b\n" + " RZ_DEBUG if defined, show error messages and crash signal\n" + ""); if (v == 2) { printf("Supported Assembler directives:\n"); rz_asm_list_directives(); diff --git a/librz/main/rz-bin.c b/librz/main/rz-bin.c index 2a6b081b55b..2bf80d308b3 100644 --- a/librz/main/rz-bin.c +++ b/librz/main/rz-bin.c @@ -151,68 +151,86 @@ static ut32 actions2mask(ut64 action) { } static int rabin_show_help(int v) { - printf("Usage: rz-bin [-AcdeEghHiIjlLMqrRsSUvVxzZ] [-@ at] [-a arch] [-b bits] [-B addr]\n" + printf("%s%s%s", Color_CYAN, "Usage: ", Color_RESET); + printf("rz-bin [-AcdeEghHiIjlLMqrRsSUvVxzZ] [-@ at] [-a arch] [-b bits] [-B addr]\n" " [-C F:C:D] [-f str] [-m addr] [-n str] [-N m:M] [-P[-P] pdb]\n" " [-o str] [-O str] [-k query] [-D lang symname] file\n"); if (v) { - printf( - " -@ [addr] show section, symbol or import at addr\n" - " -A list sub-binaries and their arch-bits pairs\n" - " -a [arch] set arch (x86, arm, .. or _)\n" - " -b [bits] set bits (32, 64 ...)\n" - " -B [addr] override base address (pie bins)\n" - " -c list classes\n" - " -cc list classes in header format\n" - " -C [fmt:C:D] create [elf,mach0,pe] with Code and Data hexpairs (see -a)\n" - " -d show debug/dwarf information\n" - " -D lang name demangle symbol name (-D all for bin.demangle=true)\n" - " -e entrypoint\n" - " -ee constructor/destructor entrypoints\n" - " -E globally exportable symbols\n" - " -f [str] select sub-bin named str\n" - " -F [binfmt] force to use that bin plugin (ignore header check)\n" - " -g same as -SMZIHVResizcld -SS -SSS -ee (show all info)\n" - " -G [addr] load address . offset to header\n" - " -h this help message\n" - " -H header fields\n" - " -i imports (symbols imported from libraries)\n" - " -I binary info\n" - " -j output in json\n" - " -k [sdb-query] run sdb query. for example: '*'\n" - " -K [algo] calculate checksums (md5, sha1, ..)\n" - " -l linked libraries\n" - " -L [plugin] list supported bin plugins or plugin details\n" - " -m [addr] show source line at addr\n" - " -M main (show address of main symbol)\n" - " -n [str] show section, symbol or import named str\n" - " -N [min:max] force min:max number of chars per string (see -z and -zz)\n" - " -o [str] output file/folder for write operations (out by default)\n" - " -O [str] write/extract operations (-O help)\n" - " -p show physical addresses\n" - " -P show debug/pdb information\n" - " -PP download pdb file for binary\n" - " -q be quiet, just show fewer data\n" - " -qq show less info (no offset/size for -z for ex.)\n" - " -Q show load address used by dlopen (non-aslr libs)\n" - " -r rizin output\n" - " -R relocations\n" - " -s symbols\n" - " -S sections\n" - " -SS segments\n" - " -SSS sections mapping to segments\n" - " -T display file signature\n" - " -u unfiltered (no rename duplicated symbols/sections)\n" - " -U resoUrces\n" - " -v display version and quit\n" - " -V Show binary version information\n" - " -w display try/catch blocks\n" - " -x extract bins contained in file\n" - " -X [fmt] [f] .. package in fat or zip the given files and bins contained in file\n" - " -Y [fw file] calculates all the possibles base address candidates of a firmware bin\n" - " -z strings (from data section)\n" - " -zz strings (from raw strings from bin)\n" - " -zzz dump raw strings to stdout (for huge files)\n" - " -Z guess size of binary program\n"); + const char *options[] = { + // clang-format off + "-@", "[addr]", "show section, symbol or import at addr", + "-A", "", "list sub-binaries and their arch-bits pairs", + "-a", "[arch]", "set arch (x86, arm, .. or _)", + "-b", "[bits]", "set bits (32, 64 ...)", + "-B", "[addr]", "override base address (pie bins)", + "-c", "", "list classes", + "-cc", "", "list classes in header format", + "-C", "[fmt:C:D]", "create [elf,mach0,pe] with Code and Data hexpairs (see -a)", + "-d", "", "show debug/dwarf information", + "-D", "lang name", "demangle symbol name (-D all for bin.demangle=true)", + "-e", "", "entrypoint", + "-ee", "", "constructor/destructor entrypoints", + "-E", "", "globally exportable symbols", + "-f", "[str]", "select sub-bin named str", + "-F", "[binfmt]", "force to use that bin plugin (ignore header check)", + "-g", "", "same as -SMZIHVResizcld -SS -SSS -ee (show all info)", + "-G", "[addr]", "load address . offset to header", + "-h", "", "this help message", + "-H", "", "header fields", + "-i", "", "imports (symbols imported from libraries)", + "-I", "", "binary info", + "-j", "", "output in json", + "-k", "[sdb-query]", "run sdb query. for example: '*'", + "-K", "[algo]", "calculate checksums (md5, sha1, ..)", + "-l", "", "linked libraries", + "-L", "[plugin]", "list supported bin plugins or plugin details", + "-m", "[addr]", "show source line at addr", + "-M", "", "main (show address of main symbol)", + "-n", "[str]", "show section, symbol or import named str", + "-N", "[min:max]", "force min:max number of chars per string (see -z and -zz)", + "-o", "[str]", "output file/folder for write operations (out by default)", + "-O", "[str]", "write/extract operations (-O help)", + "-p", "", "show physical addresses", + "-P", "", "show debug/pdb information", + "-PP", "", "download pdb file for binary", + "-q", "", "be quiet, just show fewer data", + "-qq", "", "show less info (no offset/size for -z for ex.)", + "-Q", "", "show load address used by dlopen (non-aslr libs)", + "-r", "", "rizin output", + "-R", "", "relocations", + "-s", "", "symbols", + "-S", "", "sections", + "-SS", "", "segments", + "-SSS", "", "sections mapping to segments", + "-T", "", "display file signature", + "-u", "", "unfiltered (no rename duplicated symbols/sections)", + "-U", "", "resoUrces", + "-v", "", "display version and quit", + "-V", "", "Show binary version information", + "-w", "", "display try/catch blocks", + "-x", "", "extract bins contained in file", + "-X", "[fmt] [f] ..", "package in fat or zip the given files and bins contained in file", + "-Y", "[fw file]", "calculates all the possibles base address candidates of a firmware bin", + "-z", "", "strings (from data section)", + "-zz", "", "strings (from raw strings from bin)", + "-zzz", "", "dump raw strings to stdout (for huge files)", + "-Z", "", "guess size of binary program", + // clang-format on + }; + size_t maxOptionAndArgLength = 0; + for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) { + size_t optionLength = strlen(options[i]); + size_t argLength = strlen(options[i + 1]); + size_t totalLength = optionLength + argLength; + if (totalLength > maxOptionAndArgLength) { + maxOptionAndArgLength = totalLength; + } + } + for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) { + if (i + 1 < sizeof(options) / sizeof(options[0])) { + rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxOptionAndArgLength); + } + } } if (v) { printf("Environment:\n" diff --git a/librz/main/rz-diff.c b/librz/main/rz-diff.c index 2299fab7a6a..db67298ab36 100644 --- a/librz/main/rz-diff.c +++ b/librz/main/rz-diff.c @@ -196,55 +196,74 @@ typedef struct diff_hex_view_t { #define rz_diff_ctx_set_opt(x, o) rz_diff_ctx_set_def(x, option, DIFF_OPT_UNKNOWN, o) static void rz_diff_show_help(bool usage_only) { - printf("Usage: rz-diff [options] \n"); + printf("%s%s%s", Color_CYAN, "Usage: ", Color_RESET); + printf("rz-diff [options] \n"); if (usage_only) { return; } + const char *options[] = { + // clang-format off + "-a", "[arch]", "specify architecture plugin to use (x86, arm, ..)", + "-b", "[bits]", "specify register size for arch (16 (thumb), 32, 64, ..)", + "-d", "[algo]", "compute edit distance based on the chosen algorithm:", + "", "", " myers | Eugene W. Myers' O(ND) algorithm (no substitution)", + "", "", " leven | Levenshtein O(N^2) algorithm (with substitution)", + "", "", " ssdeep | Context triggered piecewise hashing comparison", + "-i", "", "use command line arguments instead of files (only for -d)", + "-H", "", "hexadecimal visual mode", + "-h", "", "show the help message", + "-j", "", "json output", + "-q", "", "quite output", + "-V", "", "show version information", + "-v", "", "be more verbose (stderr output)", + "-e", "[k=v]", "set an evaluable config variable", + "-A", "", "compare virtual and physical addresses", + "-B", "", "run 'aaa' when loading the bin", + "-C", "", "disable colors", + "-T", "", "show timestamp information", + "-S", "[WxH]", "sets the width and height of the terminal for visual mode", + "-0", "[cmd]", "input for file0 when option -t 'commands' is given.", + "", "", "the same value will be set for file1, if -1 is not set.", + "-1", "[cmd]", "input for file1 when option -t 'commands' is given.", + "-t", "[type]", "compute the difference between two files based on its type:", + "", "", " bytes | compares raw bytes in the files (only for small files)", + "", "", " lines | compares text files", + "", "", " functions | compares functions found in the files", + "", "", " classes | compares classes found in the files", + "", "", " command | compares command output returned when executed in both files", + "", "", " | requires -0 and -1 is optional", + "", "", " entries | compares entries found in the files", + "", "", " fields | compares fields found in the files", + "", "", " graphs | compares 2 functions and outputs in graphviz/dot format", + "", "", " | requires -0 and -1 is optional", + "", "", " imports | compares imports found in the files", + "", "", " libraries | compares libraries found in the files", + "", "", " sections | compares sections found in the files", + "", "", " strings | compares strings found in the files", + "", "", " symbols | compares symbols found in the files", + // clang-format on + }; + size_t maxOptionAndArgLength = 0; + for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) { + size_t optionLength = strlen(options[i]); + size_t argLength = strlen(options[i + 1]); + size_t totalLength = optionLength + argLength; + if (totalLength > maxOptionAndArgLength) { + maxOptionAndArgLength = totalLength; + } + } + for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) { + if (i + 1 < sizeof(options) / sizeof(options[0])) { + rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxOptionAndArgLength); + } + } + printf( - " -a [arch] specify architecture plugin to use (x86, arm, ..)\n" - " -b [bits] specify register size for arch (16 (thumb), 32, 64, ..)\n" - " -d [algo] compute edit distance based on the choosen algorithm:\n" - " myers | Eugene W. Myers' O(ND) algorithm (no substitution)\n" - " leven | Levenshtein O(N^2) algorithm (with substitution)\n" - " ssdeep | Context triggered piecewise hashing comparison\n" - " -i use command line arguments instead of files (only for -d)\n" - " -H hexadecimal visual mode\n" - " -h show the help message\n" - " -j json output\n" - " -q quite output\n" - " -V show version information\n" - " -v be more verbose (stderr output)\n" - " -e [k=v] set an evaluable config variable\n" - " -A compare virtual and physical addresses\n" - " -B run 'aaa' when loading the bin\n" - " -C disable colors\n" - " -T show timestamp information\n" - " -S [WxH] sets the width and height of the terminal for visual mode\n" - " -0 [cmd] input for file0 when option -t 'commands' is given.\n" - " the same value will be set for file1, if -1 is not set.\n" - " -1 [cmd] input for file1 when option -t 'commands' is given.\n" - " -t [type] compute the difference between two files based on its type:\n" - " bytes | compares raw bytes in the files (only for small files)\n" - " lines | compares text files\n" - " functions | compares functions found in the files\n" - " classes | compares classes found in the files\n" - " command | compares command output returned when executed in both files\n" - " | requires -0 and -1 is optional\n" - " entries | compares entries found in the files\n" - " fields | compares fields found in the files\n" - " graphs | compares 2 functions and outputs in graphviz/dot format\n" - " | requires -0 and -1 is optional\n" - " imports | compares imports found in the files\n" - " libraries | compares libraries found in the files\n" - " sections | compares sections found in the files\n" - " strings | compares strings found in the files\n" - " symbols | compares symbols found in the files\n" - " palette colors can be changed by adding the following lines\n" - " inside the $HOME/.rizinrc file\n" - " ec diff.unknown blue | offset color\n" - " ec diff.match green | match color\n" - " ec diff.unmatch red | mismatch color\n" - ""); + "palette colors can be changed by adding the following lines\n" + "inside the $HOME/.rizinrc file\n" + "ec diff.unknown blue | offset color\n" + "ec diff.match green | match color\n" + "ec diff.unmatch red | mismatch color\n"); } static bool rz_diff_is_file(const char *file) { diff --git a/librz/main/rz-find.c b/librz/main/rz-find.c index e11afdf4ca9..7d986ca0ed7 100644 --- a/librz/main/rz-find.c +++ b/librz/main/rz-find.c @@ -171,34 +171,52 @@ static void print_bin_string(RzBinFile *bf, RzBinString *string, PJ *pj) { } static int show_help(const char *argv0, int line) { - printf("Usage: %s [-mXnzZhqv] [-a align] [-b sz] [-f/t from/to] [-[e|s|w|S|I] str] [-x hex] -|file|dir ..\n", argv0); + printf("%s%s%s", Color_CYAN, "Usage: ", Color_RESET); + printf("%s [-mXnzZhqv] [-a align] [-b sz] [-f/t from/to] [-[e|s|w|S|I] str] [-x hex] -|file|dir ..\n", argv0); if (line) { return 0; } - printf( - " -a [align] only accept aligned hits\n" - " -b [size] set block size\n" - " -e [regex] search for regex matches (can be used multiple times)\n" - " -f [from] start searching from address 'from'\n" - " -F [file] read the contents of the file and use it as keyword\n" - " -h show this help\n" - " -i identify filetype (rizin -nqcpm file)\n" - " -j output in JSON\n" - " -m magic search, file-type carver\n" - " -M [str] set a binary mask to be applied on keywords\n" - " -n do not stop on read errors\n" - " -r print using rizin commands\n" - " -s [str] search for a specific string (can be used multiple times)\n" - " -w [str] search for a specific wide string (can be used multiple times). Assumes str is UTF-8.\n" - " -I [str] search for an entry in import table.\n" - " -S [str] search for a symbol in symbol table.\n" - " -t [to] stop search at address 'to'\n" - " -q quiet - do not show headings (filenames) above matching contents (default for searching a single file)\n" - " -v print version and exit\n" - " -x [hex] search for hexpair string (909090) (can be used multiple times)\n" - " -X show hexdump of search results\n" - " -z search for zero-terminated strings\n" - " -Z show string found on each search hit\n"); + const char *options[] = { + // clang-format off + "-a", "[align]", "only accept aligned hits", + "-b", "[size]", "set block size", + "-e", "[regex]", "search for regex matches (can be used multiple times)", + "-f", "[from]", "start searching from address 'from'", + "-F", "[file]", "read the contents of the file and use it as keyword", + "-h", "", "show this help", + "-i", "", "identify filetype (rizin -nqcpm file)", + "-j", "", "output in JSON", + "-m", "", "magic search, file-type carver", + "-M", "[str]", "set a binary mask to be applied on keywords", + "-n", "", "do not stop on read errors", + "-r", "", "print using rizin commands", + "-s", "[str]", "search for a specific string (can be used multiple times)", + "-w", "[str]", "search for a specific wide string (can be used multiple times). Assumes str is UTF-8.", + "-I", "[str]", "search for an entry in import table.", + "-S", "[str]", "search for a symbol in symbol table.", + "-t", "[to]", "stop search at address 'to'", + "-q", "", "quiet - do not show headings (filenames) above matching contents (default for searching a single file)", + "-v", "", "print version and exit", + "-x", "[hex]", "search for hexpair string (909090) (can be used multiple times)", + "-X", "", "show hexdump of search results", + "-z", "", "search for zero-terminated strings", + "-Z", "", "show string found on each search hit", + // clang-format on + }; + size_t maxOptionAndArgLength = 0; + for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) { + size_t optionLength = strlen(options[i]); + size_t argLength = strlen(options[i + 1]); + size_t totalLength = optionLength + argLength; + if (totalLength > maxOptionAndArgLength) { + maxOptionAndArgLength = totalLength; + } + } + for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) { + if (i + 1 < sizeof(options) / sizeof(options[0])) { + rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxOptionAndArgLength); + } + } return 0; } diff --git a/librz/main/rz-gg.c b/librz/main/rz-gg.c index 4d3fb498925..a804eb9bdd5 100644 --- a/librz/main/rz-gg.c +++ b/librz/main/rz-gg.c @@ -8,43 +8,61 @@ #include static int usage(int v) { - printf("Usage: rz-gg [-FOLsrxhvz] [-a arch] [-b bits] [-k os] [-o file] [-I path]\n" + printf("%s%s%s", Color_CYAN, "Usage: ", Color_RESET); + printf("rz-gg [-FOLsrxhvz] [-a arch] [-b bits] [-k os] [-o file] [-I path]\n" " [-i sc] [-e enc] [-B hex] [-c k=v] [-C file] [-p pad] [-q off]\n" " [-S string] [-f fmt] [-nN dword] [-dDw off:hex] file|f.asm|-\n"); if (v) { - printf( - " -a [arch] select architecture (x86, mips, arm)\n" - " -b [bits] register size (32, 64, ..)\n" - " -B [hexpairs] append some hexpair bytes\n" - " -c [k=v] set configuration options\n" - " -C [file] append contents of file\n" - " -d [off:dword] patch dword (4 bytes) at given offset\n" - " -D [off:qword] patch qword (8 bytes) at given offset\n" - " -e [encoder] use specific encoder. see -L\n" - " -f [format] output format (raw, c, pe, elf, mach0, python, javascript)\n" - " -F output native format (osx=mach0, linux=elf, ..)\n" - " -h show this help\n" - " -i [shellcode] include shellcode plugin, uses options. see -L\n" - " -I [path] add include path\n" - " -k [os] operating system's kernel (linux,bsd,osx,w32)\n" - " -L list all plugins (shellcodes and encoders)\n" - " -n [dword] append 32bit number (4 bytes)\n" - " -N [dword] append 64bit number (8 bytes)\n" - " -o [file] output file\n" - " -O use default output file (filename without extension or a.out)\n" - " -p [padding] add padding after compilation (padding=n10s32)\n" - " ntas : begin nop, trap, 'a', sequence\n" - " NTAS : same as above, but at the end\n" - " -P [size] prepend debruijn pattern\n" - " -q [fragment] debruijn pattern offset\n" - " -r show raw bytes instead of hexpairs\n" - " -s show assembler\n" - " -S [string] append a string\n" - " -v show version\n" - " -w [off:hex] patch hexpairs at given offset\n" - " -x execute\n" - " -X [hexpairs] execute rop chain, using the stack provided\n" - " -z output in C string syntax\n"); + const char *options[] = { + // clang-format off + "-a", "[arch]" ,"select architecture (x86, mips, arm)", + "-b", "[bits]" ,"register size (32, 64, ..)", + "-B", "[hexpairs]" ,"append some hexpair bytes", + "-c", "[k=v]" ,"set configuration options", + "-C", "[file]" ,"append contents of file", + "-d", "[off:dword]" ,"patch dword (4 bytes) at given offset", + "-D", "[off:qword]" ,"patch qword (8 bytes) at given offset", + "-e", "[encoder]" ,"use specific encoder. see -L", + "-f", "[format]" ,"output format (raw, c, pe, elf, mach0, python, javascript)", + "-F", "" ,"output native format (osx=mach0, linux=elf, ..)", + "-h", "" ,"show this help", + "-i", "[shellcode]" ,"include shellcode plugin, uses options. see -L", + "-I", "[path]" ,"add include path", + "-k", "[os]" ,"operating system's kernel (linux,bsd,osx,w32)", + "-L", "" ,"list all plugins (shellcodes and encoders)", + "-n", "[dword]" ,"append 32bit number (4 bytes)", + "-N", "[dword]" ,"append 64bit number (8 bytes)", + "-o", "[file]" ,"output file", + "-O", "" ,"use default output file (filename without extension or a.out)", + "-p", "[padding]" ,"add padding after compilation (padding=n10s32)", + "", "" ,"ntas : begin nop, trap, 'a', sequence", + "", "" ,"NTAS : same as above, but at the end", + "-P", "[size]" ,"prepend debruijn pattern", + "-q", "[fragment]" ,"debruijn pattern offset", + "-r", "" ,"show raw bytes instead of hexpairs", + "-s", "" ,"show assembler", + "-S", "[string]" ,"append a string", + "-v", "" ,"show version", + "-w", "[off:hex]" ,"patch hexpairs at given offset", + "-x", "" ,"execute", + "-X", "[hexpairs]" ,"execute rop chain, using the stack provided", + "-z", "" ,"output in C string syntax", + // clang-format on + }; + size_t maxOptionAndArgLength = 0; + for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) { + size_t optionLength = strlen(options[i]); + size_t argLength = strlen(options[i + 1]); + size_t totalLength = optionLength + argLength; + if (totalLength > maxOptionAndArgLength) { + maxOptionAndArgLength = totalLength; + } + } + for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) { + if (i + 1 < sizeof(options) / sizeof(options[0])) { + rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxOptionAndArgLength); + } + } } return 1; } diff --git a/librz/main/rz-hash.c b/librz/main/rz-hash.c index 951a68215ec..fcf5e86ba70 100644 --- a/librz/main/rz-hash.c +++ b/librz/main/rz-hash.c @@ -71,40 +71,58 @@ typedef struct rz_hash_context { typedef bool (*RzHashRun)(RzHashContext *ctx, RzIO *io, const char *filename); static void rz_hash_show_help(bool usage_only) { - printf("Usage: rz-hash [-vhBkjLq] [-b S] [-a A] [-c H] [-E A] [-D A] [-s S] [-x S] [-f O] [-t O] [files|-] ...\n"); + printf("%s%s%s", Color_CYAN, "Usage: ", Color_RESET); + printf("rz-hash [-vhBkjLq] [-b S] [-a A] [-c H] [-E A] [-D A] [-s S] [-x S] [-f O] [-t O] [files|-] ...\n"); if (usage_only) { return; } - printf( - " -v Shows version\n" - " -h Shows this help page\n" - " - Input read from stdin instead from a file\n" - " -a algo Hash algorithm to use and you can specify multiple ones by\n" - " appending a comma (example: sha1,md4,md5,sha256)\n" - " -B Outputs the calculated value for each block\n" - " -b size Sets the block size\n" - " -c value Compare calculated value with a given one (hexadecimal)\n" - " -e endian Sets the endianness (default: 'big' accepted: 'big' or 'little')\n" - " -D algo Decrypt the given input; use -S to set key and -I to set IV (if needed)\n" - " -E algo Encrypt the given input; use -S to set key and -I to set IV (if needed)\n" - " -f from Starts the calculation at given offset\n" - " -t to Stops the calculation at given offset\n" - " -I iv Sets the initialization vector (IV)\n" - " -i times Repeat the calculation N times\n" - " -j Outputs the result as a JSON structure\n" - " -k Outputs the calculated value using openssh's randomkey algorithm\n" - " -L List all algorithms\n" - " -q Sets quiet mode (use -qq to get only the calculated value)\n" - " -S seed Sets the seed for -a, use '^' to append it before the input, use '@'\n" - " prefix to load it from a file and '-' from read it\n" - " -K key Sets the hmac key for -a and the key for -E/-D, use '@' prefix to\n" - " load it from a file and '-' from read it\n" - " from stdin (you can combine them)\n" - " -s string Input read from a zero-terminated string instead from a file\n" - " -x hex Input read from a hexadecimal value instead from a file\n" - "\n" - " All the inputs (besides -s/-x/-c) can be hexadecimal or strings\n" - " if 's:' prefix is specified\n"); + const char *options[] = { + // clang-format off + "-v", "", "Shows version", + "-h", "", "Shows this help page", + "-", "", "Input read from stdin instead from a file", + "-a", "algo", "Hash algorithm to use and you can specify multiple ones by", + "", "", "appending a comma (example: sha1,md4,md5,sha256)", + "-B", "", "Outputs the calculated value for each block", + "-b", "size", "Sets the block size", + "-c", "value", "Compare calculated value with a given one (hexadecimal)", + "-e", "endian", "Sets the endianness (default: 'big' accepted: 'big' or 'little')", + "-D", "algo", "Decrypt the given input; use -S to set key and -I to set IV (if needed)", + "-E", "algo", "Encrypt the given input; use -S to set key and -I to set IV (if needed)", + "-f", "from", "Starts the calculation at given offset", + "-t", "to", "Stops the calculation at given offset", + "-I", "iv", "Sets the initialization vector (IV)", + "-i", "times", "Repeat the calculation N times", + "-j", "", "Outputs the result as a JSON structure", + "-k", "", "Outputs the calculated value using openssh's randomkey algorithm", + "-L", "", "List all algorithms", + "-q", "", "Sets quiet mode (use -qq to get only the calculated value)", + "-S", "seed", "Sets the seed for -a, use '^' to append it before the input, use '@'", + "", "", "prefix to load it from a file and '-' from read it", + "-K", "key", "Sets the hmac key for -a and the key for -E/-D, use '@' prefix to", + "", "", "load it from a file and '-' from read it", + "", "", "from stdin (you can combine them)", + "-s", "string", "Input read from a zero-terminated string instead from a file", + "-x", "hex", "Input read from a hexadecimal value instead from a file", + "", "", "", + "", "", "All the inputs (besides -s/-x/-c) can be hexadecimal or strings", + "", "", "if 's:' prefix is specified", + // clang-format on + }; + size_t maxOptionAndArgLength = 0; + for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) { + size_t optionLength = strlen(options[i]); + size_t argLength = strlen(options[i + 1]); + size_t totalLength = optionLength + argLength; + if (totalLength > maxOptionAndArgLength) { + maxOptionAndArgLength = totalLength; + } + } + for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) { + if (i + 1 < sizeof(options) / sizeof(options[0])) { + rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxOptionAndArgLength); + } + } } static void rz_hash_show_algorithms(RzHashContext *ctx) { diff --git a/librz/main/rz-sign.c b/librz/main/rz-sign.c index ac5d2d36058..3f83792bbb7 100644 --- a/librz/main/rz-sign.c +++ b/librz/main/rz-sign.c @@ -12,16 +12,35 @@ enum rz_sign_option { }; static void rz_sign_show_help(void) { - printf("Usage: rz-sign [options] [file]\n" - " -h this help message\n" - " -a [-a] add extra 'a' to analysis command (available only with -o option)\n" - " -e [k=v] set an evaluable config variable (available only with -o option)\n" - " -c [output.pat] [input.sig] parses a FLIRT signature and converts it to its other format\n" - " -o [output.sig] [input.bin] performs an analysis on the binary and generates the FLIRT signature.\n" - " -d [flirt.sig] parses a FLIRT signature and dump its content\n" - " -q quiet mode\n" - " -v show version information\n" - "Examples:\n" + printf("%s%s%s", Color_CYAN, "Usage: ", Color_RESET); + printf("rz-sign [options] [file]\n"); + const char *options[] = { + // clang-format off + "-h", "", "this help message", + "-a", "[-a]", "add extra 'a' to analysis command (available only with -o option)", + "-e", "[k=v]", "set an evaluable config variable (available only with -o option)", + "-c", "[output.pat] [input.sig]", "parses a FLIRT signature and converts it to its other format", + "-o", "[output.sig] [input.bin]", "performs an analysis on the binary and generates the FLIRT signature.", + "-d", "[flirt.sig]", "parses a FLIRT signature and dumps its content", + "-q", "", "quiet mode", + "-v", "", "show version information", + // clang-format on + }; + size_t maxOptionAndArgLength = 0; + for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) { + size_t optionLength = strlen(options[i]); + size_t argLength = strlen(options[i + 1]); + size_t totalLength = optionLength + argLength; + if (totalLength > maxOptionAndArgLength) { + maxOptionAndArgLength = totalLength; + } + } + for (int i = 0; i < sizeof(options) / sizeof(options[0]); i += 3) { + if (i + 1 < sizeof(options) / sizeof(options[0])) { + rz_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxOptionAndArgLength); + } + } + printf("Examples:\n" " rz-sign -d signature.sig\n" " rz-sign -c new_signature.pat old_signature.sig\n" " rz-sign -o libc.sig libc.so.6\n"); diff --git a/librz/util/print.c b/librz/util/print.c index c692ff46267..fe3441ce732 100644 --- a/librz/util/print.c +++ b/librz/util/print.c @@ -1484,3 +1484,17 @@ RZ_API RZ_OWN RzStrBuf *rz_print_colorize_asm_str(RZ_BORROW RzPrint *p, const Rz } return out; } + +// Prints a help option with the option/arg strings colorized and aligned to a max length. +RZ_API void rz_print_colored_help_option(const char *option, const char *arg, const char *description, size_t maxOptionAndArgLength) { + size_t optionWidth = strlen(option); + size_t maxSpaces = maxOptionAndArgLength + 2; + printf(Color_GREEN " %-.*s" Color_RESET, (int)optionWidth, option); + size_t remainingSpaces = maxSpaces - optionWidth; + if (RZ_STR_ISNOTEMPTY(arg)) { + printf(Color_YELLOW " %-s " Color_RESET, arg); + remainingSpaces -= strlen(arg) + 2; + } + printf("%-*.*s", (int)remainingSpaces, (int)remainingSpaces, ""); + printf(Color_RESET "%s\n", description); +}