binp 3.0.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/example/example_01.yaml +2 -0
- data/lib/binp.rb +7 -3
- data/lib/binp/cli/main.rb +22 -1
- data/lib/binp/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 737c05ad3f05c0d57238526b2456d36e3a0fb1de14909d64fffa15942bfc76eb
|
4
|
+
data.tar.gz: 30c2ad4ec1b7a6cf12b772a85a4a811a5c22da0db93544346761584028fd3ff8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19085d777a54bd338c9e12868ad3041a57540e568ba7cd36c9c1dae393235187fa5f9240708f5a517ff42e4f9a063ba5121d8a0dd49af4c56404dd6cd4b7a6ce
|
7
|
+
data.tar.gz: 6967cd575f2897023570563fc6985981b02b75dc7c62da6b807bafad938166875891f6f333c8270263273ba0a35681887a204b390b6f0c96bfe782dba5631564
|
data/Gemfile.lock
CHANGED
data/example/example_01.yaml
CHANGED
data/lib/binp.rb
CHANGED
@@ -8,7 +8,7 @@ class BinParser
|
|
8
8
|
if e['type'] == BinParserElement::Type::FLAGS
|
9
9
|
e = BinParserElement.get_flags(uint8_array, e)
|
10
10
|
else
|
11
|
-
e['value'] = BinParserElement.get_value(uint8_array, e['offset'], e['size'], e['type'], e['endianness'])
|
11
|
+
e['value'] = BinParserElement.get_value(uint8_array, e['offset'], e['size'], e['type'], e['endianness'], e['value_label'])
|
12
12
|
end
|
13
13
|
e
|
14
14
|
}
|
@@ -79,11 +79,15 @@ class BinParserElement
|
|
79
79
|
'C' * size
|
80
80
|
end
|
81
81
|
|
82
|
-
def self.get_value(uint8_array, offset, size, type, endianness)
|
82
|
+
def self.get_value(uint8_array, offset, size, type, endianness, value_labels={})
|
83
83
|
target = uint8_array.slice(offset, size)
|
84
84
|
pack_template_string = calculate_pack_template_string(size)
|
85
85
|
unpack_template_string = calculate_unpack_template_string(type, endianness)
|
86
|
-
target.pack(pack_template_string).unpack(unpack_template_string)[0]
|
86
|
+
value = target.pack(pack_template_string).unpack(unpack_template_string)[0]
|
87
|
+
|
88
|
+
# value_label が設定されている数値であれば、それに置き換える
|
89
|
+
value_labels ||= {}
|
90
|
+
value_labels.fetch(value, value)
|
87
91
|
end
|
88
92
|
|
89
93
|
def self.get_flags(uint8_array, config)
|
data/lib/binp/cli/main.rb
CHANGED
@@ -42,10 +42,31 @@ class Main
|
|
42
42
|
all: false
|
43
43
|
}
|
44
44
|
op = OptionParser.new
|
45
|
+
op.banner = 'Usage: binp [options] FILE'
|
45
46
|
|
46
47
|
op.on('-c VALUE', '--config VALUE', '設定ファイルパス') { |v| options[:config] = v }
|
47
48
|
op.on('-a', '--all', 'name, value 以外のすべての項目(endianness, offset, size, type)を表示する') { |v| options[:all] = true }
|
48
|
-
|
49
|
+
begin
|
50
|
+
op.parse!(argv)
|
51
|
+
rescue OptionParser::InvalidOption => e
|
52
|
+
STDERR.puts 'ERROR: オプションのパースに失敗しました。'
|
53
|
+
STDERR.puts op.to_s
|
54
|
+
exit(1);
|
55
|
+
end
|
56
|
+
|
57
|
+
# 必須オプション `-c` のチェック
|
58
|
+
unless options[:config]
|
59
|
+
STDERR.puts 'ERROR: 必須オプション `-c, --config` が指定されていません。'
|
60
|
+
STDERR.puts op.to_s
|
61
|
+
exit(1);
|
62
|
+
end
|
63
|
+
|
64
|
+
# ファイル指定があるかのチェック
|
65
|
+
if argv.size == 0
|
66
|
+
STDERR.puts 'ERROR: FILE が指定されていません。'
|
67
|
+
STDERR.puts op.to_s
|
68
|
+
exit(1);
|
69
|
+
end
|
49
70
|
|
50
71
|
[options, argv]
|
51
72
|
end
|
data/lib/binp/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: binp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mikoto2000
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: formatador
|
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
100
|
- !ruby/object:Gem::Version
|
101
101
|
version: '0'
|
102
102
|
requirements: []
|
103
|
-
rubygems_version: 3.1.
|
103
|
+
rubygems_version: 3.1.4
|
104
104
|
signing_key:
|
105
105
|
specification_version: 4
|
106
106
|
summary: binary file parser.
|