4
#include<stdio.h>
#include<stdlib.h>
int main() {
    puts("Enter input: ");
    char buf[100];
    fgets(buf, 100, stdin);
    printf("%s", buf);
}

Suppose I am debugging a program, such as the one above, where I need to type in some input. Usually, what radare2 does is that it will allow me to type in any ascii input whenever the program demands that I have user input, and it will look like the following:

Enter input: Hello
Hello

However, what if I need to type in hex input? Normally, if I wanted to use hex input for my program outside of radare2, I would use a command that looks like the following:

python -c "print('\x48\x65\x6c\x6c\x6f')" | ./program

But if I am debugging the program with radare2 and use something like \x48\x65\x6c\x6c\x6f as the input, radare2 will literally interpret the backlash x as a string that looks like "\x" instead of interpreting the input as hexadecimal. How would I go about inputting hex while inside of radare2 properly?

  • Look at the documentation of rarun2 – sudhackar Apr 10 at 7:47
4
  • Write the string in a file:

    $ echo -e '\x48\x65\x6c\x6c\x6f' > p.text    
    

    or

    $ python -c "print('\x48\x65\x6c\x6c\x6f')" > p.text   
    
  • Execute radare2:

    $ r2 -d program 
    
  • Once inside of r2 execute dor (an alias for rarun2) and set the stdin to the file:

    [0x7f1a2522a090]> dor stdin=p.text
    [0x7fb15f311e06]> doo # Reopen in debugger mode
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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