I was using radare2 (2.2.0) with r2pipe (0.9.5) for python3 to debug the code generated by:
#include <stdio.h>
int main(){
char entrada[14];
gets(entrada);
puts(entrada);
return 0;
}
Disassembling the main function with radare2 outputs:
0x00400546 55 pushq %rbp
0x00400547 4889e5 movq %rsp, %rbp
0x0040054a 4883ec10 subq $0x10, %rsp
0x0040054e 488d45f0 leaq local_10h, %rax
0x00400552 4889c7 movq %rax, %rdi
0x00400555 b800000000 movl $0, %eax
0x0040055a e8e1feffff callq sym.imp.gets ; char*gets(char *s)
0x0040055f 488d45f0 leaq local_10h, %rax
0x00400563 4889c7 movq %rax, %rdi
0x00400566 e8c5feffff callq sym.imp.puts ; int puts(const char *s)
0x0040056b b800000000 movl $0, %eax
0x00400570 c9 leave
0x00400571 c3 retq
However, when debugging this program with python using this script
import r2pipe as r2
prog = r2.open("./a.out")
prog.cmd("aaa")
prog.cmd("doo")
prog.cmd("db 0x0040055f") #Breakpoint after 'gets' call
prog.cmd("dc")
prog.cmd("dc")
the execution stucks in the "gets" call, no matter which input I use. The same sequence of commands works fine with the radare2's CLI. I also tried using dor stdin=input.txt
before doo
which, despite the fact it works, it isn't convenient to write files to the disk, and for some uses, is not possible to determine the needed input before the execution.
What is the best way to use stdin with r2pipe?