rizinorg / rizin

UNIX-like reverse engineering framework and command-line toolset.
https://rizin.re
GNU Lesser General Public License v3.0
2.53k stars 342 forks source link

Refactor Visual mode (`librz/core/tui/visual.c`) to use API instead of commands #382

Open XVilka opened 3 years ago

XVilka commented 3 years ago

Currently, the code of Visual modes heavily relies on running commands instead of just calling the proper API functions. To reduce the overhead, code cruft, and code breakage in case of the command changes it is important to remove all those command calls and call the proper API directly.

[i] ℤ rg "rz_core_cmd[0f_]*\(" librz/core/tui/visual.c                                                                                                                                                                                 12:21:36 
683:          rz_core_cmd(core, buf, 0);
715:                  ch = rz_core_cmd0(core, cmd);
723:                  ch = rz_core_cmd0(core, cmd);
731:                  ch = rz_core_cmd0(core, cmd);
737:                  ch = rz_core_cmd0(core, cmd);
748:                  ch = rz_core_cmd0(core, cmd);
754:                  ch = rz_core_cmd0(core, cmd);
760:                  ch = rz_core_cmd0(core, cmd);
768:                  ch = rz_core_cmd0(core, cmd);
776:                  ch = rz_core_cmd0(core, cmd);
784:                  ch = rz_core_cmd0(core, cmd);
790:                  ch = rz_core_cmd0(core, cmd);
796:                  ch = rz_core_cmd0(core, cmd);
1992:                 rz_core_cmd0(core, "eco $(eco~...)");
1998:                 rz_core_cmd0(core, "s $(afb~...)");
2002:                 rz_core_cmd0(core, "s $(ii~...)");
2005:                 rz_core_cmd0(core, "s $(isq~...)");
2008:                 rz_core_cmd0(core, "s $(dm~...)");
2017:                 rz_core_cmdf(core, "sh~...");
2249:                         rz_core_cmd(core, buf, true);
2502:                         rz_core_cmd(core, buf, 0);
2529:                 rz_core_cmd(core, buf, 1);
2800:                         rz_core_cmd0(core, key_s);
2808:                         rz_core_cmd0(core, key_s);
2914:                                 rz_core_cmd(core, buf, 0);
2938:                                 rz_core_cmd(core, buf, 0);
3656:                 rz_core_cmd0(core, vi);
3670:         rz_core_cmd0(core, vi);
3712:                 rz_core_cmd0(core, cmd_str);
3841:         int ret = rz_core_cmd0(core, cmd);
officialcjunior commented 3 years ago

rz_core_cmd0(core, "pg");

For the above command, if this is what's getting executed, I can get an API just for that, I suppose. Same calls are in agraph as well.

ret2libc commented 3 years ago

I think this can probably be moved to a later release. It's just refactoring and we seem to have already a lot of things in our hands.