rbkb 0.7.2 → 0.7.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 (69) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/Gemfile.lock +21 -13
  4. data/bin/b64 +2 -2
  5. data/bin/bgrep +2 -2
  6. data/bin/blit +2 -2
  7. data/bin/c +2 -2
  8. data/bin/crc32 +2 -2
  9. data/bin/d64 +2 -2
  10. data/bin/dedump +2 -2
  11. data/bin/feed +2 -2
  12. data/bin/hexify +2 -2
  13. data/bin/len +2 -2
  14. data/bin/plugsrv +66 -76
  15. data/bin/rex +1 -2
  16. data/bin/rstrings +2 -2
  17. data/bin/slice +2 -2
  18. data/bin/telson +2 -2
  19. data/bin/unhexify +2 -2
  20. data/bin/urldec +2 -2
  21. data/bin/urlenc +2 -2
  22. data/bin/xor +2 -2
  23. data/lib/rbkb/cli/b64.rb +6 -7
  24. data/lib/rbkb/cli/bgrep.rb +16 -17
  25. data/lib/rbkb/cli/blit.rb +29 -31
  26. data/lib/rbkb/cli/chars.rb +1 -2
  27. data/lib/rbkb/cli/crc32.rb +8 -10
  28. data/lib/rbkb/cli/d64.rb +3 -4
  29. data/lib/rbkb/cli/dedump.rb +15 -18
  30. data/lib/rbkb/cli/feed.rb +58 -64
  31. data/lib/rbkb/cli/hexify.rb +15 -16
  32. data/lib/rbkb/cli/len.rb +19 -27
  33. data/lib/rbkb/cli/rstrings.rb +41 -44
  34. data/lib/rbkb/cli/slice.rb +8 -15
  35. data/lib/rbkb/cli/telson.rb +33 -37
  36. data/lib/rbkb/cli/unhexify.rb +10 -11
  37. data/lib/rbkb/cli/urldec.rb +8 -9
  38. data/lib/rbkb/cli/urlenc.rb +8 -8
  39. data/lib/rbkb/cli/xor.rb +13 -14
  40. data/lib/rbkb/cli.rb +52 -65
  41. data/lib/rbkb/extends/array.rb +7 -8
  42. data/lib/rbkb/extends/common.rb +3 -5
  43. data/lib/rbkb/extends/enumerable.rb +9 -9
  44. data/lib/rbkb/extends/float.rb +1 -2
  45. data/lib/rbkb/extends/numeric.rb +29 -30
  46. data/lib/rbkb/extends/object.rb +1 -2
  47. data/lib/rbkb/extends/string.rb +172 -189
  48. data/lib/rbkb/extends/symbol.rb +2 -4
  49. data/lib/rbkb/extends.rb +0 -1
  50. data/lib/rbkb/plug/blit.rb +66 -69
  51. data/lib/rbkb/plug/cli.rb +22 -25
  52. data/lib/rbkb/plug/feed_import.rb +17 -21
  53. data/lib/rbkb/plug/peer.rb +11 -13
  54. data/lib/rbkb/plug/plug.rb +83 -91
  55. data/lib/rbkb/plug/proxy.rb +4 -8
  56. data/lib/rbkb/plug/unix_domain.rb +12 -14
  57. data/lib/rbkb/plug.rb +5 -6
  58. data/lib/rbkb/version.rb +1 -1
  59. data/lib/rbkb.rb +2 -3
  60. data/rbkb.gemspec +3 -3
  61. data/test/disabled_test_cli_blit.rb +1 -2
  62. data/test/disabled_test_cli_feed.rb +1 -2
  63. data/test/disabled_test_cli_telson.rb +1 -2
  64. data/test/test_cli_crc32.rb +1 -1
  65. data/test/test_cli_dedump.rb +83 -79
  66. data/test/test_cli_len.rb +25 -24
  67. data/test/test_cli_slice.rb +22 -22
  68. data/test/test_cli_xor.rb +4 -4
  69. metadata +18 -23
data/lib/rbkb/cli/len.rb CHANGED
@@ -1,69 +1,63 @@
1
1
  require 'rbkb/cli'
2
2
 
3
- # Copyright 2009 emonti at matasano.com
3
+ # Copyright 2009 emonti at matasano.com
4
4
  # See README.rdoc for license information
5
5
 
6
6
  # len prepends a binary length number in front of its input and outputs
7
7
  # raw on STDOUT
8
8
  class Rbkb::Cli::Len < Rbkb::Cli::Executable
9
-
10
9
  def initialize(*args)
11
10
  # endianness pair. index 0 is always the default
12
- @endpair = [:big, :little]
11
+ @endpair = %i[big little]
13
12
 
14
13
  super(*args) do |this|
15
14
  {
16
- :nudge => 0,
17
- :size => 4,
18
- :endian => @endpair[0],
19
- }.each {|k,v| this.opts[k] ||= v}
15
+ nudge: 0,
16
+ size: 4,
17
+ endian: @endpair[0]
18
+ }.each { |k, v| this.opts[k] ||= v }
20
19
 
21
20
  yield this if block_given?
22
21
  end
23
22
  end
24
23
 
25
- def make_parser()
24
+ def make_parser
26
25
  super()
27
26
  add_std_file_opt(:indat)
28
27
  arg = @oparse
29
- arg.banner += " <data | blank for stdin>"
28
+ arg.banner += ' <data | blank for stdin>'
30
29
 
31
- arg.on("-n", "--nudge INT", Numeric, "Add integer to length") do |n|
30
+ arg.on('-n', '--nudge INT', Numeric, 'Add integer to length') do |n|
32
31
  @opts[:nudge] += n
33
32
  end
34
33
 
35
- arg.on("-s", "--size=SIZE", Numeric,
36
- "Size of length field in bytes") do |s|
37
- bail("Size must be greater than 0") unless (@opts[:size] = s) > 0
34
+ arg.on('-s', '--size=SIZE', Numeric, 'Size of length field in bytes') do |s|
35
+ bail('Size must be greater than 0') unless (@opts[:size] = s) > 0
38
36
  end
39
37
 
40
- arg.on("-x", "--[no-]swap",
41
- "Swap endianness. Default=#{@opts[:endian]}") do |x|
42
- @opts[:endian] = @endpair[(x)? 1 : 0]
38
+ arg.on('-x', '--[no-]swap', "Swap endianness. Default=#{@opts[:endian]}") do |x|
39
+ @opts[:endian] = @endpair[x ? 1 : 0]
43
40
  end
44
41
 
45
- arg.on("-t", "--[no-]total", "Include size word in size") do |t|
46
- @opts[:tot]=t
42
+ arg.on('-t', '--[no-]total', 'Include size word in size') do |t|
43
+ @opts[:tot] = t
47
44
  end
48
45
 
49
- arg.on("-l", "--length=LEN", Numeric,
50
- "Ignore all other flags and use static LEN") do |l|
51
- @opts[:static]=l
46
+ arg.on('-l', '--length=LEN', Numeric, 'Ignore all other flags and use static LEN') do |l|
47
+ @opts[:static] = l
52
48
  end
53
49
  end
54
50
 
55
-
56
51
  def parse(*args)
57
52
  super(*args)
58
53
  @opts[:indat] ||= @argv.shift
59
- parse_catchall()
54
+ parse_catchall
60
55
  @opts[:indat] ||= @stdin.read
61
56
  end
62
57
 
63
-
64
58
  def go(*args)
65
59
  super(*args)
66
- unless len=@opts[:static]
60
+ unless len = @opts[:static]
67
61
  len = @opts[:indat].size
68
62
  len += @opts[:size] if @opts[:tot]
69
63
  len += @opts[:nudge]
@@ -71,6 +65,4 @@ class Rbkb::Cli::Len < Rbkb::Cli::Executable
71
65
  @stdout << len.to_bytes(@opts[:endian], @opts[:size]) << @opts[:indat]
72
66
  self.exit(0)
73
67
  end
74
-
75
68
  end
76
-
@@ -1,6 +1,6 @@
1
1
  require 'rbkb/cli'
2
2
 
3
- # Copyright 2009 emonti at matasano.com
3
+ # Copyright 2009 emonti at matasano.com
4
4
  # See README.rdoc for license information
5
5
  #
6
6
  # rstrings is Unix "strings" in ruby... with some extra stuff
@@ -8,64 +8,64 @@ class Rbkb::Cli::Rstrings < Rbkb::Cli::Executable
8
8
  def initialize(*args)
