def __process_PLMInfo(self, responseBytes): (modemCommand, idHigh, idMid, idLow, deviceCat, deviceSubCat, firmwareVer, acknak) = struct.unpack('xBBBBBBBB', responseBytes) foundCommandHash = None #find our pending command in the list so we can say that we're done (if we are running in syncronous mode - if not well then the caller didn't care) for (commandHash, commandDetails) in self.__pendingCommandDetails.items(): if binascii.unhexlify( commandDetails['modemCommand']) == chr(modemCommand): #Looks like this is our command. Lets deal with it. self.__commandReturnData[commandHash] = { 'id': _byteIdToStringId(idHigh, idMid, idLow), 'deviceCategory': '%02X' % deviceCat, 'deviceSubCategory': '%02X' % deviceSubCat, 'firmwareVersion': '%02X' % firmwareVer } waitEvent = commandDetails['waitEvent'] waitEvent.set() foundCommandHash = commandHash break if foundCommandHash: del self.__pendingCommandDetails[foundCommandHash] else: print "Unable to find pending command details for the following packet:" print utilities.hex_dump(responseBytes, len(responseBytes))
def send(self, dataString): try: data = binascii.unhexlify(dataString) print "Sending: " print utilities.hex_dump(data, len(data)) self.__ftdiDevice.write_data(data) except: pass
def run(self): self._interfaceRunningEvent.set() while not self._shutdownEvent.isSet(): try: readBytes = self.__ftdiDevice.read_data(1024) if len(readBytes) > 0: print "Received: " print utilities.hex_dump(readBytes, len(readBytes)) self.c(readBytes) else: time.sleep(0.5) except Exception, ex: print ex pass
def __process_PLMInfo(self, responseBytes): (modemCommand, idHigh, idMid, idLow, deviceCat, deviceSubCat, firmwareVer, acknak) = struct.unpack('xBBBBBBBB', responseBytes) foundCommandHash = None #find our pending command in the list so we can say that we're done (if we are running in syncronous mode - if not well then the caller didn't care) for (commandHash, commandDetails) in self.__pendingCommandDetails.items(): if binascii.unhexlify(commandDetails['modemCommand']) == chr(modemCommand): #Looks like this is our command. Lets deal with it. self.__commandReturnData[commandHash] = { 'id': _byteIdToStringId(idHigh,idMid,idLow), 'deviceCategory': '%02X' % deviceCat, 'deviceSubCategory': '%02X' % deviceSubCat, 'firmwareVersion': '%02X' % firmwareVer } waitEvent = commandDetails['waitEvent'] waitEvent.set() foundCommandHash = commandHash break if foundCommandHash: del self.__pendingCommandDetails[foundCommandHash] else: print "Unable to find pending command details for the following packet:" print utilities.hex_dump(responseBytes, len(responseBytes))
def run(self): self.__interfaceRunningEvent.set(); #for checking for duplicate messages received in a row lastPacketHash = None while not self.__shutdownEvent.isSet(): #check to see if there are any outbound messages to deal with self.__commandLock.acquire() if (len(self.__outboundQueue) > 0) and (time.time() - self.__lastSendTime > self.__intersend_delay): commandHash = self.__outboundQueue.popleft() commandExecutionDetails = self.__outboundCommandDetails[commandHash] bytesToSend = commandExecutionDetails['bytesToSend'] print "> ", utilities.hex_dump(bytesToSend, len(bytesToSend)), self.__serialDevice.write(bytesToSend) self.__pendingCommandDetails[commandHash] = commandExecutionDetails del self.__outboundCommandDetails[commandHash] self.__lastSendTime = time.time() self.__commandLock.release() #check to see if there is anyting we need to read firstByte = self.__serialDevice.read(1) if len(firstByte) == 1: #got at least one byte. Check to see what kind of byte it is (helps us sort out how many bytes we need to read now) if firstByte[0] == '\x02': #modem command (could be an echo or a response) #read another byte to sort that out secondByte = self.__serialDevice.read(1) responseSize = -1 callBack = None modemCommand = binascii.hexlify(secondByte).upper() if self.__modemCommands.has_key(modemCommand): if self.__modemCommands[modemCommand].has_key('responseSize'): responseSize = self.__modemCommands[modemCommand]['responseSize'] if self.__modemCommands[modemCommand].has_key('callBack'): callBack = self.__modemCommands[modemCommand]['callBack'] if responseSize != -1: remainingBytes = self.__serialDevice.read(responseSize) print "< ", print utilities.hex_dump(firstByte + secondByte + remainingBytes, len(firstByte + secondByte + remainingBytes)), currentPacketHash = hashPacket(firstByte + secondByte + remainingBytes) if lastPacketHash and lastPacketHash == currentPacketHash: #duplicate packet. Ignore pass else: if callBack: callBack(firstByte + secondByte + remainingBytes) else: print "No callBack defined for for modem command %s" % modemCommand lastPacketHash = currentPacketHash else: print "No responseSize defined for modem command %s" % modemCommand elif firstByte[0] == '\x15': print "Received a Modem NAK!" else: print "Unknown first byte %s" % binascii.hexlify(firstByte[0]) else: #print "Sleeping" time.sleep(0.1) self.__interfaceRunningEvent.clear()
def run(self): self.__interfaceRunningEvent.set() #for checking for duplicate messages received in a row lastPacketHash = None while not self.__shutdownEvent.isSet(): #check to see if there are any outbound messages to deal with self.__commandLock.acquire() if (len(self.__outboundQueue) > 0) and (time.time() - self.__lastSendTime > self.__intersend_delay): commandHash = self.__outboundQueue.popleft() commandExecutionDetails = self.__outboundCommandDetails[ commandHash] bytesToSend = commandExecutionDetails['bytesToSend'] print "> ", utilities.hex_dump(bytesToSend, len(bytesToSend)), self.__serialDevice.write(bytesToSend) self.__pendingCommandDetails[ commandHash] = commandExecutionDetails del self.__outboundCommandDetails[commandHash] self.__lastSendTime = time.time() self.__commandLock.release() #check to see if there is anyting we need to read firstByte = self.__serialDevice.read(1) if len(firstByte) == 1: #got at least one byte. Check to see what kind of byte it is (helps us sort out how many bytes we need to read now) if firstByte[0] == '\x02': #modem command (could be an echo or a response) #read another byte to sort that out secondByte = self.__serialDevice.read(1) responseSize = -1 callBack = None modemCommand = binascii.hexlify(secondByte).upper() if self.__modemCommands.has_key(modemCommand): if self.__modemCommands[modemCommand].has_key( 'responseSize'): responseSize = self.__modemCommands[modemCommand][ 'responseSize'] if self.__modemCommands[modemCommand].has_key( 'callBack'): callBack = self.__modemCommands[modemCommand][ 'callBack'] if responseSize != -1: remainingBytes = self.__serialDevice.read(responseSize) print "< ", print utilities.hex_dump( firstByte + secondByte + remainingBytes, len(firstByte + secondByte + remainingBytes)), currentPacketHash = hashPacket(firstByte + secondByte + remainingBytes) if lastPacketHash and lastPacketHash == currentPacketHash: #duplicate packet. Ignore pass else: if callBack: callBack(firstByte + secondByte + remainingBytes) else: print "No callBack defined for for modem command %s" % modemCommand lastPacketHash = currentPacketHash else: print "No responseSize defined for modem command %s" % modemCommand elif firstByte[0] == '\x15': print "Received a Modem NAK!" else: print "Unknown first byte %s" % binascii.hexlify( firstByte[0]) else: #print "Sleeping" time.sleep(0.1) self.__interfaceRunningEvent.clear()
raw_address, raw_length = arg.split(',') address = int(raw_address, 16) if raw_address.startswith('0x') else int( raw_address, 10) length = int(raw_length, 16) if raw_length.startswith('0x') else int( raw_length, 10) device = dfu.acquire_device() serial_number = device.serial_number dfu.release_device(device) if 'PWND:[checkm8]' in serial_number: device = usbexec.PwnedUSBDevice() dump = device.read_memory(address, length) for line in utilities.hex_dump(dump, address).splitlines(): print '%x: %s' % (address, line[10:]) address += 16 else: device = PwnedDFUDevice() dump = device.read_memory(address, length) print utilities.hex_dump(dump, address), if opt == '--dump-rom': device = dfu.acquire_device() serial_number = device.serial_number dfu.release_device(device) if 'PWND:[checkm8]' in serial_number: pwned = usbexec.PwnedUSBDevice() securerom = pwned.read_memory(pwned.platform.rom_base,