Пример #1
0
 def load_elf_binary(self, bprm):
     "load the program into virtual memory (populate the mmap dict)"
     p = Task(bprm, cpu)
     p.OS = self
     self.tasks.append(p)
     # 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.mmap.write(vaddr, data)
         elif s.p_type == PT_GNU_STACK:
             executable_stack = s.p_flags & PF_X
     # init task state:
     p.state = p.initstate()
     p.state[cpu.pc] = cpu.cst(p.bin.entrypoints[0], 64)
     for r in cpu.Xregs:
         p.state[r] = cst(0, 64)
     p.state[cpu.pstate] = cst(0, 64)
     # create the stack space:
     if self.ASLR:
         p.mmap.newzone(p.cpu.rsp)
     else:
         stack_base = (0x00007fffffffffff & ~(self.PAGESIZE - 1))
         stack_size = 2 * self.PAGESIZE
         p.mmap.write(stack_base - stack_size, b'\0' * stack_size)
         p.state[cpu.sp] = cpu.cst(stack_base, 64)
     # create the dynamic segments:
     if bprm.dynamic and interp:
         self.load_elf_interp(p, interp)
     # return task:
     return p
Пример #2
0
 def initenv(self):
     from amoco.cas.mapper import mapper
     m = mapper()
     for k,v in ((cpu.pc, cpu.cst(self.bin.entrypoints[0],64)),
                ):
         m[k] = v
     return m