# File lib/rex/elfparsey/elf.rb, line 14 def initialize(isource) offset = 0 base_addr = 0 # ELF Header elf_header = ElfHeader.new(isource.read(offset, ELF_HEADER_SIZE)) # Data encoding ei_data = elf_header.e_ident[EI_DATA,1].unpack("C")[0] e_phoff = elf_header.e_phoff e_phentsize = elf_header.e_phentsize e_phnum = elf_header.e_phnum # Program Header Table program_header = [] e_phnum.times do |i| offset = e_phoff + (e_phentsize * i) program_header << ProgramHeader.new( isource.read(offset, PROGRAM_HEADER_SIZE), ei_data ) if program_header[-1].p_type == PT_LOAD && base_addr == 0 base_addr = program_header[-1].p_vaddr end end self.elf_header = elf_header self.program_header = program_header self.base_addr = base_addr self.isource = isource end
# File lib/rex/elfparsey/elf.rb, line 50 def self.new_from_file(filename, disk_backed = false) file = ::File.new(filename) # file.binmode # windows... :\ if disk_backed return self.new(ImageSource::Disk.new(file)) else obj = new_from_string(file.read) file.close return obj end end
# File lib/rex/elfparsey/elf.rb, line 116 def close isource.close end
# File lib/rex/elfparsey/elf.rb, line 112 def index(*args) isource.index(*args) end
# File lib/rex/elfparsey/elf.rb, line 96 def offset_to_rva(offset) base_addr + offset end
Returns true if this binary is for a 32-bit architecture. This check does not take into account 16-bit binaries at the moment.
# File lib/rex/elfparsey/elf.rb, line 84 def ptr_32? ptr_64? == false end
Returns true if this binary is for a 64-bit architecture.
# File lib/rex/elfparsey/elf.rb, line 71 def ptr_64? unless [ ELFCLASS32, ELFCLASS64 ].include?( elf_header.e_ident[EI_CLASS,1].unpack("C*")[0]) raise ElfHeaderError, 'Invalid class', caller end elf_header.e_ident[EI_CLASS,1].unpack("C*")[0] == ELFCLASS64 end
Converts a virtual address to a string representation based on the underlying architecture.
# File lib/rex/elfparsey/elf.rb, line 92 def ptr_s(rva) (ptr_32?) ? ("0x%.8x" % rva) : ("0x%.16x" % rva) end
# File lib/rex/elfparsey/elf.rb, line 104 def read(offset, len) isource.read(offset, len) end
Generated with the Darkfish Rdoc Generator 2.