/[dtapublic]/projs/trunk/projs/20161007_filehash/filehash.c
ViewVC logotype

Contents of /projs/trunk/projs/20161007_filehash/filehash.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 36 - (show annotations) (download)
Tue Oct 11 03:31:12 2016 UTC (7 years, 9 months ago) by dashley
File MIME type: text/plain
File size: 106932 byte(s)
"swprojs" renamed to "projs" to reflect that some projects are not software-based or don't involve
software source code.
1 //----------------------------------------------------------------------------------------------------
2 //FILEHASH--Calculates the SHA-512 cryptographic hash (also known as a message
3 // digest) of computer files, as defined by FIPS 180-3.
4 //Copyright (C) 2010, David T. Ashley.
5 //
6 //This program is free software: you can redistribute it and/or modify
7 //it under the terms of the GNU General Public License as published by
8 //the Free Software Foundation, either version 3 of the License, or
9 //(at your option) any later version.
10 //
11 //This program is distributed in the hope that it will be useful,
12 //but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 //GNU General Public License for more details.
15 //
16 //You should have received a copy of the GNU General Public License
17 //along with this program. If not, see <http://www.gnu.org/licenses/>.
18 //(A copy of the GNU General Public License, Version 3 is provided at
19 //the end of this source file.)
20 //
21 //David T. Ashley can be contacted at DASHLEY@GMAIL.COM and/or at
22 //P.O. Box 918, Marshall MI 49068.
23 //----------------------------------------------------------------------------------------------------
24 #include <windows.h>
25 #include <commdlg.h>
26
27 #include <assert.h>
28 #include <process.h>
29 #include <stdio.h>
30
31 #include "resource.h"
32
33
34 #define FILEHASH_MAXFILES (200)
35 //Maximum number of files that will be processed and displayed.
36 //Limited to avoid filling up the edit control's buffer.
37
38 #define FILEHASH_DISPBUFLEN (55000)
39 //The point at which we say the edit control buffer has too
40 //many characters in it.
41
42 #define FILEHASH_FILE_READ_BUF_SIZE (0x10000)
43 //The number of bytes for each read buffer. It is difficult to know
44 //how to size this value. On one hand, larger is better, as it
45 //enables the disk to operate in blocks. On the other hand, too
46 //large is probably not a good idea, as it will take a lot of
47 //time to fill the buffer (several disk seeks). Suspect that 16K-64K
48 //is about the optimum, but may go larger, anyway.
49
50 static char FILEHASH_dialog_file_open_buffer[15000];
51 //Buffer from the "open files" dialog box, for it to store results
52 //in.
53
54 static char FILEHASH_dispbuf[FILEHASH_DISPBUFLEN+1];
55 //The buffer which holds the contents of the edit control (the main control, the
56 //text box). This is a mirror buffer, probably not a very efficient way of doing
57 //things.
58
59 static int FILEHASH_use_sound = 1;
60 //Remembers the state of the "use sound" option. Default is YES.
61
62 static int FILEHASH_always_on_top = 1;
63 //Remembers whether the main window should always be on top.
64 //This can be annoying in some contexts, so it can be turned off.
65
66 #define WM_USER_EV_CHILD_THREAD_PROGRESS (WM_USER + 1)
67 //The child thread has progress to report (updated information that
68 //can be used by the parent).
69
70 #define WM_USER_EV_CHILD_THREAD_ENDING (WM_USER + 2)
71 //The child thread is reporting that it is ending. After this event is
72 //posted for the parent, there may be some delay until the thread is actually
73 //terminated, so additional OS interaction is required to know the thread
74 //is actually dead.
75
76 static char FILEHASH_szAppName[] = "FileHash";
77 //The application name.
78
79 static WNDPROC FILEHASH_old_win_edit_handler = NULL;
80 //The old edit control handler. This is used to remember the function pointer,
81 //in order to subclass the behavior, because we must catch the drop files event.
82
83 static volatile int FILEHASH_thread_abort_request = 0;
84 //This is set TRUE by the main thread if the child thread
85 //should abort. This means the application will terminate
86 //(this is the only reason for setting this flag). This
87 //variable is set by the main thread and read by the
88 //child thread.
89
90 static DWORD FILEHASH_parent_thread_id = 0;
91 //The thread ID of the parent obtained using the
92 //GetCurrentThreadId() call. The child needs to know this
93 //in order to post a message.
94
95 static HWND FILEHASH_parent_thread_main_window_handle = 0;
96 //Window handle of main window.
97
98 static int FILEHASH_child_thread_is_active = 0;
99 //Set TRUE when the child thread is kicked off. Set
100 //FALSE when a message from the child thread is received
101 //indicating that the thread has terminated and when the
102 //thread is confirmed dead. This variable is used only
103 //by the main thread.
104
105 static HANDLE FILEHASH_child_handle = 0;
106 //The handle of the child process. This is only valid
107 //if a thread is active. This variable is used only
108 //by the main thread to check on status.
109
110 static unsigned char FILEHASH_file_read_buf[FILEHASH_FILE_READ_BUF_SIZE];
111 //File read buffer for I/O.
112
113 struct FILEHASH_FileInfoStructPerFile
114 {
115 volatile char fpath[MAX_PATH + 1];
116 //The full path to the file, which should be recognized by the operating system.
117 //If this string is empty, it is a signal that no file is in this slot.
118 volatile int is_directory_valid;
119 //TRUE if the is_directory flag is assigned by the child process and so the
120 //parent can rely on it.
121 volatile int is_directory_error;
122 //TRUE if the child process could not obtain directory information.
123 volatile int is_directory;
124 //TRUE if the file is actually a directory. This means it cannot be processed.
125 volatile int file_size_valid;
126 //TRUE if file size has been assigned by child (or an attempt to assign it was made).
127 volatile int file_size_error;
128 //There was an error in the attempt to obtain file size.
129 volatile unsigned __int64 file_size;
130 //The number of bytes in the file.
131 volatile int sha512_valid;
132 //TRUE if the SHA512 is valid or an attempt was made.
133 volatile char sha512[200];
134 //A string representation of the SHA512 or else an error message from the child.
135 //An SHA-512 should be 129 characters long (128 characters for the hash and 1 for
136 //the terminating 0).
137 };
138
139 //Aggregated information about all of the files for which a hash is calculated.
140 //
141 struct FILEHASH_FileInfoStruct
142 {
143 volatile struct FILEHASH_FileInfoStructPerFile file_info[FILEHASH_MAXFILES];
144 volatile int terminated_normally;
145 volatile int aborted;
146 };
147
148
149 volatile struct FILEHASH_FileInfoStruct FILEHASH_file_info;
150 //This is the major structure that holds file information. Here are the three
151 //roles it fills:
152 //
153 // a)The parent thread fills in this information in preparation for starting
154 // up the child thread.
155 //
156 // b)The child thread fills in the information (file size, SHA-512) as it
157 // goes down this list, and notifies the parent thread with an event,
158 // which causes the updating of displayed information.
159 //
160 // c)After the child thread is finished with all files, another event is sent
161 // to indicate this.
162
163
164 //Function prototypes, to be sure no miscompilations where the compiled call doesn't match the
165 //compiled function.
166 int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow);
167 LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
168 static unsigned __stdcall FILEHASH_ChildThreadFunc(void *pArguments);
169 static void FILEHASH_ChildThreadHardSyncStop(void);
170 static void FILEHASH_ChildThreadStart(void);
171 static void FILEHASH_MakeGenericSound(void);
172
173
174 //Maps from a nibble to the corresponding ASCII hexadecimal digit.
175 //
176 char CF_nibble_to_lc_hex_digit(int nibble)
177 {
178 switch (nibble & 0x0F)
179 {
180 case 0:
181 return('0');
182 break;
183 case 1:
184 return('1');
185 break;
186 case 2:
187 return('2');
188 break;
189 case 3:
190 return('3');
191 break;
192 case 4:
193 return('4');
194 break;
195 case 5:
196 return('5');
197 break;
198 case 6:
199 return('6');
200 break;
201 case 7:
202 return('7');
203 break;
204 case 8:
205 return('8');
206 break;
207 case 9:
208 return('9');
209 break;
210 case 10:
211 return('a');
212 break;
213 case 11:
214 return('b');
215 break;
216 case 12:
217 return('c');
218 break;
219 case 13:
220 return('d');
221 break;
222 case 14:
223 return('e');
224 break;
225 case 15:
226 return('f');
227 break;
228 default:
229 return('?');
230 break;
231 }
232 }
233
234
235 //Returns TRUE if the passed string seems to be a
236 //valid unsigned integer (without commas) or FALSE
237 //otherwise.
238 //
239 int BSF_is_uint_wo_commas(const char *arg)
240 {
241 if (!*arg)
242 return(0);
243
244 if (arg[0] == '0')
245 {
246 if (arg[1])
247 {
248 return(0);
249 }
250 else
251 {
252 return(1);
253 }
254 }
255 else
256 {
257 while (*arg)
258 {
259 if ((*arg < '0') || (*arg > '9'))
260 return(0);
261 arg++;
262 }
263
264 return(1);
265 }
266 }
267
268
269 //Adds commas (in the traditional place) to a string that represents an unsigned integer.
270 //
271 void BSF_commanate(char *s)
272 {
273 int l;
274 int ncommas;
275 char *putpt, *getpt;
276 int ndigits;
277
278 //If the leading character on the string is a
279 //'-', bump the pointer. Then everything
280 //else applies as for an unsigned.
281 if (*s == '-')
282 s++;
283
284 //Be sure the string currently meets the syntax for
285 //a signed integer. If not, don't even touch it.
286 if (!BSF_is_uint_wo_commas(s))
287 return;
288
289 //Get the length of the current string.
290 l = strlen(s);
291
292 //Let's agree, just in case something slipped through
293 //the cracks, that zero length strings are not of
294 //interest to us.
295 if (l==0)
296 return;
297
298 //The number of commas to add is precisely
299 //(N-1) div 3.
300 if (l==0)
301 ncommas = 0;
302 else
303 ncommas = (l-1)/3;
304
305 //Walk through the string, adding commas.
306 getpt = s + l - 1;
307 putpt = s + l + ncommas;
308
309 *putpt = 0; //Write the zero terminator.
310 putpt--;
311
312 ndigits = 0;
313
314 while ((putpt > s) && (getpt > s))
315 {
316 *putpt = *getpt;
317 putpt--;
318 getpt--;
319 ndigits++;
320 if (((ndigits % 3) == 0) && (putpt != s))
321 {
322 *putpt = ',';
323 putpt--;
324 }
325
326 assert((putpt >= s) && (getpt>=s));
327 }
328 }
329
330
331 //Fundamental state for forming SHA-512s. Conceptually private to this module.
332 //
333 struct FILEHASH_SHA512_Sha512StateStruct
334 {
335 unsigned __int64 H0, H1, H2, H3, H4, H5, H6, H7;
336 //Directly from FIPS 180-3. In retrospect, this might have
337 //been better implemented as an array.
338 unsigned __int64 bit_count;
339 //The count of bits processed thus far. The algorithm here
340 //works in bytes, not bits, so this is advanced by 8 on
341 //each byte processed. FIPS 180-3 calls for processing
342 //messages up to length 2^128, but for obvious reasons
343 //we don't do that. 2^64-1 bits is in excess of 2^61-1
344 //bytes, or somewhere around 2,000 terabytes. This
345 //isn't a practical limit with current computer technology.
346 unsigned __int64 M[16];
347 //These are the words corresponding to the chars (below). We don't
348 //dare union to extract them because of big-endian/little-endian concerns.
349 //The "M" nomenclature is from FIPS 180-3. At the time the
350 //SHA-512 rounds are done, the chars (below) are converted to words
351 //(this field) so that the rounds can be done using the words.
352 unsigned char buf[128];
353 //We can't proceed to execute a round unless we have the
354 //full 1024 bits = 16 words = 128 bytes of data. We must
355 //buffer it because we can't count on being called with data
356 //blocks that are a multiple of 128. We may have data hanging
357 //around between calls. We fill up this buffer from the low
358 //end, i.e. [0], then [1], then [2], etc.
359 };
360
361
362 //Result structure, used to hold result. Caller is allowed to
363 //pick it apart.
364 //
365 struct FILEHASH_SHA512_Sha512ResultStruct
366 {
367 unsigned __int64 sha512_words[8];
368 //Hash in binary form, as the 64-bit integers.
369 char sha512_chars[129];
370 //Zero-terminated string containing character representation
371 //of SHA-512 formed.
372 };
373
374
375 //This is a right rotation macro for efficiency. This
376 //macro rotates a 64-bit quantity x right (cyclically) by
377 //n bits. Nomenclature from FIPS 180-3.
378 #define FILEHASH_SHA512_FUNC_ROTR(x, n) (((x) >> (n)) | ((x) << (64-(n))))
379
380 //This is a right shift macro for efficiency. This
381 //macro shifts a 64-bit quantity x right by
382 //n bits. Nomenclature from FIPS 180-3.
383 #define FILEHASH_SHA512_FUNC_SHR(x, n) ((x) >> (n))
384
385 //These functions come directly from FIPS 180-3.
386 #define FILEHASH_SHA512_FUNC_CH(x, y, z) (((x) & (y)) ^ (~(x) & (z)))
387 #define FILEHASH_SHA512_FUNC_MAJ(x, y, z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
388 #define FILEHASH_SHA512_FUNC_SIGMABIG_0(x) (FILEHASH_SHA512_FUNC_ROTR(x, 28) ^ FILEHASH_SHA512_FUNC_ROTR(x, 34) ^ FILEHASH_SHA512_FUNC_ROTR(x, 39))
389 #define FILEHASH_SHA512_FUNC_SIGMABIG_1(x) (FILEHASH_SHA512_FUNC_ROTR(x, 14) ^ FILEHASH_SHA512_FUNC_ROTR(x, 18) ^ FILEHASH_SHA512_FUNC_ROTR(x, 41))
390 #define FILEHASH_SHA512_FUNC_SIGMASMALL_0(x) (FILEHASH_SHA512_FUNC_ROTR(x, 1) ^ FILEHASH_SHA512_FUNC_ROTR(x, 8) ^ FILEHASH_SHA512_FUNC_SHR(x, 7))
391 #define FILEHASH_SHA512_FUNC_SIGMASMALL_1(x) (FILEHASH_SHA512_FUNC_ROTR(x, 19) ^ FILEHASH_SHA512_FUNC_ROTR(x, 61) ^ FILEHASH_SHA512_FUNC_SHR(x, 6))
392
393
394 //Constants, from FIPS 180-3.
395 const unsigned __int64 FILEHASH_SHA512_K[80] =
396 {0x428a2f98d728ae22UL, 0x7137449123ef65cdUL,
397 0xb5c0fbcfec4d3b2fUL, 0xe9b5dba58189dbbcUL,
398 0x3956c25bf348b538UL, 0x59f111f1b605d019UL,
399 0x923f82a4af194f9bUL, 0xab1c5ed5da6d8118UL,
400 0xd807aa98a3030242UL, 0x12835b0145706fbeUL,
401 0x243185be4ee4b28cUL, 0x550c7dc3d5ffb4e2UL,
402 0x72be5d74f27b896fUL, 0x80deb1fe3b1696b1UL,
403 0x9bdc06a725c71235UL, 0xc19bf174cf692694UL,
404 0xe49b69c19ef14ad2UL, 0xefbe4786384f25e3UL,
405 0x0fc19dc68b8cd5b5UL, 0x240ca1cc77ac9c65UL,
406 0x2de92c6f592b0275UL, 0x4a7484aa6ea6e483UL,
407 0x5cb0a9dcbd41fbd4UL, 0x76f988da831153b5UL,
408 0x983e5152ee66dfabUL, 0xa831c66d2db43210UL,
409 0xb00327c898fb213fUL, 0xbf597fc7beef0ee4UL,
410 0xc6e00bf33da88fc2UL, 0xd5a79147930aa725UL,
411 0x06ca6351e003826fUL, 0x142929670a0e6e70UL,
412 0x27b70a8546d22ffcUL, 0x2e1b21385c26c926UL,
413 0x4d2c6dfc5ac42aedUL, 0x53380d139d95b3dfUL,
414 0x650a73548baf63deUL, 0x766a0abb3c77b2a8UL,
415 0x81c2c92e47edaee6UL, 0x92722c851482353bUL,
416 0xa2bfe8a14cf10364UL, 0xa81a664bbc423001UL,
417 0xc24b8b70d0f89791UL, 0xc76c51a30654be30UL,
418 0xd192e819d6ef5218UL, 0xd69906245565a910UL,
419 0xf40e35855771202aUL, 0x106aa07032bbd1b8UL,
420 0x19a4c116b8d2d0c8UL, 0x1e376c085141ab53UL,
421 0x2748774cdf8eeb99UL, 0x34b0bcb5e19b48a8UL,
422 0x391c0cb3c5c95a63UL, 0x4ed8aa4ae3418acbUL,
423 0x5b9cca4f7763e373UL, 0x682e6ff3d6b2b8a3UL,
424 0x748f82ee5defb2fcUL, 0x78a5636f43172f60UL,
425 0x84c87814a1f0ab72UL, 0x8cc702081a6439ecUL,
426 0x90befffa23631e28UL, 0xa4506cebde82bde9UL,
427 0xbef9a3f7b2c67915UL, 0xc67178f2e372532bUL,
428 0xca273eceea26619cUL, 0xd186b8c721c0c207UL,
429 0xeada7dd6cde0eb1eUL, 0xf57d4f7fee6ed178UL,
430 0x06f067aa72176fbaUL, 0x0a637dc5a2c898a6UL,
431 0x113f9804bef90daeUL, 0x1b710b35131c471bUL,
432 0x28db77f523047d84UL, 0x32caab7b40c72493UL,
433 0x3c9ebe0a15c9bebcUL, 0x431d67c49c100d4cUL,
434 0x4cc5d4becb3e42b6UL, 0x597f299cfc657e2aUL,
435 0x5fcb6fab3ad6faecUL, 0x6c44198c4a475817UL};
436
437
438 //Initializes an SHA-512 state structure in preparation for adding data.
439 //
440 void FILEHASH_SHA512_Sha512StateStructOpen(struct FILEHASH_SHA512_Sha512StateStruct *arg)
441 {
442 memset(arg, 0, sizeof(struct FILEHASH_SHA512_Sha512StateStruct));
443 //Set everything to zero--processed bitcount set to zero.
444
445 //This assignment comes directly from FIPS 180-3.
446 arg->H0 = 0x6a09e667f3bcc908UL;
447 arg->H1 = 0xbb67ae8584caa73bUL;
448 arg->H2 = 0x3c6ef372fe94f82bUL;
449 arg->H3 = 0xa54ff53a5f1d36f1UL;
450 arg->H4 = 0x510e527fade682d1UL;
451 arg->H5 = 0x9b05688c2b3e6c1fUL;
452 arg->H6 = 0x1f83d9abfb41bd6bUL;
453 arg->H7 = 0x5be0cd19137e2179UL;
454 }
455
456
457 //Copies the byte buffer to the word buffer within the state block.
458 //This is done in a way which hides big-endian/little-endian concerns.
459 //
460 static void FILEHASH_SHA512_CopyBytesToWords(struct FILEHASH_SHA512_Sha512StateStruct *arg)
461 {
462 unsigned int i;
463
464 assert(arg != NULL);
465
466 //Copy the buffer contents into the words. We need to be careful
467 //to do this correctly, because of big-endian/little-endian concerns.
468 //From FIPS 180-3 (alluded to, not really stated), the message is
469 //loaded in from M[0] down to M[15]. Additionally, per the other
470 //conventions in the document, the first byte is uppermost in each
471 //word.
472 for (i=0; i<16; i++)
473 {
474 assert((i * 8 + 7) < 128);
475
476 arg->M[i] = (((unsigned __int64)(arg->buf[i*8+0])) << 56)
477 +
478 (((unsigned __int64)(arg->buf[i*8+1])) << 48)
479 +
480 (((unsigned __int64)(arg->buf[i*8+2])) << 40)
481 +
482 (((unsigned __int64)(arg->buf[i*8+3])) << 32)
483 +
484 (((unsigned __int64)(arg->buf[i*8+4])) << 24)
485 +
486 (((unsigned __int64)(arg->buf[i*8+5])) << 16)
487 +
488 (((unsigned __int64)(arg->buf[i*8+6])) << 8)
489 +
490 (((unsigned __int64)(arg->buf[i*8+7])));
491 }
492 }
493
494
495 //Copies the buffer of words into a string buffer of string length 128, and also places
496 //the zero terminator, which means that the string supplied by the caller must be of size
497 //129 or larger.
498 //
499 static void FILEHASH_SHA512_CopyWordsToStringBuffer(struct FILEHASH_SHA512_Sha512ResultStruct *arg)
500 {
501 unsigned int i, j;
502 unsigned char *puc;
503 unsigned __int64 woi;
504
505 assert(arg != NULL);
506
507 //Copy the buffer contents into the words. We need to be careful
508 //to do this correctly, because of big-endian/little-endian concerns.
509 //From FIPS 180-3 (alluded to, not really stated), the message is
510 //loaded in from M[0] down to M[15]. Additionally, per the other
511 //conventions in the document, the first byte is uppermost in each
512 //word.
513 for (i=0; i<8; i++)
514 {
515 woi = arg->sha512_words[i];
516
517 //Form a pointer to the buffer location of interest. We work
518 //backwards.
519 puc = (unsigned char *)(arg->sha512_chars) + (i * 16) + 15;
520
521 //Fill in the buffer.
522 for (j=0; j<16; j++)
523 {
524 *puc = (unsigned char)CF_nibble_to_lc_hex_digit((int)(woi & 0xF));
525 woi >>= 4;
526 puc--;
527 }
528 }
529
530 //Place the zero string terminator.
531 arg->sha512_chars[128] = 0;
532 }
533
534
535 //Do the SHA-512 rounds as specified by FIPS 180-3.
536 //
537 static void FILEHASH_SHA512_DoSha512Rounds(struct FILEHASH_SHA512_Sha512StateStruct *arg)
538 {
539 int i;
540 //Iteration variable.
541 unsigned __int64 T1, T2;
542 //Temporary variables. Nomenclature is from FIPS 180-3.
543 unsigned __int64 M[16];
544 //Buffer of message block to avoid repeated dereferences.
545 unsigned __int64 H[8];
546 //Buffer of hash state to avoid repeated dereferences.
547 unsigned __int64 W[80];
548 //Working variable. Nomenclature directly from FIPS 180-3.
549 unsigned __int64 a, b, c, d, e, f, g, h;
550 //Nomenclature above directly from FIPS 180-3.
551
552 assert(arg != NULL);
553
554 //Copy bytes into words.
555 FILEHASH_SHA512_CopyBytesToWords(arg);
556
557 //Copy out the message buffer for speed. This should avoid repeated
558 //dereferences.
559 M[ 0] = arg->M[ 0];
560 M[ 1] = arg->M[ 1];
561 M[ 2] = arg->M[ 2];
562 M[ 3] = arg->M[ 3];
563 M[ 4] = arg->M[ 4];
564 M[ 5] = arg->M[ 5];
565 M[ 6] = arg->M[ 6];
566 M[ 7] = arg->M[ 7];
567 M[ 8] = arg->M[ 8];
568 M[ 9] = arg->M[ 9];
569 M[10] = arg->M[10];
570 M[11] = arg->M[11];
571 M[12] = arg->M[12];
572 M[13] = arg->M[13];
573 M[14] = arg->M[14];
574 M[15] = arg->M[15];
575
576 //Copy out the hash state for speed. This should avoid repeated dereferences.
577 H[0] = arg->H0;
578 H[1] = arg->H1;
579 H[2] = arg->H2;
580 H[3] = arg->H3;
581 H[4] = arg->H4;
582 H[5] = arg->H5;
583 H[6] = arg->H6;
584 H[7] = arg->H7;
585
586 //Prepare the message schedule. The nomenclature comes directly from FIPS 180-3.
587 W[ 0] = M[ 0];
588 W[ 1] = M[ 1];
589 W[ 2] = M[ 2];
590 W[ 3] = M[ 3];
591 W[ 4] = M[ 4];
592 W[ 5] = M[ 5];
593 W[ 6] = M[ 6];
594 W[ 7] = M[ 7];
595 W[ 8] = M[ 8];
596 W[ 9] = M[ 9];
597 W[10] = M[10];
598 W[11] = M[11];
599 W[12] = M[12];
600 W[13] = M[13];
601 W[14] = M[14];
602 W[15] = M[15];
603
604 for (i=16; i<80; i++)
605 {
606 W[i] = FILEHASH_SHA512_FUNC_SIGMASMALL_1(W[i-2])
607 + W[i-7]
608 + FILEHASH_SHA512_FUNC_SIGMASMALL_0(W[i-15])
609 + W[i-16];
610 }
611
612 //Initialize the 8 working variables as specified in FIPS 180-3.
613 a = H[0];
614 b = H[1];
615 c = H[2];
616 d = H[3];
617 e = H[4];
618 f = H[5];
619 g = H[6];
620 h = H[7];
621
622 //Perform the rounds as specified in FIPS 180-3. Nomenclature below comes from
623 //FIPS 180-3.
624 for (i=0; i<80; i++)
625 {
626 T1 = h
627 + FILEHASH_SHA512_FUNC_SIGMABIG_1(e)
628 + FILEHASH_SHA512_FUNC_CH(e, f, g)
629 + FILEHASH_SHA512_K[i]
630 + W[i];
631 //
632 T2 = FILEHASH_SHA512_FUNC_SIGMABIG_0(a)
633 + FILEHASH_SHA512_FUNC_MAJ(a, b, c);
634 //
635 h = g;
636 //
637 g = f;
638 //
639 f = e;
640 //
641 e = d + T1;
642 //
643 d = c;
644 //
645 c = b;
646 //
647 b = a;
648 //
649 a = T1 + T2;
650 }
651
652 //Compute the next hash value. The nomenclature comes from FIPS 180-3.
653 H[0] = a + H[0];
654 H[1] = b + H[1];
655 H[2] = c + H[2];
656 H[3] = d + H[3];
657 H[4] = e + H[4];
658 H[5] = f + H[5];
659 H[6] = g + H[6];
660 H[7] = h + H[7];
661
662 //Place the local variables back in the structure. This the only state that
663 //gets preserved between the operation of doing the rounds.
664 arg->H0 = H[0];
665 arg->H1 = H[1];
666 arg->H2 = H[2];
667 arg->H3 = H[3];
668 arg->H4 = H[4];
669 arg->H5 = H[5];
670 arg->H6 = H[6];
671 arg->H7 = H[7];
672 }
673
674
675 //Adds a block of data to the SHA-512 structure. Zero length is allowed.
676 //
677 void FILEHASH_SHA512_Sha512StateStructAddData(struct FILEHASH_SHA512_Sha512StateStruct *arg,
678 void *pointer_in,
679 unsigned len)
680 {
681 unsigned int low_32;
682 unsigned int byte_offset;
683 unsigned char *data;
684
685 assert((len == 0) || (arg != NULL));
686 assert(pointer_in != NULL);
687
688 data = (unsigned char *)pointer_in;
689 //It is easier to do it this way, rather than cast all the time.
690
691 low_32 = (unsigned int)arg->bit_count;
692 //Copy off the least significant bits. Easier to do once. We only
693 //need the 32 least significant because the block size is 0 modulo 1024.
694
695 byte_offset = low_32 >> 3;
696 //This gives our byte offset, up to 500+Mb or so.
697
698 while(len--)
699 {
700 //We process rounds AFTER a byte is added to the buffer. So
701 //it is always safe to add a byte first.
702 arg->buf[byte_offset & 0x7F] = *data;
703
704 //Nothing to do unless this was the final byte of the buffer.
705 if ((byte_offset & 0x7F) == 127)
706 {
707 FILEHASH_SHA512_DoSha512Rounds(arg);
708 }
709
710 //Increment.
711 data++;
712 byte_offset++;
713 arg->bit_count += 8;
714 }
715 }
716
717
718 //Closes the SHA-512 structure and places the SHA-512 result into the result structure.
719 //After this operation, state is destroyed and no further data may be added.
720 //
721 void FILEHASH_SHA512_Sha512StateStructClose(struct FILEHASH_SHA512_Sha512StateStruct *state,
722 struct FILEHASH_SHA512_Sha512ResultStruct *result)
723 {
724 unsigned __int64 msglen;
725 //Used to hold message length before we pad the message.
726 unsigned char c80 = 0x80;
727 //Used to append the "1" per FIPS 180-3.
728 unsigned char c00 = 0x00;
729 //Used to add 0's per FIPS 180-3.
730 unsigned char length_buf[16];
731 //Buffer used to form the message length and append it to the message per FIPS 180-3.
732
733 //Be sure the input pointers aren't obviously invalid.
734 assert(state != NULL);
735 assert(result != NULL);
736
737 //Snapshot the message length. We'll be changing it when we pad the message.
738 msglen = state->bit_count;
739
740 //Add the required "1" to the end of the message, per FIPS 180-3. Because
741 //this software module only allows the addition of bytes (not bits), adding the
742 //"1" will always involve adding the byte 0x80.
743 FILEHASH_SHA512_Sha512StateStructAddData(state, &c80, 1);
744
745 //Add enough 0's to the message so that we have exactly room for 16 bytes (128 bits)
746 //of length information at the end of the message.
747 while ((state->bit_count & 0x3FF) != 896)
748 FILEHASH_SHA512_Sha512StateStructAddData(state, &c00, 1);
749
750 //Calculate the length as a series of bytes.
751 length_buf[ 0] = 0;
752 length_buf[ 1] = 0;
753 length_buf[ 2] = 0;
754 length_buf[ 3] = 0;
755 length_buf[ 4] = 0;
756 length_buf[ 5] = 0;
757 length_buf[ 6] = 0;
758 length_buf[ 7] = 0;
759 length_buf[ 8] = (unsigned char)((msglen >> 56) & 0xFF);
760 length_buf[ 9] = (unsigned char)((msglen >> 48) & 0xFF);
761 length_buf[10] = (unsigned char)((msglen >> 40) & 0xFF);
762 length_buf[11] = (unsigned char)((msglen >> 32) & 0xFF);
763 length_buf[12] = (unsigned char)((msglen >> 24) & 0xFF);
764 length_buf[13] = (unsigned char)((msglen >> 16) & 0xFF);
765 length_buf[14] = (unsigned char)((msglen >> 8) & 0xFF);
766 length_buf[15] = (unsigned char)((msglen) & 0xFF);
767
768 //Add the length to the message. This should work out to generate the
769 //final manipulation round.
770 FILEHASH_SHA512_Sha512StateStructAddData(state, length_buf, 16);
771
772 //Copy the words from the state vector to the result vector.
773 result->sha512_words[0] = state->H0;
774 result->sha512_words[1] = state->H1;
775 result->sha512_words[2] = state->H2;
776 result->sha512_words[3] = state->H3;
777 result->sha512_words[4] = state->H4;
778 result->sha512_words[5] = state->H5;
779 result->sha512_words[6] = state->H6;
780 result->sha512_words[7] = state->H7;
781
782 //Form a string from the hash vector.
783 FILEHASH_SHA512_CopyWordsToStringBuffer(result);
784
785 //Destroy the state, which may contain sensitive information.
786 memset(state, 0, sizeof(struct FILEHASH_SHA512_Sha512StateStruct));
787 }
788
789
790 //Main function for Windows.
791 //
792 int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
793 PSTR szCmdLine, int iCmdShow)
794 {
795 HWND hwnd ;
796 HMENU hmenu;
797 MSG msg ;
798 WNDCLASS wndclass ;
799
800 //Store our current parent thread ID. The child process will need
801 //to know this to post a message. This is expected to be
802 //invariant for the life of the program.
803 FILEHASH_parent_thread_id = GetCurrentThreadId();
804
805 //Zero out the file information block.
806 memset((char *)&FILEHASH_file_info, 0, sizeof(FILEHASH_file_info));
807
808 wndclass.style = CS_HREDRAW | CS_VREDRAW ;
809 wndclass.lpfnWndProc = WndProc ;
810 wndclass.cbClsExtra = 0 ;
811 wndclass.cbWndExtra = 0 ;
812 wndclass.hInstance = hInstance ;
813 wndclass.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_ICON)) ;
814 wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
815 wndclass.hbrBackground = (HBRUSH) (COLOR_BTNFACE+1) ;
816 wndclass.lpszMenuName = NULL ;
817 wndclass.lpszClassName = FILEHASH_szAppName ;
818
819 if (!RegisterClass (&wndclass))
820 {
821 MessageBox (NULL,
822 TEXT ("Error code from RegisterClass() Win32 API function. \nThe most probable cause is an incompatible operating system."),
823 FILEHASH_szAppName,
824 MB_ICONERROR) ;
825 return 0 ;
826 }
827
828 //We need to do some voodoo to figure out how large to make the main window.
829 //The feeling is that the window should be as small as possible to display the
830 //results from an individual file (the most common application), and if the user
831 //wants it bigger it can be resized. Three lines are required (file name, file
832 //size, and SHA-512), so that needs to be the height. A file
833 //SHA-512 is 512 bits = 128 characters. In addition, there is the constraint that we
834 //cannot go beyond the width and height of a screen. The guess below is quite
835 //crude, assuming that the edit box has a larger font, etc.
836 {
837 int initial_width = 0;
838 int initial_height = 0;
839
840 //Get a crude measure of how big text is.
841 initial_width = LOWORD(GetDialogBaseUnits());
842 initial_height = HIWORD(GetDialogBaseUnits());
843
844 //Dope it up linearly.
845 initial_width = (initial_width * 1500)/10;
846 initial_height = (initial_height * 150)/10;
847
848 {
849 int temp;
850
851 //Be sure nothing is bigger than 2/3 screen dimensions.
852 temp = (GetSystemMetrics(SM_CXFULLSCREEN) * 2) / 3;
853 if (initial_width > temp)
854 initial_width = temp;
855 temp = (GetSystemMetrics(SM_CYFULLSCREEN) * 2) / 3;
856 if (initial_height > temp)
857 initial_height = temp;
858 }
859
860 //Load up the menu resources. I have verified in documentation that this will be destroyed
861 //automatically.
862 hmenu = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_FILEHASH));
863
864 //Create the window. The "Ex" call is used to make it a topmost window.
865 hwnd = CreateWindowEx (
866 WS_EX_TOPMOST,
867 FILEHASH_szAppName, // window class name
868 TEXT ("FileHash"), // window caption
869 WS_OVERLAPPEDWINDOW, // window style
870 CW_USEDEFAULT, // initial x position
871 CW_USEDEFAULT, // initial y position
872 initial_width, // initial x size
873 initial_height, // initial y size
874 NULL, // parent window handle
875 hmenu, // window menu handle
876 hInstance, // program instance handle
877 NULL) ; // creation parameters
878 }
879
880
881 FILEHASH_parent_thread_main_window_handle = hwnd;
882
883 //This is standard code from Petzold's book. Don't know _exactly_ what it does, but
884 //every Windows program seems to have it.
885 ShowWindow (hwnd, iCmdShow) ;
886 UpdateWindow (hwnd) ;
887
888 while (GetMessage (&msg, NULL, 0, 0))
889 {
890 TranslateMessage (&msg) ;
891 DispatchMessage (&msg) ;
892 }
893
894 return msg.wParam ;
895 }
896
897
898 //This is the subclass WndProc. This had to be done to allow the edit
899 //control to catch the WM_DROPFILES event.
900 //
901 LRESULT CALLBACK FILEHASH_ReplacementEditProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
902 {
903 static int iDeltaPerLine = 120, iAccumDelta = 0;
904 //These are for mouse wheel logic. It may happen in the future that more
905 //precise mice without notches are introduced.
906
907 //We need to watch for the drop target notification message, and take action
908 //in that case.
909 switch(message)
910 {
911 case WM_DROPFILES:
912 {
913 int iFiles;
914 int i;
915 HDROP hDropInfo = (HANDLE)wParam;
916
917 //Do a hard sync stop on the child thread. This should not take
918 //very long. A new drag'n'drop event will just cause restart
919 //with the new set of files.
920 FILEHASH_ChildThreadHardSyncStop();
921
922 //Zero out the file information area and the text buffer mirror.
923 memset((char *)&FILEHASH_file_info, 0, sizeof(FILEHASH_file_info));
924 FILEHASH_dispbuf[0] = 0;
925
926 // Get the number of files and folders that were dropped.
927 iFiles = DragQueryFile (hDropInfo, (DWORD)(-1), (LPSTR)NULL, 0);
928
929 //Copy the paths to the right buffer area.
930 for (i=0; (i<iFiles) && (i<FILEHASH_MAXFILES); i++)
931 {
932 DragQueryFile (hDropInfo, i, (LPSTR)(FILEHASH_file_info.file_info[i].fpath), MAX_PATH);
933 }
934
935 //Start up the child thread.
936 FILEHASH_ChildThreadStart();
937
938 break;
939 }
940 case WM_MOUSEWHEEL:
941 {
942 iAccumDelta += (short) HIWORD (wParam);
943
944 while (iAccumDelta >= iDeltaPerLine)
945 {
946 SendMessage(hwnd, WM_VSCROLL, SB_PAGEUP, 0);
947 iAccumDelta -= iDeltaPerLine;
948 //iAccumDelta = 0;
949 }
950
951 while (iAccumDelta <= -iDeltaPerLine)
952 {
953 SendMessage(hwnd, WM_VSCROLL, SB_PAGEDOWN, 0);
954 iAccumDelta += iDeltaPerLine;
955 //iAccumDelta = 0;
956 }
957
958 break;
959 }
960 }
961
962 //Call the old Window procedure.
963 return (CallWindowProc(FILEHASH_old_win_edit_handler, hwnd, message, wParam, lParam));
964 }
965
966
967 //Stages the display buffer in preparation for outputting it out
968 //to the edit child window. This function generally interacts
969 //with the file information data structure even while the
970 //child thread is running. This is OK, as race conditions are
971 //covered. Essentially, as the child thread proceeds, it updates
972 //data then afterwards flags it as valid. This function
973 //never proceeds into invalid data.
974 //
975 static void FILEHASH_StageDisplayBuffer(void)
976 {
977 int dispbufidx;
978 int nfiles;
979 int len;
980 int i;
981 char buf[2*MAX_PATH+200];
982
983 //Count the number of files queued, and put that in the buffer.
984 dispbufidx = 0;
985 nfiles=0;
986 for (i=0; i<FILEHASH_MAXFILES; i++)
987 {
988 if (FILEHASH_file_info.file_info[i].fpath[0])
989 {
990 nfiles++;
991 }
992 else
993 {
994 break;
995 }
996 }
997 sprintf_s(buf, sizeof(buf), "Files to signature: %d.\x0d\x0a", nfiles);
998 len = strlen(buf);
999 if ((len + dispbufidx + 2) < FILEHASH_DISPBUFLEN)
1000 {
1001 strcpy_s(FILEHASH_dispbuf+dispbufidx, sizeof(FILEHASH_dispbuf) - dispbufidx,buf);
1002 dispbufidx += len;
1003 }
1004
1005 //Loop through and output the information for each file.
1006 for (i=0; i<FILEHASH_MAXFILES; i++)
1007 {
1008 if ((FILEHASH_file_info.file_info[i].fpath[0]) && (FILEHASH_file_info.file_info[i].is_directory_valid))
1009 {
1010 sprintf_s(buf, sizeof(buf), "--------------------\x0d\x0a");
1011 len = strlen(buf);
1012 if ((len + dispbufidx + 2) < FILEHASH_DISPBUFLEN)
1013 {
1014 strcpy_s(FILEHASH_dispbuf+dispbufidx, sizeof(FILEHASH_dispbuf)-dispbufidx, buf);
1015 dispbufidx += len;
1016 }
1017
1018 sprintf_s(buf, sizeof(buf), "[%03d/%03d] %s\x0d\x0a", i+1, nfiles, FILEHASH_file_info.file_info[i].fpath);
1019 len = strlen(buf);
1020 if ((len + dispbufidx + 2) < FILEHASH_DISPBUFLEN)
1021 {
1022 strcpy_s(FILEHASH_dispbuf+dispbufidx, sizeof(FILEHASH_dispbuf)-dispbufidx, buf);
1023 dispbufidx += len;
1024 }
1025
1026 //If the file is actually a directory or there was an error, we can't
1027 //do further processing on it.
1028 if (FILEHASH_file_info.file_info[i].is_directory_error)
1029 {
1030 sprintf_s(buf, sizeof(buf), "\tError obtaining file attributes--cannot process this file.\x0d\x0a");
1031 len = strlen(buf);
1032 if ((len + dispbufidx + 2) < FILEHASH_DISPBUFLEN)
1033 {
1034 strcpy_s(FILEHASH_dispbuf+dispbufidx, sizeof(FILEHASH_dispbuf)-dispbufidx, buf);
1035 dispbufidx += len;
1036 }
1037 }
1038 else if (FILEHASH_file_info.file_info[i].is_directory)
1039 {
1040 sprintf_s(buf, sizeof(buf), "\tThis item is a directory and will not be signatured.\x0d\x0a");
1041 len = strlen(buf);
1042 if ((len + dispbufidx + 2) < FILEHASH_DISPBUFLEN)
1043 {
1044 strcpy_s(FILEHASH_dispbuf+dispbufidx, sizeof(FILEHASH_dispbuf)-dispbufidx, buf);
1045 dispbufidx += len;
1046 }
1047 }
1048 else
1049 {
1050 //This is not a directory. We can print the rest of the
1051 //information.
1052 //
1053 //First, the file size.
1054 if (FILEHASH_file_info.file_info[i].file_size_valid)
1055 {
1056 char buf2[100];
1057
1058 buf2[0] = 0; //Just in case conversion doesn't go right.
1059 sprintf_s(buf2, sizeof(buf2), "%I64u", FILEHASH_file_info.file_info[i].file_size);
1060 BSF_commanate(buf2);
1061 sprintf_s(buf, sizeof(buf), "\tSize:\t%s\x0d\x0a", buf2);
1062
1063 len = strlen(buf);
1064 if ((len + dispbufidx + 2) < FILEHASH_DISPBUFLEN)
1065 {
1066 strcpy_s(FILEHASH_dispbuf+dispbufidx, sizeof(FILEHASH_dispbuf)-dispbufidx, buf);
1067 dispbufidx += len;
1068 }
1069 }
1070
1071 //Now, the SHA512.
1072 if (FILEHASH_file_info.file_info[i].sha512_valid)
1073 {
1074 sprintf_s(buf, sizeof(buf), "\tSHA-512:\t%s\x0d\x0a", FILEHASH_file_info.file_info[i].sha512);
1075 len = strlen(buf);
1076 if ((len + dispbufidx + 2) < FILEHASH_DISPBUFLEN)
1077 {
1078 strcpy_s(FILEHASH_dispbuf+dispbufidx, sizeof(FILEHASH_dispbuf)-dispbufidx, buf);
1079 dispbufidx += len;
1080 }
1081 }
1082 }
1083 }
1084 else
1085 {
1086 break;
1087 }
1088
1089 }
1090
1091 //Process the termination condition information.
1092 if (FILEHASH_file_info.aborted)
1093 {
1094 sprintf_s(buf, sizeof(buf), "-------------------- FILE SIGNATURE ABORTED --------------------");
1095 }
1096 else if (FILEHASH_file_info.terminated_normally)
1097 {
1098 sprintf_s(buf, sizeof(buf), "-------------------- FILE SIGNATURE COMPLETE --------------------");
1099 }
1100 else
1101 {
1102 sprintf_s(buf, sizeof(buf), "-------------------- FILE SIGNATURE IN PROGRESS -------------------");
1103 }
1104
1105 len = strlen(buf);
1106 if ((len + dispbufidx + 2) < FILEHASH_DISPBUFLEN)
1107 {
1108 strcpy_s(FILEHASH_dispbuf+dispbufidx, sizeof(FILEHASH_dispbuf)-dispbufidx, buf);
1109 dispbufidx += len;
1110 }
1111 }
1112
1113
1114 //Pushes the display buffer out to the edit control.
1115 //
1116 static int FILEHASH_UpdateEditControl(HWND te_wind)
1117 {
1118 SetWindowText(te_wind, FILEHASH_dispbuf);
1119
1120 //Must set the buffer position (i.e. the display position) to the end.
1121 //The "/10" assumes that there can't be more than 8 chars or so per line--
1122 //couldn't find a way to go to the end automatically.
1123 SendMessage(te_wind,EM_LINESCROLL,0,FILEHASH_DISPBUFLEN/8);
1124
1125 return(0);
1126 }
1127
1128
1129 //This is the Windows procedure and event loop for the
1130 //main Window.
1131 //
1132 LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
1133 {
1134 HDC hdc ;
1135 PAINTSTRUCT ps ;
1136 static RECT rect ;
1137 static HWND te_wind = 0;
1138
1139 switch (message)
1140 {
1141 case WM_CREATE:
1142 {
1143 //Need to get the size of our current window so we can create the
1144 //child same size.
1145 //
1146 GetClientRect (hwnd, &rect);
1147
1148 te_wind = CreateWindow ("EDIT", // window class name
1149 "", // window caption
1150 WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE|ES_AUTOVSCROLL|ES_WANTRETURN, // window style
1151 0, // initial x position
1152 0, // initial y position
1153 rect.right, // initial x size
1154 rect.bottom, // initial y size
1155 hwnd, // parent window handle
1156 (HMENU) 1, // window menu handle
1157 ((LPCREATESTRUCT)lParam)->hInstance, // program instance handle
1158 NULL) ; // creation parameters
1159 //Print initial usage instructions.
1160 SetWindowText(te_wind, "FILEHASH, Copyright \xA9 2010 David T. Ashley\x0d\x0a"
1161 "\x0d\x0a"
1162 "This program is provided under the GNU General Public License, Version 3, and comes with ABSOLUTELY NO WARRANTY. "
1163 "This is free software, and you are welcome to redistribute it. For a copy of the source code and license, please write to "
1164 "David T. Ashley (dashley@gmail.com)."
1165 "\x0d\x0a"
1166 "\x0d\x0a"
1167 "To calculate "
1168 "SHA-512 message digests, "
1169 "drag and drop files into this box (from Windows Explorer "
1170 "or a similar application), or use the FILE->OPEN "
1171 "menu selection. Text can be freely selected and "
1172 "copied from this window (select the desired text "
1173 "and use the right mouse button to obtain a popup menu "
1174 "which includes COPY).");
1175
1176 //Tell Windows that this child is a fair drop target for files.
1177 DragAcceptFiles (te_wind, TRUE);
1178
1179 //We need to subclass the child window, which is to define a new wndproc
1180 //for it.
1181 FILEHASH_old_win_edit_handler = (WNDPROC) SetWindowLong(te_wind, GWL_WNDPROC, (long) FILEHASH_ReplacementEditProc);
1182
1183 return 0 ;
1184 }
1185 case WM_SIZE:
1186 {
1187 rect.left = 0;
1188 rect.top = 0;
1189 rect.right = LOWORD(lParam);
1190 rect.bottom = HIWORD(lParam);
1191 MoveWindow(te_wind, 0, 0, rect.right, rect.bottom, TRUE);
1192 return 0;
1193 }
1194 case WM_PAINT:
1195 {
1196 hdc = BeginPaint (hwnd, &ps) ;
1197
1198 GetClientRect (hwnd, &rect) ;
1199
1200 EndPaint (hwnd, &ps) ;
1201 return 0 ;
1202 }
1203 case WM_DESTROY:
1204 {
1205 PostQuitMessage (0) ;
1206 FILEHASH_ChildThreadHardSyncStop();
1207 return 0 ;
1208 }
1209 //This is a home-spun event which means that there are files to be processed.
1210 //This is sent once when the drop is initially done and then each time a file
1211 //is processed another event is used to continue the process, until finally
1212 //there are no more files to do.
1213 case WM_USER_EV_CHILD_THREAD_PROGRESS:
1214 {
1215 //Just recalc the mirror buffer and redisplay it.
1216 FILEHASH_StageDisplayBuffer();
1217 FILEHASH_UpdateEditControl(te_wind);
1218 return 0;
1219 }
1220 case WM_USER_EV_CHILD_THREAD_ENDING:
1221 {
1222 HMENU hMenu;
1223
1224 //Just recalc the mirror buffer and redisplay it.
1225 FILEHASH_StageDisplayBuffer();
1226 FILEHASH_UpdateEditControl(te_wind);
1227 FILEHASH_MakeGenericSound();
1228
1229 hMenu = GetMenu(FILEHASH_parent_thread_main_window_handle);
1230
1231 EnableMenuItem(hMenu, ID_ACTIONS_HALTSIGOP, MF_GRAYED);
1232
1233 return 0;
1234 }
1235 case WM_COMMAND:
1236 {
1237 switch(LOWORD(wParam))
1238 {
1239 case ID_FILE_OPEN_FOR_SIG:
1240 {
1241 OPENFILENAME ofn;
1242 static char szFilter[] = "All Files (*.*)\0*.*\0\0";
1243
1244 //Set up for the dialog.
1245 FILEHASH_dialog_file_open_buffer[0] = 0; //Be sure that initial name zero'd out.
1246 FILEHASH_dialog_file_open_buffer[1] = 0;
1247
1248 ofn.lStructSize = sizeof(OPENFILENAME);
1249 ofn.hwndOwner = hwnd ;
1250 ofn.hInstance = NULL ;
1251 ofn.lpstrFilter = szFilter;
1252 ofn.lpstrCustomFilter = NULL ;
1253 ofn.nMaxCustFilter = 0 ;
1254 ofn.nFilterIndex = 0 ;
1255 ofn.lpstrFile = FILEHASH_dialog_file_open_buffer;
1256 ofn.nMaxFile = sizeof(FILEHASH_dialog_file_open_buffer) - 1;
1257 ofn.lpstrFileTitle = NULL;
1258 ofn.nMaxFileTitle = 0;
1259 ofn.lpstrInitialDir = NULL ;
1260 ofn.lpstrTitle = "Open File(s) For Message Digest Calculation" ;
1261 ofn.Flags = OFN_ALLOWMULTISELECT
1262 | OFN_FILEMUSTEXIST
1263 | OFN_HIDEREADONLY
1264 | OFN_NODEREFERENCELINKS
1265 | OFN_PATHMUSTEXIST
1266 | OFN_EXPLORER
1267 | OFN_SHAREAWARE;
1268 ofn.nFileOffset = 0 ;
1269 ofn.nFileExtension = 0 ;
1270 ofn.lpstrDefExt = NULL;
1271 ofn.lCustData = 0L ;
1272 ofn.lpfnHook = NULL ;
1273 ofn.lpTemplateName = NULL ;
1274
1275 //Zero out the dialog return area buffer.
1276 FILEHASH_dialog_file_open_buffer[0] = 0;
1277 FILEHASH_dialog_file_open_buffer[1] = 0;
1278
1279 if (GetOpenFileName (&ofn))
1280 {
1281 int dstarridx=0;
1282 int srccharidx=0;
1283
1284 //There was success and something specified. This means we must
1285 //kill the child thread if it is running.
1286 //Do a hard sync stop on the child thread. This should not take
1287 //very long. A new drag'n'drop event will just cause restart
1288 //with the new set of files.
1289 FILEHASH_ChildThreadHardSyncStop();
1290
1291 //Zero out the file information area and the text buffer mirror.
1292 memset((char *)&FILEHASH_file_info, 0, sizeof(FILEHASH_file_info));
1293 FILEHASH_dispbuf[0] = 0;
1294
1295 dstarridx=0;
1296 srccharidx=0;
1297
1298 //Advance to first string terminator.
1299 while (FILEHASH_dialog_file_open_buffer[srccharidx] != 0)
1300 srccharidx++;
1301
1302 //In the special case where the double-null is encountered immediately, there is
1303 //only one file, and full path is specified.
1304 //
1305 if (!FILEHASH_dialog_file_open_buffer[srccharidx+1])
1306 {
1307 strcpy_s((char *)FILEHASH_file_info.file_info[0].fpath, sizeof(FILEHASH_file_info.file_info[0].fpath), FILEHASH_dialog_file_open_buffer);
1308 }
1309 else
1310 {
1311 //This is the multiple file case.
1312 while ((dstarridx < FILEHASH_MAXFILES) && (FILEHASH_dialog_file_open_buffer[srccharidx+1]))
1313 {
1314 int len;
1315
1316 srccharidx++;
1317 strcpy_s((char *)FILEHASH_file_info.file_info[dstarridx].fpath, sizeof(FILEHASH_file_info.file_info[dstarridx].fpath), FILEHASH_dialog_file_open_buffer);
1318
1319 //Watch out for adding two backslashes. This can happen if the path
1320 //contains only a drive letter ("c:\", for example) so that the OS
1321 //adds a path on.
1322 len = strlen(FILEHASH_dialog_file_open_buffer);
1323 if ((len != 0) && (FILEHASH_dialog_file_open_buffer[len-1]=='\\'))
1324 {
1325 //Do nothing. Watch out in modifying this. The "len != 0" test
1326 //above is to prevent an access violation in the second test--watch
1327 //out when modifying this if-then-else construct.
1328 }
1329 else
1330 {
1331 strcat_s((char *)FILEHASH_file_info.file_info[dstarridx].fpath, sizeof(FILEHASH_file_info.file_info[dstarridx].fpath), "\\");
1332 }
1333 strcat_s((char *)FILEHASH_file_info.file_info[dstarridx].fpath, sizeof(FILEHASH_file_info.file_info[dstarridx].fpath), FILEHASH_dialog_file_open_buffer+srccharidx);
1334 while (FILEHASH_dialog_file_open_buffer[srccharidx] != 0)
1335 srccharidx++;
1336 dstarridx++;
1337 }
1338 }
1339
1340 //Start up the child thread.
1341 FILEHASH_ChildThreadStart();
1342
1343 //Redisplay the edit buffer.
1344 FILEHASH_StageDisplayBuffer();
1345 FILEHASH_UpdateEditControl(te_wind);
1346 }
1347
1348 return 0;
1349 }
1350 case ID_FILE_EXIT:
1351 {
1352 SendMessage(hwnd, WM_CLOSE, 0, 0);
1353 return 0;
1354 }
1355 case ID_ACTIONS_HALTSIGOP:
1356 {
1357 FILEHASH_ChildThreadHardSyncStop();
1358 FILEHASH_MakeGenericSound();
1359 FILEHASH_StageDisplayBuffer();
1360 FILEHASH_UpdateEditControl(te_wind);
1361 return 0;
1362 }
1363 case ID_OPTIONS_USE_SOUND:
1364 {
1365 if (FILEHASH_use_sound)
1366 {
1367 HMENU hMenu;
1368
1369 hMenu = GetMenu(FILEHASH_parent_thread_main_window_handle);
1370 FILEHASH_use_sound = 0;
1371 CheckMenuItem(hMenu, ID_OPTIONS_USE_SOUND, MF_UNCHECKED);
1372 }
1373 else
1374 {
1375 HMENU hMenu;
1376
1377 hMenu = GetMenu(FILEHASH_parent_thread_main_window_handle);
1378 FILEHASH_use_sound = 1;
1379 CheckMenuItem(hMenu, ID_OPTIONS_USE_SOUND, MF_CHECKED);
1380 }
1381 return 0;
1382 }
1383 case ID_OPTIONS_WINDOWALWAYSONTOP:
1384 {
1385 if (FILEHASH_always_on_top)
1386 {
1387 HMENU hMenu;
1388
1389 hMenu = GetMenu(FILEHASH_parent_thread_main_window_handle);
1390 FILEHASH_always_on_top = 0;
1391 CheckMenuItem(hMenu, ID_OPTIONS_WINDOWALWAYSONTOP, MF_UNCHECKED);
1392 SetWindowPos(FILEHASH_parent_thread_main_window_handle,
1393 HWND_NOTOPMOST,
1394 0,
1395 0,
1396 0,
1397 0,
1398 SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
1399 }
1400 else
1401 {
1402 HMENU hMenu;
1403
1404 hMenu = GetMenu(FILEHASH_parent_thread_main_window_handle);
1405 FILEHASH_always_on_top = 1;
1406 CheckMenuItem(hMenu, ID_OPTIONS_WINDOWALWAYSONTOP, MF_CHECKED);
1407 SetWindowPos(FILEHASH_parent_thread_main_window_handle,
1408 HWND_TOPMOST,
1409 0,
1410 0,
1411 0,
1412 0,
1413 SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
1414 }
1415 return 0;
1416 }
1417 case ID_HELP_ABOUT:
1418 case ID_HELP_HELP:
1419 {
1420 char *msg;
1421 char *first_line = "FILEHASH, Copyright \xA9 2010 David T. Ashley\n\n";
1422 char *second_line = "This program is provided under the GNU General Public License, Version 3, and comes with ABSOLUTELY NO WARRANTY.\n\n";
1423 char *third_line = "This is free software, and you are welcome to redistribute it. For a copy of the source code and license or to inquire "
1424 "about technical matters, please write to "
1425 "David T. Ashley (dashley@gmail.com).\n\n";
1426 char *fourth_line = "[Built on " __DATE__ " at " __TIME__ "]";
1427
1428 msg = malloc(
1429 strlen(first_line) +
1430 strlen(second_line) +
1431 strlen(third_line) +
1432 strlen(fourth_line) +
1433 1);
1434
1435 assert(msg != NULL);
1436
1437 if (msg)
1438 {
1439 strcpy_s(msg, strlen(first_line)+strlen(second_line)+strlen(third_line)+strlen(fourth_line)+1, first_line);
1440 strcat_s(msg, strlen(first_line)+strlen(second_line)+strlen(third_line)+strlen(fourth_line)+1, second_line);
1441 strcat_s(msg, strlen(first_line)+strlen(second_line)+strlen(third_line)+strlen(fourth_line)+1, third_line);
1442 strcat_s(msg, strlen(first_line)+strlen(second_line)+strlen(third_line)+strlen(fourth_line)+1, fourth_line);
1443 MessageBox (hwnd,
1444 msg,
1445 FILEHASH_szAppName,
1446 MB_OK|MB_ICONINFORMATION) ;
1447 free(msg);
1448 }
1449 return 0 ;
1450 }
1451 }
1452 break;
1453 }
1454 }
1455
1456 return DefWindowProc (hwnd, message, wParam, lParam) ;
1457 }
1458
1459
1460 //This is the child thread which is started in order to calculate the SHA-512
1461 //of a single group of files. This is done because a single-threaded approach
1462 //does not allow the GUI to continue to receive Windows events, and it
1463 //clogs up the desktop with an unmoveable unresponsive blob. This child
1464 //thread keeps its eye on the abort flag, and will terminate if it sees that.
1465 //It takes its input from the top of the list of filenames, and returns
1466 //the SHA-512, which takes some time to compute.
1467 //
1468 static unsigned __stdcall FILEHASH_ChildThreadFunc(void *pArguments)
1469 {
1470 int fidx;
1471 //The index of the table entry we're currently processing.
1472 DWORD file_attributes;
1473 //The returned file attributes from the OS.
1474 HANDLE hFile = (HANDLE) -1;
1475 //The file handle used to get size and to open for reading. This being
1476 //not the error value signals that it is valid and will need to be closed.
1477 DWORD file_size=0;
1478 //File size obtained from a call to the GetFileSize() function.
1479 DWORD file_size_high=0;
1480 //High 32 bits of same.
1481 DWORD last_error=0;
1482 //Result of the GetLastError() function. This is required to properly decode
1483 //the file size when very large files are involved.
1484 DWORD rc = 0;
1485 //Return code from file seek.
1486 BOOL rv = 0;
1487
1488 struct FILEHASH_SHA512_Sha512StateStruct sha512s;
1489 struct FILEHASH_SHA512_Sha512ResultStruct sha512r;
1490 int exit_flag = 0;
1491 DWORD bytes_read = 0;
1492
1493
1494 //We have been invoked. We now just signature files until the list is
1495 //done or until we are asked to gracefully abort.
1496 for (
1497 fidx = 0;
1498 (fidx<FILEHASH_MAXFILES) && (FILEHASH_file_info.file_info[fidx].fpath[0] != 0) && (!FILEHASH_thread_abort_request);
1499 fidx++
1500 )
1501 {
1502 //Set any values here that are critical to have right in case we must abort.
1503 hFile = (HANDLE) -1;
1504 //This has to be the error value. If we abort, need to know whether
1505 //to try to close this.
1506
1507 /********************************************************************************/
1508 /********************************************************************************/
1509 /******* F I L E A T T R I B U T E S ***************************************/
1510 /********************************************************************************/
1511 /********************************************************************************/
1512 file_attributes = GetFileAttributes((char *)FILEHASH_file_info.file_info[fidx].fpath);
1513 if (file_attributes == 0xFFFFFFFF)
1514 {
1515 FILEHASH_file_info.file_info[fidx].is_directory_error = 1;
1516 //Signal trouble trying to figure out if this is a directory. This also
1517 //signals that the OS does not understand the file path, so can't do much.
1518 }
1519 else if (file_attributes & FILE_ATTRIBUTE_DIRECTORY)
1520 {
1521 FILEHASH_file_info.file_info[fidx].is_directory = 1;
1522 //This is a directory.
1523 }
1524
1525 //In any case, the is_directory information is now valid.
1526 FILEHASH_file_info.file_info[fidx].is_directory_valid = 1;
1527
1528 /********************************************************************************/
1529 /********************************************************************************/
1530 /******* F I L E S I Z E ***************************************************/
1531 /********************************************************************************/
1532 /********************************************************************************/
1533 //If this is a directory or if there was an error getting information, we
1534 //cannot go forward with finding file size information.
1535 if (FILEHASH_file_info.file_info[fidx].is_directory || FILEHASH_file_info.file_info[fidx].is_directory_error)
1536 {
1537 FILEHASH_file_info.file_info[fidx].file_size_error = 1;
1538 }
1539 else
1540 {
1541 hFile = CreateFile ((char *)FILEHASH_file_info.file_info[fidx].fpath,
1542 GENERIC_READ,
1543 FILE_SHARE_READ | FILE_SHARE_WRITE,
1544 NULL,
1545 OPEN_EXISTING,
1546 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
1547 (HANDLE)NULL);
1548 //Try to open the file to look at it. The documentation
1549 //of the CreateFile() call is misleading in the MSDN help.
1550 //A web reference said that the flag combination above,
1551 //
1552 // FILE_SHARE_READ | FILE_SHARE_WRITE,
1553 //
1554 //means "exclude none", i.e. allow others to have file open for both read
1555 //and write. This seems to be the right combination to allow
1556 //the signaturing of documents that are open with Microsoft
1557 //Word or other applications. I have no idea what will happen
1558 //if the file size changes while the file is open, but I
1559 //assume that the EOF will become true or there will be an error,
1560 //either of which will terminate processing of the file.
1561 if (hFile == (HANDLE) -1)
1562 {
1563 //Open error. Can't go further.
1564 FILEHASH_file_info.file_info[fidx].file_size_error = 1;
1565 }
1566 else
1567 {
1568 //Try to obtain the file size.
1569 file_size = GetFileSize(hFile, &file_size_high);
1570
1571 //Try to get the error flags, which we may need.
1572 last_error = GetLastError();
1573
1574 //There is some voodoo involved with file size and the
1575 //error code. This is documented in the GetFileSize() docs.
1576 if ((file_size == 0xFFFFFFFF) && (last_error != NO_ERROR))
1577 {
1578 FILEHASH_file_info.file_info[fidx].file_size_error = 1;
1579 }
1580 else
1581 {
1582 unsigned __int64 lo, hi, composite;
1583 //If we're here, we have a clean size. Convert it and display it.
1584
1585 //Play the bit games to get the size.
1586 lo = (unsigned __int64)file_size;
1587 hi = (unsigned __int64)file_size_high;
1588 composite = lo + (hi << 32);
1589 FILEHASH_file_info.file_info[fidx].file_size = composite;
1590 }
1591 }
1592 }
1593
1594 //The file size information is now valid in any case.
1595 FILEHASH_file_info.file_info[fidx].file_size_valid = 1;
1596
1597 //At this point there is potentially progress to report to
1598 //the main thread. We will sit and spin until the main
1599 //thread will accept a posted event announcing progress
1600 //or until we are aborted.
1601 while (!PostMessage(FILEHASH_parent_thread_main_window_handle,
1602 WM_USER_EV_CHILD_THREAD_PROGRESS,
1603 0,
1604 0)
1605 &&
1606 !FILEHASH_thread_abort_request)
1607 {
1608 Sleep(1000); //Wait 1 second until trying again.
1609 //1000ms is a long time for a modern computer,
1610 //and this should be OK to ease the load if
1611 //the system is encountering performance difficulties.
1612 }
1613
1614 /********************************************************************************/
1615 /********************************************************************************/
1616 /******* S H A - 5 1 2 *******************************************************/
1617 /********************************************************************************/
1618 /********************************************************************************/
1619 if (hFile == (HANDLE) -1)
1620 {
1621 //File handle signals an error condition. We cannot
1622 //even read the file for SHA-512. Just set info
1623 //and boogie.
1624 strcpy_s((char *)FILEHASH_file_info.file_info[fidx].sha512, sizeof(FILEHASH_file_info.file_info[fidx].sha512), "INVALID FILE HANDLE");
1625 }
1626 else
1627 {
1628 //This is the meat of the matter where we read the file contents and do
1629 //the hash calculations. The assumption made is the the buffer size
1630 //will be somewhere in the range of 16K-1M, so that the time to process
1631 //that much data is fairly small. This should be enough granularity
1632 //for a graceful voluntary thread abort.
1633 //
1634 //Rewind the file to positon 0.
1635 rc = SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
1636 if (rc == 0xFFFFFFFF)
1637 {
1638 strcpy_s((char *)FILEHASH_file_info.file_info[fidx].sha512, sizeof(FILEHASH_file_info.file_info[fidx].sha512), "FILE SEEK ERROR");
1639 goto file_read_loop_endpoint;
1640 }
1641
1642 //Initialize the SHA512 state block.
1643 FILEHASH_SHA512_Sha512StateStructOpen(&sha512s);
1644
1645 //Iterate through, reading the file and processing the blocks. In the case
1646 //of an abort, we assign the strings appropriately.
1647 exit_flag = 0;
1648 while (!exit_flag)
1649 {
1650 rv = ReadFile(hFile, FILEHASH_file_read_buf, FILEHASH_FILE_READ_BUF_SIZE, &bytes_read, NULL);
1651
1652 //Add whatever has been read to the running calculation.
1653 if (bytes_read)
1654 {
1655 FILEHASH_SHA512_Sha512StateStructAddData(&sha512s, FILEHASH_file_read_buf, bytes_read);
1656 }
1657
1658 //Process error conditions.
1659 if (!rv)
1660 {
1661 strcpy_s((char *)FILEHASH_file_info.file_info[fidx].sha512, sizeof(FILEHASH_file_info.file_info[fidx].sha512), "FILE READ ERROR");
1662 goto file_read_loop_endpoint;
1663 }
1664
1665 if (!bytes_read)
1666 {
1667 //This is the no-error abort when we hit the end of the file naturally.
1668 exit_flag = 1;
1669 }
1670 else if (FILEHASH_thread_abort_request)
1671 {
1672 strcpy_s((char *)FILEHASH_file_info.file_info[fidx].sha512, sizeof(FILEHASH_file_info.file_info[fidx].sha512), "OPERATION ABORTED");
1673 goto file_read_loop_endpoint;
1674 }
1675 }
1676
1677 //This is the natural fallthrough when there was no error.
1678 //
1679 //Close up the SHA-512 structure.
1680 FILEHASH_SHA512_Sha512StateStructClose(&sha512s, &sha512r);
1681
1682 //Form up an SHA-512 string.
1683 strcpy_s((char *)FILEHASH_file_info.file_info[fidx].sha512, sizeof(FILEHASH_file_info.file_info[fidx].sha512), sha512r.sha512_chars);
1684
1685 //Report progress to parent thread.
1686 while (!PostMessage(FILEHASH_parent_thread_main_window_handle,
1687 WM_USER_EV_CHILD_THREAD_PROGRESS,
1688 0,
1689 0))
1690 {
1691 Sleep(1000); //Wait 1 second until trying again.
1692 }
1693
1694 file_read_loop_endpoint: ;
1695 }
1696
1697 //In any case both CRC32 and MD5 info filled in.
1698 FILEHASH_file_info.file_info[fidx].sha512_valid = 1;
1699
1700 //If the file handle is valid (i.e. we opened the file) we must
1701 //close it, regardless of cause.
1702 if (hFile != (HANDLE)-1)
1703 {
1704 BOOL close_result;
1705
1706 close_result = CloseHandle(hFile);
1707
1708 if (!close_result)
1709 {
1710 strcpy_s((char *)FILEHASH_file_info.file_info[fidx].sha512, sizeof(FILEHASH_file_info.file_info[fidx].sha512), "FILE HANDLE CLOSE ERROR");
1711 }
1712 }
1713 } // End for() each table entry loop.
1714
1715
1716 //Report completion to parent thread.
1717 if (FILEHASH_thread_abort_request)
1718 FILEHASH_file_info.aborted = 1;
1719 else
1720 FILEHASH_file_info.terminated_normally = 1;
1721
1722 while (!PostMessage(FILEHASH_parent_thread_main_window_handle,
1723 WM_USER_EV_CHILD_THREAD_ENDING,
1724 0,
1725 0))
1726 {
1727 Sleep(1000); //Wait 1 second until trying again.
1728 }
1729
1730 return 0;
1731 }
1732
1733
1734 //This function does a hard sync stop on the child thread if it is running.
1735 //If not running, returns immediately. Because the time to CRC32 or MD5 a
1736 //single buffer is negligible, it shouldn't take long for the thread to
1737 //gracefully end itself.
1738 //
1739 static void FILEHASH_ChildThreadHardSyncStop(void)
1740 {
1741 if (FILEHASH_child_thread_is_active)
1742 {
1743 HMENU hMenu;
1744
1745 FILEHASH_thread_abort_request = 1;
1746
1747 WaitForSingleObject(FILEHASH_child_handle, INFINITE);
1748
1749 //The thread is done.
1750 FILEHASH_child_thread_is_active = 0;
1751 FILEHASH_thread_abort_request = 0;
1752 FILEHASH_child_handle = 0;
1753
1754 hMenu = GetMenu(FILEHASH_parent_thread_main_window_handle);
1755
1756 EnableMenuItem(hMenu, ID_ACTIONS_HALTSIGOP, MF_GRAYED);
1757 }
1758 }
1759
1760
1761 //Starts up a child thread.
1762 //
1763 static void FILEHASH_ChildThreadStart(void)
1764 {
1765 unsigned thread_id;
1766 //We just discard this.
1767
1768 //We don't dare start up our single child thread unless none is already running.
1769 //In the release version, such an error is just ignored, but in the debug version,
1770 //hard stop.
1771 assert(!FILEHASH_child_thread_is_active);
1772
1773 if (!FILEHASH_child_thread_is_active)
1774 {
1775 //Test compilation of second thread invocation.
1776 FILEHASH_child_handle = (HANDLE) _beginthreadex(NULL,
1777 0,
1778 &FILEHASH_ChildThreadFunc,
1779 NULL,
1780 0,
1781 &thread_id);
1782 if (!FILEHASH_child_handle)
1783 {
1784 //This is an error return from _beginthreadex.
1785 assert(0);
1786 }
1787 else
1788 {
1789 HMENU hMenu;
1790
1791 FILEHASH_child_thread_is_active = 1;
1792
1793 hMenu = GetMenu(FILEHASH_parent_thread_main_window_handle);
1794
1795 EnableMenuItem(hMenu, ID_ACTIONS_HALTSIGOP, MF_ENABLED);
1796 }
1797 }
1798 }
1799
1800
1801 //Makes a generic sound to alert user. Honors the FILEHASH_use_sound state.
1802 //
1803 static void FILEHASH_MakeGenericSound(void)
1804 {
1805 if (FILEHASH_use_sound)
1806 {
1807 MessageBeep(MB_ICONEXCLAMATION);
1808 }
1809 }
1810
1811
1812 //----------------------------------------------------------------------------------------------------
1813 // GNU GENERAL PUBLIC LICENSE
1814 // Version 3, 29 June 2007
1815 //
1816 // Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
1817 // Everyone is permitted to copy and distribute verbatim copies
1818 // of this license document, but changing it is not allowed.
1819 //
1820 // Preamble
1821 //
1822 // The GNU General Public License is a free, copyleft license for
1823 //software and other kinds of works.
1824 //
1825 // The licenses for most software and other practical works are designed
1826 //to take away your freedom to share and change the works. By contrast,
1827 //the GNU General Public License is intended to guarantee your freedom to
1828 //share and change all versions of a program--to make sure it remains free
1829 //software for all its users. We, the Free Software Foundation, use the
1830 //GNU General Public License for most of our software; it applies also to
1831 //any other work released this way by its authors. You can apply it to
1832 //your programs, too.
1833 //
1834 // When we speak of free software, we are referring to freedom, not
1835 //price. Our General Public Licenses are designed to make sure that you
1836 //have the freedom to distribute copies of free software (and charge for
1837 //them if you wish), that you receive source code or can get it if you
1838 //want it, that you can change the software or use pieces of it in new
1839 //free programs, and that you know you can do these things.
1840 //
1841 // To protect your rights, we need to prevent others from denying you
1842 //these rights or asking you to surrender the rights. Therefore, you have
1843 //certain responsibilities if you distribute copies of the software, or if
1844 //you modify it: responsibilities to respect the freedom of others.
1845 //
1846 // For example, if you distribute copies of such a program, whether
1847 //gratis or for a fee, you must pass on to the recipients the same
1848 //freedoms that you received. You must make sure that they, too, receive
1849 //or can get the source code. And you must show them these terms so they
1850 //know their rights.
1851 //
1852 // Developers that use the GNU GPL protect your rights with two steps:
1853 //(1) assert copyright on the software, and (2) offer you this License
1854 //giving you legal permission to copy, distribute and/or modify it.
1855 //
1856 // For the developers' and authors' protection, the GPL clearly explains
1857 //that there is no warranty for this free software. For both users' and
1858 //authors' sake, the GPL requires that modified versions be marked as
1859 //changed, so that their problems will not be attributed erroneously to
1860 //authors of previous versions.
1861 //
1862 // Some devices are designed to deny users access to install or run
1863 //modified versions of the software inside them, although the manufacturer
1864 //can do so. This is fundamentally incompatible with the aim of
1865 //protecting users' freedom to change the software. The systematic
1866 //pattern of such abuse occurs in the area of products for individuals to
1867 //use, which is precisely where it is most unacceptable. Therefore, we
1868 //have designed this version of the GPL to prohibit the practice for those
1869 //products. If such problems arise substantially in other domains, we
1870 //stand ready to extend this provision to those domains in future versions
1871 //of the GPL, as needed to protect the freedom of users.
1872 //
1873 // Finally, every program is threatened constantly by software patents.
1874 //States should not allow patents to restrict development and use of
1875 //software on general-purpose computers, but in those that do, we wish to
1876 //avoid the special danger that patents applied to a free program could
1877 //make it effectively proprietary. To prevent this, the GPL assures that
1878 //patents cannot be used to render the program non-free.
1879 //
1880 // The precise terms and conditions for copying, distribution and
1881 //modification follow.
1882 //
1883 // TERMS AND CONDITIONS
1884 //
1885 // 0. Definitions.
1886 //
1887 // "This License" refers to version 3 of the GNU General Public License.
1888 //
1889 // "Copyright" also means copyright-like laws that apply to other kinds of
1890 //works, such as semiconductor masks.
1891 //
1892 // "The Program" refers to any copyrightable work licensed under this
1893 //License. Each licensee is addressed as "you". "Licensees" and
1894 //"recipients" may be individuals or organizations.
1895 //
1896 // To "modify" a work means to copy from or adapt all or part of the work
1897 //in a fashion requiring copyright permission, other than the making of an
1898 //exact copy. The resulting work is called a "modified version" of the
1899 //earlier work or a work "based on" the earlier work.
1900 //
1901 // A "covered work" means either the unmodified Program or a work based
1902 //on the Program.
1903 //
1904 // To "propagate" a work means to do anything with it that, without
1905 //permission, would make you directly or secondarily liable for
1906 //infringement under applicable copyright law, except executing it on a
1907 //computer or modifying a private copy. Propagation includes copying,
1908 //distribution (with or without modification), making available to the
1909 //public, and in some countries other activities as well.
1910 //
1911 // To "convey" a work means any kind of propagation that enables other
1912 //parties to make or receive copies. Mere interaction with a user through
1913 //a computer network, with no transfer of a copy, is not conveying.
1914 //
1915 // An interactive user interface displays "Appropriate Legal Notices"
1916 //to the extent that it includes a convenient and prominently visible
1917 //feature that (1) displays an appropriate copyright notice, and (2)
1918 //tells the user that there is no warranty for the work (except to the
1919 //extent that warranties are provided), that licensees may convey the
1920 //work under this License, and how to view a copy of this License. If
1921 //the interface presents a list of user commands or options, such as a
1922 //menu, a prominent item in the list meets this criterion.
1923 //
1924 // 1. Source Code.
1925 //
1926 // The "source code" for a work means the preferred form of the work
1927 //for making modifications to it. "Object code" means any non-source
1928 //form of a work.
1929 //
1930 // A "Standard Interface" means an interface that either is an official
1931 //standard defined by a recognized standards body, or, in the case of
1932 //interfaces specified for a particular programming language, one that
1933 //is widely used among developers working in that language.
1934 //
1935 // The "System Libraries" of an executable work include anything, other
1936 //than the work as a whole, that (a) is included in the normal form of
1937 //packaging a Major Component, but which is not part of that Major
1938 //Component, and (b) serves only to enable use of the work with that
1939 //Major Component, or to implement a Standard Interface for which an
1940 //implementation is available to the public in source code form. A
1941 //"Major Component", in this context, means a major essential component
1942 //(kernel, window system, and so on) of the specific operating system
1943 //(if any) on which the executable work runs, or a compiler used to
1944 //produce the work, or an object code interpreter used to run it.
1945 //
1946 // The "Corresponding Source" for a work in object code form means all
1947 //the source code needed to generate, install, and (for an executable
1948 //work) run the object code and to modify the work, including scripts to
1949 //control those activities. However, it does not include the work's
1950 //System Libraries, or general-purpose tools or generally available free
1951 //programs which are used unmodified in performing those activities but
1952 //which are not part of the work. For example, Corresponding Source
1953 //includes interface definition files associated with source files for
1954 //the work, and the source code for shared libraries and dynamically
1955 //linked subprograms that the work is specifically designed to require,
1956 //such as by intimate data communication or control flow between those
1957 //subprograms and other parts of the work.
1958 //
1959 // The Corresponding Source need not include anything that users
1960 //can regenerate automatically from other parts of the Corresponding
1961 //Source.
1962 //
1963 // The Corresponding Source for a work in source code form is that
1964 //same work.
1965 //
1966 // 2. Basic Permissions.
1967 //
1968 // All rights granted under this License are granted for the term of
1969 //copyright on the Program, and are irrevocable provided the stated
1970 //conditions are met. This License explicitly affirms your unlimited
1971 //permission to run the unmodified Program. The output from running a
1972 //covered work is covered by this License only if the output, given its
1973 //content, constitutes a covered work. This License acknowledges your
1974 //rights of fair use or other equivalent, as provided by copyright law.
1975 //
1976 // You may make, run and propagate covered works that you do not
1977 //convey, without conditions so long as your license otherwise remains
1978 //in force. You may convey covered works to others for the sole purpose
1979 //of having them make modifications exclusively for you, or provide you
1980 //with facilities for running those works, provided that you comply with
1981 //the terms of this License in conveying all material for which you do
1982 //not control copyright. Those thus making or running the covered works
1983 //for you must do so exclusively on your behalf, under your direction
1984 //and control, on terms that prohibit them from making any copies of
1985 //your copyrighted material outside their relationship with you.
1986 //
1987 // Conveying under any other circumstances is permitted solely under
1988 //the conditions stated below. Sublicensing is not allowed; section 10
1989 //makes it unnecessary.
1990 //
1991 // 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
1992 //
1993 // No covered work shall be deemed part of an effective technological
1994 //measure under any applicable law fulfilling obligations under article
1995 //11 of the WIPO copyright treaty adopted on 20 December 1996, or
1996 //similar laws prohibiting or restricting circumvention of such
1997 //measures.
1998 //
1999 // When you convey a covered work, you waive any legal power to forbid
2000 //circumvention of technological measures to the extent such circumvention
2001 //is effected by exercising rights under this License with respect to
2002 //the covered work, and you disclaim any intention to limit operation or
2003 //modification of the work as a means of enforcing, against the work's
2004 //users, your or third parties' legal rights to forbid circumvention of
2005 //technological measures.
2006 //
2007 // 4. Conveying Verbatim Copies.
2008 //
2009 // You may convey verbatim copies of the Program's source code as you
2010 //receive it, in any medium, provided that you conspicuously and
2011 //appropriately publish on each copy an appropriate copyright notice;
2012 //keep intact all notices stating that this License and any
2013 //non-permissive terms added in accord with section 7 apply to the code;
2014 //keep intact all notices of the absence of any warranty; and give all
2015 //recipients a copy of this License along with the Program.
2016 //
2017 // You may charge any price or no price for each copy that you convey,
2018 //and you may offer support or warranty protection for a fee.
2019 //
2020 // 5. Conveying Modified Source Versions.
2021 //
2022 // You may convey a work based on the Program, or the modifications to
2023 //produce it from the Program, in the form of source code under the
2024 //terms of section 4, provided that you also meet all of these conditions:
2025 //
2026 // a) The work must carry prominent notices stating that you modified
2027 // it, and giving a relevant date.
2028 //
2029 // b) The work must carry prominent notices stating that it is
2030 // released under this License and any conditions added under section
2031 // 7. This requirement modifies the requirement in section 4 to
2032 // "keep intact all notices".
2033 //
2034 // c) You must license the entire work, as a whole, under this
2035 // License to anyone who comes into possession of a copy. This
2036 // License will therefore apply, along with any applicable section 7
2037 // additional terms, to the whole of the work, and all its parts,
2038 // regardless of how they are packaged. This License gives no
2039 // permission to license the work in any other way, but it does not
2040 // invalidate such permission if you have separately received it.
2041 //
2042 // d) If the work has interactive user interfaces, each must display
2043 // Appropriate Legal Notices; however, if the Program has interactive
2044 // interfaces that do not display Appropriate Legal Notices, your
2045 // work need not make them do so.
2046 //
2047 // A compilation of a covered work with other separate and independent
2048 //works, which are not by their nature extensions of the covered work,
2049 //and which are not combined with it such as to form a larger program,
2050 //in or on a volume of a storage or distribution medium, is called an
2051 //"aggregate" if the compilation and its resulting copyright are not
2052 //used to limit the access or legal rights of the compilation's users
2053 //beyond what the individual works permit. Inclusion of a covered work
2054 //in an aggregate does not cause this License to apply to the other
2055 //parts of the aggregate.
2056 //
2057 // 6. Conveying Non-Source Forms.
2058 //
2059 // You may convey a covered work in object code form under the terms
2060 //of sections 4 and 5, provided that you also convey the
2061 //machine-readable Corresponding Source under the terms of this License,
2062 //in one of these ways:
2063 //
2064 // a) Convey the object code in, or embodied in, a physical product
2065 // (including a physical distribution medium), accompanied by the
2066 // Corresponding Source fixed on a durable physical medium
2067 // customarily used for software interchange.
2068 //
2069 // b) Convey the object code in, or embodied in, a physical product
2070 // (including a physical distribution medium), accompanied by a
2071 // written offer, valid for at least three years and valid for as
2072 // long as you offer spare parts or customer support for that product
2073 // model, to give anyone who possesses the object code either (1) a
2074 // copy of the Corresponding Source for all the software in the
2075 // product that is covered by this License, on a durable physical
2076 // medium customarily used for software interchange, for a price no
2077 // more than your reasonable cost of physically performing this
2078 // conveying of source, or (2) access to copy the
2079 // Corresponding Source from a network server at no charge.
2080 //
2081 // c) Convey individual copies of the object code with a copy of the
2082 // written offer to provide the Corresponding Source. This
2083 // alternative is allowed only occasionally and noncommercially, and
2084 // only if you received the object code with such an offer, in accord
2085 // with subsection 6b.
2086 //
2087 // d) Convey the object code by offering access from a designated
2088 // place (gratis or for a charge), and offer equivalent access to the
2089 // Corresponding Source in the same way through the same place at no
2090 // further charge. You need not require recipients to copy the
2091 // Corresponding Source along with the object code. If the place to
2092 // copy the object code is a network server, the Corresponding Source
2093 // may be on a different server (operated by you or a third party)
2094 // that supports equivalent copying facilities, provided you maintain
2095 // clear directions next to the object code saying where to find the
2096 // Corresponding Source. Regardless of what server hosts the
2097 // Corresponding Source, you remain obligated to ensure that it is
2098 // available for as long as needed to satisfy these requirements.
2099 //
2100 // e) Convey the object code using peer-to-peer transmission, provided
2101 // you inform other peers where the object code and Corresponding
2102 // Source of the work are being offered to the general public at no
2103 // charge under subsection 6d.
2104 //
2105 // A separable portion of the object code, whose source code is excluded
2106 //from the Corresponding Source as a System Library, need not be
2107 //included in conveying the object code work.
2108 //
2109 // A "User Product" is either (1) a "consumer product", which means any
2110 //tangible personal property which is normally used for personal, family,
2111 //or household purposes, or (2) anything designed or sold for incorporation
2112 //into a dwelling. In determining whether a product is a consumer product,
2113 //doubtful cases shall be resolved in favor of coverage. For a particular
2114 //product received by a particular user, "normally used" refers to a
2115 //typical or common use of that class of product, regardless of the status
2116 //of the particular user or of the way in which the particular user
2117 //actually uses, or expects or is expected to use, the product. A product
2118 //is a consumer product regardless of whether the product has substantial
2119 //commercial, industrial or non-consumer uses, unless such uses represent
2120 //the only significant mode of use of the product.
2121 //
2122 // "Installation Information" for a User Product means any methods,
2123 //procedures, authorization keys, or other information required to install
2124 //and execute modified versions of a covered work in that User Product from
2125 //a modified version of its Corresponding Source. The information must
2126 //suffice to ensure that the continued functioning of the modified object
2127 //code is in no case prevented or interfered with solely because
2128 //modification has been made.
2129 //
2130 // If you convey an object code work under this section in, or with, or
2131 //specifically for use in, a User Product, and the conveying occurs as
2132 //part of a transaction in which the right of possession and use of the
2133 //User Product is transferred to the recipient in perpetuity or for a
2134 //fixed term (regardless of how the transaction is characterized), the
2135 //Corresponding Source conveyed under this section must be accompanied
2136 //by the Installation Information. But this requirement does not apply
2137 //if neither you nor any third party retains the ability to install
2138 //modified object code on the User Product (for example, the work has
2139 //been installed in ROM).
2140 //
2141 // The requirement to provide Installation Information does not include a
2142 //requirement to continue to provide support service, warranty, or updates
2143 //for a work that has been modified or installed by the recipient, or for
2144 //the User Product in which it has been modified or installed. Access to a
2145 //network may be denied when the modification itself materially and
2146 //adversely affects the operation of the network or violates the rules and
2147 //protocols for communication across the network.
2148 //
2149 // Corresponding Source conveyed, and Installation Information provided,
2150 //in accord with this section must be in a format that is publicly
2151 //documented (and with an implementation available to the public in
2152 //source code form), and must require no special password or key for
2153 //unpacking, reading or copying.
2154 //
2155 // 7. Additional Terms.
2156 //
2157 // "Additional permissions" are terms that supplement the terms of this
2158 //License by making exceptions from one or more of its conditions.
2159 //Additional permissions that are applicable to the entire Program shall
2160 //be treated as though they were included in this License, to the extent
2161 //that they are valid under applicable law. If additional permissions
2162 //apply only to part of the Program, that part may be used separately
2163 //under those permissions, but the entire Program remains governed by
2164 //this License without regard to the additional permissions.
2165 //
2166 // When you convey a copy of a covered work, you may at your option
2167 //remove any additional permissions from that copy, or from any part of
2168 //it. (Additional permissions may be written to require their own
2169 //removal in certain cases when you modify the work.) You may place
2170 //additional permissions on material, added by you to a covered work,
2171 //for which you have or can give appropriate copyright permission.
2172 //
2173 // Notwithstanding any other provision of this License, for material you
2174 //add to a covered work, you may (if authorized by the copyright holders of
2175 //that material) supplement the terms of this License with terms:
2176 //
2177 // a) Disclaiming warranty or limiting liability differently from the
2178 // terms of sections 15 and 16 of this License; or
2179 //
2180 // b) Requiring preservation of specified reasonable legal notices or
2181 // author attributions in that material or in the Appropriate Legal
2182 // Notices displayed by works containing it; or
2183 //
2184 // c) Prohibiting misrepresentation of the origin of that material, or
2185 // requiring that modified versions of such material be marked in
2186 // reasonable ways as different from the original version; or
2187 //
2188 // d) Limiting the use for publicity purposes of names of licensors or
2189 // authors of the material; or
2190 //
2191 // e) Declining to grant rights under trademark law for use of some
2192 // trade names, trademarks, or service marks; or
2193 //
2194 // f) Requiring indemnification of licensors and authors of that
2195 // material by anyone who conveys the material (or modified versions of
2196 // it) with contractual assumptions of liability to the recipient, for
2197 // any liability that these contractual assumptions directly impose on
2198 // those licensors and authors.
2199 //
2200 // All other non-permissive additional terms are considered "further
2201 //restrictions" within the meaning of section 10. If the Program as you
2202 //received it, or any part of it, contains a notice stating that it is
2203 //governed by this License along with a term that is a further
2204 //restriction, you may remove that term. If a license document contains
2205 //a further restriction but permits relicensing or conveying under this
2206 //License, you may add to a covered work material governed by the terms
2207 //of that license document, provided that the further restriction does
2208 //not survive such relicensing or conveying.
2209 //
2210 // If you add terms to a covered work in accord with this section, you
2211 //must place, in the relevant source files, a statement of the
2212 //additional terms that apply to those files, or a notice indicating
2213 //where to find the applicable terms.
2214 //
2215 // Additional terms, permissive or non-permissive, may be stated in the
2216 //form of a separately written license, or stated as exceptions;
2217 //the above requirements apply either way.
2218 //
2219 // 8. Termination.
2220 //
2221 // You may not propagate or modify a covered work except as expressly
2222 //provided under this License. Any attempt otherwise to propagate or
2223 //modify it is void, and will automatically terminate your rights under
2224 //this License (including any patent licenses granted under the third
2225 //paragraph of section 11).
2226 //
2227 // However, if you cease all violation of this License, then your
2228 //license from a particular copyright holder is reinstated (a)
2229 //provisionally, unless and until the copyright holder explicitly and
2230 //finally terminates your license, and (b) permanently, if the copyright
2231 //holder fails to notify you of the violation by some reasonable means
2232 //prior to 60 days after the cessation.
2233 //
2234 // Moreover, your license from a particular copyright holder is
2235 //reinstated permanently if the copyright holder notifies you of the
2236 //violation by some reasonable means, this is the first time you have
2237 //received notice of violation of this License (for any work) from that
2238 //copyright holder, and you cure the violation prior to 30 days after
2239 //your receipt of the notice.
2240 //
2241 // Termination of your rights under this section does not terminate the
2242 //licenses of parties who have received copies or rights from you under
2243 //this License. If your rights have been terminated and not permanently
2244 //reinstated, you do not qualify to receive new licenses for the same
2245 //material under section 10.
2246 //
2247 // 9. Acceptance Not Required for Having Copies.
2248 //
2249 // You are not required to accept this License in order to receive or
2250 //run a copy of the Program. Ancillary propagation of a covered work
2251 //occurring solely as a consequence of using peer-to-peer transmission
2252 //to receive a copy likewise does not require acceptance. However,
2253 //nothing other than this License grants you permission to propagate or
2254 //modify any covered work. These actions infringe copyright if you do
2255 //not accept this License. Therefore, by modifying or propagating a
2256 //covered work, you indicate your acceptance of this License to do so.
2257 //
2258 // 10. Automatic Licensing of Downstream Recipients.
2259 //
2260 // Each time you convey a covered work, the recipient automatically
2261 //receives a license from the original licensors, to run, modify and
2262 //propagate that work, subject to this License. You are not responsible
2263 //for enforcing compliance by third parties with this License.
2264 //
2265 // An "entity transaction" is a transaction transferring control of an
2266 //organization, or substantially all assets of one, or subdividing an
2267 //organization, or merging organizations. If propagation of a covered
2268 //work results from an entity transaction, each party to that
2269 //transaction who receives a copy of the work also receives whatever
2270 //licenses to the work the party's predecessor in interest had or could
2271 //give under the previous paragraph, plus a right to possession of the
2272 //Corresponding Source of the work from the predecessor in interest, if
2273 //the predecessor has it or can get it with reasonable efforts.
2274 //
2275 // You may not impose any further restrictions on the exercise of the
2276 //rights granted or affirmed under this License. For example, you may
2277 //not impose a license fee, royalty, or other charge for exercise of
2278 //rights granted under this License, and you may not initiate litigation
2279 //(including a cross-claim or counterclaim in a lawsuit) alleging that
2280 //any patent claim is infringed by making, using, selling, offering for
2281 //sale, or importing the Program or any portion of it.
2282 //
2283 // 11. Patents.
2284 //
2285 // A "contributor" is a copyright holder who authorizes use under this
2286 //License of the Program or a work on which the Program is based. The
2287 //work thus licensed is called the contributor's "contributor version".
2288 //
2289 // A contributor's "essential patent claims" are all patent claims
2290 //owned or controlled by the contributor, whether already acquired or
2291 //hereafter acquired, that would be infringed by some manner, permitted
2292 //by this License, of making, using, or selling its contributor version,
2293 //but do not include claims that would be infringed only as a
2294 //consequence of further modification of the contributor version. For
2295 //purposes of this definition, "control" includes the right to grant
2296 //patent sublicenses in a manner consistent with the requirements of
2297 //this License.
2298 //
2299 // Each contributor grants you a non-exclusive, worldwide, royalty-free
2300 //patent license under the contributor's essential patent claims, to
2301 //make, use, sell, offer for sale, import and otherwise run, modify and
2302 //propagate the contents of its contributor version.
2303 //
2304 // In the following three paragraphs, a "patent license" is any express
2305 //agreement or commitment, however denominated, not to enforce a patent
2306 //(such as an express permission to practice a patent or covenant not to
2307 //sue for patent infringement). To "grant" such a patent license to a
2308 //party means to make such an agreement or commitment not to enforce a
2309 //patent against the party.
2310 //
2311 // If you convey a covered work, knowingly relying on a patent license,
2312 //and the Corresponding Source of the work is not available for anyone
2313 //to copy, free of charge and under the terms of this License, through a
2314 //publicly available network server or other readily accessible means,
2315 //then you must either (1) cause the Corresponding Source to be so
2316 //available, or (2) arrange to deprive yourself of the benefit of the
2317 //patent license for this particular work, or (3) arrange, in a manner
2318 //consistent with the requirements of this License, to extend the patent
2319 //license to downstream recipients. "Knowingly relying" means you have
2320 //actual knowledge that, but for the patent license, your conveying the
2321 //covered work in a country, or your recipient's use of the covered work
2322 //in a country, would infringe one or more identifiable patents in that
2323 //country that you have reason to believe are valid.
2324 //
2325 // If, pursuant to or in connection with a single transaction or
2326 //arrangement, you convey, or propagate by procuring conveyance of, a
2327 //covered work, and grant a patent license to some of the parties
2328 //receiving the covered work authorizing them to use, propagate, modify
2329 //or convey a specific copy of the covered work, then the patent license
2330 //you grant is automatically extended to all recipients of the covered
2331 //work and works based on it.
2332 //
2333 // A patent license is "discriminatory" if it does not include within
2334 //the scope of its coverage, prohibits the exercise of, or is
2335 //conditioned on the non-exercise of one or more of the rights that are
2336 //specifically granted under this License. You may not convey a covered
2337 //work if you are a party to an arrangement with a third party that is
2338 //in the business of distributing software, under which you make payment
2339 //to the third party based on the extent of your activity of conveying
2340 //the work, and under which the third party grants, to any of the
2341 //parties who would receive the covered work from you, a discriminatory
2342 //patent license (a) in connection with copies of the covered work
2343 //conveyed by you (or copies made from those copies), or (b) primarily
2344 //for and in connection with specific products or compilations that
2345 //contain the covered work, unless you entered into that arrangement,
2346 //or that patent license was granted, prior to 28 March 2007.
2347 //
2348 // Nothing in this License shall be construed as excluding or limiting
2349 //any implied license or other defenses to infringement that may
2350 //otherwise be available to you under applicable patent law.
2351 //
2352 // 12. No Surrender of Others' Freedom.
2353 //
2354 // If conditions are imposed on you (whether by court order, agreement or
2355 //otherwise) that contradict the conditions of this License, they do not
2356 //excuse you from the conditions of this License. If you cannot convey a
2357 //covered work so as to satisfy simultaneously your obligations under this
2358 //License and any other pertinent obligations, then as a consequence you may
2359 //not convey it at all. For example, if you agree to terms that obligate you
2360 //to collect a royalty for further conveying from those to whom you convey
2361 //the Program, the only way you could satisfy both those terms and this
2362 //License would be to refrain entirely from conveying the Program.
2363 //
2364 // 13. Use with the GNU Affero General Public License.
2365 //
2366 // Notwithstanding any other provision of this License, you have
2367 //permission to link or combine any covered work with a work licensed
2368 //under version 3 of the GNU Affero General Public License into a single
2369 //combined work, and to convey the resulting work. The terms of this
2370 //License will continue to apply to the part which is the covered work,
2371 //but the special requirements of the GNU Affero General Public License,
2372 //section 13, concerning interaction through a network will apply to the
2373 //combination as such.
2374 //
2375 // 14. Revised Versions of this License.
2376 //
2377 // The Free Software Foundation may publish revised and/or new versions of
2378 //the GNU General Public License from time to time. Such new versions will
2379 //be similar in spirit to the present version, but may differ in detail to
2380 //address new problems or concerns.
2381 //
2382 // Each version is given a distinguishing version number. If the
2383 //Program specifies that a certain numbered version of the GNU General
2384 //Public License "or any later version" applies to it, you have the
2385 //option of following the terms and conditions either of that numbered
2386 //version or of any later version published by the Free Software
2387 //Foundation. If the Program does not specify a version number of the
2388 //GNU General Public License, you may choose any version ever published
2389 //by the Free Software Foundation.
2390 //
2391 // If the Program specifies that a proxy can decide which future
2392 //versions of the GNU General Public License can be used, that proxy's
2393 //public statement of acceptance of a version permanently authorizes you
2394 //to choose that version for the Program.
2395 //
2396 // Later license versions may give you additional or different
2397 //permissions. However, no additional obligations are imposed on any
2398 //author or copyright holder as a result of your choosing to follow a
2399 //later version.
2400 //
2401 // 15. Disclaimer of Warranty.
2402 //
2403 // THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
2404 //APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
2405 //HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
2406 //OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
2407 //THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2408 //PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
2409 //IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
2410 //ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
2411 //
2412 // 16. Limitation of Liability.
2413 //
2414 // IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
2415 //WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
2416 //THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
2417 //GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
2418 //USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
2419 //DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
2420 //PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
2421 //EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
2422 //SUCH DAMAGES.
2423 //
2424 // 17. Interpretation of Sections 15 and 16.
2425 //
2426 // If the disclaimer of warranty and limitation of liability provided
2427 //above cannot be given local legal effect according to their terms,
2428 //reviewing courts shall apply local law that most closely approximates
2429 //an absolute waiver of all civil liability in connection with the
2430 //Program, unless a warranty or assumption of liability accompanies a
2431 //copy of the Program in return for a fee.
2432 //
2433 // END OF TERMS AND CONDITIONS
2434 //
2435 // How to Apply These Terms to Your New Programs
2436 //
2437 // If you develop a new program, and you want it to be of the greatest
2438 //possible use to the public, the best way to achieve this is to make it
2439 //free software which everyone can redistribute and change under these terms.
2440 //
2441 // To do so, attach the following notices to the program. It is safest
2442 //to attach them to the start of each source file to most effectively
2443 //state the exclusion of warranty; and each file should have at least
2444 //the "copyright" line and a pointer to where the full notice is found.
2445 //
2446 // <one line to give the program's name and a brief idea of what it does.>
2447 // Copyright (C) <year> <name of author>
2448 //
2449 // This program is free software: you can redistribute it and/or modify
2450 // it under the terms of the GNU General Public License as published by
2451 // the Free Software Foundation, either version 3 of the License, or
2452 // (at your option) any later version.
2453 //
2454 // This program is distributed in the hope that it will be useful,
2455 // but WITHOUT ANY WARRANTY; without even the implied warranty of
2456 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2457 // GNU General Public License for more details.
2458 //
2459 // You should have received a copy of the GNU General Public License
2460 // along with this program. If not, see <http://www.gnu.org/licenses/>.
2461 //
2462 //Also add information on how to contact you by electronic and paper mail.
2463 //
2464 // If the program does terminal interaction, make it output a short
2465 //notice like this when it starts in an interactive mode:
2466 //
2467 // <program> Copyright (C) <year> <name of author>
2468 // This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
2469 // This is free software, and you are welcome to redistribute it
2470 // under certain conditions; type `show c' for details.
2471 //
2472 //The hypothetical commands `show w' and `show c' should show the appropriate
2473 //parts of the General Public License. Of course, your program's commands
2474 //might be different; for a GUI interface, you would use an "about box".
2475 //
2476 // You should also get your employer (if you work as a programmer) or school,
2477 //if any, to sign a "copyright disclaimer" for the program, if necessary.
2478 //For more information on this, and how to apply and follow the GNU GPL, see
2479 //<http://www.gnu.org/licenses/>.
2480 //
2481 // The GNU General Public License does not permit incorporating your program
2482 //into proprietary programs. If your program is a subroutine library, you
2483 //may consider it more useful to permit linking proprietary applications with
2484 //the library. If this is what you want to do, use the GNU Lesser General
2485 //Public License instead of this License. But first, please read
2486 //<http://www.gnu.org/philosophy/why-not-lgpl.html>.
2487 //----------------------------------------------------------------------------------------------------
2488 // End of FILEHASH.C. */
2489 //----------------------------------------------------------------------------------------------------
2490

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25