/
gt7racedata.py
93 lines (82 loc) · 2.65 KB
/
gt7racedata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import socket
import sys
import struct
# pip3 install salsa20
from salsa20 import Salsa20_xor
#https://github.com/Nenkai/PDTools/blob/master/SimulatorInterface/SimulatorInterface.cs
SendDelaySeconds = 10
ReceivePort = 33740
SendPort = 33739
port = ReceivePort
if len(sys.argv) == 2:
# Get "IP address of Server" and also the "port number" from
ip = sys.argv[1]
else:
print("Run like : python3 gt7racedata.py <playstation-ip>")
exit(1)
# Create a UDP socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Bind the socket to the port
server_address = ('0.0.0.0', port)
s.bind(server_address)
s.settimeout(10)
#https://github.com/Nenkai/PDTools/blob/master/PDTools.Crypto/SimulationInterface/SimulatorInterfaceCryptorGT7.cs
def salsa20_dec(dat):
KEY = b'Simulator Interface Packet GT7 ver 0.0'
oiv = dat[0x40:0x44]
iv1 = int.from_bytes(oiv, byteorder='little') # Seed IV is always located there
iv2 = iv1 ^ 0xDEADBEAF #// Notice DEADBEAF, not DEADBEEF
"""
print("OIV: %d bytes" % len(oiv))
print(' '.join(format(x, '02x') for x in oiv))
print("IV1: %d bytes" % len(iv1.to_bytes(4, 'big')))
print(' '.join(format(x, '02x') for x in iv1.to_bytes(4, 'big')))
print("IV2: %d bytes" % len(iv2.to_bytes(4, 'big')))
print(' '.join(format(x, '02x') for x in iv2.to_bytes(4, 'big')))
"""
IV = bytearray()
IV.extend(iv2.to_bytes(4, 'little'))
IV.extend(iv1.to_bytes(4, 'little'))
#print("IV: %d bytes" % len(IV))
#print(' '.join(format(x, '02x') for x in IV))
"""
// Magic should be "G7S0" when decrypted
SpanReader sr = new SpanReader(data);
int magic = sr.ReadInt32();
if (magic != 0x47375330) // 0S7G - G7S0
"""
ddata = Salsa20_xor(dat, bytes(IV), KEY[0:32])#.decode()
#check magic number
magic = int.from_bytes(ddata[0:4], byteorder='little')
if magic != 0x47375330:
return bytearray(b'')
return ddata
def send_hb(s):
#send HB
send_data = 'A'
s.sendto(send_data.encode('utf-8'), (ip, SendPort))
print('send heartbeat')
send_hb(s)
print("Ctrl+C to exit the program")
pknt = 0
while True:
try:
data, address = s.recvfrom(4096)
pknt = pknt + 1
print("received: %d bytes" % len(data))
#print(' '.join(format(x, '02x') for x in data))
ddata = salsa20_dec(data)
#print("decoded: %d bytes" % len(ddata))
#print(' '.join(format(x, '02x') for x in ddata))
if len(ddata) > 0:
#https://github.com/Nenkai/PDTools/blob/master/PDTools.SimulatorInterface/SimulatorPacketGT7.cs
#RPM: 15th 4byte ints
rpm = struct.unpack('f', ddata[15*4:15*4+4])
print('RPM %d' %(rpm))
if pknt > 100:
send_hb(s)
pknt = 0
except Exception as e:
send_hb(s)
pknt = 0
pass