From e800fd3fff6ea9c782ab9fa45f6b2113e4da36c2 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Sat, 10 Dec 2022 09:19:43 -0800 Subject: [PATCH] fix prs_decompress_size --- src/Compression.cc | 1 + src/Main.cc | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/Compression.cc b/src/Compression.cc index 41e3fc66..25b8abb1 100644 --- a/src/Compression.cc +++ b/src/Compression.cc @@ -325,6 +325,7 @@ size_t prs_decompress_size(const void* data, size_t size, size_t max_output_size while (!r.eof()) { if (cr.read()) { ret++; + r.get_u8(); } else { ssize_t offset; diff --git a/src/Main.cc b/src/Main.cc index 73e9542e..70c2e8f9 100644 --- a/src/Main.cc +++ b/src/Main.cc @@ -282,6 +282,8 @@ The options are:\n\ --decompress-bc0 [input-filename [output-filename]]\n\ Compress or decompress data using the PRS or BC0 algorithms. Both\n\ input-filename and output-filename may be specified.\n\ + --prs-size\n\ + Compute the decompressed size of the PRS-compressed input data.\n\ --encrypt-data\n\ --decrypt-data\n\ Encrypt or decrypt data using PSO's standard network protocol encryption.\n\ @@ -367,6 +369,7 @@ enum class Behavior { DECOMPRESS_PRS, COMPRESS_BC0, DECOMPRESS_BC0, + PRS_SIZE, ENCRYPT_DATA, DECRYPT_DATA, DECRYPT_TRIVIAL_DATA, @@ -385,6 +388,7 @@ static bool behavior_takes_input_filename(Behavior b) { (b == Behavior::DECOMPRESS_PRS) || (b == Behavior::COMPRESS_BC0) || (b == Behavior::DECOMPRESS_BC0) || + (b == Behavior::PRS_SIZE) || (b == Behavior::ENCRYPT_DATA) || (b == Behavior::DECRYPT_DATA) || (b == Behavior::DECRYPT_TRIVIAL_DATA) || @@ -445,6 +449,8 @@ int main(int argc, char** argv) { behavior = Behavior::COMPRESS_BC0; } else if (!strcmp(argv[x], "--decompress-bc0")) { behavior = Behavior::DECOMPRESS_BC0; + } else if (!strcmp(argv[x], "--prs-size")) { + behavior = Behavior::PRS_SIZE; } else if (!strcmp(argv[x], "--encrypt-data")) { behavior = Behavior::ENCRYPT_DATA; } else if (!strcmp(argv[x], "--decrypt-data")) { @@ -579,6 +585,15 @@ int main(int argc, char** argv) { break; } + case Behavior::PRS_SIZE: { + string data = read_input_data(); + size_t input_bytes = data.size(); + size_t output_bytes = prs_decompress_size(data); + log_info("%zu (0x%zX) bytes input => %zu (0x%zX) bytes output", + input_bytes, input_bytes, output_bytes, output_bytes); + break; + } + case Behavior::DECRYPT_DATA: case Behavior::ENCRYPT_DATA: { shared_ptr crypt;