kaitai-struct-visualizer 0.5 → 0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '0294e63ea9c355016ef56c48aed683eec1204ee4'
4
- data.tar.gz: 49acc6230547d1c10c1978d626cb498a29d2cd0f
3
+ metadata.gz: 7b37b3d7fa10586b07b80076fb60a9b5bea5719a
4
+ data.tar.gz: 2ff461ac414e9ab3ecf4b0a712ad4e757acc27ff
5
5
  SHA512:
6
- metadata.gz: 7962d68bdafde103d6cf56408436ec79299e3fc25ed7b76dee888bde59d06e65bc71231732d4c9fe6ba5dfd3ebb5c727c2f394aa9c081af1123c69f39fb20380
7
- data.tar.gz: 07ac40819e35d59ae48e3fcdba3f965df4288ec0c6fe45867f236ec3859f0f06ed62b5e1ea5e6e59fdae80c4a1a7d688fd2ff7658da81767e61fb1b389e41302
6
+ metadata.gz: 2f9f6599576d9d6399cf5ceae258459cb8a26f038a1f95e7a2a1e4560e411b1b59e708026c75c6adb88efbf86cd38fcabeced8e6692868ca6c6495f725b37205
7
+ data.tar.gz: d276166a68b97fee40538360bea6717c70a22517972567f2a7886a629eb3b47d5c0bf04bf94ad6c36a5b849616f3e7f26a3aab818ead47fddf1472103d5a79ec
data/README.md CHANGED
@@ -43,8 +43,7 @@ out source code in repository:
43
43
 
44
44
  ## Licensing
45
45
 
46
- Kaitai Struct visualizer itself is copyright (C) 2015-2016 Kaitai
47
- Project.
46
+ Kaitai Struct visualizer is copyright (C) 2015-2017 Kaitai Project.
48
47
 
49
48
  This program is free software: you can redistribute it and/or modify
50
49
  it under the terms of the GNU General Public License as published by
@@ -0,0 +1,126 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+
5
+ # Some additional magic to make it work right after repo checkout,
6
+ # without installation to proper Ruby library dirs
7
+
8
+ full_bin_path = File.realpath($PROGRAM_NAME)
9
+ dist_path = File.expand_path(File.dirname(full_bin_path) + '/..')
10
+
11
+ $LOAD_PATH << "#{dist_path}/lib"
12
+ $LOAD_PATH << "#{dist_path}/../runtime/ruby/lib"
13
+
14
+ require 'kaitai/struct/visualizer'
15
+
16
+ # ======================================================================
17
+
18
+ options = {:format => 'yaml'}
19
+ parser = OptionParser.new do |opts|
20
+ $prog_name = File.basename($PROGRAM_NAME)
21
+
22
+ opts.banner = "Usage: #{$prog_name} [options] <file_to_parse.bin> <format.ksy>..."
23
+ opts.separator ""
24
+
25
+ opts.on("-I", "--import-path [DIRECTORIES]", ".ksy library search path(s) for imports (see also KSPATH env variable)") do |v|
26
+ options[:import_path] = v
27
+ end
28
+
29
+ FORMATS = ['json', 'xml', 'yaml']
30
+ opts.on("-f", "--format FORMAT", FORMATS, "choose dump format - #{FORMATS.join(', ')} (default: #{options[:format]})") do |v|
31
+ options[:format] = v
32
+ end
33
+
34
+ opts.on("--version", "show versions of #{$prog_name} and ksc") do |v|
35
+ puts "#{$prog_name} #{Kaitai::Struct::Visualizer::VERSION}"
36
+ system("ksc", "--version")
37
+ exit 0
38
+ end
39
+ end
40
+
41
+ begin
42
+ parser.parse!
43
+ rescue OptionParser::InvalidOption => e
44
+ puts e
45
+ puts parser
46
+ exit 1
47
+ end
48
+
49
+ if ARGV.size < 2
50
+ puts parser
51
+ exit 1
52
+ end
53
+
54
+ c = Kaitai::Struct::Visualizer::KSYCompiler.new(options)
55
+ app = Kaitai::Struct::Visualizer::Parser.new(c, ARGV[0], ARGV[1..-1], options)
56
+ app.load
57
+
58
+ # ======================================================================
59
+
60
+ def obj_to_h(obj)
61
+ if obj == true or obj == false or obj.is_a?(Numeric) or obj.nil?
62
+ obj
63
+ elsif obj.is_a?(Symbol)
64
+ obj.to_s
65
+ elsif obj.is_a?(String)
66
+ if obj.encoding == Encoding::ASCII_8BIT
67
+ r = ''
68
+ obj.each_byte { |x| r << sprintf('%02X ', x) }
69
+ r.chop!
70
+ r
71
+ else
72
+ obj.encode('UTF-8')
73
+ end
74
+ elsif obj.is_a?(Array)
75
+ obj.map { |x| obj_to_h(x) }
76
+ else
77
+ root = {}
78
+ valid_struct = false
79
+
80
+ common_meths = Set.new
81
+ obj.class.ancestors.each { |cl|
82
+ next if cl == obj.class
83
+ valid_struct = true if cl == Kaitai::Struct::Struct
84
+ common_meths.merge(cl.instance_methods)
85
+ }
86
+
87
+ return "OPAQUE (#{obj.class.to_s})" if not valid_struct
88
+
89
+ inst_meths = Set.new(obj.public_methods) - common_meths
90
+ inst_meths.sort.each { |meth|
91
+ k = meth.to_s
92
+ next if k =~ /^_/ # or attrs.include?(k)
93
+
94
+ el = obj.send(meth)
95
+ v = obj_to_h(el)
96
+ root[k] = v unless v.nil?
97
+ }
98
+
99
+ # obj.instance_variables.each { |k|
100
+ # k = k.to_s
101
+ # next if k =~ /^@_/
102
+ # el = obj.instance_eval(k)
103
+ # root[k[1..-1]] = obj_to_h(el)
104
+ # }
105
+ root
106
+ end
107
+ end
108
+
109
+ tree = obj_to_h(app.data)
110
+ r = nil
111
+
112
+ case options[:format]
113
+ when 'json'
114
+ require 'json'
115
+ r = JSON.pretty_generate(tree)
116
+ when 'xml'
117
+ require 'active_support'
118
+ require 'active_support/core_ext'
119
+ r = tree.to_xml
120
+ when 'yaml'
121
+ require 'yaml'
122
+ r = tree.to_yaml
123
+ r = r[4..-1] if r[0..3] == "---\n"
124
+ end
125
+
126
+ print r
data/bin/ksv CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'optparse'
4
+
3
5
  # Some additional magic to make it work right after repo checkout,
