clean up big-endian encryption
This commit is contained in:
+22
-4
@@ -81,7 +81,8 @@ uint32_t PSOV2Encryption::next(bool advance) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PSOV2Encryption::encrypt(void* vdata, size_t size, bool advance) {
|
template <typename LongT>
|
||||||
|
void PSOV2Encryption::encrypt_t(void* vdata, size_t size, bool advance) {
|
||||||
if (size & 3) {
|
if (size & 3) {
|
||||||
throw invalid_argument("size must be a multiple of 4");
|
throw invalid_argument("size must be a multiple of 4");
|
||||||
}
|
}
|
||||||
@@ -90,12 +91,20 @@ void PSOV2Encryption::encrypt(void* vdata, size_t size, bool advance) {
|
|||||||
}
|
}
|
||||||
size >>= 2;
|
size >>= 2;
|
||||||
|
|
||||||
le_uint32_t* data = reinterpret_cast<le_uint32_t*>(vdata);
|
LongT* data = reinterpret_cast<LongT*>(vdata);
|
||||||
for (size_t x = 0; x < size; x++) {
|
for (size_t x = 0; x < size; x++) {
|
||||||
data[x] ^= this->next(advance);
|
data[x] ^= this->next(advance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PSOV2Encryption::encrypt(void* vdata, size_t size, bool advance) {
|
||||||
|
this->encrypt_t<le_uint32_t>(vdata, size, advance);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PSOV2Encryption::encrypt_big_endian(void* vdata, size_t size, bool advance) {
|
||||||
|
this->encrypt_t<be_uint32_t>(vdata, size, advance);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void PSOV3Encryption::update_stream() {
|
void PSOV3Encryption::update_stream() {
|
||||||
@@ -158,7 +167,8 @@ PSOV3Encryption::PSOV3Encryption(uint32_t seed) : offset(0) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PSOV3Encryption::encrypt(void* vdata, size_t size, bool advance) {
|
template <typename LongT>
|
||||||
|
void PSOV3Encryption::encrypt_t(void* vdata, size_t size, bool advance) {
|
||||||
if (size & 3) {
|
if (size & 3) {
|
||||||
throw invalid_argument("size must be a multiple of 4");
|
throw invalid_argument("size must be a multiple of 4");
|
||||||
}
|
}
|
||||||
@@ -167,12 +177,20 @@ void PSOV3Encryption::encrypt(void* vdata, size_t size, bool advance) {
|
|||||||
}
|
}
|
||||||
size >>= 2;
|
size >>= 2;
|
||||||
|
|
||||||
le_uint32_t* data = reinterpret_cast<le_uint32_t*>(vdata);
|
LongT* data = reinterpret_cast<LongT*>(vdata);
|
||||||
for (size_t x = 0; x < size; x++) {
|
for (size_t x = 0; x < size; x++) {
|
||||||
data[x] ^= this->next(advance);
|
data[x] ^= this->next(advance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PSOV3Encryption::encrypt(void* vdata, size_t size, bool advance) {
|
||||||
|
this->encrypt_t<le_uint32_t>(vdata, size, advance);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PSOV3Encryption::encrypt_big_endian(void* vdata, size_t size, bool advance) {
|
||||||
|
this->encrypt_t<be_uint32_t>(vdata, size, advance);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void PSOBBEncryption::decrypt(void* vdata, size_t size, bool advance) {
|
void PSOBBEncryption::decrypt(void* vdata, size_t size, bool advance) {
|
||||||
|
|||||||
@@ -39,10 +39,14 @@ public:
|
|||||||
explicit PSOV2Encryption(uint32_t seed);
|
explicit PSOV2Encryption(uint32_t seed);
|
||||||
|
|
||||||
virtual void encrypt(void* data, size_t size, bool advance = true);
|
virtual void encrypt(void* data, size_t size, bool advance = true);
|
||||||
|
void encrypt_big_endian(void* data, size_t size, bool advance = true);
|
||||||
|
|
||||||
uint32_t next(bool advance = true);
|
uint32_t next(bool advance = true);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
template <typename LongT>
|
||||||
|
void encrypt_t(void* data, size_t size, bool advance);
|
||||||
|
|
||||||
void update_stream();
|
void update_stream();
|
||||||
|
|
||||||
uint32_t stream[V2_STREAM_LENGTH + 1];
|
uint32_t stream[V2_STREAM_LENGTH + 1];
|
||||||
@@ -54,10 +58,14 @@ public:
|
|||||||
explicit PSOV3Encryption(uint32_t key);
|
explicit PSOV3Encryption(uint32_t key);
|
||||||
|
|
||||||
virtual void encrypt(void* data, size_t size, bool advance = true);
|
virtual void encrypt(void* data, size_t size, bool advance = true);
|
||||||
|
void encrypt_big_endian(void* data, size_t size, bool advance = true);
|
||||||
|
|
||||||
uint32_t next(bool advance = true);
|
uint32_t next(bool advance = true);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
template <typename LongT>
|
||||||
|
void encrypt_t(void* data, size_t size, bool advance);
|
||||||
|
|
||||||
void update_stream();
|
void update_stream();
|
||||||
|
|
||||||
uint32_t stream[V3_STREAM_LENGTH];
|
uint32_t stream[V3_STREAM_LENGTH];
|
||||||
|
|||||||
+1
-9
@@ -254,15 +254,7 @@ void send_function_call(
|
|||||||
data.resize((data.size() + 3) & ~3);
|
data.resize((data.size() + 3) & ~3);
|
||||||
PSOV2Encryption crypt(key);
|
PSOV2Encryption crypt(key);
|
||||||
if (code->is_big_endian()) {
|
if (code->is_big_endian()) {
|
||||||
// The code section is decrypted without byteswapping on the client.
|
crypt.encrypt_big_endian(data.data(), data.size());
|
||||||
// Since PowerPC systems (including the GameCube) are usually
|
|
||||||
// big-endian, we have to treat the data the same way here (hence we
|
|
||||||
// can't just use crypt.encrypt).
|
|
||||||
StringReader compressed_r(data);
|
|
||||||
while (!compressed_r.eof()) {
|
|
||||||
w.put_u32b(compressed_r.get_u32b() ^ crypt.next());
|
|
||||||
}
|
|
||||||
data = move(w.str());
|
|
||||||
} else {
|
} else {
|
||||||
crypt.encrypt(data.data(), data.size());
|
crypt.encrypt(data.data(), data.size());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user