title: How to dump function's disassembly using r2pipe
body: <p>I'm about to write a software that puts a binary into radare2 and then dumps subroutines including instructions, addresses and binary representation of instructions into a text file.</p>
  
  <p>I got it working with IDA Pro and IDAPython but I also want to recreate it for radare2. The text file should look like this in the end:</p>
  
  <pre><code>0x0804ba0a      55             push ebp
  0x0804ba0b      89e5           mov ebp, esp
  0x0804ba0d      83ec18         sub esp, 0x18
  0x0804ba10      83e4f0         and esp, 0xfffffff0
  0x0804ba13      b800000000     mov eax, 0
  0x0804ba18      29c4           sub esp, eax
  </code></pre>
  
  <p>Unfortunately, the sources in the web are scarce and the documentation is not exactly long. I would love to give you more to work with but I'm somehow stuck here.
  I figured out how to disassemble a function using the pdf command and I could probably use it like this in python but the way I've done it, the main, entry point and sym.main would be missing. I would like to disassemble the whole .text section or all functions in the .text section:</p>
  
  <pre><code>import r2pipe
  
  file = 'path_to_file'
  r = r2pipe.open()
  
  with open (file, 'w') as f:
      r.cmd('aaa')
      # disassemble all functions starting with fcn and write them
      # to the file
      f.write(r.cmd('pdf @@ fcn*'))
  </code></pre>