def write_physical_mem( self, phys_address, length, buf, bytewise=False ): if bytewise : width = 1 else : width = 8 ptr = 0 format = {1: 'B', 2: 'H', 4: 'L', 8:'Q'} while width >= 1 : while (length - ptr) >= width : v = struct.unpack_from(format[width], buf, ptr) self.base.threads[self.find_thread()].mem(itpii.Address((phys_address + ptr),itpii.AddressType.physical), width, v[0]) ptr += width width = width / 2 return
def read_physical_mem( self, phys_address, length, bytewise=False ): if bytewise : width = 1 else : width = 8 out_buf = (c_char * length)() ptr = 0 format = {1: 'B', 2: 'H', 4: 'L', 8:'Q'} while width >= 1 : while (length - ptr) >= width : v = self.base.threads[self.find_thread()].mem(itpii.Address((phys_address + ptr),itpii.AddressType.physical), width) struct.pack_into(format[width], out_buf, ptr, v.ToUInt64()) ptr += width width = width / 2 return ''.join(out_buf)
def write_physical_mem(self, phys_address, length, buf, bytewise=False): # write memory in largest chunks possible unless bytewise is set if bytewise: width = 1 else: # do we need to handle systems that don't support quad-word memory accesses? width = 8 ptr = 0 format = {1: 'B', 2: 'H', 4: 'L', 8: 'Q'} while width >= 1: while (length - ptr) >= width: v = struct.unpack_from(format[width], buf, ptr) #print "Writing", width, "bytes (", hex(v[0]), ") to", hex(phys_address + ptr) self.base.threads[self.find_thread()].mem( itpii.Address((phys_address + ptr), itpii.AddressType.physical), width, v[0]) ptr += width width = width / 2 return
def read_physical_mem(self, phys_address, length, bytewise=False): # read memory in largest chunks possible unless bytewise is set if bytewise: width = 1 else: # do we need to handle systems that don't support quad-word memory accesses? width = 8 out_buf = (c_char * length)() ptr = 0 format = {1: 'B', 2: 'H', 4: 'L', 8: 'Q'} while width >= 1: while (length - ptr) >= width: #print "Reading", width, "bytes from", hex(phys_address + ptr) v = self.base.threads[self.find_thread()].mem( itpii.Address((phys_address + ptr), itpii.AddressType.physical), width) struct.pack_into(format[width], out_buf, ptr, v.ToUInt64()) ptr += width width = width / 2 return ''.join(out_buf)