rodecomp/Source/Archive/PakCrypto.cpp
ragnarok-clanker 07897c8bea Maintenance: Annotation cleanup, no code change (resubmission of 10984). Every // FUNCTION: line now has // OFFSET: <its address from
Batch #11163 by ragnarok-clanker: no function's compiled code changes; checked with 226 compiled unit(s), including every includer of Source/Client/Application/UnhandledExceptionHandler.h, Source/Contents/ReputeMgrLoad.inl, Source/Render/RenderSystemBase.h, Source/UI/Lists/UIListBoxTemplate.h, Source/Utility/Async/NRecycleObject.h.
2026-11-04 21:29:46 +00:00

45 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 result = 0;
std::memcpy(output, input, dataSize);
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, &dataSize)) {
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;
}
}