Skip to content

Commit

Permalink
try to detect even older unencrypted pak format
Browse files Browse the repository at this point in the history
  • Loading branch information
devinacker committed May 7, 2021
1 parent 29566df commit eddbd1b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ struct PakHeader
};
#pragma pack()

static const DWORD PakMagic = 0x5a6f12e1;

// track encrypted index locations that we've found
struct PakIndex
{
Expand Down Expand Up @@ -77,7 +79,7 @@ static void CheckPakHeader(HANDLE hFile, const PakHeaderOld *header, const GUID
WCHAR path[MAX_PATH];
GetFinalPathNameByHandleW(hFile, path, MAX_PATH, 0);

if (header->bEncrypted)
if (header != NULL && header->bEncrypted)
{
SendStringMessage(L"Reading pak info for %ws (encrypted)", path);

Expand Down Expand Up @@ -191,14 +193,18 @@ static BOOL WINAPI hook_ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nSize, LPD

if (ok)
{
if (*lpSize >= sizeof(PakHeader) && header->data.magic == 0x5a6f12e1)
if (*lpSize >= sizeof(PakHeader) && header->data.magic == PakMagic)
{
CheckPakHeader(hFile, &header->data, &header->guid);
}
else if (*lpSize >= sizeof(PakHeaderOld) && headerOld->magic == 0x5a6f12e1)
else if (*lpSize >= sizeof(PakHeaderOld) && headerOld->magic == PakMagic)
{
CheckPakHeader(hFile, headerOld);
}
else if (*lpSize >= sizeof(DWORD) && *(DWORD*)lpBuffer == PakMagic)
{
CheckPakHeader(hFile, NULL);
}
else for (auto &index : g_pakIndexes)
{
// see if we're reading the encrypted index for one of the pak files we found earlier
Expand Down

0 comments on commit eddbd1b

Please sign in to comment.