From 9f4b53178adaf01703edf44029385081a074a2c7 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Fri, 2 Dec 2022 23:35:02 -0800 Subject: [PATCH] add jsd0 --- src/PSOEncryption.cc | 29 +++++++++++++++++++++++++++++ src/PSOEncryption.hh | 16 ++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/PSOEncryption.cc b/src/PSOEncryption.cc index 31425291..c875972f 100644 --- a/src/PSOEncryption.cc +++ b/src/PSOEncryption.cc @@ -837,6 +837,35 @@ shared_ptr PSOBBMultiKeyImitatorEncryption::ensure_crypt() { +JSD0Encryption::JSD0Encryption(const void* seed, size_t seed_size) : key(0) { + const uint8_t* bytes = reinterpret_cast(seed); + for (size_t z = 0; z < seed_size; z++) { + this->key ^= bytes[z]; + } +} + +void JSD0Encryption::decrypt(void* data, size_t size, bool) { + uint8_t* bytes = reinterpret_cast(data); + for (size_t z = 0; z < size; z++) { + bytes[z] ^= this->key; + bytes[z] -= this->key; + } +} + +void JSD0Encryption::encrypt(void* data, size_t size, bool) { + uint8_t* bytes = reinterpret_cast(data); + for (size_t z = 0; z < size; z++) { + bytes[z] += this->key; + bytes[z] ^= this->key; + } +} + +PSOEncryption::Type JSD0Encryption::type() const { + return Type::JSD0; +} + + + void decrypt_trivial_gci_data(void* data, size_t size, uint8_t basis) { uint8_t* bytes = reinterpret_cast(data); uint8_t key = basis + 0x80; diff --git a/src/PSOEncryption.hh b/src/PSOEncryption.hh index 9a7dc22b..2f23a61a 100644 --- a/src/PSOEncryption.hh +++ b/src/PSOEncryption.hh @@ -18,6 +18,7 @@ public: V2 = 0, V3, BB, + JSD0, }; virtual ~PSOEncryption() = default; @@ -229,4 +230,19 @@ protected: +class JSD0Encryption : public PSOEncryption { +public: + JSD0Encryption(const void* seed, size_t seed_size); + + virtual void encrypt(void* data, size_t size, bool advance = true); + virtual void decrypt(void* data, size_t size, bool advance = true); + + virtual Type type() const = 0; + +private: + uint8_t key; +}; + + + void decrypt_trivial_gci_data(void* data, size_t size, uint8_t basis);