9
9
  super(*args) do |this|
10
10
  {
11
- :start_off => 0,
12
- :end_off => -1,
13
- :encoding => :both,
14
- :minimum => 6,
15
- :indat => Array.new,
16
- :fnames => Array.new,
17
- }.each {|k,v| this.opts[k] ||= v }
11
+ start_off: 0,
12
+ end_off: -1,
13
+ encoding: :both,
14
+ minimum: 6,
15
+ indat: [],
16
+ fnames: []
17
+ }.each { |k, v| this.opts[k] ||= v }
18
18
 
19
19
  yield this if block_given?
20
20
  end
21
21
  end
22
22
 
23
- def make_parser()
23
+ def make_parser
24
24
  arg = super()
25
- arg.banner += " <file ... || blank for stdin>"
25
+ arg.banner += ' <file ... || blank for stdin>'
26
26
 
27
- arg.on("-s", "--start=OFFSET", "Start at offset") do |s|
28
- unless m=/^(?:(\d+)|0x([A-Fa-f0-9]+))$/.match(s)
27
+ arg.on('-s', '--start=OFFSET', 'Start at offset') do |s|
28
+ unless m = /^(?:(\d+)|0x([A-Fa-f0-9]+))$/.match(s)
29
29
  bail "invalid offset '#{s}'"
30
30
  end
31
- @opts[:start_off] = (m[2])? m[0].hex : m[0].to_i
31
+ @opts[:start_off] = m[2] ? m[0].hex : m[0].to_i
32
32
  end
33
33
 
34
- arg.on("-e", "--end=OFFSET", "End at offset") do |e|
35
- unless m=/^(?:(\d+)|0x([A-Fa-f0-9]+))$/.match(e)
34
+ arg.on('-e', '--end=OFFSET', 'End at offset') do |e|
35
+ unless m = /^(?:(\d+)|0x([A-Fa-f0-9]+))$/.match(e)
36
36
  bail "invalid offset '#{e}'"
37
37
  end
38
- @opts[:end_off] = (m[2])? m[0].hex : m[0].to_i
38
+ @opts[:end_off] = m[2] ? m[0].hex : m[0].to_i
39
39
  end
40
40
 
41
- arg.on("-t", "--encoding-type=TYPE",
42
- "Encoding: ascii/unicode/both (default=#{@opts[:encoding]})") do |t|
43
- @opts[:encoding] = t.to_sym
41
+ arg.on('-t', '--encoding-type=TYPE',
42
+ "Encoding: ascii/unicode/both (default=#{@opts[:encoding]})") do |t|
43
+ @opts[:encoding] = t.to_sym
44
44
  end
45
45
 
46
- arg.on("-l", "--min-length=NUM", Numeric,
47
- "Minimum length of strings (default=#{@opts[:minimum]})") do |l|
48
- @opts[:minimum] = l
46
+ arg.on('-l', '--min-length=NUM', Numeric,
47
+ "Minimum length of strings (default=#{@opts[:minimum]})") do |l|
48
+ @opts[:minimum] = l
49
49
  end
50
50
 
51
- return arg
51
+ arg
52
52
  end
53
53
 
54
54
  def parse(*args)
55
55
  super(*args)
56
- if @opts[:indat].empty? and not @argv.empty?
57
- while a=@argv.shift
56
+ if @opts[:indat].empty? and !@argv.empty?
57
+ while a = @argv.shift
58
58
  @opts[:indat] << do_file_read(a)
59
59
  @opts[:fnames] << a
60
60
  end
61
61
  end
62
62
 
63
- parse_catchall()
63
+ parse_catchall
64
64
 
65
- if @opts[:indat].empty?
66
- @opts[:indat] << @stdin.read() if @opts[:indat].empty?
67
- @opts[:fnames] << "[STDIN]"
68
- end
65
+ return unless @opts[:indat].empty?
66
+
67
+ @opts[:indat] << @stdin.read if @opts[:indat].empty?
68
+ @opts[:fnames] << '[STDIN]'
69
69
  end
70
70
 
71
71
  def go(*args)
@@ -77,26 +77,23 @@ class Rbkb::Cli::Rstrings < Rbkb::Cli::Executable
77
77
  min = @opts[:minimum]
78
78
  align = @opts[:align]
79
79
 
