Class: Rex::ElfParsey::ElfBase::ElfHeader

Inherits:
GenericHeader show all
Defined in:
lib/rex/elfparsey/elfbase.rb

Instance Attribute Summary

Attributes inherited from GenericStruct

#struct

Instance Method Summary collapse

Methods inherited from GenericStruct

#[], #keys, #method_missing, #v

Constructor Details

#initialize(rawdata) ⇒ ElfHeader

Returns a new instance of ElfHeader.



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/rex/elfparsey/elfbase.rb', line 156

def initialize(rawdata)

	# Identify the data encoding and parse ELF Header
	elf_header = ELF32_EHDR_LSB.make_struct

	if !elf_header.from_s(rawdata)
		raise ElfHeaderError, "Couldn't parse ELF Header", caller
	end

	if elf_header.v['e_ident'][EI_DATA,1].unpack('C')[0] == ELFDATA2MSB
		elf_header = ELF32_EHDR_MSB.make_struct

		if !elf_header.from_s(rawdata)
			raise ElfHeaderError, "Couldn't parse ELF Header", caller
		end
	end

	unless [ ELFDATA2LSB, ELFDATA2MSB ].include?(
	elf_header.v['e_ident'][EI_DATA,1].unpack('C')[0])
		raise ElfHeaderError, "Invalid data encoding", caller
	end

	# Identify the file as an ELF object file
	unless elf_header.v['e_ident'][EI_MAG0, 4] == ELFMAG
		raise ElfHeaderError, 'Invalid magic number', caller
	end

	self.struct = elf_header
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Rex::ElfParsey::ElfBase::GenericStruct

Instance Method Details

#e_identObject



186
187
188
# File 'lib/rex/elfparsey/elfbase.rb', line 186

def e_ident
	struct.v['e_ident']
end