-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
There seems to be no way to determine the base of a number when there are no analysis hints defined #17727
Comments
Do you need a command? Or is an API enough for Cutter? Because adding a command just for this seems a bit overkill to me, but an API can be easily added. Also, having a RAnalHint for each instruction that has a number could be too much to store IMO. |
I'm still a beginner so I'm not sure (I believe that Cutter communicates with radare using commands?). |
Ok, I guess Cutter uses radare2 API after all (not sure why this wasn't obvious for me), only some actions are performed by commands. I guess an API would be enough then. |
@trufae considering guessing which base is used by each disassembler seem like a very bad solution, maybe we could enforce a "r2 rule" for immediates. For example, numbers <10 are showed in decimal, without 0x, while numbers >= 10 are shown in hexadecimal, with 0x. This would have the disadvantage of always having some filter operations on instructions, but it would ensure consistency and it would avoid having RAnalHints saved everywhere. By having this hard rule, it would be very easy for r2 to provide an API that gets the base used by an instruction. WDYT? |
This rule is defined in sdb already, and capstone have a similar behaviour i think |
Where exactly? Could you point to where this is done? I know capstone uses the same behaviour, but as we don't support only capstone we should provide a consistent behaviour across disassemblers probably. |
A quick grep spotted this:
also this thing was discussed in the capstone repo as well |
Sorry, I'm not sure I understand. What has |
I checked this with a couple of disassemblers and for me, it seems like the way the immediates are formatted by default is dependent on the disassembler. For example, x86 usually outputs immediates below 10 as decimals, brainfuck outputs all immediates as decimals, in GNU PowerPC it's dependent on the instruction ( What would also help me solve this issue (and another one related to that cutter pull request) is having an api/command to get the immediates with the formatting applied. I'm not sure if such a feature could be implemented easily, are the immediate base analysis hints converted to some kind of configuration that's passed to external disassemblers? Or are those hints used only in radare when displaying the assembly? (Also, I noticed that |
This. However, in some cases we also pass some options to the disassembler. For example to x86 capstone we pass an option to specify to always use hexadecimal IIRC. |
How do you suggest to proceed with this issue? I am sure that @plaets is not the only one who is confused regarding this. Me as well. Do we have a way to determine the base of the number without analysis hints everywhere? |
if the number starts with 0x its hexadecimal, otherwise it's decimal. that's the way to determine the base number if no hints are defined, you can't rely on all the disassembler engines or parse plugins to behave the same way because users can modify them, and there's no need to overengineer this simple topic |
I'm trying to implement a hotkey to toggle the immediate base in Cutter. For the hotkey to always work correctly, I need to obtain the current immediate base for the selected instruction. However, there seems to be no way to get that information, unless an analysis hint was defined for that particular address earlier.
The only alternative I have considered is parsing the opcode, but I'm not sure if that's a good idea (radare supports many different instruction sets, syntaxes, and disassemblers).
aoj
/ao
does not seem to be useful in this case either.See https://github.com/radareorg/cutter/pull/2429#issuecomment-699868626 :
@ret2libc
Expected behavior
(Or maybe a different command to get the default immediate base or other information that could be useful in this case)
Actual behavior
Related to
https://github.com/radareorg/cutter/pull/2429
The text was updated successfully, but these errors were encountered: