Commit graph

46 commits

Author SHA1 Message Date
Riccardo Schirone
9ba89d8116 core/cmd: rewrite rz_cmd_macro API 2022-08-26 07:53:43 +08:00
Riccardo Schirone
02a0b7a1ad core/cmd: just store RzCore reference instead of void *data 2022-08-26 07:53:43 +08:00
Riccardo Schirone
ac1b0e4d94
core/cmd: fix CHOICES argument selection between choices_cb/choices (#2932) 2022-08-18 20:10:13 +08:00
Riccardo Schirone
f745478fde
Improve suggestions when wrong command/args is used (#2365) 2022-03-02 10:39:33 +01:00
Riccardo Schirone
9df2994127
RzCmd: add support for dynamically generated details sections (#2361)
So far all the help sections were statically generated from the YAML
files, however sometimes you may want to list things in the help
messages that depend on what is loaded in Rizin (e.g. plugins, etc.).
This patch adds support for a details_cb that provides a dynamically
created RzCmdDescDetail array.
2022-02-25 09:25:15 +00:00
Riccardo Schirone
75fc447873
Fix some memleaks in unit tests (#1869)
* Cleanup RzAnalysisRzil when freeing RzAnalysis

* Fix str leaking in rz_core_write_string_at

* Fix buf leaking in rz_core_yank_paste

* Fix memleak in json unit tests

* Fix features leaking in RzBinInfo

* Fix features leaking in RzAsm

* Fix memleaks in RzTable

* Fix test_str_search memleaks

* Fix memleak in test_io.c

* Fix memleaks in RzBuf and test_buf.c

* Fix memleaks in test_cmd.c

* Fix memleaks in test_config.c

* Fix memleaks in RzCons

* Fix hashes leaking in test_bin.c

* Fix memleaks in test_id_storage.c

* Fix memleaks in test_il*.c and adjust APIs
2021-10-22 09:33:20 +08:00
Riccardo Schirone
1172c4085c Re-design the way ? and ?? are used in rzshell
* `<cmd>?` allows to list the sub-commands of <cmd>. If <cmd> has no
  sub-commands, the full help of <cmd> is printed instead.
* `<cmd>??` allows to always list the full help of <cmd>. Useful when
  <cmd> is both the name of a group and a command itself.
* output modes are only listed as part of the full help and not
  considered as sub-commands.
* fix a bug where `<cmd><mode>?` was just printing the list of
  sub-commands of <cmd> instead of the full help of <cmd><mode>.
2021-10-18 11:57:17 +02:00
Riccardo Schirone
a5333f2a44 core/cmd_descs: add support for default_mode
Some commands might have one of the output modes as default one. If
that's the case, RzCmd should be aware of that so that it can
initializes everything needed for that default mode.

For example, if command `c` supports TABLE, JSON and QUIET and you want
to have `c`(with no suffix) print the TABLE mode, the parser would have
to initialize the RzTable data structures anyway, so it must be aware of
it.
2021-08-30 17:31:09 +02:00
Riccardo Schirone
2049360560 RzCmd: add some helper APIs for RzCmdStateOutput 2021-08-30 07:39:21 +02:00
Riccardo Schirone
4183cc4039 core/cmd: add new RzCmdDescType ARGV_STATE 2021-04-21 15:26:35 +02:00
Riccardo Schirone
53bf5c497f SPDX Copyright text for all files based on history
- Add LICENSES directory
- Download additional licenses used
- Add .reuse directory
- Add doc about SPDX/reuse

Co-authored-by: Florian Märkl <info@florianmaerkl.de>
2021-03-05 19:39:15 +08:00
Riccardo Schirone
53be388b8f core: allow to sort subcommands of a command group 2021-03-02 08:44:44 +01:00
Riccardo Schirone
8baacdddf2 core: extract RzCorePlugins from RzCmd to RzCore 2021-03-02 08:44:44 +01:00
Riccardo Schirone
bdd7a990a7 core: RzCmd provides default_value to handler when specified 2021-02-26 12:36:39 +01:00
Riccardo Schirone
42d3b01f09
core: retrieve parents details when not available (#724) 2021-02-26 12:59:43 +08:00
wargio
8005c480b2 Moving java from shlr to core
Removed unused code and comments.
Removed dead code
Moved print method outside class.c
Moved json method outside class.c
Removed yc_w_refs and i_mref which never worked.
Fixed set_flags method to work as intended.
Fixed various parsing errors.
Fixed many memory leaks.
Fixed "insecure" rz_cons_printf warning.
removed `#define V`, `#define U` and `#define _`
Implemented newshell calls.
Optimized code.
Refactoring rz_bin_java_get_field_offsets
Avoid loading static core plugins when not needed.
Removed useless `if 0`
2021-02-25 12:02:20 +01:00
Alexis Ehret
55e3d3ebed Fix dead assignment test/unit/test_cmd.c 2021-02-09 10:37:25 -01:00
wargio
8cfa9e31e3 Support in newshell for <cmd>?*[j] and j*[j] <command> 2021-02-08 01:53:32 +01:00
Anton Kochkov
a0be4e2e64 Run clang-format 2021-01-21 22:05:44 +08:00
Riccardo Schirone
4eae6a0686 Add rz_cmd_desc_get_arg API 2021-01-21 11:15:13 +08:00
Riccardo Schirone
68c9388fb9
Shell error messages improvements (#339)
* Print proper error message when command does not exist

* Improve error messages on wrong arguments or wrong help

* Fix cmd_w test

* Check char * and avoid calling old input commands

* Fix english

* Check for NULLs and fix memleak
2021-01-13 00:28:58 +08:00
Riccardo Schirone
0abb2c8bfc Convert 'e' commands to newshell ##newshell 2021-01-05 23:33:32 -06:00
Riccardo Schirone
296b64e2e9 Add flags to RzCmdArg to mark array, last, option args 2021-01-05 23:33:32 -06:00
Riccardo Schirone
40af504ec1 Fix memory leaks in test_cmd 2021-01-05 23:33:32 -06:00
Liumeo
619a583acc Fix memleak in test_str & test_debug_session (#18164) 2021-01-05 05:21:41 -06:00
Liumeo
d50d0a43a9 Fix memleak in test_buf & test_cmd (#18162) 2021-01-05 05:21:41 -06:00
Riccardo Schirone
a7fd3fa3c6 Use mu_main to reduce boilerplate in unit tests
* Disable colors on Windows because terminal looks bad otherwise
* Use environment on Windows to set PATH and make sure unit tests use
  the compiled libraries and not the installed ones
* Define ssize_t on Windows as well by using SSIZE_T

Update test_analysis_block.c

Update test_intervaltree.c

Update test_unum.c
2021-01-03 11:42:38 +01:00
Riccardo Schirone
31d3fe8e65 Add API to (un)escape arguments and use it to pass commands as arguments
Just use one API to escape/unescape args and pass argument
2020-11-20 09:45:17 +01:00
Riccardo Schirone
c98e393618 Add initial version to complete filenames, env and choices ##newshell
* Add unit test for RzCore autocompletion
2020-11-16 16:19:35 +01:00
Riccardo Schirone
da956fed38
Introduce ARGV_MODES command descriptors ##newshell (#52)
* Use ARGV_MODES in z, zs, zi, and z/
2020-10-28 14:28:17 +01:00
Riccardo Schirone
1ce181a56f
Add argument descriptions for each command ##newshell (#47)
Describe the list of arguments each command expects, so we can
automatically construct the argument strings in the help messages.
These info can also be used to check the user is passing the right
number of arguments to commands, auto completion, etc.
2020-10-27 10:12:52 +01:00
Riccardo Schirone
5595b55b22 Wrap summaries when displaying help ##newshell
When the summary cannot be placed on a single line of the screen and the
user is in interactive mode, this PR ensures the summary of the command
wraps in the best possible way, without ruining the alignment.
2020-10-13 10:52:57 +02:00
Riccardo Schirone
0ce940130d Few fixes to newshell
- Rename DEFINE_CMD_ARGV_GROUP_WITH_CHILD with .._GROUP_EXEC ##newshell
- Make sure ARGV RzCmdDesc do not have children ##newshell

Also enable WARNING level logs by default, so that warnings generated
during rizin initialization, and before RzConfig is initialized, can be
logged.
2020-10-08 10:03:54 +02:00
Riccardo Schirone
39f39fdcbb Make RzCmdDescExample more generic with RzCmdDescDetail ##newshell
Let's not use that structure just for examples of commands, we can make
it more generic and use it for other detailed section as well (e.g.
`pf??`, `ae??`, etc.)
2020-10-05 16:10:55 +02:00
Riccardo Schirone
cde558e6e5
Convert %, *, env, w6 commands to argv ##newshell (#16)
* No more FS plugins in rizin
* Fix retrieval of cmddesc with GROUP involved ##newshell
* Add w6d/w6e argv-style handlers ##newshell
* Add OLDINPUT_SPECIAL for special characters ##newshell
* Convert % to a argv command ##newshell
* Hide `=` from command handlers that use eq_sep_args ##newshell

Command handlers like `env`, `%` or `*` expect arguments with an equal
as a separator. So far `=` was visible as an arg_identifier to make sure
that existing handlers could still work. This is not required anymore,
as all commands that use eq_sep_args are now converted to a argv-style
handler.

* Convert * command to argv-style ##newshell
2020-10-05 15:43:02 +02:00
Riccardo Schirone
502e91aff7
Rename R_ and R2_ to RZ_ (#8)
* Rename R2_ -> RZ_
* Rename R_ -> RZ_
* Rename R2R_ -> RZ_TEST_
* Rename R2R defines and types to RZ_TEST/RzTest
* Keep R_ for REIL registers
2020-10-02 16:09:13 +02:00
Riccardo Schirone
721609a17b
Rename to rizin (#2) 2020-10-01 16:13:03 +02:00
Riccardo Schirone
72baf0da5c
Split GROUP RCmdDesc and regular ones ##newshell (#17726)
* Convert R_CMD_DESC_TYPE_GROUP to INNER

* Avoid confusing "group_" prefixes by splitting cmddesc ##newshell

Create "group" command descriptor and give them their own help, to avoid
dupping fields such as group_summary, group_args_str, etc. By having a
separate help structure for the grouping node we make the cmd_api code
easier because it doesn't need to distinguish between
group_summary/summary, group_args_str/args_str, etc. and we avoid few
bytes for each command descriptor help structure, since most of them
did not use group_* fields.

* Other simplification in cmd_api due to split GROUP/exec cb.

* Handle R_CMD_DESC_TYPE_GROUP in r_cmd_call_parsed_args
2020-09-30 13:38:30 +08:00
Riccardo Schirone
9b59074787
Automatically group sub-commands ##newshell (#17663)
* Add GROUP RCmdDesc type and fix where the args_str is shown
* Adjust color of `[?]`
* Differentiate between cmd<?> and cmd[?]
<?> when cmd is not valid by itself
[?] when cmd is valid but there are also other sub-commands available
* Fix usage for commands like `w` that are both commands and groups
* Do not automatically switch to detail=2 for leaf commands
* Fix test due to change in `?`/`??` behaviour
2020-09-24 17:50:52 +02:00
Riccardo Schirone
75a80741ee
Make root a argv RCmdDesc ##newshell (#17326) 2020-09-15 15:27:10 +02:00
Riccardo Schirone
652df7f497
Add r_cmd_desc_remove API to unregister commands (#17349) 2020-07-24 14:23:56 +08:00
Riccardo Schirone
2ffa790e0a
Generate help automatically ##newshell (#16782)
* Add additional RCmdStatuses
* ?? should be a cmd_identifier, not help_command
2020-06-17 21:29:23 +02:00
Riccardo Schirone
56f88a0e20
Remove INNER nodes and merge inner node with the command with same name (#16784)
* Remove INNER nodes and merge inner node with the command with same name
* Add test
2020-05-11 10:55:49 +02:00
Riccardo Schirone
03a5c4d3f5
Remove RCoreCmdStatus and just use RCmdStatus (#16774)
* Remove RCoreCmdStatus and just use RCmdStatus
* Assume RCorePlugins returns true/false
2020-05-06 14:38:20 +02:00
Riccardo Schirone
64e6df5004
Extend RCmdDesc with different types (#16738)
* Add RCmdDesc and use it for newshell to call command handlers
* Keep supporting existing RCorePlugin commands
* Properly free RCmdDesc tree
* Remove help from API because not used
* Check for cp->call before using it
* Set res to 0 because otherwise it could exit too early
2020-05-06 14:34:19 +08:00
Riccardo Schirone
169531abb5
Pass parsed arguments directly to RCmd (#16703)
* Remove r_cmd_call_long API because never used
* Remove r_cmd_add_long because never used
* Remove r_cmd_args and fix some spaces
* Add RCmdParsedArgs and unit tests
* Introduce r_cmd_call_parsed_args and use it in cmd.c
* Introduce RCmdParsedArgs in cmd.c
2020-04-24 09:46:43 +02:00