diff options
author | jaseg <git@jaseg.net> | 2018-11-08 19:01:10 +0900 |
---|---|---|
committer | jaseg <git@jaseg.net> | 2018-11-08 19:01:10 +0900 |
commit | e4e231880413c58215130c4b084ac49a03c16b9b (patch) | |
tree | 1ba6c1684499b7405a90b58a34dfd4a1a36b654b /hexnoise.py | |
parent | 333d94bf9f1b4e4c83a125342dd20fea62589057 (diff) | |
download | secure-hid-e4e231880413c58215130c4b084ac49a03c16b9b.tar.gz secure-hid-e4e231880413c58215130c4b084ac49a03c16b9b.tar.bz2 secure-hid-e4e231880413c58215130c4b084ac49a03c16b9b.zip |
Break out noise.c and packet_interface.c
Diffstat (limited to 'hexnoise.py')
-rwxr-xr-x | hexnoise.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/hexnoise.py b/hexnoise.py index b092bb3..e8a3d73 100755 --- a/hexnoise.py +++ b/hexnoise.py @@ -9,12 +9,12 @@ def _print_line(write, ts, line, width=16): h,m,s,ms = int(ts//3600), int((ts//60)%60), int(ts%60), int((ts%1.0) * 1000) timestamp = f'{h: 3d}:{m:02d}:{s:02d}:{ms:03d}' line = list(line) + [None]*(width-len(line)) - hexcol = '\033[94m' + hexcol = '\033[0m' col = lambda b, s: s if b != 0 else f'\033[91m{s}{hexcol}' hexfmt = ' '.join( ' '.join(col(b, f'{b:02x}') if b is not None else ' ' for b in line[i*8:i*8+8]) for i in range(1 + (len(line)-1)//8)) - asciifmt = ''.join(chr(c) if c is not None and chr(c) in string.printable else '.' for c in line) + asciifmt = ''.join(chr(c) if c is not None and chr(c) in string.printable and c>=0x20 else '.' for c in line) write(f'\033[38;5;244m{timestamp} {hexcol}{hexfmt} \033[38;5;244m|\033[92m{asciifmt}\033[38;5;244m|\033[0m', flush=True, end='') startup = time.time() @@ -29,9 +29,9 @@ def hexdump(write, packet, width=16): write() def send_packet(ser, data, width=16): - encoded = cobs.encode(data) + b'\0' print(f'\033[93mSending {len(data)} bytes\033[0m') - hexdump(print, encoded, width) + hexdump(print, data, width) + encoded = cobs.encode(data) + b'\0' ser.write(encoded) ser.flushOutput() @@ -67,7 +67,7 @@ if __name__ == '__main__': proto.set_as_initiator() proto.set_keypair_from_private_bytes(Keypair.STATIC, STATIC_LOCAL) proto.start_handshake() - print('\033[91mHandshake started\033[0m') + print('Handshake started') while True: if proto.handshake_finished: |