kaitai-struct-visualizer 0.5 → 0.11

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.
data/lib/kaitai/tui.rb CHANGED
@@ -1,109 +1,100 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'forwardable'
3
4
 
4
5
  module Kaitai
6
+ class TUI
7
+ extend Forwardable
8
+ def_delegators :@console, :rows, :cols, :goto, :clear, :fg_color=, :bg_color=, :reset_colors, :read_char_mapped
9
+
10
+ attr_reader :highlight_colors
11
+
12
+ def initialize
13
+ if TUI.windows?
14
+ require 'kaitai/console_windows'
15
+ @console = ConsoleWindows.new
16
+ @highlight_colors = %i[bright_white bright_cyan cyan gray]
17
+ else
18
+ require 'kaitai/console_ansi'
19
+ @console = ConsoleANSI.new
20
+ @highlight_colors = %i[bright_white bright_cyan cyan gray]
21
+ end
22
+ end
5
23
 
6
- class TUI
7
- extend Forwardable
8
- def_delegators :@console, :rows, :cols, :goto, :clear, :fg_color=, :bg_color=, :reset_colors, :read_char_mapped
9
-
10
- attr_reader :highlight_colors
11
-
12
- def initialize
13
- if TUI::is_windows?
14
- require 'kaitai/console_windows'
15
- @console = ConsoleWindows.new
16
- @highlight_colors = [
17
- :white,
18
- :aqua,
19
- :blue,
20
- :green,
21
- :white,
22
- ]
23
- else
24
- require 'kaitai/console_ansi'
25
- @console = ConsoleANSI.new
26
- @highlight_colors = [
27
- :gray14,
28
- :gray11,
29
- :gray8,
30
- :gray5,
31
- :gray2,
32
- ]
24
+ def on_resize=(handler)
25
+ @console.on_resize = handler
33
26
  end
34
- end
35
27
 
36
- def message_box_exception(e)
37
- message_box("Error while parsing", e.message)
38
- end
28
+ def message_box_exception(e)
29
+ message_box('Error while parsing', e.message)
30
+ end
39
31
 
40
- SINGLE_CHARSET = '┌┐└┘─│'
41
- HEAVY_CHARSET = '┏┓┗┛━┃'
42
- DOUBLE_CHARSET = '╔╗╚╝═║'
43
-
44
- CHAR_TL = 0
45
- CHAR_TR = 1
46
- CHAR_BL = 2
47
- CHAR_BR = 3
48
- CHAR_H = 4
49
- CHAR_V = 5
50
-
51
- def message_box(header, msg)
52
- top_y = @console.rows / 2 - 5
53
- draw_rectangle(10, top_y, @console.cols - 20, 10)
54
- @console.goto(@console.cols / 2 - (header.length / 2) - 1, top_y)
55
- print ' ', header, ' '
56
- @console.goto(11, top_y + 1)
57
- puts msg
58
- draw_button(@console.cols / 2 - 10, top_y + 8, 10, 'OK')
59
- loop {
60
- c = @console.read_char_mapped
61
- return if c == :enter
62
- }
63
- end
32
+ SINGLE_CHARSET = '┌┐└┘─│'
33
+ HEAVY_CHARSET = '┏┓┗┛━┃'
34
+ DOUBLE_CHARSET = '╔╗╚╝═║'
35
+
36
+ CHAR_TL = 0
37
+ CHAR_TR = 1
38
+ CHAR_BL = 2
39
+ CHAR_BR = 3
40
+ CHAR_H = 4
41
+ CHAR_V = 5
42
+
43
+ def message_box(header, msg)
44
+ top_y = @console.rows / 2 - 5
45
+ draw_rectangle(10, top_y, @console.cols - 20, 10)
46
+ @console.goto(@console.cols / 2 - (header.length / 2) - 1, top_y)
47
+ print ' ', header, ' '
48
+ @console.goto(11, top_y + 1)
49
+ puts msg
50
+ draw_button(@console.cols / 2 - 10, top_y + 8, 10, 'OK')
51
+ loop do
52
+ c = @console.read_char_mapped
53
+ return if c == :enter
54
+ end
55
+ end
64
56
 
65
- def input_str(header, msg)
66
- top_y = @console.rows / 2 - 5
67
- draw_rectangle(10, top_y, @console.cols - 20, 10)
68
- goto(@console.cols / 2 - (header.length / 2) - 1, top_y)
69
- print ' ', header, ' '
57
+ def input_str(header, _msg)
58
+ top_y = @console.rows / 2 - 5
59
+ draw_rectangle(10, top_y, @console.cols - 20, 10)
60
+ goto(@console.cols / 2 - (header.length / 2) - 1, top_y)
61
+ print ' ', header, ' '
70
62
 
71
- goto(11, top_y + 1)
72
- Readline.readline('', false)
73
- end
63
+ goto(11, top_y + 1)
64
+ Readline.readline('', false)
65
+ end
74
66
 
75
- def draw_rectangle(x, y, w, h, charset = DOUBLE_CHARSET)
76
- goto(x, y)
77
- print charset[CHAR_TL]
78
- print charset[CHAR_H] * (w - 2)
79
- print charset[CHAR_TR]
80
-
81
- ((y + 1)..(y + h - 1)).each { |i|
82
- goto(x, i)
83
- print charset[CHAR_V]
84
- print ' ' * (w - 2)
85
- print charset[CHAR_V]
86
- }
87
-
88
- goto(x, y + h)
89
- print charset[CHAR_BL]
90
- print charset[CHAR_H] * (w - 2)
91
- print charset[CHAR_BR]
92
- end
67
+ def draw_rectangle(x, y, w, h, charset = DOUBLE_CHARSET)
68
+ goto(x, y)
69
+ print charset[CHAR_TL]
70
+ print charset[CHAR_H] * (w - 2)
71
+ print charset[CHAR_TR]
72
+
73
+ ((y + 1)..(y + h - 1)).each do |i|
74
+ goto(x, i)
75
+ print charset[CHAR_V]
76
+ print ' ' * (w - 2)
77
+ print charset[CHAR_V]
78
+ end
79
+
80
+ goto(x, y + h)
81
+ print charset[CHAR_BL]
82
+ print charset[CHAR_H] * (w - 2)
83
+ print charset[CHAR_BR]
84
+ end
93
85
 
94
- def draw_button(x, y, w, caption)
95
- goto(x, y)
96
- puts "[ #{caption} ]"
97
- end
86
+ def draw_button(x, y, _w, caption)
87
+ goto(x, y)
88
+ puts "[ #{caption} ]"
89
+ end
98
90
 
99
- # Regexp borrowed from
100
- # http://stackoverflow.com/questions/170956/how-can-i-find-which-operating-system-my-ruby-program-is-running-on
101
- @@is_windows = (RUBY_PLATFORM =~ /cygwin|mswin|mingw|bccwin|wince|emx/) ? true : false
91
+ # Regexp borrowed from
92
+ # http://stackoverflow.com/questions/170956/how-can-i-find-which-operating-system-my-ruby-program-is-running-on
93
+ @@is_windows = (RUBY_PLATFORM =~ /cygwin|mswin|mingw|bccwin|wince|emx/) ? true : false
102
94
 
103
- # Detects if current platform is Windows-based.
104
- def self.is_windows?
105
- @@is_windows
95
+ # Detects whether the current platform is Windows-based.
96
+ def self.windows?
97
+ @@is_windows
98
+ end
106
99
  end
107
100
  end
108
-
109
- end
metadata CHANGED
@@ -1,57 +1,82 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kaitai-struct-visualizer
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.5'
4
+ version: '0.11'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikhail Yakshin
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2016-11-15 00:00:00.000000000 Z
10
+ date: 2025-09-19 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
- name: bundler
13
+ name: activesupport
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - "~>"
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: 5.0.0
19
+ - - "<"
18
20
  - !ruby/object:Gem::Version
19
- version: '1.3'
20
- type: :development
21
+ version: 9.0.0
22
+ type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
23
25
  requirements:
24
- - - "~>"
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: 5.0.0
29
+ - - "<"
25
30
  - !ruby/object:Gem::Version
26
- version: '1.3'
31
+ version: 9.0.0
27
32
  - !ruby/object:Gem::Dependency
28
- name: rake
33
+ name: builder
29
34
  requirement: !ruby/object:Gem::Requirement
30
35
  requirements:
31
36
  - - "~>"
32
37
  - !ruby/object:Gem::Version
33
- version: '10'
34
- type: :development
38
+ version: '3.3'
39
+ type: :runtime
35
40
  prerelease: false
36
41
  version_requirements: !ruby/object:Gem::Requirement
