-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecurity.cpp
More file actions
71 lines (56 loc) · 2.34 KB
/
Security.cpp
File metadata and controls
71 lines (56 loc) · 2.34 KB
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
#include <common/Common.hpp>
#include <game/net/RKNetController.hpp>
#include <game/net/packet/RKNetRoomPacket.hpp>
#include <game/net/packet/RKNetSelectPacket.hpp>
#include <wiimmfi/Security.hpp>
#include <ModSupport.hpp>
namespace Wiimmfi {
namespace Security {
// TODO rewrite with worldwide support
bool IsPacketSectionSizeValid(int section, u32 sectionSize) {
// Skip empty sections
if (sectionSize == 0)
return true;
// The check depends on each section
u32 destSize = RKNetController::packetBufferSizes[section];
switch (section) {
// For EVENT packets, ensure the size fits the buffer as it is variable
case RKNetRACEPacketHeader::EVENT:
return sectionSize <= destSize;
// For ROOM/SELECT packets, ensure the size matches one of the two possible values
case RKNetRACEPacketHeader::ROOM_SELECT:
return (sectionSize == sizeof(RKNetROOMPacket) || sectionSize == sizeof(RKNetSELECTPacket));
// For RACEDATA and ITEM packets, ensure the size is either half or the full buffer size
case RKNetRACEPacketHeader::RACEDATA:
case RKNetRACEPacketHeader::ITEM:
return (sectionSize == destSize / 2 || sectionSize == destSize);
// For all other sections, match exactly the default size
default:
return sectionSize == destSize;
}
}
// Code ported from WiiLink24's WFC patcher
bool ValidateRACEPacket(u32 aid, RKNetRACEPacketHeader* data, u32 dataLength) {
// Verify each section size is valid
// Do this separately as the sizes may be valid but may not add up
u32 expectedPacketSize = 0;
for (int i = 0; i < RKNetRACEPacketHeader::SECTION_COUNT; i++) {
expectedPacketSize += data->sizes[i];
if (!IsPacketSectionSizeValid(i, data->sizes[i]))
return false;
}
// Ensure the declared sizes match the cumulative size
if (dataLength < expectedPacketSize)
return false;
// Verify each section's data is valid
u8* packetData = (u8*)data;
for (int i = 0; i < RKNetRACEPacketHeader::SECTION_COUNT; i++) {
if (!ModSupport::IsPacketSectionDataValid(i, packetData, data->sizes[i]))
return false;
packetData += data->sizes[i];
}
// All checks passed, we're ready to go!
return true;
}
} // namespace Security
} // namespace Wiimmfi