Skip to content

Conversation

@SverkerBerggren
Copy link
Contributor

@SverkerBerggren SverkerBerggren commented Nov 5, 2025

  • Mark this if you consider it ready to merge
  • I've added tests (optional)
  • I wrote some lines in the book (optional)

Description

When starting radare with the -i option to execute a script, so did the alias for registers not work correctly for math operations such as "? rbp". The reason, as I understand it, is that when a debugger is attached, so is a part of the setup to set all the registers as flags using the ".dr*" command, but that on startup just sets them all to 0x0. Later, when the token's numerical value is fetched, so does it first lookup flags rather than registers, which means it always gets the flag value. This makes it so that using "? rbp" in a -i script will always yield 0x0.

The reason why it works normally otherwise as I understand it, is because during the regular command loop so does it always execute a certain number of commands after each user inputed command, and one of them is ".dr*" which makes the register flags always up to date.

The way to fix this issue would be either to make it so that the same "cleanup" commands are executed after each -i command in the startup script, or the suggested change that I made, which I find to be less intrusive. It does, on the other hand, change the way that "? rbp" is executed in almost all scenarios, but I do not feel that I have the knowledge to say if that is necessarily a bad thing.

This pull request also includes a commit that was supposed to me made in this previous pull request but I did not push it before it was merged. #24767

@SverkerBerggren SverkerBerggren changed the title Main Change the order where register aliases fetch their numeric value to prioritize r_reg_get over r_flag_get ##radare2 Nov 5, 2025
@trufae
Copy link
Collaborator

trufae commented Nov 5, 2025

Do not do merge commits. Always rebase

@trufae
Copy link
Collaborator

trufae commented Nov 5, 2025

There r 2 ways to fix that:

  • use the $r:regname prefix
  • Hook the rregget callback to the flagitems associated with registers

@trufae
Copy link
Collaborator

trufae commented Nov 5, 2025

The problem of the first is that it is different symtax, the problem of the second is that it will slowdown the thing because it will sync regs all the time unless we mark a dirty bit somewhere to avoid syncing the regs all the time

@SverkerBerggren
Copy link
Contributor Author

I tried to follow the instructions regarding rebasing but I am not a git wizard. Is there any action that needs to be taken to fix this branch now or?

I personally prefer the second approach you describe because I value that scripting works as similar to the interactive mode as possible, I think it is very hard for a new user to debug and understand the nuances in how the context of the invocation of the commands affect their output, but that is just my opinion.

Is r_reg_get and r_reg_get_value expensive operations compared to r_flag_get? The changes I have in this pull request resolved the issue for me, but do you think that this solution is undesirable because of performance?

I would otherwise be willing to test to implement the dirty bit solution, but is there a way to know which commands affect the state of the binary? Continuing the execution of the program would I guess always need to set the registers dirty, but just seeking to an adress would not.

@trufae
Copy link
Collaborator

trufae commented Nov 7, 2025

sorry rebase again please

@trufae
Copy link
Collaborator

trufae commented Nov 7, 2025

rebase

@SverkerBerggren
Copy link
Contributor Author

I have seen on some other pull requests that not all tests have been successful, but are there tests here that should pass unless my changes introduced some bugs?

@trufae
Copy link
Collaborator

trufae commented Nov 11, 2025

your pr introduces bugs:


[XX] /home/runner/work/radare2/radare2/test/db/cmd/cmd_pa asm/callflag
R2_NOPLUGINS=1 radare2 -escr.utf8=0 -escr.color=0 -escr.interactive=0 -NN -Qc 'e asm.arch=x86
f eax=33
pa call eax
f test=eax
pa call test
' -
-- stdout
@@ -1,2 +1,2 @@
 ffd0
-e81c000000
+e8fbffffff

this is clearly eax not being usable as a normal flag because its hooked by the rreg api so it fails and returns -1.
also your patch doesnt pass the sys/lint.sh linter with this error:

libr/core/numvars.inc.c:1019:			

^thats an empty line with trailing spaces

Copy link
Collaborator

@trufae trufae left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes look good. can you rebase, apply the fixes and take care of the broken tests? maybe the way to fix those tests is by adding a config var to disable this behaviour by default for now. and we can enable it when running in debug mode , but i wont include that change in this release.

the timeout thing is somthing that should be merged before the rls

if ((flag = r_flag_get (core->flags, str))) {
ret = flag->addr;
// check for reg alias
RRegItem *r = r_reg_get (core->dbg->reg, str, -1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can also use r_reg_getv

return false;
}
r_socket_block_time(fd, true, 99999, 0);
r_socket_block_time(fd, true, 0, 0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
r_socket_block_time(fd, true, 0, 0);
r_socket_block_time (fd, true, 0, 0);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants