ronin-support 0.4.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (224) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +11 -0
  3. data/.github/workflows/ruby.yml +28 -0
  4. data/.ruby-version +1 -0
  5. data/.yardopts +1 -1
  6. data/ChangeLog.md +121 -33
  7. data/Gemfile +17 -18
  8. data/README.md +57 -33
  9. data/Rakefile +10 -3
  10. data/gemspec.yml +16 -7
  11. data/lib/ronin/binary.rb +21 -0
  12. data/lib/ronin/binary/hexdump.rb +20 -0
  13. data/lib/ronin/binary/hexdump/parser.rb +403 -0
  14. data/lib/ronin/binary/struct.rb +567 -0
  15. data/lib/ronin/binary/template.rb +454 -0
  16. data/lib/ronin/extensions.rb +5 -5
  17. data/lib/ronin/extensions/enumerable.rb +5 -5
  18. data/lib/ronin/extensions/file.rb +39 -33
  19. data/lib/ronin/extensions/ip_addr.rb +29 -31
  20. data/lib/ronin/extensions/kernel.rb +5 -5
  21. data/lib/ronin/extensions/meta.rb +5 -5
  22. data/lib/ronin/extensions/regexp.rb +50 -5
  23. data/lib/ronin/extensions/resolv.rb +7 -9
  24. data/lib/ronin/extensions/string.rb +10 -10
  25. data/lib/ronin/formatting.rb +5 -5
  26. data/lib/ronin/formatting/binary.rb +5 -5
  27. data/lib/ronin/formatting/digest.rb +5 -5
  28. data/lib/ronin/formatting/extensions.rb +5 -5
  29. data/lib/ronin/formatting/extensions/binary.rb +7 -5
  30. data/lib/ronin/formatting/extensions/binary/array.rb +61 -0
  31. data/lib/ronin/formatting/extensions/binary/base64.rb +106 -0
  32. data/lib/ronin/formatting/extensions/binary/file.rb +44 -11
  33. data/lib/ronin/formatting/extensions/binary/float.rb +65 -0
  34. data/lib/ronin/formatting/extensions/binary/integer.rb +66 -50
  35. data/lib/ronin/formatting/extensions/binary/string.rb +81 -205
  36. data/lib/ronin/formatting/extensions/digest.rb +5 -5
  37. data/lib/ronin/formatting/extensions/digest/file.rb +5 -5
  38. data/lib/ronin/formatting/extensions/digest/string.rb +5 -5
  39. data/lib/ronin/formatting/extensions/html.rb +5 -5
  40. data/lib/ronin/formatting/extensions/html/integer.rb +9 -13
  41. data/lib/ronin/formatting/extensions/html/string.rb +31 -39
  42. data/lib/ronin/formatting/extensions/http.rb +5 -5
  43. data/lib/ronin/formatting/extensions/http/integer.rb +6 -6
  44. data/lib/ronin/formatting/extensions/http/string.rb +7 -7
  45. data/lib/ronin/formatting/extensions/sql.rb +5 -5
  46. data/lib/ronin/formatting/extensions/sql/string.rb +22 -24
  47. data/lib/ronin/formatting/extensions/text.rb +5 -5
  48. data/lib/ronin/formatting/extensions/text/array.rb +13 -11
  49. data/lib/ronin/formatting/extensions/text/string.rb +70 -13
  50. data/lib/ronin/formatting/html.rb +5 -5
  51. data/lib/ronin/formatting/http.rb +5 -5
  52. data/lib/ronin/formatting/sql.rb +5 -5
  53. data/lib/ronin/formatting/text.rb +5 -5
  54. data/lib/ronin/fuzzing.rb +5 -5
  55. data/lib/ronin/fuzzing/extensions.rb +5 -5
  56. data/lib/ronin/fuzzing/extensions/string.rb +42 -213
  57. data/lib/ronin/fuzzing/fuzzer.rb +110 -0
  58. data/lib/ronin/fuzzing/fuzzing.rb +33 -26
  59. data/lib/ronin/fuzzing/mutator.rb +161 -0
  60. data/lib/ronin/fuzzing/repeater.rb +81 -0
  61. data/lib/ronin/fuzzing/template.rb +133 -0
  62. data/lib/ronin/mixin.rb +2 -2
  63. data/lib/ronin/network.rb +7 -5
  64. data/lib/ronin/network/dns.rb +64 -24
  65. data/lib/ronin/network/esmtp.rb +5 -5
  66. data/lib/ronin/network/extensions.rb +5 -5
  67. data/lib/ronin/network/extensions/dns.rb +5 -5
  68. data/lib/ronin/network/extensions/dns/net.rb +5 -5
  69. data/lib/ronin/network/extensions/esmtp.rb +5 -5
  70. data/lib/ronin/network/extensions/esmtp/net.rb +5 -5
  71. data/lib/ronin/network/extensions/http.rb +5 -5
  72. data/lib/ronin/network/extensions/http/net.rb +5 -5
  73. data/lib/ronin/network/extensions/http/uri/http.rb +5 -5
  74. data/lib/ronin/network/extensions/imap.rb +5 -5
  75. data/lib/ronin/network/extensions/imap/net.rb +5 -5
  76. data/lib/ronin/network/extensions/pop3.rb +5 -5
  77. data/lib/ronin/network/extensions/pop3/net.rb +5 -5
  78. data/lib/ronin/network/extensions/smtp.rb +5 -5
  79. data/lib/ronin/network/extensions/smtp/net.rb +5 -5
  80. data/lib/ronin/network/extensions/ssl.rb +5 -5
  81. data/lib/ronin/network/extensions/ssl/net.rb +5 -5
  82. data/lib/ronin/network/extensions/tcp.rb +5 -5
  83. data/lib/ronin/network/extensions/tcp/net.rb +5 -5
  84. data/lib/ronin/network/extensions/telnet.rb +5 -5
  85. data/lib/ronin/network/extensions/telnet/net.rb +5 -5
  86. data/lib/ronin/network/extensions/udp.rb +5 -5
  87. data/lib/ronin/network/extensions/udp/net.rb +5 -5
  88. data/lib/ronin/network/ftp.rb +149 -0
  89. data/lib/ronin/network/http.rb +5 -5
  90. data/lib/ronin/network/http/exceptions.rb +5 -5
  91. data/lib/ronin/network/http/exceptions/unknown_request.rb +5 -5
  92. data/lib/ronin/network/http/http.rb +65 -70
  93. data/lib/ronin/network/http/proxy.rb +5 -5
  94. data/lib/ronin/network/imap.rb +16 -15
  95. data/lib/ronin/network/mixins.rb +6 -5
  96. data/lib/ronin/network/mixins/dns.rb +5 -5
  97. data/lib/ronin/network/mixins/esmtp.rb +5 -5
  98. data/lib/ronin/network/mixins/ftp.rb +155 -0
  99. data/lib/ronin/network/mixins/http.rb +58 -587
  100. data/lib/ronin/network/mixins/imap.rb +5 -5
  101. data/lib/ronin/network/mixins/mixin.rb +5 -5
  102. data/lib/ronin/network/mixins/pop3.rb +5 -5
  103. data/lib/ronin/network/mixins/smtp.rb +5 -5
  104. data/lib/ronin/network/mixins/ssl.rb +5 -5
  105. data/lib/ronin/network/mixins/tcp.rb +43 -10
  106. data/lib/ronin/network/mixins/telnet.rb +5 -5
  107. data/lib/ronin/network/mixins/udp.rb +126 -6
  108. data/lib/ronin/network/mixins/unix.rb +279 -0
  109. data/lib/ronin/network/network.rb +5 -5
  110. data/lib/ronin/network/pop3.rb +10 -10
  111. data/lib/ronin/network/proxy.rb +578 -0
  112. data/lib/ronin/network/smtp.rb +5 -5
  113. data/lib/ronin/network/smtp/email.rb +6 -6
  114. data/lib/ronin/network/smtp/smtp.rb +12 -13
  115. data/lib/ronin/network/ssl.rb +16 -17
  116. data/lib/ronin/network/tcp.rb +7 -310
  117. data/lib/ronin/network/tcp/proxy.rb +417 -0
  118. data/lib/ronin/network/tcp/tcp.rb +452 -0
  119. data/lib/ronin/network/telnet.rb +34 -28
  120. data/lib/ronin/network/udp.rb +7 -271
  121. data/lib/ronin/network/udp/proxy.rb +191 -0
  122. data/lib/ronin/network/udp/udp.rb +452 -0
  123. data/lib/ronin/network/unix.rb +286 -0
  124. data/lib/ronin/path.rb +35 -39
  125. data/lib/ronin/spec/ui/output.rb +6 -12
  126. data/lib/ronin/support.rb +6 -5
  127. data/lib/ronin/support/inflector.rb +8 -12
  128. data/lib/ronin/support/support.rb +7 -5
  129. data/lib/ronin/support/version.rb +6 -6
  130. data/lib/ronin/templates.rb +5 -5
  131. data/lib/ronin/templates/erb.rb +5 -5
  132. data/lib/ronin/templates/template.rb +5 -5
  133. data/lib/ronin/ui/output.rb +5 -5
  134. data/lib/ronin/ui/output/helpers.rb +42 -28
  135. data/lib/ronin/ui/output/output.rb +17 -21
  136. data/lib/ronin/ui/output/terminal.rb +5 -5
  137. data/lib/ronin/ui/output/terminal/color.rb +15 -9
  138. data/lib/ronin/ui/output/terminal/raw.rb +5 -5
  139. data/lib/ronin/ui/shell.rb +8 -11
  140. data/lib/ronin/wordlist.rb +110 -30
  141. data/ronin-support.gemspec +39 -109
  142. data/spec/binary/hexdump/helpers/hexdumps.rb +13 -0
  143. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/ascii.bin +0 -0
  144. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_decimal_shorts.txt +0 -0
  145. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_hex_bytes.txt +0 -0
  146. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_hex_shorts.txt +0 -0
  147. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_octal_bytes.txt +0 -0
  148. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_octal_shorts.txt +0 -0
  149. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/hexdump_repeated.txt +0 -0
  150. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_decimal_bytes.txt +0 -0
  151. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_decimal_ints.txt +0 -0
  152. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_decimal_quads.txt +0 -0
  153. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_decimal_shorts.txt +0 -0
  154. data/spec/binary/hexdump/helpers/hexdumps/od_doubles.txt +17 -0
  155. data/spec/binary/hexdump/helpers/hexdumps/od_floats.txt +17 -0
  156. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_hex_bytes.txt +0 -0
  157. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_hex_ints.txt +0 -0
  158. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_hex_quads.txt +0 -0
  159. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_hex_shorts.txt +0 -0
  160. data/spec/binary/hexdump/helpers/hexdumps/od_named_chars.txt +17 -0
  161. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_octal_bytes.txt +0 -0
  162. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_octal_ints.txt +0 -0
  163. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_octal_quads.txt +0 -0
  164. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_octal_shorts.txt +0 -0
  165. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/od_repeated.txt +0 -0
  166. data/spec/{formatting/binary → binary/hexdump}/helpers/hexdumps/repeated.bin +0 -0
  167. data/spec/binary/hexdump/parser_spec.rb +302 -0
  168. data/spec/binary/struct_spec.rb +496 -0
  169. data/spec/binary/template_spec.rb +416 -0
  170. data/spec/extensions/enumerable_spec.rb +4 -4
  171. data/spec/extensions/file_spec.rb +12 -14
  172. data/spec/extensions/ip_addr_spec.rb +76 -50
  173. data/spec/extensions/kernel_spec.rb +7 -7
  174. data/spec/extensions/regexp_spec.rb +119 -59
  175. data/spec/extensions/resolv_spec.rb +2 -2
  176. data/spec/extensions/string_spec.rb +31 -30
  177. data/spec/formatting/binary/array_spec.rb +26 -0
  178. data/spec/formatting/binary/base64_spec.rb +50 -0
  179. data/spec/formatting/binary/float_spec.rb +36 -0
  180. data/spec/formatting/binary/integer_spec.rb +76 -50
  181. data/spec/formatting/binary/string_spec.rb +91 -198
  182. data/spec/formatting/digest/string_spec.rb +5 -5
  183. data/spec/formatting/html/integer_spec.rb +6 -6
  184. data/spec/formatting/html/string_spec.rb +10 -10
  185. data/spec/formatting/http/integer_spec.rb +3 -3
  186. data/spec/formatting/http/string_spec.rb +5 -5
  187. data/spec/formatting/sql/string_spec.rb +21 -19
  188. data/spec/formatting/text/array_spec.rb +15 -15
  189. data/spec/formatting/text/string_spec.rb +58 -28
  190. data/spec/fuzzing/extensions/string_spec.rb +87 -0
  191. data/spec/fuzzing/fuzzer_spec.rb +109 -0
  192. data/spec/fuzzing/fuzzing_spec.rb +24 -0
  193. data/spec/fuzzing/mutator_spec.rb +112 -0
  194. data/spec/fuzzing/repeater_spec.rb +57 -0
  195. data/spec/fuzzing/template_spec.rb +54 -0
  196. data/spec/mixin_spec.rb +10 -12
  197. data/spec/network/dns_spec.rb +89 -23
  198. data/spec/network/ftp_spec.rb +81 -0
  199. data/spec/network/http/http_spec.rb +237 -144
  200. data/spec/network/http/proxy_spec.rb +37 -37
  201. data/spec/network/network_spec.rb +2 -2
  202. data/spec/network/proxy_spec.rb +121 -0
  203. data/spec/network/shared/unix_server.rb +31 -0
  204. data/spec/network/smtp/email_spec.rb +14 -14
  205. data/spec/network/ssl_spec.rb +53 -3
  206. data/spec/network/tcp/proxy_spec.rb +118 -0
  207. data/spec/network/tcp/tcp_spec.rb +316 -0
  208. data/spec/network/telnet_spec.rb +67 -0
  209. data/spec/network/udp/udp_spec.rb +298 -0
  210. data/spec/network/unix_spec.rb +182 -0
  211. data/spec/path_spec.rb +43 -18
  212. data/spec/spec_helper.rb +2 -3
  213. data/spec/support/inflector_spec.rb +4 -4
  214. data/spec/support_spec.rb +1 -1
  215. data/spec/templates/erb_spec.rb +3 -3
  216. data/spec/templates/template_spec.rb +10 -10
  217. data/spec/ui/shell_spec.rb +15 -15
  218. data/spec/wordlist_spec.rb +80 -19
  219. metadata +176 -121
  220. data/.gemtest +0 -0
  221. data/spec/formatting/binary/helpers/hexdumps.rb +0 -16
  222. data/spec/fuzzing/string_spec.rb +0 -158
  223. data/spec/network/tcp_spec.rb +0 -247
  224. data/spec/network/udp_spec.rb +0 -248
@@ -0,0 +1,416 @@
1
+ # encoding: US-ASCII
2
+
3
+ require 'spec_helper'
4
+ require 'ronin/binary/template'
5
+
6
+ describe Binary::Template do
7
+ describe "TYPES" do
8
+ subject { described_class::TYPES }
9
+
10
+ it("uint8 => C") { expect(subject[:uint8]).to eq('C' ) }
11
+ it("uint16 => S") { expect(subject[:uint16]).to eq('S' ) }
12
+ it("uint32 => L") { expect(subject[:uint32]).to eq('L' ) }
13
+ it("uint64 => Q") { expect(subject[:uint64]).to eq('Q' ) }
14
+ it("int8 => C") { expect(subject[:int8]).to eq('c' ) }
15
+ it("int16 => S") { expect(subject[:int16]).to eq('s' ) }
16
+ it("int32 => L") { expect(subject[:int32]).to eq('l' ) }
17
+ it("int64 => Q") { expect(subject[:int64]).to eq('q' ) }
18
+ if RUBY_VERSION < '1.9.'
19
+ it("uint16_le => v") { expect(subject[:uint16_le]).to eq('v' ) }
20
+ it("uint32_le => V") { expect(subject[:uint32_le]).to eq('V' ) }
21
+ it("uint16_be => n") { expect(subject[:uint16_be]).to eq('n' ) }
22
+ it("uint32_be => N") { expect(subject[:uint32_be]).to eq('N' ) }
23
+ end
24
+ it("uchar => Z") { expect(subject[:uchar]).to eq('Z' ) }
25
+ it("ushort => S!") { expect(subject[:ushort]).to eq('S!') }
26
+ it("uint => I!") { expect(subject[:uint]).to eq('I!') }
27
+ it("ulong => L!") { expect(subject[:ulong]).to eq('L!') }
28
+ it("ulong_long => Q") { expect(subject[:ulong_long]).to eq('Q' ) }
29
+ it("char => Z") { expect(subject[:char]).to eq('Z' ) }
30
+ it("short => s!") { expect(subject[:short]).to eq('s!') }
31
+ it("int => i!") { expect(subject[:int]).to eq('i!') }
32
+ it("long => l!") { expect(subject[:long]).to eq('l!') }
33
+ it("long_long => q") { expect(subject[:long_long]).to eq('q' ) }
34
+ it("utf8 => U") { expect(subject[:utf8]).to eq('U' ) }
35
+ it("float => F") { expect(subject[:float]).to eq('F' ) }
36
+ it("double => D") { expect(subject[:double]).to eq('D' ) }
37
+ it("float_le => e") { expect(subject[:float_le]).to eq('e' ) }
38
+ it("double_le => E") { expect(subject[:double_le]).to eq('E' ) }
39
+ it("float_be => g") { expect(subject[:float_be]).to eq('g' ) }
40
+ it("double_ge => G") { expect(subject[:double_be]).to eq('G' ) }
41
+ it("ubyte => C") { expect(subject[:ubyte]).to eq('C' ) }
42
+ it("byte => c") { expect(subject[:byte]).to eq('c' ) }
43
+ it("string => Z*") { expect(subject[:string]).to eq('Z*') }
44
+
45
+ if RUBY_VERSION > '1.9.'
46
+ context "Ruby 1.9" do
47
+ it("uint16_le => S<") { expect(subject[:uint16_le]).to eq('S<' ) }
48
+ it("uint32_le => L<") { expect(subject[:uint32_le]).to eq('L<' ) }
49
+ it("uint64_le => Q<") { expect(subject[:uint64_le]).to eq('Q<' ) }
50
+ it("int16_le => S<") { expect(subject[:int16_le]).to eq('s<' ) }
51
+ it("int32_le => L<") { expect(subject[:int32_le]).to eq('l<' ) }
52
+ it("int64_le => Q<") { expect(subject[:int64_le]).to eq('q<' ) }
53
+ it("uint16_be => S>") { expect(subject[:uint16_be]).to eq('S>' ) }
54
+ it("uint32_be => L>") { expect(subject[:uint32_be]).to eq('L>' ) }
55
+ it("uint64_be => Q>") { expect(subject[:uint64_be]).to eq('Q>' ) }
56
+ it("int16_be => S>") { expect(subject[:int16_be]).to eq('s>' ) }
57
+ it("int32_be => L>") { expect(subject[:int32_be]).to eq('l>' ) }
58
+ it("int64_be => Q>") { expect(subject[:int64_be]).to eq('q>' ) }
59
+ it("ushort_le => S!<") { expect(subject[:ushort_le]).to eq('S!<') }
60
+ it("uint_le => I!<") { expect(subject[:uint_le]).to eq('I!<') }
61
+ it("ulong_le => L!<") { expect(subject[:ulong_le]).to eq('L!<') }
62
+ it("ulong_long_le => L!<") { expect(subject[:ulong_long_le]).to eq('Q<' ) }
63
+ it("short_le => S!<") { expect(subject[:short_le]).to eq('s!<') }
64
+ it("int_le => I!<") { expect(subject[:int_le]).to eq('i!<') }
65
+ it("long_le => L!<") { expect(subject[:long_le]).to eq('l!<') }
66
+ it("long_long_le => L!<") { expect(subject[:long_long_le]).to eq('q<' ) }
67
+ it("ushort_be => S!>") { expect(subject[:ushort_be]).to eq('S!>') }
68
+ it("uint_be => I!>") { expect(subject[:uint_be]).to eq('I!>') }
69
+ it("ulong_be => L!>") { expect(subject[:ulong_be]).to eq('L!>') }
70
+ it("ulong_long_be => L!>") { expect(subject[:ulong_long_be]).to eq('Q>' ) }
71
+ it("short_be => S!>") { expect(subject[:short_be]).to eq('s!>') }
72
+ it("int_be => I!>") { expect(subject[:int_be]).to eq('i!>') }
73
+ it("long_be => L!>") { expect(subject[:long_be]).to eq('l!>') }
74
+ it("long_long_be => L!>") { expect(subject[:long_long_be]).to eq('q>' ) }
75
+ end
76
+ end
77
+ end
78
+
79
+ describe "translate" do
80
+ subject { described_class }
81
+
82
+ context "when given :endian" do
83
+ it "should translate endian-types" do
84
+ expect(subject.translate(:uint, :endian => :little)).to eq(:uint_le)
85
+ end
86
+
87
+ it "should not translate non-endian-types" do
88
+ expect(subject.translate(:string, :endian => :little)).to eq(:string)
89
+ end
90
+
91
+ it "should raise an ArgumentError for unknown endianness" do
92
+ expect {
93
+ subject.translate(:uint, :endian => :foo)
94
+ }.to raise_error(ArgumentError)
95
+ end
96
+ end
97
+ end
98
+
99
+ describe "compile" do
100
+ let(:type) { :uint }
101
+ let(:code) { subject::TYPES[type] }
102
+
103
+ subject { described_class }
104
+
105
+ it "should translate types to their pack codes" do
106
+ expect(subject.compile([type])).to eq(code)
107
+ end
108
+
109
+ it "should support specifying the length of a field" do
110
+ expect(subject.compile([[type, 10]])).to eq("#{code}10")
111
+ end
112
+
113
+ it "should raise ArgumentError for unknown types" do
114
+ expect {
115
+ subject.compile([:foo])
116
+ }.to raise_error(ArgumentError)
117
+ end
118
+ end
119
+
120
+ describe "#initialize" do
121
+ subject { described_class.new [:uint32, :string] }
122
+
123
+ it "should store the types" do
124
+ expect(subject.fields).to eq([
125
+ :uint32,
126
+ :string
127
+ ])
128
+ end
129
+
130
+ it "should raise ArgumentError for unknown types" do
131
+ expect {
132
+ described_class.new [:foo]
133
+ }.to raise_error(ArgumentError)
134
+ end
135
+ end
136
+
137
+ ENDIANNESS = if [0x1234].pack('S') == "\x34\x12"
138
+ :little
139
+ else
140
+ :big
141
+ end
142
+
143
+ let(:byte) { 0x41 }
144
+ let(:char) { 'A' }
145
+
146
+ let(:bytes) { [104, 101, 108, 108, 111] }
147
+ let(:chars) { bytes.map(&:chr).join }
148
+ let(:string) { chars }
149
+
150
+ let(:uint8) { 0xff }
151
+ let(:uint16) { 0xffff }
152
+ let(:uint32) { 0xffffffff }
153
+ let(:uint64) { 0xffffffffffffffff }
154
+
155
+ let(:int8) { -1 }
156
+ let(:int16) { -1 }
157
+ let(:int32) { -1 }
158
+ let(:int32) { -1 }
159
+ let(:int64) { -1 }
160
+
161
+ describe "#pack" do
162
+ context ":byte" do
163
+ subject { described_class.new [:byte] }
164
+
165
+ it "should pack a signed byte" do
166
+ expect(subject.pack(byte)).to eq(char)
167
+ end
168
+ end
169
+
170
+ context "[:byte, n]" do
171
+ let(:n) { string.length }
172
+ subject { described_class.new [[:byte, n]] }
173
+
174
+ it "should pack multiple signed characters" do
175
+ expect(subject.pack(*bytes)).to eq(chars)
176
+ end
177
+ end
178
+
179
+ context ":char" do
180
+ subject { described_class.new [:char] }
181
+
182
+ it "should pack a signed character" do
183
+ expect(subject.pack(char)).to eq(char)
184
+ end
185
+ end
186
+
187
+ context "[:char, n]" do
188
+ let(:n) { string.length }
189
+ subject { described_class.new [[:char, n]] }
190
+
191
+ it "should pack multiple signed characters" do
192
+ expect(subject.pack(*chars)).to eq(string)
193
+ end
194
+
195
+ context "padding" do
196
+ let(:padding) { 10 }
197
+ subject { described_class.new [[:char, n + padding]] }
198
+
199
+ it "should pad the string with '\\0' characters" do
200
+ expect(subject.pack(*chars)).to eq((string + ("\0" * padding)))
201
+ end
202
+ end
203
+ end
204
+
205
+ context ":uint8" do
206
+ subject { described_class.new [:uint8] }
207
+
208
+ it "should pack an unsigned 8bit integer" do
209
+ expect(subject.pack(uint8)).to eq("\xff")
210
+ end
211
+ end
212
+
213
+ context ":uint16" do
214
+ subject { described_class.new [:uint16] }
215
+
216
+ it "should pack an unsigned 16bit integer" do
217
+ expect(subject.pack(uint16)).to eq("\xff\xff")
218
+ end
219
+ end
220
+
221
+ context ":uint32" do
222
+ subject { described_class.new [:uint32] }
223
+
224
+ it "should pack an unsigned 32bit integer" do
225
+ expect(subject.pack(uint32)).to eq("\xff\xff\xff\xff")
226
+ end
227
+ end
228
+
229
+ context ":uint64" do
230
+ subject { described_class.new [:uint64] }
231
+
232
+ it "should pack an unsigned 64bit integer" do
233
+ expect(subject.pack(uint64)).to eq("\xff\xff\xff\xff\xff\xff\xff\xff")
234
+ end
235
+ end
236
+
237
+ context ":int8" do
238
+ subject { described_class.new [:int8] }
239
+
240
+ it "should pack an signed 8bit integer" do
241
+ expect(subject.pack(int8)).to eq("\xff")
242
+ end
243
+ end
244
+
245
+ context ":int16" do
246
+ subject { described_class.new [:int16] }
247
+
248
+ it "should pack an unsigned 16bit integer" do
249
+ expect(subject.pack(int16)).to eq("\xff\xff")
250
+ end
251
+ end
252
+
253
+ context ":int32" do
254
+ subject { described_class.new [:int32] }
255
+
256
+ it "should pack an unsigned 32bit integer" do
257
+ expect(subject.pack(int32)).to eq("\xff\xff\xff\xff")
258
+ end
259
+ end
260
+
261
+ context ":int64" do
262
+ subject { described_class.new [:int64] }
263
+
264
+ it "should pack an unsigned 64bit integer" do
265
+ expect(subject.pack(int64)).to eq("\xff\xff\xff\xff\xff\xff\xff\xff")
266
+ end
267
+ end
268
+
269
+ context ":string" do
270
+ subject { described_class.new [:string] }
271
+
272
+ it "should pack a string" do
273
+ expect(subject.pack(string)).to eq("#{string}\0")
274
+ end
275
+ end
276
+ end
277
+
278
+ describe "#unpack" do
279
+ context ":byte" do
280
+ subject { described_class.new [:byte] }
281
+
282
+ it "should unpack a signed byte" do
283
+ expect(subject.unpack(char)).to eq([byte])
284
+ end
285
+ end
286
+
287
+ context "[:byte, n]" do
288
+ let(:n) { string.length }
289
+ subject { described_class.new [[:byte, n]] }
290
+
291
+ it "should pack multiple signed characters" do
292
+ expect(subject.unpack(chars)).to eq(bytes)
293
+ end
294
+ end
295
+
296
+ context ":char" do
297
+ subject { described_class.new [:char] }
298
+
299
+ it "should unpack a signed character" do
300
+ expect(subject.unpack(char)).to eq([char])
301
+ end
302
+ end
303
+
304
+ context "[:char, n]" do
305
+ let(:n) { string.length }
306
+ subject { described_class.new [[:char, n]] }
307
+
308
+ it "should unpack multiple signed characters" do
309
+ expect(subject.unpack(string)).to eq([chars])
310
+ end
311
+
312
+ context "padding" do
313
+ let(:padding) { 10 }
314
+ subject { described_class.new [[:char, n + padding]] }
315
+
316
+ it "should strip '\\0' padding characters" do
317
+ expect(subject.unpack(string + ("\0" * padding))).to eq([chars])
318
+ end
319
+ end
320
+ end
321
+
322
+ context ":uint8" do
323
+ subject { described_class.new [:uint8] }
324
+
325
+ it "should unpack an unsigned 8bit integer" do
326
+ expect(subject.unpack("\xff")).to eq([uint8])
327
+ end
328
+ end
329
+
330
+ context ":uint16" do
331
+ subject { described_class.new [:uint16] }
332
+
333
+ it "should unpack an unsigned 16bit integer" do
334
+ expect(subject.unpack("\xff\xff")).to eq([uint16])
335
+ end
336
+ end
337
+
338
+ context ":uint32" do
339
+ subject { described_class.new [:uint32] }
340
+
341
+ it "should unpack an unsigned 32bit integer" do
342
+ expect(subject.unpack("\xff\xff\xff\xff")).to eq([uint32])
343
+ end
344
+ end
345
+
346
+ context ":uint64" do
347
+ subject { described_class.new [:uint64] }
348
+
349
+ it "should unpack an unsigned 64bit integer" do
350
+ expect(subject.unpack("\xff\xff\xff\xff\xff\xff\xff\xff")).to eq([uint64])
351
+ end
352
+ end
353
+
354
+ context ":int8" do
355
+ subject { described_class.new [:int8] }
356
+
357
+ it "should unpack an signed 8bit integer" do
358
+ expect(subject.unpack("\xff")).to eq([int8])
359
+ end
360
+ end
361
+
362
+ context ":int16" do
363
+ subject { described_class.new [:int16] }
364
+
365
+ it "should unpack an unsigned 16bit integer" do
366
+ expect(subject.unpack("\xff\xff")).to eq([int16])
367
+ end
368
+ end
369
+
370
+ context ":int32" do
371
+ subject { described_class.new [:int32] }
372
+
373
+ it "should unpack an unsigned 32bit integer" do
374
+ expect(subject.unpack("\xff\xff\xff\xff")).to eq([int32])
375
+ end
376
+ end
377
+
378
+ context ":int64" do
379
+ subject { described_class.new [:int64] }
380
+
381
+ it "should unpack an unsigned 64bit integer" do
382
+ expect(subject.unpack("\xff\xff\xff\xff\xff\xff\xff\xff")).to eq([int64])
383
+ end
384
+ end
385
+
386
+ context ":string" do
387
+ subject { described_class.new [:string] }
388
+
389
+ it "should unpack a string" do
390
+ expect(subject.unpack("#{string}\0")).to eq([string])
391
+ end
392
+ end
393
+ end
394
+
395
+ describe "#to_s" do
396
+ subject { described_class.new [:uint32, :string] }
397
+
398
+ it "should return the pack format String" do
399
+ expect(subject.to_s).to eq("LZ*")
400
+ end
401
+ end
402
+
403
+ describe "#inspect" do
404
+ let(:template) { described_class.new [:uint32, :string] }
405
+
406
+ subject { template.inspect }
407
+
408
+ it "should inspect the class" do
409
+ expect(subject).to include(described_class.name)
410
+ end
411
+
412
+ it "should inspect the template" do
413
+ expect(subject).to include(template.fields.inspect)
414
+ end
415
+ end
416
+ end
@@ -4,21 +4,21 @@ require 'ronin/extensions/enumerable'
4
4
  describe Enumerable do
5
5
  describe "#map_hash" do
6
6
  it "should map elements to a Hash" do
7
- [1, 2, 3].map_hash { |i| i ** 2 }.should == {
7
+ expect([1, 2, 3].map_hash { |i| i ** 2 }).to eq({
8
8
  1 => 1,
9
9
  2 => 4,
10
10
  3 => 9
11
- }
11
+ })
12
12
  end
13
13
 
14
14
  it "should not map the same element twice" do
15
- [1, 2, 2].map_hash { |i| rand }.keys.should =~ [1, 2]
15
+ expect([1, 2, 2].map_hash { |i| rand }.keys).to match_array([1, 2])
16
16
  end
17
17
 
18
18
  it "should set the default_proc of the Hash" do
19
19
  hash = [].map_hash { |i| i ** 2 }
20
20
 
21
- hash[3].should == 9
21
+ expect(hash[3]).to eq(9)
22
22
  end
23
23
  end
24
24
  end
@@ -7,20 +7,19 @@ describe File do
7
7
  subject { File }
8
8
 
9
9
  it "should provide File.escape_path" do
10
- subject.should respond_to(:escape_path)
10
+ expect(subject).to respond_to(:escape_path)
11
11
  end
12
12
 
13
13
  describe "each_line" do
14
14
  let(:lines) { %w[one two three] }
