Class: R2Pipe
- Inherits:
-
Object
- Object
- R2Pipe
- Defined in:
- lib/r2pipe.rb
Overview
R2Pipe is an easy way to communicate with an r2 core through ruby
Instance Method Summary collapse
-
#cmd(str) ⇒ Object
runs a command on the radare2 core.
-
#initialize(file) ⇒ R2Pipe
constructor
A new instance of R2Pipe.
-
#json(str) ⇒ Object
returns a parsed json string.
-
#quit ⇒ Object
closes the radare2 core and quits.
Constructor Details
#initialize(file) ⇒ R2Pipe
Returns a new instance of R2Pipe.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/r2pipe.rb', line 8 def initialize(file) @file = file exec = "r2 -q0 #{Shellwords.shellescape file} 2>/dev/null" PTY.spawn(exec) do |read, write, pid| @read = read @write = write @pid = pid @read.gets("\0") end end |
Instance Method Details
#cmd(str) ⇒ Object
runs a command on the radare2 core
20 21 22 23 |
# File 'lib/r2pipe.rb', line 20 def cmd(str) @write.print "#{str}\n" @read.gets("\0")[0..-2] end |
#json(str) ⇒ Object
returns a parsed json string
32 33 34 |
# File 'lib/r2pipe.rb', line 32 def json(str) JSON.parse str.sub("\n", '').sub("\r", '') end |
#quit ⇒ Object
closes the radare2 core and quits
26 27 28 29 |
# File 'lib/r2pipe.rb', line 26 def quit cmd('q!') ::Process.wait @pid end |