def load_elf_binary(self, bprm): "load the program into virtual memory (populate the mmap dict)" p = Task(bprm, cpu) p.OS = self # create text and data segments according to elf header: for s in bprm.Phdr: if s.p_type == PT_INTERP: interp = bprm.readsegment(s).strip(b"\0") elif s.p_type == PT_LOAD: ms = bprm.loadsegment(s, self.PAGESIZE) if ms != None: vaddr, data = ms.popitem() p.state.mmap.write(vaddr, data) elif s.p_type == PT_GNU_STACK: # executable_stack = s.p_flags & PF_X pass # init task state: for r in cpu.regs: p.state[r] = cpu.cst(0, 32) entry = cpu.cst(p.bin.entrypoints[0], 32) p.setx(cpu.pc_, entry) # create the stack space: if self.ASLR: p.state.mmap.newzone(p.cpu.sp) else: stack_base = 0x7FFFFFFF & ~(self.PAGESIZE - 1) stack_size = 2 * self.PAGESIZE p.state.mmap.write(stack_base - stack_size, b"\0" * stack_size) p.state[cpu.sp] = cpu.cst(stack_base, 32) # create the dynamic segments: if bprm.dynamic and interp: self.load_elf_interp(p, interp) # start task: self.tasks.append(p) return p
def initenv(self): from amoco.cas.mapper import mapper m = mapper() for k,v in ((cpu.pc, cpu.cst(self.bin.entrypoints[0],32)), ): m[k] = v return m
def initenv(self): from amoco.cas.mapper import mapper m = mapper() for k,v in ((cpu.pc, cpu.cst(self.bin.entrypoints[0],32)), ): if v&1: # switch to Thumb mode if pc&1: self.cpu.internals['isetstate'] = 1 v = (v>>1)<<1 m[k] = v return m
def use_arm(self): from amoco.arch.arm import cpu_armv7 self.cpu = cpu_armv7 self.state[cpu_armv7.pc_] = cpu_armv7.cst(0,32)
def initenv(self): from amoco.cas.mapper import mapper m = mapper() for k, v in ((cpu.pc, cpu.cst(self.bin.entrypoints[0], 32)), ): m[k] = v return m