15
+ let(:path) { Tempfile.new('ronin-support-File#each_line') }
15
16
 
16
- before(:all) do
17
- @file = Tempfile.new('ronin-support')
18
- @file.puts(*lines)
19
- @file.close
17
+ before do
18
+ File.open(path,'w') { |file| file.puts(*lines) }
20
19
  end
21
20
 
22
21
  it "should enumerate over each line in the file" do
23
- File.each_line(@file.path).to_a.should == lines
22
+ expect(File.each_line(path).to_a).to eq(lines)
24
23
  end
25
24
  end
26
25
 
@@ -35,29 +34,28 @@ describe File do
35
34
  let(:separator) { '|' }
36
35
  let(:newline) { "\r\n" }
37
36
  let(:lines) { rows.map { |row| row.join(separator) }.join(newline) }
37
+ let(:path) { Tempfile.new('ronin-support-File#each_row') }
38
38
 
39
- before(:all) do
40
- @file = Tempfile.new('ronin-support')
41
- @file.write(lines)
42
- @file.close
39
+ before do
40
+ File.open(path,'w') { |file| file.puts(*lines) }
43
41
  end
44
42
 
45
43
  it "should enumerate over each row from each line" do
46
- File.each_row(@file.path,separator).to_a.should == rows
44
+ expect(File.each_row(path,separator).to_a).to eq(rows)
47
45
  end
48
46
  end
49
47
 
50
48
  describe "escape_path" do
51
49
  it "should remove null-bytes" do
52
- File.escape_path("hello\0world\0").should == "helloworld"
50
+ expect(File.escape_path("hello\0world\0")).to eq("helloworld")
53
51
  end
54
52
 
55
53
  it "should escape home-dir expansions" do
56
- File.escape_path("hello/~world").should == "hello/\\~world"
54
+ expect(File.escape_path("hello/~world")).to eq("hello/\\~world")
57
55
  end
58
56
 
59
57
  it "should remove '.' and '..' directories" do
60
- File.escape_path("hello/./../world").should == "world"
58
+ expect(File.escape_path("hello/./../world")).to eq("world")
61
59
  end
62
60
  end
63
61
  end