Class: Exerb::ResourceLibrary

Inherits:
Object
  • Object
show all
Defined in:
lib/exerb/resource_library.rb

Overview

#

Defined Under Namespace

Classes: Stab

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rsrc) ⇒ ResourceLibrary

Returns a new instance of ResourceLibrary


18
19
20
# File 'lib/exerb/resource_library.rb', line 18

def initialize(rsrc)
  @rsrc = rsrc
end

Instance Attribute Details

#rsrcObject

Returns the value of attribute rsrc


22
23
24
# File 'lib/exerb/resource_library.rb', line 22

def rsrc
  @rsrc
end

Class Method Details

.createObject


24
25
26
# File 'lib/exerb/resource_library.rb', line 24

def self.create
  return self.new(Exerb::Resource.new)
end

Instance Method Details

#packObject


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/exerb/resource_library.rb', line 28

def pack
  rsrc = @rsrc.pack(0x00001000)
  stab = Exerb::ResourceLibrary::Stab.new

  size_of_rsrc_with_padding = Exerb::Utility.alignment4k(rsrc).size
  size_of_stab_with_padding = Exerb::Utility.alignment4k(stab.pack).size

  stab.time_date_stamp              = Time.now.to_i
  stab.size_of_initialized_data     = size_of_rsrc_with_padding
  stab.size_of_image                = size_of_stab_with_padding + size_of_rsrc_with_padding
  stab.rsrc_section_virtual_address = size_of_stab_with_padding
  stab.rsrc_section_virtual_size    = rsrc.size
  stab.rsrc_section_raw_size        = size_of_rsrc_with_padding

  return Exerb::Utility.alignment4k(stab.pack) + Exerb::Utility.alignment4k(rsrc)
end

#write(out) ⇒ Object


45
46
47
48
49
50
51
52
# File 'lib/exerb/resource_library.rb', line 45

def write(out)
  case out
  when IO     then out.write(self.pack)
  when String then File.open(out, 'wb') { |file| self.write(file) }
  else raise(ArgumentError, 'arg must be IO or String object')
  end
  return nil
end