Fixed some compiler warnings

This commit is contained in:
WolverinDEV 2019-10-14 16:07:17 +01:00
parent 3b3574d54d
commit 5fff4369ef
3 changed files with 14 additions and 7 deletions

View File

@ -1,4 +1,4 @@
1 1
success success
cb73d9df3258eaf59e4799c9e54d5f865e891734 870933c892c6b84a7127daac8f92f5c205b09611
22 Sep 2019 13:38:56 22 Sep 2019 16:25:55

View File

@ -39,15 +39,17 @@ namespace str_obf {
return !str[h] ? 5381 : (string_hash(str, h + 1) * 33) ^ str[h]; 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 { constexpr std::uint32_t rng32_next(std::uint64_t& state, const std::uint32_t& inc) noexcept {
std::uint64_t oldstate = state; std::uint64_t oldstate = state;
// Advance internal state // Advance internal state
state = oldstate * 6364136223846793005ULL + (inc | 1UL); state = oldstate * 6364136223846793005ULL + (inc | 1UL);
// Calculate output function (XSH RR), uses old state for max ILP // 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; std::uint32_t rot = oldstate >> 59u;
return (xorshifted >> rot) | (xorshifted << ((-rot) & 31)); 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 */ /* 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 { 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_seed = internal::time_seed() ^ internal::string_hash(message, 0);
std::uint64_t rng_base = rng_seed; std::uint64_t rng_base = rng_seed;
while(padding-- > 0) 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; std::uint64_t rng_base = seed;
size_t length = 0; size_t length = 0;
do { 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); } 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 */ /* 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); constexpr size_t key_length = generate_key_length(internal::time_seed() ^ (line_number << 37UL), max_size);
std::array<uint8_t, key_length> result{}; std::array<uint8_t, key_length> result{};
for(auto& it : 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; return result;
} }
@ -166,7 +168,7 @@ namespace str_obf {
#endif #endif
const char* c_str() noexcept { const char* c_str() noexcept {
if(!this->decoded) { if(!this->decoded) {
memcpy(this->buffer.data(), this->encoded.buffer.begin(), message::_size); memcpy(this->buffer.data(), this->encoded.buffer.data(), message::_size);
crypt< crypt<
typename message::_char_t, typename message::_char_t,
typename message::_key_t typename message::_key_t

View File

@ -7,6 +7,11 @@
#include <memory> #include <memory>
#include <mutex> #include <mutex>
// Windows defines the macro max(a, b)
#ifdef max
#undef max
#endif
namespace ts { namespace ts {
namespace protocol { namespace protocol {
template <typename T> template <typename T>