Obfuscate default nodes
This commit is contained in:
parent
0c978d9980
commit
b0ffeeb334
2
deps/mongoose
vendored
2
deps/mongoose
vendored
@ -1 +1 @@
|
||||
Subproject commit b3fb21dacccfb08b046b73740eec52cd66e944de
|
||||
Subproject commit 844c7787f9d86715c80ab56f4f28d1b808df5341
|
2
deps/protobuf
vendored
2
deps/protobuf
vendored
@ -1 +1 @@
|
||||
Subproject commit 3d9d1a1255583bac550f7bf94f3016e8c238fa5e
|
||||
Subproject commit e721ce66cfeaa5d8790ecba09c73d1ef399887d2
|
@ -8,19 +8,13 @@ namespace Components
|
||||
|
||||
void Node::LoadNodePreset()
|
||||
{
|
||||
Proto::Node::List list;
|
||||
FileSystem::File defaultNodes("nodes_default.dat");
|
||||
if (!defaultNodes.Exists()) return;
|
||||
if (!defaultNodes.Exists() || !list.ParseFromString(Utils::Compression::ZLib::Decompress(defaultNodes.GetBuffer()))) return;
|
||||
|
||||
auto buffer = defaultNodes.GetBuffer();
|
||||
Utils::String::Replace(buffer, "\r", "");
|
||||
|
||||
auto nodes = Utils::String::Explode(buffer, '\n');
|
||||
for (auto node : nodes)
|
||||
for (int i = 0; i < list.address_size(); ++i)
|
||||
{
|
||||
if (!node.empty())
|
||||
{
|
||||
Node::AddNode(node);
|
||||
}
|
||||
Node::AddNode(list.address(i));
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,7 +22,7 @@ namespace Components
|
||||
{
|
||||
Proto::Node::List list;
|
||||
std::string nodes = Utils::IO::ReadFile("players/nodes.dat");
|
||||
if (nodes.empty() || !list.ParseFromString(nodes)) return;
|
||||
if (nodes.empty() || !list.ParseFromString(Utils::Compression::ZLib::Decompress(nodes))) return;
|
||||
|
||||
for (int i = 0; i < list.address_size(); ++i)
|
||||
{
|
||||
@ -60,7 +54,10 @@ namespace Components
|
||||
}
|
||||
|
||||
CreateDirectoryW(L"players", NULL);
|
||||
Utils::IO::WriteFile("players/nodes.dat", list.SerializeAsString());
|
||||
|
||||
|
||||
|
||||
Utils::IO::WriteFile("players/nodes.dat", Utils::Compression::ZLib::Compress(list.SerializeAsString()));
|
||||
}
|
||||
|
||||
Node::NodeEntry* Node::FindNode(Network::Address address)
|
||||
@ -907,6 +904,31 @@ namespace Components
|
||||
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - startTime).count();
|
||||
Logger::Print("took %llims\n", duration);
|
||||
|
||||
printf("Testing ZLib compression...");
|
||||
|
||||
std::string test = fmt::sprintf("%c", Utils::Cryptography::Rand::GenerateInt());
|
||||
|
||||
for (int i = 0; i < 21; ++i)
|
||||
{
|
||||
std::string compressed = Utils::Compression::ZLib::Compress(test);
|
||||
std::string decompressed = Utils::Compression::ZLib::Decompress(compressed);
|
||||
|
||||
if (test != decompressed)
|
||||
{
|
||||
printf("Error\n");
|
||||
printf("Compressing %d bytes and decompressing failed!\n", test.size());
|
||||
return false;
|
||||
}
|
||||
|
||||
auto size = test.size();
|
||||
for (unsigned int j = 0; j < size; ++j)
|
||||
{
|
||||
test.append(fmt::sprintf("%c", Utils::Cryptography::Rand::GenerateInt()));
|
||||
}
|
||||
}
|
||||
|
||||
printf("Success\n");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -6,8 +6,13 @@ namespace Utils
|
||||
{
|
||||
std::string ZLib::Compress(std::string data)
|
||||
{
|
||||
Utils::Memory::Allocator allocator;
|
||||
unsigned long length = (data.size() * 2);
|
||||
char* buffer = Utils::Memory::AllocateArray<char>(length);
|
||||
|
||||
// Make sure the buffer is large enough
|
||||
if (length < 100) length *= 10;
|
||||
|
||||
char* buffer = allocator.AllocateArray<char>(length);
|
||||
|
||||
if (compress2(reinterpret_cast<Bytef*>(buffer), &length, reinterpret_cast<Bytef*>(const_cast<char*>(data.data())), data.size(), Z_BEST_COMPRESSION) != Z_OK)
|
||||
{
|
||||
@ -18,8 +23,6 @@ namespace Utils
|
||||
data.clear();
|
||||
data.append(buffer, length);
|
||||
|
||||
Utils::Memory::Free(buffer);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -44,6 +47,7 @@ namespace Utils
|
||||
{
|
||||
stream.avail_in = std::min(static_cast<size_t>(CHUNK), data.size() - (dataPtr - data.data()));
|
||||
stream.next_in = reinterpret_cast<const uint8_t*>(dataPtr);
|
||||
dataPtr += stream.avail_in;
|
||||
|
||||
do
|
||||
{
|
||||
@ -51,7 +55,7 @@ namespace Utils
|
||||
stream.next_out = dest;
|
||||
|
||||
ret = inflate(&stream, Z_NO_FLUSH);
|
||||
if (ret == Z_STREAM_ERROR)
|
||||
if (ret != Z_OK && ret != Z_STREAM_END)
|
||||
{
|
||||
inflateEnd(&stream);
|
||||
return "";
|
||||
|
Loading…
Reference in New Issue
Block a user