37
42
  requirements:
38
43
  - - "~>"
39
44
  - !ruby/object:Gem::Version
40
- version: '10'
45
+ version: '3.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: benchmark
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 0.1.0
53
+ - - "<"
54
+ - !ruby/object:Gem::Version
55
+ version: 0.5.0
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 0.1.0
63
+ - - "<"
64
+ - !ruby/object:Gem::Version
65
+ version: 0.5.0
41
66
  - !ruby/object:Gem::Dependency
42
67
  name: kaitai-struct
43
68
  requirement: !ruby/object:Gem::Requirement
44
69
  requirements:
45
70
  - - "~>"
46
71
  - !ruby/object:Gem::Version
47
- version: '0.4'
72
+ version: '0.7'
48
73
  type: :runtime
49
74
  prerelease: false
50
75
  version_requirements: !ruby/object:Gem::Requirement
51
76
  requirements:
52
77
  - - "~>"
53
78
  - !ruby/object:Gem::Version
54
- version: '0.4'
79
+ version: '0.7'
55
80
  description: |
56
81
  Kaitai Struct is a declarative language used for describe various binary data structures, laid out in files or in memory: i.e. binary file formats, network stream packet formats, etc.
57
82
 
@@ -60,30 +85,36 @@ description: |
60
85
  This package is a visualizer tool for .ksy files. Given a particular binary file and .ksy file(s) that describe its format, it can visualize internal data structures in a tree form and a multi-level highlight hex viewer.
61
86
  email: greycat@kaitai.io
62
87
  executables:
88
+ - ksdump
63
89
  - ksv
64
90
  extensions: []
65
91
  extra_rdoc_files: []
66
92
  files:
67
93
  - LICENSE
68
94
  - README.md
95
+ - bin/ksdump
69
96
  - bin/ksv
70
- - kaitai-struct-visualizer.gemspec
71
97
  - lib/kaitai/console_ansi.rb
72
98
  - lib/kaitai/console_windows.rb
73
99
  - lib/kaitai/struct/visualizer.rb
74
100
  - lib/kaitai/struct/visualizer/hex_viewer.rb
101
+ - lib/kaitai/struct/visualizer/ks_error_matcher.rb
102
+ - lib/kaitai/struct/visualizer/ksy_compiler.rb
75
103
  - lib/kaitai/struct/visualizer/node.rb
104
+ - lib/kaitai/struct/visualizer/obj_to_h.rb
105
+ - lib/kaitai/struct/visualizer/parser.rb
76
106
  - lib/kaitai/struct/visualizer/tree.rb
77
107
  - lib/kaitai/struct/visualizer/version.rb
78
108
  - lib/kaitai/struct/visualizer/visualizer.rb
79
- - lib/kaitai/struct/visualizer/visualizer_main.rb
80
- - lib/kaitai/struct/visualizer/visualizer_ruby.rb
81
109
  - lib/kaitai/tui.rb
82
- homepage: http://kaitai.io
110
+ homepage: https://kaitai.io/
83
111
  licenses:
84
- - GPL-3.0+
85
- metadata: {}
86
- post_install_message:
112
+ - GPL-3.0-or-later
113
+ metadata:
114
+ bug_tracker_uri: https://github.com/kaitai-io/kaitai_struct_visualizer/issues
115
+ homepage_uri: https://kaitai.io/
116
+ source_code_uri: https://github.com/kaitai-io/kaitai_struct_visualizer
117
+ rubygems_mfa_required: 'true'
87
118
  rdoc_options: []
88
119
  require_paths:
89
120
  - lib
@@ -91,16 +122,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
91
122
  requirements:
92
123
  - - ">="
93
124
  - !ruby/object:Gem::Version
94
- version: '0'
125
+ version: 2.4.0
95
126
  required_rubygems_version: !ruby/object:Gem::Requirement
96
127
  requirements:
97
128
  - - ">="
98
129
  - !ruby/object:Gem::Version
99
130
  version: '0'
