Skip to content

Commit

Permalink
adding exception for our help strings in clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
byteninjaa0 committed Jan 8, 2024
1 parent c4096c8 commit 13f17b9
Show file tree
Hide file tree
Showing 9 changed files with 347 additions and 338 deletions.
2 changes: 1 addition & 1 deletion librz/include/rz_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ RZ_API RZ_OWN char *rz_core_print_dump_str(RZ_NONNULL RzCore *core, RzOutputMode
RZ_API RZ_OWN char *rz_core_print_hexdump_or_hexdiff_str(RZ_NONNULL RzCore *core, RzOutputMode mode, ut64 addr, int len, bool use_comment);
RZ_API RZ_OWN char *rz_core_print_hexdump_byline_str(RZ_NONNULL RzCore *core, bool hex_offset, ut64 addr, int len, ut8 size);
RZ_API RZ_OWN char *rz_core_print_bytes_with_inst(RZ_NONNULL RzCore *core, RZ_NONNULL const ut8 *buf, ut64 addr, int len);
RZ_API void rz_core_print_colored_help_option(const char *option, const char *arg, const char *description,size_t maxOptionAndArgLength);
RZ_API void rz_core_print_colored_help_option(const char *option, const char *arg, const char *description, size_t maxOptionAndArgLength);

typedef enum {
RZ_CORE_DISASM_STRINGS_MODE_BYTES = 0,
Expand Down
115 changes: 58 additions & 57 deletions librz/main/rizin.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,70 +94,71 @@ static int main_help(int line) {
if (line < 2) {
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");

" [-s addr] [-B baddr] [-m maddr] [-c cmd] [-e k=v] file|pid|-|--|=\n");
}
if (line != 1) {
const char *options[] = {
"--","","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 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) {
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_core_print_colored_help_option(options[i], options[i + 1], options[i + 2],maxOptionAndArgLength);
rz_core_print_colored_help_option(options[i], options[i + 1], options[i + 2], maxOptionAndArgLength);
}
}
}
Expand Down
90 changes: 46 additions & 44 deletions librz/main/rz-asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,61 +171,63 @@ static int rasm_show_help(int v) {
if (v < 2) {
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");
" [-f file] [-F fil:ter] [-i skip] [-l len] 'code'|hex|-\n");
}
const char *options[] = {
"-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 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) {
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) {
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_core_print_colored_help_option(options[i], options[i + 1], options[i + 2],maxOptionAndArgLength);
rz_core_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 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();
Expand Down
Loading

0 comments on commit 13f17b9

Please sign in to comment.