4
6
  # without installation to proper Ruby library dirs
5
7
 
@@ -11,10 +13,41 @@ $LOAD_PATH << "#{dist_path}/../runtime/ruby/lib"
11
13
 
12
14
  require 'kaitai/struct/visualizer'
13
15
 
16
+ # ======================================================================
17
+
18
+ options = {}
19
+ parser = OptionParser.new do |opts|
20
+ opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} [options] <file_to_parse.bin> <format.ksy>..."
21
+ opts.separator ""
22
+
23
+ opts.on("-I", "--import-path [DIRECTORIES]", ".ksy library search path(s) for imports (see also KSPATH env variable)") do |v|
24
+ options[:import_path] = v
25
+ end
26
+
27
+ opts.on("--opaque-types [BOOLEAN]", "opaque types allowed, default: false") do |v|
28
+ options[:opaque_types] = v
29
+ end
30
+
31
+ opts.on("--version", "show versions of ksv and ksc") do |v|
32
+ puts "kaitai-struct-visualizer #{Kaitai::Struct::Visualizer::VERSION}"
33
+ system("ksc", "--version")
34
+ exit 0
35
+ end
36
+ end
37
+
38
+ begin
39
+ parser.parse!
40
+ rescue OptionParser::InvalidOption => e
41
+ puts e
42
+ puts parser
43
+ exit 1
44
+ end
45
+
14
46
  if ARGV.size < 2
15
- puts "Usage: #{File.basename($PROGRAM_NAME)} <file_to_parse.bin> <format.yaml>..."
47
+ puts parser
16
48
  exit 1
17
49
  end
18
50
 
19
- v = Kaitai::Struct::Visualizer::ExternalCompilerVisualizer.new(ARGV[0], ARGV[1..-1])
51
+ c = Kaitai::Struct::Visualizer::KSYCompiler.new(options)
52
+ v = Kaitai::Struct::Visualizer::Visualizer.new(c, ARGV[0], ARGV[1..-1], options)
20
53
  v.run
@@ -9,15 +9,28 @@ class ConsoleANSI
9
9
  attr_reader :rows
10
10
 
11
11
  def initialize
12
- # Normal POSIX way to determine console parameters
13
- @cols = `tput cols`.to_i
14
- @rows = `tput lines`.to_i
12
+ get_term_size
15
13
 
