Module: DataExplorer

Included in:
Convert::DatToAscii
Defined in:
lib/data_explorer.rb,
lib/data_explorer/convert/dat_to_ascii.rb

Defined Under Namespace

Modules: Convert

Constant Summary collapse

@@data_explorer_instance =
nil

Instance Method Summary collapse

Instance Method Details

#close_data_explorerObject



12
13
14
15
16
17
18
# File 'lib/data_explorer.rb', line 12

def close_data_explorer
  if @@data_explorer_instance
    data_explorer.quit
    data_explorer.ole_free
    @@data_explorer_instance = nil
  end
end

#data_explorerObject



7
8
9
10
# File 'lib/data_explorer.rb', line 7

def data_explorer
  @@data_explorer_instance = WIN32OLE.new('DataExplorer.Application') unless @@data_explorer_instance
  @@data_explorer_instance
end

#data_explorer_versionObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/data_explorer.rb', line 20

def data_explorer_version
  # Gets the version information for a windows executable
  # trivially modified from: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/161140
  #fname = 'D:\ruby\bin\ruby.exe'  
  fname = data_explorer.fullname
  get_file_version_info_size = Win32API.new('Version', 'GetFileVersionInfoSize', 'PP', 'L')
  get_file_version_info     = Win32API.new('Version', 'GetFileVersionInfo', 'PLLP', 'L')
  ver_query_value          = Win32API.new('Version', 'VerQueryValue', 'PPPP', 'I')
  memcpy = Win32API.new('msvcrt', 'memcpy', 'PLL', 'L')

  addr = "\0"*4

  v_info_sz = get_file_version_info_size.call(fname, addr)

  raise 'GFVIS failed' if v_info_sz == 0
  v_info = "\0"*v_info_sz
  get_file_version_info.call(fname, 0, v_info_sz, v_info)

  v_val_sz = "\0"*4
  ver_query_value.call(v_info, '\\', addr, v_val_sz)
  v_bufsz = v_val_sz.unpack('L')[0]
  v_buf = "\0" * v_bufsz
  v_src = addr.unpack('L')[0]
  ret = memcpy.call(v_buf, v_src, v_bufsz)
  raise 'memcpy failed' if ret == 0

  raise 'Oops' unless v_buf[0, 4].unpack('L')[0] == 0xFEEF04BD
  #p v_buf[0x08, 8].unpack('S*').values_at(1,0,3,2)  #-> [1, 8, 2, 0]
  #p v_buf[0x10, 8].unpack('S*').values_at(1,0,3,2)  #-> [1, 8, 2, 0]
  v_buf[0x08, 8].unpack('S*').values_at(1,0,3,2).join('.')
end