100
- requirements: []
101
- rubyforge_project:
102
- rubygems_version: 2.5.1
103
- signing_key:
131
+ requirements:
132
+ - kaitai-struct-compiler (https://kaitai.io/#download), the version must match the
133
+ kaitai-struct gem (check using `ksv --version`)
134
+ rubygems_version: 3.7.2
104
135
  specification_version: 4
105
136
  summary: Advanced hex viewer and binary structure exploration tool (visualizer) using
106
137
  Kaitai Struct ksy files
@@ -1,37 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- require File.expand_path("../lib/kaitai/struct/visualizer/version", __FILE__)
4
- require 'date'
5
-
6
- Gem::Specification.new { |s|
7
- s.name = 'kaitai-struct-visualizer'
8
- s.version = Kaitai::Struct::Visualizer::VERSION
9
- s.date = Date.today.to_s
10
-
11
- s.authors = ['Mikhail Yakshin']
12
- s.email = 'greycat@kaitai.io'
13
-
14
- s.homepage = 'http://kaitai.io'
15
- s.summary = 'Advanced hex viewer and binary structure exploration tool (visualizer) using Kaitai Struct ksy files'
16
- s.license = 'GPL-3.0+'
17
- s.description = <<-EOF
18
- Kaitai Struct is a declarative language used for describe various binary data structures, laid out in files or in memory: i.e. binary file formats, network stream packet formats, etc.
19
-
20
- The main idea is that a particular format is described in Kaitai Struct language (.ksy file) and then can be compiled with ksc into source files in one of the supported programming languages. These modules will include a generated code for a parser that can read described data structure from a file / stream and give access to it in a nice, easy-to-comprehend API.
21
-
22
- This package is a visualizer tool for .ksy files. Given a particular binary file and .ksy file(s) that describe its format, it can visualize internal data structures in a tree form and a multi-level highlight hex viewer.
23
- EOF
24
-
25
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
26
- s.require_paths = ['lib']
27
-
28
- s.files = `git ls-files`.split("\n")
29
- s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
30
- s.test_files = s.files.grep(%r{^(test|spec|features)/})
31
-
32
- s.add_development_dependency "bundler", "~> 1.3"
33
- s.add_development_dependency 'rake', '~> 10'
34
- # s.add_development_dependency 'rspec', '~> 3'
35
-
36
- s.add_dependency 'kaitai-struct', "~> 0.4"
37
- }
@@ -1,42 +0,0 @@
1
- require 'kaitai/struct/visualizer/version'
2
- require 'kaitai/struct/visualizer/visualizer'
3
- require 'kaitai/tui'
4
-
5
- module Kaitai::Struct::Visualizer
6
-
7
- class ExternalCompilerVisualizer < Visualizer
8
- def compile_format(fn)
9
- main_class_name = nil
10
- Dir.mktmpdir { |code_dir|
11
- args = ['--debug', '-t', 'ruby', fn, '-d', code_dir]
12
-
13
- # UNIX-based systems run ksc via a shell wrapper that requires
14
- # extra '--' in invocation to disambiguate our '-d' from java runner
15
- # '-d' (which allows to pass defines to JVM). Windows-based systems
16
- # do not need and do not support this extra '--', so we don't add it
17
- # on Windows.
18
- args.unshift('--') unless Kaitai::TUI::is_windows?
19
-
20
- system('kaitai-struct-compiler', *args)
21
- if $?.exitstatus != 0
22
- st = $?.exitstatus
23
- $stderr.puts("ksv: unable to find and execute kaitai-struct-compiler in your PATH") if st == 127
24
- exit st
25
- end
26
-
27
- puts "Compilation OK"
28
-
29
- compiled_path = Dir.glob("#{code_dir}/*.rb")[0]
30
-
31
- require compiled_path
32
-
33
- puts "Class loaded OK"
34
-
35
- main_class_name = File.readlines(compiled_path).grep(/^class /)[0].strip.gsub(/^class /, '').gsub(/ <.*$/, '')
36
- }
37
-
38
- return main_class_name
39
- end
40
- end
41
-
42
- end
@@ -1,18 +0,0 @@
1
- require 'ks_ruby_compiler'
2
-
3
- class RubyCompilerVisualizer extends Visualizer
4
- def compile
5
- Dir.mktmpdir { |code_dir|
6
- compiled_path = "#{code_dir}/compiled.rb"
7
- @compiler = CompileToRuby.new(@format_fn, compiled_path)
8
- @compiler.compile
9
-
10
- require compiled_path
11
-
12
- main_class_name = @compiler.type2class(@compiler.desc['meta']['id'])
13
- #puts "Main class: #{main_class_name}"
14
- main_class = Kernel::const_get(main_class_name)
15
- @data = main_class.from_file(@bin_fn)
16
- }
17
- end
18
- end