Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to not use calling the external commands unless necessary #1223

Open
1 of 16 tasks
XVilka opened this issue Jun 18, 2021 · 2 comments
Open
1 of 16 tasks

Refactor to not use calling the external commands unless necessary #1223

XVilka opened this issue Jun 18, 2021 · 2 comments
Labels
API cmd-api Switch from cmd calls to API high-priority refactor Refactoring requests Tracking Issue tracks a progress

Comments

@XVilka
Copy link
Member

XVilka commented Jun 18, 2021

There is a bunch of rz_sys_cmd*() calls in the librz/ while most of them unnecessary and can be achieved with the calling of the API function.

There are two categories of such calls - calling of the internal utils, e.g. rz-bin, and calling of the external tools, e.g. cp or move.

[i] ℤ rg "rz_sys_cmd*" librz                                                                                                                                                                                                      11:49:26 
librz/cons/cons.c
	:1000: rz_sys_cmd_str_full(I.pager, CTX(buffer), NULL, NULL, NULL);
librz/util/sys.c
	:324: ret = rz_sys_cmd_str(cmd, NULL, NULL);
	:899: if (rz_sys_cmd_str_full(cmd, input, &output, len, NULL)) {
librz/util/file.c
	:1227: int rc = rz_sys_cmdf("cp -f '%s' '%s'", src2, dst2);
librz/io/p/io_winedbg.c
	:144: rz_sys_cmdf("pkill rz-run");
librz/egg/egg_Cfile.c
	:283: output = rz_sys_cmd_strf("rz-bin -o '%s.text' -O d/S/'%s' '%s'.o",
	:307: output = rz_sys_cmd_strf("'%s' -j .text -O binary '%s.o' '%s.text'",
librz/arch/p/asm/asm_x86_nasm.c
	:33: if (!rz_sys_cmdf("nasm %s -o %s", ipath, opath)) {
librz/socket/socket.c
	:258: int res = rz_sys_cmdf("rz-run system=\"%s\" listen=%d", a, port);
librz/socket/run.c
	:219: char *tmp = rz_sys_cmd_str(copy + 1, NULL, NULL);
	:227: char *tmp = rz_sys_cmd_str(copy + 1, NULL, NULL);
	:245: char *tmp = rz_sys_cmd_str(copy + 2, NULL, NULL);
librz/socket/socket_http.c
	:205: int ret = rz_sys_cmd_str_full(command, NULL, &res, &len, &err);
librz/include/rz_util/rz_sys.h
	:145: // #define rz_sys_cmd_str(cmd, input, len) rz_sys_cmd_str_full(cmd, input, len, 0)
librz/core/cmd/cmd_debug.c
	:1081: res = rz_sys_cmd_strf("env RZ_BIN_PREFIX=\"%s\" rz-bin %s-B 0x%08" PFMT64x " -S \"%s\" | grep \"%s\"", name, mode, baddr, filesc, sect);
	:1084: res = rz_sys_cmd_strf("env RZ_BIN_PREFIX=\"%s\" rz-bin %s-B 0x%08" PFMT64x " -S \"%s\"", name, mode, baddr, filesc);
librz/core/cmd/cmd.c
	:585: rz_sys_cmd_str_full(shell_cmd + 1, str, &out, &olen, NULL);
	:1311: rz_sys_cmdf("%s '%s'", editor, str);
	:5020: rcmd = buf = rz_sys_cmd_str(command, 0, &len);
librz/core/tui/define.c
	:215: rz_sys_cmdf("man %s", man);
librz/core/core.c
	:2328: rz_sys_cmdf("%s \"%s\"", editor, escaped_name);
librz/core/rtr_http.c
	:382: rz_sys_cmdf("%s http://%s:%d/%s &",
librz/main/rz-find.c
	:409: rz_sys_cmdf("rizin"
	:421: rz_sys_cmdf("rizin -qc \"/E %s\" \"%s\"", kw, efile);

Todo

Note though, that some of them are legit.
Tick the once which are, otherwise link PR.

  • librz/cons/cons.c
  • librz/util/sys.c
  • librz/util/file.c
  • librz/io/p/io_winedbg.c
  • librz/egg/egg_Cfile.c
  • librz/arch/p/asm/asm_x86_nasm.c
  • librz/socket/socket.c
  • librz/socket/run.c
  • librz/socket/socket_http.c
  • librz/include/rz_util/rz_sys.h
  • librz/core/cmd/cmd_debug.c - Also Convert i/rz-bin calls inside Rizin to the API calls #1475
  • librz/core/cmd/cmd.c - Necessary: open editor, or non-Rizin command execution.
  • librz/core/tui/define.c
  • librz/core/core.c
  • librz/core/rtr_http.c
  • librz/main/rz-find.c
@karliss

This comment has been minimized.

@XVilka

This comment has been minimized.

@ret2libc ret2libc added the cmd-api Switch from cmd calls to API label Sep 3, 2021
@Rot127 Rot127 added the Tracking Issue tracks a progress label Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API cmd-api Switch from cmd calls to API high-priority refactor Refactoring requests Tracking Issue tracks a progress
Development

No branches or pull requests

4 participants