Class: Winject::EXE

Inherits:
Object
  • Object
show all
Defined in:
lib/shoes/winject.rb

Constant Summary collapse

SHOES_APP_NAME =

Constants for RT_STRING resources

50
SHOES_DOWNLOAD_SITE =

Name of script or shy

51
SHOES_DOWNLOAD_PATH =

website download - no http://

52
SHOES_VERSION_NEEDED =

/path/to/cgi

53
SHOES_USE_ARGS =

version number string - TBD

54
SHOES_APP_CONTENT =

Constants for RC_DATA resources

128
SHOES_SYS_SETUP =

contents of script or shy

129

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filepath) ⇒ EXE

Returns a new instance of EXE.



22
23
24
25
26
27
28
29
# File 'lib/shoes/winject.rb', line 22

def initialize filepath
  #puts "Winject init from #{filepath}"
  rawpe = ''
  #File.open(filepath, 'r:ASCII-8BIT') {|file| rawpe = file.read}
  File.open(filepath, 'rb') {|file| rawpe = file.read}
  # parse the rawpe into Exerb objects
  return @exe = Exerb::Executable.new(rawpe)
end

Instance Attribute Details

#exeObject

Returns the value of attribute exe.



20
21
22
# File 'lib/shoes/winject.rb', line 20

def exe
  @exe
end

Instance Method Details

#inject_file(id, io) ⇒ Object



48
49
50
51
# File 'lib/shoes/winject.rb', line 48

def inject_file (id, io)
  #puts "Winject file #{id}"
  @exe.rsrc.add_rcdata(id, io)
end

#inject_icons(iconf_path) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/shoes/winject.rb', line 53

def inject_icons(iconf_path)
  # delete existing RT_ICON's and RT_ICON_GROUP
  @exe.rsrc.remove(Exerb::Win32::Const::RT_ICON)
  @exe.rsrc.remove(Exerb::Win32::Const::RT_GROUP_ICON)
  group_icon = Exerb::Resource::GroupIcon.new

  icos = Exerb::Win32::IconFile.read(iconf_path)
  icos.entries.each_with_index do |entry, index|
    # Exerb::Win32::IconFile::Entry:
    # make a new Icon and copy
    icon = Exerb::Resource::Icon.new
    icon.width     = entry.width == 256 ? 0 : entry.width
    icon.height    = entry.height == 256 ? 0 : entry.height
    icon.bit_count = entry.bit_count
    icon.value     = entry.value

    id   = index + 1
    #icon = Exerb::Resource::Icon.read(icos, entry.width, entry.height, entry.bit_count)
    @exe.rsrc.add(Exerb::Win32::Const::RT_ICON, id, icon)
    group_icon.add(id, icon)
  end
  @exe.rsrc.add(Exerb::Win32::Const::RT_GROUP_ICON, 1, group_icon)
end

#inject_string(id, contents) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/shoes/winject.rb', line 36

def inject_string (id, contents)
  #puts "injecting string #{id} = #{contents}"
  #@exe.rsrc.each do |rs| 
  #  puts "resource #{rs.id}"
  #end
  @exe.rsrc.add_string( id, contents)
  #puts "=== after inject ===="
  #@exe.rsrc.each do |rs| 
  #  puts "resource #{rs.id}"
  #end
end

#save(filepath) ⇒ Object



31
32
33
34
# File 'lib/shoes/winject.rb', line 31

def save filepath
  #puts "Winject writing #{filepath}"
  @exe.write(filepath)
end