From cf10dadb91bfe72335e3c6f2a4e6fbb439a4d129 Mon Sep 17 00:00:00 2001 From: galaxyhaxz Date: Wed, 26 Sep 2018 17:49:30 -0500 Subject: [PATCH] Correct function names in "encrypt.cpp" (#344) --- Source/diablo.cpp | 2 +- Source/encrypt.cpp | 36 ++++++++++++++++++------------------ Source/encrypt.h | 19 +++++++++---------- Source/mpqapi.cpp | 42 +++++++++++++++++++++--------------------- Source/msg.cpp | 4 ++-- 5 files changed, 51 insertions(+), 52 deletions(-) diff --git a/Source/diablo.cpp b/Source/diablo.cpp index d6bf2c3d0..6880997a3 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -299,7 +299,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine } ShowCursor(FALSE); srand(GetTickCount()); - encrypt_init_lookup_table(); + InitHash(); exception_get_filter(); if ( !diablo_find_window("DIABLO") && diablo_get_not_running() ) { diff --git a/Source/encrypt.cpp b/Source/encrypt.cpp index 22130c0e6..b548f45af 100644 --- a/Source/encrypt.cpp +++ b/Source/encrypt.cpp @@ -2,9 +2,9 @@ #include "../types.h" -int encrypt_table[1280]; +int hashtable[1280]; -void __fastcall encrypt_decrypt_block(void *block, int size, int key) // DecryptMPQBlock +void __fastcall Decrypt(void *block, int size, int key) { unsigned int v3; // edx int v4; // eax @@ -21,7 +21,7 @@ void __fastcall encrypt_decrypt_block(void *block, int size, int key) // Decrypt v6 = key; do { - v7 = encrypt_table[(unsigned char)v6 + 1024] + v4; + v7 = hashtable[(unsigned char)v6 + 1024] + v4; *(_DWORD *)block ^= v7 + v6; v8 = *(_DWORD *)block; block = (char *)block + 4; @@ -33,7 +33,7 @@ void __fastcall encrypt_decrypt_block(void *block, int size, int key) // Decrypt } } -void __fastcall encrypt_encrypt_block(void *block, int size, int key) // EncryptMPQBlock +void __fastcall Encrypt(void *block, int size, int key) { unsigned int v3; // edx int v4; // eax @@ -50,7 +50,7 @@ void __fastcall encrypt_encrypt_block(void *block, int size, int key) // Encrypt v6 = key; do { - v7 = encrypt_table[(unsigned char)v6 + 1024] + v4; + v7 = hashtable[(unsigned char)v6 + 1024] + v4; v8 = *(_DWORD *)block ^ (v7 + v6); v4 = 33 * v7 + *(_DWORD *)block + 3; *(_DWORD *)block = v8; @@ -62,7 +62,7 @@ void __fastcall encrypt_encrypt_block(void *block, int size, int key) // Encrypt } } -int __fastcall encrypt_hash(char *s, int type) // HashStringSlash +int __fastcall Hash(char *s, int type) { int v2; // ebp char *v3; // ebx @@ -79,13 +79,13 @@ int __fastcall encrypt_hash(char *s, int type) // HashStringSlash { v6 = *v3++; v7 = toupper(v6); - v4 = (v5 + v4) ^ encrypt_table[v7 + (v2 << 8)]; + v4 = (v5 + v4) ^ hashtable[v7 + (v2 << 8)]; v5 = v7 + 33 * v5 + v4 + 3; } return v4; } -void __cdecl encrypt_init_lookup_table() // InitScratchSpace +void __cdecl InitHash() { unsigned int v0; // eax int *v1; // edi @@ -95,7 +95,7 @@ void __cdecl encrypt_init_lookup_table() // InitScratchSpace int *v5; // [esp+10h] [ebp-4h] v0 = 0x100001; - v5 = encrypt_table; + v5 = hashtable; do { v1 = v5; @@ -112,10 +112,10 @@ void __cdecl encrypt_init_lookup_table() // InitScratchSpace while ( v4 ); ++v5; } - while ( (signed int)v5 < (signed int)&encrypt_table[256] ); + while ( (signed int)v5 < (signed int)&hashtable[256] ); } -int __fastcall encrypt_compress(void *buf, int size) // MPQCompress_PKWare +int __fastcall PkwareCompress(void *buf, int size) { unsigned char *v2; // ebx unsigned char *v3; // esi @@ -141,8 +141,8 @@ int __fastcall encrypt_compress(void *buf, int size) // MPQCompress_PKWare param.pbSize = v3; dsize = 4096; implode( - encrypt_pkware_read, - encrypt_pkware_write, + PkwareBufferRead, + PkwareBufferWrite, ptr, ¶m, &type, @@ -157,7 +157,7 @@ int __fastcall encrypt_compress(void *buf, int size) // MPQCompress_PKWare return (int)v3; } -unsigned int __cdecl encrypt_pkware_read(char *buf, unsigned int *size, void *param) // ReadPKWare +unsigned int __cdecl PkwareBufferRead(char *buf, unsigned int *size, void *param) { TDataInfo * pInfo = (TDataInfo *)param; int v3; // edi @@ -172,7 +172,7 @@ unsigned int __cdecl encrypt_pkware_read(char *buf, unsigned int *size, void *pa return v3; } -void __cdecl encrypt_pkware_write(char *buf, unsigned int *size, void *param) // WritePKWare +void __cdecl PkwareBufferWrite(char *buf, unsigned int *size, void *param) { TDataInfo * pInfo = (TDataInfo *)param; @@ -180,7 +180,7 @@ void __cdecl encrypt_pkware_write(char *buf, unsigned int *size, void *param) // pInfo->pbOutBuffEnd += *size; } -void __fastcall encrypt_decompress(void *param, int recv_size, int dwMaxBytes) // MPQDecompress_PKWare +void __fastcall PkwareDecompress(void *param, int recv_size, int dwMaxBytes) { unsigned char *v3; // edi unsigned char *v4; // ebx @@ -198,8 +198,8 @@ void __fastcall encrypt_decompress(void *param, int recv_size, int dwMaxBytes) / info.pbOutBuff = v5; info.pbSize = v4; explode( - encrypt_pkware_read, - encrypt_pkware_write, + PkwareBufferRead, + PkwareBufferWrite, ptr, &info); memcpy(v3, v5, (size_t)info.pbOutBuffEnd); diff --git a/Source/encrypt.h b/Source/encrypt.h index f3c150b84..20673fa9c 100644 --- a/Source/encrypt.h +++ b/Source/encrypt.h @@ -2,16 +2,15 @@ #ifndef __ENCRYPT_H__ #define __ENCRYPT_H__ -extern int encrypt_table[1280]; -//int encrypt_52B564[257]; +extern int hashtable[1280]; -void __fastcall encrypt_decrypt_block(void *block, int size, int key); -void __fastcall encrypt_encrypt_block(void *block, int size, int key); -int __fastcall encrypt_hash(char *s, int type); -void __cdecl encrypt_init_lookup_table(); -int __fastcall encrypt_compress(void *buf, int size); -unsigned int __cdecl encrypt_pkware_read(char *buf, unsigned int *size, void *param); -void __cdecl encrypt_pkware_write(char *buf, unsigned int *size, void *param); -void __fastcall encrypt_decompress(void *param, int recv_size, int dwMaxBytes); +void __fastcall Decrypt(void *block, int size, int key); +void __fastcall Encrypt(void *block, int size, int key); +int __fastcall Hash(char *s, int type); +void __cdecl InitHash(); +int __fastcall PkwareCompress(void *buf, int size); +unsigned int __cdecl PkwareBufferRead(char *buf, unsigned int *size, void *param); +void __cdecl PkwareBufferWrite(char *buf, unsigned int *size, void *param); +void __fastcall PkwareDecompress(void *param, int recv_size, int dwMaxBytes); #endif /* __ENCRYPT_H__ */ diff --git a/Source/mpqapi.cpp b/Source/mpqapi.cpp index 4ae202a61..215baa363 100644 --- a/Source/mpqapi.cpp +++ b/Source/mpqapi.cpp @@ -259,9 +259,9 @@ int __fastcall mpqapi_get_hash_index_of_path(char *pszName) // FetchHandle short v4; // ax v1 = pszName; - v2 = encrypt_hash(pszName, 2); // MPQ_HASH_NAME_B - v3 = encrypt_hash(v1, 1); // MPQ_HASH_NAME_A - v4 = encrypt_hash(v1, 0); // MPQ_HASH_TABLE_INDEX + v2 = Hash(pszName, 2); // MPQ_HASH_NAME_B + v3 = Hash(v1, 1); // MPQ_HASH_NAME_A + v4 = Hash(v1, 0); // MPQ_HASH_TABLE_INDEX return mpqapi_get_hash_index(v4, v3, v2, 0); } @@ -343,9 +343,9 @@ _BLOCKENTRY *__fastcall mpqapi_add_file(char *pszName, _BLOCKENTRY *pBlk, int bl v12 = pBlk; v3 = pszName; - v4 = encrypt_hash(pszName, 0); - v5 = encrypt_hash(v3, 1); - v11 = encrypt_hash(v3, 2); + v4 = Hash(pszName, 0); + v5 = Hash(v3, 1); + v11 = Hash(v3, 2); if ( mpqapi_get_hash_index(v4, v5, v11, 0) != -1 ) TermMsg("Hash collision between \"%s\" and existing file\n", v3); v6 = 2048; @@ -409,7 +409,7 @@ bool __fastcall mpqapi_write_file_contents(char *pszName, char *pbData, int dwLe break; v4 = v7 + 1; } - encrypt_hash(v4, 3); + Hash(v4, 3); v8 = dwLen; v9 = pBlk; size = 4 * ((unsigned int)(dwLen + 4095) >> 12) + 4; @@ -433,7 +433,7 @@ bool __fastcall mpqapi_write_file_contents(char *pszName, char *pbData, int dwLe dwLen = 4096; memcpy(mpq_buf, v17, dwLen); v17 += dwLen; - dwLen = encrypt_compress(mpq_buf, dwLen); + dwLen = PkwareCompress(mpq_buf, dwLen); if ( !v18 ) { nNumberOfBytesToWrite = size; @@ -556,7 +556,7 @@ bool __fastcall mpqapi_open_archive(char *pszArchive, bool hidden, int dwChar) / v3 = pszArchive; v4 = hidden; lpFileName = pszArchive; - encrypt_init_lookup_table(); + InitHash(); if ( !mpqapi_set_hidden(v3, v4) ) return 0; v6 = (unsigned char)gbMaxPlayers > 1u ? FILE_FLAG_WRITE_THROUGH : 0; @@ -588,8 +588,8 @@ LABEL_15: { goto LABEL_15; } - v8 = encrypt_hash("(block table)", 3); - encrypt_decrypt_block(sgpBlockTbl, 0x8000, v8); + v8 = Hash("(block table)", 3); + Decrypt(sgpBlockTbl, 0x8000, v8); } sgpHashTbl = (_HASHENTRY *)DiabloAllocPtr(0x8000); memset(sgpHashTbl, 255, 0x8000u); @@ -600,8 +600,8 @@ LABEL_15: { goto LABEL_15; } - v10 = encrypt_hash("(hash table)", 3); - encrypt_decrypt_block(sgpHashTbl, 0x8000, v10); + v10 = Hash("(hash table)", 3); + Decrypt(sgpHashTbl, 0x8000, v10); } } return 1; @@ -767,11 +767,11 @@ bool __cdecl mpqapi_write_block_table() if ( SetFilePointer(sghArchive, 104, NULL, FILE_BEGIN) == -1 ) return 0; - v1 = encrypt_hash("(block table)", 3); - encrypt_encrypt_block(sgpBlockTbl, 0x8000, v1); + v1 = Hash("(block table)", 3); + Encrypt(sgpBlockTbl, 0x8000, v1); v2 = WriteFile(sghArchive, sgpBlockTbl, 0x8000u, &NumberOfBytesWritten, 0); - v3 = encrypt_hash("(block table)", 3); - encrypt_decrypt_block(sgpBlockTbl, 0x8000, v3); + v3 = Hash("(block table)", 3); + Decrypt(sgpBlockTbl, 0x8000, v3); return v2 && NumberOfBytesWritten == 0x8000; } @@ -784,11 +784,11 @@ bool __cdecl mpqapi_write_hash_table() if ( SetFilePointer(sghArchive, 32872, NULL, FILE_BEGIN) == -1 ) return 0; - v1 = encrypt_hash("(hash table)", 3); - encrypt_encrypt_block(sgpHashTbl, 0x8000, v1); + v1 = Hash("(hash table)", 3); + Encrypt(sgpHashTbl, 0x8000, v1); v2 = WriteFile(sghArchive, sgpHashTbl, 0x8000u, &NumberOfBytesWritten, 0); - v3 = encrypt_hash("(hash table)", 3); - encrypt_decrypt_block(sgpHashTbl, 0x8000, v3); + v3 = Hash("(hash table)", 3); + Decrypt(sgpHashTbl, 0x8000, v3); return v2 && NumberOfBytesWritten == 0x8000; } diff --git a/Source/msg.cpp b/Source/msg.cpp index e4aac8588..2998b53e3 100644 --- a/Source/msg.cpp +++ b/Source/msg.cpp @@ -396,7 +396,7 @@ int __fastcall msg_comp_level(char *buffer, int size) v2 = buffer; v3 = size - (_DWORD)buffer - 1; - v4 = encrypt_compress(buffer + 1, v3); + v4 = PkwareCompress(buffer + 1, v3); *v2 = v3 != v4; return v4 + 1; } @@ -1598,7 +1598,7 @@ void __fastcall DeltaImportData(unsigned char cmd, int recv_offset) v2 = cmd; if ( sgRecvBuf[0] ) - encrypt_decompress(&sgRecvBuf[1], recv_offset, 4721); + PkwareDecompress(&sgRecvBuf[1], recv_offset, 4721); if ( v2 == CMD_DLEVEL_JUNK ) { DeltaImportJunk((int)&sgRecvBuf[1]);