binp 4.0.0 → 4.1.0
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 +4 -4
- data/.gitignore +0 -0
- data/.travis.yml +0 -0
- data/Gemfile +0 -0
- data/Gemfile.lock +18 -8
- data/LICENSE +0 -0
- data/README.md +8 -0
- data/Rakefile +0 -0
- data/bin/console +0 -0
- data/bin/setup +0 -0
- data/binp.gemspec +1 -0
- data/example/example.bin +0 -0
- data/example/example.yaml +0 -0
- data/example/example_01.bin +0 -0
- data/example/example_01.yaml +0 -0
- data/lib/binp/cli/main.rb +90 -26
- data/lib/binp/version.rb +1 -1
- data/lib/binp.rb +6 -5
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c53f3f9d6f7dfaf4ef40754a51b901510e27c13a28ca4bebf51138d7af7eeef
|
4
|
+
data.tar.gz: 84343e0458654820acf6f33d053506786b72c226aa1c7db2ba493b2e67b2227a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3315c9cbdb10d04fb4d47afbd13b0056054bfd43d05358dae11967062d1c9ba3c4494565546deb783deec692870bbe4a6284ed9e00ab3338abc71a3a22d2fca0
|
7
|
+
data.tar.gz: 69f95fcd377c8c153a6c583b1094f31032e347f6baa2bc15ed31938ba93ebcebfea263f5b11eb5c88a8840e6f80cd447e0d90cee70249ecdc0cdb99cd3a18b98
|
data/.gitignore
CHANGED
File without changes
|
data/.travis.yml
CHANGED
File without changes
|
data/Gemfile
CHANGED
File without changes
|
data/Gemfile.lock
CHANGED
@@ -1,21 +1,31 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
binp (4.
|
4
|
+
binp (4.1.0)
|
5
5
|
formatador
|
6
|
+
listen
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
10
|
-
docile (1.
|
11
|
-
|
12
|
-
|
11
|
+
docile (1.4.0)
|
12
|
+
ffi (1.15.5)
|
13
|
+
formatador (1.1.0)
|
14
|
+
listen (3.8.0)
|
15
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
16
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
17
|
+
power_assert (2.0.3)
|
13
18
|
rake (12.3.3)
|
14
|
-
|
19
|
+
rb-fsevent (0.11.2)
|
20
|
+
rb-inotify (0.10.1)
|
21
|
+
ffi (~> 1.0)
|
22
|
+
simplecov (0.22.0)
|
15
23
|
docile (~> 1.1)
|
16
24
|
simplecov-html (~> 0.11)
|
17
|
-
|
18
|
-
|
25
|
+
simplecov_json_formatter (~> 0.1)
|
26
|
+
simplecov-html (0.12.3)
|
27
|
+
simplecov_json_formatter (0.1.4)
|
28
|
+
test-unit (3.6.1)
|
19
29
|
power_assert
|
20
30
|
|
21
31
|
PLATFORMS
|
@@ -28,4 +38,4 @@ DEPENDENCIES
|
|
28
38
|
test-unit
|
29
39
|
|
30
40
|
BUNDLED WITH
|
31
|
-
2.
|
41
|
+
2.4.19
|
data/LICENSE
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -7,6 +7,14 @@
|
|
7
7
|
|
8
8
|
# 使い方
|
9
9
|
|
10
|
+
```sh
|
11
|
+
Usage: binp [options] FILE
|
12
|
+
-c, --config VALUE 設定ファイルパス
|
13
|
+
-a, --all name, value 以外のすべての項目(endianness, offset, size, type)を表示する
|
14
|
+
-p, --polling VALUE 指定したポーリング間隔(ミリ秒)で再表示します
|
15
|
+
-w, --watch ファイル更新時に再表示します
|
16
|
+
```
|
17
|
+
|
10
18
|
以下内容のバイナリファイルをパースする場合について説明する。
|
11
19
|
|
12
20
|
■ `example.bin`
|
data/Rakefile
CHANGED
File without changes
|
data/bin/console
CHANGED
File without changes
|
data/bin/setup
CHANGED
File without changes
|
data/binp.gemspec
CHANGED
data/example/example.bin
CHANGED
File without changes
|
data/example/example.yaml
CHANGED
File without changes
|
data/example/example_01.bin
CHANGED
File without changes
|
data/example/example_01.yaml
CHANGED
File without changes
|
data/lib/binp/cli/main.rb
CHANGED
@@ -1,51 +1,52 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
require 'formatador'
|
3
3
|
require 'json'
|
4
|
+
require 'listen'
|
4
5
|
require 'optparse'
|
6
|
+
require 'pathname'
|
5
7
|
require 'yaml'
|
6
8
|
|
7
9
|
require_relative '../../binp.rb'
|
8
10
|
|
9
11
|
class Main
|
10
12
|
def self.run(argv)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
13
|
+
begin
|
14
|
+
# 引数パース
|
15
|
+
opts, argv = parse_option(argv)
|
16
|
+
|
17
|
+
# コンフィグファイル読み込み
|
18
|
+
config = read_config_file(opts[:config])
|
19
|
+
|
20
|
+
# watch オプションを確認し、フラグがたっていれば watch モードで実行
|
21
|
+
if opts[:watch]
|
22
|
+
watch(config, opts[:all], argv[0])
|
23
|
+
elsif opts[:polling] != 0
|
24
|
+
interval = opts[:polling].to_f / 1000.0
|
25
|
+
loop do
|
26
|
+
display(config, opts[:all], argv[0], true)
|
27
|
+
sleep interval
|
28
|
+
end
|
29
|
+
else
|
30
|
+
display(config, opts[:all], argv[0], false)
|
28
31
|
end
|
29
|
-
|
30
|
-
#
|
31
|
-
e.delete('layout')
|
32
|
-
e
|
33
|
-
}
|
34
|
-
if !opts[:all]
|
35
|
-
result.map! { |e| { 'name' => e['name'], 'value' => e['value']} }
|
32
|
+
rescue Interrupt
|
33
|
+
# do nothing
|
36
34
|
end
|
37
|
-
Formatador.display_compact_table(result)
|
38
35
|
end
|
39
36
|
|
40
37
|
def self.parse_option(argv)
|
41
38
|
options = {
|
42
|
-
all: false
|
39
|
+
all: false,
|
40
|
+
polling: 0,
|
41
|
+
watch: false
|
43
42
|
}
|
44
43
|
op = OptionParser.new
|
45
44
|
op.banner = 'Usage: binp [options] FILE'
|
46
45
|
|
47
46
|
op.on('-c VALUE', '--config VALUE', '設定ファイルパス') { |v| options[:config] = v }
|
48
47
|
op.on('-a', '--all', 'name, value 以外のすべての項目(endianness, offset, size, type)を表示する') { |v| options[:all] = true }
|
48
|
+
op.on('-p VALUE', '--polling VALUE', '指定したポーリング間隔(ミリ秒)で再表示します') { |v| options[:polling] = v }
|
49
|
+
op.on('-w', '--watch', 'ファイル更新時に再表示します') { |v| options[:watch] = true }
|
49
50
|
begin
|
50
51
|
op.parse!(argv)
|
51
52
|
rescue OptionParser::InvalidOption => e
|
@@ -111,5 +112,68 @@ class Main
|
|
111
112
|
f.each_byte.to_a
|
112
113
|
}
|
113
114
|
end
|
115
|
+
|
116
|
+
# watch モード(指定されたファイルが更新されるたびに結果を出力する)
|
117
|
+
def self.watch(config, is_all, file)
|
118
|
+
# 初回の出力
|
119
|
+
display(config, is_all, file, true)
|
120
|
+
|
121
|
+
# ファイルの変更を監視し、変更があればターミナルに出力
|
122
|
+
directory = Pathname.new(file).dirname.to_s
|
123
|
+
listener = Listen.to(directory) do |modified, _added, _removed|
|
124
|
+
modified_file = Pathname.new(modified.first).expand_path
|
125
|
+
|
126
|
+
# 変更されたファイルが監視対象でなければ何もしない
|
127
|
+
next unless modified_file == Pathname.new(file).expand_path
|
128
|
+
|
129
|
+
# 出力
|
130
|
+
display(config, is_all, modified_file, true)
|
131
|
+
end
|
132
|
+
|
133
|
+
listener.start
|
134
|
+
begin
|
135
|
+
sleep
|
136
|
+
rescue Interrupt
|
137
|
+
# do nothing
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
# バイナリファイルをパースして、出力用にフォーマットする
|
142
|
+
def self.parse_and_format(config, is_all, file)
|
143
|
+
uint8_array = read_binary_file(file);
|
144
|
+
|
145
|
+
# バイナリパース
|
146
|
+
raw_result = BinParser.parse(uint8_array, config)
|
147
|
+
|
148
|
+
# パース結果を出力用に加工
|
149
|
+
result = raw_result.map { |e|
|
150
|
+
e['type'] = e['type'][:name]
|
151
|
+
|
152
|
+
# FLAGS では endianness が無い場合があるのでチェックしてから設定
|
153
|
+
if e['endianness']
|
154
|
+
e['endianness'] = e['endianness'][:name]
|
155
|
+
end
|
156
|
+
|
157
|
+
# layout は出力量が多すぎるので削除
|
158
|
+
e.delete('layout')
|
159
|
+
e
|
160
|
+
}
|
161
|
+
|
162
|
+
# all フラグが立っていない場合、 name と value のみ抽出
|
163
|
+
if !is_all
|
164
|
+
result.map! { |e| { 'name' => e['name'], 'value' => e['value']} }
|
165
|
+
end
|
166
|
+
|
167
|
+
result
|
168
|
+
end
|
169
|
+
|
170
|
+
def self.display(config, is_all, file, is_reset)
|
171
|
+
# 表示用文字列を取得
|
172
|
+
result = parse_and_format(config, is_all, file)
|
173
|
+
|
174
|
+
# 一度ターミナルをリセットして表示し直す
|
175
|
+
printf "\033c" if is_reset
|
176
|
+
Formatador.display_compact_table(result)
|
177
|
+
end
|
114
178
|
end
|
115
179
|
|
data/lib/binp/version.rb
CHANGED
data/lib/binp.rb
CHANGED
@@ -3,16 +3,17 @@ require "binp/version"
|
|
3
3
|
|
4
4
|
class BinParser
|
5
5
|
def self.parse(uint8_array, config)
|
6
|
-
config.flat_map { |e|
|
6
|
+
flatten_config = config.flat_map { |e|
|
7
|
+
new_e = e.clone
|
7
8
|
# ビットフラグかどうかを確認
|
8
9
|
if e['type'] == BinParserElement::Type::FLAGS
|
9
|
-
|
10
|
+
new_e = BinParserElement.get_flags(uint8_array, e)
|
10
11
|
else
|
11
|
-
|
12
|
+
new_e['value'] = BinParserElement.get_value(uint8_array, e['offset'], e['size'], e['type'], e['endianness'], e['value_label'])
|
12
13
|
end
|
13
|
-
|
14
|
+
new_e
|
14
15
|
}
|
15
|
-
|
16
|
+
end
|
16
17
|
end
|
17
18
|
|
18
19
|
class BinParserElement
|
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.
|
4
|
+
version: 4.1.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: 2023-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: formatador
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: listen
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: test-unit
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
114
|
- !ruby/object:Gem::Version
|
101
115
|
version: '0'
|
102
116
|
requirements: []
|
103
|
-
rubygems_version: 3.
|
117
|
+
rubygems_version: 3.4.10
|
104
118
|
signing_key:
|
105
119
|
specification_version: 4
|
106
120
|
summary: binary file parser.
|