示例#1
0
文件: leon2.py 项目: jiandandan/amoco
 def initenv(self):
     from amoco.cas.mapper import mapper
     m = mapper()
     e = self.bin.entrypoints[0]
     for k, v in ((cpu.pc, cpu.cst(e, 32)), (cpu.npc, cpu.cst(e + 4, 32)),
                  (cpu.sp, cpu.cst(0xc0000000,
                                   32)), (cpu.fp, cpu.cst(0xc0000000, 32))):
         m[k] = v
     return m
示例#2
0
文件: leon2.py 项目: zachriggle/amoco
 def initenv(self):
     from amoco.cas.mapper import mapper
     m = mapper()
     e = self.bin.entrypoints[0]
     for k,v in ((cpu.pc , cpu.cst(e,32)),
                 (cpu.npc, cpu.cst(e+4,32)),
                 (cpu.sp , cpu.cst(0xc0000000,32)),
                 (cpu.fp , cpu.cst(0xc0000000,32))):
         m[k] = v
     return m
示例#3
0
文件: leon2.py 项目: zytMatrix/amoco
 def load_binary(self):
     p = self.bin
     if p!=None:
         # create text and data segments according to elf header:
         for s in p.Phdr:
           ms = p.loadsegment(s,PAGESIZE)
           if ms!=None:
               vaddr,data = list(ms.items())[0]
               self.state.mmap.write(vaddr,data)
     # create the stack zone:
     self.state.mmap.newzone(cpu.sp)
     e = self.bin.entrypoints[0]
     for k,v in ((cpu.pc , cpu.cst(e,32)),
                 (cpu.npc, cpu.cst(e+4,32)),
                 (cpu.sp , cpu.cst(0xc0000000,32)),
                 (cpu.fp , cpu.cst(0xc0000000,32))):
         self.state[k] = v
示例#4
0
 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 registers:
     e = p.bin.entrypoints[0]
     p.state[cpu.pc] = cpu.cst(e, 32)
     p.state[cpu.npc] = cpu.cst(e + 4, 32)
     for r in cpu.r:
         p.state[r] = cpu.cst(0, r.size)
     # create the stack space:
     if self.ASLR:
         p.state.mmap.newzone(p.cpu.esp)
     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)
         p.state[cpu.fp] = cpu.cst(stack_base, 32)
     # create the dynamic segments:
     if bprm.dynamic and interp:
         self.load_elf_interp(p)
     # start task:
     self.tasks.append(p)
     return p