def patch(self, addr, size, value, offset=0): """Record the details of a patch to a segment.""" if self.elf.machine == ElfMachine(8): if self.elf.flags & EF_MIPS_ABI_O64: if addr & 0x80000000: addr |= 0xffffffff00000000L self.patches.append(self.Patch(addr, size, value, offset))
def get_value(self, address, size, endianess=None): """get a value from an elf file.""" if self.machine == ElfMachine(8): if self.flags & EF_MIPS_ABI_O64: if address & 0x80000000: address |= 0xffffffff00000000L for segment in self.segments: if not segment.has_sections(): continue for section in segment.get_sections(): if address >= section.address and \ address < (section.address + section.get_size()): offset = address - section.address if endianess is None: endianess = self.endianess return section.get_data().get_data(offset, size, endianess) return None
def __init__(self, elf, section): """ Create a new root server section. This is not normally called directly, as rootserver instances usually are created first as ELfSection objects and then transformed. """ self._section = section self._cellinit = None self._format_str = None if section.wordsize == 32 and not \ (elf.machine == ElfMachine(8) and elf.flags & EF_MIPS_ABI_O64): self._wordsize = 32 self._format_str = "I" else: self._wordsize = 64 self._format_str = "Q" self._format_str = section.endianess + self._format_str
def fromdata(self, data, ehdr): """Initialise an ElfHeader object from provided data""" if len(data) != self.size(): raise ElfFormatError, "Data size must be %s. %s provided." % \ (self.size(), len(data)) fields = struct.unpack(self.endianess + self.layout, data) self.p_type = fields[0] self.p_offset = fields[1] vaddr = fields[2] if ehdr.e_machine == ElfMachine(8): if ehdr.e_flags & EF_MIPS_ABI_O64: if vaddr & 0x80000000: vaddr |= 0xffffffff00000000L self.p_vaddr = vaddr self.p_paddr = fields[3] self.p_filesz = fields[4] self.p_memsz = fields[5] self.p_flags = fields[6] self.p_align = fields[7]
def _set_machine(self, machine): """Set the machine architecture.""" assert is_integer(machine) self._e_machine = ElfMachine(machine)
def __init__(self, elf, section): """ Section containing elfweaver attributes """ self._section = section self._format_str = None self.attributes = None self.utcb_size = 0 self.arch_max_spaces = 0 self.valid_page_perms = 0 self.arch_cache_perms = None if elf.wordsize == 32 and not \ (elf.machine == ElfMachine(8) and elf.flags & EF_MIPS_ABI_O64): self._wordsize = 32 self._format_str = "12B12I22H" else: self._wordsize = 64 self._format_str = "12B12Q22H" self._format_str = elf.endianess + self._format_str # print "%s %s" % (len(self._format_str), len(self._section._data)) default, cached, uncached, writeback, writethrough, coherent, device, \ writecombining, strong, _, _, _, self.utcb_size, self.arch_max_spaces, \ self.valid_page_perms, \ self.clist_size, self.cap_size, self.space_size, \ self.tcb_size, self.mutex_size, self.segment_list_size, \ self.small_object_blocksize, self.kmem_chunksize, \ self.pgtable_top_size, \ uncached_mask, uncached_comp, \ cached_mask, cached_comp, \ iomemory_mask, iomemory_comp, \ iomemoryshared_mask, iomemoryshared_comp, \ writethrough_mask, writethrough_comp, \ writeback_mask, writeback_comp, \ shared_mask, shared_comp, \ nonshared_mask, nonshared_comp, \ custom_mask, custom_comp, \ strong_mask, strong_comp, \ buffered_mask, buffered_comp \ = struct.unpack(self._format_str, self._section._data) self.arch_cache_perms = { 'uncached': (uncached_mask, uncached_comp), 'cached': (cached_mask, cached_comp), 'iomemory': (iomemory_mask, iomemory_comp), 'iomemoryshared': (iomemoryshared_mask, iomemoryshared_comp), 'writethrough': (writethrough_mask, writethrough_comp), 'writeback': (writeback_mask, writeback_comp), 'shared': (shared_mask, shared_comp), 'nonshared': (nonshared_mask, nonshared_comp), 'custom': (custom_mask, custom_comp), 'strong': (strong_mask, strong_comp), 'buffered': (buffered_mask, buffered_comp) } self.attributes = [('default', default), ('cached', cached), ('uncached', uncached), ('writeback', writeback), ('writethrough', writethrough), ('coherent', coherent), ('device', device), ('writecombining', writecombining), ('strong', strong)]