00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #pragma once
00023
00024 #include "Packet.h"
00025
00026 #pragma pack(1)
00027
00028 typedef struct
00029 {
00030 BYTE nProtocol;
00031 DWORD nLength;
00032 BYTE nType;
00033 } ED2K_TCP_HEADER;
00034
00035 typedef struct
00036 {
00037 BYTE nProtocol;
00038 BYTE nType;
00039 } ED2K_UDP_HEADER;
00040
00041 typedef struct
00042 {
00043 BYTE nProtocol;
00044 DWORD nLength;
00045 BYTE nType;
00046 MD4 pMD4;
00047 DWORD nOffset1;
00048 DWORD nOffset2;
00049 } ED2K_PART_HEADER;
00050
00051 #pragma pack()
00052
00053 typedef struct
00054 {
00055 DWORD nType;
00056 LPCTSTR pszName;
00057 } ED2K_PACKET_DESC;
00058
00059 #define ED2K_VERSION 0x3D
00060 #define ED2K_PROTOCOL_EDONKEY 0xE3
00061 #define ED2K_PROTOCOL_PACKED 0xD4
00062 #define ED2K_PROTOCOL_EMULE 0xC5
00063 #define ED2K_PROTOCOL_MLDONKEY 0x00
00064 #define ED2K_PROTOCOL_MET 0x0E
00065
00066 class CBuffer;
00067
00068
00069 class CEDPacket : public CPacket
00070 {
00071
00072 protected:
00073 CEDPacket();
00074 virtual ~CEDPacket();
00075
00076
00077 public:
00078 BYTE m_nEdProtocol;
00079 BYTE m_nType;
00080
00081
00082 public:
00083 CString ReadEDString(DWORD ServerFlags);
00084 void WriteEDString(LPCTSTR psz, DWORD ServerFlags);
00085 CString ReadEDString(BOOL bUnicode);
00086 void WriteEDString(LPCTSTR psz, BOOL bUnicode);
00087 CString ReadLongEDString(BOOL bUnicode);
00088 void WriteLongEDString(LPCTSTR psz, BOOL bUnicode);
00089 BOOL Deflate();
00090 BOOL InflateOrRelease(BYTE nEdProtocol);
00091 public:
00092 virtual void ToBuffer(CBuffer* pBuffer) const;
00093 virtual void ToBufferUDP(CBuffer* pBuffer) const;
00094 static CEDPacket* ReadBuffer(CBuffer* pBuffer, BYTE nEdProtocol);
00095 public:
00096 virtual LPCTSTR GetType() const;
00097 virtual void Debug(LPCTSTR pszReason) const;
00098
00099
00100 public:
00101 inline static BOOL IsLowID(DWORD nID) { return nID > 0 && nID < 16777216; }
00102
00103
00104 protected:
00105 static ED2K_PACKET_DESC m_pszTypes[];
00106
00107
00108 protected:
00109 class CEDPacketPool : public CPacketPool
00110 {
00111 public:
00112 virtual ~CEDPacketPool() { Clear(); }
00113 protected:
00114 virtual void NewPoolImpl(int nSize, CPacket*& pPool, int& nPitch);
00115 virtual void FreePoolImpl(CPacket* pPool);
00116 };
00117
00118 static CEDPacketPool POOL;
00119
00120
00121 public:
00122 static CEDPacket* New(BYTE nType, BYTE nProtocol = ED2K_PROTOCOL_EDONKEY)
00123 {
00124 CEDPacket* pPacket = (CEDPacket*)POOL.New();
00125 pPacket->m_nEdProtocol = nProtocol;
00126 pPacket->m_nType = nType;
00127 return pPacket;
00128 }
00129
00130 static CEDPacket* New(ED2K_TCP_HEADER* pHeader)
00131 {
00132 CEDPacket* pPacket = (CEDPacket*)POOL.New();
00133 pPacket->m_nEdProtocol = pHeader->nProtocol;
00134 pPacket->m_nType = pHeader->nType;
00135 pPacket->Write( &pHeader[1], pHeader->nLength - 1 );
00136 return pPacket;
00137 }
00138
00139 static CEDPacket* New(ED2K_UDP_HEADER* pHeader, DWORD nLength)
00140 {
00141 CEDPacket* pPacket = (CEDPacket*)POOL.New();
00142 pPacket->m_nEdProtocol = pHeader->nProtocol;
00143 pPacket->m_nType = pHeader->nType;
00144 pPacket->Write( &pHeader[1], nLength - sizeof(*pHeader) );
00145 return pPacket;
00146 }
00147
00148 inline virtual void Delete()
00149 {
00150 POOL.Delete( this );
00151 }
00152
00153 friend class CEDPacket::CEDPacketPool;
00154 };
00155
00156 inline void CEDPacket::CEDPacketPool::NewPoolImpl(int nSize, CPacket*& pPool, int& nPitch)
00157 {
00158 nPitch = sizeof(CEDPacket);
00159 pPool = new CEDPacket[ nSize ];
00160 }
00161
00162 inline void CEDPacket::CEDPacketPool::FreePoolImpl(CPacket* pPacket)
00163 {
00164 delete [] (CEDPacket*)pPacket;
00165 }
00166
00167
00168 #define ED2K_C2S_LOGINREQUEST 0x01
00169 #define ED2K_C2S_GETSERVERLIST 0x14
00170 #define ED2K_C2S_OFFERFILES 0x15
00171 #define ED2K_C2S_SEARCHREQUEST 0x16
00172 #define ED2K_C2S_SEARCHUSER 0x1a
00173 #define ED2K_C2S_GETSOURCES 0x19
00174 #define ED2K_C2S_CALLBACKREQUEST 0x1C
00175 #define ED2K_C2S_MORERESULTS 0x21
00176 #define ED2K_S2C_REJECTED 0x05
00177 #define ED2K_S2C_SERVERMESSAGE 0x38
00178 #define ED2K_S2C_IDCHANGE 0x40
00179 #define ED2K_S2C_SERVERLIST 0x32
00180 #define ED2K_S2C_SEARCHRESULTS 0x33
00181 #define ED2K_S2C_FOUNDSOURCES 0x42
00182 #define ED2K_S2C_SERVERSTATUS 0x34
00183 #define ED2K_S2C_SERVERIDENT 0x41
00184 #define ED2K_S2C_CALLBACKREQUESTED 0x35
00185
00186
00187 #define ED2K_C2SG_SEARCHREQUEST2 0x92
00188 #define ED2K_C2SG_GETSOURCES2 0x94
00189 #define ED2K_C2SG_SERVERSTATUSREQUEST 0x96
00190 #define ED2K_S2CG_SERVERSTATUS 0x97
00191 #define ED2K_C2SG_SEARCHREQUEST 0x98
00192 #define ED2K_S2CG_SEARCHRESULT 0x99
00193 #define ED2K_C2SG_GETSOURCES 0x9A
00194 #define ED2K_S2CG_FOUNDSOURCES 0x9B
00195 #define ED2K_C2SG_CALLBACKREQUEST 0x9C
00196 #define ED2K_S2CG_CALLBACKFAIL 0x9E
00197
00198
00199 #define ED2K_C2C_HELLO 0x01
00200 #define ED2K_C2C_HELLOANSWER 0x4C
00201 #define ED2K_C2C_FILEREQUEST 0x58
00202 #define ED2K_C2C_FILEREQANSWER 0x59
00203 #define ED2K_C2C_FILENOTFOUND 0x48
00204 #define ED2K_C2C_FILESTATUS 0x50
00205 #define ED2K_C2C_QUEUEREQUEST 0x54
00206 #define ED2K_C2C_QUEUERELEASE 0x56
00207 #define ED2K_C2C_QUEUERANK 0x5C
00208 #define ED2K_C2C_STARTUPLOAD 0x55
00209 #define ED2K_C2C_FINISHUPLOAD 0x57
00210 #define ED2K_C2C_REQUESTPARTS 0x47
00211 #define ED2K_C2C_SENDINGPART 0x46
00212 #define ED2K_C2C_FILESTATUSREQUEST 0x4F
00213 #define ED2K_C2C_HASHSETREQUEST 0x51
00214 #define ED2K_C2C_HASHSETANSWER 0x52
00215 #define ED2K_C2C_ASKSHAREDFILES 0x4A
00216 #define ED2K_C2C_ASKSHAREDFILESANSWER 0x4B
00217 #define ED2K_C2C_MESSAGE 0x4E
00218
00219 #define ED2K_C2C_EMULEINFO 0x01
00220 #define ED2K_C2C_EMULEINFOANSWER 0x02
00221 #define ED2K_C2C_COMPRESSEDPART 0x40
00222 #define ED2K_C2C_QUEUERANKING 0x60
00223 #define ED2K_C2C_FILEDESC 0x61
00224 #define ED2K_C2C_REQUESTSOURCES 0x81
00225 #define ED2K_C2C_ANSWERSOURCES 0x82
00226
00227
00228 #define ED2K_C2C_UDP_REASKFILEPING 0x90
00229 #define ED2K_C2C_UDP_REASKACK 0x91
00230 #define ED2K_C2C_UDP_FILENOTFOUND 0x92
00231 #define ED2K_C2C_UDP_QUEUEFULL 0x93
00232
00233
00234 #define ED2K_SERVER_TCP_DEFLATE 0x00000001
00235 #define ED2K_SERVER_TCP_SMALLTAGS 0x00000008
00236 #define ED2K_SERVER_TCP_UNICODE 0x00000010
00237 #define ED2K_SERVER_TCP_GETSOURCES2 0x00000020
00238 #define ED2K_SERVER_TCP_RELATEDSEARCH 0x00000040
00239
00240 #define ED2K_SERVER_UDP_GETSOURCES 0x00000001
00241 #define ED2K_SERVER_UDP_GETFILES 0x00000002
00242 #define ED2K_SERVER_UDP_UNICODE 0x00000010
00243 #define ED2K_SERVER_UDP_GETSOURCES2 0x00000020
00244
00245
00246 class CEDTag
00247 {
00248
00249 public:
00250 CEDTag();
00251 CEDTag(BYTE nKey);
00252 CEDTag(BYTE nKey, DWORD nValue);
00253 CEDTag(BYTE nKey, LPCTSTR pszValue);
00254 CEDTag(LPCTSTR pszKey);
00255 CEDTag(LPCTSTR pszKey, DWORD nValue);
00256 CEDTag(LPCTSTR pszKey, LPCTSTR pszValue);
00257 ~CEDTag() {};
00258
00259
00260 public:
00261 BYTE m_nType;
00262 CString m_sKey;
00263 BYTE m_nKey;
00264 CString m_sValue;
00265 DWORD m_nValue;
00266
00267
00268 public:
00269 void Clear();
00270 void Write(CEDPacket* pPacket, DWORD ServerFlags = 0);
00271 BOOL Read(CEDPacket* pPacket, DWORD ServerFlags = 0);
00272 BOOL Read(CFile* pFile);
00273
00274
00275 public:
00276 inline BOOL Check(BYTE nKey, BYTE nType) const
00277 {
00278 return m_nKey == nKey && m_nType == nType;
00279 }
00280 };
00281
00282
00283 #define ED2K_TAG_NULL 0x00
00284 #define ED2K_TAG_HASH 0x01
00285 #define ED2K_TAG_STRING 0x02
00286 #define ED2K_TAG_INT 0x03
00287 #define ED2K_TAG_FLOAT 0x04
00288 #define ED2K_TAG_BOOL 0x05
00289 #define ED2K_TAG_BOOL_ARRAY 0x06
00290 #define ED2K_TAG_BLOB 0x07
00291
00292 #define ED2K_TAG_UINT16 0x08
00293 #define ED2K_TAG_UINT8 0x09
00294 #define ED2K_TAG_UNUSED 0x0A // 8 bit size, then value
00295 #define ED2K_TAG_SHORTSTRING 0x11 //String <=16 bytes, using tag ID for length
00296
00297 #define ED2K_TAG_STRING1 0x11
00298 #define ED2K_TAG_STRING16 0x20
00299
00300
00301 #define ED2K_ST_SERVERNAME 0x01
00302 #define ED2K_ST_DESCRIPTION 0x0B
00303 #define ED2K_ST_PING 0x0C
00304 #define ED2K_ST_PREFERENCE 0x0E
00305 #define ED2K_ST_FAIL 0x0D
00306 #define ED2K_ST_DYNIP 0x85
00307 #define ED2K_ST_LASTPING 0x86
00308 #define ED2K_ST_MAXUSERS 0x87
00309 #define ED2K_ST_MAXFILES 0x88
00310 #define ED2K_ST_UDPFLAGS 0x92
00311
00312
00313 #define ED2K_CT_NAME 0x01
00314 #define ED2K_CT_PORT 0x0F
00315 #define ED2K_CT_VERSION 0x11
00316 #define ED2K_CT_FLAGS 0x20 // Tell server about compression, new tags, unicode
00317 #define ED2K_CT_MODVERSION 0x55 // MOD version
00318 #define ED2K_CT_UDPPORTS 0xF9 // Ports used for UDP
00319 #define ED2K_CT_FEATUREVERSIONS 0xFA // Tells extended features (like emule info)
00320 #define ED2K_CT_SOFTWAREVERSION 0xFB // Version of the program.
00321 #define ED2K_CT_UNKNOWN1 0xFC // ?
00322 #define ED2K_CT_UNKNOWN2 0xFD // ?
00323 #define ED2K_CT_MOREFEATUREVERSIONS 0xFE // KAD version (Unused)
00324 #define ED2K_CT_UNKNOWN3 0xFF // ?
00325
00326
00327
00328 #define ED2K_FT_FILENAME 0x01
00329 #define ED2K_FT_FILESIZE 0x02
00330 #define ED2K_FT_FILETYPE 0x03
00331 #define ED2K_FT_FILEFORMAT 0x04
00332 #define ED2K_FT_LASTSEENCOMPLETE 0x05
00333 #define ED2K_FT_TRANSFERED 0x08
00334 #define ED2K_FT_GAPSTART 0x09
00335 #define ED2K_FT_GAPEND 0x0A
00336 #define ED2K_FT_PARTFILENAME 0x12
00337 #define ED2K_FT_PRIORITY 0x13
00338 #define ED2K_FT_STATUS 0x14
00339 #define ED2K_FT_SOURCES 0x15
00340 #define ED2K_FT_PERMISSIONS 0x16
00341 #define ED2K_FT_ULPRIORITY 0x17
00342 #define ED2K_FT_COMPLETESOURCES 0x30
00343 #define ED2K_FT_ATTRANSFERED 0x50
00344 #define ED2K_FT_ATREQUESTED 0x51
00345 #define ED2K_FT_ATACCEPTED 0x52
00346 #define ED2K_FT_LENGTH 0xD3
00347 #define ED2K_FT_BITRATE 0xD4
00348 #define ED2K_FT_CODEC 0xD5
00349 #define ED2K_FT_FILERATING 0xF7
00350
00351
00352 #define ED2K_ET_COMPRESSION 0x20
00353 #define ED2K_ET_UDPPORT 0x21
00354 #define ED2K_ET_UDPVER 0x22
00355 #define ED2K_ET_SOURCEEXCHANGE 0x23
00356 #define ED2K_ET_COMMENTS 0x24
00357 #define ED2K_ET_EXTENDEDREQUEST 0x25
00358 #define ED2K_ET_COMPATIBLECLIENT 0x26 // Client ID.
00359 #define ED2K_ET_FEATURES 0x27 // Preview and sec ID
00360
00361
00362 #define ED2K_MAXFILESINPACKET 0x20
00363
00364
00365 #define ED2K_MESSAGE_MAX 500
00366
00367 #define ED2K_COMMENT_MAX 250
00368
00369
00370 #define ED2K_COMPATIBLECLIENT_ID ED2K_CLIENT_ID // Used to be 4, changed on request
00371
00372
00373 #define ED2K_CLIENT_UNKNOWN 0xFF
00374 #define ED2K_CLIENT_MOD 0xFE
00375
00376
00377 #define ED2K_VERSION_COMPRESSION 0x01
00378 #define ED2K_VERSION_UDP 0x02
00379 #define ED2K_VERSION_SOURCEEXCHANGE 0x02
00380 #define ED2K_VERSION_COMMENTS 0x01
00381 #define ED2K_VERSION_EXTENDEDREQUEST 0x01
00382
00383 #define ED2K_VERSION_AICH 0x00
00384 #define ED2K_VERSION_SECUREID 0x00
00385
00386
00387
00388