16
14
  @seq_clear = `tput clear`
17
15
  @seq_sgr0 = `tput sgr0`
18
16
 
19
17
  @seq_fgcolor = []
20
18
  @seq_bgcolor = []
19
+
20
+ @on_resize = nil
21
+
22
+ Signal.trap('SIGWINCH', proc {
23
+ get_term_size
24
+ @on_resize.call if @on_resize
25
+ })
26
+ end
27
+
28
+ def on_resize=(handler)
29
+ @on_resize = handler
30
+ end
31
+
32
+ def get_term_size
33
+ @rows, @cols = IO.console.winsize
21
34
  end
22
35
 
23
36
  def clear
@@ -50,6 +50,10 @@ class ConsoleWindows
50
50
  @rows = win_bottom - win_top + 1
51
51
  end
52
52
 
53
+ def on_resize=(handler)
54
+ @on_resize = handler
55
+ end
56
+
53
57
  def puts(s)
54
58
  Kernel::puts s
55
59
  # num_written = 'XXXX'
@@ -1,2 +1,3 @@
1
1
  require 'kaitai/struct/visualizer/version'
2
- require 'kaitai/struct/visualizer/visualizer_main'
2
+ require 'kaitai/struct/visualizer/visualizer'
3
+ require 'kaitai/struct/visualizer/ksy_compiler'
@@ -2,10 +2,12 @@ require 'kaitai/struct/visualizer/version'
2
2
 
3
3
  module Kaitai::Struct::Visualizer
4
4
  class HexViewer
5
- def initialize(ui, buf, shift_x = 0, tree = nil)
5
+ attr_accessor :shift_x
6
+
7
+ def initialize(ui, buf, tree = nil)
6
8
  @ui = ui
7
9
  @buf = buf
8
- @shift_x = shift_x
10
+ @shift_x = 0
9
11
  @tree = tree
10
12
 
11
13
  @embedded = not(tree.nil?)
@@ -0,0 +1,116 @@
1
+ require 'kaitai/struct/visualizer/version'
2
+ require 'kaitai/tui'
3
+
4
+ require 'open3'
5
+ require 'json'
6
+ require 'tmpdir'
7
+
8
+ module Kaitai::Struct::Visualizer
9
+
10
+ class KSYCompiler
11
+ def initialize(opts, out = $stderr)
12
+ @opts = opts
13
+ @out = out
14
+ end
15
+
16
+ def compile_formats(fns)
17
+ errs = false
18
+ main_class_name = nil
19
+ Dir.mktmpdir { |code_dir|
20
+ args = ['--ksc-json-output', '--debug', '-t', 'ruby', *fns, '-d', code_dir]
21
+
22
+ # Extra arguments
23
+ extra = []
24
+ extra += ['--import-path', @opts[:import_path]] if @opts[:import_path]
25
+ extra += ['--opaque-types', @opts[:opaque_types]] if @opts[:opaque_types]
26
+
27
+ args = extra + args
28
+
29
+ # UNIX-based systems run ksc via a shell wrapper that requires
30
+ # extra '--' in invocation to disambiguate our '-d' from java runner
31
+ # '-d' (which allows to pass defines to JVM). Windows-based systems
32
+ # do not need and do not support this extra '--', so we don't add it
33
+ # on Windows.
34
+ args.unshift('--') unless Kaitai::TUI::is_windows?
35
+
36
+ status = nil
37
+ log_str = nil
38
+ err_str = nil
39
+ Open3.popen3('kaitai-struct-compiler', *args) { |stdin, stdout, stderr, wait_thr|
40
+ status = wait_thr.value
41
+ log_str = stdout.read
42
+ err_str = stderr.read
43
+ }
44
+
45
+ if not status.success?
46
+ if status.exitstatus == 127
47
+ @out.puts "ksv: unable to find and execute kaitai-struct-compiler in your PATH"
48
+ elsif err_str =~ /Error: Unknown option --ksc-json-output/
49
+ @out.puts "ksv: your kaitai-struct-compiler is too old:"
50
+ system('kaitai-struct-compiler', '--version')
51
+ @out.puts "\nPlease use at least v0.7."
52
+ else
53
+ @out.puts "ksc crashed (exit status = #{status}):\n"
54
+ @out.puts "== STDOUT\n"
55
+ @out.puts log_str
56
+ @out.puts
57
+ @out.puts "== STDERR\n"
58
+ @out.puts err_str
59
+ @out.puts
60
+ end
61
+ exit status.exitstatus
62
+ end
63
+
64
+ log = JSON.load(log_str)
65
+
66
+ # FIXME: add log results check
67
+ @out.puts "Compilation OK"
68
+
69
+ fns.each_with_index { |fn, idx|
70
+ @out.puts "... processing #{fn} #{idx}"
71
+
72
+ log_fn = log[fn]
73
+ if log_fn['errors']
74
+ report_err(log_fn['errors'])
75
+ errs = true
76
+ else
77
+ log_classes = log_fn['output']['ruby']
78
+ log_classes.each_pair { |k, v|
79
+ if v['errors']
80
+ report_err(v['errors'])
81
+ errs = true
82
+ else
83
+ compiled_name = v['files'][0]['fileName']
84
+ compiled_path = "#{code_dir}/#{compiled_name}"
85
+
86
+ @out.puts "...... loading #{compiled_name}"
87
+ require compiled_path
88
+ end
89
+ }
90
+
91
+ # Is it main ClassSpecs?
92
+ if idx == 0
93
+ main = log_classes[log_fn['firstSpecName']]
94
+ main_class_name = main['topLevelName']
95
+ end
96
+ end
97
+ }
98
+
99
+ }
100
+
101
+ if errs
102
+ @out.puts "Fatal errors encountered, cannot continue"
103
+ exit 1
104
+ else
105
+ @out.puts "Classes loaded OK, main class = #{main_class_name}"
106
+ end
107
+
108
+ return main_class_name
109
+ end
110
+
111
+ def report_err(err)
112
+ @out.puts "Error: #{err.inspect}"
113
+ end
114
+ end
115
+
116
+ end
@@ -186,6 +186,10 @@ class Node
186
186
  @pos2 = debug_el[:end]
