def __init__(self, path, backend): self.path = path self.backend = backend self.fileobj = open(path, 'rb') self.elf = elffile.open(fileobj=self.fileobj) self.linker = Linker(self) self.final_hook = [] self.asm_hook = [] self.c_hook = [] self.verbose = False autolink.declare(self.linker) start = 0xFFFFFFFFFFFFFFFF end = 0 # TODO: doesn't handle new mem being mapped or unmapped for ph in reversed(self.elf.progs): if ph.isload: start = min(start, ph.vaddr) end = max(ph.vaddr + ph.vsize, end) # add patch segment def new_segment(addr): align = 0x1000 ph = self.elf.programHeaderClass() ph.data = bytearray() ph.type = PT['PT_LOAD'].code ph.vaddr = (addr + align - 1) & ~(align - 1) ph.paddr = ph.vaddr # TODO: default is RWX?! ph.flags = 7 ph.align = align ph.memsz = 0 ph.filesz = 0 self.elf.progs.append(ph) return ph # RX self.code = new_segment(end) self.code.flags = 5 # RW self.data = new_segment(end + 0x800000) self.data.flags = 6 self.entry_hooks = [] self.arch = arch.create_arch(self, backend)
def __init__(self, path): self.path = path self.fileobj = open(path, 'rb') self.elf = elffile.open(fileobj=self.fileobj) self.linker = Linker(self) self.final_hook = [] self.asm_hook = [] self.c_hook = [] self.verbose = False autolink.declare(self.linker) start = 0xFFFFFFFFFFFFFFFF end = 0 # TODO: doesn't handle new mem being mapped or unmapped for ph in reversed(self.elf.progs): if elfutil.is_load(ph): start = min(start, ph.vaddr) end = max(ph.vaddr + ph.vsize, end) # add patch segment def new_segment(addr): align = 0x1000 ph = self.elf.programHeaderClass() ph.data = bytearray() ph.type = PT.byname['PT_LOAD'].code ph.vaddr = (addr + align - 1) & ~(align - 1) ph.paddr = ph.vaddr # TODO: default is RWX?! ph.flags = 7 ph.align = align ph.memsz = 0 ph.filesz = 0 self.elf.progs.append(ph) return ph self.patch = new_segment(end) self.nxpatch = new_segment(end + 0x800000) self.nxpatch.flags = 6 self.linkpatch = new_segment(end + 0x1600000) self.jitpatch = new_segment(end + 0x2400000) self.entry_hooks = []