This repository has been archived by the owner on Dec 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
race-packet-validation.s
90 lines (79 loc) · 1.82 KB
/
race-packet-validation.s
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
# Checks the section sizes of incoming RACE packets are valid, and ignores it if not
# This should act as an antifreeze for some freeze codes and also as RCE protection
# for the same exploit as https://mkwii.com/showthread.php?tid=1543
# See http://wiki.tockdom.com/wiki/MKWii_Network_Protocol#Main_records_.28.22RACE.22_records.29
#=================#
# C2 #
#=================#
# 806555FC NTSC-U #
# 806590F0 NTSC-J #
# 80659a84 PAL #
# 80647D9C NTSC-K #
#=================#
# r3 RKnetController ptr
# r4 aid
# r5 packet ptr
# r6 size
# HEADER Record
lbz r9, 8(r5)
cmpwi r9, 0x10
bnelr-
# RACEHEADER_1 Record
lbz r9, 9(r5)
cmpwi r9, 0
beq- loc_valid_RACEHEADER_1_record
cmplwi r9, 0x28
bnelr-
loc_valid_RACEHEADER_1_record:
# RACEHEADER_2 Record
lbz r10, 0xA(r5)
cmpwi r10, 0
beq- loc_valid_RACEHEADER_2_record
cmplwi r10, 0x28
bnelr-
loc_valid_RACEHEADER_2_record:
# ROOM / SELECT Record
lbz r8, 0xB(r5)
andi. r7, r8, 0xFB
beq+ loc_valid_ROOM_SELECT_record
cmplwi r8, 0x38
bnelr-
loc_valid_ROOM_SELECT_record:
# RACEDATA Record
lbz r7, 0xC(r5)
andi. r11, r7, 0x7F
beq- loc_valid_RACEDATA_record
cmplwi r7, 0x40
bnelr-
loc_valid_RACEDATA_record:
# USER Record
lbz r11, 0xD(r5)
cmpwi r11, 0
beq+ loc_valid_USER_record
cmplwi r11, 0xC0
bnelr-
add r9, r5, r9
add r9, r9, r10
add r9, r9, r8
add r9, r9, r7
lhz r9, 0x14(r9)
cmpwi r9, 2
bnelr-
loc_valid_USER_record:
# ITEM Record
lbz r9, 0xE(r5)
andi. r10, r9, 0xEF
beq- loc_valid_ITEM_record
cmplwi r9, 8
bnelr-
loc_valid_ITEM_record:
# EVENT Record
lbz r9, 0xF(r5)
cmpwi r9, 0
beq- loc_valid_EVENT_record
addi r9, r9, -0x18
clrlwi r9, r9, 24
cmplwi r9, 0xE0
bgtlr-
loc_valid_EVENT_record:
stwu r1, -0x30(r1)