4

If I want to debug ls I can run,

radare -d /bin/ls

But, how do I provide an argument or parameter to ls? Like I would do if I wanted to run radare -d /bin/ls -1. I've tried it like that without quotes, which returns

radare2: invalid option -- '1'

I've also tried quoting the whole thing

radare2 -d "/bin/ls -1"
Could not execvp: No such file or directory
[w] Cannot open 'dbg:///bin/ls\ -1' for writing.

The Radare2book's "Basic Debugger Session" says , "or you can start a new program by specifying its name and parameters", but it's not clear how you specify the parameters.

2 Answers 2

5

Seems like radare has problems with passing arguments starting with dash ("-"). Please consider open an issue.

Anyway, you can pass arguments to radare2 debugged program in several ways.

The simplest way is:

r2 -d program arg1 arg2 arg3
  • r2 is an alias for radare2.
  • -d is telling radare2 to debug the execuable.
  • arg1..3 are the arguments passed to the executable by radare2.

For example:

$ r2 -d echo Hello, World!
Process with PID 4755 started...
= attach 4755 4755
bin.baddr 0x00400000
Using 0x400000
asm.bits 64
 -- You haxor! Me jane?

[0x7f9b1b000c30]> dc
Hello, World!

Another way is using the ood command inside radare2 shell:

Execute radare2 ./program, then type ood arg1 arg2 arg3. The ood command is used to "reopen in debugger mode (with args)".

$ r2 /bin/ls
 -- Use V! to enter into the visual panels mode (dwm style)

[0x004049a0]> doo -la
Process with PID 4757 started...
File dbg:///bin/ls  -la reopened in read-write mode
= attach 4757 4757
4757

[0x7f5f36600c30]> dc
total 206
drwxrwxrwx 0 root root   512 Feb 13 04:25 .
drwxrwxrwx 0 root root   512 Jan 16 05:30 ..

You can also call ood with dynamic parameters using backticks. For example we want debug our program using the content from a file on our system as an arguments:

ood `!cat file.txt`

Say file.txt content is 'foo bar' so this equivalent to executing ood foo bar

  • backticks are used for passing the output of radare2 commands.
  • ! is running the given command as in system(3).

Another way to pass arguments to radare2 debugged program is by using rarun2 profile files:

$ r2 -R profile.rr2 -d program
$ cat profile.rr2
#!/usr/bin/rarun2
arg1=foo
arg2=bar
  • -R [rarun2] specify rarun2 profile to load.
1
  • The last bit of this question seems to be wrong (possibly reporting an old behaviour?) I found that the correct way of specifying a profile is via -r, not -R. -R can be used to specify directives without using a file. In other words: r2 -r profile.rr2 -d program
    – Dacav
    Commented Feb 13 at 5:25
0

rarun2

This comes under the purview of rarun2 which isn't documented in the radare2 book, but instead in radare2-explorations. From man rarun2

The rr2 (rarun2) configuration file accepts the following directives, described as key=value entries and comments defined as lines starting with '#'.

arg[0-N] set value for argument N passed to the program

So you can run that simply by either creating a profile, or doing this

r2 -R arg0="-1" -d /bin/ls

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.