-
Notifications
You must be signed in to change notification settings - Fork 6
/
Crc32.c
251 lines (232 loc) · 6.96 KB
/
Crc32.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/* This file was generated by the Hex-Rays decompiler.
Copyright (c) 2007-2020 Hex-Rays <[email protected]>
Detected compiler: Visual C++
*/
#include <windows.h>
#include <defs.h>
//-------------------------------------------------------------------------
// Function declarations
#define __thiscall __cdecl // Test compile in C mode
CFvCrc32 *__thiscall CFvCrc32::CFvCrc32(CFvCrc32 *this);
char __thiscall CFvCrc32::Crc32Mem(CFvCrc32 *this, unsigned __int8 *a2, unsigned int a3, unsigned int *a4);
char __thiscall CFvCrc32::Crc32MemCont(CFvCrc32 *this, unsigned __int8 *a2, unsigned int a3, unsigned int *a4);
char __thiscall CFvCrc32::Crc32File(CFvCrc32 *this, LPCSTR lpFileName, unsigned int *a3);
char __thiscall CFvCrc32::Crc32FileRange(CFvCrc32 *this, LPCSTR lpFileName, LONG lDistanceToMove, unsigned int a4, unsigned int *a5);
char __thiscall CFvCrc32::Crc32FileRangeCont(CFvCrc32 *this, LPCSTR lpFileName, LONG lDistanceToMove, unsigned int a4, unsigned int *a5);
// BOOL __stdcall CloseHandle(HANDLE hObject);
// BOOL __stdcall ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped);
// HANDLE __stdcall CreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
// DWORD __stdcall SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod);
//----- (00000000) --------------------------------------------------------
CFvCrc32 *__thiscall CFvCrc32::CFvCrc32(CFvCrc32 *this)
{
CFvCrc32 *result; // eax
int v2; // esi
CFvCrc32 *v3; // edi
unsigned int v4; // edx
int v5; // ebx
result = this;
v2 = 0;
v3 = this;
do
{
v4 = v2;
v5 = 8;
do
{
if ( (v4 & 1) != 0 )
v4 = (v4 >> 1) ^ 0xEDB88320;
else
v4 >>= 1;
--v5;
}
while ( v5 );
*(_DWORD *)v3 = v4;
++v2;
v3 = (CFvCrc32 *)((char *)v3 + 4);
}
while ( v2 < 256 );
return result;
}
//----- (00000050) --------------------------------------------------------
char __thiscall CFvCrc32::Crc32Mem(CFvCrc32 *this, unsigned __int8 *a2, unsigned int a3, unsigned int *a4)
{
*a4 = -1;
CFvCrc32::Crc32MemCont(this, a2, a3, a4);
*a4 = ~*a4;
return 1;
}
//----- (00000080) --------------------------------------------------------
char __thiscall CFvCrc32::Crc32MemCont(CFvCrc32 *this, unsigned __int8 *a2, unsigned int a3, unsigned int *a4)
{
unsigned __int8 *v4; // eax
char result; // al
unsigned int v7; // ecx
v4 = a2;
if ( a2 )
{
if ( a2 < &a2[a3] )
{
do
{
v7 = (*a4 >> 8) ^ *((_DWORD *)this + (*(unsigned __int8 *)a4 ^ *v4++));
*a4 = v7;
}
while ( v4 < &a2[a3] );
}
result = 1;
}
else
{
*((_DWORD *)this + 256) = 1;
result = 0;
}
return result;
}
//----- (000000D0) --------------------------------------------------------
char __thiscall CFvCrc32::Crc32File(CFvCrc32 *this, LPCSTR lpFileName, unsigned int *a3)
{
HANDLE v4; // edi
char result; // al
char *v6; // ecx
char *i; // eax
unsigned int v8; // edx
DWORD NumberOfBytesRead; // [esp+Ch] [ebp-1004h] BYREF
char Buffer[4096]; // [esp+10h] [ebp-1000h] BYREF
*a3 = -1;
if ( lpFileName && *lpFileName )
{
v4 = CreateFileA(lpFileName, 0x80000000, 3u, 0, 3u, 0x80u, 0);
if ( v4 == (HANDLE)-1 )
{
*((_DWORD *)this + 256) = 2;
result = 0;
}
else
{
if ( ReadFile(v4, Buffer, 0x1000u, &NumberOfBytesRead, 0) )
{
while ( NumberOfBytesRead )
{
v6 = &Buffer[NumberOfBytesRead];
for ( i = Buffer; i < v6; *a3 = v8 )
v8 = (*a3 >> 8) ^ *((_DWORD *)this + ((unsigned __int8)*i++ ^ *(unsigned __int8 *)a3));
if ( !ReadFile(v4, Buffer, 0x1000u, &NumberOfBytesRead, 0) )
goto LABEL_12;
}
}
else
{
LABEL_12:
*((_DWORD *)this + 256) = 3;
}
CloseHandle(v4);
*a3 = ~*a3;
result = 1;
}
}
else
{
*((_DWORD *)this + 256) = 1;
result = 0;
}
return result;
}
// 1AD: conditional instruction was optimized away because of 'eax.4!=0'
//----- (000001F0) --------------------------------------------------------
char __thiscall CFvCrc32::Crc32FileRange(CFvCrc32 *this, LPCSTR lpFileName, LONG lDistanceToMove, unsigned int a4, unsigned int *a5)
{
char result; // al
*a5 = -1;
CFvCrc32::Crc32FileRangeCont(this, lpFileName, lDistanceToMove, a4, a5);
result = 1;
*a5 = ~*a5;
return result;
}
//----- (00000220) --------------------------------------------------------
char __thiscall CFvCrc32::Crc32FileRangeCont(CFvCrc32 *this, LPCSTR lpFileName, LONG lDistanceToMove, unsigned int a4, unsigned int *a5)
{
CFvCrc32 *v5; // esi
HANDLE v6; // ebx
char result; // al
BOOL v8; // eax
char *v10; // ecx
char *v11; // edx
unsigned int v12; // eax
BOOL v14; // [esp+Ch] [ebp-100Ch]
DWORD NumberOfBytesRead; // [esp+10h] [ebp-1008h] BYREF
HANDLE v16; // [esp+14h] [ebp-1004h]
char Buffer[4096]; // [esp+18h] [ebp-1000h] BYREF
v5 = this;
if ( lpFileName && *lpFileName )
{
v6 = CreateFileA(lpFileName, 0x80000000, 3u, 0, 3u, 0x80u, 0);
v16 = v6;
if ( v6 == (HANDLE)-1 )
{
*((_DWORD *)v5 + 256) = 2;
result = 0;
}
else if ( SetFilePointer(v6, lDistanceToMove, 0, 0) == -1 )
{
*((_DWORD *)v5 + 256) = 4;
CloseHandle(v6);
result = 0;
}
else
{
v8 = ReadFile(v6, Buffer, 0x1000u, &NumberOfBytesRead, 0);
v14 = v8;
if ( v8 )
{
while ( NumberOfBytesRead )
{
v10 = Buffer;
if ( a4 <= NumberOfBytesRead )
{
v11 = &Buffer[a4];
a4 = 0;
}
else
{
v11 = &Buffer[NumberOfBytesRead];
a4 -= NumberOfBytesRead;
}
if ( Buffer < v11 )
{
do
{
v12 = (*a5 >> 8) ^ *((_DWORD *)this + (*(unsigned __int8 *)a5 ^ (unsigned __int8)*v10++));
*a5 = v12;
}
while ( v10 < v11 );
v6 = v16;
v8 = v14;
}
if ( !a4 )
break;
v8 = ReadFile(v6, Buffer, 0x1000u, &NumberOfBytesRead, 0);
v14 = v8;
if ( !v8 )
goto LABEL_19;
}
if ( v8 )
goto LABEL_21;
LABEL_19:
v5 = this;
}
*((_DWORD *)v5 + 256) = 3;
LABEL_21:
CloseHandle(v6);
result = 1;
}
}
else
{
*((_DWORD *)this + 256) = 1;
result = 0;
}
return result;
}
// nfuncs=12 queued=6 decompiled=6 lumina nreq=0 worse=0 better=0
// ALL OK, 6 function(s) have been successfully decompiled