187
187
  end
188
188
  elsif @value.is_a?(Array)
189
+ # Bail out early for empty array: it doesn't have proper
190
+ # debugging aids structure anyway
191
+ return if @value.empty?
192
+
189
193
  clean_id = @id[0] == '@' ? @id[1..-1] : @id
190
194
  debug_el = @parent.value._debug[clean_id]
191
195
  raise "Unable to get debugging aid for array: #{@parent.value._debug.inspect} using ID '#{clean_id}'" unless debug_el
@@ -0,0 +1,42 @@
1
+ require 'kaitai/struct/visualizer/version'
2
+ require 'kaitai/tui'
3
+ require 'kaitai/struct/visualizer/tree'
4
+
5
+ # TODO: should be inside compiled files
6
+ require 'zlib'
7
+ require 'stringio'
8
+
9
+ module Kaitai::Struct::Visualizer
10
+
11
+ ##
12
+ # Base class for everything that deals with compiling .ksy and parsing
13
+ # stuff as object tree.
14
+ class Parser
15
+ attr_reader :data
16
+
17
+ def initialize(compiler, bin_fn, formats_fn, opts)
18
+ @compiler = compiler
19
+ @bin_fn = bin_fn
20
+ @formats_fn = formats_fn
21
+ @opts = opts
22
+ end
23
+
24
+ def load
25
+ main_class_name = @compiler.compile_formats(@formats_fn)
26
+
27
+ main_class = Kernel::const_get(main_class_name)
28
+ @data = main_class.from_file(@bin_fn)
29
+
30
+ load_exc = nil
31
+ begin
32
+ @data._read
33
+ rescue EOFError => e
34
+ load_exc = e
35
+ rescue Kaitai::Struct::Stream::UnexpectedDataError => e
36
+ load_exc = e
37
+ end
38
+
39
+ return load_exc
40
+ end
41
+ end
42
+ end
@@ -11,17 +11,27 @@ class Tree
11
11
  @st = st
12
12
  @root = Node.new(self, st, 0)
13
13
  @root.id = '[root]'
14
- @max_scr_ln = @ui.rows - 3
15
-
16
- @hv_shift_x = @ui.cols - HexViewer.line_width - 1
17
14
 
18
15
  @cur_io = nil
19
- @hv = HexViewer.new(ui, nil, @hv_shift_x, self)
16
+ @hv = HexViewer.new(ui, nil, self)
20
17
  @hv_hidden = false
21
18
 
19
+ recalc_sizes
20
+
22
21
  @cur_line = 0
23
22
  @cur_shift = 0
24
23
  @do_exit = false
24
+
25
+ @ui.on_resize = proc {
26
+ recalc_sizes
27
+ redraw
28
+ @hv.redraw
29
+ }
30
+ end
31
+
32
+ def recalc_sizes
33
+ @max_scr_ln = @ui.rows - 3
34
+ @hv.shift_x = @ui.cols - HexViewer.line_width - 1
25
35
  end
26
36
 
27
37
  def run
@@ -221,7 +231,7 @@ class Tree
221
231
  if @hv_hidden
222
232
  @ui.cols
223
233
  else
224
- @hv_shift_x
234
+ @hv.shift_x
225
235
  end
226
236
  end
227
237
 
@@ -1,7 +1,7 @@
1
1
  module Kaitai
2
2
  module Struct
3
3
  module Visualizer
4
- VERSION = '0.5'
4
+ VERSION = '0.7'
5
5
  end
6
6
  end
7
7
  end
@@ -1,7 +1,6 @@
1
- require 'tmpdir'
2
-
3
1
  require 'kaitai/struct/visualizer/version'
4
2
  require 'kaitai/tui'
3
+ require 'kaitai/struct/visualizer/parser'
5
4
  require 'kaitai/struct/visualizer/tree'
6
5
 
7
6
  # TODO: should be inside compiled files
@@ -9,38 +8,16 @@ require 'zlib'
9
8
  require 'stringio'
10
9
 
11
10
  module Kaitai::Struct::Visualizer
12
- class Visualizer
13
- def initialize(bin_fn, formats_fn)
14
- @bin_fn = bin_fn
15
- @formats_fn = formats_fn
16
- @primary_format = @formats_fn.shift
17
-
18
- main_class_name = compile_format(@primary_format)
19
-
20
- @formats_fn.each { |fn|
21
- compile_format(fn)
22
- }
23
-
24
- main_class = Kernel::const_get(main_class_name)
25
- @data = main_class.from_file(@bin_fn)
26
-
27
- load_exc = nil
28
- begin
29
- @data._read
30
- rescue EOFError => e
31
- load_exc = e
32
- rescue Kaitai::Struct::Stream::UnexpectedDataError => e
33
- load_exc = e
34
- end
11
+ class Visualizer < Parser
12
+ def run
13
+ load_exc = load
35
14
 
36
15
  @ui = Kaitai::TUI.new
37
16
  @tree = Tree.new(@ui, @data)
38
17
 
39
18
  @tree.redraw
40
19
  @ui.message_box_exception(load_exc) if load_exc
41
- end
42
20
 
43
- def run
44
21
  @tree.run
45
22
  end
46
23
  end
@@ -33,6 +33,10 @@ class TUI
33
33
  end
34
34
  end
35
35
 
36
+ def on_resize=(handler)
37
+ @console.on_resize = handler
38
+ end
39
+
36
40
  def message_box_exception(e)
37
41
  message_box("Error while parsing", e.message)
38
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
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.7'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikhail Yakshin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-15 00:00:00.000000000 Z
11
+ date: 2017-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -60,24 +60,26 @@ description: |
60
60
  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
61
  email: greycat@kaitai.io
62
62
  executables:
63
+ - ksdump
63
64
  - ksv
64
65
  extensions: []
65
66
  extra_rdoc_files: []
66
67
  files:
67
68
  - LICENSE
68
69
  - README.md
70
+ - bin/ksdump
69
71
  - bin/ksv
70
72
  - kaitai-struct-visualizer.gemspec
71
73
  - lib/kaitai/console_ansi.rb
72
74
  - lib/kaitai/console_windows.rb
73
75
  - lib/kaitai/struct/visualizer.rb
74
76
  - lib/kaitai/struct/visualizer/hex_viewer.rb
77
+ - lib/kaitai/struct/visualizer/ksy_compiler.rb
75
78
  - lib/kaitai/struct/visualizer/node.rb
79
+ - lib/kaitai/struct/visualizer/parser.rb
76
80
  - lib/kaitai/struct/visualizer/tree.rb
77
81
  - lib/kaitai/struct/visualizer/version.rb
78
82
  - lib/kaitai/struct/visualizer/visualizer.rb
79
- - lib/kaitai/struct/visualizer/visualizer_main.rb
80
- - lib/kaitai/struct/visualizer/visualizer_ruby.rb
81
83
  - lib/kaitai/tui.rb
82
84
  homepage: http://kaitai.io
83
85
  licenses:
@@ -99,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
101
  version: '0'
100
102
  requirements: []
101
103
  rubyforge_project:
102
- rubygems_version: 2.5.1
104
+ rubygems_version: 2.5.2
103
105
  signing_key:
104
106
  specification_version: 4
105
107
  summary: Advanced hex viewer and binary structure exploration tool (visualizer) using
@@ -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