pyduml.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:pyduml 作者: hdnes 项目源码 文件源码
def doSparkRc():
    f = open (str(firmware_file), "rb")
    data = f.read()
    f.close()

    send_duml_tcp(s, 0x02, 0x1b, 0x40, 0x00, 0x07, bytearray.fromhex(u'00 00 00 00 00 00 00 00 00'))

    packet_08 = bytearray.fromhex(u'00')
    packet_08 += struct.pack('<I', len(data))
    packet_08 += bytearray.fromhex(u'00 00 00 00 00 00 01 04')
    send_duml_tcp(s, 0x02, 0x1b, 0x40, 0x00, 0x08, packet_08)

    for i in range(0, int(len(data)//1000)):
        packet_09 = bytearray.fromhex(u'00')
        packet_09 += struct.pack('<I', i)
        packet_09 += struct.pack('<H', 1000)
        packet_09 += data[i * 1000:(i + 1) * 1000]
        send_duml_tcp(s, 0x02, 0x1b, 0x00, 0x00, 0x09, packet_09)

    i += 1
    remain = len(data) % 1000
    packet_09 = bytearray.fromhex(u'00')
    packet_09 += struct.pack('<I', i)
    packet_09 += struct.pack('<H', remain)
    packet_09 += data[i * 1000:]
    send_duml_tcp(s, 0x02, 0x1b, 0x00, 0x00, 0x09, packet_09)

    filehash = hashlib.md5()
    filehash.update(data)
    filehash = filehash.digest()
    packet_0a = bytearray.fromhex(u'00')
    packet_0a += filehash
    send_duml_tcp(s, 0x02, 0x1b, 0x40, 0x00, 0x0a, packet_0a)

# from comm_serial2pcap.py
# https://github.com/mefistotelis/phantom-firmware-tools/issues/25#issuecomment-306052129
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号