The command permits the user to open a file, this is mapped at offset 0 unless it has a known binary header and then the maps are created in virtual addresses.
Sometimes, we want to rebase a binary, or maybe we want to load or map the file in a different address.
When launching r2, the base address can be changed with the -B
flag. But you must notice the difference when opening files with unknown headers, like bootloaders, so we need to map them using the -m
flag (or specifying it as argument to the o
command).
Opening files (and mapping them) is done using the o
(open) command. Let’s read the help:
Prepare a simple layout:
$ rabin2 -l /bin/ls
libselinux.so.1
libacl.so.1
libc.so.6
Map a file:
[0x00000000]> o
- 6 /bin/ls @ 0x0 ; r
- 10 /lib/ld-linux.so.2 @ 0x100000000 ; r
Print hexadecimal values from /bin/zsh:
Unmap files using the o-
command. Pass the required file descriptor to it as an argument:
You can also view the ascii table showing the list of the opened files: