bindata 2.4.3 → 2.4.8
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of bindata might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +4 -2
- data/ChangeLog.rdoc +25 -0
- data/README.md +0 -1
- data/bindata.gemspec +1 -3
- data/examples/tcp_ip.rb +2 -2
- data/lib/bindata.rb +3 -11
- data/lib/bindata/array.rb +16 -8
- data/lib/bindata/base.rb +1 -2
- data/lib/bindata/bits.rb +11 -7
- data/lib/bindata/int.rb +11 -6
- data/lib/bindata/io.rb +4 -2
- data/lib/bindata/registry.rb +9 -3
- data/lib/bindata/stringz.rb +1 -1
- data/lib/bindata/version.rb +1 -1
- data/test/array_test.rb +5 -0
- data/test/buffer_test.rb +0 -1
- data/test/offset_test.rb +9 -3
- data/test/registry_test.rb +17 -3
- data/test/stringz_test.rb +2 -2
- data/test/system_test.rb +34 -0
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 930073ad9a50e67aa2d584a17c0138f3cb4008e4bd96851ceef305e16c7cadd2
|
4
|
+
data.tar.gz: ec59bb6fcff33192da1ee33952c69e1069c214c0f41f9b21786694ed7fa4c87c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2ebc4a2e56294d7b503d73cfee08fa165c37b96a4216e6ac17206b2566d3b5ea77adb188b819a8e63bf1a059ab79d068d1def5059d7b2b6811609f099a3656f
|
7
|
+
data.tar.gz: 96c38802d6197001dfbfb76a4a338bcc7dbf2e8f7ec685b5007cdc6a8917b502ad8bc1ca106323a52f3555cada27f1b90ba204a5c72253447983026af020c27f
|
data/.travis.yml
CHANGED
data/ChangeLog.rdoc
CHANGED
@@ -1,5 +1,30 @@
|
|
1
1
|
= BinData Changelog
|
2
2
|
|
3
|
+
== Version 2.4.8 (2020-07-21)
|
4
|
+
|
5
|
+
* Bug fix array self assignment. Thanks to Spencer McIntyre.
|
6
|
+
* Bug fix Stringz max_length. Thanks to cdelafuente-r7.
|
7
|
+
|
8
|
+
== Version 2.4.7 (2020-03-31)
|
9
|
+
|
10
|
+
* Fix choice assignment inside arrays. Reported by Spencer McIntyre.
|
11
|
+
|
12
|
+
== Version 2.4.6 (2020-02-27)
|
13
|
+
|
14
|
+
* More encoding fixes. Thanks to Aaron Patterson.
|
15
|
+
|
16
|
+
== Version 2.4.5 (2020-02-21)
|
17
|
+
|
18
|
+
* Small typo fixes to examples.
|
19
|
+
* Fix encoding issue for ruby 2.7. Thanks to Aaron Patterson.
|
20
|
+
* Quieter test output.
|
21
|
+
|
22
|
+
== Version 2.4.4 (2018-10-03)
|
23
|
+
|
24
|
+
* Display a hint when endian is omitted. Requested by Tails.
|
25
|
+
* Add thread safety to Integer/BitField creation. Requested by jbpeirce.
|
26
|
+
* Ensure windows sockets are unseekable. Thanks to Brent Cook.
|
27
|
+
|
3
28
|
== Version 2.4.3 (2018-03-10)
|
4
29
|
|
5
30
|
* Add Uint8Arrays. Requested by masarakki.
|
data/README.md
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
[![Version ](http://img.shields.io/gem/v/bindata.svg) ](https://rubygems.org/gems/bindata)
|
4
4
|
[![Travis CI ](http://img.shields.io/travis/dmendel/bindata/master.svg) ](https://travis-ci.org/dmendel/bindata)
|
5
|
-
[![Quality ](http://img.shields.io/codeclimate/github/dmendel/bindata.svg)](https://codeclimate.com/github/dmendel/bindata)
|
6
5
|
[![Coverage ](http://img.shields.io/coveralls/dmendel/bindata.svg) ](https://coveralls.io/r/dmendel/bindata)
|
7
6
|
|
8
7
|
Do you ever find yourself writing code like this?
|
data/bindata.gemspec
CHANGED
@@ -9,16 +9,14 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.author = 'Dion Mendel'
|
10
10
|
s.email = 'bindata@dm9.info'
|
11
11
|
s.homepage = 'http://github.com/dmendel/bindata'
|
12
|
-
s.rubyforge_project = 'bindata'
|
13
12
|
s.require_path = 'lib'
|
14
|
-
s.has_rdoc = true
|
15
13
|
s.extra_rdoc_files = ['NEWS.rdoc']
|
16
14
|
s.rdoc_options << '--main' << 'NEWS.rdoc'
|
17
15
|
s.files = `git ls-files`.split("\n")
|
18
16
|
s.license = 'Ruby'
|
19
17
|
|
20
18
|
s.add_development_dependency('rake')
|
21
|
-
s.add_development_dependency('minitest', "> 5.0.0")
|
19
|
+
s.add_development_dependency('minitest', "> 5.0.0", "< 5.12.0")
|
22
20
|
s.add_development_dependency('coveralls')
|
23
21
|
s.description = <<-END.gsub(/^ +/, "")
|
24
22
|
BinData is a declarative way to read and write binary file formats.
|
data/examples/tcp_ip.rb
CHANGED
@@ -14,7 +14,7 @@ class MacAddr < BinData::Primitive
|
|
14
14
|
array :octets, type: :uint8, initial_length: 6
|
15
15
|
|
16
16
|
def set(val)
|
17
|
-
self.octets = val.split(
|
17
|
+
self.octets = val.split(/:/).collect(&:to_i)
|
18
18
|
end
|
19
19
|
|
20
20
|
def get
|
@@ -23,7 +23,7 @@ class MacAddr < BinData::Primitive
|
|
23
23
|
end
|
24
24
|
|
25
25
|
# Present IP addresses in a human readable way
|
26
|
-
class
|
26
|
+
class IP_Addr < BinData::Primitive
|
27
27
|
array :octets, type: :uint8, initial_length: 4
|
28
28
|
|
29
29
|
def set(val)
|
data/lib/bindata.rb
CHANGED
@@ -1,13 +1,5 @@
|
|
1
1
|
# BinData -- Binary data manipulator.
|
2
|
-
# Copyright (c) 2007 -
|
3
|
-
|
4
|
-
if RUBY_VERSION <= "1.9"
|
5
|
-
fail "BinData requires ruby >= 1.9.3. Use BinData version 1.8.x instead"
|
6
|
-
end
|
7
|
-
|
8
|
-
if RUBY_VERSION == "2.1.0" and RUBY_PATCHLEVEL == "0"
|
9
|
-
fail "Ruby 2.1.0p0 has a bug that causes BinData to fail. Upgrade your ruby version"
|
10
|
-
end
|
2
|
+
# Copyright (c) 2007 - 2018 Dion Mendel.
|
11
3
|
|
12
4
|
require 'bindata/version'
|
13
5
|
require 'bindata/array'
|
@@ -36,10 +28,10 @@ require 'bindata/warnings'
|
|
36
28
|
# A declarative way to read and write structured binary data.
|
37
29
|
#
|
38
30
|
# A full reference manual is available online at
|
39
|
-
#
|
31
|
+
# https://github.com/dmendel/bindata/wiki
|
40
32
|
#
|
41
33
|
# == License
|
42
34
|
#
|
43
35
|
# BinData is released under the same license as Ruby.
|
44
36
|
#
|
45
|
-
# Copyright (c) 2007 -
|
37
|
+
# Copyright (c) 2007 - 2018 Dion Mendel.
|
data/lib/bindata/array.rb
CHANGED
@@ -80,9 +80,11 @@ module BinData
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def assign(array)
|
83
|
+
return if self.equal?(array) # prevent self assignment
|
83
84
|
raise ArgumentError, "can't set a nil value for #{debug_name}" if array.nil?
|
84
85
|
|
85
|
-
@element_list =
|
86
|
+
@element_list = []
|
87
|
+
concat(array)
|
86
88
|
end
|
87
89
|
|
88
90
|
def snapshot
|
@@ -119,7 +121,17 @@ module BinData
|
|
119
121
|
|
120
122
|
def insert(index, *objs)
|
121
123
|
extend_array(index - 1)
|
122
|
-
|
124
|
+
abs_index = (index >= 0) ? index : index + 1 + length
|
125
|
+
|
126
|
+
# insert elements before...
|
127
|
+
new_elements = objs.map { new_element }
|
128
|
+
elements.insert(index, *new_elements)
|
129
|
+
|
130
|
+
# ...assigning values
|
131
|
+
objs.each_with_index do |obj, i|
|
132
|
+
self[abs_index + i] = obj
|
133
|
+
end
|
134
|
+
|
123
135
|
self
|
124
136
|
end
|
125
137
|
|
@@ -238,10 +250,6 @@ module BinData
|
|
238
250
|
end
|
239
251
|
end
|
240
252
|
|
241
|
-
def to_storage_formats(els)
|
242
|
-
els.collect { |el| new_element(el) }
|
243
|
-
end
|
244
|
-
|
245
253
|
def elements
|
246
254
|
@element_list ||= []
|
247
255
|
end
|
@@ -252,8 +260,8 @@ module BinData
|
|
252
260
|
element
|
253
261
|
end
|
254
262
|
|
255
|
-
def new_element
|
256
|
-
@element_prototype.instantiate(
|
263
|
+
def new_element
|
264
|
+
@element_prototype.instantiate(nil, self)
|
257
265
|
end
|
258
266
|
|
259
267
|
def sum_num_bytes_for_all_elements
|
data/lib/bindata/base.rb
CHANGED
data/lib/bindata/bits.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'thread'
|
1
2
|
require 'bindata/base_primitive'
|
2
3
|
|
3
4
|
module BinData
|
@@ -5,15 +6,18 @@ module BinData
|
|
5
6
|
# The integer is defined by endian and number of bits.
|
6
7
|
|
7
8
|
module BitField #:nodoc: all
|
9
|
+
@@mutex = Mutex.new
|
10
|
+
|
8
11
|
class << self
|
9
12
|
def define_class(name, nbits, endian, signed = :unsigned)
|
10
|
-
|
11
|
-
BinData.
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
@@mutex.synchronize do
|
14
|
+
unless BinData.const_defined?(name)
|
15
|
+
new_class = Class.new(BinData::BasePrimitive)
|
16
|
+
BitField.define_methods(new_class, nbits, endian.to_sym, signed.to_sym)
|
17
|
+
RegisteredClasses.register(name, new_class)
|
18
|
+
|
19
|
+
BinData.const_set(name, new_class)
|
20
|
+
end
|
17
21
|
end
|
18
22
|
|
19
23
|
BinData.const_get(name)
|
data/lib/bindata/int.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'thread'
|
1
2
|
require 'bindata/base_primitive'
|
2
3
|
|
3
4
|
module BinData
|
@@ -5,14 +6,18 @@ module BinData
|
|
5
6
|
# is defined by endian, signedness and number of bytes.
|
6
7
|
|
7
8
|
module Int #:nodoc: all
|
9
|
+
@@mutex = Mutex.new
|
10
|
+
|
8
11
|
class << self
|
9
12
|
def define_class(name, nbits, endian, signed)
|
10
|
-
|
11
|
-
BinData.
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
@@mutex.synchronize do
|
14
|
+
unless BinData.const_defined?(name)
|
15
|
+
new_class = Class.new(BinData::BasePrimitive)
|
16
|
+
Int.define_methods(new_class, nbits, endian.to_sym, signed.to_sym)
|
17
|
+
RegisteredClasses.register(name, new_class)
|
18
|
+
|
19
|
+
BinData.const_set(name, new_class)
|
20
|
+
end
|
16
21
|
end
|
17
22
|
|
18
23
|
BinData.const_get(name)
|
data/lib/bindata/io.rb
CHANGED
@@ -29,7 +29,7 @@ module BinData
|
|
29
29
|
|
30
30
|
def seekable?
|
31
31
|
@raw_io.pos
|
32
|
-
rescue NoMethodError, Errno::ESPIPE, Errno::EPIPE
|
32
|
+
rescue NoMethodError, Errno::ESPIPE, Errno::EPIPE, Errno::EINVAL
|
33
33
|
nil
|
34
34
|
end
|
35
35
|
|
@@ -213,7 +213,9 @@ module BinData
|
|
213
213
|
|
214
214
|
# Creates a StringIO around +str+.
|
215
215
|
def self.create_string_io(str = "")
|
216
|
-
StringIO.new(str.dup.force_encoding(Encoding::BINARY))
|
216
|
+
s = StringIO.new(str.dup.force_encoding(Encoding::BINARY))
|
217
|
+
s.binmode
|
218
|
+
s
|
217
219
|
end
|
218
220
|
|
219
221
|
# Create a new IO Read wrapper around +io+. +io+ must provide #read,
|
data/lib/bindata/registry.rb
CHANGED
@@ -24,7 +24,7 @@ module BinData
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def register(name, class_to_register)
|
27
|
-
return if class_to_register.nil?
|
27
|
+
return if name.nil? || class_to_register.nil?
|
28
28
|
|
29
29
|
formatted_name = underscore_name(name)
|
30
30
|
warn_if_name_is_already_registered(formatted_name, class_to_register)
|
@@ -37,8 +37,14 @@ module BinData
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def lookup(name, hints = {})
|
40
|
-
|
41
|
-
|
40
|
+
the_class = @registry[normalize_name(name, hints)]
|
41
|
+
if the_class
|
42
|
+
the_class
|
43
|
+
elsif @registry[normalize_name(name, hints.merge(endian: :big))]
|
44
|
+
raise(UnRegisteredTypeError, "#{name}, do you need to specify endian?")
|
45
|
+
else
|
46
|
+
raise(UnRegisteredTypeError, name)
|
47
|
+
end
|
42
48
|
end
|
43
49
|
|
44
50
|
# Convert CamelCase +name+ to underscore style.
|
data/lib/bindata/stringz.rb
CHANGED
data/lib/bindata/version.rb
CHANGED
data/test/array_test.rb
CHANGED
@@ -266,6 +266,11 @@ describe BinData::Array, "when accessing elements" do
|
|
266
266
|
lambda { obj["a"] }.must_raise TypeError
|
267
267
|
lambda { obj[1, "a"] }.must_raise TypeError
|
268
268
|
end
|
269
|
+
|
270
|
+
it "is unaffected by self assignment" do
|
271
|
+
obj.assign(obj)
|
272
|
+
obj.snapshot.must_equal [1, 2, 3, 4, 5]
|
273
|
+
end
|
269
274
|
end
|
270
275
|
|
271
276
|
describe BinData::Array, "with :read_until" do
|
data/test/buffer_test.rb
CHANGED
data/test/offset_test.rb
CHANGED
@@ -74,9 +74,15 @@ describe BinData::Base, "offsets" do
|
|
74
74
|
end
|
75
75
|
|
76
76
|
it "adjust offset when incorrect" do
|
77
|
-
|
78
|
-
|
79
|
-
|
77
|
+
w, $-w = $-w, false
|
78
|
+
|
79
|
+
begin
|
80
|
+
io.seek(2)
|
81
|
+
obj = TenByteOffsetBase.create(adjust_offset: 13)
|
82
|
+
obj.read(io).snapshot.must_equal data[2 + 13, 3]
|
83
|
+
ensure
|
84
|
+
$-w = w
|
85
|
+
end
|
80
86
|
end
|
81
87
|
|
82
88
|
it "succeeds when offset is correct" do
|
data/test/registry_test.rb
CHANGED
@@ -36,10 +36,16 @@ describe BinData::Registry do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it "allows overriding of registered classes" do
|
39
|
-
|
40
|
-
r.register('A', B)
|
39
|
+
w, $-w = $-w, false
|
41
40
|
|
42
|
-
|
41
|
+
begin
|
42
|
+
r.register('A', A)
|
43
|
+
r.register('A', B)
|
44
|
+
|
45
|
+
r.lookup('a').must_equal B
|
46
|
+
ensure
|
47
|
+
$-w = w
|
48
|
+
end
|
43
49
|
end
|
44
50
|
|
45
51
|
it "converts CamelCase to underscores" do
|
@@ -71,6 +77,14 @@ describe BinData::Registry, "with numerics" do
|
|
71
77
|
}.must_raise BinData::UnRegisteredTypeError
|
72
78
|
end
|
73
79
|
|
80
|
+
it "provides a nice error message when endian is omitted" do
|
81
|
+
begin
|
82
|
+
r.lookup("int24")
|
83
|
+
rescue BinData::UnRegisteredTypeError => e
|
84
|
+
e.message.must_equal "int24, do you need to specify endian?"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
74
88
|
it "does not lookup non byte based integers" do
|
75
89
|
lambda {
|
76
90
|
r.lookup("int3")
|
data/test/stringz_test.rb
CHANGED
@@ -106,12 +106,12 @@ describe BinData::Stringz, "with max_length" do
|
|
106
106
|
end
|
107
107
|
|
108
108
|
it "trims values greater than max_length" do
|
109
|
-
obj.assign("
|
109
|
+
obj.assign("abcdefg")
|
110
110
|
obj.must_equal "abcd"
|
111
111
|
end
|
112
112
|
|
113
113
|
it "writes values greater than max_length" do
|
114
|
-
obj.assign("
|
114
|
+
obj.assign("abcdefg")
|
115
115
|
obj.to_binary_s.must_equal_binary "abcd\0"
|
116
116
|
end
|
117
117
|
|
data/test/system_test.rb
CHANGED
@@ -360,3 +360,37 @@ describe BinData::Record, "with boolean parameters" do
|
|
360
360
|
obj.a.must_equal 2
|
361
361
|
end
|
362
362
|
end
|
363
|
+
|
364
|
+
describe BinData::Record, "encoding" do
|
365
|
+
class EncodingTestBufferRecord < BinData::Record
|
366
|
+
endian :big
|
367
|
+
default_parameter length: 5
|
368
|
+
|
369
|
+
uint16 :num
|
370
|
+
string :str, length: 10
|
371
|
+
end
|
372
|
+
|
373
|
+
it "returns binary encoded data" do
|
374
|
+
obj = EncodingTestBufferRecord.new(num: 3)
|
375
|
+
obj.to_binary_s.encoding.must_equal Encoding::ASCII_8BIT
|
376
|
+
end
|
377
|
+
|
378
|
+
it "returns binary encoded data with utf-8 string" do
|
379
|
+
obj = EncodingTestBufferRecord.new(num: 3, str: "日本語")
|
380
|
+
obj.to_binary_s.encoding.must_equal Encoding::ASCII_8BIT
|
381
|
+
end
|
382
|
+
|
383
|
+
it "returns binary encoded data despite Encoding.default_internal" do
|
384
|
+
w, $-w = $-w, false
|
385
|
+
before_enc = Encoding.default_internal
|
386
|
+
|
387
|
+
begin
|
388
|
+
Encoding.default_internal = Encoding::UTF_8
|
389
|
+
obj = EncodingTestBufferRecord.new(num: 3, str: "日本語")
|
390
|
+
obj.to_binary_s.encoding.must_equal Encoding::ASCII_8BIT
|
391
|
+
ensure
|
392
|
+
Encoding.default_internal = before_enc
|
393
|
+
$-w = w
|
394
|
+
end
|
395
|
+
end
|
396
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bindata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dion Mendel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -31,6 +31,9 @@ dependencies:
|
|
31
31
|
- - ">"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 5.0.0
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 5.12.0
|
34
37
|
type: :development
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -38,6 +41,9 @@ dependencies:
|
|
38
41
|
- - ">"
|
39
42
|
- !ruby/object:Gem::Version
|
40
43
|
version: 5.0.0
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 5.12.0
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: coveralls
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,8 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
170
|
- !ruby/object:Gem::Version
|
165
171
|
version: '0'
|
166
172
|
requirements: []
|
167
|
-
|
168
|
-
rubygems_version: 2.6.14
|
173
|
+
rubygems_version: 3.1.2
|
169
174
|
signing_key:
|
170
175
|
specification_version: 4
|
171
176
|
summary: A declarative way to read and write binary file formats
|