-
Notifications
You must be signed in to change notification settings - Fork 0
/
tkey.c
311 lines (226 loc) · 6.94 KB
/
tkey.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
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#include <stdio.h>
#include <io.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <fcntl.h>
#include <dir.h>
#include <conio.h>
#include <sys\stat.h>
#include <typedefs.h>
#include <video.h>
#include <scrnutil.h>
#include "input.h"
#include "idlekey.h"
#include "message.h"
#define TIMEDCODE 0xFAFA9090L
#define REGSITE 1
typedef struct
{
char rand1[12];
dword generated;
char rand2[10];
dword keyval;
char rand3[7];
dword ascvals;
dword crc2;
char regsite;
word serial;
dword ascvals2;
dword ascvals3;
char rand4[17];
word ascvals4;
word zero;
char rand5[14];
dword total;
char rand6[5];
} STRKEY;
typedef struct
{
char bytes[100];
} ARRKEY;
union KEY
{
STRKEY strkey;
ARRKEY arrkey;
} key;
word serial; // Serial number to use now
//union KEY key;
dword SquishHash(byte *f);
dword JAMsysCrc32(void *pBuf, unsigned int len, dword crc);
void GenerateKey(char *name);
void main(void)
{
int ok;
char name[36],
lowername[36],
number[10],
keyfilename[100],
descfilename[100],
filename[100];
FILE *sfile, *descfile, *logfile;
int keyfile;
BOX *hdr;
char temp[120], keyname[20];
time_t curtime;
video_init();
check_enhanced();
cls();
hdr = initbox(0,0,2,79,113,113,S_VERT,NO, ' ');
drawbox(hdr);
delbox(hdr);
print(1,2,113," timEd key generator ù To be used by Evin Mulron only ù DO NOT DISTRIBUTE!");
if( (sfile = fopen("serial.txt", "r")) == NULL )
{
print(5,0,7,"Can't open serial.txt!");
MoveXY(1,7);
exit(254);
}
if(fgets(number, 9, sfile) == NULL)
{
print(5,0,7,"Can't read serial.txt!");
MoveXY(1,7);
exit(254);
}
fclose(sfile);
serial = atoi(number); // This is the serial number we will now use.
print(4,0,7," þ Reading serial.txt...");
sprintf(temp, " þ Next serial # to be used: %d", serial);
print(5,0,7,temp);
print(6,0,7," þ Registername:");
memset(name, '\0', sizeof(name));
if(getstring(6, 17, name, 35, "", 30) == ESC)
goto Exit;
strcpy(lowername, name);
strlwr(lowername);
print(7,0,7," þ Filename:");
ok=0;
do
{
memset(filename, '\0', sizeof(filename));
if(getstring(7, 13, filename, 65, "", 30) == ESC)
goto Exit;
sprintf(keyfilename, "%s.KEY", filename);
sprintf(descfilename, "%s.ASC", filename);
if( (keyfile=open(keyfilename, O_CREAT | O_EXCL | O_WRONLY | O_BINARY, S_IREAD | S_IWRITE)) == -1)
Message("Error opening file!", -1, 0, YES);
else if( (descfile=fopen(descfilename, "w+")) == NULL)
Message("Error opening file!", -1, 0, YES);
else
ok = 1;
}
while(!ok);
GenerateKey(lowername);
sprintf(temp, " þ Writing keyfile (%s).", keyfilename);
print(8,0,7,temp);
if(write(keyfile, &key, sizeof(key)) != sizeof(key))
{
print(8,0,7, "Error writing keyfile!");
serial--;
close(keyfile);
fclose(descfile);
goto Exit;
}
close(keyfile);
sprintf(temp, " þ Writing msgfile (%s).", descfilename);
print(9,0,7,temp);
fnsplit(keyfilename, NULL, NULL, keyname, NULL);
fprintf(descfile, "\nRegistername: \"%s\"\n\n", name);
fprintf(descfile, "The registration key was calculated using the 'registername'\n");
fprintf(descfile, "listed above. It should correspond with the first NAME listed in\n");
fprintf(descfile, "timEd.cfg\n");
fprintf(descfile, "The file %s.KEY holds your registration key, and should\n", strupr(keyname));
fprintf(descfile, "be renamed to TIMED.KEY in the timEd-directory.\n");
fclose(descfile);
if( (logfile = fopen("tkey.log", "a")) == NULL )
Message("Error opening logile!", -1, 0, YES);
else
{
curtime = time(NULL);
fprintf(logfile, "\n ==> %s\n", ctime(&curtime));
fprintf(logfile, " þ Generated key for : \"%s\"\n", name);
fprintf(logfile, " þ Filename : %s\n", keyfilename);
fprintf(logfile, " þ Serial number : %d\n\n", key.strkey.serial);
fclose(logfile);
}
Exit:
if( (sfile=fopen("serial.txt", "w+")) == NULL )
{
Message("Can't open serial.txt for write!", -1, 0, YES);
exit(254);
}
fprintf(sfile, "%d\n", serial);
fclose(sfile);
print(10,0,7," þ Writing serial.txt...");
print(11,0,7," þ Clean up successful, press any key to exit.");
get_idle_key();
MoveXY(1,20);
_setcursortype(_NORMALCURSOR);
}
// =======================================
// Generate our registration key in here..
// =======================================
void GenerateKey(char *name)
{
dword crc;
dword hash;
dword total = 0L;
char *charptr;
int i;
memset(&key, '\0', sizeof(union KEY));
crc = JAMsysCrc32(name, strlen(name), -1L);
key.strkey.crc2 = JAMsysCrc32(name, strlen(name), 0xFF00FF91L);
hash = SquishHash(name);
for(charptr=name; *charptr; charptr++)
key.strkey.ascvals += ((unsigned char) (*charptr + 27));
for(charptr=name; *charptr; charptr++)
key.strkey.ascvals2 += ((unsigned char) ((*charptr*2) + 3));
for(charptr=name; *charptr; charptr++)
key.strkey.ascvals3 += ((unsigned char) ( ((*charptr/3)*5) + 11) );
for(charptr=name; *charptr; charptr++)
key.strkey.ascvals4 += ((unsigned char) (255 - *charptr));
key.strkey.keyval = ( (crc/3) + (hash/3) + (TIMEDCODE/3) );
key.strkey.generated = time(NULL);
randomize();
for(i=0; i<12; i++)
key.strkey.rand1[i] = (unsigned char) random(255);
key.strkey.rand1[5] = 0;
for(i=0; i<10; i++)
key.strkey.rand2[i] = (unsigned char) random(255);
key.strkey.rand2[3] = 0;
for(i=0; i<7; i++)
key.strkey.rand3[i] = (unsigned char) random(255);
for(i=0; i<17; i++)
key.strkey.rand4[i] = (unsigned char) random(255);
key.strkey.rand4[7] = 0;
for(i=0; i<14; i++)
key.strkey.rand5[i] = (unsigned char) random(255);
key.strkey.rand5[1] = 0;
for(i=0; i<5; i++)
key.strkey.rand6[i] = (unsigned char) random(255);
key.strkey.serial = serial++;
key.strkey.regsite = REGSITE;
for(i=0; i<100; i++)
total += key.arrkey.bytes[i];
key.strkey.total = total;
}
// =============================================
// Calculate the hash value for a certain string
// =============================================
dword SquishHash(byte *f)
{
dword hash=0, g;
char *p;
for (p=f; *p; p++)
{
hash=(hash << 4) + tolower(*p);
if ((g=(hash & 0xf0000000L)) != 0L)
{
hash |= g >> 24;
hash |= g;
}
}
/* Strip off high bit */
return (hash & 0x7fffffffLu);
}