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.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/Gemfile.lock +21 -13
- data/bin/b64 +2 -2
- data/bin/bgrep +2 -2
- data/bin/blit +2 -2
- data/bin/c +2 -2
- data/bin/crc32 +2 -2
- data/bin/d64 +2 -2
- data/bin/dedump +2 -2
- data/bin/feed +2 -2
- data/bin/hexify +2 -2
- data/bin/len +2 -2
- data/bin/plugsrv +66 -76
- data/bin/rex +1 -2
- data/bin/rstrings +2 -2
- data/bin/slice +2 -2
- data/bin/telson +2 -2
- data/bin/unhexify +2 -2
- data/bin/urldec +2 -2
- data/bin/urlenc +2 -2
- data/bin/xor +2 -2
- data/lib/rbkb/cli/b64.rb +6 -7
- data/lib/rbkb/cli/bgrep.rb +16 -17
- data/lib/rbkb/cli/blit.rb +29 -31
- data/lib/rbkb/cli/chars.rb +1 -2
- data/lib/rbkb/cli/crc32.rb +8 -10
- data/lib/rbkb/cli/d64.rb +3 -4
- data/lib/rbkb/cli/dedump.rb +15 -18
- data/lib/rbkb/cli/feed.rb +58 -64
- data/lib/rbkb/cli/hexify.rb +15 -16
- data/lib/rbkb/cli/len.rb +19 -27
- data/lib/rbkb/cli/rstrings.rb +41 -44
- data/lib/rbkb/cli/slice.rb +8 -15
- data/lib/rbkb/cli/telson.rb +33 -37
- data/lib/rbkb/cli/unhexify.rb +10 -11
- data/lib/rbkb/cli/urldec.rb +8 -9
- data/lib/rbkb/cli/urlenc.rb +8 -8
- data/lib/rbkb/cli/xor.rb +13 -14
- data/lib/rbkb/cli.rb +52 -65
- data/lib/rbkb/extends/array.rb +7 -8
- data/lib/rbkb/extends/common.rb +3 -5
- data/lib/rbkb/extends/enumerable.rb +9 -9
- data/lib/rbkb/extends/float.rb +1 -2
- data/lib/rbkb/extends/numeric.rb +29 -30
- data/lib/rbkb/extends/object.rb +1 -2
- data/lib/rbkb/extends/string.rb +172 -189
- data/lib/rbkb/extends/symbol.rb +2 -4
- data/lib/rbkb/extends.rb +0 -1
- data/lib/rbkb/plug/blit.rb +66 -69
- data/lib/rbkb/plug/cli.rb +22 -25
- data/lib/rbkb/plug/feed_import.rb +17 -21
- data/lib/rbkb/plug/peer.rb +11 -13
- data/lib/rbkb/plug/plug.rb +83 -91
- data/lib/rbkb/plug/proxy.rb +4 -8
- data/lib/rbkb/plug/unix_domain.rb +12 -14
- data/lib/rbkb/plug.rb +5 -6
- data/lib/rbkb/version.rb +1 -1
- data/lib/rbkb.rb +2 -3
- data/rbkb.gemspec +3 -3
- data/test/disabled_test_cli_blit.rb +1 -2
- data/test/disabled_test_cli_feed.rb +1 -2
- data/test/disabled_test_cli_telson.rb +1 -2
- data/test/test_cli_crc32.rb +1 -1
- data/test/test_cli_dedump.rb +83 -79
- data/test/test_cli_len.rb +25 -24
- data/test/test_cli_slice.rb +22 -22
- data/test/test_cli_xor.rb +4 -4
- metadata +18 -23
data/lib/rbkb/cli/blit.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rbkb/cli'
|
2
2
|
require 'rbkb/plug'
|
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
|
# blit is for use with any of the "plug" tools such as telson, feed, blitplug.
|
@@ -12,64 +12,63 @@ class Rbkb::Cli::Blit < Rbkb::Cli::Executable
|
|
12
12
|
def initialize(*args)
|
13
13
|
super(*args)
|
14
14
|
{
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
19
|
-
}.each {|k, v| @opts[k] ||= v}
|
15
|
+
b_addr: Plug::Blit::DEFAULT_IPADDR,
|
16
|
+
b_port: Plug::Blit::DEFAULT_PORT,
|
17
|
+
bp_proto: :TCP,
|
18
|
+
b_peeridx: 0
|
19
|
+
}.each { |k, v| @opts[k] ||= v }
|
20
20
|
end
|
21
21
|
|
22
|
-
def make_parser
|
22
|
+
def make_parser
|
23
23
|
super()
|
24
24
|
add_std_file_opt(:indat)
|
25
25
|
arg = @oparse
|
26
26
|
|
27
|
-
arg.banner +=
|
27
|
+
arg.banner += ' <data | blank for stdin>'
|
28
28
|
|
29
|
-
arg.on(
|
30
|
-
|
29
|
+
arg.on('-t', '--trans-protocol=PROTO',
|
30
|
+
'Blit transport protocol TCP/UDP') do |t|
|
31
31
|
@opts[:b_proto] = t.upcase.to_sym
|
32
32
|
end
|
33
33
|
|
34
|
-
arg.on(
|
34
|
+
arg.on('-S', '--starttls', 'Start TLS handshake for the peer index (-i)') do |_s|
|
35
35
|
@blit_msg = Plug::Blit.make_starttls(@opts[:b_peeridx])
|
36
36
|
end
|
37
37
|
|
38
|
-
arg.on(
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
bail "invalid blit address/port"
|
38
|
+
arg.on('-b', '--blitsrv=ADDR:PORT',
|
39
|
+
'Where to send blit messages') do |b|
|
40
|
+
unless (m = /^(?:([\w.]+):)?(\d+)$/.match(b))
|
41
|
+
bail 'invalid blit address/port'
|
43
42
|
end
|
44
43
|
@opts[:b_port] = m[2].to_i
|
45
44
|
@opts[:b_port] = m[1] if m[1]
|
46
45
|
end
|
47
46
|
|
48
|
-
arg.on(
|
49
|
-
|
47
|
+
arg.on('-i', '--peer-index=IDX', Numeric,
|
48
|
+
'Index for remote peer to receive') do |i|
|
50
49
|
@opts[:b_peeridx] = i
|
51
50
|
end
|
52
51
|
|
53
|
-
arg.on(
|
52
|
+
arg.on('-l', '--list-peers', 'Lists the peer array for the target') do
|
54
53
|
@blit_msg = Plug::Blit.make_list_peers
|
55
54
|
end
|
56
55
|
|
57
|
-
arg.on(
|
56
|
+
arg.on('-k', '--kill', 'Stops the remote event loop.') do
|
58
57
|
@blit_msg = Plug::Blit.make_kill
|
59
58
|
end
|
60
59
|
|
61
|
-
|
60
|
+
arg
|
62
61
|
end
|
63
62
|
|
64
63
|
def parse(*args)
|
65
64
|
super(*args)
|
66
65
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
@blit_msg = Plug::Blit.make_sendmsg(@opts[:b_peeridx], @opts[:indat])
|
66
|
+
return if @blit_msg
|
67
|
+
|
68
|
+
if @opts[:indat].nil?
|
69
|
+
@opts[:indat] = @argv.length > 0 ? @argv.join(' ') : @stdin.read
|
72
70
|
end
|
71
|
+
@blit_msg = Plug::Blit.make_sendmsg(@opts[:b_peeridx], @opts[:indat])
|
73
72
|
end
|
74
73
|
|
75
74
|
def go(*args)
|
@@ -77,17 +76,16 @@ class Rbkb::Cli::Blit < Rbkb::Cli::Executable
|
|
77
76
|
|
78
77
|
begin
|
79
78
|
Plug::Blit.blit_init(
|
80
|
-
:
|
81
|
-
:
|
82
|
-
:
|
79
|
+
addr: @opts[:b_addr],
|
80
|
+
port: @opts[:b_port],
|
81
|
+
protocol: @opts[:b_proto]
|
83
82
|
)
|
84
83
|
|
85
84
|
Plug::Blit.blit_raw(@blit_msg)
|
86
|
-
rescue
|
85
|
+
rescue StandardError
|
87
86
|
bail($!)
|
88
87
|
end
|
89
88
|
|
90
89
|
self.exit(0)
|
91
90
|
end
|
92
|
-
|
93
91
|
end
|
data/lib/rbkb/cli/chars.rb
CHANGED
@@ -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
|
# Repeats an argument N times
|
@@ -21,4 +21,3 @@ class Rbkb::Cli::Chars < Rbkb::Cli::Executable
|
|
21
21
|
self.exit(0)
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
data/lib/rbkb/cli/crc32.rb
CHANGED
@@ -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
|
# crc32 returns a crc32 checksum in hex from stdin or a file
|
@@ -11,9 +11,9 @@ class Rbkb::Cli::Crc32 < Rbkb::Cli::Executable
|
|
11
11
|
@opts[:last] ||= -1
|
12
12
|
end
|
13
13
|
|
14
|
-
def make_parser
|
14
|
+
def make_parser
|
15
15
|
arg = super()
|
16
|
-
arg.banner +=
|
16
|
+
arg.banner += ' [filename]'
|
17
17
|
add_std_file_opt(:indat)
|
18
18
|
add_range_opts(:first, :last)
|
19
19
|
end
|
@@ -21,18 +21,16 @@ class Rbkb::Cli::Crc32 < Rbkb::Cli::Executable
|
|
21
21
|
def parse(*args)
|
22
22
|
super(*args)
|
23
23
|
parse_file_argument(:indat)
|
24
|
-
parse_catchall
|
24
|
+
parse_catchall
|
25
25
|
end
|
26
26
|
|
27
27
|
def go(*args)
|
28
28
|
super(*args)
|
29
|
-
@opts[:indat] ||= @stdin.read
|
29
|
+
@opts[:indat] ||= @stdin.read
|
30
30
|
dat = opts[:indat].force_to_binary
|
31
|
-
dat = dat[
|
32
|
-
dat ||=
|
33
|
-
@stdout.puts(
|
31
|
+
dat = dat[@opts[:first]..@opts[:last]]
|
32
|
+
dat ||= ''
|
33
|
+
@stdout.puts('%0.8x' % dat.force_to_binary.crc32)
|
34
34
|
self.exit(0)
|
35
35
|
end
|
36
36
|
end
|
37
|
-
|
38
|
-
|
data/lib/rbkb/cli/d64.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
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
|
# d64 converts a base-64 encoded string back to its orginal form.
|
7
7
|
class Rbkb::Cli::D64 < Rbkb::Cli::Executable
|
8
8
|
def make_parser
|
9
9
|
super()
|
10
|
-
@oparse.banner +=
|
10
|
+
@oparse.banner += ' <data | blank for stdin>'
|
11
11
|
add_std_file_opt(:indat)
|
12
12
|
end
|
13
13
|
|
@@ -15,7 +15,7 @@ class Rbkb::Cli::D64 < Rbkb::Cli::Executable
|
|
15
15
|
super(*args)
|
16
16
|
parse_string_argument(:indat)
|
17
17
|
parse_file_argument(:indat)
|
18
|
-
parse_catchall
|
18
|
+
parse_catchall
|
19
19
|
@opts[:indat] ||= @stdin.read
|
20
20
|
end
|
21
21
|
|
@@ -25,4 +25,3 @@ class Rbkb::Cli::D64 < Rbkb::Cli::Executable
|
|
25
25
|
self.exit(0)
|
26
26
|
end
|
27
27
|
end
|
28
|
-
|
data/lib/rbkb/cli/dedump.rb
CHANGED
@@ -1,53 +1,50 @@
|
|
1
1
|
require 'rbkb/cli'
|
2
2
|
require 'rbkb/extends'
|
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
|
-
# Reverses a hexdump back to raw data. Designed to work with hexdumps created
|
7
|
+
# Reverses a hexdump back to raw data. Designed to work with hexdumps created
|
8
8
|
# by Unix utilities like 'xxd' as well as 'hexdump -C'.
|
9
9
|
class Rbkb::Cli::Dedump < Rbkb::Cli::Executable
|
10
10
|
def initialize(*args)
|
11
|
-
super(*args)
|
11
|
+
super(*args) do |this|
|
12
12
|
this.opts[:len] ||= 16
|
13
13
|
yield this if block_given?
|
14
|
-
|
14
|
+
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def make_parser
|
17
|
+
def make_parser
|
18
18
|
arg = super()
|
19
|
-
arg.banner +=
|
19
|
+
arg.banner += ' <input-file | blank for stdin>'
|
20
20
|
|
21
|
-
arg.on(
|
22
|
-
|
23
|
-
|
21
|
+
arg.on('-l', '--length LEN', Numeric,
|
22
|
+
"Bytes per line in hexdump (Default: #{@opts[:len]})") do |l|
|
23
|
+
bail('Length must be greater than zero') unless (@opts[:len] = l) > 0
|
24
24
|
end
|
25
|
-
|
25
|
+
arg
|
26
26
|
end
|
27
27
|
|
28
28
|
def parse(*args)
|
29
29
|
super(*args)
|
30
30
|
parse_file_argument(:indat)
|
31
|
-
parse_catchall
|
31
|
+
parse_catchall
|
32
32
|
end
|
33
33
|
|
34
34
|
def go(*args)
|
35
35
|
super(*args)
|
36
36
|
|
37
37
|
# Default to standard input
|
38
|
-
@opts[:indat] ||= @stdin.read
|
38
|
+
@opts[:indat] ||= @stdin.read
|
39
39
|
|
40
|
-
self.exit(1) unless(
|
40
|
+
self.exit(1) unless (@opts[:len] ||= @opts[:indat].length) > 0
|
41
41
|
|
42
42
|
begin
|
43
|
-
@opts[:indat].dehexdump(
|
44
|
-
rescue
|
43
|
+
@opts[:indat].dehexdump(len: @opts[:len], out: @stdout)
|
44
|
+
rescue StandardError
|
45
45
|
bail "Error: #{$!}"
|
46
46
|
end
|
47
47
|
|
48
48
|
self.exit(0)
|
49
49
|
end
|
50
50
|
end
|
51
|
-
|
52
|
-
|
53
|
-
|
data/lib/rbkb/cli/feed.rb
CHANGED
@@ -7,10 +7,10 @@ require 'eventmachine'
|
|
7
7
|
# See README.rdoc for license information
|
8
8
|
#
|
9
9
|
# This is a plug-board message feeder from static data sources.
|
10
|
-
# The "feed" handles messages opaquely and just plays them in the given
|
10
|
+
# The "feed" handles messages opaquely and just plays them in the given
|
11
11
|
# sequence.
|
12
12
|
#
|
13
|
-
# Feed can do the following things with minimum fuss:
|
13
|
+
# Feed can do the following things with minimum fuss:
|
14
14
|
# - Import messages from files, yaml, or pcap
|
15
15
|
# - Inject custom/modified messages with "blit"
|
16
16
|
# - Run as a server or client using UDP or TCP
|
@@ -29,7 +29,7 @@ require 'eventmachine'
|
|
29
29
|
|
30
30
|
class Rbkb::Cli::Feed < Rbkb::Cli::Executable
|
31
31
|
def initialize(*args)
|
32
|
-
@local_addr =
|
32
|
+
@local_addr = '0.0.0.0'
|
33
33
|
@local_port = nil
|
34
34
|
@listen = false
|
35
35
|
@persist = false
|
@@ -39,108 +39,106 @@ class Rbkb::Cli::Feed < Rbkb::Cli::Executable
|
|
39
39
|
@blit_addr = Plug::Blit::DEFAULT_IPADDR
|
40
40
|
@blit_port = Plug::Blit::DEFAULT_PORT
|
41
41
|
|
42
|
-
|
43
42
|
## Default options sent to the Feed handler
|
44
|
-
@feed_opts = {
|
45
|
-
:
|
46
|
-
:
|
47
|
-
:
|
43
|
+
@feed_opts = {
|
44
|
+
close_at_end: false,
|
45
|
+
step: false,
|
46
|
+
go_first: false
|
48
47
|
}
|
49
48
|
|
50
49
|
super(*args)
|
51
50
|
|
52
|
-
# TODO Plug::UI obviously need fixing.
|
51
|
+
# TODO: Plug::UI obviously need fixing.
|
53
52
|
# TODO It shouldn't be driven by constants for configuration
|
54
53
|
Plug::UI::LOGCFG[:verbose] = true
|
55
54
|
Plug::UI::LOGCFG[:dump] = :hex
|
56
55
|
Plug::UI::LOGCFG[:out] = @stderr
|
57
56
|
end
|
58
57
|
|
59
|
-
def make_parser
|
58
|
+
def make_parser
|
60
59
|
arg = super()
|
61
|
-
arg.banner +=
|
60
|
+
arg.banner += ' host:port'
|
62
61
|
|
63
|
-
arg.on(
|
64
|
-
Plug::UI::LOGCFG[:out] = File.open(o,
|
62
|
+
arg.on('-o', '--output=FILE', 'Output to file') do |o|
|
63
|
+
Plug::UI::LOGCFG[:out] = File.open(o, 'w')
|
65
64
|
end
|
66
65
|
|
67
|
-
arg.on(
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
raise "Invalid listen argument: #{p.inspect}"
|
74
|
-
end
|
66
|
+
arg.on('-l', '--listen=(ADDR:?)PORT', 'Server - on port (and addr?)') do |p|
|
67
|
+
raise "Invalid listen argument: #{p.inspect}" unless /^(?:([\w._-]+):)?(\d+)$/.match(p)
|
68
|
+
|
69
|
+
@local_addr = ::Regexp.last_match(1) if ::Regexp.last_match(1)
|
70
|
+
@local_port = ::Regexp.last_match(2).to_i
|
71
|
+
@listen = true
|
75
72
|
end
|
76
73
|
|
77
|
-
arg.on(
|
78
|
-
if
|
79
|
-
@local_addr =
|
80
|
-
@local_port =
|
74
|
+
arg.on('-s', '--source=(ADDR:?)PORT', 'Bind client on port and addr') do |p|
|
75
|
+
if /^(?:([\w.]+):)?(\d+)$/.match(p)
|
76
|
+
@local_addr = ::Regexp.last_match(1) if ::Regexp.last_match(1)
|
77
|
+
@local_port = ::Regexp.last_match(2).to_i
|
81
78
|
else
|
82
79
|
bail("Invalid source argument: #{p.inspect}")
|
83
80
|
end
|
84
81
|
end
|
85
82
|
|
86
|
-
arg.on(
|
83
|
+
arg.on('-b', '--blit=(ADDR:)?PORT', 'Where to listen for blit') do |b|
|
87
84
|
puts b
|
88
|
-
unless(m
|
85
|
+
unless (m = /^(?:([\w._-]+):)?(\d+)$/.match(b))
|
89
86
|
raise "Invalid blit argument: #{b.inspect}"
|
90
87
|
end
|
88
|
+
|
91
89
|
@blit_port = m[2].to_i
|
92
90
|
@blit_addr = m[1] if m[1]
|
93
91
|
end
|
94
92
|
|
95
|
-
arg.on(
|
93
|
+
arg.on('-i', '--[no-]initiate', 'Send the first message on connect') do |i|
|
96
94
|
@feed_opts[:go_first] = i
|
97
95
|
end
|
98
96
|
|
99
|
-
arg.on(
|
97
|
+
arg.on('-e', '--[no-]end', 'End connection when feed is exhausted') do |c|
|
100
98
|
@feed_opts[:close_at_end] = c
|
101
99
|
end
|
102
|
-
|
103
|
-
arg.on(
|
100
|
+
|
101
|
+
arg.on('--[no-]step', "'Continue' prompt between messages") do |s|
|
104
102
|
@feed_opts[:step] = s
|
105
103
|
end
|
106
104
|
|
107
|
-
arg.on(
|
105
|
+
arg.on('-u', '--udp', 'Use UDP instead of TCP') do
|
108
106
|
@transport = :UDP
|
109
107
|
end
|
110
108
|
|
111
|
-
arg.on(
|
112
|
-
@persist=true
|
109
|
+
arg.on('-r', '--reconnect', 'Attempt to reconnect endlessly.') do
|
110
|
+
@persist = true
|
113
111
|
end
|
114
112
|
|
115
|
-
arg.on(
|
113
|
+
arg.on('-q', '--quiet', 'Suppress verbose messages/dumps') do
|
116
114
|
Plug::UI::LOGCFG[:verbose] = false
|
117
115
|
end
|
118
116
|
|
119
|
-
arg.on(
|
117
|
+
arg.on('-Q', '--squelch-exhausted', "Squelch 'FEED EXHAUSTED' messages") do |_s|
|
120
118
|
@feed_opts[:squelch_exhausted] = true
|
121
119
|
end
|
122
120
|
|
123
|
-
arg.separator
|
121
|
+
arg.separator ' Sources: (can be combined)'
|
124
122
|
|
125
|
-
arg.on(
|
123
|
+
arg.on('-f', '--from-files=GLOB', 'Import messages from raw files') do |f|
|
126
124
|
@feed_opts[:feed] ||= []
|
127
125
|
@feed_opts[:feed] += FeedImport.import_rawfiles(f)
|
128
126
|
end
|
129
127
|
|
130
|
-
arg.on(
|
128
|
+
arg.on('-x', '--from-hex=FILE', 'Import messages from hexdumps') do |x|
|
131
129
|
@feed_opts[:feed] ||= []
|
132
130
|
@feed_opts[:feed] += FeedImport.import_dump(x)
|
133
131
|
end
|
134
132
|
|
135
|
-
arg.on(
|
133
|
+
arg.on('-y', '--from-yaml=FILE', 'Import messages from yaml') do |y|
|
136
134
|
@feed_opts[:feed] ||= []
|
137
135
|
@feed_opts[:feed] += FeedImport.import_yaml(y)
|
138
136
|
end
|
139
137
|
|
140
|
-
arg.on(
|
138
|
+
arg.on('-p', '--from-pcap=FILE[:FILTER]', 'Import messages from pcap') do |p|
|
141
139
|
if /^([^:]+):(.+)$/.match(p)
|
142
|
-
file =
|
143
|
-
filter =
|
140
|
+
file = ::Regexp.last_match(1)
|
141
|
+
filter = ::Regexp.last_match(2)
|
144
142
|
else
|
145
143
|
file = p
|
146
144
|
filter = nil
|
@@ -154,9 +152,7 @@ class Rbkb::Cli::Feed < Rbkb::Cli::Executable
|
|
154
152
|
def parse(*args)
|
155
153
|
super(*args)
|
156
154
|
|
157
|
-
if @transport == :UDP
|
158
|
-
@svr_method = @cli_method = :open_datagram_socket
|
159
|
-
end
|
155
|
+
@svr_method = @cli_method = :open_datagram_socket if @transport == :UDP
|
160
156
|
|
161
157
|
@local_port ||= 0
|
162
158
|
# Prepare EventMachine arguments based on whether we are a client or server
|
@@ -168,18 +164,18 @@ class Rbkb::Cli::Feed < Rbkb::Cli::Executable
|
|
168
164
|
else # client
|
169
165
|
|
170
166
|
## Get target/listen argument for client mode
|
171
|
-
unless (m = /^([\w
|
167
|
+
unless (m = /^([\w.]+):(\d+)$/.match(tgt = @argv.shift))
|
172
168
|
bail_args tgt
|
173
169
|
end
|
174
170
|
|
175
171
|
@target_addr = m[1]
|
176
172
|
@target_port = m[2].to_i
|
177
173
|
|
178
|
-
if @transport == :UDP
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
174
|
+
addr_args = if @transport == :UDP
|
175
|
+
[@local_addr, @local_port]
|
176
|
+
else
|
177
|
+
[@local_addr, @local_port, @target_addr, @target_port]
|
178
|
+
end
|
183
179
|
|
184
180
|
@meth = @cli_method
|
185
181
|
@feed_opts[:kind] = :client
|
@@ -187,18 +183,17 @@ class Rbkb::Cli::Feed < Rbkb::Cli::Executable
|
|
187
183
|
|
188
184
|
@feed_opts[:feed] ||= []
|
189
185
|
|
190
|
-
@em_args=[
|
191
|
-
@meth,
|
186
|
+
@em_args = [
|
187
|
+
@meth,
|
192
188
|
addr_args,
|
193
|
-
Plug::ArrayFeeder,
|
194
|
-
@transport,
|
189
|
+
Plug::ArrayFeeder,
|
190
|
+
@transport,
|
195
191
|
@feed_opts
|
196
192
|
].flatten
|
197
193
|
|
198
|
-
parse_catchall
|
194
|
+
parse_catchall
|
199
195
|
end
|
200
196
|
|
201
|
-
|
202
197
|
def go(*args)
|
203
198
|
super(*args)
|
204
199
|
|
@@ -206,13 +201,13 @@ class Rbkb::Cli::Feed < Rbkb::Cli::Executable
|
|
206
201
|
|
207
202
|
## Start the eventmachine
|
208
203
|
loop do
|
209
|
-
EventMachine
|
204
|
+
EventMachine.run do
|
210
205
|
EventMachine.send(*@em_args) do |c|
|
211
206
|
EventMachine.start_server(@blit_addr, @blit_port, Plug::Blit, :TCP, c)
|
212
|
-
Plug::UI
|
207
|
+
Plug::UI.verbose("** BLITSRV-#{@blit_addr}:#{@blit_port}(TCP) Started")
|
213
208
|
|
214
209
|
# if this is a UDP client, we will always send the first message
|
215
|
-
if [
|
210
|
+
if %i[UDP client] == [@transport, c.kind]
|
216
211
|
peer = c.peers.add_peer_manually(@target_addr, @target_port)
|
217
212
|
c.feed_data(peer)
|
218
213
|
c.go_first = false
|
@@ -221,9 +216,8 @@ class Rbkb::Cli::Feed < Rbkb::Cli::Executable
|
|
221
216
|
end
|
222
217
|
|
223
218
|
break unless @persist
|
224
|
-
Plug::UI::verbose("** RECONNECTING")
|
225
|
-
end
|
226
219
|
|
220
|
+
Plug::UI.verbose('** RECONNECTING')
|
221
|
+
end
|
227
222
|
end
|
228
223
|
end
|
229
|
-
|
data/lib/rbkb/cli/hexify.rb
CHANGED
@@ -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
|
-
# The hexify command converts a string or raw data to hex characters.
|
6
|
+
# The hexify command converts a string or raw data to hex characters.
|
7
7
|
# Input can be supplied via stdin, a string argument, or a file (with -f).
|
8
8
|
class Rbkb::Cli::Hexify < Rbkb::Cli::Executable
|
9
9
|
def make_parser
|
@@ -12,21 +12,21 @@ class Rbkb::Cli::Hexify < Rbkb::Cli::Executable
|
|
12
12
|
arg = @oparse
|
13
13
|
|
14
14
|
# Add local options
|
15
|
-
arg.banner +=
|
15
|
+
arg.banner += ' <data | blank for stdin>'
|
16
16
|
|
17
|
-
arg.on(
|
17
|
+
arg.on('-l', '--length LEN', Numeric, 'Output lines of LEN bytes') do |l|
|
18
18
|
@opts[:len] = l
|
19
19
|
end
|
20
20
|
|
21
|
-
arg.on(
|
21
|
+
arg.on('-d', '--delim=DELIMITER', 'DELIMITER between each byte') do |d|
|
22
22
|
@opts[:delim] = d
|
23
23
|
end
|
24
24
|
|
25
|
-
arg.on(
|
25
|
+
arg.on('-p', '--prefix=PREFIX', 'PREFIX before each byte') do |p|
|
26
26
|
@opts[:prefix] = p
|
27
27
|
end
|
28
28
|
|
29
|
-
arg.on(
|
29
|
+
arg.on('-s', '--suffix=SUFFIX', 'SUFFIX after each byte') do |s|
|
30
30
|
@opts[:suffix] = s
|
31
31
|
end
|
32
32
|
end
|
@@ -35,31 +35,30 @@ class Rbkb::Cli::Hexify < Rbkb::Cli::Executable
|
|
35
35
|
super(*args)
|
36
36
|
|
37
37
|
# blackbag-style space delimiter compatability
|
38
|
-
if @argv[0] ==
|
39
|
-
@opts[:delim]=
|
38
|
+
if @argv[0] == '+' and @opts[:delim].nil?
|
39
|
+
@opts[:delim] = ' '
|
40
40
|
@argv.shift
|
41
41
|
end
|
42
42
|
|
43
43
|
parse_string_argument(:indat)
|
44
|
-
parse_catchall
|
44
|
+
parse_catchall
|
45
45
|
end
|
46
46
|
|
47
47
|
def go(*args)
|
48
48
|
super(*args)
|
49
49
|
|
50
50
|
# Default to standard input
|
51
|
-
@opts[:indat] ||= @stdin.read
|
51
|
+
@opts[:indat] ||= @stdin.read
|
52
52
|
|
53
53
|
indat = @opts.delete(:indat)
|
54
|
-
len =
|
54
|
+
len = @opts.delete(:len) || indat.length
|
55
55
|
|
56
|
-
bail(
|
56
|
+
bail('Length must be greater than zero') unless len > 0
|
57
57
|
|
58
|
-
until (m = indat.slice!(0..len-1)).empty?
|
58
|
+
until (m = indat.slice!(0..len - 1)).empty?
|
59
59
|
@stdout << m.hexify(@opts)
|
60
|
-
@stdout.puts((opts[:delim] and !
|
60
|
+
@stdout.puts((opts[:delim] and !indat.empty?) ? opts[:delim] : "\n")
|
61
61
|
end
|
62
62
|
self.exit(0)
|
63
63
|
end
|
64
64
|
end
|
65
|
-
|