forked from elastomania/across
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CRCCHECK.CPP
286 lines (261 loc) · 6.31 KB
/
CRCCHECK.CPP
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#include "all.h"
static int Beallitas = 0;
static unsigned long Crcszam = 0x05b839e45l;
static int Crchiba = 0; // 1 eseten across.exe, 2 eseten readme.txt valtozott,
// 3 eseten kommand line nem across-sal fejezodik
static int Crcellenorizve = 0;
enum { FILE_IS_MISSING = 10, FILE_HAS_CHANGED, FILE_NAME_CHANGED, ACROSS_EXE, README_TXT };
void check_kommand( const char* komline ) {
if( Beallitas )
return;
const char* nevmutato = &komline[strlen( komline ) - 10];
/*FILE* h = fopen( "nev.txt", "wt" );
if( !h )
hiba( "uigruovvruvrvriruvr" );
fprintf( h, "Nev: <%s>", nevmutato );
fclose( h ); */
char tmp[12];
tmp[6] = '.';
tmp[7] = 'e';
tmp[3] = 'o';
tmp[8] = 'x';
tmp[0] = 'a';
tmp[2] = 'r';
tmp[10] = 0;
tmp[5] = 's';
tmp[1] = 'c';
tmp[9] = 'e';
tmp[4] = 's';
if( strcmpi( nevmutato, tmp ) == 0 ) {
for( int i = 0; i < 11; i++ )
tmp[i] = ' ';
return;
}
for( int i = 0; i < 11; i++ )
tmp[i] = ' ';
// Nem stimmel kommand line nev:
Crchiba = 3;
Crcellenorizve = 1;
}
static char* titstring( int azonosito, int masodikbuff = 0 ) {
static char titbuffer1[100];
static char titbuffer2[100];
static int titbufferi[100];
titbufferi[99] = 0;
switch( azonosito ) {
case FILE_IS_MISSING:
titbufferi[0] = 'F';
titbufferi[1] = 'i';
titbufferi[2] = 'l';
titbufferi[3] = 'e';
titbufferi[4] = ' ';
titbufferi[5] = 'i';
titbufferi[6] = 's';
titbufferi[7] = ' ';
titbufferi[8] = 'm';
titbufferi[9] = 'i';
titbufferi[10] = 's';
titbufferi[11] = 's';
titbufferi[12] = 'i';
titbufferi[13] = 'n';
titbufferi[14] = 'g';
titbufferi[15] = '!';
titbufferi[16] = ':';
titbufferi[17] = ' ';
titbufferi[18] = 0;
break;
case FILE_HAS_CHANGED:
titbufferi[0] = 'F';
titbufferi[1] = 'i';
titbufferi[2] = 'l';
titbufferi[3] = 'e';
titbufferi[4] = ' ';
titbufferi[5] = 'h';
titbufferi[6] = 'a';
titbufferi[7] = 's';
titbufferi[8] = ' ';
titbufferi[9] = 'c';
titbufferi[10] = 'h';
titbufferi[11] = 'a';
titbufferi[12] = 'n';
titbufferi[13] = 'g';
titbufferi[14] = 'e';
titbufferi[15] = 'd';
titbufferi[16] = '!';
titbufferi[17] = ':';
titbufferi[18] = ' ';
titbufferi[19] = 0;
break;
case FILE_NAME_CHANGED:
titbufferi[0] = 'F';
titbufferi[1] = 'i';
titbufferi[2] = 'l';
titbufferi[3] = 'e';
titbufferi[4] = ' ';
titbufferi[5] = 'n';
titbufferi[6] = 'a';
titbufferi[7] = 'm';
titbufferi[8] = 'e';
titbufferi[9] = ' ';
titbufferi[10] = 'c';
titbufferi[11] = 'h';
titbufferi[12] = 'a';
titbufferi[13] = 'n';
titbufferi[14] = 'g';
titbufferi[15] = 'e';
titbufferi[16] = 'd';
titbufferi[17] = '!';
titbufferi[18] = ':';
titbufferi[19] = ' ';
titbufferi[20] = 0;
break;
case ACROSS_EXE:
titbufferi[0] = 'a';
titbufferi[1] = 'c';
titbufferi[2] = 'r';
titbufferi[3] = 'o';
titbufferi[4] = 's';
titbufferi[5] = 's';
titbufferi[6] = '.';
titbufferi[7] = 'e';
titbufferi[8] = 'x';
titbufferi[9] = 'e';
titbufferi[10] = 0;
break;
case README_TXT:
titbufferi[0] = 'r';
titbufferi[1] = 'e';
titbufferi[2] = 'a';
titbufferi[3] = 'd';
titbufferi[4] = 'm';
titbufferi[5] = 'e';
titbufferi[6] = '.';
titbufferi[7] = 't';
titbufferi[8] = 'x';
titbufferi[9] = 't';
titbufferi[10] = 0;
break;
default:
hiba( "titstring-ben azonosito default!" );
}
for( int i = 0; i < 100; i++ ) {
if( masodikbuff ) {
titbuffer1[i] = (char)titbufferi[i];
if( !titbuffer1[i] )
return titbuffer1;
}
else {
titbuffer2[i] = (char)titbufferi[i];
if( !titbuffer2[i] )
return titbuffer2;
}
}
hiba( "Bug475876!" );
return titbuffer1;
}
// Valodi file-t nez:
static unsigned long getcrc( char* nev_p, long ellenorzohossz ) {
char nev[40];
strcpy( nev, nev_p );
FILE* h = fopen( nev, "rb" );
if( !h )
return 0;
long hossz = filelength( fileno( h ) );
if( hossz != ellenorzohossz && !Beallitas ) {
//uzenet( "File size has changed!: ", nev );
Crchiba = 1;
return 0;
}
long number = (hossz-3)/4;
unsigned long sum = Crcszam;
for( long l = 0; l < number; l++ ) {
unsigned long ujszam;
if( fread( &ujszam, 1, 4, h ) != 4 )
return 0;
sum ^= ujszam ^ Crcszam;
if( sum > 0x7fffffffl )
sum = (sum << 1) + 1;
else
sum = (sum << 1);
}
fclose( h );
if( Beallitas ) {
FILE* h2 = fopen( "biztlist.txt", "at" );
if( !h2 )
hiba( "!h2!" );
fprintf( h2, "%ld\n%lu\n", hossz, sum );
fclose( h2 );
}
return sum;
}
static unsigned long loadulong( FILE* h ) {
unsigned long ertek = 0xfffffffful;
char sor[200];
if( fgets( sor, 190, h ) == NULL )
hiba( "Nem tudott olvasni sort filebol!" );
if( sscanf( sor, "%lu", &ertek ) != 1 )
hiba( "loadulong-ban nem tudta feldolgozni sort!: ", sor );
if( ertek == 0xfffffffful )
hiba( "loadulong-ban ertek == 0xfffffffful!: ", sor );
return ertek;
}
void crccheck2( void ) {
if( Crchiba ) {
if( Crchiba == 1 )
uzenet( titstring( FILE_HAS_CHANGED ), titstring( ACROSS_EXE, 1 ) );
if( Crchiba == 2 )
uzenet( titstring( FILE_HAS_CHANGED ), titstring( README_TXT, 1 ) );
if( Crchiba == 3 )
uzenet( titstring( FILE_NAME_CHANGED ), titstring( ACROSS_EXE, 1 ) );
}
}
void crccheck( void ) {
// Csak neha megy bele fuggvenybe:
if( !Beallitas ) {
unsigned short egesz, tort;
getbiostort( &egesz, &tort );
if( tort%120 )
return;
}
if( Crcellenorizve )
return;
Crcellenorizve = 1;
long hossz_across_exe = 0, hossz_readme_txt = 0;
unsigned long crc_across_exe = 0, crc_readme_txt = 0;
if( !Beallitas ) {
#ifdef SARVARI
FILE* h = qopen( "bizton_s.txt", "rt" );
#else
FILE* h = qopen( "bizton_r.txt", "rt" );
#endif
if( !h )
hiba( "Nem tudta megnyitni bizton_?.txt file-t!" );
hossz_across_exe = loadulong( h );
crc_across_exe = loadulong( h );
hossz_readme_txt = loadulong( h );
crc_readme_txt = loadulong( h );
qclose( h );
}
if( getcrc( titstring( ACROSS_EXE ), hossz_across_exe ) != crc_across_exe &&
!Beallitas ) {
//uzenet( "File has changed!: ", "across.exe" );
Crchiba = 1;
return;
}
if( Crchiba ) {
Crchiba = 1;
return;
}
if( getcrc( titstring( README_TXT ), hossz_readme_txt ) != crc_readme_txt &&
!Beallitas ) {
//uzenet( "File has changed!: ", "readme.txt" );
Crchiba = 2;
return;
}
if( Crchiba ) {
Crchiba = 2;
return;
}
if( Beallitas )
hiba( "Kiirta kodokat!" );
}