fix unsafe memory access in PSOBBEncryption

This commit is contained in:
Martin Michelsen
2022-05-12 11:45:20 -07:00
parent 71d78839a4
commit 307eef88d0
4 changed files with 162 additions and 139 deletions
+21 -5
View File
@@ -6,6 +6,9 @@
#include <memory>
#include <string>
#include <vector>
#include <phosg/Encoding.hh>
#include "Text.hh" // for parray
@@ -70,8 +73,21 @@ public:
struct KeyFile {
// initial_keys are actually a stream of uint32_ts, but we treat them as
// bytes for code simplicity
uint8_t initial_keys[0x12 * 4];
uint32_t private_keys[0x400];
union InitialKeys {
uint8_t jsd1_stream_offset;
parray<uint8_t, 0x48> as8;
parray<le_uint32_t, 0x12> as32;
InitialKeys() : as32() { }
InitialKeys(const InitialKeys& other) : as32(other.as32) { }
} __attribute__((packed));
union PrivateKeys {
parray<uint8_t, 0x1000> as8;
parray<le_uint32_t, 0x400> as32;
PrivateKeys() : as32() { }
PrivateKeys(const PrivateKeys& other) : as32(other.as32) { }
} __attribute__((packed));
InitialKeys initial_keys;
PrivateKeys private_keys;
Subtype subtype;
} __attribute__((packed));
@@ -81,9 +97,9 @@ public:
virtual void decrypt(void* data, size_t size, bool advance = true);
protected:
Subtype subtype;
std::vector<uint32_t> stream;
uint8_t jsd1_stream_offset;
KeyFile state;
void apply_seed(const void* original_seed, size_t seed_size);
};
// The following classes provide support for multiple PSOBB private keys, and