1

Frequently when I use Radare2 I work mostly in hexadecimal. This means I'm constantly having to remember to type 0x in front of addresses, which is different from the machine-language monitors I'm used to using. (I'm generally working with binaries for 8-bit systems, where decimal is rarely used when working in machine language.)

Is there any way to set the default input radix to hexadecimal? I'd like to be able to type s ff00 instead of s 0xff00 at the command line, and gff00 instead of g0xff00 in visual mode.

And if I can do this, how does one enter decimal numbers, should that be necessary, in this mode?

Links to documentation are appreciated.

2 Answers 2

1

I suppose there is no such option currently in radare2 (though more experienced radare2 contributors would tell it for sure).

However, if you are really annoyed by having to type 0x's in front every single time, you can perform a temporary (very hacky) solution. To do so, you can modify the libr/core/cmd_seek.c file (which is responsible for handling seek command) as follows: r2SeekHAck

And then use make to compile the project. After this, you will get the feature you want (will also work with g in Visual Mode):

r2HexSeekHack

You can find the patch code below:

ut64 addr;
if ((input[1] >= '1' && input[1] <= '9') || (input[1] >= 'a' && input[1] <= 'f'))
{
    char inputHex[strlen(input) + 1];
    inputHex[0] = '0';
    inputHex[1] = 'x';
    int i = 2;
    for (; i < strlen(input) + 1; i++)
        inputHex[i] = input[i - 1];
    addr = r_num_math (core->num, inputHex);
} 
else
     addr = r_num_math (core->num, input + 1);
0
1

i cant say how much helpful this is but you can set e asm.tailsub=true and use .. instead of 0x
(this is not actually replacing the 0x it is tail substitution)

that is it will seek to +0x10 if you do s .. 10 from current seek or seek 0x100 if you do s ..100 or seek 0x1000 if you do s ..1000

it only substitutes the tail we are abusing this by substituting the whole body see the edit just so if you were wondering how are why

like

radare2 c:\Windows\System32\calc.exe
 -- Enable asm.trace to see the tracing information inside the disassembly
[0x140001820]> e asm.tailsub
false
[0x140001820]> s 1400018f0
Cannot seek to unknown address '1400018f0'
[0x140001820]> e asm.tailsub = true
[0x140001820]> s ..1400018f0
[0x1400018f0]>   

edit as explanation for what is .. or tailsub

[0x100000000]

> s entry0
[0x140001820]> s ..1337
[0x140001337]> s ..99999
[0x140099999]>  
3
  • Would you be able to provide a link to the documentation on asm.tailsub? I'm not entirely clear on exactly how it works, and a search of the Radare2 book provides no results for "tailsub." It does look like it might be useful beyond just allowing me to default to hex radix.
    – cjs
    Commented May 30, 2020 at 11:15
  • asm.tailsub doesn't seem strictly related to the .. syntax. I've conformed with e asm.tailsub that it's false and yet I can use commands such as s ..c000 (which seeks to 0xc000 on a freshly opened file) and omb. ..c000 (which sets the offset to 0x0c000, sometimes).
    – cjs
    Commented May 30, 2020 at 12:33
  • ok ive seen it acting weird try s someaddr+..f0 it willseek to double the current seek but such is the nature of features that arent production tested
    – blabb
    Commented May 30, 2020 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.