def read(reader, transfer): #Responsible for preventing endless rx thread loop LoopControl = True while (LoopControl): try: data = reader.Read() if (len(data) > 0): for index in range(0, len(data)): item = data[index] print('D+{0} = {1}'.format(index, Byte(item))) if (len(data) > 1): transfer.Write([0x06]) LoopControl = False except BadPacketReadError as err: print("Error Bytes") bytes = err.getArrayBytes() for index in range(0, len(bytes)): item = bytes[index] print('D+{0} = {1}\n'.format(index, Byte(item))) print err if (LoopControl == False): reader.__del__()
def read(reader, transfer): global ResultFrame packetObject = NextPointInformationTest() packetObject.createPointInformationPacket() while (True): try: data = reader.Read() if (len(data) > 0): for index in range(0, len(data)): item = data[index] print('D+{0} = {1}'.format(index, Byte(item))) if (len(data) > 1): transfer.Write([0x06]) ResultFrame = ResultFrame.format(data) #format data clientID = ResultFrame.packet.content.getParameter( "clientID") #get contentparam from packet ResultFrame = LocalFrameFormatter() #create new FrameFormatter instance packetObject.sendNextPointInformationPacket(clientID) #send nextpoint with client id of point reply except BadPacketReadError as err: print("Error Bytes") bytes = err.getArrayBytes() for index in range(0, len(bytes)): item = bytes[index] print('D+{0} = {1}\n'.format(index, Byte(item))) print err
def read(reader, transfer): #Responsible for preventing endless rx thread loop LoopControl = True strVar = "" while (LoopControl): data = reader.Read() if (len(data) == 1): if (data[0] == 0x06): #time.sleep(0.5); data = reader.Read() if (len(data) == 0): LoopControl = False if (len(data) > 1): transfer.Write([0x06]) for index in range(0, len(data)): item = data[index] strVar += str(Byte(item)) + ',' LoopControl = False if (LoopControl == False): reader.Stop() print(strVar) if (reader.IsRunning() == False): reader.__del__()
def generate_key(salt=None, message='', iteration_count=1): if salt is None: salt = PBKD.get_salt() result = PBKD.HMAC(salt, message) for i in range(iteration_count - 1): temp = PBKD.HMAC(result, message) result = Byte.xor(result, temp) return result
def size_parser(path_elf, path_size='size'): import re regex = r'^(\.\S+)\s*(\d+)' size = path_size.split() result = subprocess.run( [size[0], *size[1:], '-A', str(path_elf)], stdout=subprocess.PIPE, ).stdout.decode('utf-8') return { match.group(1): Byte(match.group(2)) for match in re.finditer(regex, result, re.MULTILINE) }
def size_parser(path): result = subprocess.run(['arm-none-eabi-size', path], stdout=subprocess.PIPE) result = result.stdout.decode('utf-8') head, data = result.strip().split('\n') def parse_size_table(data): return list(map(methodcaller('strip'), data.split()))[:-2] head = parse_size_table(head) data = parse_size_table(data) size = dict() for i, name in enumerate(head): size[name] = Byte(data[i]) return size
def linker_script_parser(path): with open(path, 'r') as fr: script = fr.readlines() memory_flag = False memory = dict() for line in script: if 'MEMORY' in line: memory_flag = True elif memory_flag: if '}' in line: break elif 'LENGTH' in line: name = line.strip().split(':')[0].strip().split()[0].strip() length = Byte(line.strip().split(':')[1].strip().split(',') [1].split('=')[1]) memory[name] = length return memory
def read(reader, nPackets): reader.Wait() status = False count = 0 while (reader.IsRunning()): try: data = reader.Read() if (len(data) > 0): for index in range(0, len(data)): item = data[index] print('D+{0} = {1}\n'.format(index, Byte(item))) if (nPackets == count): reader.Stop() count = 0 count = count + 1 except BadPacketReadError as err: print err return status
def decrypt(message, key, _base64=True): salt = Byte.hex_to_byte("633f7b241f16d678c20f84e92d9197f1") generated_key = PBKD.generate_key(''.join([chr(c) for c in salt]), key, 2) # set key key_iv = generated_key[0:16] # set IV key_iv += "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" hc = hc128() hc.set_key([ord(c) for c in key_iv]) if _base64: message = base64.b64decode(message) _input = [ord(c) for c in message] _output = [] for _in in _input: _output.append(hc.crypt(_in)) _output = ''.join([chr(c) for c in _output]) return _output
def __get_salt(): return Byte.hex_to_byte("633f7b241f16d678c20f84e92d9197f1")
def __init__(self, flash, ram, eeprom): self.flash = Byte(flash) self.ram = Byte(ram) self.eeprom = Byte(eeprom) self.avrdude = None self.define = None