diff --git a/source/common/crypto/crc.cpp b/source/common/crypto/crc.cpp index dc11181..d0e0d79 100644 --- a/source/common/crypto/crc.cpp +++ b/source/common/crypto/crc.cpp @@ -1,9 +1,7 @@ // Copyright (C) 2007-2025 EQ2EMulator // Licensed under GPL v3 -#include - -unsigned long IntArray[] = { +unsigned long IntArray[] = { 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, @@ -68,55 +66,55 @@ unsigned long IntArray[] = { 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D, -}; - -unsigned long CRC16(const unsigned char *buf, int size, int key) +}; + +unsigned long CRC16(const unsigned char *buf, int size, int key) { - unsigned long ecx = key; //mov ecx, [esp+arg_8] - unsigned long eax = ecx; //mov eax, ecx + unsigned long ecx = key; //mov ecx, [esp+arg_8] + unsigned long eax = ecx; //mov eax, ecx unsigned long edi; - eax = ~ eax; //not eax - eax&=0xFF; //and eax, 0FFh - eax=IntArray[eax]; //mov eax, dword_0_10115D38[eax*4] IntArray - eax ^= 0x00FFFFFF; //xor eax, 0FFFFFFh - int edx = ecx; //mov edx, ecx - edx = edx >> 8; //sar edx, 8 - edx = edx ^ eax; //xor edx, eax - eax = eax >> 8; //sar eax, 8 - edx &= 0xFF; //and edx, 0FFh - eax &= 0x00FFFFFF; //and eax, 0FFFFFFh - eax ^= IntArray[edx]; //xor eax, dword_0_10115D38[edx*4] - edx = ecx; //mov edx, ecx - edx = edx >> 0x10; //sar edx, 10h - edx ^= eax; //xor edx, eax - eax = eax >> 8; //sar eax, 8 - edx &= 0xFF; //and edx, 0FFh - int esi = IntArray[edx]; //mov esi, dword_0_10115D38[edx*4] - edx = size; //mov edx, [esp+4+arg_4] - eax &= 0x00FFFFFF; //and eax, 0FFFFFFh - eax ^= esi; //xor eax, esi - ecx = ecx >> 0x18; //sar ecx, 18h - ecx ^= eax; //xor ecx, eax - ecx &= 0xFF; //and ecx, 0FFh - esi = IntArray[ecx]; //mov esi, dword_0_10115D38[ecx*4] - ecx = (int)*buf; //mov ecx, [esp+4+arg_0] - eax = eax >> 8; //sar eax, 8 - eax &= 0x00FFFFFF; //and eax, 0FFFFFFh + eax = ~ eax; //not eax + eax&=0xFF; //and eax, 0FFh + eax=IntArray[eax]; //mov eax, dword_0_10115D38[eax*4] IntArray + eax ^= 0x00FFFFFF; //xor eax, 0FFFFFFh + int edx = ecx; //mov edx, ecx + edx = edx >> 8; //sar edx, 8 + edx = edx ^ eax; //xor edx, eax + eax = eax >> 8; //sar eax, 8 + edx &= 0xFF; //and edx, 0FFh + eax &= 0x00FFFFFF; //and eax, 0FFFFFFh + eax ^= IntArray[edx]; //xor eax, dword_0_10115D38[edx*4] + edx = ecx; //mov edx, ecx + edx = edx >> 0x10; //sar edx, 10h + edx ^= eax; //xor edx, eax + eax = eax >> 8; //sar eax, 8 + edx &= 0xFF; //and edx, 0FFh + int esi = IntArray[edx]; //mov esi, dword_0_10115D38[edx*4] + edx = size; //mov edx, [esp+4+arg_4] + eax &= 0x00FFFFFF; //and eax, 0FFFFFFh + eax ^= esi; //xor eax, esi + ecx = ecx >> 0x18; //sar ecx, 18h + ecx ^= eax; //xor ecx, eax + ecx &= 0xFF; //and ecx, 0FFh + esi = IntArray[ecx]; //mov esi, dword_0_10115D38[ecx*4] + ecx = (int)*buf; //mov ecx, [esp+4+arg_0] + eax = eax >> 8; //sar eax, 8 + eax &= 0x00FFFFFF; //and eax, 0FFFFFFh eax ^= esi; //xor eax, esi for(int x = 0; x < size; x++) { - //eax is the crc, ecx is the current part of the buffer - int edx = 0; //xor edx, edx - edx = buf[x] & 0x00FF; //mov dl, [ecx] + //eax is the crc, ecx is the current part of the buffer + int edx = 0; //xor edx, edx + edx = buf[x] & 0x00FF; //mov dl, [ecx] - edx ^= eax; //xor edx, eax - eax = eax >> 8; //sar eax, 8 - edx &= 0xFF; //and edx, 0FFh - edi = IntArray[edx]; //mov edi, dword_0_10115D38[edx*4] - eax &= 0x00FFFFFF; //and eax, 0FFFFFFh - eax ^= edi; //xor eax, edi - } - - return ~eax; -} + edx ^= eax; //xor edx, eax + eax = eax >> 8; //sar eax, 8 + edx &= 0xFF; //and edx, 0FFh + edi = IntArray[edx]; //mov edi, dword_0_10115D38[edx*4] + eax &= 0x00FFFFFF; //and eax, 0FFFFFFh + eax ^= edi; //xor eax, edi + } + + return ~eax; +} diff --git a/source/common/crypto/crypto.cpp b/source/common/crypto/crypto.cpp index cfe1423..77df26a 100644 --- a/source/common/crypto/crypto.cpp +++ b/source/common/crypto/crypto.cpp @@ -2,12 +2,11 @@ // Licensed under GPL v3 #include "crypto.h" -#include #include #include #include -int64 Crypto::RSADecrypt(uchar* text, int16 size) noexcept +int64 Crypto::RSADecrypt(uchar* text, [[maybe_unused]] int16 size) noexcept { int64 ret = 0; std::array buffer{}; @@ -50,4 +49,3 @@ void Crypto::setRC4Key(int64 key) noexcept server.reset(); } } - diff --git a/source/common/crypto/rc4.h b/source/common/crypto/rc4.h index 92e7f77..a4fc4d2 100644 --- a/source/common/crypto/rc4.h +++ b/source/common/crypto/rc4.h @@ -1,5 +1,6 @@ // Copyright (C) 2007-2025 EQ2EMulator // Licensed under GPL v3 + #pragma once #include "../types.h" @@ -19,4 +20,3 @@ private: uchar m_x{}; uchar m_y{}; }; - diff --git a/source/common/crypto/sha512.cpp b/source/common/crypto/sha512.cpp index 6658798..71c7040 100644 --- a/source/common/crypto/sha512.cpp +++ b/source/common/crypto/sha512.cpp @@ -2,7 +2,6 @@ // Licensed under GPL v3 #include "sha512.h" -#include #include #include @@ -158,7 +157,7 @@ std::string sha512(std::string_view input) noexcept ctx.final(digest.data()); std::array buf{}; - for (int i = 0; i < SHA512::DIGEST_SIZE; ++i) { + for (unsigned int i = 0; i < SHA512::DIGEST_SIZE; ++i) { std::sprintf(buf.data() + i * 2, "%02x", digest[i]); } return std::string{buf.data()}; diff --git a/source/common/crypto/sha512.h b/source/common/crypto/sha512.h index 8197077..a5295be 100644 --- a/source/common/crypto/sha512.h +++ b/source/common/crypto/sha512.h @@ -1,3 +1,6 @@ +// Copyright (C) 2007-2025 EQ2EMulator +// Licensed under GPL v3 + #pragma once #include @@ -21,9 +24,9 @@ protected: using uint64 = std::uint64_t; static const std::array sha512_k; - + void transform(const unsigned char* message, unsigned int block_nb) noexcept; - + unsigned int m_tot_len{}; unsigned int m_len{}; std::array m_block{}; @@ -31,7 +34,7 @@ protected: }; [[nodiscard]] std::string sha512(std::string_view input) noexcept; - + #define SHA2_SHFR(x, n) (x >> n) #define SHA2_ROTR(x, n) ((x >> n) | (x << ((sizeof(x) << 3) - n))) #define SHA2_ROTL(x, n) ((x << n) | (x >> ((sizeof(x) << 3) - n))) @@ -70,5 +73,3 @@ protected: | ((uint64) *((str) + 1) << 48) \ | ((uint64) *((str) + 0) << 56); \ } - -#endif \ No newline at end of file