r2pipe 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/r2pipe.rb +31 -12
  3. data/lib/r2pipe/version.rb +1 -1
  4. metadata +3 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3cd0ed01cd73d94e861c4df971e7971faeb17b94
4
- data.tar.gz: 5e8a47c903624fa129119d3de4a1b9583d5b1d52
3
+ metadata.gz: e704f13a7167821d211d8719a13a7ea52f3dfacc
4
+ data.tar.gz: fe52e28dc67357ae80cfef586efa9519fbe70f0c
5
5
  SHA512:
6
- metadata.gz: 07189412b734239a5da651065dd5d3e906ac580f0daffe98222ce942d61cbc132ea40c622fe20ee9b076b44c744c3f2322b10f2c4f8fc9df3a174148800c4867
7
- data.tar.gz: 8ea3c34421fd1c87c11a718b2e689f5108b7865faf12eb81703f3d45afc311ca0d9b6d0fa292ed6a733c66fcca0d26c6bfcbe9e88e63dce7d740f4f69afbd577
6
+ metadata.gz: 1042254c44fc987d15f3caf9da81652d123c75c1ad34d4cd7f69e4c5f0789c6a966518fac82aa432087e706441041b929d1124b5f5bd9c6293ba40fa673aacad
7
+ data.tar.gz: 2095d822db51d872a512ad84cbcaa214de99d10914648157d652dab4c9b8ad9e251ad9cc43ef7604306f2f2210c4567438574aebda52ffedffb4871762630ee3
@@ -5,31 +5,50 @@ require 'shellwords'
5
5
 
6
6
  # R2Pipe is an easy way to communicate with an r2 core through ruby
7
7
  class R2Pipe
8
- def initialize(file)
8
+ def initialize(file = nil)
9
9
  @file = file
10
- exec = "r2 -q0 #{Shellwords.shellescape file} 2>/dev/null"
11
- PTY.spawn(exec) do |read, write, pid|
12
- @read = read
13
- @write = write
14
- @pid = pid
15
- @read.gets("\0")
10
+ if file == nil
11
+ fdIn = ENV['R2PIPE_IN'].to_i
12
+ fdOut = ENV['R2PIPE_OUT'].to_i
13
+ if fdIn < 1 or fdOut < 1
14
+ raise 'Cannot find R2PIPE_IN and R2PIPE_OUT environment variables'
15
+ end
16
+ @read = IO.new(fdIn, 'r')
17
+ @write = IO.new(fdOut, 'w')
18
+ @pid = -1
19
+ else
20
+ exec = "r2 -q0 #{Shellwords.shellescape file} 2>/dev/null"
21
+ PTY.spawn(exec) do |read, write, pid|
22
+ @read = read
23
+ @write = write
24
+ @pid = pid
25
+ @read.gets("\0")
26
+ end
16
27
  end
17
28
  end
18
29
 
19
- # runs a command on the radare2 core
20
30
  def cmd(str)
21
31
  @write.print "#{str}\n"
32
+ @write.flush
22
33
  @read.gets("\0")[0..-2]
23
34
  end
24
35
 
25
- # closes the radare2 core and quits
36
+ def cmdj(str)
37
+ json(cmd(str))
38
+ end
39
+
26
40
  def quit
27
41
  cmd('q!')
28
- ::Process.wait @pid
42
+ @read.close
43
+ @write.close
44
+ if @pid != -1
45
+ ::Process.wait @pid
46
+ end
29
47
  end
30
48
 
31
- # returns a parsed json string
32
49
  def json(str)
33
- JSON.parse str.sub("\n", '').sub("\r", '')
50
+ if !str.nil?
51
+ JSON.parse str.sub("\n", '').sub("\r", '')
52
+ end
34
53
  end
35
54
  end
@@ -1,3 +1,3 @@
1
1
  module R2pipe
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r2pipe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeffrey Crowell
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2015-04-23 00:00:00.000000000 Z
12
+ date: 2017-11-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -82,9 +82,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  version: '0'
83
83
  requirements: []
84
84
  rubyforge_project:
85
- rubygems_version: 2.4.6
85
+ rubygems_version: 2.6.12
86
86
  signing_key:
87
87
  specification_version: 4
88
88
  summary: Communicate with Radare2 via pipes.
89
89
  test_files: []
90
- has_rdoc: