1 /*********************************************************************
2 ----------------------------------------------------------------------
7 ----------------------------------------------------------------------
8 *********************************************************************/
15 #include <utility/tagitem.h>
16 #include <workbench/startup.h>
17 #include <workbench/workbench.h>
18 #include <libraries/cybergraphics.h>
19 #include <intuition/intuition.h>
20 #include <exec/memory.h>
22 #include <clib/macros.h>
24 #include <proto/asl.h>
25 #include <proto/exec.h>
26 #include <proto/intuition.h>
27 #include <proto/graphics.h>
28 #include <proto/utility.h>
29 #include <proto/guigfx.h>
30 #include <proto/cybergraphics.h>
32 #include <proto/dos.h>
33 #include <proto/intuition.h>
34 #include <proto/gadtools.h>
35 #include <proto/icon.h>
36 #include <proto/render.h>
38 #include "Mystic_FileHandling.h"
39 #include "Mystic_Subtask.h"
40 #include "Mystic_Keyfile.h"
46 void crcgen(unsigned long *table
)
48 unsigned long crc
, poly
;
52 for (i
=0; i
<256; i
++) {
56 crc
= (crc
>> 1) ^ poly
;
66 unsigned long getcrc(unsigned long *crctable
, char *buffer
, int buffersize
)
68 register unsigned long crc
;
73 for (i
= 0; i
< buffersize
; ++i
)
75 crc
= ((crc
>>8) & 0x00FFFFFF) ^ crctable
[ (crc
^buffer
[i
]) & 0xFF ];
78 return( crc
^0xFFFFFFFF );
84 BOOL
getbit(char *buffer
, int bitnr
)
86 unsigned char mask
= 1 << (7 - (bitnr
& 7));
88 return (BOOL
) !!(buffer
[bitnr
>>3] & mask
);
93 void setbit(char *buffer
, int bitnr
, BOOL bit
)
95 unsigned char mask
= 1 << (7 - (bitnr
& 7));
97 buffer
[bitnr
>>3] &= ~mask
;
100 buffer
[bitnr
>>3] |= mask
;
105 void decode(char *buffer
, int buflen
, unsigned long key
)
112 bitlen
= buflen
<< 3;
116 srand(key
^0x7f532c9a);
118 for (i
= 0; i
< buflen
; ++i
)
125 for (i
= 0; i
< bitlen
/ 2; ++i
)
129 bit1
= !getbit(buffer
, pos1
);
130 bit2
= getbit(buffer
, pos2
);
131 setbit(buffer
, pos1
, bit2
);
132 setbit(buffer
, pos2
, bit1
);
142 struct keyfile
*keyfile
;
143 BOOL keyokay
= FALSE
;
145 if (keyfile
= (struct keyfile
*) FindSemaphore(mypersonalID
))
149 if (buffer
= Malloc(keyfile
->len
))
153 memcpy(buffer
, keyfile
->key
, keyfile
->len
);
154 decode(buffer
, keyfile
->len
, keyfile
->len
);
155 crc
= getcrc(keyfile
->crctable
, buffer
+ 4, keyfile
->len
- 4);
157 if (crc
== *((ULONG
*) buffer
))
178 char *GetKeyLicensee(void)
182 struct keyfile
*keyfile
;
185 if (keyfile
= (struct keyfile
*) FindSemaphore(mypersonalID
))
189 if (buffer
= Malloc(keyfile
->len
))
193 memcpy(buffer
, keyfile
->key
, keyfile
->len
);
194 decode(buffer
, keyfile
->len
, keyfile
->len
);
195 crc
= getcrc(keyfile
->crctable
, buffer
+ 4, keyfile
->len
- 4);
197 if (crc
== *((ULONG
*) buffer
))
199 name
= _StrDup(&buffer
[13]);
223 /*********************************************************************
224 ----------------------------------------------------------------------
228 remove keyfile from memory.
230 ----------------------------------------------------------------------
231 *********************************************************************/
233 void RemoveKey(struct keyfile
*keyfile
)
239 RemSemaphore(&keyfile
->semaphore
);
248 /*********************************************************************
249 ----------------------------------------------------------------------
251 keyfile = InstallKey()
253 install keyfile in memory.
255 ----------------------------------------------------------------------
256 *********************************************************************/
258 struct keyfile
*InstallKey(void)
262 struct keyfile
*keyfile
;
264 BOOL success
= FALSE
;
266 struct FileInfoBlock ALIGNED fib
;
269 if (keyfile
= Malloclear(sizeof(struct keyfile
)))
271 if (fp
= Open("L:MysticView.key", MODE_OLDFILE
))
275 keyfile
->len
= fib
.fib_Size
;
277 if (keyfile
->key
= Malloc(keyfile
->len
))
279 if (Read(fp
, keyfile
->key
, keyfile
->len
) == keyfile
->len
)
281 keyfile
->semaphore
.ss_Link
.ln_Name
= mypersonalID
;
282 keyfile
->semaphore
.ss_Link
.ln_Pri
= 1;
283 crcgen(keyfile
->crctable
);
284 AddSemaphore(&keyfile
->semaphore
);
292 if (!success
&& keyfile
)