def _init_cls_sections(self, file_, prepare, classes): """ Initialise the sections which are of a given list of classes """ for i, header in enumerate(self._sheaders): sect_cls = ELF_SECTION_TYPES.get(header.sh_type, UnpreparedElfSection) if sect_cls in classes: data = file_.get_data(header.sh_offset, header.sh_size) strtable = self._get_strtable() name = strtable.get_string_ofs(header.sh_name) sect = sect_cls(self, name, header.sh_type, header.sh_addr, data, header.sh_flags, header.sh_addralign, header.sh_info, self.sections[header.sh_link]) if prepare: sect = sect.prepare(header.sh_offset, i, header.sh_name) self.sections[i] = sect # Now set up any links between sections and convert the info # field to the appropriate type. for section, header in zip(self.sections, self._sheaders): if section: if header.sh_link: section.link = self.sections[header.sh_link] if section.info_is_section(): section.info = self.sections[header.sh_info] else: section.info = header.sh_info
def _initialise_sections(self, hdr, f, prepare): """Initialise information from section headers.""" self._sh_offset = shoff = hdr.e_shoff self._sh_strndx = 0 self.sections = [] if shoff == 0: return # Create an array of section headers sheaders = self._get_section_headers(hdr, f) # Now create section objects for all of them for i, sh in enumerate(sheaders): sect_cls = ELF_SECTION_TYPES.get(sh.sh_type, UnpreparedElfSection) if sh.sh_type != SHT_NOBITS: data = f.get_data(sh.sh_offset, sh.sh_size) else: data = sh.sh_size es = sect_cls(None, sh.sh_type, sh.sh_addr, data, sh.sh_flags, \ sh.sh_addralign, sh.sh_entsize, sh.sh_info) if prepare: es = es.prepare(sh.sh_offset, i, sh.sh_name, self.wordsize, self.endianess) self.sections.append(es) # Find the section header string table if there is one if hdr.e_shstrndx != 0: self._sh_strndx = hdr.e_shstrndx strtable = self.sections[hdr.e_shstrndx] if strtable.type != SHT_STRTAB: raise ElfFormatError, \ "The section string table is malformed. %s %s" \ % (strtable, self.sections) assert strtable.__class__ == { True: PreparedElfStringTable, False: UnpreparedElfStringTable }[prepare] # Now update all the section names with the string for section, sh in zip(self.sections, sheaders): section._name = strtable.get_string_ofs(sh.sh_name) # Now set up any links between for section, sh in zip(self.sections, sheaders): if sh.sh_link: section.link = self.sections[sh.sh_link]
def _initialise_sections(self, hdr, file_, prepare): """Initialise information from section headers.""" self._sh_offset = hdr.e_shoff self._sh_strndx = hdr.e_shstrndx self._sheaders = self._get_section_headers(hdr, file_) self.sections = [] if self._sh_offset == 0: return # Now create section objects for all of them for i, header in enumerate(self._sheaders): sect_cls = ELF_SECTION_TYPES.get(header.sh_type, UnpreparedElfSection) if header.sh_type != SHT_NOBITS: data = file_.get_data(header.sh_offset, header.sh_size) else: data = header.sh_size if sect_cls in [ UnpreparedElfSymbolTable, UnpreparedElfReloc, UnpreparedElfReloca ]: section = None # We handle symbol tables and relocs later else: section = sect_cls(self, None, header.sh_type, header.sh_addr, data, header.sh_flags, header.sh_addralign, header.sh_info) if prepare: section = section.prepare(header.sh_offset, i, header.sh_name) self.sections.append(section) # Now set up any links between sections and convert the info # field to the appropriate type. for section, header in zip(self.sections, self._sheaders): if section: if header.sh_link: section.link = self.sections[header.sh_link] if section.info_is_section(): section.info = self.sections[header.sh_info] else: section.info = header.sh_info
def _initialise_sections(self, hdr, file_, prepare): """Initialise information from section headers.""" self._sh_offset = hdr.e_shoff self._sh_strndx = hdr.e_shstrndx self._sheaders = self._get_section_headers(hdr, file_) self.sections = [] if self._sh_offset == 0: return # Now create section objects for all of them for i, header in enumerate(self._sheaders): sect_cls = ELF_SECTION_TYPES.get(header.sh_type, UnpreparedElfSection) if header.sh_type != SHT_NOBITS: data = file_.get_data(header.sh_offset, header.sh_size) else: data = header.sh_size if sect_cls in [UnpreparedElfSymbolTable, UnpreparedElfReloc, UnpreparedElfReloca]: section = None # We handle symbol tables and relocs later else: section = sect_cls(self, None, header.sh_type, header.sh_addr, data, header.sh_flags, header.sh_addralign, header.sh_info) if prepare: section = section.prepare(header.sh_offset, i, header.sh_name) self.sections.append(section) # Now set up any links between sections and convert the info # field to the appropriate type. for section, header in zip(self.sections, self._sheaders): if section: if header.sh_link: section.link = self.sections[header.sh_link] if section.info_is_section(): section.info = self.sections[header.sh_info] else: section.info = header.sh_info
def _initialise_sections(self, hdr, f, prepare): """Initialise information from section headers.""" self._sh_offset = shoff = hdr.e_shoff self._sh_strndx = 0 self.sections = [] if shoff == 0: return # Create an array of section headers sheaders = self._get_section_headers(hdr, f) # Now create section objects for all of them for i, sh in enumerate(sheaders): sect_cls = ELF_SECTION_TYPES.get(sh.sh_type, UnpreparedElfSection) if sh.sh_type != SHT_NOBITS: data = f.get_data(sh.sh_offset, sh.sh_size) else: data = sh.sh_size es = sect_cls(None, sh.sh_type, sh.sh_addr, data, sh.sh_flags, sh.sh_addralign, sh.sh_entsize, sh.sh_info) if prepare: es = es.prepare(sh.sh_offset, i, sh.sh_name, self.wordsize, self.endianess) self.sections.append(es) # Find the section header string table if there is one if hdr.e_shstrndx != 0: self._sh_strndx = hdr.e_shstrndx strtable = self.sections[hdr.e_shstrndx] if strtable.type != SHT_STRTAB: raise ElfFormatError, "The section string table is malformed. %s %s" % (strtable, self.sections) assert strtable.__class__ == {True: PreparedElfStringTable, False: UnpreparedElfStringTable}[prepare] # Now update all the section names with the string for section, sh in zip(self.sections, sheaders): section._name = strtable.get_string_ofs(sh.sh_name) # Now set up any links between for section, sh in zip(self.sections, sheaders): if sh.sh_link: section.link = self.sections[sh.sh_link]