80
- @opts[:pr_fnames]=true if @opts[:fnames].size > 1
80
+ @opts[:pr_fnames] = true if @opts[:fnames].size > 1
81
81
 
82
- i=0
83
- while buf=@opts[:indat].shift
82
+ i = 0
83
+ while buf = @opts[:indat].shift
84
84
  buf[start_off..end_off].strings(
85
- :encoding => enc,
86
- :minimum => min,
87
- :align => align
85
+ encoding: enc,
86
+ minimum: min,
87
+ align: align
88
88
  ) do |off, len, type, str|
89
- if @opts[:pr_fnames]
90
- @stdout << "#{@opts[:fnames][i]}:"
91
- end
92
- @stdout << "#{(off+start_off).to_hex.rjust(8,"0")}:"+
93
- "#{(len+start_off).to_hex.rjust(8,"0")}:"+
94
- "#{type.to_s[0,1]}:#{str.delete("\x00").inspect}\n"
89
+ @stdout << "#{@opts[:fnames][i]}:" if @opts[:pr_fnames]
90
+ @stdout << "#{(off + start_off).to_hex.rjust(8, '0')}:" +
91
+ "#{(len + start_off).to_hex.rjust(8, '0')}:" +
92
+ "#{type.to_s[0, 1]}:#{str.delete("\x00").inspect}\n"
95
93
  end
96
- i+=1
94
+ i += 1
97
95
  end
98
96
 
99
97
  self.exit(0)
100
98
  end
101
99
  end
102
-
@@ -1,47 +1,40 @@
1
1
  require 'rbkb/cli'
2
2
 
3
- # Copyright 2009 emonti at matasano.com
3
+ # Copyright 2009 emonti at matasano.com
4
4
  # See README.rdoc for license information
5
5
  #
6
- # Returns a slice from input. This is just a shell interface to a String.slice
6
+ # Returns a slice from input. This is just a shell interface to a String.slice
7
7
  # operation.
8
8
  class Rbkb::Cli::Slice < Rbkb::Cli::Executable
9
-
10
9
  def initialize(*args)
11
10
  super(*args)
12
11
  @opts[:last] ||= -1
13
12
  end
14
13
 
15
- def make_parser()
14
+ def make_parser
16
15
  super()
17
16
  add_std_file_opt(:indat)
18
17
  add_range_opts(:first, :last)
19
18
  arg = @oparse
20
19
 
21
- arg.banner += " start (no args when using -r or -x)"
20
+ arg.banner += ' start (no args when using -r or -x)'
22
21
  end
23
22
 
24
-
25
23
  def parse(*args)
26
24
  super(*args)
27
25
  @opts[:first] ||= @argv.shift
28
26
 
29
- unless(Numeric === @opts[:first] or /^-?\d+$/.match(@opts[:first]) )
30
- bail_args "invalid start length"
31
- end
27
+ bail_args 'invalid start length' unless @opts[:first].is_a?(Numeric) or /^-?\d+$/.match(@opts[:first])
32
28
 
33
- parse_catchall()
29
+ parse_catchall
34
30
 
35
31
  @opts[:first] = @opts[:first].to_i
36
- @opts[:indat] ||= @stdin.read()
32
+ @opts[:indat] ||= @stdin.read
37
33
  end
38
34
 
39
-
40
35
  def go(*args)
41
36
  super(*args)
42
- @stdout << @opts[:indat][ @opts[:first] .. @opts[:last] ]
37
+ @stdout << @opts[:indat][ @opts[:first]..@opts[:last] ]
43
38
  self.exit(0)
44
39
  end
45
-
46
40
  end
47
-
@@ -1,87 +1,83 @@
1
1
  require 'rbkb/plug/cli'
2
2
 
3
- # Copyright 2009 emonti at matasano.com
3
+ # Copyright 2009 emonti at matasano.com
4
4
  # See README.rdoc for license information
5
5
  #
6
- # This is an implementation of the original blackbag "telson" around
7
- # ruby and eventmachine.
6
+ # This is an implementation of the original blackbag "telson" around
7
+ # ruby and eventmachine.
8
8
  #
9
- # Telson can do the following things with minimum fuss:
9
+ # Telson can do the following things with minimum fuss:
10
10
  # - Run as a "stubbed" network client using UDP or TCP
11
11
  # - Debugging network protocols
