From 5fff4369ef7fad88d6872e3ce7d92e4b88c000c6 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Mon, 14 Oct 2019 16:07:17 +0100 Subject: [PATCH] Fixed some compiler warnings --- .build_win32_amd64.txt | 4 ++-- src/misc/strobf.h | 12 +++++++----- src/protocol/ringbuffer.h | 5 +++++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.build_win32_amd64.txt b/.build_win32_amd64.txt index a47cf4d..fd233fd 100644 --- a/.build_win32_amd64.txt +++ b/.build_win32_amd64.txt @@ -1,4 +1,4 @@ 1 success -cb73d9df3258eaf59e4799c9e54d5f865e891734 -22 Sep 2019 13:38:56 +870933c892c6b84a7127daac8f92f5c205b09611 +22 Sep 2019 16:25:55 diff --git a/src/misc/strobf.h b/src/misc/strobf.h index 6b03b20..f2e2d90 100644 --- a/src/misc/strobf.h +++ b/src/misc/strobf.h @@ -39,15 +39,17 @@ namespace str_obf { return !str[h] ? 5381 : (string_hash(str, h + 1) * 33) ^ str[h]; } +#pragma warning(disable: 4146) // unary minus operator applied to unsigned type, result still unsigned constexpr std::uint32_t rng32_next(std::uint64_t& state, const std::uint32_t& inc) noexcept { std::uint64_t oldstate = state; // Advance internal state state = oldstate * 6364136223846793005ULL + (inc | 1UL); // Calculate output function (XSH RR), uses old state for max ILP - std::uint32_t xorshifted = ((oldstate >> 18u) ^ oldstate) >> 27u; + std::uint32_t xorshifted = (uint32_t) (((oldstate >> 18u) ^ oldstate) >> 27u); std::uint32_t rot = oldstate >> 59u; return (xorshifted >> rot) | (xorshifted << ((-rot) & 31)); } +#pragma warning(default: 4146) // unary minus operator applied to unsigned type, result still unsigned /* we use a buffer dividable by 8 so the compiler could do crazy shit, when loading (moving) the characters */ constexpr size_t recommand_message_buffer(size_t message_size) noexcept { @@ -105,7 +107,7 @@ namespace str_obf { std::uint64_t rng_seed = internal::time_seed() ^ internal::string_hash(message, 0); std::uint64_t rng_base = rng_seed; while(padding-- > 0) - *bit++ = internal::rng32_next(rng_base, rng_seed) & 0xFFUL; + *bit++ = internal::rng32_next(rng_base, (uint32_t) rng_seed) & 0xFFUL; } } @@ -134,7 +136,7 @@ namespace str_obf { std::uint64_t rng_base = seed; size_t length = 0; do { - length = (internal::rng32_next(rng_base, seed) >> 12UL) & 0xFFUL; + length = (size_t) ((internal::rng32_next(rng_base, (uint32_t) seed) >> 12UL) & 0xFFUL); } while(length < 8 || length >= max_size); /* it does not really matter if we have a 8 byte aligned number here, because we iterate so or so byte for byte */ @@ -149,7 +151,7 @@ namespace str_obf { constexpr size_t key_length = generate_key_length(internal::time_seed() ^ (line_number << 37UL), max_size); std::array result{}; for(auto& it : result) - it = (internal::rng32_next(rng_base, rng_seed) >> 16UL) & 0xFFUL; + it = (internal::rng32_next(rng_base, (uint32_t) rng_seed) >> 16UL) & 0xFFUL; return result; } @@ -166,7 +168,7 @@ namespace str_obf { #endif const char* c_str() noexcept { if(!this->decoded) { - memcpy(this->buffer.data(), this->encoded.buffer.begin(), message::_size); + memcpy(this->buffer.data(), this->encoded.buffer.data(), message::_size); crypt< typename message::_char_t, typename message::_key_t diff --git a/src/protocol/ringbuffer.h b/src/protocol/ringbuffer.h index 7a1f643..74e2243 100644 --- a/src/protocol/ringbuffer.h +++ b/src/protocol/ringbuffer.h @@ -7,6 +7,11 @@ #include #include +// Windows defines the macro max(a, b) +#ifdef max + #undef max +#endif + namespace ts { namespace protocol { template