/usr/share/doc/radare-doc/html/Section20.7.html is in radare-doc 1:1.5.2-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=US-ASCII">
<title>Filedescriptors</title>
<link rel="previous" href="Section20.6.4.html">
<link rel="ToC" href="contents.html">
<link rel="next" href="Section20.8.html">
</head>
<body>
<h1><a name="fds"></a>20.7 Filedescriptors</h1>
<p>
The file descriptors of a process can be manipulated in multiple ways to get information about the opened files of a program, in which permissions, duplicate them as new file descriptors, close, change the seek, open a file on an already opened filedescriptor or making a TCP connection for example.
</p>
<p>
All this stuff is system-dependant, so if it is not implemented in your favourite operating system(R) i'll be happy to receive feedback and patches.
</p>
<p>
It is handled by the '!fd' command:
</p>
<pre><code>[0x4A13C00E]> !fd?
Usage: !fd[s|d] [-#] [file | host:port]
!fd ; list filedescriptors
!fdd 2 7 ; dup2(2, 7)
!fds 3 0x840 ; seek filedescriptor
!fdr 3 0x8048000 100 ; read 100 bytes from fd=3 at 0x80..
!fdw 3 0x8048000 100 ; write 100 bytes from fd=3 at 0x80..
!fdio [fdnum] ; enter fd-io mode on a fd, no args = back to dbg-io
!fd -1 ; close stdout
!fd /etc/motd ; open file at fd=3
!fd 127.0.0.1:9999 ; open socket at fd=5
</code></pre>
<p>
Here's the filedescriptor list once a process is created with stdin, stdout and sterr
</p>
<p>
[0x4A13C00E]> !fd 0 0x00000013 rwC /dev/pts/0 1 0x00000000 rwC /dev/pts/0 2 0x00000000 rwC /dev/pts/0
</p>
<p>
Now we can close the stdout of the program or just redirect them to a file opening a file on the fd number '1':
</p>
<pre><code>[0x4A13C00E]> !fd /tmp/stdout.txt ; open new fd
[0x4A13C00E]> !fd -1 ; close stdout
[0x4A13C00E]> !fdd 3 1 ; stdout = new_fd
[0x4A13C00E]> !fd -3 ; close file
</code></pre>
<p>
There are three commands for reading and writing from/to filedescriptors of the child process from the debugger. !fdr and !fdw are the basic ones. As a simple example you can just use the child stdout filedescriptor for dumping the ELF signature to stdout.
</p>
<pre><code>[0x465D8810]> !fdw 1 0x8048001 3
ELF
</code></pre>
<p>
Cool right? :)
</p>
<p>
Now you can do the same with !fdr. Both commands are used to inject a simple syscall instruction on the child process, so the addresses should be accessible from the target process.
</p>
<p>
Be aware if you are trying to read from stdin or from a socket, because this can break the program execution or trash your terminal.
</p>
<p>
The latest experimental but really interesting command is the <code>'!fdio'</code> one. It is used to abstract the debugger IO layer to work transparently by using a simple syscall proxying using read and write over the child file descriptors and let the developer read and write on child filedescriptors.
</p>
<pre><code>[0x465D8810]> !fdio 3
FDIO enabled on 3
...
[0x465D8810]> !fdio
FDIO disabled
</code></pre>
<p>
Once FDIO is enabled, radare will read and write over the child, so you'll loss the view of the process memory layout to have access to the file opened by the process.
</p>
<p>
This is useful for debugging remote programs, because this way you can access to these files. In the same way you can open a new file and access it thru the remote debugger like if it was a local one.
</p>
<!-- version IDs:
$Id: radare.but 2009-04-25 pancake $
-->
</body>
</html>
|