12
12
  # - Observe client/server behaviors using different messages at
13
13
  # various phases of a conversation.
14
14
  #
15
15
  class Rbkb::Cli::Telson < Rbkb::Cli::PlugCli
16
-
17
16
  def initialize(*args)
18
17
  super(*args) do |this|
19
- this.local_addr = "0.0.0.0"
18
+ this.local_addr = '0.0.0.0'
20
19
  this.local_port = 0
21
20
  end
22
21
 
23
22
  @persist = false
24
23
  end
25
24
 
26
-
27
- def make_parser()
25
+ def make_parser
28
26
  arg = super()
29
27
 
30
- arg.on("-r", "--reconnect", "Attempt to reconnect endlessly.") do
31
- @persist=true
28
+ arg.on('-r', '--reconnect', 'Attempt to reconnect endlessly.') do
29
+ @persist = true
32
30
  end
33
31
 
34
- arg.on("-s", "--source=(ADDR:?)PORT", "Bind client on port and addr") do |p|
35
- if m=/^(?:([\w\.]+):)?(\d+)$/.match(p)
36
- @local_addr = $1 if $1
37
- @local_port = $2.to_i
32
+ arg.on('-s', '--source=(ADDR:?)PORT', 'Bind client on port and addr') do |p|
33
+ if /^(?:([\w.]+):)?(\d+)$/.match(p)
34
+ @local_addr = ::Regexp.last_match(1) if ::Regexp.last_match(1)
35
+ @local_port = ::Regexp.last_match(2).to_i
38
36
  else
39
37
  bail("Invalid source argument: #{p.inspect}")
40
38
  end
41
39
  end
42
40
  end
43
41
 
44
-
45
42
  def parse(*args)
46
43
  super(*args)
47
44
 
48
- parse_target_argument()
49
- parse_catchall()
45
+ parse_target_argument
46
+ parse_catchall
50
47
  end
51
48
 
52
-
53
49
  def go(*args)
54
50
  super(*args)
55
51
  loop do
56
- EventMachine.run {
52
+ EventMachine.run do
57
53
  if @transport == :TCP
58
54
 
59
- c=EventMachine.bind_connect( @local_addr,
60
- @local_port,
61
- @target_addr,
62
- @target_port,
63
- Plug::Telson,
64
- @transport,
65
- @plug_opts )
55
+ c = EventMachine.bind_connect(@local_addr,
56
+ @local_port,
57
+ @target_addr,
58
+ @target_port,
59
+ Plug::Telson,
60
+ @transport,
61
+ @plug_opts)
66
62
  elsif @transport == :UDP
67
- c=EventMachine.open_datagram_socket( @local_addr,
68
- @local_port,
69
- Plug::Telson,
70
- @transport,
71
- @plug_opts )
72
-
63
+ c = EventMachine.open_datagram_socket(@local_addr,
64
+ @local_port,
65
+ Plug::Telson,
66
+ @transport,
67
+ @plug_opts)
68
+
73
69
  c.peers.add_peer_manually(@target_addr, @target_port)
74
70
 
75
71
  ### someday maybe raw or others?
76
72
  else
77
- raise "bad transport protocol"
73
+ raise 'bad transport protocol'
78
74
  end
79
75
  EventMachine.start_server(@blit_addr, @blit_port, Plug::Blit, @blit_proto, c)
80
- Plug::UI::verbose("** BLITSRV-#{@blit_addr}:#{@blit_port}(TCP) Started") # XXX
81
- }
76
+ Plug::UI.verbose("** BLITSRV-#{@blit_addr}:#{@blit_port}(TCP) Started") # XXX
77
+ end
82
78
  break unless @persist
83
- Plug::UI::verbose("** RECONNECTING") # XXX
79
+
80
+ Plug::UI.verbose('** RECONNECTING') # XXX
84
81
  end
85
82
  end
86
83
  end
87
-
@@ -1,9 +1,9 @@
1
1
  require 'rbkb/cli'
2
2
 
3
- # Copyright 2009 emonti at matasano.com
3
+ # Copyright 2009 emonti at matasano.com
4
4
  # See README.rdoc for license information
5
5
  #
6
- # unhexify converts a string of hex bytes back to raw data. Input can be
6
+ # unhexify converts a string of hex bytes back to raw data. Input can be
7
7
  # supplied via stdin, a hex-string argument, or a file containing hex (use -f).
