예제 #1
0
import enum
import os
import pathlib
import socket
import openocd
import shutil

serial ='13678/00110029'
KM=0

def word2bytes(word):
 result=[(word)&0xff,(word>>8)&0xff,(word>>16)&0xff,(word>>24)&0xff]
 return bytes(result)
 
if __name__ == '__main__':
 oocd = openocd.OpenOcd('localhost', 6666)

 try:
  oocd.connect()
 except Exception as e:
  sys.exit('Failed to connect to OpenOCD')
 shutil.copy('data.bin','data_temp.bin')
 scooter_data=open('data_temp.bin','r+b')
 # Disable RDP
 sys.stdout.write('unsecuring device...\n')
 sys.stdout.flush()
 oocd.send('init')
 oocd.send('reset halt')
 oocd.send('stm32f1x unlock 0')
 oocd.send('reset')
 sys.stdout.write('done\n')
    bits = []
    for i in range(0, len(xored)):
        nibble = xored[::-1][i] - b'0'[0]
        if nibble != 0:
            for bit in range(0, 4):
                if nibble & (1 << bit):
                    bits.append((i * 4) + bit)
    return bits


if __name__ == "__main__":
    bsdl = BsdlJson(sys.argv[1])

    # ocd_process = subprocess.run(["openocd", "-f", "board/digilent_analog_discovery.cfg"])

    with openocd.OpenOcd() as ocd:
        ocd.send("irscan xc6s.tap {}".format(bsdl.sample_opcode))
        original_data = ocd.send("drscan xc6s.tap {} 0".format(
            bsdl.boundary_length))

    input("Press enter to capture again.")

    with openocd.OpenOcd() as ocd:
        ocd.send("irscan xc6s.tap {}".format(bsdl.sample_opcode))
        new_data = ocd.send("drscan xc6s.tap {} 0".format(
            bsdl.boundary_length))

    difference = xor(original_data, new_data)
    bits = find_bits(difference)

    for bit in bits: