Package envi :: Package archs :: Package amd64
[hide private]
[frames] | no frames]

Source Code for Package envi.archs.amd64

 1  """
 
 2  The envi architecuture module for the AMD 64 platform.
 
 3  """ 
 4  import envi 
 5  import envi.bits as e_bits 
 6  import envi.registers as e_reg 
 7  import envi.archs.i386 as e_i386 
 8  
 
 9  from envi.archs.amd64.regs import * 
10  from envi.archs.amd64.disasm import * 
11  
 
12  # NOTE: The REX prefixes don't end up with displayed names
 
13  # NOTE: the REX prefix must be the *last* non escape (0f) prefix
 
14  
 
15  # EMU NOTES:
 
16  # In 64 bit mode, all 32 bit dest regs get 0 extended into the rest of the bits
 
17  # In 64 bit mode, all 8/16 bit accesses do NOT modify the upper bits
 
18  # In 64 bit mode, all near branches, and implicit RSP (push pop) use RIP even w/o REX
 
19  # In 64 bit mode, if mod/rm is mod=0 and r/m is 5, it's RIP relative IMM32
 
20  
 
21 -class Amd64Module(e_i386.i386Module):
22
23 - def __init__(self):
24 envi.ArchitectureModule.__init__(self, "amd64") 25 self._arch_dis = Amd64Disasm()
26
27 - def getEmulator(self):
28 return Amd64Emulator()
29
30 - def getPointerSize(self):
31 return 8
32
33 - def pointerString(self, va):
34 return "0x%.8x" % va
35
36 - def archGetRegCtx(self):
38
39 -class Amd64Call(envi.CallingConvention):
40
41 - def getCallArgs(self, emu, count):
42 ret = [] 43 if count == 0: return ret 44 ret.append(emu.getRegister(REG_RCX)) 45 if count == 1: return ret 46 ret.append(emu.getRegister(REG_RDX)) 47 if count == 2: return ret 48 ret.append(emu.getRegister(REG_R8)) 49 if count == 3: return ret 50 ret.append(emu.getRegister(REG_R9)) 51 if count == 4: return ret 52 rsp = emu.getStackCounter() 53 stargs = emu.readMemoryFormat(rsp, "<12Q") 54 ret.extend(stargs[4:]) 55 return ret[:count]
56
57 - def setReturnValue(self, emu, value, argc):
62 63 amd64call = Amd64Call() 64
65 -class Amd64Emulator(Amd64RegisterContext, e_i386.IntelEmulator):
66 - def __init__(self):
67 e_i386.IntelEmulator.__init__(self) 68 # The above sets up the intel reg context, so we smash over it 69 Amd64RegisterContext.__init__(self) 70 # For the format calls in reading memory 71 self.imem_psize = 8 72 self.addCallingConvention("amd64call", amd64call)
73