def salsa20_dec(dat):
KEY = b'Simulator Interface Packet GT7 ver 0.0'
# Seed IV is always located here
oiv = dat[0x40:0x44]
iv1 = int.from_bytes(oiv, byteorder='little')
# Notice DEADBEAF, not DEADBEEF
iv2 = iv1 ^ 0xDEADBEAF
IV = bytearray()
IV.extend(iv2.to_bytes(4, 'little'))
IV.extend(iv1.to_bytes(4, 'little'))
#ddata = salsa20_xor(dat, bytes(IV), KEY[0:32])
ddata = salsa20_xor(KEY[0:32],bytes(IV),dat)
magic = int.from_bytes(ddata[0:4], byteorder='little')
if magic != 0x47375330:
return bytearray(b'')
return ddata