Browse Source

Clean up codec_encode.

pull/114/head
Sergey Semushin 7 years ago committed by Anders Jenbo
parent
commit
01bc47c7fc
  1. 70
      Source/codec.cpp
  2. 2
      Source/codec.h

70
Source/codec.cpp

@ -87,52 +87,40 @@ DWORD codec_get_encoded_len(DWORD dwSrcBytes)
return dwSrcBytes + 8; return dwSrcBytes + 8;
} }
void codec_encode(void *pbSrcDst, int size, int size_64, char *pszPassword) void codec_encode(BYTE* pbSrcDst, DWORD size, int size_64, char *pszPassword)
{ {
char *v4; // esi char buf[128];
char v5; // bl char tmp[20];
size_t v6; // edi char dst[20];
signed int v7; // ecx DWORD chunk;
char v9[128]; // [esp+8h] [ebp-ACh] WORD last_chunk;
char v10[20]; // [esp+88h] [ebp-2Ch]
char dst[20]; // [esp+9Ch] [ebp-18h]
size_t v12; // [esp+B0h] [ebp-4h]
v4 = (char *)pbSrcDst;
v12 = size;
if (size_64 != codec_get_encoded_len(size)) if (size_64 != codec_get_encoded_len(size))
app_fatal("Invalid encode parameters"); app_fatal("Invalid encode parameters");
codec_init_key(1, pszPassword); codec_init_key(1, pszPassword);
v5 = 0;
if (v12) { last_chunk = 0;
do { while (size != 0) {
v6 = v12; chunk = size < 64 ? size : 64;
if (v12 >= 0x40) memcpy(buf, pbSrcDst, chunk);
v6 = 64; if (chunk < 64)
memcpy(v9, v4, v6); memset(buf + chunk, 0, 64 - chunk);
if (v6 < 0x40) SHA1Result(0, dst);
memset(&v9[v6], 0, 64 - v6); SHA1Calculate(0, buf, NULL);
SHA1Result(0, dst); for (int j = 0; j < 64; j++) {
SHA1Calculate(0, v9, NULL); buf[j] ^= dst[j % 20];
v7 = 0; }
do { memset(dst, 0, sizeof(dst));
v9[v7] ^= dst[v7 % 20]; memcpy(pbSrcDst, buf, 64);
++v7; last_chunk = chunk;
} while (v7 < 64); pbSrcDst += 64;
memset(dst, 0, sizeof(dst)); size -= chunk;
memcpy(v4, v9, 0x40u);
v4 += 64;
v12 -= v6;
} while (v12);
v5 = v6;
} }
memset(v9, 0, sizeof(v9)); memset(buf, 0, sizeof(buf));
SHA1Result(0, v10); SHA1Result(0, tmp);
v4[4] = 0; pbSrcDst[4] = 0;
*((_WORD *)v4 + 3) = 0; ((WORD *)pbSrcDst)[3] = 0;
*(_DWORD *)v4 = *(_DWORD *)v10; ((DWORD *)pbSrcDst)[0] = ((DWORD *)tmp)[0];
v4[5] = v5; pbSrcDst[5] = last_chunk;
SHA1Clear(); SHA1Clear();
} }
// 4036BE: using guessed type char var_AC[128];
// 4036BE: using guessed type char dst[20];

2
Source/codec.h

@ -5,6 +5,6 @@
int codec_decode(BYTE *pbSrcDst, DWORD size, char *pszPassword); int codec_decode(BYTE *pbSrcDst, DWORD size, char *pszPassword);
void codec_init_key(int unused, char *pszPassword); void codec_init_key(int unused, char *pszPassword);
DWORD codec_get_encoded_len(DWORD dwSrcBytes); DWORD codec_get_encoded_len(DWORD dwSrcBytes);
void codec_encode(void *pbSrcDst, int size, int size_64, char *pszPassword); void codec_encode(BYTE* pbSrcDst, DWORD size, int size_64, char *pszPassword);
#endif /* __CODEC_H__ */ #endif /* __CODEC_H__ */

Loading…
Cancel
Save