rodecomp/Source/Archive/PakCrypto.cpp
ragnarok-clanker d77e77bb82 Decompile fn_18121 (myGPack::DecryptPakData)
Batch #16304 by Yommy: 0 byte-identical, 1 confirmed by peer review.

- fn_18121 myGPack::DecryptPakData: logic confirmed by peer review

Peer-reviewed-by: youko, bgamez23
Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes).
2026-11-10 16:54:37 +00:00

46 lines
1.2 KiB
C++

#include "Archive/PakCrypto.h"
#include <cstring>
#include <wincrypt.h>
namespace myGPack {
// OFFSET: 0x00AEA5C0
// FUNCTION: fn_18121
int DecryptPakData(const BYTE* secret, DWORD secretSize, const BYTE* input, BYTE* output, DWORD dataSize) {
HCRYPTPROV provider = 0;
HCRYPTKEY key = 0;
HCRYPTHASH hash = 0;
DWORD length = dataSize;
DWORD result = 0;
std::memcpy(output, input, length);
try {
if (!CryptAcquireContextA(&provider, nullptr, nullptr, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
throw GetLastError();
}
if (!CryptCreateHash(provider, CALG_MD5, 0, 0, &hash)) {
throw GetLastError();
}
if (!CryptHashData(hash, secret, secretSize, 0)) {
throw GetLastError();
}
if (!CryptDeriveKey(provider, CALG_RC4, hash, CRYPT_EXPORTABLE, &key)) {
throw GetLastError();
}
if (!CryptDecrypt(key, 0, TRUE, 0, output, &length)) {
throw GetLastError();
}
} catch (DWORD error) {
result = error;
}
if (key != 0) {
CryptDestroyKey(key);
}
if (hash != 0) {
CryptDestroyHash(hash);
}
if (provider != 0) {
CryptReleaseContext(provider, 0);
}
return result;
}
}