def init_and_prepare_from_file(self, file_): """This method initialise an ElfFile from a given File object.""" ident = ElfIdentification() ident.fromdata(file_.get_data(0, ident.get_size())) if file_.size() < ident.get_size(): self.wordsize = 0 self.sections = [] self.segments = [] return self.wordsize = ident.wordsize self.endianess = ident.endianess header_data = file_.get_data(0, ELF_HEADER_CLASSES[self.wordsize].size()) hdr = ELF_HEADER_CLASSES[self.wordsize]() hdr.fromdata(header_data) self._initialise_header_information(hdr) self._initialise_sections(hdr, file_) self._initialise_symbol_tables(file_) self._initialise_relocs(file_) self._initialise_section_names() self._initialise_segments(hdr, file_) # FIXME: Mothra bug2591 # This code removes any zero-sized sections. # Perhaps not the right place to do it, but works around linkder # scripts that generate zero-sized sections. Note this may only # be a problem due to stupid scatter-load handling. self.sections = [s for s in self.sections if s.get_size() or not s.name] for segment in self.segments: if segment.has_sections(): segment.sections = [s for s in segment.sections if s.get_size() or not s.name]
def init_and_prepare_from_file(self, f): """This method initialise an ElfFile from a given File object.""" ident = ElfIdentification() ident.fromdata(f.get_data(0, ident.get_size())) self.wordsize = ident.wordsize self.endianess = ident.endianess header_data = f.get_data(0, ELF_HEADER_CLASSES[self.wordsize].size()) hdr = ELF_HEADER_CLASSES[self.wordsize]() hdr.fromdata(header_data) self._initialise_header_information(hdr) self._initialise_sections(hdr, f) self._initialise_symbol_table(self.wordsize, self.endianess) self._initialise_segments(hdr, f) # FIXME: Mothra bug2591 # This code removes any zero-sized sections. # Perhaps not the right place to do it, but works around linkder # scripts that generate zero-sized sections. Note this may only # be a problem due to stupid scatter-load handling. self.sections = [ s for s in self.sections if s.get_size() or not s.name ] for segment in self.segments: if segment.has_sections(): segment.sections = [ s for s in segment.sections if s.get_size() or not s.name ]
def test_get_size(self): self.assertEqual(ElfIdentification.get_size(), 16)
def test_get_size(self): self.assertEqual(ElfIdentification.get_size(), 16)