packetfu 1.1.10 → 1.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +2 -0
- data/.gitignore +3 -0
- data/.travis.yml +8 -0
- data/CONTRIBUTING.md +47 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +1 -1
- data/README.rdoc +35 -30
- data/Rakefile +4 -4
- data/bench/octets.rb +9 -9
- data/examples/100kpackets.rb +12 -12
- data/examples/ackscan.rb +16 -16
- data/examples/arp.rb +35 -35
- data/examples/arphood.rb +36 -36
- data/examples/dissect_thinger.rb +6 -6
- data/examples/new-simple-stats.rb +23 -23
- data/examples/packetfu-shell.rb +25 -25
- data/examples/simple-sniffer.rb +9 -9
- data/examples/simple-stats.rb +23 -23
- data/examples/slammer.rb +3 -3
- data/gem-public_cert.pem +21 -0
- data/lib/packetfu.rb +149 -127
- data/lib/packetfu/capture.rb +169 -169
- data/lib/packetfu/config.rb +52 -52
- data/lib/packetfu/inject.rb +56 -56
- data/lib/packetfu/packet.rb +531 -528
- data/lib/packetfu/pcap.rb +579 -579
- data/lib/packetfu/protos/arp.rb +90 -90
- data/lib/packetfu/protos/arp/header.rb +158 -158
- data/lib/packetfu/protos/arp/mixin.rb +36 -36
- data/lib/packetfu/protos/eth.rb +44 -44
- data/lib/packetfu/protos/eth/header.rb +243 -243
- data/lib/packetfu/protos/eth/mixin.rb +3 -3
- data/lib/packetfu/protos/hsrp.rb +69 -69
- data/lib/packetfu/protos/hsrp/header.rb +107 -107
- data/lib/packetfu/protos/hsrp/mixin.rb +29 -29
- data/lib/packetfu/protos/icmp.rb +71 -71
- data/lib/packetfu/protos/icmp/header.rb +82 -82
- data/lib/packetfu/protos/icmp/mixin.rb +14 -14
- data/lib/packetfu/protos/invalid.rb +49 -49
- data/lib/packetfu/protos/ip.rb +69 -69
- data/lib/packetfu/protos/ip/header.rb +291 -291
- data/lib/packetfu/protos/ip/mixin.rb +40 -40
- data/lib/packetfu/protos/ipv6.rb +50 -50
- data/lib/packetfu/protos/ipv6/header.rb +188 -188
- data/lib/packetfu/protos/ipv6/mixin.rb +29 -29
- data/lib/packetfu/protos/tcp.rb +176 -176
- data/lib/packetfu/protos/tcp/ecn.rb +35 -35
- data/lib/packetfu/protos/tcp/flags.rb +74 -74
- data/lib/packetfu/protos/tcp/header.rb +268 -268
- data/lib/packetfu/protos/tcp/hlen.rb +32 -32
- data/lib/packetfu/protos/tcp/mixin.rb +46 -46
- data/lib/packetfu/protos/tcp/option.rb +321 -321
- data/lib/packetfu/protos/tcp/options.rb +95 -95
- data/lib/packetfu/protos/tcp/reserved.rb +35 -35
- data/lib/packetfu/protos/udp.rb +159 -123
- data/lib/packetfu/protos/udp/header.rb +91 -91
- data/lib/packetfu/protos/udp/mixin.rb +3 -3
- data/lib/packetfu/structfu.rb +280 -280
- data/lib/packetfu/utils.rb +292 -225
- data/lib/packetfu/version.rb +41 -41
- data/packetfu.gemspec +14 -3
- data/spec/arp_spec.rb +191 -0
- data/spec/eth_spec.rb +148 -0
- data/spec/icmp_spec.rb +97 -0
- data/spec/ip_spec.rb +78 -0
- data/spec/ipv6_spec.rb +81 -0
- data/spec/packet_spec.rb +61 -59
- data/spec/packet_subclasses_spec.rb +9 -10
- data/spec/packetfu_spec.rb +55 -62
- data/spec/sample3.pcap +0 -0
- data/spec/spec_helper.rb +44 -0
- data/spec/structfu_spec.rb +270 -271
- data/spec/tcp_spec.rb +76 -77
- data/spec/udp_spec.rb +32 -0
- data/spec/utils_spec.rb +95 -0
- data/test/all_tests.rb +14 -17
- data/test/func_lldp.rb +3 -3
- data/test/ptest.rb +2 -2
- data/test/test_capture.rb +45 -45
- data/test/test_eth.rb +70 -68
- data/test/test_hsrp.rb +9 -9
- data/test/test_inject.rb +18 -18
- data/test/test_invalid.rb +16 -16
- data/test/test_octets.rb +23 -21
- data/test/test_packet.rb +156 -154
- data/test/test_pcap.rb +172 -170
- data/test/test_structfu.rb +99 -97
- data/test/test_tcp.rb +322 -320
- data/test/test_udp.rb +78 -76
- metadata +108 -44
- metadata.gz.sig +2 -0
- data/spec/ethpacket_spec.rb +0 -74
- data/test/test_arp.rb +0 -135
- data/test/test_icmp.rb +0 -62
- data/test/test_ip.rb +0 -50
- data/test/test_ip6.rb +0 -68
data/spec/sample3.pcap
ADDED
Binary file
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
|
2
|
+
$:.unshift File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib")
|
3
|
+
require 'packetfu'
|
4
|
+
|
5
|
+
puts "rspec #{RSpec::Core::Version::STRING}"
|
6
|
+
if RSpec::Core::Version::STRING[0] == '3'
|
7
|
+
require 'rspec/its'
|
8
|
+
RSpec.configure do |config|
|
9
|
+
#config.raise_errors_for_deprecations!
|
10
|
+
config.expect_with :rspec do |c|
|
11
|
+
c.syntax = [:expect, :should]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
module FakePacket
|
18
|
+
def layer
|
19
|
+
7
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class PacketFu::FooPacket < PacketFu::Packet
|
24
|
+
extend FakePacket
|
25
|
+
end
|
26
|
+
|
27
|
+
class PacketFu::BarPacket < PacketFu::Packet
|
28
|
+
extend FakePacket
|
29
|
+
end
|
30
|
+
|
31
|
+
class PacketBaz
|
32
|
+
end
|
33
|
+
|
34
|
+
def add_fake_packets
|
35
|
+
PacketFu.add_packet_class(PacketFu::FooPacket)
|
36
|
+
PacketFu.add_packet_class(PacketFu::BarPacket)
|
37
|
+
end
|
38
|
+
|
39
|
+
def remove_fake_packets
|
40
|
+
PacketFu.remove_packet_class(PacketFu::FooPacket)
|
41
|
+
PacketFu.remove_packet_class(PacketFu::BarPacket)
|
42
|
+
end
|
43
|
+
|
44
|
+
remove_fake_packets
|
data/spec/structfu_spec.rb
CHANGED
@@ -1,335 +1,334 @@
|
|
1
|
-
|
2
|
-
require 'packetfu'
|
1
|
+
require 'spec_helper'
|
3
2
|
|
4
3
|
describe StructFu, "mixin methods" do
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
5
|
+
before :each do
|
6
|
+
class StructClass
|
7
|
+
include StructFu
|
8
|
+
end
|
9
|
+
@sc = StructClass.new
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should provide the basic StructFu methods" do
|
13
|
+
@sc.respond_to?(:sz).should be true
|
14
|
+
@sc.respond_to?(:len).should be true
|
15
|
+
@sc.respond_to?(:typecast).should be true
|
16
|
+
@sc.respond_to?(:body=).should be true
|
17
|
+
end
|
18
|
+
end
|
20
19
|
|
21
20
|
describe StructFu::Int, "basic Int class" do
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
22
|
+
before :each do
|
23
|
+
@int = StructFu::Int.new(8)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should have an initial state" do
|
27
|
+
new_int = StructFu::Int.new
|
28
|
+
new_int.value.should be_nil
|
29
|
+
new_int.endian.should be_nil
|
30
|
+
new_int.width.should be_nil
|
31
|
+
new_int.default.should == 0
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should raise when to_s'ed directly" do
|
35
|
+
expect { @int.to_s}.to raise_error(StandardError, "StructFu::Int#to_s accessed, must be redefined.")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should have a value of 8" do
|
39
|
+
@int.value.should == 8
|
40
|
+
@int.to_i.should == 8
|
41
|
+
@int.to_f.to_s.should == "8.0"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should read an integer" do
|
45
|
+
@int.read(7)
|
46
|
+
@int.to_i.should == 7
|
47
|
+
end
|
49
48
|
|
50
49
|
end
|
51
50
|
|
52
51
|
describe StructFu::Int8, "one byte value" do
|
53
52
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
53
|
+
before :each do
|
54
|
+
@int = StructFu::Int8.new(11)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should have an initial state" do
|
58
|
+
new_int = StructFu::Int8.new
|
59
|
+
new_int.value.should be_nil
|
60
|
+
new_int.endian.should be_nil
|
61
|
+
new_int.width.should == 1
|
62
|
+
new_int.default.should == 0
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should print a one character packed string" do
|
66
|
+
@int.to_s.should == "\x0b"
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should have a value of 11" do
|
70
|
+
@int.value.should == 11
|
71
|
+
@int.to_i.should == 11
|
72
|
+
@int.to_f.to_s.should == "11.0"
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should reset with a new integer" do
|
76
|
+
@int.read(2)
|
77
|
+
@int.to_i.should == 2
|
78
|
+
@int.to_s.should == "\x02"
|
79
|
+
@int.read(254)
|
80
|
+
@int.to_i.should == 254
|
81
|
+
@int.to_s.should == "\xfe".force_encoding("binary")
|
82
|
+
end
|
84
83
|
|
85
84
|
end
|
86
85
|
|
87
86
|
describe StructFu::Int16, "two byte value" do
|
88
87
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
88
|
+
before :each do
|
89
|
+
@int = StructFu::Int16.new(11)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should have an initial state" do
|
93
|
+
new_int = StructFu::Int16.new
|
94
|
+
new_int.value.should be_nil
|
95
|
+
new_int.endian.should == :big
|
96
|
+
new_int.width.should == 2
|
97
|
+
new_int.default.should == 0
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should print a two character packed string" do
|
101
|
+
@int.to_s.should == "\x00\x0b".force_encoding("binary")
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should have a value of 11" do
|
105
|
+
@int.value.should == 11
|
106
|
+
@int.to_i.should == 11
|
107
|
+
@int.to_f.to_s.should == "11.0"
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should reset with a new integer" do
|
111
|
+
@int.read(2)
|
112
|
+
@int.to_i.should == 2
|
113
|
+
@int.to_s.should == "\x00\x02"
|
114
|
+
@int.read(254)
|
115
|
+
@int.to_i.should == 254
|
116
|
+
@int.to_s.should == "\x00\xfe".force_encoding("binary")
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should be able to set endianness" do
|
120
|
+
int_be = StructFu::Int16.new(11,:big)
|
121
|
+
int_be.to_s.should == "\x00\x0b"
|
122
|
+
int_le = StructFu::Int16.new(11,:little)
|
123
|
+
int_le.to_s.should == "\x0b\x00"
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should be able to switch endianness" do
|
127
|
+
@int.endian.should == :big
|
128
|
+
@int.to_s.should == "\x00\x0b"
|
129
|
+
@int.endian = :little
|
130
|
+
@int.endian.should == :little
|
131
|
+
@int.read(11)
|
132
|
+
@int.to_s.should == "\x0b\x00"
|
133
|
+
end
|
135
134
|
|
136
135
|
end
|
137
136
|
|
138
137
|
describe StructFu::Int16le, "2 byte little-endian value" do
|
139
138
|
|
140
|
-
|
141
|
-
|
142
|
-
|
139
|
+
before :each do
|
140
|
+
@int = StructFu::Int16le.new(11)
|
141
|
+
end
|
143
142
|
|
144
|
-
|
145
|
-
|
146
|
-
|
143
|
+
it "should behave pretty much like any other 16 bit int" do
|
144
|
+
@int.to_s.should == "\x0b\x00"
|
145
|
+
end
|
147
146
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
147
|
+
it "should raise when you try to change endianness" do
|
148
|
+
expect { @int.endian = :big }.to raise_error(NoMethodError, /undefined method `endian='/)
|
149
|
+
expect { @int.endian = :little }.to raise_error(NoMethodError, /undefined method `endian='/)
|
150
|
+
end
|
152
151
|
|
153
152
|
end
|
154
153
|
|
155
154
|
describe StructFu::Int16be, "2 byte big-endian value" do
|
156
155
|
|
157
|
-
|
158
|
-
|
159
|
-
|
156
|
+
before :each do
|
157
|
+
@int = StructFu::Int16be.new(11)
|
158
|
+
end
|
160
159
|
|
161
|
-
|
162
|
-
|
163
|
-
|
160
|
+
it "should behave pretty much like any other 16 bit int" do
|
161
|
+
@int.to_s.should == "\x00\x0b"
|
162
|
+
end
|
164
163
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
164
|
+
it "should raise when you try to change endianness" do
|
165
|
+
expect { @int.endian = :big }.to raise_error(NoMethodError, /undefined method `endian='/)
|
166
|
+
expect { @int.endian = :little }.to raise_error(NoMethodError, /undefined method `endian='/)
|
167
|
+
end
|
169
168
|
|
170
169
|
end
|
171
170
|
|
172
171
|
describe StructFu::Int32, "four byte value" do
|
173
172
|
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
173
|
+
before :each do
|
174
|
+
@int = StructFu::Int32.new(11)
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should have an initial state" do
|
178
|
+
new_int = StructFu::Int32.new
|
179
|
+
new_int.value.should be_nil
|
180
|
+
new_int.endian.should == :big
|
181
|
+
new_int.width.should == 4
|
182
|
+
new_int.default.should == 0
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should print a four character packed string" do
|
186
|
+
@int.to_s.should == "\x00\x00\x00\x0b"
|
187
|
+
end
|
188
|
+
|
189
|
+
it "should have a value of 11" do
|
190
|
+
@int.value.should == 11
|
191
|
+
@int.to_i.should == 11
|
192
|
+
@int.to_f.to_s.should == "11.0"
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should reset with a new integer" do
|
196
|
+
@int.read(2)
|
197
|
+
@int.to_i.should == 2
|
198
|
+
@int.to_s.should == "\x00\x00\x00\x02"
|
199
|
+
@int.read(254)
|
200
|
+
@int.to_i.should == 254
|
201
|
+
@int.to_s.should == "\x00\x00\x00\xfe".force_encoding("binary")
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should be able to set endianness" do
|
205
|
+
int_be = StructFu::Int32.new(11,:big)
|
206
|
+
int_be.to_s.should == "\x00\x00\x00\x0b"
|
207
|
+
int_le = StructFu::Int32.new(11,:little)
|
208
|
+
int_le.to_s.should == "\x0b\x00\x00\x00"
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should be able to switch endianness" do
|
212
|
+
@int.endian.should == :big
|
213
|
+
@int.to_s.should == "\x00\x00\x00\x0b"
|
214
|
+
@int.endian = :little
|
215
|
+
@int.endian.should == :little
|
216
|
+
@int.read(11)
|
217
|
+
@int.to_s.should == "\x0b\x00\x00\x00"
|
218
|
+
end
|
220
219
|
|
221
220
|
end
|
222
221
|
|
223
222
|
describe StructFu::Int32le, "4 byte little-endian value" do
|
224
223
|
|
225
|
-
|
226
|
-
|
227
|
-
|
224
|
+
before :each do
|
225
|
+
@int = StructFu::Int32le.new(11)
|
226
|
+
end
|
228
227
|
|
229
|
-
|
230
|
-
|
231
|
-
|
228
|
+
it "should behave pretty much like any other 32 bit int" do
|
229
|
+
@int.to_s.should == "\x0b\x00\x00\x00"
|
230
|
+
end
|
232
231
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
232
|
+
it "should raise when you try to change endianness" do
|
233
|
+
expect { @int.endian = :big }.to raise_error(NoMethodError, /undefined method `endian='/)
|
234
|
+
expect { @int.endian = :little }.to raise_error(NoMethodError, /undefined method `endian='/)
|
235
|
+
end
|
237
236
|
|
238
237
|
end
|
239
238
|
|
240
239
|
describe StructFu::Int32be, "4 byte big-endian value" do
|
241
240
|
|
242
|
-
|
243
|
-
|
244
|
-
|
241
|
+
before :each do
|
242
|
+
@int = StructFu::Int32be.new(11)
|
243
|
+
end
|
245
244
|
|
246
|
-
|
247
|
-
|
248
|
-
|
245
|
+
it "should behave pretty much like any other 32 bit int" do
|
246
|
+
@int.to_s.should == "\x00\x00\x00\x0b"
|
247
|
+
end
|
249
248
|
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
249
|
+
it "should raise when you try to change endianness" do
|
250
|
+
expect { @int.endian = :big }.to raise_error(NoMethodError, /undefined method `endian='/)
|
251
|
+
expect { @int.endian = :little }.to raise_error(NoMethodError, /undefined method `endian='/)
|
252
|
+
end
|
254
253
|
|
255
254
|
end
|
256
255
|
|
257
256
|
describe StructFu::String, "a sligtly more special String" do
|
258
257
|
|
259
|
-
|
260
|
-
|
261
|
-
|
258
|
+
before :each do
|
259
|
+
@str = StructFu::String.new("Oi, a string")
|
260
|
+
end
|
262
261
|
|
263
|
-
|
264
|
-
|
265
|
-
|
262
|
+
it "should behave pretty much like a string" do
|
263
|
+
@str.should be_kind_of(String)
|
264
|
+
end
|
266
265
|
|
267
|
-
|
268
|
-
|
269
|
-
|
266
|
+
it "should have a read method" do
|
267
|
+
@str.should respond_to(:read)
|
268
|
+
end
|
270
269
|
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
270
|
+
it "should read data like other StructFu things" do
|
271
|
+
@str.read("hello")
|
272
|
+
@str.should == "hello"
|
273
|
+
end
|
275
274
|
|
276
275
|
end
|
277
276
|
|
278
277
|
describe StructFu::IntString do
|
279
278
|
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
279
|
+
it "should be" do
|
280
|
+
StructFu::IntString.should be
|
281
|
+
end
|
282
|
+
|
283
|
+
it "should have a length and value" do
|
284
|
+
istr = StructFu::IntString.new("Avast!")
|
285
|
+
istr.to_s.should == "\x06Avast!"
|
286
|
+
end
|
287
|
+
|
288
|
+
it "should have a 16-bit length and a value" do
|
289
|
+
istr = StructFu::IntString.new("Avast!",StructFu::Int16)
|
290
|
+
istr.to_s.should == "\x00\x06Avast!"
|
291
|
+
end
|
292
|
+
|
293
|
+
it "should have a 32-bit length and a value" do
|
294
|
+
istr = StructFu::IntString.new("Avast!",StructFu::Int32)
|
295
|
+
istr.to_s.should == "\x00\x00\x00\x06Avast!"
|
296
|
+
end
|
297
|
+
|
298
|
+
before :each do
|
299
|
+
@istr = StructFu::IntString.new("Avast!",StructFu::Int32)
|
300
|
+
end
|
301
|
+
|
302
|
+
it "should report the correct length with a new string" do
|
303
|
+
@istr.to_s.should == "\x00\x00\x00\x06Avast!"
|
304
|
+
@istr.string = "Ahoy!"
|
305
|
+
@istr.to_s.should == "\x00\x00\x00\x05Ahoy!"
|
306
|
+
end
|
307
|
+
|
308
|
+
it "should report the correct length with a new string" do
|
309
|
+
@istr.string = "Ahoy!"
|
310
|
+
@istr.to_s.should == "\x00\x00\x00\x05Ahoy!"
|
311
|
+
end
|
312
|
+
|
313
|
+
it "should keep the old length with a new string" do
|
314
|
+
@istr[:string] = "Ahoy!"
|
315
|
+
@istr.to_s.should == "\x00\x00\x00\x06Ahoy!"
|
316
|
+
end
|
317
|
+
|
318
|
+
it "should allow for adjusting the length manually" do
|
319
|
+
@istr.len = 16
|
320
|
+
@istr.to_s.should == "\x00\x00\x00\x10Avast!"
|
321
|
+
end
|
322
|
+
|
323
|
+
it "should read in an expected string" do
|
324
|
+
data = "\x00\x00\x00\x09Yo ho ho!"
|
325
|
+
@istr.read(data)
|
326
|
+
@istr.to_s.should == data
|
327
|
+
end
|
328
|
+
|
329
|
+
it "should raise when a string is too short" do
|
330
|
+
data = "\x01A"
|
331
|
+
expect { @istr.read(data) }.to raise_error(StandardError, "String is too short for type StructFu::Int32")
|
332
|
+
end
|
334
333
|
|
335
334
|
end
|