8
8
  class Rbkb::Cli::Unhexify < Rbkb::Cli::Executable
9
9
  def make_parser
@@ -13,11 +13,11 @@ class Rbkb::Cli::Unhexify < Rbkb::Cli::Executable
13
13
 
14
14
  #----------------------------------------------------------------------
15
15
  # Add local options
16
- arg.banner += " <data | blank for stdin>"
16
+ arg.banner += ' <data | blank for stdin>'
17
17
 
18
- arg.on("-d", "--delim DELIMITER",
19
- "DELIMITER regex between hex chunks") do |d|
20
- @opts[:delim] = Regexp.new(d.gsub('\\\\', '\\'))
18
+ arg.on('-d', '--delim DELIMITER',
19
+ 'DELIMITER regex between hex chunks') do |d|
20
+ @opts[:delim] = Regexp.new(d.gsub('\\\\', '\\'))
21
21
  end
22
22
  end
23
23
 
@@ -25,19 +25,19 @@ class Rbkb::Cli::Unhexify < Rbkb::Cli::Executable
25
25
  super(*args)
26
26
 
27
27
  # default string arg
28
- if @opts[:indat].nil? and a=@argv.shift
29
- @opts[:indat] = a.dup
28
+ if @opts[:indat].nil? and a = @argv.shift
29
+ @opts[:indat] = a.dup
30
30
  end
31
31
 
32
32
  # catchall
33
- bail_args @argv.join(' ') if ARGV.length != 0
33
+ bail_args @argv.join(' ') if ARGV.length != 0
34
34
  end
35
35
 
36
36
  def go(*args)
37
37
  super(*args)
38
38
 
39
39
  # Default to standard input
40
- @opts[:indat] ||= @stdin.read()
40
+ @opts[:indat] ||= @stdin.read
41
41
 
42
42
  @opts[:indat].delete!("\r\n")
43
43
  @opts[:delim] ||= Regexp.new('\s*')
@@ -47,4 +47,3 @@ class Rbkb::Cli::Unhexify < Rbkb::Cli::Executable
47
47
  self.exit(0)
48
48
  end
49
49
  end
50
-
@@ -1,35 +1,34 @@
1
1
  require 'rbkb/cli'
2
2
 
3
- # Copyright 2009 emonti at matasano.com
3
+ # Copyright 2009 emonti at matasano.com
4
4
  # See README.rdoc for license information
5
5
  #
6
6
  # urldec converts a url percent-encoded string back to its raw form.
7
7
  # Input can be supplied via stdin, a string argument, or a file (with -f).
8
8
  # (url percent-encoding is just fancy hex encoding)
9
9
  class Rbkb::Cli::Urldec < Rbkb::Cli::Executable
10
- def make_parser()
10
+ def make_parser
11
11
  super()
12
12
  add_std_file_opt(:indat)
13
13
  arg = @oparse
14
- arg.banner += " <data | blank for stdin>"
14
+ arg.banner += ' <data | blank for stdin>'
15
15
 
16
- arg.on("-p", "--[no-]plus", "Convert '+' to space (default: true)") do |p|
17
- @opts[:noplus] = (not p)
16
+ arg.on('-p', '--[no-]plus', "Convert '+' to space (default: true)") do |p|
17
+ @opts[:noplus] = !p
18
18
  end
19
19
  end
20
20
 
21
21
  def parse(*args)
22
22
  super(*args)
23
23
  parse_string_argument(:indat)
24
- parse_catchall()
24
+ parse_catchall
25
25
  end
26
26
 
27
27
  def go(*args)
28
28
  super(*args)
29
29
  # Default to standard input
30
- @opts[:indat] ||= @stdin.read()
31
- @stdout << @opts[:indat].urldec(:noplus => @opts[:noplus])
30
+ @opts[:indat] ||= @stdin.read
31
+ @stdout << @opts[:indat].urldec(noplus: @opts[:noplus])
32
32
  self.exit(0)
33
33
  end
34
34
  end
35
-
@@ -1,19 +1,19 @@
1
1
  require 'rbkb/cli'
2
2
 
3
- # Copyright 2009 emonti at matasano.com
3
+ # Copyright 2009 emonti at matasano.com
4
4
  # See README.rdoc for license information
