Search code examples
c++steamlibarchive

Steam Protocol C++ Unzip Multi message


I'm writting a plugin for Steam protocol in C++. I'm using https://github.com/seishun/SteamPP which uses protobufs from https://github.com/SteamRE/SteamKit and generally it works. I can communicate Steam, I can send and receive single messages (including logging in) without problems, but Steam sends often few messages zipped in one message (EMsg::Multi from protobuf) and here is my problem. I cannot unzip them correctly. I can't understand what I'm doing wrong.

std::string unzip(std::string &input) {
auto archive = archive_read_new();

auto result = archive_read_support_filter_all(archive);
assert(result == ARCHIVE_OK);

result = archive_read_support_format_zip(archive);
assert(result == ARCHIVE_OK);

result = archive_read_open_memory(archive, &input[0], input.size());
assert(result == ARCHIVE_OK);

archive_entry* entry;
result = archive_read_next_header(archive, &entry);
if (result != ARCHIVE_OK) {
    return "read next header error " + std::to_string(result);
}
assert(result == ARCHIVE_OK);

std::string output;
output.resize(archive_entry_size(entry));

auto length = archive_read_data(archive, &output[0], output.size());
assert(length == output.size());
if (length != output.size()) {
    return "hello world" + std::to_string(length);
}

assert(archive_read_next_header(archive, &entry) == ARCHIVE_EOF);

result = archive_read_free(archive);
assert(result == ARCHIVE_OK);

return output;
}

in this function (libarchive) archive_read_data returns -25 which is an error code and next assert throws error. What is wrong? It's working well in C# SteamKit version and also in node.js version. I have tried also Crypto++ Gunzip but it throws an CryptoPP::Gunzip::HeaderErr exception. CHECK DEBUG GIF


Solution

  • I think you are missing Zlib in your Libarchive, because Steam messages are deflated and you need Zlib to process them. Now libarchive couldn't process them so it returns -25 because of unsupported file type. Try to recompile libarchive with Zlib attached in CMake.