Class: Exerb::Win32::ResourceDirectory

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

Overview

#

Direct Known Subclasses

ResourceDirectoryRoot

Defined Under Namespace

Classes: Entry

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) {|_self| ... } ⇒ ResourceDirectory

Returns a new instance of ResourceDirectory

Yields:

  • (_self)

Yield Parameters:



20
21
22
23
24
25
# File 'lib/exerb/win32/resource_directory.rb', line 20

def initialize(name)
  @name    = name
  @entries = []

  yield(self) if block_given?
end

Instance Attribute Details

#entriesObject

Returns the value of attribute entries



27
28
29
# File 'lib/exerb/win32/resource_directory.rb', line 27

def entries
  @entries
end

#nameObject

Returns the value of attribute name



27
28
29
# File 'lib/exerb/win32/resource_directory.rb', line 27

def name
  @name
end

Class Method Details

.read(io, base, name = nil) ⇒ Object



29
30
31
# File 'lib/exerb/win32/resource_directory.rb', line 29

def self.read(io, base, name = nil)
  return self.new(nil).read(io, base, name)
end

Instance Method Details

#<<(entry) ⇒ Object



33
34
35
# File 'lib/exerb/win32/resource_directory.rb', line 33

def <<(entry)
  @entries << entry
end

#pack(table, reloc, base) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/exerb/win32/resource_directory.rb', line 45

def pack(table, reloc, base)
  dir = Exerb::Win32::Struct::ImageResourceDirectory.new
  dir.characteristics        = 0
  dir.time_date_stamp        = 0
  dir.major_version          = 0
  dir.minor_version          = 0
  dir.number_of_name_entries = 0
  dir.number_of_id_entries   = @entries.size

  return dir.pack
end

#read(io, base, name) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/exerb/win32/resource_directory.rb', line 57

def read(io, base, name)
  dir = Exerb::Win32::Struct::ImageResourceDirectory.read(io)

  @name    = name
  @entries = (1..(dir.number_of_name_entries + dir.number_of_id_entries)).collect {
    Exerb::Win32::Struct::ImageResourceDirectoryEntry.read(io)
  }.collect { |entry|
    if entry.data_is_directory?
      io.seek(entry.offset_to_directory)
      Exerb::Win32::ResourceDirectory.read(io, base, entry.name)
    else
      io.seek(entry.offset_to_data)
      Exerb::Win32::ResourceEntry.read(io, base, entry.name)
    end
  }

  return self
end

#serialize(elements, level) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/exerb/win32/resource_directory.rb', line 37

def serialize(elements, level)
  elements[0][level] = [] if elements[0][level].nil?
  elements[0][level] << self
  @entries.each { |entry| elements[0][level] << Exerb::Win32::ResourceDirectory::Entry.new(entry) }
  @entries.each { |entry| entry.serialize(elements, level + 1) }
  return elements
end