5
5
  #
6
- # urlenc converts a string or raw data to a url percent-encoded string
6
+ # urlenc converts a string or raw data to a url percent-encoded string
7
7
  # Input can be supplied via stdin, a string argument, or a file (with -f).
8
8
  # (url percent-encoding is just fancy hex encoding)
9
9
  class Rbkb::Cli::Urlenc < Rbkb::Cli::Executable
10
- def make_parser()
10
+ def make_parser
11
11
  super()
12
12
  add_std_file_opt(:indat)
13
13
  arg = @oparse
14
- arg.banner += " <data | blank for stdin>"
14
+ arg.banner += ' <data | blank for stdin>'
15
15
 
16
- arg.on("-p", "--[no-]plus",
16
+ arg.on('-p', '--[no-]plus',
17
17
  "Convert spaces to '+' (default: false)") do |p|
18
18
  @opts[:plus] = p
19
19
  end
@@ -22,14 +22,14 @@ class Rbkb::Cli::Urlenc < Rbkb::Cli::Executable
22
22
  def parse(*args)
23
23
  super(*args)
24
24
  parse_string_argument(:indat)
25
- parse_catchall()
25
+ parse_catchall
26
26
  end
27
27
 
28
28
  def go(*args)
29
29
  super(*args)
30
30
  # Default to standard input
31
- @opts[:indat] ||= @stdin.read()
32
- @stdout << @opts[:indat].urlenc(:plus => @opts[:plus]) + "\n"
31
+ @opts[:indat] ||= @stdin.read
32
+ @stdout << @opts[:indat].urlenc(plus: @opts[:plus]) + "\n"
33
33
  self.exit(0)
34
34
  end
35
35
  end
data/lib/rbkb/cli/xor.rb CHANGED
@@ -1,36 +1,36 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'rbkb/cli'
3
3
 
4
- # Copyright 2009 emonti at matasano.com
4
+ # Copyright 2009 emonti at matasano.com
5
5
  # See README.rdoc for license information
6
6
  #
7
7
  # Repeating string xor. Takes input from a string, stdin, or a file (-f).
8
8
  class Rbkb::Cli::Xor < Rbkb::Cli::Executable
9
- def make_parser()
9
+ def make_parser
10
10
  super()
11
11
  add_std_file_opt(:indat)
12
12
  arg = @oparse
13
- arg.banner += " -k|-s <key> <data | stdin>"
13
+ arg.banner += ' -k|-s <key> <data | stdin>'
14
14
 
15
- arg.separator " Key options (you must specify one of the following):"
16
- arg.on("-s", "--strkey STRING", "xor against STRING") do |s|
17
- bail "only one key option can be specified with -s or -x" if @opts[:key]
18
- @opts[:key] = s
15
+ arg.separator ' Key options (you must specify one of the following):'
16
+ arg.on('-s', '--strkey STRING', 'xor against STRING') do |s|
17
+ bail 'only one key option can be specified with -s or -x' if @opts[:key]
18
+ @opts[:key] = s
19
19
  end
20
20
 
21
- arg.on("-x", "--hexkey HEXSTR", "xor against binary HEXSTR") do |x|
22
- bail "only one key option can be specified with -s or -x" if @opts[:key]
23
- x.sub!(/^0[xX]/, '')
24
- bail "Unable to parse hex string" unless @opts[:key] = x.unhexify
21
+ arg.on('-x', '--hexkey HEXSTR', 'xor against binary HEXSTR') do |x|
22
+ bail 'only one key option can be specified with -s or -x' if @opts[:key]
23
+ x.sub!(/^0[xX]/, '')
24
+ bail 'Unable to parse hex string' unless @opts[:key] = x.unhexify
25
25
  end
26
- return arg
26
+ arg
27
27
  end
28
28
 
29
29
  def parse(*args)
30
30
  super(*args)
31
31
  bail("You must specify a key with -s or -x\n#{@oparse}") unless @opts[:key]
32
32
  parse_string_argument(:indat)
33
- parse_catchall()
33
+ parse_catchall
34
34
  end
35
35
 
36
36
  def go(*args)
@@ -40,4 +40,3 @@ class Rbkb::Cli::Xor < Rbkb::Cli::Executable
40
40
  self.exit(0)
41
41
  end
42
42
  end
43
-