TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Warden.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef _WARDEN_BASE_H
20 #define _WARDEN_BASE_H
21 
22 #include <map>
23 #include "Cryptography/ARC4.h"
24 #include "Cryptography/BigNumber.h"
25 #include "ByteBuffer.h"
26 #include "WardenCheckMgr.h"
27 
29 {
30  // Client->Server
34  WARDEN_CMSG_MEM_CHECKS_RESULT = 3, // only sent if MEM_CHECK bytes doesn't match
36  WARDEN_CMSG_MODULE_FAILED = 5, // this is sent when client failed to load uploaded module due to cache fail
37 
38  // Server->Client
43  WARDEN_SMSG_MEM_CHECKS_REQUEST = 4, // byte len; while (!EOF) { byte unk(1); byte index(++); string module(can be 0); int offset; byte len; byte[] bytes_to_compare[len]; }
45 };
46 
48 {
49  MEM_CHECK = 0xF3, // 243: byte moduleNameIndex + uint Offset + byte Len (check to ensure memory isn't modified)
50  PAGE_CHECK_A = 0xB2, // 178: uint Seed + byte[20] SHA1 + uint Addr + byte Len (scans all pages for specified hash)
51  PAGE_CHECK_B = 0xBF, // 191: uint Seed + byte[20] SHA1 + uint Addr + byte Len (scans only pages starts with MZ+PE headers for specified hash)
52  MPQ_CHECK = 0x98, // 152: byte fileNameIndex (check to ensure MPQ file isn't modified)
53  LUA_STR_CHECK = 0x8B, // 139: byte luaNameIndex (check to ensure LUA string isn't used)
54  DRIVER_CHECK = 0x71, // 113: uint Seed + byte[20] SHA1 + byte driverNameIndex (check to ensure driver isn't loaded)
55  TIMING_CHECK = 0x57, // 87: empty (check to ensure GetTickCount() isn't detoured)
56  PROC_CHECK = 0x7E, // 126: uint Seed + byte[20] SHA1 + byte moluleNameIndex + byte procNameIndex + uint Offset + byte Len (check to ensure proc isn't detoured)
57  MODULE_CHECK = 0xD9 // 217: uint Seed + byte[20] SHA1 (check to ensure module isn't injected)
58 };
59 
60 #pragma pack(push, 1)
61 
63 {
68 };
69 
71 {
74  uint8 Data[500];
75 };
76 
78 {
80  uint8 Seed[16];
81 };
82 
83 #pragma pack(pop)
84 
86 {
87  uint8 Id[16];
88  uint8 Key[16];
91 };
92 
93 class WorldSession;
94 
96 {
97  friend class WardenWin;
98  friend class WardenMac;
99 
100  public:
101  Warden();
102  virtual ~Warden();
103 
104  virtual void Init(WorldSession* session, BigNumber* k) = 0;
105  virtual ClientWardenModule* GetModuleForClient() = 0;
106  virtual void InitializeModule() = 0;
107  virtual void RequestHash() = 0;
108  virtual void HandleHashResult(ByteBuffer &buff) = 0;
109  virtual void RequestData() = 0;
110  virtual void HandleData(ByteBuffer &buff) = 0;
111 
112  void SendModuleToClient();
113  void RequestModule();
114  void Update();
115  void DecryptData(uint8* buffer, uint32 length);
116  void EncryptData(uint8* buffer, uint32 length);
117 
118  static bool IsValidCheckSum(uint32 checksum, const uint8 *data, const uint16 length);
119  static uint32 BuildChecksum(const uint8 *data, uint32 length);
120 
121  // If no check is passed, the default action from config is executed
122  std::string Penalty(WardenCheck* check = NULL);
123 
124  private:
131  uint32 _checkTimer; // Timer for sending check requests
132  uint32 _clientResponseTimer; // Timer for client response delay
133  bool _dataSent;
137 };
138 
139 #endif
uint8 ModuleId[16]
Definition: Warden.h:65
Definition: BigNumber.h:28
Definition: Warden.h:39
Definition: Warden.h:44
uint32 _clientResponseTimer
Definition: Warden.h:132
Definition: Warden.h:36
Definition: ByteBuffer.h:70
uint32 _previousTimestamp
Definition: Warden.h:134
Warden()
Definition: Warden.cpp:33
Definition: Warden.h:54
Definition: Warden.h:43
ClientWardenModule * _module
Definition: Warden.h:135
Definition: Warden.h:51
uint8 Id[16]
Definition: Warden.h:87
void HandleData(ByteBuffer &buff) override
Definition: WardenMac.cpp:216
Definition: Warden.h:77
Definition: Warden.h:62
uint32 CompressedSize
Definition: Warden.h:89
void InitializeModule() override
Definition: WardenMac.cpp:93
uint8 Key[16]
Definition: Warden.h:88
arena_t NULL
Definition: jemalloc_internal.h:624
std::string Penalty(WardenCheck *check=NULL)
Definition: Warden.cpp:184
uint8 Seed[16]
Definition: Warden.h:80
bool _dataSent
Definition: Warden.h:133
Definition: Warden.h:53
uint8 Command
Definition: Warden.h:72
uint8 _seed[16]
Definition: Warden.h:128
uint8 ModuleKey[16]
Definition: Warden.h:66
static uint32 BuildChecksum(const uint8 *data, uint32 length)
Definition: Warden.cpp:173
ClientWardenModule * GetModuleForClient() override
Definition: WardenMac.cpp:72
Definition: WardenMac.h:31
void RequestHash() override
Definition: WardenMac.cpp:98
uint8 Command
Definition: Warden.h:64
void Init(WorldSession *session, BigNumber *k) override
Definition: WardenMac.cpp:39
Definition: Warden.h:35
Definition: Warden.h:56
Definition: Warden.h:57
uint8 * CompressedData
Definition: Warden.h:90
Definition: Warden.h:41
WardenCheckType
Definition: Warden.h:47
void DecryptData(uint8 *buffer, uint32 length)
Definition: Warden.cpp:132
Definition: Warden.h:70
Definition: Warden.h:52
Definition: Warden.h:40
Definition: Warden.h:95
WardenOpcodes
Definition: Warden.h:28
Definition: Warden.h:50
Definition: Warden.h:42
Definition: Warden.h:33
uint32 Size
Definition: Warden.h:67
Definition: ARC4.h:25
uint32_t uint32
Definition: Define.h:150
uint16_t uint16
Definition: Define.h:151
void EncryptData(uint8 *buffer, uint32 length)
Definition: Warden.cpp:137
WorldSession * _session
Definition: Warden.h:125
void RequestModule()
Definition: Warden.cpp:75
uint8 _outputKey[16]
Definition: Warden.h:127
void SendModuleToClient()
Definition: Warden.cpp:49
float length(float v)
Definition: vectorMath.h:208
ARC4 _outputCrypto
Definition: Warden.h:130
ARC4 _inputCrypto
Definition: Warden.h:129
Definition: Warden.h:31
uint8 Command
Definition: Warden.h:79
Definition: Warden.h:55
Definition: WardenWin.h:65
uint8 _inputKey[16]
Definition: Warden.h:126
bool _initialized
Definition: Warden.h:136
#define TC_GAME_API
Definition: Define.h:134
uint8_t uint8
Definition: Define.h:152
static bool IsValidCheckSum(uint32 checksum, const uint8 *data, const uint16 length)
Definition: Warden.cpp:142
uint32 _checkTimer
Definition: Warden.h:131
uint16 DataSize
Definition: Warden.h:73
Definition: WardenCheckMgr.h:34
Player session in the World.
Definition: WorldSession.h:882
Definition: Warden.h:32
T check(T value)
Definition: format.h:305
Definition: Warden.h:34
virtual ~Warden()
Definition: Warden.cpp:41
void RequestData() override
Definition: WardenMac.cpp:192
void HandleHashResult(ByteBuffer &buff) override
Definition: WardenMac.cpp:130
Data
Definition: molten_core.h:69
Definition: Warden.h:49
void Update(uint32 diff)
Definition: WeatherMgr.cpp:150
Definition: Warden.h:85