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

Convert i/rz-bin calls inside Rizin to the API calls #1475

Open
Tracked by #4738
XVilka opened this issue Aug 18, 2021 · 5 comments · Fixed by #2441
Open
Tracked by #4738

Convert i/rz-bin calls inside Rizin to the API calls #1475

XVilka opened this issue Aug 18, 2021 · 5 comments · Fixed by #2441
Assignees
Labels
cmd-api Switch from cmd calls to API high-priority refactor Refactoring requests RzBin Tracking Issue tracks a progress

Comments

@XVilka
Copy link
Member

XVilka commented Aug 18, 2021

librz/main/rz-find.c
409:		rz_sys_cmdf("rizin"
421:			rz_sys_cmdf("rizin -qc \"/E %s\" \"%s\"", kw, efile);

librz/egg/egg_Cfile.c
289:    output = rz_sys_cmd_strf("rz-bin -o '%s.text' -O d/S/'%s' '%s'.o",

librz/core/cmd_debug.c
1673:                           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);
1676:                           res = rz_sys_cmd_strf("env RZ_BIN_PREFIX=\"%s\" rz-bin %s-B 0x%08" PFMT64x " -S \"%s\"", name, mode, baddr, filesc);

Originally posted by @XVilka in #1238 (comment)

I have removed the following: ``` librz/core/cmd_info.c 703: rz_sys_cmdf("rz-bin -O \"%s\" \"%s\"", rz_str_trim_head_ro(input + 1), desc->name); 706: rz_sys_cmdf("rz-bin -O help"); ```

because those are not i commands.

@ret2libc ret2libc modified the milestones: 0.3.0, 0.4.0 Sep 3, 2021
@ret2libc ret2libc added the cmd-api Switch from cmd calls to API label Sep 3, 2021
@ret2libc
Copy link
Member

I didn't see any work on this during this time, so I doubt it will be done for 0.4.0.
I'm removing the 0.4.0 milestone for now until someone starts to actively looking at this.

cc @XVilka

@ret2libc ret2libc removed this from the 0.4.0 milestone Feb 10, 2022
@XVilka
Copy link
Member Author

XVilka commented Mar 24, 2022

Only partially resolved.

@ret2libc ret2libc removed their assignment Mar 17, 2023
@Rot127 Rot127 moved this from To do to In progress in Switch from command calls to the API Nov 28, 2024
@Rot127
Copy link
Member

Rot127 commented Nov 28, 2024

Fixing the cmd_debug.c case it not possible easily.

The issue is fundamentally that Core and Bin are not separated well enough.
RzCoreBin implements the whole printing of sections and other stuff.
The RzCoreBin API always requires a RzCore pointer passed and uses
'core->io', 'core->bin', 'core->hash' everywhere.

RzCore is built with the assumption, that the binary registered with RzCore
(via core->io, core->bin etc.) is the only binary in the whole universe of interest.

But the command dmS should not just list the sections of the debugged binary,
but also of the libraries dynamically loaded.
So this assumption becomes wrong.

We can't just close the current binary and open the library file,
just for listing sections. Because we are in live debug mode.

The current dmS implementation avoids this by simply calling rz-bin
and indirectly spawning a RzCore in a new process for each binary we want the sections of.

Creating a new RzCore for each binary of interest is not possible,
because RzCore is not thread save.

In short: To fix this RzCoreBin needs to be separated properly.
Which is a little bigger task.

@Rot127
Copy link
Member

Rot127 commented Nov 29, 2024

Same problem for egg_Cfile.c unfortunately.

The other one is a search. It makes more sense to refactor the search before removing it.

@Rot127 Rot127 self-assigned this Nov 29, 2024
@Rot127 Rot127 added the Tracking Issue tracks a progress label Nov 29, 2024
@Rot127 Rot127 moved this from In progress to To do in Switch from command calls to the API Nov 29, 2024
@Rot127
Copy link
Member

Rot127 commented Nov 30, 2024

So the cmd_debug.c could be resolved apparently. I found a case where they simply backed up core->bin, set it to the library object, read symbols and other stuff and then set it again to the currently debugged binary. I guess it works. But who knows if this has consequences (e.g. due to a state change in RzIO). So it could be fixed, but wouldn't feel confortable with it.
If we do this hacky solution now, we maybe forget fixing it properly in the future? Would you agree?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmd-api Switch from cmd calls to API high-priority refactor Refactoring requests RzBin Tracking Issue tracks a progress
Development

Successfully merging a pull request may close this issue.

3 participants