|
|
1.1.1.11! root 1: /* ! 2: Legal Notice: The source code contained in this file has been derived from ! 3: the source code of Encryption for the Masses 2.02a, which is Copyright (c) ! 4: Paul Le Roux and which is covered by the 'License Agreement for Encryption ! 5: for the Masses'. Modifications and additions to that source code contained ! 6: in this file are Copyright (c) TrueCrypt Foundation and are covered by the ! 7: TrueCrypt License 2.2 the full text of which is contained in the file ! 8: License.txt included in TrueCrypt binary and source code distribution ! 9: packages. */ 1.1 root 10: 1.1.1.7 root 11: #include "Tcdefs.h" 1.1 root 12: 1.1.1.7 root 13: #include <dbt.h> 14: #include <fcntl.h> 15: #include <io.h> 16: #include <shlobj.h> 17: #include <sys/stat.h> 1.1 root 18: #include <stdlib.h> 1.1.1.5 root 19: #include <time.h> 1.1 root 20: 1.1.1.7 root 21: #include "Resource.h" 22: 23: #include "Apidrvr.h" 1.1.1.11! root 24: #include "Combo.h" 1.1.1.7 root 25: #include "Crypto.h" 26: #include "Dictionary.h" 27: #include "Dlgcode.h" 1.1.1.11! root 28: #include "Common/Endian.h" 1.1.1.7 root 29: #include "Language.h" 30: #include "Keyfiles.h" 1.1.1.11! root 31: #include "Mount/Mount.h" 1.1.1.7 root 32: #include "Pkcs5.h" 33: #include "Random.h" 34: #include "Registry.h" 35: #include "Tests.h" 36: #include "Volumes.h" 37: #include "Xml.h" 1.1.1.5 root 38: 1.1.1.11! root 39: #ifdef VOLFORMAT ! 40: #include "Format/Tcformat.h" ! 41: #endif ! 42: ! 43: LONG DriverVersion; ! 44: 1.1.1.10 root 45: char *LastDialogId; 1.1 root 46: char szHelpFile[TC_MAX_PATH]; 1.1.1.7 root 47: char szHelpFile2[TC_MAX_PATH]; 48: HFONT hFixedDigitFont = NULL; 1.1 root 49: HFONT hBoldFont = NULL; 50: HFONT hTitleFont = NULL; 51: HFONT hFixedFont = NULL; 52: 53: HFONT hUserFont = NULL; 54: HFONT hUserUnderlineFont = NULL; 55: HFONT hUserBoldFont = NULL; 1.1.1.5 root 56: HFONT hUserUnderlineBoldFont = NULL; 1.1 root 57: 1.1.1.7 root 58: HWND MainDlg = NULL; 59: wchar_t *lpszTitle = NULL; 60: 61: BOOL Silent = FALSE; 62: BOOL bPreserveTimestamp = TRUE; 63: 1.1.1.10 root 64: BOOL bHistory = FALSE; 65: 1.1 root 66: int nCurrentOS = 0; 67: int CurrentOSMajor = 0; 68: int CurrentOSMinor = 0; 1.1.1.10 root 69: int CurrentOSServicePack = 0; 70: BOOL RemoteSession = FALSE; 1.1.1.11! root 71: BOOL UacElevated = FALSE; 1.1 root 72: 1.1.1.7 root 73: /* Globals used by Mount and Format (separately per instance) */ 74: BOOL KeyFilesEnable = FALSE; 75: KeyFile *FirstKeyFile = NULL; 76: KeyFilesDlgParam defaultKeyFilesParam; 77: 1.1 root 78: /* Handle to the device driver */ 79: HANDLE hDriver = INVALID_HANDLE_VALUE; 1.1.1.11! root 80: 1.1 root 81: HINSTANCE hInst = NULL; 82: HANDLE hMutex = NULL; 83: HCURSOR hCursor = NULL; 84: 85: ATOM hDlgClass, hSplashClass; 86: 1.1.1.7 root 87: static FILE *ConfigFileHandle; 88: static char *ConfigBuffer; 89: 90: #define RANDOM_POOL_DISPLAY_REFRESH_INTERVAL 30 91: 1.1 root 92: /* Windows dialog class */ 93: #define WINDOWS_DIALOG_CLASS "#32770" 94: 95: /* Custom class names */ 96: #define TC_DLG_CLASS "CustomDlg" 97: #define TC_SPLASH_CLASS "SplashDlg" 98: 1.1.1.7 root 99: /* Benchmarks */ 100: 1.1.1.5 root 101: #ifndef SETUP 1.1.1.7 root 102: 1.1.1.5 root 103: #define BENCHMARK_MAX_ITEMS 100 1.1.1.7 root 104: #define BENCHMARK_DEFAULT_BUF_SIZE BYTES_PER_MB 105: #define HASH_FNC_BENCHMARKS FALSE // For development purposes only. Must be FALSE when building a public release. 106: #define PKCS5_BENCHMARKS FALSE // For development purposes only. Must be FALSE when building a public release. 107: #if PKCS5_BENCHMARKS && HASH_FNC_BENCHMARKS 108: #error PKCS5_BENCHMARKS and HASH_FNC_BENCHMARKS are both TRUE (at least one of them should be FALSE). 109: #endif 1.1.1.5 root 110: 111: enum 112: { 113: BENCHMARK_SORT_BY_NAME = 0, 114: BENCHMARK_SORT_BY_SPEED 115: }; 116: 117: typedef struct 118: { 119: int id; 120: char name[100]; 121: unsigned __int64 encSpeed; 122: unsigned __int64 decSpeed; 123: unsigned __int64 meanBytesPerSec; 124: } BENCHMARK_REC; 125: 126: BENCHMARK_REC benchmarkTable [BENCHMARK_MAX_ITEMS]; 127: int benchmarkTotalItems = 0; 128: int benchmarkBufferSize = BENCHMARK_DEFAULT_BUF_SIZE; 129: int benchmarkLastBufferSize = BENCHMARK_DEFAULT_BUF_SIZE; 130: int benchmarkSortMethod = BENCHMARK_SORT_BY_SPEED; 131: LARGE_INTEGER benchmarkPerformanceFrequency; 1.1.1.7 root 132: 1.1.1.5 root 133: #endif // #ifndef SETUP 134: 135: 1.1 root 136: void 137: cleanup () 138: { 139: /* Cleanup the GDI fonts */ 140: if (hFixedFont != NULL) 141: DeleteObject (hFixedFont); 1.1.1.7 root 142: if (hFixedDigitFont != NULL) 143: DeleteObject (hFixedDigitFont); 1.1 root 144: if (hBoldFont != NULL) 145: DeleteObject (hBoldFont); 146: if (hTitleFont != NULL) 147: DeleteObject (hTitleFont); 148: if (hUserFont != NULL) 149: DeleteObject (hUserFont); 150: if (hUserUnderlineFont != NULL) 151: DeleteObject (hUserUnderlineFont); 152: if (hUserBoldFont != NULL) 153: DeleteObject (hUserBoldFont); 1.1.1.5 root 154: if (hUserUnderlineBoldFont != NULL) 155: DeleteObject (hUserUnderlineBoldFont); 1.1 root 156: /* Cleanup our dialog class */ 157: if (hDlgClass) 158: UnregisterClass (TC_DLG_CLASS, hInst); 159: if (hSplashClass) 160: UnregisterClass (TC_SPLASH_CLASS, hInst); 161: /* Close the device driver handle */ 162: if (hDriver != INVALID_HANDLE_VALUE) 163: { 1.1.1.7 root 164: // Unload driver mode if possible (non-install mode) 165: if (IsNonInstallMode ()) 166: DriverUnload (); 167: else 168: CloseHandle (hDriver); 1.1 root 169: } 170: 171: if (hMutex != NULL) 172: { 173: CloseHandle (hMutex); 174: } 1.1.1.7 root 175: 176: if (ConfigBuffer != NULL) 177: { 178: free (ConfigBuffer); 179: ConfigBuffer = NULL; 180: } 1.1.1.10 root 181: 182: CoUninitialize (); 1.1 root 183: } 184: 185: void 186: LowerCaseCopy (char *lpszDest, char *lpszSource) 187: { 188: int i = strlen (lpszSource); 189: 190: lpszDest[i] = 0; 191: while (--i >= 0) 192: { 193: lpszDest[i] = (char) tolower (lpszSource[i]); 194: } 195: 196: } 197: 198: void 199: UpperCaseCopy (char *lpszDest, char *lpszSource) 200: { 201: int i = strlen (lpszSource); 202: 203: lpszDest[i] = 0; 204: while (--i >= 0) 205: { 206: lpszDest[i] = (char) toupper (lpszSource[i]); 207: } 208: } 209: 1.1.1.11! root 210: ! 211: BOOL IsVolumeDeviceHosted (char *lpszDiskFile) ! 212: { ! 213: return strstr (lpszDiskFile, "\\Device\\") == lpszDiskFile ! 214: || strstr (lpszDiskFile, "\\DEVICE\\") == lpszDiskFile; ! 215: } ! 216: ! 217: 1.1 root 218: void 219: CreateFullVolumePath (char *lpszDiskFile, char *lpszFileName, BOOL * bDevice) 220: { 221: if (strcmp (lpszFileName, "Floppy (A:)") == 0) 222: strcpy (lpszFileName, "\\Device\\Floppy0"); 223: else if (strcmp (lpszFileName, "Floppy (B:)") == 0) 224: strcpy (lpszFileName, "\\Device\\Floppy1"); 225: 226: UpperCaseCopy (lpszDiskFile, lpszFileName); 227: 228: *bDevice = FALSE; 229: 230: if (memcmp (lpszDiskFile, "\\DEVICE", sizeof (char) * 7) == 0) 231: { 232: *bDevice = TRUE; 233: } 234: 235: strcpy (lpszDiskFile, lpszFileName); 236: 237: #if _DEBUG 238: OutputDebugString ("CreateFullVolumePath: "); 239: OutputDebugString (lpszDiskFile); 240: OutputDebugString ("\n"); 241: #endif 242: 243: } 244: 245: int 246: FakeDosNameForDevice (char *lpszDiskFile, char *lpszDosDevice, char *lpszCFDevice, BOOL bNameOnly) 247: { 248: BOOL bDosLinkCreated = TRUE; 249: sprintf (lpszDosDevice, "truecrypt%lu", GetCurrentProcessId ()); 250: 251: if (bNameOnly == FALSE) 252: bDosLinkCreated = DefineDosDevice (DDD_RAW_TARGET_PATH, lpszDosDevice, lpszDiskFile); 253: 254: if (bDosLinkCreated == FALSE) 255: return ERR_OS_ERROR; 256: else 257: sprintf (lpszCFDevice, "\\\\.\\%s", lpszDosDevice); 258: 259: return 0; 260: } 261: 262: int 263: RemoveFakeDosName (char *lpszDiskFile, char *lpszDosDevice) 264: { 265: BOOL bDosLinkRemoved = DefineDosDevice (DDD_RAW_TARGET_PATH | DDD_EXACT_MATCH_ON_REMOVE | 266: DDD_REMOVE_DEFINITION, lpszDosDevice, lpszDiskFile); 267: if (bDosLinkRemoved == FALSE) 268: { 269: return ERR_OS_ERROR; 270: } 271: 272: return 0; 273: } 274: 275: 276: void 1.1.1.7 root 277: AbortProcess (char *stringId) 1.1 root 278: { 279: MessageBeep (MB_ICONEXCLAMATION); 1.1.1.7 root 280: MessageBoxW (NULL, GetString (stringId), lpszTitle, ICON_HAND); 1.1 root 281: exit (1); 282: } 283: 1.1.1.5 root 284: void 285: AbortProcessSilent (void) 286: { 287: exit (1); 288: } 289: 1.1 root 290: void * 291: err_malloc (size_t size) 292: { 293: void *z = (void *) TCalloc (size); 294: if (z) 295: return z; 1.1.1.7 root 296: AbortProcess ("OUTOFMEMORY"); 1.1 root 297: return 0; 298: } 299: 300: char * 301: err_strdup (char *lpszText) 302: { 303: int j = (strlen (lpszText) + 1) * sizeof (char); 304: char *z = (char *) err_malloc (j); 305: memmove (z, lpszText, j); 306: return z; 307: } 308: 1.1.1.5 root 309: DWORD 1.1 root 310: handleWin32Error (HWND hwndDlg) 311: { 1.1.1.7 root 312: PWSTR lpMsgBuf; 1.1 root 313: DWORD dwError = GetLastError (); 314: 1.1.1.11! root 315: if (Silent || dwError == 0) ! 316: return dwError; ! 317: ! 318: // Access denied ! 319: if (dwError == ERROR_ACCESS_DENIED && !IsAdmin ()) ! 320: { ! 321: Error ("ERR_ACCESS_DENIED"); ! 322: return dwError; ! 323: } 1.1.1.7 root 324: 325: FormatMessageW ( 1.1 root 326: FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 327: NULL, 328: dwError, 329: MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */ 1.1.1.7 root 330: (PWSTR) &lpMsgBuf, 1.1 root 331: 0, 332: NULL 333: ); 334: 1.1.1.7 root 335: MessageBoxW (hwndDlg, lpMsgBuf, lpszTitle, ICON_HAND); 1.1 root 336: LocalFree (lpMsgBuf); 1.1.1.5 root 337: 1.1.1.7 root 338: // Device not ready 339: if (dwError == ERROR_NOT_READY) 340: CheckSystemAutoMount(); 341: 1.1.1.5 root 342: return dwError; 1.1 root 343: } 344: 345: BOOL 1.1.1.7 root 346: translateWin32Error (wchar_t *lpszMsgBuf, int nSizeOfBuf) 1.1 root 347: { 348: DWORD dwError = GetLastError (); 349: 1.1.1.7 root 350: if (FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError, 1.1 root 351: MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */ 352: lpszMsgBuf, nSizeOfBuf, NULL)) 353: return TRUE; 354: else 355: return FALSE; 356: } 357: 1.1.1.11! root 358: ! 359: int GetTextGfxWidth (HWND hwndDlgItem, wchar_t *text, HFONT hFont) ! 360: { ! 361: SIZE sizes; ! 362: TEXTMETRIC textMetrics; ! 363: HDC hdc = GetDC (hwndDlgItem); ! 364: ! 365: SelectObject(hdc, (HGDIOBJ) hFont); ! 366: ! 367: GetTextExtentPoint32W (hdc, text, wcslen (text), &sizes); ! 368: ! 369: GetTextMetrics(hdc, &textMetrics); // Necessary for non-TrueType raster fonts (tmOverhang) ! 370: ! 371: ReleaseDC (hwndDlgItem, hdc); ! 372: ! 373: return ((int) sizes.cx - (int) textMetrics.tmOverhang); ! 374: } ! 375: ! 376: ! 377: int GetTextGfxHeight (HWND hwndDlgItem, wchar_t *text, HFONT hFont) ! 378: { ! 379: SIZE sizes; ! 380: HDC hdc = GetDC (hwndDlgItem); ! 381: ! 382: SelectObject(hdc, (HGDIOBJ) hFont); ! 383: ! 384: GetTextExtentPoint32W (hdc, text, wcslen (text), &sizes); ! 385: ! 386: ReleaseDC (hwndDlgItem, hdc); ! 387: ! 388: return ((int) sizes.cy); ! 389: } ! 390: ! 391: ! 392: static LRESULT CALLBACK HyperlinkProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) ! 393: { ! 394: WNDPROC wp = (WNDPROC) GetWindowLongPtr (hwnd, GWL_USERDATA); ! 395: static BOOL tracked = FALSE; ! 396: ! 397: switch (message) ! 398: { ! 399: case WM_SETCURSOR: ! 400: if (!tracked) ! 401: { ! 402: TRACKMOUSEEVENT trackMouseEvent; ! 403: ! 404: trackMouseEvent.cbSize = sizeof(trackMouseEvent); ! 405: trackMouseEvent.dwFlags = TME_LEAVE; ! 406: trackMouseEvent.hwndTrack = hwnd; ! 407: ! 408: tracked = TrackMouseEvent(&trackMouseEvent); ! 409: ! 410: HandCursor(); ! 411: } ! 412: return 0; ! 413: ! 414: case WM_MOUSELEAVE: ! 415: tracked = FALSE; ! 416: NormalCursor(); ! 417: return 0; ! 418: } ! 419: ! 420: return CallWindowProc (wp, hwnd, message, wParam, lParam); ! 421: } ! 422: ! 423: ! 424: BOOL ToHyperlink (HWND hwndDlg, UINT ctrlId) ! 425: { ! 426: RECT rec, wrec, trec; ! 427: HWND hwndCtrl = GetDlgItem (hwndDlg, ctrlId); ! 428: int width, origWidth, origHeight; ! 429: int horizSubOffset, vertOffset, alignPosDiff = 0; ! 430: wchar_t text [MAX_URL_LENGTH]; ! 431: WINDOWINFO windowInfo; ! 432: BOOL bBorderlessWindow = !(GetWindowLongPtr (hwndDlg, GWL_STYLE) & (WS_BORDER | WS_DLGFRAME)); ! 433: ! 434: SendMessage (hwndCtrl, WM_SETFONT, (WPARAM) hUserUnderlineFont, 0); ! 435: ! 436: SetWindowLongPtr (hwndCtrl, GWL_USERDATA, (LONG_PTR) GetWindowLongPtr (hwndCtrl, GWL_WNDPROC)); ! 437: SetWindowLongPtr (hwndCtrl, GWL_WNDPROC, (LONG_PTR) HyperlinkProc); ! 438: ! 439: ! 440: // Resize the field according to its length and font size and move if centered or right-aligned ! 441: ! 442: GetWindowTextW (hwndCtrl, text, sizeof (text) / sizeof (wchar_t)); ! 443: ! 444: width = GetTextGfxWidth (hwndCtrl, text, hUserUnderlineFont); ! 445: ! 446: GetClientRect (hwndCtrl, &rec); ! 447: origWidth = rec.right; ! 448: origHeight = rec.bottom; ! 449: ! 450: if (width > 0 ! 451: && origWidth > width) // The original width of the field is the maximum allowed size ! 452: { ! 453: horizSubOffset = origWidth - width; ! 454: ! 455: // Window coords ! 456: GetWindowRect(hwndDlg, &wrec); ! 457: GetClientRect(hwndDlg, &trec); ! 458: ! 459: // Vertical "title bar" offset ! 460: vertOffset = wrec.bottom - wrec.top - trec.bottom - (bBorderlessWindow ? 0 : GetSystemMetrics(SM_CYFIXEDFRAME)); ! 461: ! 462: // Text field coords ! 463: GetWindowRect(hwndCtrl, &rec); ! 464: ! 465: // Alignment offset ! 466: windowInfo.cbSize = sizeof(windowInfo); ! 467: GetWindowInfo (hwndCtrl, &windowInfo); ! 468: ! 469: if (windowInfo.dwStyle & SS_CENTER) ! 470: alignPosDiff = horizSubOffset / 2; ! 471: else if (windowInfo.dwStyle & SS_RIGHT) ! 472: alignPosDiff = horizSubOffset; ! 473: ! 474: // Resize/move ! 475: if (alignPosDiff > 0) ! 476: { ! 477: // Resize and move the text field ! 478: MoveWindow (hwndCtrl, ! 479: rec.left - wrec.left - (bBorderlessWindow ? 0 : GetSystemMetrics(SM_CXFIXEDFRAME)) + alignPosDiff, ! 480: rec.top - wrec.top - vertOffset, ! 481: origWidth - horizSubOffset, ! 482: origHeight, ! 483: TRUE); ! 484: } ! 485: else ! 486: { ! 487: // Resize the text field ! 488: SetWindowPos (hwndCtrl, 0, 0, 0, ! 489: origWidth - horizSubOffset, ! 490: origHeight, ! 491: SWP_NOMOVE | SWP_NOZORDER); ! 492: } ! 493: } ! 494: return TRUE; ! 495: } ! 496: ! 497: 1.1 root 498: /* Except in response to the WM_INITDIALOG message, the dialog box procedure 499: should return nonzero if it processes the message, and zero if it does 500: not. - see DialogProc */ 501: BOOL WINAPI 502: AboutDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) 503: { 504: WORD lw = LOWORD (wParam); 505: if (lParam); /* remove warning */ 506: 507: switch (msg) 508: { 509: 510: case WM_INITDIALOG: 511: { 1.1.1.7 root 512: char szTmp[100]; 1.1.1.11! root 513: LocalizeDialog (hwndDlg, "IDD_ABOUT_DLG"); 1.1 root 514: 1.1.1.8 root 515: SetWindowText (GetDlgItem (hwndDlg, IDC_HOMEPAGE), "www.truecrypt.org"); 1.1.1.11! root 516: ToHyperlink (hwndDlg, IDC_HOMEPAGE); 1.1.1.5 root 517: 518: // Version 519: SendMessage (GetDlgItem (hwndDlg, IDT_ABOUT_VERSION), WM_SETFONT, (WPARAM) hUserBoldFont, 0); 1.1 root 520: sprintf (szTmp, "TrueCrypt %s", VERSION_STRING); 1.1.1.7 root 521: #ifdef _DEBUG 522: strcat (szTmp, " (debug)"); 523: #endif 1.1 root 524: SetDlgItemText (hwndDlg, IDT_ABOUT_VERSION, szTmp); 1.1.1.5 root 525: 526: // Credits 527: SendMessage (GetDlgItem (hwndDlg, IDC_ABOUT_CREDITS), WM_SETFONT, (WPARAM) hUserFont, (LPARAM) 0); 1.1.1.11! root 528: SendMessage (hwndDlg, WM_APP, 0, 0); 1.1 root 529: return 1; 530: } 531: 1.1.1.11! root 532: case WM_APP: ! 533: SetWindowText (GetDlgItem (hwndDlg, IDC_ABOUT_CREDITS), ! 534: "Portions of this software are based in part on the works of the following people:\r\n" ! 535: "Paul Le Roux, " ! 536: "Bruce Schneier, " ! 537: "Horst Feistel, Don Coppersmith, " ! 538: "Walt Tuchmann, " ! 539: "Joan Daemen, Vincent Rijmen, " ! 540: "Lars Knudsen, Ross Anderson, Eli Biham, " ! 541: "David Wagner, John Kelsey, Niels Ferguson, Doug Whiting, Chris Hall, " ! 542: "Carlisle Adams, Stafford Tavares, " ! 543: "Hans Dobbertin, Antoon Bosselaers, Bart Preneel, " ! 544: "Paulo Barreto, Brian Gladman, Wei Dai, Peter Gutmann, and many others.\r\n\r\n" ! 545: "Portions of this software:\r\n" ! 546: "Copyright \xA9 2003-2007 TrueCrypt Foundation. All Rights Reserved.\r\n" ! 547: "Copyright \xA9 1998-2000 Paul Le Roux. All Rights Reserved.\r\n" ! 548: "Copyright \xA9 1999-2006 Dr. Brian Gladman. All Rights Reserved.\r\n" ! 549: "Copyright \xA9 1995-1997 Eric Young. All Rights Reserved.\r\n" ! 550: "Copyright \xA9 2001 Markus Friedl. All Rights Reserved.\r\n\r\n" ! 551: "A TrueCrypt Foundation Release"); ! 552: return 1; ! 553: 1.1 root 554: case WM_COMMAND: 555: if (lw == IDOK || lw == IDCANCEL) 556: { 557: EndDialog (hwndDlg, 0); 558: return 1; 559: } 560: 1.1.1.5 root 561: if (lw == IDC_HOMEPAGE) 562: { 1.1.1.11! root 563: Applink ("main", TRUE, ""); 1.1.1.5 root 564: return 1; 565: } 566: 1.1.1.11! root 567: if (lw == IDC_DONATIONS) ! 568: { ! 569: Applink ("donate", FALSE, ""); ! 570: return 1; ! 571: } ! 572: 1.1.1.5 root 573: // Disallow modification of credits 574: if (HIWORD (wParam) == EN_UPDATE) 575: { 1.1.1.11! root 576: SendMessage (hwndDlg, WM_APP, 0, 0); 1.1.1.5 root 577: return 1; 578: } 579: 1.1 root 580: return 0; 581: 582: case WM_CLOSE: 583: EndDialog (hwndDlg, 0); 584: return 1; 585: } 586: 587: return 0; 588: } 589: 590: 591: BOOL 592: IsButtonChecked (HWND hButton) 593: { 594: if (SendMessage (hButton, BM_GETCHECK, 0, 0) == BST_CHECKED) 595: return TRUE; 596: else 597: return FALSE; 598: } 599: 600: void 601: CheckButton (HWND hButton) 602: { 603: SendMessage (hButton, BM_SETCHECK, BST_CHECKED, 0); 604: } 605: 606: 607: /***************************************************************************** 608: ToSBCS: converts a unicode string to Single Byte Character String (SBCS). 609: ***************************************************************************/ 610: 611: void 612: ToSBCS (LPWSTR lpszText) 613: { 614: int j = wcslen (lpszText); 615: if (j == 0) 616: { 617: strcpy ((char *) lpszText, ""); 618: return; 619: } 620: else 621: { 622: char *lpszNewText = (char *) err_malloc (j + 1); 623: j = WideCharToMultiByte (CP_ACP, 0L, lpszText, -1, lpszNewText, j + 1, NULL, NULL); 624: if (j > 0) 625: strcpy ((char *) lpszText, lpszNewText); 626: else 627: strcpy ((char *) lpszText, ""); 628: free (lpszNewText); 629: } 630: } 631: 632: /***************************************************************************** 633: ToUNICODE: converts a SBCS string to a UNICODE string. 634: ***************************************************************************/ 635: 636: void 637: ToUNICODE (char *lpszText) 638: { 639: int j = strlen (lpszText); 640: if (j == 0) 641: { 642: wcscpy ((LPWSTR) lpszText, (LPWSTR) WIDE ("")); 643: return; 644: } 645: else 646: { 647: LPWSTR lpszNewText = (LPWSTR) err_malloc ((j + 1) * 2); 648: j = MultiByteToWideChar (CP_ACP, 0L, lpszText, -1, lpszNewText, j + 1); 649: if (j > 0) 650: wcscpy ((LPWSTR) lpszText, lpszNewText); 651: else 652: wcscpy ((LPWSTR) lpszText, (LPWSTR) ""); 653: free (lpszNewText); 654: } 655: } 656: 657: /* InitDialog - initialize the applications main dialog, this function should 658: be called only once in the dialogs WM_INITDIALOG message handler */ 659: void 660: InitDialog (HWND hwndDlg) 661: { 1.1.1.7 root 662: NONCLIENTMETRICSW metric; 663: static BOOL aboutMenuAppended = FALSE; 664: 1.1 root 665: HDC hDC; 666: int nHeight; 1.1.1.7 root 667: LOGFONTW lf; 1.1 root 668: HMENU hMenu; 1.1.1.7 root 669: Font *font; 1.1 root 670: 671: hDC = GetDC (hwndDlg); 672: 1.1.1.7 root 673: // Normal 674: font = GetFont ("font_normal"); 675: 676: metric.cbSize = sizeof (metric); 677: SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, sizeof(metric), &metric, 0); 678: 679: metric.lfMessageFont.lfHeight = !font ? -11 : -font->Size; 680: metric.lfMessageFont.lfWidth = 0; 681: 682: if (font && wcscmp (font->FaceName, L"default") != 0) 1.1.1.11! root 683: { ! 684: wcsncpy ((WCHAR *)metric.lfMessageFont.lfFaceName, font->FaceName, sizeof (metric.lfMessageFont.lfFaceName)/2); ! 685: } ! 686: else if (nCurrentOS == WIN_VISTA_OR_LATER) ! 687: { ! 688: // Vista's new default font (size and spacing) breaks compatibility with Windows 2k/XP applications. ! 689: // Force use of Tahoma (as Microsoft does in many dialogs) until a native Vista look is implemented. ! 690: wcsncpy ((WCHAR *)metric.lfMessageFont.lfFaceName, L"Tahoma", sizeof (metric.lfMessageFont.lfFaceName)/2); ! 691: } 1.1.1.7 root 692: 693: hUserFont = CreateFontIndirectW (&metric.lfMessageFont); 694: 695: metric.lfMessageFont.lfUnderline = TRUE; 696: hUserUnderlineFont = CreateFontIndirectW (&metric.lfMessageFont); 697: 698: metric.lfMessageFont.lfUnderline = FALSE; 699: metric.lfMessageFont.lfWeight = FW_BOLD; 700: hUserBoldFont = CreateFontIndirectW (&metric.lfMessageFont); 701: 702: metric.lfMessageFont.lfUnderline = TRUE; 703: metric.lfMessageFont.lfWeight = FW_BOLD; 704: hUserUnderlineBoldFont = CreateFontIndirectW (&metric.lfMessageFont); 705: 1.1.1.11! root 706: // Fixed (digits) 1.1.1.7 root 707: nHeight = -((9 * GetDeviceCaps (hDC, LOGPIXELSY)) / 72); 1.1 root 708: lf.lfHeight = nHeight; 709: lf.lfWidth = 0; 710: lf.lfEscapement = 0; 711: lf.lfOrientation = 0; 1.1.1.7 root 712: lf.lfWeight = FW_NORMAL; 1.1 root 713: lf.lfItalic = FALSE; 714: lf.lfUnderline = FALSE; 715: lf.lfStrikeOut = FALSE; 716: lf.lfCharSet = DEFAULT_CHARSET; 717: lf.lfOutPrecision = OUT_DEFAULT_PRECIS; 718: lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; 719: lf.lfQuality = PROOF_QUALITY; 720: lf.lfPitchAndFamily = FF_DONTCARE; 1.1.1.7 root 721: wcscpy (lf.lfFaceName, L"Courier New"); 722: hFixedDigitFont = CreateFontIndirectW (&lf); 723: if (hFixedDigitFont == NULL) 1.1 root 724: { 725: handleWin32Error (hwndDlg); 1.1.1.7 root 726: AbortProcess ("NOFONT"); 1.1 root 727: } 728: 1.1.1.7 root 729: // Bold 730: font = GetFont ("font_bold"); 1.1 root 731: 1.1.1.7 root 732: nHeight = -(((!font ? 10 : font->Size) * GetDeviceCaps (hDC, LOGPIXELSY)) / 72); 1.1 root 733: lf.lfHeight = nHeight; 1.1.1.7 root 734: lf.lfWeight = FW_BLACK; 735: wcsncpy (lf.lfFaceName, !font ? L"Arial" : font->FaceName, sizeof (lf.lfFaceName)/2); 736: hBoldFont = CreateFontIndirectW (&lf); 1.1 root 737: if (hBoldFont == NULL) 738: { 739: handleWin32Error (hwndDlg); 1.1.1.7 root 740: AbortProcess ("NOFONT"); 1.1 root 741: } 742: 1.1.1.7 root 743: // Title 744: font = GetFont ("font_title"); 745: 746: nHeight = -(((!font ? 16 : font->Size) * GetDeviceCaps (hDC, LOGPIXELSY)) / 72); 1.1 root 747: lf.lfHeight = nHeight; 748: lf.lfWeight = FW_REGULAR; 1.1.1.7 root 749: wcsncpy (lf.lfFaceName, !font ? L"Times New Roman" : font->FaceName, sizeof (lf.lfFaceName)/2); 750: hTitleFont = CreateFontIndirectW (&lf); 1.1 root 751: if (hTitleFont == NULL) 752: { 753: handleWin32Error (hwndDlg); 1.1.1.7 root 754: AbortProcess ("NOFONT"); 1.1 root 755: } 756: 1.1.1.7 root 757: // Fixed 758: font = GetFont ("font_fixed"); 759: 760: nHeight = -(((!font ? 9 : font->Size) * GetDeviceCaps (hDC, LOGPIXELSY)) / 72); 1.1 root 761: lf.lfHeight = nHeight; 762: lf.lfWidth = 0; 763: lf.lfEscapement = 0; 764: lf.lfOrientation = 0; 765: lf.lfWeight = FW_NORMAL; 766: lf.lfItalic = FALSE; 767: lf.lfUnderline = FALSE; 768: lf.lfStrikeOut = FALSE; 769: lf.lfCharSet = DEFAULT_CHARSET; 770: lf.lfOutPrecision = OUT_DEFAULT_PRECIS; 771: lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; 772: lf.lfQuality = PROOF_QUALITY; 773: lf.lfPitchAndFamily = FF_DONTCARE; 1.1.1.7 root 774: wcsncpy (lf.lfFaceName, !font ? L"Lucida Console" : font->FaceName, sizeof (lf.lfFaceName)/2); 775: hFixedFont = CreateFontIndirectW (&lf); 1.1 root 776: if (hFixedFont == NULL) 777: { 778: handleWin32Error (hwndDlg); 1.1.1.7 root 779: AbortProcess ("NOFONT"); 1.1 root 780: } 781: 1.1.1.7 root 782: if (!aboutMenuAppended) 783: { 784: hMenu = GetSystemMenu (hwndDlg, FALSE); 785: AppendMenu (hMenu, MF_SEPARATOR, 0, NULL); 786: AppendMenuW (hMenu, MF_ENABLED | MF_STRING, IDC_ABOUT, GetString ("ABOUTBOX")); 1.1.1.5 root 787: 1.1.1.7 root 788: aboutMenuAppended = TRUE; 789: } 1.1 root 790: } 791: 792: HDC 793: CreateMemBitmap (HINSTANCE hInstance, HWND hwnd, char *resource) 794: { 795: HBITMAP picture = LoadBitmap (hInstance, resource); 796: HDC viewDC = GetDC (hwnd), dcMem; 797: 798: dcMem = CreateCompatibleDC (viewDC); 799: 800: SetMapMode (dcMem, MM_TEXT); 801: 802: SelectObject (dcMem, picture); 803: 804: ReleaseDC (hwnd, viewDC); 805: 806: return dcMem; 807: } 808: 809: /* Draw the specified bitmap at the specified location - Stretch to fit. */ 810: void 811: PaintBitmap (HDC pdcMem, int x, int y, int nWidth, int nHeight, HDC hDC) 812: { 813: HGDIOBJ picture = GetCurrentObject (pdcMem, OBJ_BITMAP); 814: 815: BITMAP bitmap; 816: GetObject (picture, sizeof (BITMAP), &bitmap); 817: 818: BitBlt (hDC, x, y, nWidth, nHeight, pdcMem, 0, 0, SRCCOPY); 819: } 820: 1.1.1.7 root 821: 1.1 root 822: LRESULT CALLBACK 1.1.1.7 root 823: RedTick (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 1.1 root 824: { 1.1.1.7 root 825: if (uMsg == WM_CREATE) 826: { 827: } 828: else if (uMsg == WM_DESTROY) 829: { 830: } 831: else if (uMsg == WM_TIMER) 832: { 833: } 834: else if (uMsg == WM_PAINT) 835: { 836: PAINTSTRUCT tmp; 837: HPEN hPen; 838: HDC hDC; 839: BOOL bEndPaint; 840: RECT Rect; 841: 842: if (GetUpdateRect (hwnd, NULL, FALSE)) 843: { 844: hDC = BeginPaint (hwnd, &tmp); 845: bEndPaint = TRUE; 846: if (hDC == NULL) 847: return DefWindowProc (hwnd, uMsg, wParam, lParam); 848: } 849: else 850: { 851: hDC = GetDC (hwnd); 852: bEndPaint = FALSE; 853: } 854: 855: GetClientRect (hwnd, &Rect); 856: 857: hPen = CreatePen (PS_SOLID, 2, RGB (0, 255, 0)); 858: if (hPen != NULL) 859: { 860: HGDIOBJ hObj = SelectObject (hDC, hPen); 861: WORD bx = LOWORD (GetDialogBaseUnits ()); 862: WORD by = HIWORD (GetDialogBaseUnits ()); 1.1 root 863: 1.1.1.7 root 864: MoveToEx (hDC, (Rect.right - Rect.left) / 2, Rect.bottom, NULL); 865: LineTo (hDC, Rect.right, Rect.top); 866: MoveToEx (hDC, (Rect.right - Rect.left) / 2, Rect.bottom, NULL); 1.1 root 867: 1.1.1.7 root 868: LineTo (hDC, (3 * bx) / 4, (2 * by) / 8); 1.1 root 869: 1.1.1.7 root 870: SelectObject (hDC, hObj); 871: DeleteObject (hPen); 872: } 873: 874: if (bEndPaint) 875: EndPaint (hwnd, &tmp); 876: else 877: ReleaseDC (hwnd, hDC); 1.1 root 878: 1.1.1.7 root 879: return TRUE; 880: } 881: 882: return DefWindowProc (hwnd, uMsg, wParam, lParam); 883: } 1.1 root 884: 1.1.1.7 root 885: BOOL 886: RegisterRedTick (HINSTANCE hInstance) 887: { 888: WNDCLASS wc; 889: ULONG rc; 1.1 root 890: 1.1.1.7 root 891: memset(&wc, 0 , sizeof wc); 1.1 root 892: 1.1.1.7 root 893: wc.style = CS_HREDRAW | CS_VREDRAW; 894: wc.cbClsExtra = 0; 895: wc.cbWndExtra = 4; 896: wc.hInstance = hInstance; 897: wc.hIcon = LoadIcon (NULL, IDI_APPLICATION); 898: wc.hCursor = NULL; 899: wc.hbrBackground = GetStockObject (LTGRAY_BRUSH); 900: wc.lpszClassName = "REDTICK"; 901: wc.lpfnWndProc = &RedTick; 902: 903: rc = (ULONG) RegisterClass (&wc); 1.1 root 904: 1.1.1.7 root 905: return rc == 0 ? FALSE : TRUE; 906: } 1.1 root 907: 1.1.1.7 root 908: BOOL 909: UnregisterRedTick (HINSTANCE hInstance) 910: { 911: return UnregisterClass ("REDTICK", hInstance); 912: } 1.1 root 913: 1.1.1.7 root 914: LRESULT CALLBACK 915: SplashDlgProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 916: { 1.1 root 917: return DefDlgProc (hwnd, uMsg, wParam, lParam); 918: } 919: 920: void 921: WaitCursor () 922: { 923: static HCURSOR hcWait; 924: if (hcWait == NULL) 925: hcWait = LoadCursor (NULL, IDC_WAIT); 926: SetCursor (hcWait); 927: hCursor = hcWait; 928: } 929: 930: void 931: NormalCursor () 932: { 933: static HCURSOR hcArrow; 934: if (hcArrow == NULL) 935: hcArrow = LoadCursor (NULL, IDC_ARROW); 936: SetCursor (hcArrow); 937: hCursor = NULL; 938: } 939: 940: void 941: ArrowWaitCursor () 942: { 943: static HCURSOR hcArrowWait; 944: if (hcArrowWait == NULL) 945: hcArrowWait = LoadCursor (NULL, IDC_APPSTARTING); 946: SetCursor (hcArrowWait); 947: hCursor = hcArrowWait; 948: } 1.1.1.11! root 949: ! 950: void HandCursor () ! 951: { ! 952: static HCURSOR hcHand; ! 953: if (hcHand == NULL) ! 954: hcHand = LoadCursor (NULL, IDC_HAND); ! 955: SetCursor (hcHand); ! 956: hCursor = hcHand; ! 957: } ! 958: 1.1.1.7 root 959: void 960: AddComboPair (HWND hComboBox, char *lpszItem, int value) 961: { 962: LPARAM nIndex; 963: 964: nIndex = SendMessage (hComboBox, CB_ADDSTRING, 0, (LPARAM) lpszItem); 965: nIndex = SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) value); 966: } 967: 968: void 969: AddComboPairW (HWND hComboBox, wchar_t *lpszItem, int value) 970: { 971: LPARAM nIndex; 972: 973: nIndex = SendMessageW (hComboBox, CB_ADDSTRING, 0, (LPARAM) lpszItem); 974: nIndex = SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) value); 975: } 976: 977: void 978: SelectAlgo (HWND hComboBox, int *algo_id) 979: { 980: LPARAM nCount = SendMessage (hComboBox, CB_GETCOUNT, 0, 0); 981: LPARAM x, i; 982: 983: for (i = 0; i < nCount; i++) 984: { 985: x = SendMessage (hComboBox, CB_GETITEMDATA, i, 0); 986: if (x == (LPARAM) * algo_id) 987: { 988: SendMessage (hComboBox, CB_SETCURSEL, i, 0); 989: return; 990: } 991: } 992: 993: /* Something went wrong ; couldn't find the requested algo id so we drop 994: back to a default */ 995: 996: *algo_id = SendMessage (hComboBox, CB_GETITEMDATA, 0, 0); 997: 998: SendMessage (hComboBox, CB_SETCURSEL, 0, 0); 999: 1000: } 1.1 root 1001: 1002: LRESULT CALLBACK 1003: CustomDlgProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 1004: { 1005: if (uMsg == WM_SETCURSOR && hCursor != NULL) 1006: { 1007: SetCursor (hCursor); 1008: return TRUE; 1009: } 1010: 1011: return DefDlgProc (hwnd, uMsg, wParam, lParam); 1012: } 1013: 1.1.1.7 root 1014: 1.1.1.11! root 1015: void ExceptionHandlerThread (void *ept) 1.1.1.9 root 1016: { 1.1.1.10 root 1017: #define MAX_RET_ADDR_COUNT 64 1.1.1.11! root 1018: EXCEPTION_POINTERS *ep = (EXCEPTION_POINTERS *) ept; 1.1.1.10 root 1019: DWORD addr, retAddr[MAX_RET_ADDR_COUNT]; 1020: DWORD exCode = ep->ExceptionRecord->ExceptionCode; 1.1.1.11! root 1021: SYSTEM_INFO si; ! 1022: wchar_t msg[8192]; ! 1023: char url[MAX_URL_LENGTH]; ! 1024: int i; 1.1.1.9 root 1025: 1.1.1.10 root 1026: addr = (DWORD) ep->ExceptionRecord->ExceptionAddress; 1027: ZeroMemory (retAddr, sizeof (retAddr)); 1028: 1029: if (exCode == 0xc0000006) 1030: { 1031: // Exception not caused by TrueCrypt 1032: MessageBoxW (MainDlg, GetString ("EXCEPTION_REPORT_EXT"), 1033: GetString ("EXCEPTION_REPORT_TITLE"), 1034: MB_ICONERROR | MB_OK | MB_SETFOREGROUND | MB_TOPMOST); 1035: 1.1.1.11! root 1036: return; 1.1.1.10 root 1037: } 1038: else 1039: { 1040: // Call stack 1041: PDWORD sp = (PDWORD) ep->ContextRecord->Esp, stackTop; 1042: int i = 0, e = 0; 1043: MEMORY_BASIC_INFORMATION mi; 1044: 1045: VirtualQuery (sp, &mi, sizeof (mi)); 1046: stackTop = (PDWORD)((char *)mi.BaseAddress + mi.RegionSize); 1047: 1048: while (&sp[i] < stackTop && e < MAX_RET_ADDR_COUNT) 1049: { 1050: if (sp[i] > 0x400000 && sp[i] < 0x500000) 1051: { 1052: int ee = 0; 1053: 1054: // Skip duplicates 1055: while (ee < MAX_RET_ADDR_COUNT && retAddr[ee] != sp[i]) 1056: ee++; 1057: if (ee != MAX_RET_ADDR_COUNT) 1058: { 1059: i++; 1060: continue; 1061: } 1062: 1063: retAddr[e++] = sp[i]; 1064: } 1065: i++; 1066: } 1067: } 1068: 1.1.1.11! root 1069: GetSystemInfo (&si); ! 1070: ! 1071: sprintf (url, TC_APPLINK_SECURE "&dest=err-report&osver=%d.%d.%d-%s&cpus=%d&app=%s&dlg=%s&err=%x&addr=%x" 1.1.1.10 root 1072: , CurrentOSMajor 1073: , CurrentOSMinor 1074: , CurrentOSServicePack 1075: , Is64BitOs () ? "64" : "32" 1.1.1.11! root 1076: , si.dwNumberOfProcessors 1.1.1.9 root 1077: #ifdef TCMOUNT 1078: ,"main" 1079: #endif 1080: #ifdef VOLFORMAT 1081: ,"format" 1082: #endif 1083: #ifdef SETUP 1084: ,"setup" 1085: #endif 1.1.1.10 root 1086: , LastDialogId ? LastDialogId : "-" 1087: , exCode 1088: , addr); 1089: 1090: for (i = 0; i < MAX_RET_ADDR_COUNT && retAddr[i]; i++) 1.1.1.11! root 1091: sprintf (url + strlen(url), "&st%d=%x", i, retAddr[i]); ! 1092: ! 1093: swprintf (msg, GetString ("EXCEPTION_REPORT"), url); 1.1.1.9 root 1094: 1.1.1.11! root 1095: if (IDYES == MessageBoxW (0, msg, GetString ("EXCEPTION_REPORT_TITLE"), MB_ICONERROR | MB_YESNO | MB_DEFBUTTON1 | MB_SETFOREGROUND | MB_TOPMOST)) 1.1.1.9 root 1096: ShellExecute (NULL, "open", (LPCTSTR) url, NULL, NULL, SW_SHOWNORMAL); 1097: else 1098: UnhandledExceptionFilter (ep); 1.1.1.11! root 1099: } ! 1100: ! 1101: ! 1102: LONG __stdcall ExceptionHandler (EXCEPTION_POINTERS *ep) ! 1103: { ! 1104: SetUnhandledExceptionFilter (NULL); ! 1105: WaitForSingleObject ((HANDLE) _beginthread (ExceptionHandlerThread, 0, (void *)ep), INFINITE); 1.1.1.9 root 1106: 1107: return EXCEPTION_EXECUTE_HANDLER; 1108: } 1109: 1110: 1.1.1.11! root 1111: static LRESULT CALLBACK NonInstallUacWndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) ! 1112: { ! 1113: return DefWindowProc (hWnd, message, wParam, lParam); ! 1114: } ! 1115: ! 1116: 1.1 root 1117: /* InitApp - initialize the application, this function is called once in the 1118: applications WinMain function, but before the main dialog has been created */ 1119: void 1.1.1.11! root 1120: InitApp (HINSTANCE hInstance, char *lpszCommandLine) 1.1 root 1121: { 1122: WNDCLASS wc; 1123: OSVERSIONINFO os; 1.1.1.7 root 1124: char langId[6]; 1.1 root 1125: 1126: /* Save the instance handle for later */ 1127: hInst = hInstance; 1128: 1129: /* Pull down the windows version */ 1130: os.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); 1.1.1.7 root 1131: 1.1 root 1132: if (GetVersionEx (&os) == FALSE) 1.1.1.7 root 1133: AbortProcess ("NO_OS_VER"); 1134: 1135: CurrentOSMajor = os.dwMajorVersion; 1136: CurrentOSMinor = os.dwMinorVersion; 1137: 1138: if (os.dwPlatformId == VER_PLATFORM_WIN32_NT && CurrentOSMajor == 5 && CurrentOSMinor == 0) 1139: nCurrentOS = WIN_2000; 1140: else if (os.dwPlatformId == VER_PLATFORM_WIN32_NT && CurrentOSMajor == 5 && CurrentOSMinor == 1) 1141: nCurrentOS = WIN_XP; 1142: else if (os.dwPlatformId == VER_PLATFORM_WIN32_NT && CurrentOSMajor == 5 && CurrentOSMinor == 2) 1.1.1.11! root 1143: { ! 1144: OSVERSIONINFOEX osEx; ! 1145: ! 1146: osEx.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX); ! 1147: GetVersionEx ((LPOSVERSIONINFOA) &osEx); ! 1148: ! 1149: if (osEx.wProductType == VER_NT_SERVER || osEx.wProductType == VER_NT_DOMAIN_CONTROLLER) ! 1150: nCurrentOS = WIN_SERVER_2003; ! 1151: else ! 1152: nCurrentOS = WIN_XP64; ! 1153: } ! 1154: else if (os.dwPlatformId == VER_PLATFORM_WIN32_NT && CurrentOSMajor >= 6) ! 1155: nCurrentOS = WIN_VISTA_OR_LATER; 1.1.1.7 root 1156: else if (os.dwPlatformId == VER_PLATFORM_WIN32_NT && CurrentOSMajor == 4) 1157: nCurrentOS = WIN_NT4; 1.1 root 1158: else if (os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && os.dwMajorVersion == 4 && os.dwMinorVersion == 0) 1159: nCurrentOS = WIN_95; 1160: else if (os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && os.dwMajorVersion == 4 && os.dwMinorVersion == 10) 1161: nCurrentOS = WIN_98; 1.1.1.7 root 1162: else if (os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && os.dwMajorVersion == 4 && os.dwMinorVersion == 90) 1163: nCurrentOS = WIN_ME; 1164: else if (os.dwPlatformId == VER_PLATFORM_WIN32s) 1165: nCurrentOS = WIN_31; 1166: else 1167: nCurrentOS = WIN_UNKNOWN; 1.1 root 1168: 1.1.1.11! root 1169: CoInitialize (NULL); ! 1170: ! 1171: langId[0] = 0; ! 1172: SetPreferredLangId (ConfigReadString ("Language", "", langId, sizeof (langId))); ! 1173: ! 1174: if (langId[0] == 0) ! 1175: DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_LANGUAGE), NULL, ! 1176: (DLGPROC) LanguageDlgProc, (LPARAM) 1); ! 1177: ! 1178: LoadLanguageFile (); ! 1179: ! 1180: #ifndef SETUP ! 1181: // UAC elevation moniker cannot be used in traveller mode. ! 1182: // A new instance of the application must be created with elevated privileges. ! 1183: if (IsNonInstallMode () && !IsAdmin () && IsUacSupported ()) ! 1184: { ! 1185: char modPath[MAX_PATH], newCmdLine[4096]; ! 1186: WNDCLASSEX wcex; ! 1187: HWND hWnd; ! 1188: ! 1189: if (strstr (lpszCommandLine, "/q UAC ") == lpszCommandLine) ! 1190: { ! 1191: Error ("UAC_INIT_ERROR"); ! 1192: exit (1); ! 1193: } ! 1194: ! 1195: memset (&wcex, 0, sizeof (wcex)); ! 1196: wcex.cbSize = sizeof(WNDCLASSEX); ! 1197: wcex.lpfnWndProc = (WNDPROC) NonInstallUacWndProc; ! 1198: wcex.hInstance = hInstance; ! 1199: wcex.lpszClassName = "TrueCrypt"; ! 1200: RegisterClassEx (&wcex); ! 1201: ! 1202: // A small transparent window is necessary to bring the new instance to foreground ! 1203: hWnd = CreateWindowEx (WS_EX_TOOLWINDOW | WS_EX_LAYERED, ! 1204: "TrueCrypt", "TrueCrypt", 0, ! 1205: GetSystemMetrics (SM_CXSCREEN)/2, ! 1206: GetSystemMetrics (SM_CYSCREEN)/2, ! 1207: 1, 1, NULL, NULL, hInstance, NULL); ! 1208: ! 1209: SetLayeredWindowAttributes (hWnd, 0, 0, LWA_ALPHA); ! 1210: ShowWindow (hWnd, SW_SHOWNORMAL); ! 1211: ! 1212: GetModuleFileName (NULL, modPath, sizeof (modPath)); ! 1213: ! 1214: strcpy (newCmdLine, "/q UAC "); ! 1215: strcat_s (newCmdLine, sizeof (newCmdLine), lpszCommandLine); ! 1216: ! 1217: if ((int)ShellExecute (hWnd, "runas", modPath, newCmdLine, NULL, SW_SHOWNORMAL) <= 32) ! 1218: exit (1); ! 1219: ! 1220: Sleep (2000); ! 1221: exit (0); ! 1222: } ! 1223: #endif ! 1224: ! 1225: SetUnhandledExceptionFilter (ExceptionHandler); ! 1226: 1.1.1.10 root 1227: RemoteSession = GetSystemMetrics (SM_REMOTESESSION) != 0; 1228: 1.1.1.6 root 1229: // OS version check 1230: if (CurrentOSMajor < 5) 1231: { 1.1.1.7 root 1232: MessageBoxW (NULL, GetString ("UNSUPPORTED_OS"), lpszTitle, MB_ICONSTOP); 1.1.1.6 root 1233: exit (1); 1234: } 1.1.1.7 root 1235: else 1236: { 1237: OSVERSIONINFOEX osEx; 1238: 1239: // Service pack check 1240: osEx.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX); 1241: if (GetVersionEx ((LPOSVERSIONINFOA) &osEx) != 0) 1242: { 1.1.1.10 root 1243: CurrentOSServicePack = osEx.wServicePackMajor; 1.1.1.7 root 1244: switch (nCurrentOS) 1245: { 1246: case WIN_2000: 1247: if (osEx.wServicePackMajor < 3) 1248: Warning ("LARGE_IDE_WARNING_2K"); 1249: break; 1250: case WIN_XP: 1251: if (osEx.wServicePackMajor < 1) 1.1.1.11! root 1252: { ! 1253: HKEY k; ! 1254: // PE environment does not report version of SP ! 1255: if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "System\\CurrentControlSet\\Control\\minint", 0, KEY_READ, &k) != ERROR_SUCCESS) ! 1256: Warning ("LARGE_IDE_WARNING_XP"); ! 1257: else ! 1258: RegCloseKey (k); ! 1259: } 1.1.1.7 root 1260: break; 1261: } 1262: } 1.1.1.11! root 1263: ! 1264: #ifndef SETUP ! 1265: if (CurrentOSMajor == 6 && CurrentOSMinor == 0 && osEx.dwBuildNumber < 6000) ! 1266: { ! 1267: Error ("UNSUPPORTED_BETA_OS"); ! 1268: exit (0); ! 1269: } ! 1270: #endif 1.1.1.7 root 1271: } 1.1 root 1272: 1273: /* Get the attributes for the standard dialog class */ 1274: if ((GetClassInfo (hInst, WINDOWS_DIALOG_CLASS, &wc)) == 0) 1.1.1.7 root 1275: AbortProcess ("INIT_REGISTER"); 1.1 root 1276: 1277: #ifndef SETUP 1278: wc.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (IDI_TRUECRYPT_ICON)); 1279: #else 1280: #include "../setup/resource.h" 1281: wc.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (IDI_SETUP)); 1282: #endif 1283: wc.lpszClassName = TC_DLG_CLASS; 1284: wc.lpfnWndProc = &CustomDlgProc; 1285: wc.hCursor = LoadCursor (NULL, IDC_ARROW); 1286: wc.cbWndExtra = DLGWINDOWEXTRA; 1287: 1288: hDlgClass = RegisterClass (&wc); 1289: if (hDlgClass == 0) 1.1.1.7 root 1290: AbortProcess ("INIT_REGISTER"); 1.1 root 1291: 1292: wc.lpszClassName = TC_SPLASH_CLASS; 1293: wc.lpfnWndProc = &SplashDlgProc; 1294: wc.hCursor = LoadCursor (NULL, IDC_ARROW); 1295: wc.cbWndExtra = DLGWINDOWEXTRA; 1296: 1297: hSplashClass = RegisterClass (&wc); 1298: if (hSplashClass == 0) 1.1.1.7 root 1299: AbortProcess ("INIT_REGISTER"); 1300: 1301: InitHelpFileName (); 1302: } 1303: 1304: void InitHelpFileName (void) 1305: { 1306: char *lpszTmp; 1.1 root 1307: 1308: GetModuleFileName (NULL, szHelpFile, sizeof (szHelpFile)); 1309: lpszTmp = strrchr (szHelpFile, '\\'); 1310: if (lpszTmp) 1311: { 1.1.1.7 root 1312: char szTemp[TC_MAX_PATH]; 1.1 root 1313: 1.1.1.7 root 1314: // Primary file name 1315: if (strcmp (GetPreferredLangId(), "en") == 0 1316: || GetPreferredLangId() == NULL) 1.1 root 1317: { 1.1.1.7 root 1318: strcpy (++lpszTmp, "TrueCrypt User Guide.pdf"); 1.1 root 1319: } 1320: else 1.1.1.7 root 1321: { 1322: sprintf (szTemp, "TrueCrypt User Guide.%s.pdf", GetPreferredLangId()); 1323: strcpy (++lpszTmp, szTemp); 1324: } 1325: 1326: // Secondary file name (used when localized documentation is not found). 1327: GetModuleFileName (NULL, szHelpFile2, sizeof (szHelpFile2)); 1328: lpszTmp = strrchr (szHelpFile2, '\\'); 1329: if (lpszTmp) 1330: { 1331: strcpy (++lpszTmp, "TrueCrypt User Guide.pdf"); 1332: } 1.1 root 1333: } 1334: } 1335: 1336: BOOL 1337: OpenDevice (char *lpszPath, OPEN_TEST_STRUCT * driver) 1338: { 1339: DWORD dwResult; 1340: BOOL bResult; 1341: 1342: strcpy ((char *) &driver->wszFileName[0], lpszPath); 1.1.1.7 root 1343: ToUNICODE ((char *) &driver->wszFileName[0]); 1.1 root 1344: 1345: bResult = DeviceIoControl (hDriver, OPEN_TEST, 1346: driver, sizeof (OPEN_TEST_STRUCT), 1.1.1.7 root 1347: NULL, 0, 1.1 root 1348: &dwResult, NULL); 1349: 1350: if (bResult == FALSE) 1351: { 1352: dwResult = GetLastError (); 1.1.1.7 root 1353: 1.1 root 1354: if (dwResult == ERROR_SHARING_VIOLATION) 1355: return TRUE; 1356: else 1357: return FALSE; 1358: } 1.1.1.7 root 1359: 1360: return TRUE; 1.1 root 1361: } 1362: 1363: 1.1.1.11! root 1364: BOOL GetDriveLabel (int driveNo, wchar_t *label, int labelSize) ! 1365: { ! 1366: DWORD fileSystemFlags; ! 1367: wchar_t root[] = { L'A' + driveNo, L':', L'\\', 0 }; ! 1368: ! 1369: return GetVolumeInformationW (root, label, labelSize / 2, NULL, NULL, &fileSystemFlags, NULL, 0); ! 1370: } ! 1371: ! 1372: 1.1 root 1373: int 1374: GetAvailableFixedDisks (HWND hComboBox, char *lpszRootPath) 1375: { 1376: int i, n; 1377: int line = 0; 1.1.1.5 root 1378: LVITEM LvItem; 1.1.1.6 root 1379: __int64 deviceSize = 0; 1.1 root 1380: 1381: for (i = 0; i < 64; i++) 1382: { 1383: BOOL drivePresent = FALSE; 1.1.1.6 root 1384: BOOL removable = FALSE; 1.1 root 1385: 1.1.1.11! root 1386: LvItem.lParam = 0; ! 1387: 1.1.1.5 root 1388: for (n = 0; n <= 32; n++) 1.1 root 1389: { 1.1.1.7 root 1390: char szTmp[TC_MAX_PATH]; 1391: wchar_t size[100] = {0}, partTypeStr[1024] = {0}, *partType = partTypeStr; 1.1 root 1392: OPEN_TEST_STRUCT driver; 1393: 1394: sprintf (szTmp, lpszRootPath, i, n); 1.1.1.7 root 1395: if (OpenDevice (szTmp, &driver)) 1.1 root 1396: { 1397: BOOL bResult; 1398: PARTITION_INFORMATION diskInfo; 1.1.1.6 root 1399: DISK_GEOMETRY driveInfo; 1.1 root 1400: 1401: drivePresent = TRUE; 1.1.1.11! root 1402: bResult = GetPartitionInfo (szTmp, &diskInfo); 1.1 root 1403: 1.1.1.7 root 1404: // Test if device is removable 1.1.1.11! root 1405: if (n == 0 && GetDriveGeometry (szTmp, &driveInfo)) 1.1.1.7 root 1406: removable = driveInfo.MediaType == RemovableMedia; 1.1 root 1407: 1.1.1.7 root 1408: if (bResult) 1409: { 1.1.1.6 root 1410: 1.1.1.7 root 1411: // System creates a virtual partition1 for some storage devices without 1412: // partition table. We try to detect this case by comparing sizes of 1413: // partition0 and partition1. If they match, no partition of the device 1414: // is displayed to the user to avoid confusion. Drive letter assigned by 1415: // system to partition1 is displayed as subitem of partition0 1.1.1.6 root 1416: 1.1.1.7 root 1417: if (n == 1 && diskInfo.PartitionLength.QuadPart == deviceSize) 1418: { 1419: char drive[] = { 0, ':', 0 }; 1420: char device[MAX_PATH * 2]; 1421: int driveNo; 1422: 1423: // Drive letter 1424: strcpy (device, szTmp); 1425: ToUNICODE (device); 1426: driveNo = GetDiskDeviceDriveLetter ((PWSTR) device); 1427: drive[0] = driveNo == -1 ? 0 : 'A' + driveNo; 1.1.1.11! root 1428: 1.1.1.7 root 1429: LvItem.iSubItem = 1; 1430: LvItem.pszText = drive; 1431: SendMessage (hComboBox,LVM_SETITEM,0,(LPARAM)&LvItem); 1.1 root 1432: 1.1.1.11! root 1433: // Label ! 1434: if (driveNo != -1) ! 1435: { ! 1436: wchar_t name[64]; ! 1437: ! 1438: if (GetDriveLabel (driveNo, name, sizeof (name))) ! 1439: ListSubItemSetW (hComboBox, LvItem.iItem, 3, name); ! 1440: } ! 1441: ! 1442: // Mark the device as containing a virtual partition ! 1443: LvItem.iSubItem = 0; ! 1444: LvItem.mask = LVIF_PARAM; ! 1445: LvItem.lParam |= SELDEVFLAG_VIRTUAL_PARTITION; ! 1446: SendMessage (hComboBox, LVM_SETITEM, 0, (LPARAM) &LvItem); ! 1447: 1.1.1.7 root 1448: break; 1449: } 1.1 root 1450: 1.1.1.7 root 1451: switch(diskInfo.PartitionType) 1452: { 1.1.1.11! root 1453: case PARTITION_ENTRY_UNUSED: partType = L""; break; 1.1.1.7 root 1454: case PARTITION_XINT13_EXTENDED: 1455: case PARTITION_EXTENDED: partType = L"Extended"; break; 1.1.1.11! root 1456: case PARTITION_HUGE: partType = L"FAT (06)"; break; 1.1.1.7 root 1457: case PARTITION_FAT_12: partType = L"FAT12"; break; 1458: case PARTITION_FAT_16: partType = L"FAT16"; break; 1459: case PARTITION_FAT32: 1460: case PARTITION_FAT32_XINT13: partType = L"FAT32"; break; 1461: case 0x08: partType = L"DELL (spanning)"; break; 1462: case 0x12: partType = L"Config/diagnostics"; break; 1463: case 0x11: 1464: case 0x14: 1465: case 0x16: 1466: case 0x1b: 1467: case 0x1c: 1468: case 0x1e: partType = L"Hidden FAT"; break; 1469: case PARTITION_IFS: partType = L"NTFS"; break; 1470: case 0x17: partType = L"Hidden NTFS"; break; 1471: case 0x3c: partType = L"PMagic recovery"; break; 1472: case 0x3d: partType = L"Hidden NetWare"; break; 1473: case 0x41: partType = L"Linux/MINIX"; break; 1474: case 0x42: partType = L"SFS/LDM/Linux Swap"; break; 1475: case 0x51: 1476: case 0x64: 1477: case 0x65: 1478: case 0x66: 1479: case 0x67: 1480: case 0x68: 1481: case 0x69: partType = L"Novell"; break; 1482: case 0x55: partType = L"EZ-Drive"; break; 1483: case PARTITION_OS2BOOTMGR: partType = L"OS/2 BM"; break; 1484: case PARTITION_XENIX_1: 1485: case PARTITION_XENIX_2: partType = L"Xenix"; break; 1486: case PARTITION_UNIX: partType = L"UNIX"; break; 1487: case 0x74: partType = L"Scramdisk"; break; 1488: case 0x78: partType = L"XOSL FS"; break; 1489: case 0x80: 1490: case 0x81: partType = L"MINIX"; break; 1491: case 0x82: partType = L"Linux Swap"; break; 1492: case 0x43: 1493: case 0x83: partType = L"Linux"; break; 1494: case 0xc2: 1495: case 0x93: partType = L"Hidden Linux"; break; 1496: case 0x86: 1497: case 0x87: partType = L"NTFS volume set"; break; 1498: case 0x9f: partType = L"BSD/OS"; break; 1499: case 0xa0: 1500: case 0xa1: partType = L"Hibernation"; break; 1501: case 0xa5: partType = L"BSD"; break; 1502: case 0xa8: partType = L"Mac OS-X"; break; 1503: case 0xa9: partType = L"NetBSD"; break; 1504: case 0xab: partType = L"Mac OS-X Boot"; break; 1505: case 0xb8: partType = L"BSDI BSD/386 swap"; break; 1506: case 0xc3: partType = L"Hidden Linux swap"; break; 1507: case 0xfb: partType = L"VMware"; break; 1508: case 0xfc: partType = L"VMware swap"; break; 1509: case 0xfd: partType = L"Linux RAID"; break; 1510: case 0xfe: partType = L"WinNT hidden"; break; 1511: default: wsprintfW (partTypeStr, L"0x%02X", diskInfo.PartitionType); partType = partTypeStr; break; 1.1 root 1512: } 1513: 1.1.1.7 root 1514: GetSizeString (diskInfo.PartitionLength.QuadPart, size); 1.1.1.6 root 1515: } 1.1.1.5 root 1516: 1.1.1.7 root 1517: 1.1.1.5 root 1518: memset (&LvItem,0,sizeof(LvItem)); 1519: LvItem.mask = LVIF_TEXT; 1520: LvItem.iItem = line++; 1521: 1522: // Device Name 1.1.1.7 root 1523: if (n == 0) 1524: { 1525: wchar_t s[1024]; 1526: deviceSize = diskInfo.PartitionLength.QuadPart; 1527: wsprintfW (s, L"Harddisk %d:", i); 1528: ListItemAddW (hComboBox, LvItem.iItem, s); 1529: } 1530: else 1531: { 1532: LvItem.pszText = szTmp; 1533: SendMessage (hComboBox,LVM_INSERTITEM,0,(LPARAM)&LvItem); 1534: } 1.1.1.5 root 1535: 1536: // Size 1.1.1.11! root 1537: ListSubItemSetW (hComboBox, LvItem.iItem, 2, size); 1.1.1.5 root 1538: 1.1.1.6 root 1539: // Device type removable 1540: if (n == 0 && removable) 1541: { 1.1.1.11! root 1542: ListSubItemSetW (hComboBox, LvItem.iItem, 4, GetString ("REMOVABLE")); 1.1.1.6 root 1543: } 1544: 1.1.1.5 root 1545: if (n > 0) 1546: { 1547: char drive[] = { 0, ':', 0 }; 1548: char device[MAX_PATH * 2]; 1549: int driveNo; 1550: 1551: // Drive letter 1552: strcpy (device, szTmp); 1553: ToUNICODE (device); 1554: driveNo = GetDiskDeviceDriveLetter ((PWSTR) device); 1555: drive[0] = driveNo == -1 ? 0 : 'A' + driveNo; 1556: 1557: LvItem.iSubItem = 1; 1558: LvItem.pszText = drive; 1559: SendMessage (hComboBox,LVM_SETITEM,0,(LPARAM)&LvItem); 1560: 1.1.1.11! root 1561: // Label ! 1562: if (driveNo != -1) ! 1563: { ! 1564: wchar_t name[64]; ! 1565: ! 1566: if (GetDriveLabel (driveNo, name, sizeof (name))) ! 1567: ListSubItemSetW (hComboBox, LvItem.iItem, 3, name); ! 1568: } ! 1569: 1.1.1.5 root 1570: // Partition type 1.1.1.11! root 1571: ListSubItemSetW (hComboBox, LvItem.iItem, 4, partType); 1.1.1.5 root 1572: } 1.1 root 1573: 1.1.1.11! root 1574: if (n == 1) 1.1.1.5 root 1575: { 1.1.1.11! root 1576: // Mark the device as containing partition 1.1.1.5 root 1577: LvItem.iItem = line - 2; 1.1.1.11! root 1578: LvItem.iSubItem = 0; ! 1579: LvItem.mask = LVIF_PARAM; ! 1580: LvItem.lParam |= SELDEVFLAG_CONTAINS_PARTITIONS; ! 1581: SendMessage (hComboBox, LVM_SETITEM, 0, (LPARAM) &LvItem); 1.1.1.5 root 1582: } 1583: } 1.1.1.6 root 1584: else if (n == 0) 1585: break; 1.1.1.2 root 1586: } 1587: 1.1.1.5 root 1588: if (drivePresent) 1.1.1.2 root 1589: { 1.1.1.5 root 1590: memset (&LvItem,0,sizeof(LvItem)); 1591: LvItem.mask = LVIF_TEXT; 1592: LvItem.iItem = line++; 1.1.1.2 root 1593: 1.1.1.5 root 1594: LvItem.pszText = ""; 1595: SendMessage (hComboBox,LVM_INSERTITEM,0,(LPARAM)&LvItem); 1.1 root 1596: } 1597: } 1598: 1599: i = SendMessage (hComboBox, LVM_GETITEMCOUNT, 0, 0); 1600: if (i != CB_ERR) 1601: return i; 1602: else 1603: return 0; 1604: } 1605: 1606: int 1607: GetAvailableRemovables (HWND hComboBox, char *lpszRootPath) 1608: { 1609: char szTmp[TC_MAX_PATH]; 1610: int i; 1611: LVITEM LvItem; 1612: 1613: if (lpszRootPath); /* Remove unused parameter warning */ 1614: 1.1.1.5 root 1615: memset (&LvItem,0,sizeof(LvItem)); 1.1 root 1616: LvItem.mask = LVIF_TEXT; 1617: LvItem.iItem = SendMessage (hComboBox, LVM_GETITEMCOUNT, 0, 0)+1; 1618: 1.1.1.11! root 1619: if (QueryDosDevice ("A:", szTmp, sizeof (szTmp)) != 0 && GetDriveType ("A:\\") == DRIVE_REMOVABLE) 1.1 root 1620: { 1.1.1.5 root 1621: LvItem.pszText = "\\Device\\Floppy0"; 1622: LvItem.iItem = SendMessage (hComboBox,LVM_INSERTITEM,0,(LPARAM)&LvItem); 1623: 1624: LvItem.iSubItem = 1; 1625: LvItem.pszText = "A:"; 1626: SendMessage (hComboBox,LVM_SETITEM,0,(LPARAM)&LvItem); 1627: 1.1 root 1628: } 1.1.1.11! root 1629: if (QueryDosDevice ("B:", szTmp, sizeof (szTmp)) != 0 && GetDriveType ("B:\\") == DRIVE_REMOVABLE) 1.1 root 1630: { 1.1.1.5 root 1631: LvItem.pszText = "\\Device\\Floppy1"; 1632: LvItem.iSubItem = 0; 1633: LvItem.iItem = SendMessage (hComboBox, LVM_GETITEMCOUNT, 0, 0)+1; 1634: LvItem.iItem = SendMessage (hComboBox,LVM_INSERTITEM,0,(LPARAM)&LvItem); 1635: 1636: LvItem.iSubItem = 1; 1637: LvItem.pszText = "B:"; 1638: SendMessage (hComboBox,LVM_SETITEM,0,(LPARAM)&LvItem); 1.1 root 1639: } 1640: 1641: i = SendMessage (hComboBox, LVM_GETITEMCOUNT, 0, 0); 1642: if (i != CB_ERR) 1643: return i; 1644: else 1645: return 0; 1646: } 1647: 1.1.1.7 root 1648: BOOL WINAPI LegalNoticesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) 1.1 root 1649: { 1650: WORD lw = LOWORD (wParam); 1651: if (lParam); /* remove warning */ 1652: 1653: switch (msg) 1654: { 1.1.1.7 root 1655: 1.1 root 1656: case WM_INITDIALOG: 1657: { 1.1.1.11! root 1658: char *r; 1.1.1.7 root 1659: LocalizeDialog (hwndDlg, "IDD_LEGAL_NOTICES_DLG"); 1.1.1.11! root 1660: ! 1661: r = GetLegalNotices (); ! 1662: if (r != NULL) ! 1663: { ! 1664: SetWindowText (GetDlgItem (hwndDlg, IDC_LEGAL_NOTICES), r); ! 1665: free (r); ! 1666: } 1.1.1.7 root 1667: return 1; 1668: } 1.1 root 1669: 1.1.1.7 root 1670: case WM_COMMAND: 1671: if (lw == IDOK || lw == IDCANCEL) 1672: { 1673: EndDialog (hwndDlg, 0); 1674: return 1; 1675: } 1.1 root 1676: 1.1.1.7 root 1677: // Disallow modification 1678: if (HIWORD (wParam) == EN_UPDATE) 1679: { 1680: SendMessage (hwndDlg, WM_INITDIALOG, 0, 0); 1681: return 1; 1682: } 1683: 1684: return 0; 1685: 1686: case WM_CLOSE: 1687: EndDialog (hwndDlg, 0); 1688: return 1; 1689: } 1690: 1691: return 0; 1692: } 1693: 1694: 1695: char * GetLegalNotices () 1696: { 1697: static char *resource; 1.1.1.11! root 1698: static DWORD size; ! 1699: char *buf; 1.1.1.7 root 1700: 1701: if (resource == NULL) 1.1.1.11! root 1702: resource = MapResource ("Text", IDR_LICENSE, &size); 1.1.1.7 root 1703: 1.1.1.11! root 1704: if (resource != NULL) ! 1705: { ! 1706: buf = malloc (size + 1); ! 1707: if (buf != NULL) ! 1708: { ! 1709: memcpy (buf, resource, size); ! 1710: buf[size] = 0; ! 1711: } ! 1712: } ! 1713: ! 1714: return buf; 1.1.1.7 root 1715: } 1716: 1717: 1718: BOOL WINAPI 1719: RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) 1720: { 1721: static char *lpszFileName; 1722: WORD lw = LOWORD (wParam); 1723: 1724: if (lParam); /* remove warning */ 1725: 1726: switch (msg) 1727: { 1728: case WM_INITDIALOG: 1729: { 1730: int nCount; 1731: LVCOLUMNW LvCol; 1732: HWND hList = GetDlgItem (hwndDlg, IDC_DEVICELIST); 1733: 1734: LocalizeDialog (hwndDlg, "IDD_RAWDEVICES_DLG"); 1735: 1736: SendMessage (hList,LVM_SETEXTENDEDLISTVIEWSTYLE,0, 1737: LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP|LVS_EX_TWOCLICKACTIVATE|LVS_EX_LABELTIP 1738: ); 1739: 1740: memset (&LvCol,0,sizeof(LvCol)); 1741: LvCol.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_FMT; 1742: LvCol.pszText = GetString ("DEVICE"); 1.1.1.11! root 1743: LvCol.cx = 160; 1.1.1.7 root 1744: LvCol.fmt = LVCFMT_LEFT; 1745: SendMessage (hList,LVM_INSERTCOLUMNW,0,(LPARAM)&LvCol); 1.1.1.5 root 1746: 1.1.1.7 root 1747: LvCol.pszText = GetString ("DRIVE"); 1.1.1.11! root 1748: LvCol.cx = 38; ! 1749: LvCol.fmt = LVCFMT_LEFT; 1.1.1.7 root 1750: SendMessage (hList,LVM_INSERTCOLUMNW,1,(LPARAM)&LvCol); 1.1 root 1751: 1.1.1.7 root 1752: LvCol.pszText = GetString ("SIZE"); 1.1.1.11! root 1753: LvCol.cx = 52; 1.1 root 1754: LvCol.fmt = LVCFMT_RIGHT; 1.1.1.7 root 1755: SendMessage (hList,LVM_INSERTCOLUMNW,2,(LPARAM)&LvCol); 1.1 root 1756: 1.1.1.11! root 1757: LvCol.pszText = GetString ("VOLUME_LABEL"); ! 1758: LvCol.cx = 90; 1.1 root 1759: LvCol.fmt = LVCFMT_LEFT; 1.1.1.7 root 1760: SendMessage (hList,LVM_INSERTCOLUMNW,3,(LPARAM)&LvCol); 1.1 root 1761: 1.1.1.11! root 1762: LvCol.pszText = GetString ("TYPE"); ! 1763: LvCol.cx = 76; ! 1764: LvCol.fmt = LVCFMT_LEFT; ! 1765: SendMessage (hList,LVM_INSERTCOLUMNW,4,(LPARAM)&LvCol); ! 1766: 1.1 root 1767: nCount = GetAvailableFixedDisks (hList, "\\Device\\Harddisk%d\\Partition%d"); 1768: nCount += GetAvailableRemovables (hList, "\\Device\\Floppy%d"); 1769: 1770: if (nCount == 0) 1771: { 1772: handleWin32Error (hwndDlg); 1.1.1.7 root 1773: MessageBoxW (hwndDlg, GetString ("RAWDEVICES"), lpszTitle, ICON_HAND); 1.1 root 1774: EndDialog (hwndDlg, IDCANCEL); 1775: } 1776: 1777: lpszFileName = (char *) lParam; 1778: return 1; 1779: } 1780: 1781: case WM_COMMAND: 1782: case WM_NOTIFY: 1783: // catch non-device line selected 1784: if (msg == WM_NOTIFY && ((LPNMHDR) lParam)->code == LVN_ITEMCHANGED && (((LPNMLISTVIEW) lParam)->uNewState & LVIS_FOCUSED )) 1785: { 1786: LVITEM LvItem; 1787: memset(&LvItem,0,sizeof(LvItem)); 1.1.1.11! root 1788: LvItem.mask = LVIF_TEXT | LVIF_PARAM; 1.1 root 1789: LvItem.iItem = ((LPNMLISTVIEW) lParam)->iItem; 1790: LvItem.pszText = lpszFileName; 1791: LvItem.cchTextMax = TC_MAX_PATH; 1792: 1.1.1.11! root 1793: SendMessage (GetDlgItem (hwndDlg, IDC_DEVICELIST), LVM_GETITEM, LvItem.iItem, (LPARAM) &LvItem); 1.1 root 1794: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), lpszFileName[0] != 0 && lpszFileName[0] != ' '); 1.1.1.11! root 1795: 1.1 root 1796: return 1; 1797: } 1798: 1799: if (msg == WM_COMMAND && lw == IDOK || msg == WM_NOTIFY && ((NMHDR *)lParam)->code == LVN_ITEMACTIVATE) 1800: { 1801: LVITEM LvItem; 1.1.1.5 root 1802: memset (&LvItem,0,sizeof(LvItem)); 1.1.1.11! root 1803: LvItem.mask = LVIF_TEXT | LVIF_PARAM; 1.1 root 1804: LvItem.iItem = SendMessage (GetDlgItem (hwndDlg, IDC_DEVICELIST), LVM_GETSELECTIONMARK, 0, 0); 1805: LvItem.pszText = lpszFileName; 1806: LvItem.cchTextMax = TC_MAX_PATH; 1807: 1.1.1.11! root 1808: SendMessage (GetDlgItem (hwndDlg, IDC_DEVICELIST), LVM_GETITEM, LvItem.iItem, (LPARAM) &LvItem); 1.1 root 1809: 1.1.1.5 root 1810: if (lpszFileName[0] == 'H') 1811: { 1812: // Whole device selected 1813: int driveNo; 1814: 1.1.1.11! root 1815: if (sscanf (lpszFileName, "Harddisk %d", &driveNo) != 1) ! 1816: { ! 1817: EnableWindow (GetDlgItem (hwndDlg, IDOK), FALSE); ! 1818: return 1; ! 1819: } ! 1820: ! 1821: sprintf (lpszFileName, ! 1822: (LvItem.lParam & SELDEVFLAG_VIRTUAL_PARTITION) ? ! 1823: "\\Device\\Harddisk%d\\Partition1" : "\\Device\\Harddisk%d\\Partition0", ! 1824: driveNo); 1.1.1.5 root 1825: 1826: #ifdef VOLFORMAT 1.1.1.11! root 1827: // Disallow format if the device contains partitions, but not if the partition is virtual ! 1828: if (!(LvItem.lParam & SELDEVFLAG_VIRTUAL_PARTITION) ! 1829: && !bHiddenVolDirect) 1.1.1.5 root 1830: { 1.1.1.11! root 1831: if (LvItem.lParam & SELDEVFLAG_CONTAINS_PARTITIONS) 1.1.1.7 root 1832: { 1.1.1.11! root 1833: EnableWindow (GetDlgItem (hwndDlg, IDOK), FALSE); ! 1834: Error ("DEVICE_PARTITIONS_ERR"); ! 1835: return 1; ! 1836: } 1.1.1.7 root 1837: 1.1.1.11! root 1838: if (AskWarnNoYes ("WHOLE_DEVICE_WARNING") == IDNO) ! 1839: return 1; 1.1.1.7 root 1840: 1.1.1.11! root 1841: Warning ("WHOLE_DEVICE_NOTE"); 1.1.1.5 root 1842: } 1843: #endif 1844: } 1845: 1846: if (lpszFileName[0] == 0) 1.1.1.7 root 1847: return 1; // non-device line selected 1.1 root 1848: 1849: EndDialog (hwndDlg, IDOK); 1.1.1.7 root 1850: return 1; 1.1 root 1851: } 1852: 1853: if (lw == IDCANCEL) 1854: { 1855: EndDialog (hwndDlg, IDCANCEL); 1.1.1.7 root 1856: return 1; 1.1 root 1857: } 1858: return 0; 1859: } 1860: return 0; 1861: } 1862: 1.1.1.6 root 1863: 1864: // Install and start driver service and mark it for removal (non-install mode) 1865: static int DriverLoad () 1866: { 1867: HANDLE file; 1868: WIN32_FIND_DATA find; 1869: SC_HANDLE hManager, hService = NULL; 1870: char driverPath[TC_MAX_PATH*2]; 1871: BOOL res; 1872: char *tmp; 1873: 1874: GetModuleFileName (NULL, driverPath, sizeof (driverPath)); 1875: tmp = strrchr (driverPath, '\\'); 1876: if (!tmp) 1877: { 1878: strcpy (driverPath, "."); 1879: tmp = driverPath + 1; 1880: } 1881: 1.1.1.7 root 1882: strcpy (tmp, !Is64BitOs () ? "\\truecrypt.sys" : "\\truecrypt-x64.sys"); 1.1.1.6 root 1883: 1884: file = FindFirstFile (driverPath, &find); 1885: 1886: if (file == INVALID_HANDLE_VALUE) 1887: { 1.1.1.7 root 1888: MessageBoxW (0, GetString ("DRIVER_NOT_FOUND"), lpszTitle, ICON_HAND); 1.1.1.6 root 1889: return ERR_DONT_REPORT; 1890: } 1891: 1892: FindClose (file); 1893: 1894: hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS); 1895: if (hManager == NULL) 1.1.1.7 root 1896: { 1897: if (GetLastError () == ERROR_ACCESS_DENIED) 1898: { 1899: MessageBoxW (0, GetString ("ADMIN_PRIVILEGES_DRIVER"), lpszTitle, ICON_HAND); 1900: return ERR_DONT_REPORT; 1901: } 1902: 1.1.1.6 root 1903: return ERR_OS_ERROR; 1.1.1.7 root 1904: } 1.1.1.6 root 1905: 1906: hService = CreateService (hManager, "truecrypt", "truecrypt", 1907: SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, 1908: driverPath, NULL, NULL, NULL, NULL, NULL); 1909: 1910: if (hService == NULL) 1911: { 1912: CloseServiceHandle (hManager); 1913: return ERR_OS_ERROR; 1914: } 1915: 1916: res = StartService (hService, 0, NULL); 1917: 1918: DeleteService (hService); 1919: CloseServiceHandle (hManager); 1920: CloseServiceHandle (hService); 1921: 1922: return !res ? ERR_OS_ERROR : ERROR_SUCCESS; 1923: } 1924: 1925: 1.1.1.7 root 1926: BOOL DriverUnload () 1927: { 1928: MOUNT_LIST_STRUCT driver; 1929: int refCount; 1930: DWORD dwResult; 1931: BOOL bResult; 1932: 1933: SC_HANDLE hManager, hService = NULL; 1934: BOOL bRet; 1935: SERVICE_STATUS status; 1936: int x; 1937: 1938: if (hDriver == INVALID_HANDLE_VALUE) 1939: return TRUE; 1940: 1941: // Test for mounted volumes 1942: bResult = DeviceIoControl (hDriver, MOUNT_LIST, &driver, sizeof (driver), &driver, 1943: sizeof (driver), &dwResult, NULL); 1944: 1945: if (bResult) 1946: { 1947: if (driver.ulMountedDrives != 0) 1948: return FALSE; 1949: } 1950: else 1951: return TRUE; 1952: 1953: // Test for any applications attached to driver 1954: refCount = GetDriverRefCount (); 1955: 1956: if (refCount > 1) 1957: return FALSE; 1958: 1959: CloseHandle (hDriver); 1960: 1961: // Stop driver service 1962: 1963: hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS); 1964: if (hManager == NULL) 1965: goto error; 1966: 1967: hService = OpenService (hManager, "truecrypt", SERVICE_ALL_ACCESS); 1968: if (hService == NULL) 1969: goto error; 1970: 1971: bRet = QueryServiceStatus (hService, &status); 1972: if (bRet != TRUE) 1973: goto error; 1974: 1975: if (status.dwCurrentState != SERVICE_STOPPED) 1976: { 1977: ControlService (hService, SERVICE_CONTROL_STOP, &status); 1978: 1979: for (x = 0; x < 5; x++) 1980: { 1981: bRet = QueryServiceStatus (hService, &status); 1982: if (bRet != TRUE) 1983: goto error; 1984: 1985: if (status.dwCurrentState == SERVICE_STOPPED) 1986: break; 1987: 1988: Sleep (200); 1989: } 1990: } 1991: 1992: error: 1993: if (hService != NULL) 1994: CloseServiceHandle (hService); 1995: 1996: if (hManager != NULL) 1997: CloseServiceHandle (hManager); 1998: 1999: if (status.dwCurrentState == SERVICE_STOPPED) 2000: { 2001: hDriver = INVALID_HANDLE_VALUE; 2002: return TRUE; 2003: } 2004: 2005: return FALSE; 2006: } 2007: 2008: 1.1 root 2009: int 2010: DriverAttach (void) 2011: { 1.1.1.6 root 2012: /* Try to open a handle to the device driver. It will be closed later. */ 1.1 root 2013: 1.1.1.6 root 2014: hDriver = CreateFile (WIN32_ROOT_PREFIX, 0, 0, NULL, OPEN_EXISTING, 0, NULL); 1.1 root 2015: 2016: if (hDriver == INVALID_HANDLE_VALUE) 2017: { 1.1.1.6 root 2018: #ifndef SETUP 2019: // Attempt to load driver (non-install mode) 1.1.1.8 root 2020: { 2021: BOOL res = DriverLoad (); 1.1.1.6 root 2022: 1.1.1.8 root 2023: if (res != ERROR_SUCCESS) 2024: return res; 1.1.1.6 root 2025: 1.1.1.8 root 2026: hDriver = CreateFile (WIN32_ROOT_PREFIX, 0, 0, NULL, OPEN_EXISTING, 0, NULL); 2027: } 1.1.1.6 root 2028: #endif 2029: if (hDriver == INVALID_HANDLE_VALUE) 2030: return ERR_OS_ERROR; 1.1 root 2031: } 1.1.1.7 root 2032: 2033: if (hDriver != INVALID_HANDLE_VALUE) 1.1 root 2034: { 2035: DWORD dwResult; 2036: 2037: BOOL bResult = DeviceIoControl (hDriver, DRIVER_VERSION, 1.1.1.11! root 2038: &DriverVersion, 4, &DriverVersion, 4, &dwResult, NULL); 1.1 root 2039: 1.1.1.11! root 2040: #ifndef SETUP // Don't check version during setup to allow removal of another version 1.1 root 2041: if (bResult == FALSE) 2042: return ERR_OS_ERROR; 1.1.1.11! root 2043: else if (DriverVersion != VERSION_NUM) 1.1 root 2044: return ERR_DRIVER_VERSION; 1.1.1.11! root 2045: #else ! 2046: if (!bResult) ! 2047: DriverVersion = 0; 1.1 root 2048: #endif 1.1.1.11! root 2049: } 1.1 root 2050: 2051: return 0; 2052: } 2053: 1.1.1.5 root 2054: 2055: // Sets file pointer to hidden volume header 2056: BOOL SeekHiddenVolHeader (HFILE dev, unsigned __int64 volSize, BOOL deviceFlag) 2057: { 2058: LARGE_INTEGER offset, offsetNew; 2059: 2060: if (deviceFlag) 2061: { 2062: // Partition/device 2063: 2064: offset.QuadPart = volSize - HIDDEN_VOL_HEADER_OFFSET; 2065: 2066: if (SetFilePointerEx ((HANDLE) dev, offset, &offsetNew, FILE_BEGIN) == 0) 2067: return FALSE; 2068: 2069: if (offsetNew.QuadPart != offset.QuadPart) 2070: return FALSE; 2071: } 2072: else 2073: { 2074: // File-hosted volume 2075: 2076: offset.QuadPart = - HIDDEN_VOL_HEADER_OFFSET; 2077: 2078: if (SetFilePointerEx ((HANDLE) dev, offset, &offsetNew, FILE_END) == 0) 2079: return FALSE; 2080: } 2081: 2082: return TRUE; 2083: } 2084: 1.1.1.10 root 2085: 2086: void ResetCurrentDirectory () 2087: { 2088: char p[MAX_PATH]; 2089: if (!IsNonInstallMode () && SHGetFolderPath (NULL, CSIDL_PROFILE, NULL, 0, p) == ERROR_SUCCESS) 2090: { 2091: SetCurrentDirectory (p); 2092: } 2093: else 2094: { 1.1.1.11! root 2095: GetModPath (p, sizeof (p)); 1.1.1.10 root 2096: SetCurrentDirectory (p); 2097: } 2098: } 2099: 2100: 1.1.1.11! root 2101: BOOL BrowseFiles (HWND hwndDlg, char *stringId, char *lpszFileName, BOOL keepHistory, BOOL saveMode) ! 2102: { ! 2103: return BrowseFilesInDir (hwndDlg, stringId, NULL, lpszFileName, keepHistory, saveMode); ! 2104: } ! 2105: ! 2106: ! 2107: BOOL BrowseFilesInDir (HWND hwndDlg, char *stringId, char *initialDir, char *lpszFileName, BOOL keepHistory, BOOL saveMode) 1.1 root 2108: { 1.1.1.7 root 2109: OPENFILENAMEW ofn; 2110: wchar_t file[TC_MAX_PATH] = { 0 }; 1.1.1.11! root 2111: wchar_t wInitialDir[TC_MAX_PATH] = { 0 }; 1.1.1.7 root 2112: wchar_t filter[1024]; 2113: 1.1.1.10 root 2114: ZeroMemory (&ofn, sizeof (ofn)); 1.1.1.7 root 2115: *lpszFileName = 0; 1.1.1.11! root 2116: ! 2117: if (initialDir) ! 2118: { ! 2119: swprintf_s (wInitialDir, sizeof (wInitialDir) / 2, L"%hs", initialDir); ! 2120: ofn.lpstrInitialDir = wInitialDir; ! 2121: } ! 2122: 1.1.1.10 root 2123: ofn.lStructSize = sizeof (ofn); 2124: ofn.hwndOwner = hwndDlg; 2125: wsprintfW (filter, L"%ls (*.*)%c*.*%c%ls (*.tc)%c*.tc%c%c", 2126: GetString ("ALL_FILES"), 0, 0, GetString ("TC_VOLUMES"), 0, 0, 0); 2127: ofn.lpstrFilter = filter; 2128: ofn.nFilterIndex = 1; 2129: ofn.lpstrFile = file; 2130: ofn.nMaxFile = sizeof (file) / sizeof (file[0]); 2131: ofn.lpstrTitle = GetString (stringId); 2132: ofn.Flags = OFN_HIDEREADONLY 1.1.1.8 root 2133: | OFN_PATHMUSTEXIST 2134: | (keepHistory ? 0 : OFN_DONTADDTORECENT) 2135: | (saveMode ? OFN_OVERWRITEPROMPT : 0); 2136: 1.1.1.11! root 2137: if (!keepHistory) ! 2138: CleanLastVisitedMRU (); ! 2139: 1.1.1.8 root 2140: if (!saveMode) 1.1.1.7 root 2141: { 1.1.1.8 root 2142: if (!GetOpenFileNameW (&ofn)) 2143: return FALSE; 1.1.1.7 root 2144: } 1.1 root 2145: else 1.1.1.7 root 2146: { 1.1.1.8 root 2147: if (!GetSaveFileNameW (&ofn)) 2148: return FALSE; 1.1.1.7 root 2149: } 1.1.1.8 root 2150: 2151: WideCharToMultiByte (CP_ACP, 0, file, -1, lpszFileName, MAX_PATH, NULL, NULL); 1.1.1.9 root 2152: 1.1.1.11! root 2153: if (!keepHistory) ! 2154: CleanLastVisitedMRU (); 1.1.1.9 root 2155: 1.1.1.11! root 2156: ResetCurrentDirectory (); 1.1.1.9 root 2157: 2158: return TRUE; 2159: } 2160: 2161: 2162: static char SelectMultipleFilesPath[MAX_PATH]; 2163: static int SelectMultipleFilesOffset; 2164: 2165: BOOL SelectMultipleFiles (HWND hwndDlg, char *stringId, char *lpszFileName, BOOL keepHistory) 2166: { 2167: OPENFILENAMEW ofn; 2168: wchar_t file[TC_MAX_PATH] = { 0 }; 2169: wchar_t filter[1024]; 2170: 1.1.1.10 root 2171: ZeroMemory (&ofn, sizeof (ofn)); 1.1.1.9 root 2172: 2173: *lpszFileName = 0; 1.1.1.10 root 2174: ofn.lStructSize = sizeof (ofn); 2175: ofn.hwndOwner = hwndDlg; 2176: wsprintfW (filter, L"%ls (*.*)%c*.*%c%ls (*.tc)%c*.tc%c%c", 2177: GetString ("ALL_FILES"), 0, 0, GetString ("TC_VOLUMES"), 0, 0, 0); 2178: ofn.lpstrFilter = filter; 2179: ofn.nFilterIndex = 1; 2180: ofn.lpstrFile = file; 2181: ofn.nMaxFile = sizeof (file) / sizeof (file[0]); 2182: ofn.lpstrTitle = GetString (stringId); 2183: ofn.Flags = OFN_HIDEREADONLY 1.1.1.9 root 2184: | OFN_EXPLORER 2185: | OFN_PATHMUSTEXIST 2186: | OFN_ALLOWMULTISELECT 2187: | (keepHistory ? 0 : OFN_DONTADDTORECENT); 2188: 2189: if (!keepHistory) 2190: CleanLastVisitedMRU (); 2191: 1.1.1.11! root 2192: if (!GetOpenFileNameW (&ofn)) ! 2193: return FALSE; ! 2194: 1.1.1.9 root 2195: if (file[ofn.nFileOffset - 1] != 0) 2196: { 2197: // Single file selected 2198: WideCharToMultiByte (CP_ACP, 0, file, -1, lpszFileName, MAX_PATH, NULL, NULL); 2199: SelectMultipleFilesOffset = 0; 2200: } 2201: else 2202: { 2203: // Multiple files selected 2204: int n; 2205: wchar_t *f = file; 2206: char *s = SelectMultipleFilesPath; 2207: while ((n = WideCharToMultiByte (CP_ACP, 0, f, -1, s, MAX_PATH, NULL, NULL)) > 1) 2208: { 2209: f += n; 2210: s += n; 2211: } 2212: 2213: SelectMultipleFilesOffset = ofn.nFileOffset; 2214: SelectMultipleFilesNext (lpszFileName); 2215: } 2216: 1.1.1.11! root 2217: if (!keepHistory) ! 2218: CleanLastVisitedMRU (); 1.1.1.9 root 2219: 1.1.1.11! root 2220: ResetCurrentDirectory (); 1.1.1.9 root 2221: 2222: return TRUE; 2223: } 2224: 2225: 2226: BOOL SelectMultipleFilesNext (char *lpszFileName) 2227: { 2228: if (SelectMultipleFilesOffset == 0) 2229: return FALSE; 2230: 2231: strncpy (lpszFileName, SelectMultipleFilesPath, sizeof (SelectMultipleFilesPath)); 2232: 2233: if (lpszFileName[strlen (lpszFileName) - 1] != '\\') 2234: strcat (lpszFileName, "\\"); 2235: 2236: strcat (lpszFileName, SelectMultipleFilesPath + SelectMultipleFilesOffset); 2237: 2238: SelectMultipleFilesOffset += strlen (SelectMultipleFilesPath + SelectMultipleFilesOffset) + 1; 2239: if (SelectMultipleFilesPath[SelectMultipleFilesOffset] == 0) 2240: SelectMultipleFilesOffset = 0; 2241: 1.1.1.8 root 2242: return TRUE; 1.1 root 2243: } 2244: 2245: 1.1.1.7 root 2246: static int CALLBACK 2247: BrowseCallbackProc(HWND hwnd,UINT uMsg,LPARAM lp, LPARAM pData) 1.1.1.6 root 2248: { 1.1.1.7 root 2249: switch(uMsg) { 2250: case BFFM_INITIALIZED: 2251: { 2252: /* WParam is TRUE since we are passing a path. 2253: It would be FALSE if we were passing a pidl. */ 2254: SendMessage (hwnd,BFFM_SETSELECTION,TRUE,(LPARAM)pData); 2255: break; 2256: } 2257: 2258: case BFFM_SELCHANGED: 2259: { 2260: char szDir[TC_MAX_PATH]; 2261: 2262: /* Set the status window to the currently selected path. */ 2263: if (SHGetPathFromIDList((LPITEMIDLIST) lp ,szDir)) 2264: { 2265: SendMessage (hwnd,BFFM_SETSTATUSTEXT,0,(LPARAM)szDir); 2266: } 2267: break; 2268: } 2269: 2270: default: 2271: break; 2272: } 2273: 2274: return 0; 2275: } 1.1.1.6 root 2276: 2277: 1.1.1.7 root 2278: BOOL 2279: BrowseDirectories (HWND hwndDlg, char *lpszTitle, char *dirName) 2280: { 2281: BROWSEINFOW bi; 2282: LPITEMIDLIST pidl; 2283: LPMALLOC pMalloc; 2284: BOOL bOK = FALSE; 1.1.1.6 root 2285: 1.1.1.7 root 2286: if (SUCCEEDED(SHGetMalloc(&pMalloc))) 1.1.1.6 root 2287: { 1.1.1.7 root 2288: ZeroMemory(&bi,sizeof(bi)); 2289: bi.hwndOwner = hwndDlg; 2290: bi.pszDisplayName = 0; 2291: bi.lpszTitle = GetString (lpszTitle); 2292: bi.pidlRoot = 0; 2293: bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT /*| BIF_EDITBOX*/; 2294: bi.lpfn = BrowseCallbackProc; 2295: bi.lParam = (LPARAM)dirName; 1.1.1.6 root 2296: 1.1.1.7 root 2297: pidl = SHBrowseForFolderW (&bi); 2298: if (pidl!=NULL) 2299: { 2300: if (SHGetPathFromIDList(pidl, dirName)) 2301: { 2302: bOK = TRUE; 2303: } 2304: 2305: pMalloc->lpVtbl->Free(pMalloc,pidl); 2306: pMalloc->lpVtbl->Release(pMalloc); 2307: } 1.1.1.6 root 2308: } 2309: 1.1.1.7 root 2310: return bOK; 1.1.1.6 root 2311: } 2312: 2313: 1.1 root 2314: void 2315: handleError (HWND hwndDlg, int code) 2316: { 1.1.1.11! root 2317: WCHAR szTmp[4096]; 1.1.1.7 root 2318: 2319: if (Silent) return; 1.1 root 2320: 2321: switch (code) 2322: { 2323: case ERR_OS_ERROR: 2324: handleWin32Error (hwndDlg); 2325: break; 2326: case ERR_OUTOFMEMORY: 1.1.1.7 root 2327: MessageBoxW (hwndDlg, GetString ("OUTOFMEMORY"), lpszTitle, ICON_HAND); 1.1 root 2328: break; 1.1.1.7 root 2329: 1.1 root 2330: case ERR_PASSWORD_WRONG: 1.1.1.11! root 2331: swprintf (szTmp, GetString (KeyFilesEnable ? "PASSWORD_OR_KEYFILE_WRONG" : "PASSWORD_WRONG")); 1.1.1.7 root 2332: if (CheckCapsLock (hwndDlg, TRUE)) 2333: wcscat (szTmp, GetString ("PASSWORD_WRONG_CAPSLOCK_ON")); 2334: 2335: MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONWARNING); 1.1 root 2336: break; 1.1.1.7 root 2337: 1.1 root 2338: case ERR_DRIVE_NOT_FOUND: 1.1.1.7 root 2339: MessageBoxW (hwndDlg, GetString ("NOT_FOUND"), lpszTitle, ICON_HAND); 1.1 root 2340: break; 2341: case ERR_FILES_OPEN: 1.1.1.7 root 2342: MessageBoxW (hwndDlg, GetString ("OPENFILES_DRIVER"), lpszTitle, ICON_HAND); 1.1 root 2343: break; 2344: case ERR_FILES_OPEN_LOCK: 1.1.1.7 root 2345: MessageBoxW (hwndDlg, GetString ("OPENFILES_LOCK"), lpszTitle, ICON_HAND); 1.1 root 2346: break; 2347: case ERR_VOL_SIZE_WRONG: 1.1.1.7 root 2348: MessageBoxW (hwndDlg, GetString ("VOL_SIZE_WRONG"), lpszTitle, ICON_HAND); 1.1 root 2349: break; 2350: case ERR_COMPRESSION_NOT_SUPPORTED: 1.1.1.7 root 2351: MessageBoxW (hwndDlg, GetString ("COMPRESSION_NOT_SUPPORTED"), lpszTitle, ICON_HAND); 1.1 root 2352: break; 2353: case ERR_PASSWORD_CHANGE_VOL_TYPE: 1.1.1.7 root 2354: MessageBoxW (hwndDlg, GetString ("WRONG_VOL_TYPE"), lpszTitle, ICON_HAND); 1.1 root 2355: break; 2356: case ERR_VOL_SEEKING: 1.1.1.7 root 2357: MessageBoxW (hwndDlg, GetString ("VOL_SEEKING"), lpszTitle, ICON_HAND); 1.1 root 2358: break; 2359: case ERR_VOL_WRITING: 1.1.1.7 root 2360: MessageBoxW (hwndDlg, GetString ("VOL_WRITING"), lpszTitle, ICON_HAND); 1.1 root 2361: break; 2362: case ERR_VOL_READING: 1.1.1.7 root 2363: MessageBoxW (hwndDlg, GetString ("VOL_READING"), lpszTitle, ICON_HAND); 2364: break; 2365: case ERR_CIPHER_INIT_FAILURE: 2366: MessageBoxW (hwndDlg, GetString ("ERR_CIPHER_INIT_FAILURE"), lpszTitle, ICON_HAND); 2367: break; 2368: case ERR_CIPHER_INIT_WEAK_KEY: 2369: MessageBoxW (hwndDlg, GetString ("ERR_CIPHER_INIT_WEAK_KEY"), lpszTitle, ICON_HAND); 1.1 root 2370: break; 2371: case ERR_VOL_ALREADY_MOUNTED: 1.1.1.7 root 2372: MessageBoxW (hwndDlg, GetString ("VOL_ALREADY_MOUNTED"), lpszTitle, ICON_HAND); 1.1 root 2373: break; 2374: case ERR_FILE_OPEN_FAILED: 1.1.1.7 root 2375: MessageBoxW (hwndDlg, GetString ("FILE_OPEN_FAILED"), lpszTitle, ICON_HAND); 1.1 root 2376: break; 2377: case ERR_VOL_MOUNT_FAILED: 1.1.1.7 root 2378: MessageBoxW (hwndDlg, GetString ("VOL_MOUNT_FAILED"), lpszTitle, ICON_HAND); 1.1 root 2379: break; 2380: case ERR_NO_FREE_DRIVES: 1.1.1.7 root 2381: MessageBoxW (hwndDlg, GetString ("NO_FREE_DRIVES"), lpszTitle, ICON_HAND); 1.1 root 2382: break; 2383: case ERR_INVALID_DEVICE: 1.1.1.7 root 2384: MessageBoxW (hwndDlg, GetString ("INVALID_DEVICE"), lpszTitle, ICON_HAND); 1.1 root 2385: break; 2386: case ERR_ACCESS_DENIED: 1.1.1.7 root 2387: MessageBoxW (hwndDlg, GetString ("ACCESS_DENIED"), lpszTitle, ICON_HAND); 1.1 root 2388: break; 2389: 2390: case ERR_DRIVER_VERSION: 1.1.1.7 root 2391: wsprintfW (szTmp, GetString ("DRIVER_VERSION"), VERSION_STRING); 2392: MessageBoxW (hwndDlg, szTmp, lpszTitle, ICON_HAND); 1.1 root 2393: break; 2394: 2395: case ERR_NEW_VERSION_REQUIRED: 1.1.1.7 root 2396: MessageBoxW (hwndDlg, GetString ("NEW_VERSION_REQUIRED"), lpszTitle, ICON_HAND); 2397: break; 2398: 2399: case ERR_SELF_TESTS_FAILED: 2400: Error ("ERR_SELF_TESTS_FAILED"); 1.1 root 2401: break; 2402: 1.1.1.6 root 2403: case ERR_DONT_REPORT: 2404: break; 2405: 1.1 root 2406: default: 1.1.1.7 root 2407: wsprintfW (szTmp, GetString ("ERR_UNKNOWN"), code); 2408: MessageBoxW (hwndDlg, szTmp, lpszTitle, ICON_HAND); 1.1 root 2409: } 2410: } 2411: 1.1.1.7 root 2412: static BOOL CALLBACK LocalizeDialogEnum( HWND hwnd, LPARAM font) 1.1 root 2413: { 1.1.1.7 root 2414: // Localization of controls 1.1 root 2415: 1.1.1.7 root 2416: if (LocalizationActive) 1.1 root 2417: { 1.1.1.7 root 2418: int ctrlId = GetDlgCtrlID (hwnd); 2419: if (ctrlId != 0) 2420: { 2421: char name[10] = { 0 }; 2422: GetClassName (hwnd, name, sizeof (name)); 1.1.1.5 root 2423: 1.1.1.7 root 2424: if (_stricmp (name, "Button") == 0 || _stricmp (name, "Static") == 0) 2425: { 2426: wchar_t *str = GetDictionaryValueByInt (ctrlId); 2427: if (str != NULL) 2428: SetWindowTextW (hwnd, str); 2429: } 2430: } 2431: } 1.1 root 2432: 1.1.1.7 root 2433: // Font 2434: SendMessage (hwnd, WM_SETFONT, (WPARAM) font, 0); 2435: 2436: return TRUE; 2437: } 1.1 root 2438: 1.1.1.7 root 2439: void LocalizeDialog (HWND hwnd, char *stringId) 2440: { 1.1.1.10 root 2441: LastDialogId = stringId; 1.1.1.7 root 2442: SetWindowLongPtr (hwnd, GWLP_USERDATA, (LONG_PTR) 'TRUE'); 1.1.1.8 root 2443: SendMessage (hwnd, WM_SETFONT, (WPARAM) hUserFont, 0); 1.1.1.5 root 2444: 1.1.1.11! root 2445: if (stringId == NULL) ! 2446: SetWindowText (hwnd, "TrueCrypt"); ! 2447: else if (LocalizationActive) 1.1.1.7 root 2448: SetWindowTextW (hwnd, GetString (stringId)); 1.1.1.11! root 2449: 1.1.1.7 root 2450: if (hUserFont != 0) 2451: EnumChildWindows (hwnd, LocalizeDialogEnum, (LPARAM) hUserFont); 1.1.1.5 root 2452: } 2453: 2454: void OpenVolumeExplorerWindow (int driveNo) 2455: { 2456: char dosName[5]; 2457: SHFILEINFO fInfo; 2458: 2459: sprintf (dosName, "%c:\\", (char) driveNo + 'A'); 2460: 2461: // Force explorer to discover the drive 2462: SHGetFileInfo (dosName, 0, &fInfo, sizeof (fInfo), 0); 2463: 2464: ShellExecute (NULL, "open", dosName, NULL, NULL, SW_SHOWNORMAL); 2465: } 2466: 2467: static BOOL explorerCloseSent; 1.1.1.11! root 2468: static HWND explorerTopLevelWindow; 1.1.1.5 root 2469: 1.1.1.11! root 2470: static BOOL CALLBACK CloseVolumeExplorerWindowsChildEnum (HWND hwnd, LPARAM driveStr) 1.1.1.5 root 2471: { 1.1.1.11! root 2472: char s[MAX_PATH]; ! 2473: SendMessage (hwnd, WM_GETTEXT, sizeof (s), (LPARAM) s); 1.1.1.5 root 2474: 1.1.1.11! root 2475: if (strstr (s, (char *) driveStr) != NULL) 1.1.1.5 root 2476: { 1.1.1.11! root 2477: PostMessage (explorerTopLevelWindow, WM_CLOSE, 0, 0); ! 2478: explorerCloseSent = TRUE; ! 2479: return FALSE; ! 2480: } 1.1.1.5 root 2481: 1.1.1.11! root 2482: return TRUE; ! 2483: } ! 2484: ! 2485: static BOOL CALLBACK CloseVolumeExplorerWindowsEnum (HWND hwnd, LPARAM driveNo) ! 2486: { ! 2487: char driveStr[10]; ! 2488: char s[MAX_PATH]; ! 2489: ! 2490: sprintf (driveStr, "%c:\\", driveNo + 'A'); ! 2491: ! 2492: GetClassName (hwnd, s, sizeof s); ! 2493: if (strcmp (s, "CabinetWClass") == 0) ! 2494: { ! 2495: GetWindowText (hwnd, s, sizeof s); ! 2496: if (strstr (s, driveStr) != NULL) 1.1.1.5 root 2497: { 2498: PostMessage (hwnd, WM_CLOSE, 0, 0); 2499: explorerCloseSent = TRUE; 1.1.1.11! root 2500: return FALSE; 1.1.1.5 root 2501: } 2502: 1.1.1.11! root 2503: explorerTopLevelWindow = hwnd; ! 2504: EnumChildWindows (hwnd, CloseVolumeExplorerWindowsChildEnum, (LPARAM) driveStr); 1.1.1.5 root 2505: } 1.1.1.11! root 2506: 1.1.1.5 root 2507: return TRUE; 2508: } 2509: 2510: BOOL CloseVolumeExplorerWindows (HWND hwnd, int driveNo) 2511: { 2512: explorerCloseSent = FALSE; 2513: EnumWindows (CloseVolumeExplorerWindowsEnum, (LPARAM) driveNo); 2514: 2515: return explorerCloseSent; 2516: } 2517: 1.1.1.7 root 2518: void GetSizeString (unsigned __int64 size, wchar_t *str) 2519: { 2520: static wchar_t *b, *kb, *mb, *gb, *tb, *pb; 2521: static int serNo; 2522: 2523: if (b == NULL || serNo != LocalizationSerialNo) 2524: { 2525: serNo = LocalizationSerialNo; 2526: kb = GetString ("KB"); 2527: mb = GetString ("MB"); 2528: gb = GetString ("GB"); 2529: tb = GetString ("TB"); 2530: pb = GetString ("PB"); 2531: b = GetString ("BYTE"); 2532: } 2533: 2534: if (size > 1024I64*1024*1024*1024*1024*99) 2535: swprintf (str, L"%I64d %s", size/1024/1024/1024/1024/1024, pb); 2536: else if (size > 1024I64*1024*1024*1024*1024) 2537: swprintf (str, L"%.1f %s",(double)(size/1024.0/1024/1024/1024/1024), pb); 2538: else if (size > 1024I64*1024*1024*1024*99) 2539: swprintf (str, L"%I64d %s",size/1024/1024/1024/1024, tb); 2540: else if (size > 1024I64*1024*1024*1024) 2541: swprintf (str, L"%.1f %s",(double)(size/1024.0/1024/1024/1024), tb); 2542: else if (size > 1024I64*1024*1024*99) 2543: swprintf (str, L"%I64d %s",size/1024/1024/1024, gb); 2544: else if (size > 1024I64*1024*1024) 2545: swprintf (str, L"%.1f %s",(double)(size/1024.0/1024/1024), gb); 2546: else if (size > 1024I64*1024*99) 2547: swprintf (str, L"%I64d %s", size/1024/1024, mb); 2548: else if (size > 1024I64*1024) 2549: swprintf (str, L"%.1f %s",(double)(size/1024.0/1024), mb); 2550: else if (size > 1024I64) 2551: swprintf (str, L"%I64d %s", size/1024, kb); 2552: else 2553: swprintf (str, L"%I64d %s", size, b); 2554: } 1.1.1.5 root 2555: 2556: #ifndef SETUP 1.1.1.7 root 2557: void GetSpeedString (unsigned __int64 speed, wchar_t *str) 1.1.1.5 root 2558: { 1.1.1.7 root 2559: static wchar_t *b, *kb, *mb, *gb, *tb, *pb; 2560: static int serNo; 2561: 2562: if (b == NULL || serNo != LocalizationSerialNo) 2563: { 2564: serNo = LocalizationSerialNo; 2565: kb = GetString ("KB_PER_SEC"); 2566: mb = GetString ("MB_PER_SEC"); 2567: gb = GetString ("GB_PER_SEC"); 2568: tb = GetString ("TB_PER_SEC"); 2569: pb = GetString ("PB_PER_SEC"); 2570: b = GetString ("B_PER_SEC"); 2571: } 2572: 1.1.1.5 root 2573: if (speed > 1024I64*1024*1024*1024*1024*99) 1.1.1.7 root 2574: swprintf (str, L"%I64d %s", speed/1024/1024/1024/1024/1024, pb); 1.1.1.5 root 2575: else if (speed > 1024I64*1024*1024*1024*1024) 1.1.1.7 root 2576: swprintf (str, L"%.1f %s",(double)(speed/1024.0/1024/1024/1024/1024), pb); 1.1.1.5 root 2577: else if (speed > 1024I64*1024*1024*1024*99) 1.1.1.7 root 2578: swprintf (str, L"%I64d %s",speed/1024/1024/1024/1024, tb); 1.1.1.5 root 2579: else if (speed > 1024I64*1024*1024*1024) 1.1.1.7 root 2580: swprintf (str, L"%.1f %s",(double)(speed/1024.0/1024/1024/1024), tb); 1.1.1.5 root 2581: else if (speed > 1024I64*1024*1024*99) 1.1.1.7 root 2582: swprintf (str, L"%I64d %s",speed/1024/1024/1024, gb); 1.1.1.5 root 2583: else if (speed > 1024I64*1024*1024) 1.1.1.7 root 2584: swprintf (str, L"%.1f %s",(double)(speed/1024.0/1024/1024), gb); 1.1.1.5 root 2585: else if (speed > 1024I64*1024*99) 1.1.1.7 root 2586: swprintf (str, L"%I64d %s", speed/1024/1024, mb); 1.1.1.5 root 2587: else if (speed > 1024I64*1024) 1.1.1.7 root 2588: swprintf (str, L"%.1f %s",(double)(speed/1024.0/1024), mb); 2589: else if (speed > 1024I64) 2590: swprintf (str, L"%I64d %s", speed/1024, kb); 1.1.1.5 root 2591: else 1.1.1.7 root 2592: swprintf (str, L"%I64d %s", speed, b); 1.1.1.5 root 2593: } 2594: 2595: static void DisplayBenchmarkResults (HWND hwndDlg) 2596: { 1.1.1.7 root 2597: wchar_t item1[100]={0}; 2598: LVITEMW LvItem; 1.1.1.5 root 2599: HWND hList = GetDlgItem (hwndDlg, IDC_RESULTS); 2600: int ea, i; 2601: BOOL unsorted = TRUE; 1.1.1.7 root 2602: BENCHMARK_REC tmp_line; 1.1.1.5 root 2603: 2604: /* Sort the list */ 2605: 2606: switch (benchmarkSortMethod) 2607: { 2608: case BENCHMARK_SORT_BY_SPEED: 2609: 2610: while (unsorted) 2611: { 2612: unsorted = FALSE; 2613: for (i = 0; i < benchmarkTotalItems - 1; i++) 2614: { 2615: if (benchmarkTable[i].meanBytesPerSec < benchmarkTable[i+1].meanBytesPerSec) 2616: { 2617: unsorted = TRUE; 2618: memcpy (&tmp_line, &benchmarkTable[i], sizeof(BENCHMARK_REC)); 2619: memcpy (&benchmarkTable[i], &benchmarkTable[i+1], sizeof(BENCHMARK_REC)); 2620: memcpy (&benchmarkTable[i+1], &tmp_line, sizeof(BENCHMARK_REC)); 2621: } 2622: } 2623: } 2624: break; 2625: 2626: case BENCHMARK_SORT_BY_NAME: 2627: 2628: while (unsorted) 2629: { 2630: unsorted = FALSE; 2631: for (i = 0; i < benchmarkTotalItems - 1; i++) 2632: { 2633: if (benchmarkTable[i].id > benchmarkTable[i+1].id) 2634: { 2635: unsorted = TRUE; 2636: memcpy (&tmp_line, &benchmarkTable[i], sizeof(BENCHMARK_REC)); 2637: memcpy (&benchmarkTable[i], &benchmarkTable[i+1], sizeof(BENCHMARK_REC)); 2638: memcpy (&benchmarkTable[i+1], &tmp_line, sizeof(BENCHMARK_REC)); 2639: } 2640: } 2641: } 2642: break; 2643: } 2644: 2645: /* Render the results */ 2646: 2647: SendMessage (hList,LVM_DELETEALLITEMS,0,(LPARAM)&LvItem); 2648: 2649: for (i = 0; i < benchmarkTotalItems; i++) 2650: { 2651: ea = benchmarkTable[i].id; 2652: 2653: memset (&LvItem,0,sizeof(LvItem)); 2654: LvItem.mask = LVIF_TEXT; 1.1.1.7 root 2655: LvItem.iItem = i; 1.1.1.5 root 2656: LvItem.iSubItem = 0; 1.1.1.7 root 2657: LvItem.pszText = (LPWSTR) benchmarkTable[i].name; 2658: SendMessageW (hList, LVM_INSERTITEM, 0, (LPARAM)&LvItem); 1.1.1.5 root 2659: 1.1.1.7 root 2660: #if PKCS5_BENCHMARKS 2661: wcscpy (item1, L"-"); 2662: #else 2663: GetSpeedString ((unsigned __int64) (benchmarkLastBufferSize / ((float) benchmarkTable[i].encSpeed / benchmarkPerformanceFrequency.QuadPart)), item1); 2664: #endif 1.1.1.5 root 2665: LvItem.iSubItem = 1; 2666: LvItem.pszText = item1; 2667: 1.1.1.7 root 2668: SendMessageW (hList, LVM_SETITEMW, 0, (LPARAM)&LvItem); 2669: 2670: #if PKCS5_BENCHMARKS 2671: wcscpy (item1, L"-"); 2672: #else 2673: GetSpeedString ((unsigned __int64) (benchmarkLastBufferSize / ((float) benchmarkTable[i].decSpeed / benchmarkPerformanceFrequency.QuadPart)), item1); 2674: #endif 1.1.1.5 root 2675: LvItem.iSubItem = 2; 2676: LvItem.pszText = item1; 2677: 1.1.1.7 root 2678: SendMessageW (hList, LVM_SETITEMW, 0, (LPARAM)&LvItem); 1.1.1.5 root 2679: 1.1.1.7 root 2680: #if PKCS5_BENCHMARKS 2681: swprintf (item1, L"%d t", benchmarkTable[i].encSpeed); 2682: #else 2683: GetSpeedString (benchmarkTable[i].meanBytesPerSec, item1); 2684: #endif 1.1.1.5 root 2685: LvItem.iSubItem = 3; 2686: LvItem.pszText = item1; 2687: 1.1.1.7 root 2688: SendMessageW (hList, LVM_SETITEMW, 0, (LPARAM)&LvItem); 1.1.1.5 root 2689: } 2690: } 2691: 2692: static BOOL PerformBenchmark(HWND hwndDlg) 2693: { 2694: LARGE_INTEGER performanceCountStart, performanceCountEnd; 2695: BYTE *lpTestBuffer; 1.1.1.8 root 2696: PCRYPTO_INFO ci = NULL; 1.1.1.7 root 2697: #if !(PKCS5_BENCHMARKS || HASH_FNC_BENCHMARKS) 1.1.1.8 root 2698: ci = crypto_open (); 2699: if (!ci) 2700: return FALSE; 1.1.1.7 root 2701: #endif 1.1.1.5 root 2702: 2703: if (QueryPerformanceFrequency (&benchmarkPerformanceFrequency) == 0) 2704: { 1.1.1.7 root 2705: MessageBoxW (hwndDlg, GetString ("ERR_PERF_COUNTER"), lpszTitle, ICON_HAND); 1.1.1.5 root 2706: return FALSE; 2707: } 2708: 2709: lpTestBuffer = malloc(benchmarkBufferSize - (benchmarkBufferSize % 16)); 2710: if (lpTestBuffer == NULL) 2711: { 1.1.1.7 root 2712: MessageBoxW (hwndDlg, GetString ("ERR_MEM_ALLOC"), lpszTitle, ICON_HAND); 1.1.1.5 root 2713: return FALSE; 2714: } 2715: VirtualLock (lpTestBuffer, benchmarkBufferSize - (benchmarkBufferSize % 16)); 2716: 1.1.1.11! root 2717: WaitCursor (); 1.1.1.5 root 2718: benchmarkTotalItems = 0; 1.1.1.7 root 2719: 1.1.1.11! root 2720: ! 2721: // CPU "warm up" (an attempt to prevent skewed results on systems where CPU frequency ! 2722: // gradually changes depending on CPU load). ! 2723: ci->ea = EAGetFirst(); ! 2724: if (!EAInit (ci->ea, ci->master_key, ci->ks)) ! 2725: { ! 2726: ci->mode = LRW; ! 2727: if (EAInitMode (ci)) ! 2728: { ! 2729: int i; ! 2730: ! 2731: for (i = 0; i < 2; i++) ! 2732: { ! 2733: EncryptBuffer ((unsigned __int32 *) lpTestBuffer, (unsigned __int64) benchmarkBufferSize, ci); ! 2734: DecryptBuffer ((unsigned __int32 *) lpTestBuffer, (unsigned __int64) benchmarkBufferSize, ci); ! 2735: } ! 2736: } ! 2737: } ! 2738: 1.1.1.7 root 2739: #if HASH_FNC_BENCHMARKS 2740: 2741: /* Measures the speed at which each of the hash algorithms processes the message to produce 2742: a single digest. 2743: 2744: The hash algorithm benchmarks are included here for development purposes only. Do not enable 2745: them when building a public release (the benchmark GUI strings wouldn't make sense). */ 2746: 2747: { 2748: BYTE *digest [MAX_DIGESTSIZE]; 2749: WHIRLPOOL_CTX wctx; 2750: RMD160_CTX rctx; 2751: sha1_ctx sctx; 2752: int hid; 2753: 2754: for (hid = 1; hid <= LAST_PRF_ID; hid++) 2755: { 2756: if (QueryPerformanceCounter (&performanceCountStart) == 0) 2757: goto counter_error; 2758: 2759: switch (hid) 2760: { 2761: case SHA1: 2762: sha1_begin (&sctx); 2763: sha1_hash (lpTestBuffer, benchmarkBufferSize, &sctx); 2764: sha1_end ((unsigned char *) digest, &sctx); 2765: break; 2766: 2767: case RIPEMD160: 2768: RMD160Init(&rctx); 2769: RMD160Update(&rctx, lpTestBuffer, benchmarkBufferSize); 2770: RMD160Final((unsigned char *) digest, &rctx); 2771: break; 2772: 2773: case WHIRLPOOL: 2774: WHIRLPOOL_init (&wctx); 2775: WHIRLPOOL_add (lpTestBuffer, benchmarkBufferSize * 8, &wctx); 2776: WHIRLPOOL_finalize (&wctx, (unsigned char *) digest); 2777: break; 2778: } 2779: 2780: if (QueryPerformanceCounter (&performanceCountEnd) == 0) 2781: goto counter_error; 2782: 2783: benchmarkTable[benchmarkTotalItems].encSpeed = performanceCountEnd.QuadPart - performanceCountStart.QuadPart; 2784: 2785: benchmarkTable[benchmarkTotalItems].decSpeed = benchmarkTable[benchmarkTotalItems].encSpeed; 2786: benchmarkTable[benchmarkTotalItems].id = hid; 2787: benchmarkTable[benchmarkTotalItems].meanBytesPerSec = ((unsigned __int64) (benchmarkBufferSize / ((float) benchmarkTable[benchmarkTotalItems].encSpeed / benchmarkPerformanceFrequency.QuadPart)) + (unsigned __int64) (benchmarkBufferSize / ((float) benchmarkTable[benchmarkTotalItems].decSpeed / benchmarkPerformanceFrequency.QuadPart))) / 2; 1.1.1.9 root 2788: sprintf (benchmarkTable[benchmarkTotalItems].name, "%s", HashGetName(hid)); 1.1.1.7 root 2789: 2790: benchmarkTotalItems++; 2791: } 2792: } 2793: 2794: #elif PKCS5_BENCHMARKS // #if HASH_FNC_BENCHMARKS 2795: 2796: /* Measures the time that it takes for the PKCS-5 routine to derive a header key using 2797: each of the implemented PRF algorithms. 2798: 2799: The PKCS-5 benchmarks are included here for development purposes only. Do not enable 2800: them when building a public release (the benchmark GUI strings wouldn't make sense). */ 2801: { 2802: int thid, i; 2803: char dk[HEADER_DISKKEY]; 2804: char *tmp_salt = {"\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA\xBB\xCC\xDD\xEE\xFF\x01\x23\x45\x67\x89\xAB\xCD\xEF\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA\xBB\xCC\xDD\xEE\xFF\x01\x23\x45\x67\x89\xAB\xCD\xEF\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA\xBB\xCC\xDD\xEE\xFF"}; 2805: 2806: for (thid = 1; thid <= LAST_PRF_ID; thid++) 2807: { 2808: if (QueryPerformanceCounter (&performanceCountStart) == 0) 2809: goto counter_error; 2810: 2811: for (i = 1; i <= 5; i++) 2812: { 2813: switch (thid) 2814: { 2815: case SHA1: 2816: /* PKCS-5 test with HMAC-SHA-1 used as the PRF */ 2817: derive_key_sha1 ("passphrase-1234567890", 21, tmp_salt, 64, get_pkcs5_iteration_count(thid), dk, HEADER_DISKKEY); 2818: break; 2819: 2820: case RIPEMD160: 2821: /* PKCS-5 test with HMAC-RIPEMD-160 used as the PRF */ 2822: derive_key_ripemd160 ("passphrase-1234567890", 21, tmp_salt, 64, get_pkcs5_iteration_count(thid), dk, HEADER_DISKKEY); 2823: break; 2824: 2825: case WHIRLPOOL: 2826: /* PKCS-5 test with HMAC-Whirlpool used as the PRF */ 2827: derive_key_whirlpool ("passphrase-1234567890", 21, tmp_salt, 64, get_pkcs5_iteration_count(thid), dk, HEADER_DISKKEY); 2828: break; 2829: } 2830: } 2831: 2832: if (QueryPerformanceCounter (&performanceCountEnd) == 0) 2833: goto counter_error; 2834: 2835: benchmarkTable[benchmarkTotalItems].encSpeed = performanceCountEnd.QuadPart - performanceCountStart.QuadPart; 2836: benchmarkTable[benchmarkTotalItems].id = thid; 2837: sprintf (benchmarkTable[benchmarkTotalItems].name, "%s", get_pkcs5_prf_name (thid)); 2838: 2839: benchmarkTotalItems++; 2840: } 2841: } 2842: 2843: #else // #elif PKCS5_BENCHMARKS 2844: 2845: /* Encryption algorithm benchmarks */ 1.1.1.8 root 2846: 2847: for (ci->ea = EAGetFirst(); ci->ea != 0; ci->ea = EAGetNext(ci->ea)) 1.1.1.5 root 2848: { 1.1.1.11! root 2849: if (!EAIsFormatEnabled (ci->ea)) 1.1.1.8 root 2850: continue; 2851: 2852: EAInit (ci->ea, ci->master_key, ci->ks); 2853: 2854: ci->mode = LRW; 2855: if (!EAInitMode (ci)) 2856: break; 2857: 1.1.1.5 root 2858: if (QueryPerformanceCounter (&performanceCountStart) == 0) 2859: goto counter_error; 2860: 1.1.1.8 root 2861: EncryptBuffer ((unsigned __int32 *) lpTestBuffer, (unsigned __int64) benchmarkBufferSize, ci); 1.1.1.5 root 2862: 2863: if (QueryPerformanceCounter (&performanceCountEnd) == 0) 2864: goto counter_error; 2865: 2866: benchmarkTable[benchmarkTotalItems].encSpeed = performanceCountEnd.QuadPart - performanceCountStart.QuadPart; 2867: 2868: if (QueryPerformanceCounter (&performanceCountStart) == 0) 2869: goto counter_error; 2870: 1.1.1.8 root 2871: DecryptBuffer ((unsigned __int32 *) lpTestBuffer, (unsigned __int64) benchmarkBufferSize, ci); 2872: 1.1.1.5 root 2873: if (QueryPerformanceCounter (&performanceCountEnd) == 0) 2874: goto counter_error; 2875: 2876: benchmarkTable[benchmarkTotalItems].decSpeed = performanceCountEnd.QuadPart - performanceCountStart.QuadPart; 1.1.1.8 root 2877: benchmarkTable[benchmarkTotalItems].id = ci->ea; 1.1.1.5 root 2878: benchmarkTable[benchmarkTotalItems].meanBytesPerSec = ((unsigned __int64) (benchmarkBufferSize / ((float) benchmarkTable[benchmarkTotalItems].encSpeed / benchmarkPerformanceFrequency.QuadPart)) + (unsigned __int64) (benchmarkBufferSize / ((float) benchmarkTable[benchmarkTotalItems].decSpeed / benchmarkPerformanceFrequency.QuadPart))) / 2; 1.1.1.8 root 2879: EAGetName (benchmarkTable[benchmarkTotalItems].name, ci->ea); 1.1.1.5 root 2880: 2881: benchmarkTotalItems++; 2882: } 2883: 1.1.1.7 root 2884: #endif // #elif PKCS5_BENCHMARKS (#else) 2885: 1.1.1.8 root 2886: if (ci) 2887: crypto_close (ci); 2888: 1.1.1.5 root 2889: VirtualUnlock (lpTestBuffer, benchmarkBufferSize - (benchmarkBufferSize % 16)); 2890: 2891: free(lpTestBuffer); 2892: 2893: benchmarkLastBufferSize = benchmarkBufferSize; 2894: 2895: DisplayBenchmarkResults(hwndDlg); 2896: 1.1.1.7 root 2897: EnableWindow (GetDlgItem (hwndDlg, IDC_PERFORM_BENCHMARK), TRUE); 1.1.1.5 root 2898: EnableWindow (GetDlgItem (hwndDlg, IDCLOSE), TRUE); 2899: 2900: NormalCursor (); 2901: return TRUE; 2902: 2903: counter_error: 1.1.1.8 root 2904: 2905: if (ci) 2906: crypto_close (ci); 1.1.1.5 root 2907: 2908: VirtualUnlock (lpTestBuffer, benchmarkBufferSize - (benchmarkBufferSize % 16)); 2909: 2910: free(lpTestBuffer); 2911: 2912: NormalCursor (); 2913: 1.1.1.7 root 2914: EnableWindow (GetDlgItem (hwndDlg, IDC_PERFORM_BENCHMARK), TRUE); 1.1.1.5 root 2915: EnableWindow (GetDlgItem (hwndDlg, IDCLOSE), TRUE); 2916: 1.1.1.7 root 2917: MessageBoxW (hwndDlg, GetString ("ERR_PERF_COUNTER"), lpszTitle, ICON_HAND); 1.1.1.5 root 2918: return FALSE; 2919: } 2920: 2921: 2922: BOOL WINAPI BenchmarkDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) 2923: { 2924: WORD lw = LOWORD (wParam); 2925: LPARAM nIndex; 2926: HWND hCboxSortMethod = GetDlgItem (hwndDlg, IDC_BENCHMARK_SORT_METHOD); 2927: HWND hCboxBufferSize = GetDlgItem (hwndDlg, IDC_BENCHMARK_BUFFER_SIZE); 2928: 2929: switch (msg) 2930: { 2931: case WM_INITDIALOG: 2932: { 1.1.1.7 root 2933: LVCOLUMNW LvCol; 2934: wchar_t s[128]; 1.1.1.5 root 2935: HWND hList = GetDlgItem (hwndDlg, IDC_RESULTS); 2936: 1.1.1.7 root 2937: LocalizeDialog (hwndDlg, "IDD_BENCHMARK_DLG"); 1.1.1.5 root 2938: 2939: benchmarkBufferSize = BENCHMARK_DEFAULT_BUF_SIZE; 2940: benchmarkSortMethod = BENCHMARK_SORT_BY_SPEED; 2941: 2942: SendMessage (hList,LVM_SETEXTENDEDLISTVIEWSTYLE,0, 1.1.1.7 root 2943: LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP|LVS_EX_LABELTIP 1.1.1.5 root 2944: ); 2945: 2946: memset (&LvCol,0,sizeof(LvCol)); 2947: LvCol.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_FMT; 1.1.1.7 root 2948: LvCol.pszText = GetString ("ALGORITHM"); 2949: LvCol.cx = 114; 1.1.1.5 root 2950: LvCol.fmt = LVCFMT_LEFT; 1.1.1.7 root 2951: SendMessage (hList,LVM_INSERTCOLUMNW,0,(LPARAM)&LvCol); 1.1.1.5 root 2952: 1.1.1.7 root 2953: LvCol.pszText = GetString ("ENCRYPTION"); 1.1.1.5 root 2954: LvCol.cx = 80; 2955: LvCol.fmt = LVCFMT_RIGHT; 1.1.1.7 root 2956: SendMessageW (hList,LVM_INSERTCOLUMNW,1,(LPARAM)&LvCol); 1.1.1.5 root 2957: 1.1.1.7 root 2958: LvCol.pszText = GetString ("DECRYPTION"); 1.1.1.5 root 2959: LvCol.cx = 80; 2960: LvCol.fmt = LVCFMT_RIGHT; 1.1.1.7 root 2961: SendMessageW (hList,LVM_INSERTCOLUMNW,2,(LPARAM)&LvCol); 1.1.1.5 root 2962: 1.1.1.7 root 2963: LvCol.pszText = GetString ("MEAN"); 1.1.1.5 root 2964: LvCol.cx = 80; 2965: LvCol.fmt = LVCFMT_RIGHT; 1.1.1.7 root 2966: SendMessageW (hList,LVM_INSERTCOLUMNW,3,(LPARAM)&LvCol); 1.1.1.5 root 2967: 2968: /* Combo boxes */ 2969: 2970: // Sort method 2971: 2972: SendMessage (hCboxSortMethod, CB_RESETCONTENT, 0, 0); 2973: 1.1.1.7 root 2974: nIndex = SendMessageW (hCboxSortMethod, CB_ADDSTRING, 0, (LPARAM) GetString ("ALPHABETICAL_CATEGORIZED")); 1.1.1.5 root 2975: SendMessage (hCboxSortMethod, CB_SETITEMDATA, nIndex, (LPARAM) 0); 2976: 1.1.1.7 root 2977: nIndex = SendMessageW (hCboxSortMethod, CB_ADDSTRING, 0, (LPARAM) GetString ("MEAN_SPEED")); 1.1.1.5 root 2978: SendMessage (hCboxSortMethod, CB_SETITEMDATA, nIndex, (LPARAM) 0); 2979: 2980: SendMessage (hCboxSortMethod, CB_SETCURSEL, 1, 0); // Default sort method 2981: 2982: // Buffer size 2983: 2984: SendMessage (hCboxBufferSize, CB_RESETCONTENT, 0, 0); 2985: 1.1.1.7 root 2986: swprintf (s, L"5 %s", GetString ("KB")); 2987: nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s); 1.1.1.5 root 2988: SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 5 * BYTES_PER_KB); 2989: 1.1.1.7 root 2990: swprintf (s, L"100 %s", GetString ("KB")); 2991: nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s); 1.1.1.5 root 2992: SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 100 * BYTES_PER_KB); 2993: 1.1.1.7 root 2994: swprintf (s, L"500 %s", GetString ("KB")); 2995: nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s); 1.1.1.5 root 2996: SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 500 * BYTES_PER_KB); 2997: 1.1.1.7 root 2998: swprintf (s, L"1 %s", GetString ("MB")); 2999: nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s); 1.1.1.5 root 3000: SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 1 * BYTES_PER_MB); 3001: 1.1.1.7 root 3002: swprintf (s, L"5 %s", GetString ("MB")); 3003: nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s); 1.1.1.5 root 3004: SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 5 * BYTES_PER_MB); 3005: 1.1.1.7 root 3006: swprintf (s, L"10 %s", GetString ("MB")); 3007: nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s); 1.1.1.5 root 3008: SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 10 * BYTES_PER_MB); 3009: 1.1.1.7 root 3010: swprintf (s, L"50 %s", GetString ("MB")); 3011: nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s); 1.1.1.5 root 3012: SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 50 * BYTES_PER_MB); 3013: 1.1.1.7 root 3014: swprintf (s, L"100 %s", GetString ("MB")); 3015: nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s); 1.1.1.5 root 3016: SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 100 * BYTES_PER_MB); 3017: 1.1.1.7 root 3018: swprintf (s, L"200 %s", GetString ("MB")); 3019: nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s); 1.1.1.5 root 3020: SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 200 * BYTES_PER_MB); 3021: 1.1.1.7 root 3022: swprintf (s, L"500 %s", GetString ("MB")); 3023: nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s); 1.1.1.5 root 3024: SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 500 * BYTES_PER_MB); 3025: 1.1.1.7 root 3026: swprintf (s, L"1 %s", GetString ("GB")); 3027: nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s); 1.1.1.5 root 3028: SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 1 * BYTES_PER_GB); 3029: 3030: SendMessage (hCboxBufferSize, CB_SETCURSEL, 3, 0); // Default size 3031: 3032: return 1; 3033: } 3034: break; 3035: 3036: case WM_COMMAND: 3037: case WM_NOTIFY: 3038: 3039: if (lw == IDC_BENCHMARK_SORT_METHOD) 3040: { 3041: nIndex = SendMessage (hCboxSortMethod, CB_GETCURSEL, 0, 0); 3042: if (nIndex != benchmarkSortMethod) 3043: { 3044: benchmarkSortMethod = nIndex; 3045: DisplayBenchmarkResults (hwndDlg); 3046: } 1.1.1.7 root 3047: return 1; 1.1.1.5 root 3048: } 3049: 1.1.1.7 root 3050: if (lw == IDC_PERFORM_BENCHMARK) 1.1.1.5 root 3051: { 3052: nIndex = SendMessage (hCboxBufferSize, CB_GETCURSEL, 0, 0); 3053: benchmarkBufferSize = SendMessage (hCboxBufferSize, CB_GETITEMDATA, nIndex, 0); 3054: 1.1.1.11! root 3055: if (PerformBenchmark (hwndDlg) == FALSE) 1.1.1.5 root 3056: { 3057: EndDialog (hwndDlg, IDCLOSE); 3058: } 1.1.1.7 root 3059: return 1; 1.1.1.5 root 3060: } 1.1.1.7 root 3061: if (lw == IDCLOSE || lw == IDCANCEL) 1.1.1.5 root 3062: { 3063: EndDialog (hwndDlg, IDCLOSE); 1.1.1.7 root 3064: return 1; 1.1.1.5 root 3065: } 3066: return 0; 3067: 3068: break; 3069: 3070: case WM_CLOSE: 3071: EndDialog (hwndDlg, IDCLOSE); 1.1.1.7 root 3072: return 1; 1.1.1.5 root 3073: 3074: break; 3075: 3076: } 3077: return 0; 3078: } 3079: 3080: 1.1.1.7 root 3081: 3082: /* Except in response to the WM_INITDIALOG message, the dialog box procedure 3083: should return nonzero if it processes the message, and zero if it does 3084: not. - see DialogProc */ 3085: BOOL WINAPI 3086: KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) 3087: { 3088: WORD lw = LOWORD (wParam); 3089: WORD hw = HIWORD (wParam); 3090: static unsigned char randPool [RNG_POOL_SIZE]; 3091: static unsigned char lastRandPool [RNG_POOL_SIZE]; 3092: static char outputDispBuffer [RNG_POOL_SIZE*3+34]; 1.1.1.10 root 3093: static BOOL bDisplayPoolContents = TRUE; 1.1.1.7 root 3094: int hash_algo = RandGetHashFunction(); 3095: int hid; 3096: 3097: if (lParam); /* remove warning */ 3098: 3099: switch (msg) 3100: { 3101: case WM_INITDIALOG: 1.1.1.5 root 3102: { 1.1.1.7 root 3103: HWND hComboBox = GetDlgItem (hwndDlg, IDC_PRF_ID); 3104: 3105: VirtualLock (randPool, sizeof(randPool)); 3106: VirtualLock (lastRandPool, sizeof(lastRandPool)); 3107: VirtualLock (outputDispBuffer, sizeof(outputDispBuffer)); 3108: 3109: LocalizeDialog (hwndDlg, "IDD_KEYFILE_GENERATOR_DLG"); 3110: 3111: SendMessage (hComboBox, CB_RESETCONTENT, 0, 0); 3112: for (hid = 1; hid <= LAST_PRF_ID; hid++) 3113: { 1.1.1.9 root 3114: AddComboPair (hComboBox, HashGetName(hid), hid); 1.1.1.7 root 3115: } 3116: SelectAlgo (hComboBox, &hash_algo); 3117: 3118: SetCheckBox (hwndDlg, IDC_DISPLAY_POOL_CONTENTS, bDisplayPoolContents); 3119: 3120: #ifndef VOLFORMAT 3121: if (Randinit ()) 3122: { 3123: Error ("INIT_RAND"); 3124: EndDialog (hwndDlg, IDCLOSE); 3125: } 3126: #endif 3127: SetTimer (hwndDlg, 0xfd, RANDOM_POOL_DISPLAY_REFRESH_INTERVAL, NULL); 3128: SendMessage (GetDlgItem (hwndDlg, IDC_POOL_CONTENTS), WM_SETFONT, (WPARAM) hFixedDigitFont, (LPARAM) TRUE); 3129: return 1; 3130: } 3131: 3132: case WM_TIMER: 3133: { 3134: char tmp[4]; 3135: int col, row; 3136: 3137: if (bDisplayPoolContents) 3138: { 3139: RandpeekBytes (randPool, sizeof (randPool)); 3140: 3141: if (memcmp (lastRandPool, randPool, sizeof(lastRandPool)) != 0) 3142: { 3143: outputDispBuffer[0] = 0; 3144: 3145: for (row = 0; row < 16; row++) 3146: { 3147: for (col = 0; col < 20; col++) 3148: { 3149: sprintf (tmp, "%02X ", randPool[row * 20 + col]); 3150: strcat (outputDispBuffer, tmp); 3151: } 3152: strcat (outputDispBuffer, "\n"); 3153: } 3154: SetWindowText (GetDlgItem (hwndDlg, IDC_POOL_CONTENTS), outputDispBuffer); 3155: 3156: memcpy (lastRandPool, randPool, sizeof(lastRandPool)); 3157: } 3158: } 3159: return 1; 3160: } 3161: 3162: case WM_COMMAND: 3163: 3164: if (lw == IDCLOSE || lw == IDCANCEL) 3165: { 3166: goto exit; 3167: } 3168: 3169: if (lw == IDC_PRF_ID && hw == CBN_SELCHANGE) 3170: { 3171: hid = (int) SendMessage (GetDlgItem (hwndDlg, IDC_PRF_ID), CB_GETCURSEL, 0, 0); 3172: hash_algo = (int) SendMessage (GetDlgItem (hwndDlg, IDC_PRF_ID), CB_GETITEMDATA, hid, 0); 3173: RandSetHashFunction (hash_algo); 3174: return 1; 3175: } 3176: 3177: if (lw == IDC_DISPLAY_POOL_CONTENTS) 3178: { 3179: if (!(bDisplayPoolContents = GetCheckBox (hwndDlg, IDC_DISPLAY_POOL_CONTENTS))) 3180: SetWindowText (GetDlgItem (hwndDlg, IDC_POOL_CONTENTS), ""); 3181: } 3182: 3183: if (lw == IDC_GENERATE_AND_SAVE_KEYFILE) 3184: { 3185: char szFileName [TC_MAX_PATH]; 3186: unsigned char keyfile [MAX_PASSWORD]; 3187: int fhKeyfile = -1; 3188: 3189: /* Select filename */ 1.1.1.10 root 3190: if (!BrowseFiles (hwndDlg, "OPEN_TITLE", szFileName, bHistory, TRUE)) 1.1.1.7 root 3191: return 1; 3192: 3193: /* Conceive the file */ 3194: if ((fhKeyfile = _open(szFileName, _O_CREAT|_O_TRUNC|_O_WRONLY|_O_BINARY, _S_IREAD|_S_IWRITE)) == -1) 3195: { 1.1.1.10 root 3196: handleWin32Error (hwndDlg); 1.1.1.7 root 3197: return 1; 3198: } 3199: 3200: /* Generate the keyfile */ 3201: WaitCursor(); 1.1.1.10 root 3202: if (!RandgetBytes (keyfile, sizeof(keyfile), TRUE)) 3203: { 3204: _close (fhKeyfile); 3205: DeleteFile (szFileName); 3206: NormalCursor(); 3207: return 1; 3208: } 1.1.1.7 root 3209: NormalCursor(); 3210: 3211: /* Write the keyfile */ 3212: if (_write (fhKeyfile, keyfile, sizeof(keyfile)) == -1) 3213: handleWin32Error (hwndDlg); 3214: else 3215: Info("KEYFILE_CREATED"); 3216: 3217: memset (keyfile, 0, sizeof(keyfile)); 3218: _close (fhKeyfile); 3219: return 1; 3220: } 3221: return 0; 3222: 3223: case WM_CLOSE: 3224: { 3225: char tmp[RNG_POOL_SIZE+1]; 3226: exit: 3227: KillTimer (hwndDlg, 0xfd); 3228: 3229: #ifndef VOLFORMAT 3230: Randfree (); 3231: #endif 3232: /* Cleanup */ 3233: 3234: memset (randPool, 0, sizeof(randPool)); 3235: memset (lastRandPool, 0, sizeof(lastRandPool)); 3236: memset (outputDispBuffer, 0, sizeof(outputDispBuffer)); 3237: 3238: // Attempt to wipe the pool contents in the GUI text area 3239: memset (tmp, 'X', RNG_POOL_SIZE); 3240: tmp [RNG_POOL_SIZE] = 0; 3241: SetWindowText (GetDlgItem (hwndDlg, IDC_POOL_CONTENTS), tmp); 3242: 3243: EndDialog (hwndDlg, IDCLOSE); 3244: return 1; 1.1.1.5 root 3245: } 3246: } 1.1.1.7 root 3247: return 0; 1.1.1.5 root 3248: } 3249: 3250: 1.1.1.7 root 3251: 3252: /* Except in response to the WM_INITDIALOG message, the dialog box procedure 3253: should return nonzero if it processes the message, and zero if it does 3254: not. - see DialogProc */ 3255: BOOL CALLBACK 3256: CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) 1.1.1.5 root 3257: { 1.1.1.8 root 3258: static int idTestCipher = -1; /* Currently selected cipher for the test vector facility (none = -1). */ 3259: static BOOL bLRWTestEnabled = TRUE; 3260: 3261: PCRYPTO_INFO ci; 1.1.1.7 root 3262: WORD lw = LOWORD (wParam); 3263: WORD hw = HIWORD (wParam); 3264: 3265: if (lParam); /* Remove unused parameter warning */ 3266: 3267: switch (uMsg) 1.1.1.5 root 3268: { 1.1.1.7 root 3269: case WM_INITDIALOG: 3270: { 3271: int ea; 3272: char buf[100]; 3273: 3274: LocalizeDialog (hwndDlg, "IDD_CIPHER_TEST_DLG"); 3275: 3276: SendMessage(GetDlgItem(hwndDlg, IDC_TESTS_MESSAGE), WM_SETFONT, (WPARAM)hBoldFont, MAKELPARAM(TRUE,0)); 3277: SendMessage(GetDlgItem(hwndDlg, IDC_KEY), EM_LIMITTEXT, 128,0); 3278: SendMessage(GetDlgItem(hwndDlg, IDC_KEY), WM_SETFONT, (WPARAM)hFixedDigitFont, MAKELPARAM(1,0)); 3279: SendMessage(GetDlgItem(hwndDlg, IDC_PLAINTEXT), EM_LIMITTEXT,128,0); 3280: SendMessage(GetDlgItem(hwndDlg, IDC_PLAINTEXT), WM_SETFONT, (WPARAM)hFixedDigitFont, MAKELPARAM(1,0)); 3281: SendMessage(GetDlgItem(hwndDlg, IDC_CIPHERTEXT), EM_LIMITTEXT,128,0); 3282: SendMessage(GetDlgItem(hwndDlg, IDC_CIPHERTEXT), WM_SETFONT, (WPARAM)hFixedDigitFont, MAKELPARAM(1,0)); 1.1.1.8 root 3283: SendMessage(GetDlgItem(hwndDlg, IDC_LRW_KEY), EM_LIMITTEXT,128,0); 3284: SendMessage(GetDlgItem(hwndDlg, IDC_LRW_KEY), WM_SETFONT, (WPARAM)hFixedDigitFont, MAKELPARAM(1,0)); 3285: SendMessage(GetDlgItem(hwndDlg, IDC_LRW_BLOCK_INDEX), EM_LIMITTEXT,128,0); 3286: SendMessage(GetDlgItem(hwndDlg, IDC_LRW_BLOCK_INDEX), WM_SETFONT, (WPARAM)hFixedDigitFont, MAKELPARAM(1,0)); 3287: SetCheckBox (hwndDlg, IDC_LRW_MODE_ENABLED, bLRWTestEnabled); 1.1.1.9 root 3288: SetCheckBox (hwndDlg, IDC_LRW_INDEX_LSB, TRUE); 1.1.1.8 root 3289: EnableWindow (GetDlgItem (hwndDlg, IDC_LRW_KEY), bLRWTestEnabled); 3290: EnableWindow (GetDlgItem (hwndDlg, IDT_LRW_KEY), bLRWTestEnabled); 3291: EnableWindow (GetDlgItem (hwndDlg, IDC_LRW_BLOCK_INDEX), bLRWTestEnabled); 3292: EnableWindow (GetDlgItem (hwndDlg, IDT_LRW_BLOCK_INDEX), bLRWTestEnabled); 1.1.1.7 root 3293: 3294: if (idTestCipher == -1) 3295: idTestCipher = (int) lParam; 3296: 3297: SendMessage (GetDlgItem (hwndDlg, IDC_CIPHER), CB_RESETCONTENT, 0, 0); 3298: for (ea = EAGetFirst (); ea != 0; ea = EAGetNext (ea)) 3299: { 1.1.1.11! root 3300: if (EAGetCipherCount (ea) == 1 && EAIsFormatEnabled (ea)) 1.1.1.7 root 3301: AddComboPair (GetDlgItem (hwndDlg, IDC_CIPHER), EAGetName (buf, ea), ea); 3302: } 3303: 3304: ResetCipherTest(hwndDlg, idTestCipher); 3305: 3306: SelectAlgo (GetDlgItem (hwndDlg, IDC_CIPHER), &idTestCipher); 3307: 3308: return 1; 3309: } 3310: 3311: case WM_COMMAND: 3312: 3313: if (hw == CBN_SELCHANGE && lw == IDC_CIPHER) 3314: { 3315: idTestCipher = (int) SendMessage (GetDlgItem (hwndDlg, IDC_CIPHER), CB_GETITEMDATA, SendMessage (GetDlgItem (hwndDlg, IDC_CIPHER), CB_GETCURSEL, 0, 0), 0); 3316: ResetCipherTest(hwndDlg, idTestCipher); 3317: SendMessage (hwndDlg, WM_INITDIALOG, 0, 0); 3318: return 1; 3319: } 3320: 3321: if (hw == CBN_SELCHANGE && lw == IDC_KEY_SIZE) 3322: { 3323: // NOP 3324: return 1; 3325: } 3326: 3327: if (lw == IDC_RESET) 3328: { 3329: ResetCipherTest(hwndDlg, idTestCipher); 3330: 3331: return 1; 3332: } 3333: 3334: if (lw == IDC_AUTO) 3335: { 3336: if (!AutoTestAlgorithms()) 3337: { 3338: ShowWindow(GetDlgItem(hwndDlg, IDC_TESTS_MESSAGE), SW_SHOWNORMAL); 3339: SetWindowTextW(GetDlgItem(hwndDlg, IDC_TESTS_MESSAGE), GetString ("TESTS_FAILED")); 3340: } 3341: else 3342: { 3343: ShowWindow(GetDlgItem(hwndDlg, IDC_TESTS_MESSAGE), SW_SHOWNORMAL); 3344: SetWindowTextW(GetDlgItem(hwndDlg, IDC_TESTS_MESSAGE), GetString ("TESTS_PASSED")); 3345: ShowWindow(GetDlgItem(hwndDlg, IDC_REDTICK), SW_SHOWNORMAL); 3346: } 3347: 3348: return 1; 3349: 3350: } 3351: 1.1.1.8 root 3352: if (lw == IDC_LRW_MODE_ENABLED) 3353: { 3354: bLRWTestEnabled = GetCheckBox (hwndDlg, IDC_LRW_MODE_ENABLED); 3355: EnableWindow (GetDlgItem (hwndDlg, IDC_LRW_KEY), bLRWTestEnabled); 3356: EnableWindow (GetDlgItem (hwndDlg, IDT_LRW_KEY), bLRWTestEnabled); 3357: EnableWindow (GetDlgItem (hwndDlg, IDT_LRW_BLOCK_INDEX), bLRWTestEnabled); 3358: EnableWindow (GetDlgItem (hwndDlg, IDC_LRW_BLOCK_INDEX), bLRWTestEnabled); 1.1.1.9 root 3359: EnableWindow (GetDlgItem (hwndDlg, IDC_LRW_INDEX_LSB), bLRWTestEnabled); 3360: if (bLRWTestEnabled) 3361: SendMessage(GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_SETCURSEL, 0,0); 1.1.1.8 root 3362: } 3363: 1.1.1.7 root 3364: if (lw == IDOK || lw == IDC_ENCRYPT || lw == IDC_DECRYPT) 3365: { 1.1.1.8 root 3366: char key[128], inputtext[128], lrwKey[16], lrwIndex[16], szTmp[128]; 1.1.1.7 root 3367: int ks, pt, n; 3368: BOOL bEncrypt; 3369: 3370: ShowWindow(GetDlgItem(hwndDlg, IDC_TESTS_MESSAGE), SW_HIDE); 3371: ShowWindow(GetDlgItem(hwndDlg, IDC_REDTICK), SW_HIDE); 3372: 3373: ks = (int) SendMessage(GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_GETCURSEL, 0,0); 3374: ks = (int) SendMessage(GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_GETITEMDATA, ks,0); 3375: pt = (int) SendMessage(GetDlgItem(hwndDlg, IDC_PLAINTEXT_SIZE), CB_GETITEMDATA, 0,0); 3376: 3377: bEncrypt = lw == IDC_ENCRYPT; 3378: 3379: memset(key,0,sizeof(key)); 3380: memset(szTmp,0,sizeof(szTmp)); 3381: n = GetWindowText(GetDlgItem(hwndDlg, IDC_KEY), szTmp, sizeof(szTmp)); 3382: if (n != ks * 2) 3383: { 3384: MessageBoxW (hwndDlg, GetString ("TEST_KEY_SIZE"), lpszTitle, ICON_HAND); 3385: return 1; 3386: } 3387: 3388: for (n = 0; n < ks; n ++) 3389: { 3390: char szTmp2[3], *ptr; 3391: long x; 3392: 3393: szTmp2[2] = 0; 3394: szTmp2[0] = szTmp[n * 2]; 3395: szTmp2[1] = szTmp[n * 2 + 1]; 3396: 3397: x = strtol(szTmp2, &ptr, 16); 3398: 3399: key[n] = (char) x; 3400: } 3401: 1.1.1.8 root 3402: memset(inputtext, 0, sizeof(inputtext)); 3403: memset(lrwKey, 0, sizeof(lrwKey)); 3404: memset(lrwIndex, 0, sizeof(lrwIndex)); 3405: memset(szTmp, 0, sizeof(szTmp)); 1.1.1.7 root 3406: 3407: if (bEncrypt) 3408: { 3409: n = GetWindowText(GetDlgItem(hwndDlg, IDC_PLAINTEXT), szTmp, sizeof(szTmp)); 3410: } 3411: else 3412: { 3413: n = GetWindowText(GetDlgItem(hwndDlg, IDC_CIPHERTEXT), szTmp, sizeof(szTmp)); 3414: } 3415: 3416: if (n != pt * 2) 3417: { 3418: if (bEncrypt) 3419: { 3420: MessageBoxW (hwndDlg, GetString ("TEST_PLAINTEXT_SIZE"), lpszTitle, ICON_HAND); 3421: return 1; 3422: } 3423: else 3424: { 3425: MessageBoxW (hwndDlg, GetString ("TEST_CIPHERTEXT_SIZE"), lpszTitle, ICON_HAND); 3426: return 1; 3427: } 3428: } 1.1.1.8 root 3429: 1.1.1.7 root 3430: for (n = 0; n < pt; n ++) 3431: { 3432: char szTmp2[3], *ptr; 3433: long x; 3434: 3435: szTmp2[2] = 0; 3436: szTmp2[0] = szTmp[n * 2]; 3437: szTmp2[1] = szTmp[n * 2 + 1]; 3438: 3439: x = strtol(szTmp2, &ptr, 16); 3440: 3441: inputtext[n] = (char) x; 3442: } 3443: 1.1.1.8 root 3444: // LRW 3445: if (bLRWTestEnabled) 1.1.1.7 root 3446: { 1.1.1.8 root 3447: if (GetWindowText(GetDlgItem(hwndDlg, IDC_LRW_KEY), szTmp, sizeof(szTmp)) != pt * 2) 3448: { 3449: Warning ("TEST_INCORRECT_LRW_KEY_SIZE"); 3450: return 1; 3451: } 1.1.1.7 root 3452: 1.1.1.8 root 3453: // LRW key 1.1.1.7 root 3454: 1.1.1.8 root 3455: for (n = 0; n < pt; n ++) 1.1.1.7 root 3456: { 1.1.1.8 root 3457: char szTmp2[3], *ptr; 3458: long x; 3459: 3460: szTmp2[2] = 0; 3461: szTmp2[0] = szTmp[n * 2]; 3462: szTmp2[1] = szTmp[n * 2 + 1]; 3463: 3464: x = strtol(szTmp2, &ptr, 16); 3465: 3466: lrwKey[n] = (char) x; 1.1.1.7 root 3467: } 3468: 1.1.1.8 root 3469: // LRW block index 1.1.1.7 root 3470: 1.1.1.8 root 3471: if (GetWindowText(GetDlgItem(hwndDlg, IDC_LRW_BLOCK_INDEX), szTmp, sizeof(szTmp)) != pt * 2) 1.1.1.7 root 3472: { 1.1.1.8 root 3473: Warning ("TEST_INCORRECT_LRW_INDEX_SIZE"); 3474: return 1; 1.1.1.7 root 3475: } 1.1.1.8 root 3476: for (n = 0; n < pt; n ++) 1.1.1.7 root 3477: { 1.1.1.8 root 3478: char szTmp2[3], *ptr; 3479: long x; 3480: 3481: szTmp2[2] = 0; 3482: szTmp2[0] = szTmp[n * 2]; 3483: szTmp2[1] = szTmp[n * 2 + 1]; 3484: 3485: x = strtol(szTmp2, &ptr, 16); 3486: 3487: lrwIndex[n] = (char) x; 1.1.1.7 root 3488: } 1.1.1.9 root 3489: 3490: if (GetCheckBox (hwndDlg, IDC_LRW_INDEX_LSB)) 3491: { 3492: if (pt == 8) 3493: MirrorBits64 (lrwIndex); 3494: else if (pt == 16) 3495: MirrorBits128 (lrwIndex); 3496: } 1.1.1.8 root 3497: } 1.1.1.7 root 3498: 1.1.1.8 root 3499: 3500: /* Perform the actual tests */ 3501: 3502: if (ks != CB_ERR && pt != CB_ERR) 3503: { 3504: char tmp[128]; 1.1.1.9 root 3505: int tmpRetVal; 1.1.1.8 root 3506: 3507: /* Copy the plain/ciphertext */ 3508: memcpy(tmp,inputtext, pt); 3509: 3510: if (bLRWTestEnabled) 1.1.1.7 root 3511: { 1.1.1.8 root 3512: /* LRW mode */ 3513: 3514: ci = crypto_open (); 3515: if (!ci) 3516: return 1; 3517: 3518: ci->mode = LRW; 3519: ci->ea = idTestCipher; 3520: 1.1.1.9 root 3521: if (idTestCipher == BLOWFISH) 3522: { 3523: /* Convert to little-endian, this is needed here and not in 3524: above auto-tests because BF_ecb_encrypt above correctly converts 3525: from big to little endian, and EncipherBlock does not! */ 3526: LongReverse((void*)tmp, pt); 3527: } 3528: 3529: if ((tmpRetVal = EAInit (ci->ea, key, ci->ks)) != 0) 3530: { 3531: handleError (hwndDlg, tmpRetVal); 1.1.1.8 root 3532: return 1; 1.1.1.9 root 3533: } 1.1.1.8 root 3534: 3535: memcpy (&ci->iv, lrwKey, sizeof (lrwKey)); 3536: if (!EAInitMode (ci)) 3537: return 1; 3538: 3539: if (pt == 16) 3540: { 3541: if (((unsigned __int64 *)lrwIndex)[0]) 3542: { 3543: Error ("TEST_LRW_INDEX_OVERRUN"); 3544: return 1; 3545: } 3546: 3547: if (bEncrypt) 3548: EncryptBufferLRW128 (tmp, pt, BE64(((unsigned __int64 *)lrwIndex)[1]), ci); 3549: else 3550: DecryptBufferLRW128 (tmp, pt, BE64(((unsigned __int64 *)lrwIndex)[1]), ci); 3551: } 3552: else if (pt == 8) 3553: { 3554: if (bEncrypt) 3555: EncryptBufferLRW64 (tmp, pt, BE64(((unsigned __int64 *)lrwIndex)[0]), ci); 3556: else 3557: DecryptBufferLRW64 (tmp, pt, BE64(((unsigned __int64 *)lrwIndex)[0]), ci); 3558: } 1.1.1.9 root 3559: 3560: if (idTestCipher == BLOWFISH) 3561: { 3562: /* Convert to little-endian, this is needed here and not in 3563: above auto-tests because BF_ecb_encrypt above correctly converts 3564: from big to little endian, and EncipherBlock does not! */ 3565: LongReverse((void*)tmp, pt); 3566: } 3567: 1.1.1.8 root 3568: crypto_close (ci); 1.1.1.7 root 3569: } 1.1.1.8 root 3570: else 3571: { 3572: if (idTestCipher == BLOWFISH) 3573: { 3574: /* Convert to little-endian, this is needed here and not in 3575: above auto-tests because BF_ecb_encrypt above correctly converts 3576: from big to little endian, and EncipherBlock does not! */ 3577: LongReverse((void*)tmp, pt); 3578: } 3579: 3580: CipherInit2(idTestCipher, key, ks_tmp, ks); 3581: 3582: if (bEncrypt) 3583: { 3584: EncipherBlock(idTestCipher, tmp, ks_tmp); 3585: } 3586: else 3587: { 3588: DecipherBlock(idTestCipher, tmp, ks_tmp); 3589: } 1.1.1.7 root 3590: 1.1.1.8 root 3591: if (idTestCipher == BLOWFISH) 3592: { 3593: /* Convert back to big-endian */ 3594: LongReverse((void*)tmp, pt); 3595: } 3596: } 1.1.1.7 root 3597: *szTmp = 0; 3598: 1.1.1.8 root 3599: for (n = 0; n < pt; n ++) 1.1.1.7 root 3600: { 3601: char szTmp2[3]; 3602: sprintf(szTmp2, "%02x", (int)((unsigned char)tmp[n])); 3603: strcat(szTmp, szTmp2); 3604: } 3605: 3606: if (bEncrypt) 3607: SetWindowText(GetDlgItem(hwndDlg,IDC_CIPHERTEXT), szTmp); 3608: else 3609: SetWindowText(GetDlgItem(hwndDlg,IDC_PLAINTEXT), szTmp); 3610: } 1.1.1.8 root 3611: 1.1.1.7 root 3612: return 1; 3613: } 3614: 3615: if (lw == IDCLOSE || lw == IDCANCEL) 3616: { 3617: idTestCipher = -1; 3618: EndDialog (hwndDlg, 0); 3619: return 1; 3620: } 3621: break; 3622: 3623: case WM_CLOSE: 3624: idTestCipher = -1; 3625: EndDialog (hwndDlg, 0); 3626: return 1; 1.1.1.5 root 3627: } 1.1.1.7 root 3628: 3629: return 0; 3630: } 3631: 3632: void 3633: ResetCipherTest(HWND hwndDlg, int idTestCipher) 3634: { 3635: int ndx; 3636: 3637: ShowWindow(GetDlgItem(hwndDlg, IDC_TESTS_MESSAGE), SW_HIDE); 3638: ShowWindow(GetDlgItem(hwndDlg, IDC_REDTICK), SW_HIDE); 3639: 1.1.1.11! root 3640: EnableWindow(GetDlgItem(hwndDlg,IDC_KEY_SIZE), FALSE); 1.1.1.7 root 3641: 3642: /* Setup the keysize and plaintext sizes for the selected cipher */ 3643: 3644: SendMessage (GetDlgItem(hwndDlg, IDC_PLAINTEXT_SIZE), CB_RESETCONTENT, 0,0); 3645: SendMessage (GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_RESETCONTENT, 0,0); 3646: 3647: ndx = SendMessage (GetDlgItem(hwndDlg, IDC_PLAINTEXT_SIZE), CB_ADDSTRING, 0,(LPARAM) "64"); 3648: SendMessage(GetDlgItem(hwndDlg, IDC_PLAINTEXT_SIZE), CB_SETITEMDATA, ndx,(LPARAM) 8); 3649: SendMessage(GetDlgItem(hwndDlg, IDC_PLAINTEXT_SIZE), CB_SETCURSEL, ndx,0); 3650: 1.1.1.8 root 3651: SetWindowText(GetDlgItem(hwndDlg, IDC_LRW_KEY), "0000000000000000"); 3652: SetWindowText(GetDlgItem(hwndDlg, IDC_LRW_BLOCK_INDEX), "0000000000000000"); 3653: 1.1.1.7 root 3654: if (idTestCipher == BLOWFISH) 3655: { 3656: ndx = SendMessage (GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_ADDSTRING, 0,(LPARAM) "448"); 3657: SendMessage(GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_SETITEMDATA, ndx,(LPARAM) 56); 3658: ndx = SendMessage (GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_ADDSTRING, 0,(LPARAM) "256"); 3659: SendMessage(GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_SETITEMDATA, ndx,(LPARAM) 32); 3660: ndx = SendMessage (GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_ADDSTRING, 0,(LPARAM) "128"); 3661: SendMessage(GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_SETITEMDATA, ndx,(LPARAM) 16); 3662: ndx = SendMessage (GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_ADDSTRING, 0,(LPARAM) "64"); 3663: SendMessage(GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_SETITEMDATA, ndx,(LPARAM) 8); 3664: SendMessage(GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_SETCURSEL, 0,0); 3665: SetWindowText(GetDlgItem(hwndDlg, IDC_KEY), "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"); 3666: } 3667: 3668: 3669: if (idTestCipher == CAST) 3670: { 3671: ndx = SendMessage (GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_ADDSTRING, 0,(LPARAM) "128"); 3672: SendMessage(GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_SETITEMDATA, ndx,(LPARAM) 16); 3673: SendMessage(GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_SETCURSEL, ndx,0); 3674: SetWindowText(GetDlgItem(hwndDlg, IDC_KEY), "00000000000000000000000000000000"); 3675: } 3676: 3677: if (idTestCipher == TRIPLEDES) 3678: { 3679: ndx = SendMessage (GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_ADDSTRING, 0,(LPARAM) "168"); 3680: SendMessage(GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_SETITEMDATA, ndx,(LPARAM) 24); 3681: SendMessage(GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_SETCURSEL, ndx,0); 3682: SetWindowText(GetDlgItem(hwndDlg, IDC_KEY), "000000000000000000000000000000000000000000000000"); 3683: } 3684: 3685: if (idTestCipher == DES56) 3686: { 3687: ndx = SendMessage (GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_ADDSTRING, 0,(LPARAM) "56"); 3688: SendMessage(GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_SETITEMDATA, ndx,(LPARAM) 7); 3689: SendMessage(GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_SETCURSEL, 0,0); 3690: SetWindowText(GetDlgItem(hwndDlg, IDC_KEY), "0000000000000000"); 3691: } 3692: 3693: SetWindowText(GetDlgItem(hwndDlg, IDC_PLAINTEXT), "0000000000000000"); 3694: SetWindowText(GetDlgItem(hwndDlg, IDC_CIPHERTEXT), "0000000000000000"); 3695: 3696: if (idTestCipher == AES || idTestCipher == SERPENT || idTestCipher == TWOFISH) 3697: { 3698: ndx = SendMessage (GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_ADDSTRING, 0,(LPARAM) "256"); 3699: SendMessage(GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_SETITEMDATA, ndx,(LPARAM) 32); 3700: SendMessage(GetDlgItem(hwndDlg, IDC_KEY_SIZE), CB_SETCURSEL, ndx,0); 3701: 3702: SendMessage (GetDlgItem(hwndDlg, IDC_PLAINTEXT_SIZE), CB_RESETCONTENT, 0,0); 3703: ndx = SendMessage (GetDlgItem(hwndDlg, IDC_PLAINTEXT_SIZE), CB_ADDSTRING, 0,(LPARAM) "128"); 3704: SendMessage(GetDlgItem(hwndDlg, IDC_PLAINTEXT_SIZE), CB_SETITEMDATA, ndx,(LPARAM) 16); 3705: SendMessage(GetDlgItem(hwndDlg, IDC_PLAINTEXT_SIZE), CB_SETCURSEL, ndx,0); 3706: 3707: SetWindowText(GetDlgItem(hwndDlg, IDC_KEY), "0000000000000000000000000000000000000000000000000000000000000000"); 3708: SetWindowText(GetDlgItem(hwndDlg, IDC_PLAINTEXT), "00000000000000000000000000000000"); 3709: SetWindowText(GetDlgItem(hwndDlg, IDC_CIPHERTEXT), "00000000000000000000000000000000"); 1.1.1.8 root 3710: 3711: SetWindowText(GetDlgItem(hwndDlg, IDC_LRW_KEY), "00000000000000000000000000000000"); 3712: SetWindowText(GetDlgItem(hwndDlg, IDC_LRW_BLOCK_INDEX), "00000000000000000000000000000000"); 1.1.1.7 root 3713: } 3714: } 3715: 3716: #endif // #ifndef SETUP 3717: 3718: 1.1.1.11! root 3719: BOOL CALLBACK MultiChoiceDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) ! 3720: { ! 3721: char **pStr = (char **) lParam; ! 3722: char **pStrOrig = pStr; ! 3723: wchar_t **pwStr = (wchar_t **) lParam; ! 3724: wchar_t **pwStrOrig = pwStr; ! 3725: int nChoiceIDs [MAX_MULTI_CHOICES+1] = { IDC_MULTI_CHOICE_MSG, IDC_CHOICE1, IDC_CHOICE2, IDC_CHOICE3, ! 3726: IDC_CHOICE4, IDC_CHOICE5, IDC_CHOICE6, IDC_CHOICE7, IDC_CHOICE8, IDC_CHOICE9, IDC_CHOICE10 }; ! 3727: int nBaseButtonWidth = 0; ! 3728: int nBaseButtonHeight = 0; ! 3729: int nActiveChoices = -1; ! 3730: int nStr = 0; ! 3731: int vertSubOffset, horizSubOffset, vertMsgHeightOffset; ! 3732: int vertOffset = 0; ! 3733: int nLongestButtonCaptionWidth = 6; ! 3734: int nTextGfxLineHeight = 0; ! 3735: RECT rec, wrec, wtrec, trec; ! 3736: BOOL bResolve; ! 3737: ! 3738: WORD lw = LOWORD (wParam); ! 3739: ! 3740: switch (uMsg) ! 3741: { ! 3742: case WM_INITDIALOG: ! 3743: { ! 3744: LocalizeDialog (hwndDlg, NULL); ! 3745: ! 3746: SetWindowPos (hwndDlg, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); ! 3747: SetWindowPos (hwndDlg, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); ! 3748: ! 3749: bResolve = (*pStr == NULL); ! 3750: ! 3751: // Process the strings ! 3752: pStr++; ! 3753: pwStr++; ! 3754: ! 3755: do ! 3756: { ! 3757: if (*pStr != 0) ! 3758: { ! 3759: SetWindowTextW (GetDlgItem(hwndDlg, nChoiceIDs[nStr]), bResolve ? GetString(*pStr) : *pwStr); ! 3760: ! 3761: if (nStr > 0) ! 3762: { ! 3763: nLongestButtonCaptionWidth = max ( ! 3764: GetTextGfxWidth (GetDlgItem(hwndDlg, IDC_CHOICE1), ! 3765: bResolve ? GetString(*pStr) : *pwStr, ! 3766: hUserFont), ! 3767: nLongestButtonCaptionWidth); ! 3768: } ! 3769: ! 3770: nActiveChoices++; ! 3771: pStr++; ! 3772: pwStr++; ! 3773: } ! 3774: else ! 3775: { ! 3776: ShowWindow(GetDlgItem(hwndDlg, nChoiceIDs[nStr]), SW_HIDE); ! 3777: } ! 3778: nStr++; ! 3779: ! 3780: } while (nStr < MAX_MULTI_CHOICES+1); ! 3781: ! 3782: // Get the window coords ! 3783: GetWindowRect(hwndDlg, &wrec); ! 3784: ! 3785: // Get the base button size ! 3786: GetClientRect(GetDlgItem(hwndDlg, IDC_CHOICE1), &rec); ! 3787: nBaseButtonWidth = rec.right + 2; ! 3788: nBaseButtonHeight = rec.bottom + 2; ! 3789: ! 3790: // Increase in width based on the gfx length of the widest button caption ! 3791: horizSubOffset = min (500, max (0, nLongestButtonCaptionWidth + 50 - nBaseButtonWidth)); ! 3792: ! 3793: // Vertical "title bar" offset ! 3794: GetClientRect(hwndDlg, &wtrec); ! 3795: vertOffset = wrec.bottom - wrec.top - wtrec.bottom - GetSystemMetrics(SM_CYFIXEDFRAME); ! 3796: ! 3797: // Height/width of the message text ! 3798: GetClientRect(GetDlgItem(hwndDlg, IDC_MULTI_CHOICE_MSG), &trec); ! 3799: ! 3800: nTextGfxLineHeight = GetTextGfxHeight (GetDlgItem(hwndDlg, IDC_MULTI_CHOICE_MSG), ! 3801: bResolve ? GetString(*(pStrOrig+1)) : *(pwStrOrig+1), ! 3802: hUserFont); ! 3803: ! 3804: vertMsgHeightOffset = ((GetTextGfxWidth (GetDlgItem(hwndDlg, IDC_MULTI_CHOICE_MSG), ! 3805: bResolve ? GetString(*(pStrOrig+1)) : *(pwStrOrig+1), ! 3806: hUserFont) / (trec.right + horizSubOffset) + 1) * nTextGfxLineHeight) - trec.bottom; ! 3807: ! 3808: vertMsgHeightOffset = min (350, vertMsgHeightOffset + nTextGfxLineHeight + (trec.bottom + vertMsgHeightOffset) / 10); ! 3809: ! 3810: // Reduction in height according to the number of shown buttons ! 3811: vertSubOffset = ((MAX_MULTI_CHOICES - nActiveChoices) * nBaseButtonHeight); ! 3812: ! 3813: if (horizSubOffset > 0 ! 3814: || vertMsgHeightOffset > 0 ! 3815: || vertOffset > 0) ! 3816: { ! 3817: // Resize/move each button if necessary ! 3818: for (nStr = 1; nStr < MAX_MULTI_CHOICES+1; nStr++) ! 3819: { ! 3820: GetWindowRect(GetDlgItem(hwndDlg, nChoiceIDs[nStr]), &rec); ! 3821: ! 3822: MoveWindow (GetDlgItem(hwndDlg, nChoiceIDs[nStr]), ! 3823: rec.left - wrec.left - GetSystemMetrics(SM_CXFIXEDFRAME), ! 3824: rec.top - wrec.top - vertOffset + vertMsgHeightOffset, ! 3825: nBaseButtonWidth + horizSubOffset, ! 3826: nBaseButtonHeight, ! 3827: TRUE); ! 3828: } ! 3829: ! 3830: // Resize/move the remaining GUI elements ! 3831: GetWindowRect(GetDlgItem(hwndDlg, IDC_MULTI_CHOICE_MSG), &rec); ! 3832: GetClientRect(GetDlgItem(hwndDlg, IDC_MULTI_CHOICE_MSG), &trec); ! 3833: MoveWindow (GetDlgItem(hwndDlg, IDC_MULTI_CHOICE_MSG), ! 3834: rec.left - wrec.left - GetSystemMetrics(SM_CXFIXEDFRAME), ! 3835: rec.top - wrec.top - vertOffset, ! 3836: trec.right + 2 + horizSubOffset, ! 3837: trec.bottom + 2 + vertMsgHeightOffset, ! 3838: TRUE); ! 3839: ! 3840: GetWindowRect(GetDlgItem(hwndDlg, IDC_MC_DLG_HR1), &rec); ! 3841: GetClientRect(GetDlgItem(hwndDlg, IDC_MC_DLG_HR1), &trec); ! 3842: MoveWindow (GetDlgItem(hwndDlg, IDC_MC_DLG_HR1), ! 3843: rec.left - wrec.left - GetSystemMetrics(SM_CXFIXEDFRAME), ! 3844: rec.top - wrec.top - vertOffset, ! 3845: trec.right + 2 + horizSubOffset, ! 3846: trec.bottom + 2, ! 3847: TRUE); ! 3848: ! 3849: GetWindowRect(GetDlgItem(hwndDlg, IDC_MC_DLG_HR2), &rec); ! 3850: GetClientRect(GetDlgItem(hwndDlg, IDC_MC_DLG_HR2), &trec); ! 3851: MoveWindow (GetDlgItem(hwndDlg, IDC_MC_DLG_HR2), ! 3852: rec.left - wrec.left - GetSystemMetrics(SM_CXFIXEDFRAME), ! 3853: rec.top - wrec.top - vertOffset + vertMsgHeightOffset, ! 3854: trec.right + 2 + horizSubOffset, ! 3855: trec.bottom + 2, ! 3856: TRUE); ! 3857: } ! 3858: ! 3859: // Resize the window according to number of shown buttons and the longest button caption ! 3860: MoveWindow (hwndDlg, ! 3861: wrec.left - horizSubOffset / 2, ! 3862: wrec.top + vertSubOffset / 2 - vertMsgHeightOffset / 2, ! 3863: wrec.right - wrec.left + horizSubOffset, ! 3864: wrec.bottom - wrec.top - vertSubOffset + 1 + vertMsgHeightOffset, ! 3865: TRUE); ! 3866: ! 3867: return 1; ! 3868: } ! 3869: ! 3870: case WM_COMMAND: ! 3871: ! 3872: if (lw == IDCLOSE || lw == IDCANCEL) ! 3873: { ! 3874: EndDialog (hwndDlg, 0); ! 3875: return 1; ! 3876: } ! 3877: ! 3878: for (nStr = 1; nStr < MAX_MULTI_CHOICES+1; nStr++) ! 3879: { ! 3880: if (lw == nChoiceIDs[nStr]) ! 3881: { ! 3882: EndDialog (hwndDlg, nStr); ! 3883: return 1; ! 3884: } ! 3885: } ! 3886: break; ! 3887: ! 3888: case WM_CLOSE: ! 3889: EndDialog (hwndDlg, 0); ! 3890: return 1; ! 3891: } ! 3892: ! 3893: return 0; ! 3894: } ! 3895: ! 3896: 1.1.1.7 root 3897: BOOL CheckCapsLock (HWND hwnd, BOOL quiet) 3898: { 3899: if ((GetKeyState(VK_CAPITAL) & 1) != 0) 3900: { 3901: if (!quiet) 3902: { 3903: MessageBoxW (hwnd, GetString ("CAPSLOCK_ON"), lpszTitle, MB_ICONEXCLAMATION); 3904: } 3905: return TRUE; 3906: } 3907: return FALSE; 1.1.1.5 root 3908: } 3909: 3910: 1.1.1.11! root 3911: // Checks whether the file extension is not used for executable files, which often causes ! 3912: // Windows and antivirus software to interfere with the container ! 3913: BOOL CheckFileExtension (char *fileName) ! 3914: { ! 3915: char ext[5]; ! 3916: int i, j = 0; ! 3917: ! 3918: for (i = strlen(fileName)-4; i <= (int) strlen(fileName)-1 && i > 0; i++) ! 3919: { ! 3920: ext [j++] = fileName [i]; ! 3921: } ! 3922: ! 3923: if (!strncmp (ext, ".exe", 4) ! 3924: || !strncmp (ext, ".sys", 4) ! 3925: || !strncmp (ext, ".dll", 4)) ! 3926: { ! 3927: return TRUE; ! 3928: } ! 3929: ! 3930: return FALSE; ! 3931: } ! 3932: ! 3933: 1.1.1.5 root 3934: int GetFirstAvailableDrive () 3935: { 3936: DWORD dwUsedDrives = GetLogicalDrives(); 3937: int i; 3938: 3939: for (i = 3; i < 26; i++) 3940: { 3941: if (!(dwUsedDrives & 1 << i)) 3942: return i; 3943: } 3944: 3945: return -1; 3946: } 3947: 3948: 3949: int GetLastAvailableDrive () 3950: { 3951: DWORD dwUsedDrives = GetLogicalDrives(); 3952: int i; 3953: 3954: for (i = 25; i > 2; i--) 3955: { 3956: if (!(dwUsedDrives & 1 << i)) 3957: return i; 3958: } 3959: 3960: return -1; 3961: } 3962: 3963: 3964: BOOL IsDriveAvailable (int driveNo) 3965: { 3966: return (GetLogicalDrives() & (1 << driveNo)) == 0; 3967: } 3968: 3969: 1.1.1.11! root 3970: BOOL IsDeviceMounted (char *deviceName) ! 3971: { ! 3972: BOOL bResult = FALSE; ! 3973: DWORD dwResult; ! 3974: HANDLE dev = INVALID_HANDLE_VALUE; ! 3975: ! 3976: if ((dev = CreateFile (deviceName, ! 3977: GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, ! 3978: NULL, ! 3979: OPEN_EXISTING, ! 3980: 0, ! 3981: NULL)) != INVALID_HANDLE_VALUE) ! 3982: { ! 3983: bResult = DeviceIoControl (dev, FSCTL_IS_VOLUME_MOUNTED, NULL, 0, NULL, 0, &dwResult, NULL); ! 3984: CloseHandle (dev); ! 3985: } ! 3986: ! 3987: return bResult; ! 3988: } ! 3989: ! 3990: 1.1.1.5 root 3991: int DriverUnmountVolume (HWND hwndDlg, int nDosDriveNo, BOOL forced) 3992: { 3993: UNMOUNT_STRUCT unmount; 3994: DWORD dwResult; 3995: 3996: BOOL bResult; 3997: 3998: unmount.nDosDriveNo = nDosDriveNo; 3999: unmount.ignoreOpenFiles = forced; 4000: 4001: bResult = DeviceIoControl (hDriver, UNMOUNT, &unmount, 4002: sizeof (unmount), &unmount, sizeof (unmount), &dwResult, NULL); 4003: 4004: if (bResult == FALSE) 4005: { 4006: handleWin32Error (hwndDlg); 4007: return 1; 4008: } 4009: 4010: return unmount.nReturnCode; 4011: } 4012: 4013: 1.1.1.6 root 4014: void BroadcastDeviceChange (WPARAM message, int nDosDriveNo, DWORD driveMap) 1.1.1.5 root 4015: { 4016: DEV_BROADCAST_VOLUME dbv; 1.1.1.6 root 4017: DWORD dwResult; 1.1.1.11! root 4018: LONG eventId = 0; 1.1.1.7 root 4019: int i; 1.1.1.6 root 4020: 1.1.1.10 root 4021: if (message == DBT_DEVICEARRIVAL) 1.1.1.11! root 4022: eventId = SHCNE_DRIVEADD; 1.1.1.10 root 4023: else if (message == DBT_DEVICEREMOVECOMPLETE) 1.1.1.11! root 4024: eventId = SHCNE_DRIVEREMOVED; 1.1.1.5 root 4025: 1.1.1.7 root 4026: if (driveMap == 0) 1.1.1.10 root 4027: driveMap = (1 << nDosDriveNo); 4028: 1.1.1.11! root 4029: if (eventId != 0) 1.1.1.7 root 4030: { 1.1.1.11! root 4031: for (i = 0; i < 26; i++) 1.1.1.7 root 4032: { 1.1.1.11! root 4033: if (driveMap & (1 << i)) 1.1.1.7 root 4034: { 1.1.1.11! root 4035: char root[] = {i + 'A', ':', '\\', 0 }; ! 4036: SHChangeNotify (eventId, SHCNF_PATH, root, NULL); 1.1.1.10 root 4037: 1.1.1.11! root 4038: if (nCurrentOS == WIN_2000 && RemoteSession) ! 4039: { ! 4040: char target[32]; ! 4041: wsprintf (target, "%ls%c", TC_MOUNT_PREFIX, i + 'A'); ! 4042: root[2] = 0; ! 4043: ! 4044: if (message == DBT_DEVICEARRIVAL) ! 4045: DefineDosDevice (DDD_RAW_TARGET_PATH, root, target); ! 4046: else if (message == DBT_DEVICEREMOVECOMPLETE) ! 4047: DefineDosDevice (DDD_RAW_TARGET_PATH| DDD_REMOVE_DEFINITION 1.1.1.10 root 4048: | DDD_EXACT_MATCH_ON_REMOVE, root, target); 1.1.1.11! root 4049: } 1.1.1.7 root 4050: } 4051: } 4052: } 1.1.1.5 root 4053: 1.1.1.11! root 4054: dbv.dbcv_size = sizeof (dbv); 1.1.1.5 root 4055: dbv.dbcv_devicetype = DBT_DEVTYP_VOLUME; 4056: dbv.dbcv_reserved = 0; 1.1.1.10 root 4057: dbv.dbcv_unitmask = driveMap; 1.1.1.5 root 4058: dbv.dbcv_flags = 0; 4059: 1.1.1.10 root 4060: SendMessageTimeout (HWND_BROADCAST, WM_DEVICECHANGE, message, (LPARAM)(&dbv), 0, 1000, &dwResult); 1.1.1.5 root 4061: } 4062: 4063: 1.1.1.7 root 4064: // Use only cached passwords if password = NULL 4065: // 1.1.1.5 root 4066: // Returns: 4067: // -1 = user aborted mount / error 4068: // 0 = mount failed 4069: // 1 = mount OK 4070: // 2 = mount OK in shared mode 4071: 4072: int MountVolume (HWND hwndDlg, 4073: int driveNo, 4074: char *volumePath, 1.1.1.7 root 4075: Password *password, 1.1.1.5 root 4076: BOOL cachePassword, 4077: BOOL sharedAccess, 1.1.1.6 root 4078: MountOptions *mountOptions, 1.1.1.7 root 4079: BOOL quiet, 4080: BOOL bReportWrongPassword) 1.1.1.5 root 4081: { 1.1.1.7 root 4082: MOUNT_STRUCT mount; 1.1.1.5 root 4083: DWORD dwResult; 4084: BOOL bResult, bDevice; 1.1.1.11! root 4085: char root[MAX_PATH]; 1.1.1.5 root 4086: 4087: if (IsMountedVolume (volumePath)) 4088: { 4089: if (!quiet) 1.1.1.11! root 4090: Error ("VOL_ALREADY_MOUNTED"); 1.1.1.5 root 4091: return -1; 4092: } 4093: 4094: if (!IsDriveAvailable (driveNo)) 1.1.1.10 root 4095: { 1.1.1.11! root 4096: Error ("DRIVE_LETTER_UNAVAILABLE"); 1.1.1.5 root 4097: return -1; 1.1.1.10 root 4098: } 1.1.1.5 root 4099: 4100: // If using cached passwords, check cache status first 1.1.1.7 root 4101: if (password == NULL && IsPasswordCacheEmpty ()) 1.1.1.5 root 4102: return 0; 4103: 1.1.1.7 root 4104: ZeroMemory (&mount, sizeof (mount)); 4105: mount.bExclusiveAccess = sharedAccess ? FALSE : TRUE; 1.1.1.5 root 4106: retry: 1.1.1.7 root 4107: mount.nDosDriveNo = driveNo; 4108: mount.bCache = cachePassword; 4109: 4110: if (password != NULL) 4111: mount.VolumePassword = *password; 4112: else 4113: mount.VolumePassword.Length = 0; 4114: 4115: if (!mountOptions->ReadOnly && mountOptions->ProtectHiddenVolume) 4116: { 4117: mount.ProtectedHidVolPassword = mountOptions->ProtectedHidVolPassword; 4118: mount.bProtectHiddenVolume = TRUE; 4119: } 4120: else 4121: mount.bProtectHiddenVolume = FALSE; 4122: 4123: mount.bMountReadOnly = mountOptions->ReadOnly; 4124: mount.bMountRemovable = mountOptions->Removable; 1.1.1.9 root 4125: mount.bSystemVolume = mountOptions->SystemVolume; 4126: mount.bPersistentVolume = mountOptions->PersistentVolume; 1.1.1.7 root 4127: mount.bPreserveTimestamp = mountOptions->PreserveTimestamp; 4128: 4129: mount.bMountManager = TRUE; 1.1.1.5 root 4130: 4131: // Windows 2000 mount manager causes problems with remounted volumes 4132: if (CurrentOSMajor == 5 && CurrentOSMinor == 0) 1.1.1.7 root 4133: mount.bMountManager = FALSE; 1.1.1.5 root 4134: 1.1.1.7 root 4135: CreateFullVolumePath ((char *) mount.wszVolume, volumePath, &bDevice); 1.1.1.5 root 4136: 1.1.1.11! root 4137: if (!bDevice) 1.1.1.7 root 4138: { 1.1.1.11! root 4139: // UNC path ! 4140: if (volumePath[0] == '\\' && volumePath[1] == '\\') ! 4141: { ! 4142: _snprintf ((char *)mount.wszVolume, MAX_PATH, "UNC%s", volumePath + 1); 1.1.1.7 root 4143: mount.bUserContext = TRUE; 1.1.1.11! root 4144: } ! 4145: ! 4146: if (GetVolumePathName (volumePath, root, sizeof (root) - 1)) ! 4147: { ! 4148: DWORD bps, flags, d; ! 4149: if (GetDiskFreeSpace (root, &d, &bps, &d, &d)) ! 4150: mount.BytesPerSector = bps; ! 4151: ! 4152: // Read-only host filesystem ! 4153: if (!mount.bMountReadOnly && GetVolumeInformation (root, NULL, 0, NULL, &d, &flags, NULL, 0)) ! 4154: mount.bMountReadOnly = (flags & FILE_READ_ONLY_VOLUME) != 0; ! 4155: ! 4156: // Network drive ! 4157: if (GetDriveType (root) == DRIVE_REMOTE) ! 4158: mount.bUserContext = TRUE; ! 4159: } 1.1.1.7 root 4160: } 4161: 4162: ToUNICODE ((char *) mount.wszVolume); 1.1.1.5 root 4163: 1.1.1.7 root 4164: bResult = DeviceIoControl (hDriver, MOUNT, &mount, 4165: sizeof (mount), &mount, sizeof (mount), &dwResult, NULL); 4166: 4167: burn (&mount.VolumePassword, sizeof (mount.VolumePassword)); 4168: burn (&mount.ProtectedHidVolPassword, sizeof (mount.ProtectedHidVolPassword)); 1.1.1.5 root 4169: 4170: if (bResult == FALSE) 4171: { 4172: // Volume already open by another process 1.1.1.8 root 4173: if (GetLastError () == ERROR_SHARING_VIOLATION) 1.1.1.5 root 4174: { 1.1.1.7 root 4175: if (mount.bExclusiveAccess == FALSE) 1.1.1.5 root 4176: { 4177: if (!quiet) 1.1.1.7 root 4178: MessageBoxW (hwndDlg, GetString ("FILE_IN_USE_FAILED"), 1.1.1.5 root 4179: lpszTitle, MB_ICONSTOP); 4180: 4181: return -1; 4182: } 4183: else 4184: { 4185: if (quiet) 4186: { 1.1.1.7 root 4187: mount.bExclusiveAccess = FALSE; 1.1.1.5 root 4188: goto retry; 4189: } 4190: 4191: // Ask user 1.1.1.7 root 4192: if (IDYES == MessageBoxW (hwndDlg, GetString ("FILE_IN_USE"), 1.1.1.5 root 4193: lpszTitle, MB_YESNO | MB_DEFBUTTON2 | MB_ICONEXCLAMATION)) 4194: { 1.1.1.7 root 4195: mount.bExclusiveAccess = FALSE; 1.1.1.5 root 4196: goto retry; 4197: } 4198: } 4199: 4200: return -1; 4201: } 4202: 1.1.1.8 root 4203: // Mount failed in kernel space => retry in user process context 4204: if (!mount.bUserContext) 4205: { 4206: mount.bUserContext = TRUE; 4207: goto retry; 4208: } 4209: 1.1.1.5 root 4210: if (!quiet) 4211: handleWin32Error (hwndDlg); 4212: 4213: return -1; 4214: } 4215: 1.1.1.7 root 4216: if (mount.nReturnCode != 0) 1.1.1.5 root 4217: { 1.1.1.7 root 4218: if (mount.nReturnCode == ERR_PASSWORD_WRONG) 4219: { 4220: // Do not report wrong password, if not instructed to 4221: if (bReportWrongPassword) 4222: handleError (hwndDlg, mount.nReturnCode); 4223: 4224: return 0; 4225: } 1.1.1.5 root 4226: 1.1.1.7 root 4227: if (!quiet) 4228: handleError (hwndDlg, mount.nReturnCode); 1.1.1.5 root 4229: 4230: return 0; 4231: } 4232: 1.1.1.6 root 4233: BroadcastDeviceChange (DBT_DEVICEARRIVAL, driveNo, 0); 1.1.1.5 root 4234: 1.1.1.7 root 4235: if (mount.bExclusiveAccess == FALSE) 1.1.1.5 root 4236: return 2; 4237: 4238: return 1; 4239: } 4240: 4241: 1.1.1.11! root 4242: BOOL UnmountVolume (HWND hwndDlg, int nDosDriveNo, BOOL forceUnmount) 1.1.1.5 root 4243: { 4244: int result; 4245: BOOL forced = forceUnmount; 1.1.1.6 root 4246: int dismountMaxRetries = UNMOUNT_MAX_AUTO_RETRIES; 1.1.1.5 root 4247: 4248: retry: 1.1.1.11! root 4249: BroadcastDeviceChange (DBT_DEVICEREMOVEPENDING, nDosDriveNo, 0); ! 4250: 1.1.1.6 root 4251: do 4252: { 4253: result = DriverUnmountVolume (hwndDlg, nDosDriveNo, forced); 4254: 4255: if (result == ERR_FILES_OPEN) 4256: Sleep (UNMOUNT_AUTO_RETRY_DELAY); 4257: else 4258: break; 4259: 4260: } while (--dismountMaxRetries > 0); 1.1.1.5 root 4261: 4262: if (result != 0) 4263: { 1.1.1.7 root 4264: if (result == ERR_FILES_OPEN && !Silent) 1.1.1.5 root 4265: { 1.1.1.7 root 4266: if (IDYES == AskWarnNoYes("UNMOUNT_LOCK_FAILED")) 1.1.1.5 root 4267: { 4268: forced = TRUE; 4269: goto retry; 4270: } 4271: 4272: return FALSE; 4273: } 4274: 1.1.1.7 root 4275: Error ("UNMOUNT_FAILED"); 1.1.1.5 root 4276: 4277: return FALSE; 4278: } 4279: 1.1.1.6 root 4280: BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, nDosDriveNo, 0); 1.1.1.5 root 4281: 4282: return TRUE; 4283: } 4284: 4285: 4286: BOOL IsPasswordCacheEmpty (void) 4287: { 4288: DWORD dw; 4289: return !DeviceIoControl (hDriver, CACHE_STATUS, 0, 0, 0, 0, &dw, 0); 4290: } 4291: 4292: BOOL IsMountedVolume (char *volname) 4293: { 4294: MOUNT_LIST_STRUCT mlist; 4295: DWORD dwResult; 4296: int i; 4297: char volume[TC_MAX_PATH*2+16]; 4298: 4299: strcpy (volume, volname); 1.1.1.7 root 4300: 4301: if (strstr (volname, "\\Device\\") != volname) 4302: sprintf(volume, "\\??\\%s", volname); 4303: ToUNICODE (volume); 1.1.1.5 root 4304: 4305: memset (&mlist, 0, sizeof (mlist)); 4306: DeviceIoControl (hDriver, MOUNT_LIST, &mlist, 4307: sizeof (mlist), &mlist, sizeof (mlist), &dwResult, 4308: NULL); 4309: 4310: for (i=0 ; i<26; i++) 1.1.1.7 root 4311: if (0 == wcscmp (mlist.wszVolume[i], (WCHAR *)volume)) 1.1.1.5 root 4312: return TRUE; 4313: 4314: return FALSE; 4315: } 4316: 4317: 4318: BOOL IsAdmin (void) 4319: { 1.1.1.11! root 4320: return IsUserAnAdmin (); ! 4321: } 1.1.1.5 root 4322: 4323: 1.1.1.11! root 4324: BOOL IsUacSupported () ! 4325: { ! 4326: HKEY hkey; ! 4327: DWORD value = 1, size = sizeof (DWORD); 1.1.1.5 root 4328: 1.1.1.11! root 4329: if (nCurrentOS != WIN_VISTA_OR_LATER) 1.1.1.5 root 4330: return FALSE; 4331: 1.1.1.11! root 4332: if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, KEY_READ, &hkey) == ERROR_SUCCESS) 1.1.1.5 root 4333: { 1.1.1.11! root 4334: if (RegQueryValueEx (hkey, "EnableLUA", 0, 0, (LPBYTE) &value, &size) != ERROR_SUCCESS) ! 4335: value = 1; 1.1.1.5 root 4336: 1.1.1.11! root 4337: RegCloseKey (hkey); 1.1.1.5 root 4338: } 4339: 1.1.1.11! root 4340: return value != 0; 1.1.1.5 root 4341: } 4342: 4343: 4344: BOOL ResolveSymbolicLink (PWSTR symLinkName, PWSTR targetName) 4345: { 4346: BOOL bResult; 4347: DWORD dwResult; 4348: RESOLVE_SYMLINK_STRUCT resolve; 4349: 4350: memset (&resolve, 0, sizeof(resolve)); 4351: wcscpy ((PWSTR) &resolve.symLinkName, symLinkName); 4352: 4353: bResult = DeviceIoControl (hDriver, RESOLVE_SYMLINK, &resolve, 4354: sizeof (resolve), &resolve, sizeof (resolve), &dwResult, 4355: NULL); 4356: 4357: wcscpy (targetName, (PWSTR) &resolve.targetName); 4358: 4359: return bResult; 4360: } 4361: 4362: 1.1.1.11! root 4363: BOOL GetPartitionInfo (char *deviceName, PPARTITION_INFORMATION rpartInfo) ! 4364: { ! 4365: BOOL bResult; ! 4366: DWORD dwResult; ! 4367: DISK_PARTITION_INFO_STRUCT dpi; ! 4368: ! 4369: memset (&dpi, 0, sizeof(dpi)); ! 4370: wsprintfW ((PWSTR) &dpi.deviceName, L"%hs", deviceName); ! 4371: ! 4372: bResult = DeviceIoControl (hDriver, DISK_GET_PARTITION_INFO, &dpi, ! 4373: sizeof (dpi), &dpi, sizeof (dpi), &dwResult, NULL); ! 4374: ! 4375: memcpy (rpartInfo, &dpi.partInfo, sizeof (PARTITION_INFORMATION)); ! 4376: return bResult; ! 4377: } ! 4378: ! 4379: ! 4380: BOOL GetDriveGeometry (char *deviceName, PDISK_GEOMETRY diskGeometry) ! 4381: { ! 4382: BOOL bResult; ! 4383: DWORD dwResult; ! 4384: DISK_GEOMETRY_STRUCT dg; ! 4385: ! 4386: memset (&dg, 0, sizeof(dg)); ! 4387: wsprintfW ((PWSTR) &dg.deviceName, L"%hs", deviceName); ! 4388: ! 4389: bResult = DeviceIoControl (hDriver, DISK_GET_GEOMETRY, &dg, ! 4390: sizeof (dg), &dg, sizeof (dg), &dwResult, NULL); ! 4391: ! 4392: memcpy (diskGeometry, &dg.diskGeometry, sizeof (DISK_GEOMETRY)); ! 4393: return bResult; ! 4394: } ! 4395: ! 4396: 1.1.1.5 root 4397: // Returns drive letter number assigned to device (-1 if none) 4398: int GetDiskDeviceDriveLetter (PWSTR deviceName) 4399: { 4400: int i; 4401: WCHAR link[MAX_PATH]; 4402: WCHAR target[MAX_PATH]; 4403: WCHAR device[MAX_PATH]; 4404: 4405: if (!ResolveSymbolicLink (deviceName, device)) 4406: wcscpy (device, deviceName); 4407: 4408: for (i = 0; i < 26; i++) 4409: { 4410: WCHAR drive[] = { i + 'A', ':', 0 }; 4411: 4412: wcscpy (link, L"\\DosDevices\\"); 4413: wcscat (link, drive); 4414: 4415: ResolveSymbolicLink (link, target); 4416: 4417: if (wcscmp (device, target) == 0) 4418: return i; 4419: } 4420: 4421: return -1; 4422: } 4423: 4424: 1.1.1.11! root 4425: HANDLE DismountDrive (char *devName) 1.1.1.5 root 4426: { 4427: DWORD dwResult; 4428: HANDLE hVolume; 1.1.1.11! root 4429: BOOL bResult = FALSE; ! 4430: int attempt = 10; 1.1.1.5 root 4431: 1.1.1.11! root 4432: hVolume = CreateFile (devName, GENERIC_READ | GENERIC_WRITE, ! 4433: FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); 1.1.1.5 root 4434: 1.1.1.11! root 4435: if (hVolume == INVALID_HANDLE_VALUE) ! 4436: return INVALID_HANDLE_VALUE; 1.1.1.5 root 4437: 1.1.1.11! root 4438: while (!(bResult = DeviceIoControl (hVolume, FSCTL_DISMOUNT_VOLUME, NULL, 0, NULL, 0, &dwResult, NULL)) ! 4439: && attempt > 0) ! 4440: { ! 4441: Sleep (UNMOUNT_AUTO_RETRY_DELAY); ! 4442: attempt--; ! 4443: } 1.1.1.5 root 4444: 1.1.1.11! root 4445: if (!bResult) ! 4446: CloseHandle (hVolume); 1.1.1.5 root 4447: 1.1.1.11! root 4448: return (bResult ? hVolume : INVALID_HANDLE_VALUE); 1.1.1.6 root 4449: } 4450: 1.1.1.11! root 4451: 1.1.1.6 root 4452: // System CopyFile() copies source file attributes (like FILE_ATTRIBUTE_ENCRYPTED) 4453: // so we need to use our own copy function 4454: BOOL TCCopyFile (char *sourceFileName, char *destinationFile) 4455: { 4456: __int8 *buffer; 4457: HANDLE src, dst; 4458: FILETIME fileTime; 4459: DWORD bytesRead, bytesWritten; 4460: BOOL res; 4461: 4462: src = CreateFile (sourceFileName, 4463: GENERIC_READ, 4464: FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); 4465: 4466: if (src == INVALID_HANDLE_VALUE) 4467: return FALSE; 4468: 4469: dst = CreateFile (destinationFile, 4470: GENERIC_WRITE, 4471: 0, NULL, CREATE_ALWAYS, 0, NULL); 4472: 4473: if (dst == INVALID_HANDLE_VALUE) 4474: { 4475: CloseHandle (src); 4476: return FALSE; 4477: } 4478: 4479: buffer = malloc (64 * 1024); 4480: if (!buffer) 4481: { 4482: CloseHandle (src); 4483: CloseHandle (dst); 4484: return FALSE; 4485: } 4486: 4487: while (res = ReadFile (src, buffer, 64 * 1024, &bytesRead, NULL)) 4488: { 4489: if (bytesRead == 0) 4490: { 4491: res = 1; 4492: break; 4493: } 4494: 4495: if (!WriteFile (dst, buffer, bytesRead, &bytesWritten, NULL) 4496: || bytesRead != bytesWritten) 4497: { 4498: res = 0; 4499: break; 4500: } 4501: } 4502: 4503: GetFileTime (src, NULL, NULL, &fileTime); 4504: SetFileTime (dst, NULL, NULL, &fileTime); 4505: 4506: CloseHandle (src); 4507: CloseHandle (dst); 4508: 4509: free (buffer); 4510: return res != 0; 4511: } 4512: 1.1.1.7 root 4513: int BackupVolumeHeader (HWND hwndDlg, BOOL bRequireConfirmation, char *lpszVolume) 4514: { 1.1.1.11! root 4515: int nDosLinkCreated = 1, nStatus = ERR_OS_ERROR; 1.1.1.7 root 4516: char szDiskFile[TC_MAX_PATH], szCFDevice[TC_MAX_PATH]; 4517: char szFileName[TC_MAX_PATH]; 4518: char szDosDevice[TC_MAX_PATH]; 4519: char buffer[HEADER_SIZE]; 4520: void *dev = INVALID_HANDLE_VALUE; 4521: DWORD dwError; 4522: BOOL bDevice; 4523: unsigned __int64 volSize = 0; 1.1.1.11! root 4524: wchar_t szTmp[4096]; 1.1.1.7 root 4525: int volumeType; 4526: int fBackup = -1; 4527: 4528: 4529: if (IsMountedVolume (lpszVolume)) 4530: { 4531: Warning ("DISMOUNT_FIRST"); 4532: return 0; 4533: } 4534: 1.1.1.11! root 4535: swprintf (szTmp, GetString ("CONFIRM_VOL_HEADER_BAK"), lpszVolume); 1.1.1.7 root 4536: 4537: if (bRequireConfirmation 4538: && (MessageBoxW (hwndDlg, szTmp, lpszTitle, YES_NO|MB_ICONQUESTION|MB_DEFBUTTON1) == IDNO)) 4539: return 0; 4540: 4541: 4542: /* Select backup file */ 1.1.1.10 root 4543: if (!BrowseFiles (hwndDlg, "OPEN_TITLE", szFileName, bHistory, TRUE)) 1.1.1.7 root 4544: return 0; 4545: 4546: /* Conceive the backup file */ 4547: if ((fBackup = _open(szFileName, _O_CREAT|_O_TRUNC|_O_WRONLY|_O_BINARY, _S_IREAD|_S_IWRITE)) == -1) 1.1.1.11! root 4548: { ! 4549: nStatus = ERROR_CANNOT_MAKE; ! 4550: goto error; ! 4551: } 1.1.1.7 root 4552: 4553: /* Read the volume headers and write them to the backup file */ 4554: 4555: CreateFullVolumePath (szDiskFile, lpszVolume, &bDevice); 4556: 4557: if (bDevice == FALSE) 4558: strcpy (szCFDevice, szDiskFile); 4559: else 4560: { 4561: nDosLinkCreated = FakeDosNameForDevice (szDiskFile, szDosDevice, szCFDevice, FALSE); 4562: if (nDosLinkCreated != 0) 1.1.1.11! root 4563: goto error; 1.1.1.7 root 4564: } 4565: 4566: dev = CreateFile (szCFDevice, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); 4567: 4568: if (bDevice) 4569: { 4570: /* This is necessary to determine the hidden volume header offset */ 4571: 4572: if (dev == INVALID_HANDLE_VALUE) 1.1.1.11! root 4573: goto error; 1.1.1.7 root 4574: else 4575: { 4576: PARTITION_INFORMATION diskInfo; 4577: DWORD dwResult; 4578: BOOL bResult; 1.1.1.11! root 4579: ! 4580: bResult = GetPartitionInfo (lpszVolume, &diskInfo); 1.1.1.7 root 4581: 4582: if (bResult) 4583: { 4584: volSize = diskInfo.PartitionLength.QuadPart; 4585: } 4586: else 4587: { 4588: DISK_GEOMETRY driveInfo; 4589: 4590: bResult = DeviceIoControl (dev, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, 4591: &driveInfo, sizeof (driveInfo), &dwResult, NULL); 4592: 4593: if (!bResult) 4594: goto error; 4595: 4596: volSize = driveInfo.Cylinders.QuadPart * driveInfo.BytesPerSector * 4597: driveInfo.SectorsPerTrack * driveInfo.TracksPerCylinder; 4598: } 4599: 4600: if (volSize == 0) 4601: { 4602: nStatus = ERR_VOL_SIZE_WRONG; 4603: goto error; 4604: } 4605: } 4606: } 4607: 1.1.1.11! root 4608: if (dev == INVALID_HANDLE_VALUE) ! 4609: goto error; 1.1.1.7 root 4610: 4611: for (volumeType = VOLUME_TYPE_NORMAL; volumeType < NBR_VOLUME_TYPES; volumeType++) 4612: { 4613: /* Read in volume header */ 4614: 4615: if (volumeType == VOLUME_TYPE_HIDDEN) 4616: { 4617: if (!SeekHiddenVolHeader ((HFILE) dev, volSize, bDevice)) 4618: { 4619: nStatus = ERR_VOL_SEEKING; 4620: goto error; 4621: } 4622: } 4623: 1.1.1.9 root 4624: nStatus = _lread ((HFILE) dev, buffer, sizeof (buffer)); 1.1.1.7 root 4625: if (nStatus != sizeof (buffer)) 4626: { 4627: nStatus = ERR_VOL_SIZE_WRONG; 4628: goto error; 4629: } 4630: 4631: /* Write the header to the backup file */ 4632: 4633: if (_write (fBackup, buffer, sizeof(buffer)) == -1) 4634: goto error; 4635: } 4636: 4637: /* Backup has been successfully created */ 4638: nStatus = 0; 1.1.1.11! root 4639: Warning("VOL_HEADER_BACKED_UP"); 1.1.1.7 root 4640: 4641: error: 4642: dwError = GetLastError (); 4643: 1.1.1.11! root 4644: if (dev != INVALID_HANDLE_VALUE) ! 4645: CloseHandle ((HANDLE) dev); 1.1.1.7 root 4646: 1.1.1.11! root 4647: if (fBackup != -1) ! 4648: _close (fBackup); 1.1.1.7 root 4649: 1.1.1.11! root 4650: if (nDosLinkCreated == 0) ! 4651: RemoveFakeDosName (szDiskFile, szDosDevice); 1.1.1.7 root 4652: 4653: SetLastError (dwError); 1.1.1.11! root 4654: if (nStatus != 0) ! 4655: handleError (hwndDlg, nStatus); 1.1.1.7 root 4656: 4657: return nStatus; 4658: } 4659: 1.1.1.11! root 4660: 1.1.1.7 root 4661: int RestoreVolumeHeader (HWND hwndDlg, char *lpszVolume) 4662: { 1.1.1.11! root 4663: int nDosLinkCreated = -1, nStatus = ERR_OS_ERROR; 1.1.1.7 root 4664: char szDiskFile[TC_MAX_PATH], szCFDevice[TC_MAX_PATH]; 4665: char szFileName[TC_MAX_PATH]; 4666: char szDosDevice[TC_MAX_PATH]; 4667: char buffer[HEADER_SIZE]; 4668: void *dev = INVALID_HANDLE_VALUE; 4669: DWORD dwError; 4670: BOOL bDevice; 4671: unsigned __int64 volSize = 0; 4672: FILETIME ftCreationTime; 4673: FILETIME ftLastWriteTime; 4674: FILETIME ftLastAccessTime; 1.1.1.11! root 4675: wchar_t szTmp[4096]; 1.1.1.7 root 4676: BOOL bRestoreHiddenVolHeader = FALSE; 4677: BOOL bTimeStampValid = FALSE; 4678: int fBackup = -1; 4679: 4680: 4681: if (IsMountedVolume (lpszVolume)) 4682: { 4683: Warning ("DISMOUNT_FIRST"); 4684: return 0; 4685: } 4686: 1.1.1.11! root 4687: swprintf (szTmp, GetString ("CONFIRM_VOL_HEADER_RESTORE"), lpszVolume); 1.1.1.7 root 4688: 4689: if (MessageBoxW (hwndDlg, szTmp, lpszTitle, YES_NO|MB_ICONWARNING|MB_DEFBUTTON2) == IDNO) 4690: return 0; 4691: 4692: 4693: /* Select backup file */ 1.1.1.10 root 4694: if (!BrowseFiles (hwndDlg, "OPEN_TITLE", szFileName, bHistory, FALSE)) 1.1.1.7 root 4695: return 0; 4696: 1.1.1.11! root 4697: /* Ask the user to select the type of volume (normal/hidden) */ ! 4698: { ! 4699: char *tmpStr[] = {0, "HEADER_RESTORE_TYPE", "RESTORE_NORMAL_VOLUME_HEADER", "RESTORE_HIDDEN_VOLUME_HEADER", "IDCANCEL", 0}; ! 4700: switch (AskMultiChoice (tmpStr)) ! 4701: { ! 4702: case 1: ! 4703: bRestoreHiddenVolHeader = FALSE; ! 4704: break; ! 4705: case 2: ! 4706: bRestoreHiddenVolHeader = TRUE; ! 4707: break; ! 4708: default: ! 4709: return 0; ! 4710: } ! 4711: } 1.1.1.7 root 4712: 4713: /* Open the backup file */ 4714: if ((fBackup = _open(szFileName, _O_BINARY|_O_RDONLY)) == -1) 1.1.1.11! root 4715: { ! 4716: nStatus = ERROR_OPEN_FAILED; ! 4717: goto error; ! 4718: } 1.1.1.7 root 4719: 4720: CreateFullVolumePath (szDiskFile, lpszVolume, &bDevice); 4721: 4722: if (bDevice == FALSE) 4723: strcpy (szCFDevice, szDiskFile); 4724: else 4725: { 4726: nDosLinkCreated = FakeDosNameForDevice (szDiskFile, szDosDevice, szCFDevice, FALSE); 4727: if (nDosLinkCreated != 0) 1.1.1.11! root 4728: goto error; 1.1.1.7 root 4729: } 4730: 4731: dev = CreateFile (szCFDevice, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); 4732: 4733: if (bDevice) 4734: { 4735: /* This is necessary to determine the hidden volume header offset */ 4736: 4737: if (dev == INVALID_HANDLE_VALUE) 1.1.1.11! root 4738: goto error; 1.1.1.7 root 4739: else 4740: { 4741: PARTITION_INFORMATION diskInfo; 4742: DWORD dwResult; 4743: BOOL bResult; 4744: 1.1.1.11! root 4745: bResult = GetPartitionInfo (lpszVolume, &diskInfo); 1.1.1.7 root 4746: 4747: if (bResult) 4748: { 4749: volSize = diskInfo.PartitionLength.QuadPart; 4750: } 4751: else 4752: { 4753: DISK_GEOMETRY driveInfo; 4754: 4755: bResult = DeviceIoControl (dev, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, 4756: &driveInfo, sizeof (driveInfo), &dwResult, NULL); 4757: 4758: if (!bResult) 4759: goto error; 4760: 4761: volSize = driveInfo.Cylinders.QuadPart * driveInfo.BytesPerSector * 4762: driveInfo.SectorsPerTrack * driveInfo.TracksPerCylinder; 4763: } 4764: 4765: if (volSize == 0) 4766: { 4767: nStatus = ERR_VOL_SIZE_WRONG; 4768: goto error; 4769: } 4770: } 4771: } 4772: 4773: if (dev == INVALID_HANDLE_VALUE) 1.1.1.11! root 4774: goto error; 1.1.1.7 root 4775: 4776: if (!bDevice && bPreserveTimestamp) 4777: { 4778: /* Remember the container modification/creation date and time. */ 4779: 4780: if (GetFileTime ((HANDLE) dev, &ftCreationTime, &ftLastAccessTime, &ftLastWriteTime) == 0) 4781: { 4782: bTimeStampValid = FALSE; 4783: Warning ("GETFILETIME_FAILED_GENERIC"); 4784: } 4785: else 4786: bTimeStampValid = TRUE; 4787: } 4788: 4789: /* Read the volume header from the backup file */ 4790: 4791: if (_lseek(fBackup, bRestoreHiddenVolHeader ? HEADER_SIZE : 0, SEEK_SET) == -1L) 4792: { 4793: nStatus = ERROR_SEEK; 4794: goto error; 4795: } 4796: 4797: if (_read (fBackup, buffer, HEADER_SIZE) == -1) 4798: goto error; 4799: 4800: 4801: /* Restore/write the volume header */ 4802: 4803: // Seek 4804: if (bRestoreHiddenVolHeader) 4805: { 4806: if (!SeekHiddenVolHeader ((HFILE) dev, volSize, bDevice)) 4807: { 4808: nStatus = ERR_VOL_SEEKING; 4809: goto error; 4810: } 4811: } 4812: else 4813: { 4814: nStatus = _llseek ((HFILE) dev, 0, FILE_BEGIN); 4815: 4816: if (nStatus != 0) 4817: { 4818: nStatus = ERR_VOL_SEEKING; 4819: goto error; 4820: } 4821: } 4822: 4823: // Write 1.1.1.9 root 4824: if ((_lwrite ((HFILE) dev, buffer, HEADER_SIZE)) != HEADER_SIZE) 1.1.1.7 root 4825: { 4826: nStatus = ERR_VOL_WRITING; 4827: goto error; 4828: } 4829: 4830: /* Volume header has been successfully restored */ 4831: 4832: nStatus = 0; 4833: Info("VOL_HEADER_RESTORED"); 4834: 4835: error: 4836: 4837: dwError = GetLastError (); 4838: 4839: if (bTimeStampValid) 4840: { 4841: // Restore the container timestamp (to preserve plausible deniability of possible hidden volume). 4842: if (SetFileTime (dev, &ftCreationTime, &ftLastAccessTime, &ftLastWriteTime) == 0) 4843: MessageBoxW (hwndDlg, GetString ("SETFILETIME_FAILED_PW"), L"TrueCrypt", MB_OK | MB_ICONEXCLAMATION); 4844: } 4845: 1.1.1.11! root 4846: if (dev != INVALID_HANDLE_VALUE) ! 4847: CloseHandle ((HANDLE) dev); 1.1.1.7 root 4848: 1.1.1.11! root 4849: if (fBackup != -1) ! 4850: _close (fBackup); 1.1.1.7 root 4851: 1.1.1.11! root 4852: if (nDosLinkCreated == 0) ! 4853: RemoveFakeDosName (szDiskFile, szDosDevice); 1.1.1.7 root 4854: 4855: SetLastError (dwError); 1.1.1.11! root 4856: if (nStatus != 0) ! 4857: handleError (hwndDlg, nStatus); 1.1.1.7 root 4858: 4859: return nStatus; 4860: } 1.1.1.6 root 4861: 1.1.1.11! root 4862: 1.1.1.6 root 4863: BOOL IsNonInstallMode () 4864: { 1.1.1.11! root 4865: HKEY hkey; 1.1.1.6 root 4866: 1.1.1.11! root 4867: if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TrueCrypt", 0, KEY_READ, &hkey) == ERROR_SUCCESS) 1.1.1.7 root 4868: { 1.1.1.11! root 4869: RegCloseKey (hkey); ! 4870: return FALSE; 1.1.1.7 root 4871: } 4872: 1.1.1.11! root 4873: return TRUE; 1.1.1.6 root 4874: } 4875: 4876: 1.1.1.7 root 4877: LRESULT SetCheckBox (HWND hwndDlg, int dlgItem, BOOL state) 1.1.1.6 root 4878: { 1.1.1.7 root 4879: return SendDlgItemMessage (hwndDlg, dlgItem, BM_SETCHECK, state ? BST_CHECKED : BST_UNCHECKED, 0); 4880: } 1.1.1.6 root 4881: 1.1.1.7 root 4882: 4883: BOOL GetCheckBox (HWND hwndDlg, int dlgItem) 4884: { 4885: return IsButtonChecked (GetDlgItem (hwndDlg, dlgItem)); 4886: } 4887: 4888: 1.1.1.11! root 4889: // Delete the last used Windows file selector path for TrueCrypt from the registry 1.1.1.7 root 4890: void CleanLastVisitedMRU (void) 4891: { 4892: WCHAR exeFilename[MAX_PATH]; 4893: WCHAR *strToMatch; 4894: 1.1.1.11! root 4895: WCHAR strTmp[4096]; ! 4896: char regPath[128]; ! 4897: char key[64]; ! 4898: int id, len; 1.1.1.7 root 4899: 4900: GetModuleFileNameW (NULL, exeFilename, sizeof (exeFilename)); 4901: strToMatch = wcsrchr (exeFilename, '\\') + 1; 4902: 1.1.1.11! root 4903: sprintf (regPath, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\LastVisited%sMRU", nCurrentOS == WIN_VISTA_OR_LATER ? "Pidl" : ""); ! 4904: ! 4905: for (id = (nCurrentOS == WIN_VISTA_OR_LATER ? 0 : 'a'); id <= (nCurrentOS == WIN_VISTA_OR_LATER ? 1000 : 'z'); id++) 1.1.1.6 root 4906: { 1.1.1.7 root 4907: *strTmp = 0; 1.1.1.11! root 4908: sprintf (key, (nCurrentOS == WIN_VISTA_OR_LATER ? "%d" : "%c"), id); ! 4909: ! 4910: if ((len = ReadRegistryBytes (regPath, key, (char *) strTmp, sizeof (strTmp))) > 0) 1.1.1.6 root 4911: { 1.1.1.11! root 4912: if (_wcsicmp (strTmp, strToMatch) == 0) 1.1.1.7 root 4913: { 1.1.1.11! root 4914: char buf[65536], bufout[sizeof (buf)]; ! 4915: 1.1.1.7 root 4916: // Overwrite the entry with zeroes while keeping its original size 4917: memset (strTmp, 0, len); 1.1.1.11! root 4918: if (!WriteRegistryBytes (regPath, key, (char *) strTmp, len)) 1.1.1.7 root 4919: MessageBoxW (NULL, GetString ("CLEAN_WINMRU_FAILED"), lpszTitle, ICON_HAND); 4920: 1.1.1.11! root 4921: DeleteRegistryValue (regPath, key); ! 4922: ! 4923: // Remove ID from MRUList ! 4924: if (nCurrentOS == WIN_VISTA_OR_LATER) ! 4925: { ! 4926: int *p = (int *)buf; ! 4927: int *pout = (int *)bufout; ! 4928: int l; ! 4929: ! 4930: l = len = ReadRegistryBytes ("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\LastVisitedPidlMRU", "MRUListEx", buf, sizeof (buf)); ! 4931: while (l > 0) ! 4932: { ! 4933: l -= sizeof (int); ! 4934: ! 4935: if (*p == id) ! 4936: { ! 4937: p++; ! 4938: len -= sizeof (int); ! 4939: continue; ! 4940: } ! 4941: *pout++ = *p++; ! 4942: } ! 4943: ! 4944: WriteRegistryBytes ("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\LastVisitedPidlMRU", "MRUListEx", bufout, len); ! 4945: } ! 4946: else ! 4947: { ! 4948: char *p = buf; ! 4949: char *pout = bufout; ! 4950: ! 4951: ReadRegistryString ("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\LastVisitedMRU", "MRUList", "", buf, sizeof (buf)); ! 4952: while (*p) ! 4953: { ! 4954: if (*p == id) ! 4955: { ! 4956: p++; ! 4957: continue; ! 4958: } ! 4959: *pout++ = *p++; ! 4960: } ! 4961: *pout++ = 0; ! 4962: ! 4963: WriteRegistryString ("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\LastVisitedMRU", "MRUList", bufout); ! 4964: } ! 4965: ! 4966: break; 1.1.1.7 root 4967: } 4968: } 4969: } 4970: } 1.1.1.6 root 4971: 4972: 1.1.1.11! root 4973: #ifndef SETUP ! 4974: void ClearHistory (HWND hwndDlgItem) ! 4975: { ! 4976: ArrowWaitCursor (); ! 4977: ! 4978: ClearCombo (hwndDlgItem); ! 4979: DumpCombo (hwndDlgItem, TRUE); ! 4980: ! 4981: CleanLastVisitedMRU (); ! 4982: ! 4983: NormalCursor (); ! 4984: } ! 4985: #endif // #ifndef SETUP ! 4986: ! 4987: 1.1.1.7 root 4988: LRESULT ListItemAdd (HWND list, int index, char *string) 4989: { 4990: LVITEM li; 4991: memset (&li, 0, sizeof(li)); 1.1.1.6 root 4992: 1.1.1.7 root 4993: li.mask = LVIF_TEXT; 4994: li.pszText = string; 4995: li.iItem = index; 4996: li.iSubItem = 0; 4997: return ListView_InsertItem (list, &li); 4998: } 1.1.1.6 root 4999: 1.1.1.7 root 5000: 5001: LRESULT ListItemAddW (HWND list, int index, wchar_t *string) 5002: { 5003: LVITEMW li; 5004: memset (&li, 0, sizeof(li)); 5005: 5006: li.mask = LVIF_TEXT; 5007: li.pszText = string; 5008: li.iItem = index; 5009: li.iSubItem = 0; 5010: return SendMessageW (list, LVM_INSERTITEMW, 0, (LPARAM)(&li)); 5011: } 5012: 5013: 5014: LRESULT ListSubItemSet (HWND list, int index, int subIndex, char *string) 5015: { 5016: LVITEM li; 5017: memset (&li, 0, sizeof(li)); 5018: 5019: li.mask = LVIF_TEXT; 5020: li.pszText = string; 5021: li.iItem = index; 5022: li.iSubItem = subIndex; 5023: return ListView_SetItem (list, &li); 5024: } 5025: 5026: 5027: LRESULT ListSubItemSetW (HWND list, int index, int subIndex, wchar_t *string) 5028: { 5029: LVITEMW li; 5030: memset (&li, 0, sizeof(li)); 5031: 5032: li.mask = LVIF_TEXT; 5033: li.pszText = string; 5034: li.iItem = index; 5035: li.iSubItem = subIndex; 5036: return SendMessageW (list, LVM_SETITEMW, 0, (LPARAM)(&li)); 5037: } 5038: 5039: 5040: BOOL GetMountList (MOUNT_LIST_STRUCT *list) 5041: { 5042: DWORD dwResult; 5043: 5044: memset (list, 0, sizeof (*list)); 5045: return DeviceIoControl (hDriver, MOUNT_LIST, list, 5046: sizeof (*list), list, sizeof (*list), &dwResult, 5047: NULL); 5048: } 5049: 5050: 5051: int GetDriverRefCount () 5052: { 5053: DWORD dwResult; 5054: BOOL bResult; 5055: int refCount; 5056: 5057: bResult = DeviceIoControl (hDriver, DEVICE_REFCOUNT, &refCount, sizeof (refCount), &refCount, 5058: sizeof (refCount), &dwResult, NULL); 5059: 5060: if (bResult) 5061: return refCount; 5062: else 5063: return -1; 5064: } 5065: 5066: 5067: char *LoadFile (char *fileName, DWORD *size) 5068: { 5069: char *buf; 5070: HANDLE h = CreateFile (fileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); 5071: if (h == INVALID_HANDLE_VALUE) 5072: return NULL; 5073: 5074: *size = GetFileSize (h, NULL); 5075: buf = malloc (*size + 1); 5076: ZeroMemory (buf, *size + 1); 5077: 5078: if (buf != NULL) 5079: ReadFile (h, buf, *size, size, NULL); 5080: 5081: CloseHandle (h); 5082: return buf; 5083: } 5084: 5085: 1.1.1.11! root 5086: char *GetModPath (char *path, int maxSize) 1.1.1.10 root 5087: { 5088: GetModuleFileName (NULL, path, maxSize); 5089: strrchr (path, '\\')[1] = 0; 5090: return path; 5091: } 5092: 5093: 1.1.1.7 root 5094: char *GetConfigPath (char *fileName) 5095: { 1.1.1.10 root 5096: static char path[MAX_PATH * 2] = { 0 }; 1.1.1.11! root 5097: FILE *f; ! 5098: ! 5099: // Module's directory ! 5100: GetModPath (path, sizeof (path)); ! 5101: strcat (path, fileName); ! 5102: ! 5103: if (IsNonInstallMode ()) ! 5104: return path; 1.1.1.7 root 5105: 1.1.1.11! root 5106: f = fopen (fileName, "r"); ! 5107: if (f == NULL) 1.1.1.7 root 5108: { 5109: // User application data folder 1.1.1.10 root 5110: SHGetFolderPath (NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, path); 1.1.1.7 root 5111: strcat (path, "\\TrueCrypt\\"); 5112: CreateDirectory (path, NULL); 5113: strcat (path, fileName); 5114: } 5115: else 1.1.1.11! root 5116: fclose (f); 1.1.1.7 root 5117: 5118: return path; 5119: } 5120: 5121: 5122: int Info (char *stringId) 5123: { 5124: if (Silent) return 0; 5125: return MessageBoxW (MainDlg, GetString (stringId), lpszTitle, MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TOPMOST); 5126: } 5127: 5128: 5129: int Warning (char *stringId) 5130: { 5131: if (Silent) return 0; 5132: return MessageBoxW (MainDlg, GetString (stringId), lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST); 5133: } 5134: 5135: 5136: int Error (char *stringId) 5137: { 5138: if (Silent) return 0; 5139: return MessageBoxW (MainDlg, GetString (stringId), lpszTitle, MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST); 5140: } 5141: 5142: 5143: int AskYesNo (char *stringId) 5144: { 5145: if (Silent) return 0; 5146: return MessageBoxW (MainDlg, GetString (stringId), lpszTitle, MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON1 | MB_SETFOREGROUND | MB_TOPMOST); 5147: } 5148: 5149: 5150: int AskNoYes (char *stringId) 5151: { 5152: if (Silent) return 0; 5153: return MessageBoxW (MainDlg, GetString (stringId), lpszTitle, MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2 | MB_SETFOREGROUND | MB_TOPMOST); 5154: } 5155: 5156: 5157: int AskWarnYesNo (char *stringId) 5158: { 5159: if (Silent) return 0; 5160: return MessageBoxW (MainDlg, GetString (stringId), lpszTitle, MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON1 | MB_SETFOREGROUND | MB_TOPMOST); 5161: } 5162: 5163: 5164: int AskWarnNoYes (char *stringId) 5165: { 5166: if (Silent) return 0; 5167: return MessageBoxW (MainDlg, GetString (stringId), lpszTitle, MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2 | MB_SETFOREGROUND | MB_TOPMOST); 5168: } 5169: 5170: 5171: int AskWarnCancelOk (char *stringId) 5172: { 5173: if (Silent) return 0; 5174: return MessageBoxW (MainDlg, GetString (stringId), lpszTitle, MB_ICONWARNING | MB_OKCANCEL | MB_DEFBUTTON2 | MB_SETFOREGROUND | MB_TOPMOST); 5175: } 5176: 5177: 1.1.1.11! root 5178: // The function accepts two input formats: ! 5179: // Input format 1: {0, "MESSAGE_STRING_ID", "BUTTON_1_STRING_ID", ... "LAST_BUTTON_STRING_ID", 0}; ! 5180: // Input format 2: {L"", L"Message text", L"Button caption 1", ... L"Last button caption", 0}; ! 5181: // The second format is to be used if any of the strings contains format specification (e.g. %s, %d) or ! 5182: // in any other cases where a string needs to be resolved before calling this function. ! 5183: // If the returned value is 0, the user closed the dialog window without making a choice. ! 5184: // If the user made a choice, the returned value is the ordinal number of the choice (1..MAX_MULTI_CHOICES) ! 5185: int AskMultiChoice (void *strings[]) ! 5186: { ! 5187: return DialogBoxParamW (hInst, ! 5188: MAKEINTRESOURCEW (IDD_MULTI_CHOICE_DLG), MainDlg, ! 5189: (DLGPROC) MultiChoiceDialogProc, (LPARAM) &strings[0]); ! 5190: } ! 5191: ! 5192: 1.1.1.7 root 5193: BOOL ConfigWriteBegin () 5194: { 5195: DWORD size; 5196: if (ConfigFileHandle != NULL) return FALSE; 5197: 5198: if (ConfigBuffer == NULL) 5199: ConfigBuffer = LoadFile (GetConfigPath (FILE_CONFIGURATION), &size); 5200: 5201: ConfigFileHandle = fopen (GetConfigPath (FILE_CONFIGURATION), "w"); 5202: if (ConfigFileHandle == NULL) 5203: { 5204: free (ConfigBuffer); 5205: ConfigBuffer = NULL; 5206: return FALSE; 5207: } 5208: XmlWriteHeader (ConfigFileHandle); 5209: fputs ("\n\t<configuration>", ConfigFileHandle); 5210: 5211: return TRUE; 5212: } 5213: 5214: 5215: BOOL ConfigWriteEnd () 5216: { 5217: char *xml = ConfigBuffer; 5218: char key[128], value[2048]; 5219: 5220: if (ConfigFileHandle == NULL) return FALSE; 5221: 5222: // Write unmodified values 5223: while (xml && (xml = XmlFindElement (xml, "config"))) 5224: { 1.1.1.11! root 5225: XmlGetAttributeText (xml, "key", key, sizeof (key)); ! 5226: XmlGetNodeText (xml, value, sizeof (value)); 1.1.1.7 root 5227: 5228: fprintf (ConfigFileHandle, "\n\t\t<config key=\"%s\">%s</config>", key, value); 5229: xml++; 5230: } 5231: 5232: fputs ("\n\t</configuration>", ConfigFileHandle); 5233: XmlWriteFooter (ConfigFileHandle); 5234: 5235: fclose (ConfigFileHandle); 5236: ConfigFileHandle = NULL; 5237: 5238: if (ConfigBuffer != NULL) 5239: { 5240: DWORD size; 5241: free (ConfigBuffer); 5242: ConfigBuffer = LoadFile (GetConfigPath (FILE_CONFIGURATION), &size); 5243: } 5244: 5245: return TRUE; 5246: } 5247: 5248: 5249: BOOL ConfigWriteString (char *configKey, char *configValue) 5250: { 5251: char *c; 5252: if (ConfigFileHandle == NULL) 5253: return FALSE; 5254: 5255: // Mark previous config value as updated 5256: if (ConfigBuffer != NULL) 5257: { 5258: c = XmlFindElementByAttributeValue (ConfigBuffer, "config", "key", configKey); 5259: if (c != NULL) 5260: c[1] = '!'; 5261: } 5262: 5263: return 0 != fprintf ( 5264: ConfigFileHandle, "\n\t\t<config key=\"%s\">%s</config>", 5265: configKey, configValue); 5266: } 5267: 5268: 5269: BOOL ConfigWriteInt (char *configKey, int configValue) 5270: { 5271: char val[32]; 5272: sprintf (val, "%d", configValue); 5273: return ConfigWriteString (configKey, val); 5274: } 5275: 5276: 5277: static BOOL ConfigRead (char *configKey, char *configValue, int maxValueSize) 5278: { 5279: DWORD size; 5280: char *xml; 5281: 5282: if (ConfigBuffer == NULL) 5283: ConfigBuffer = LoadFile (GetConfigPath (FILE_CONFIGURATION), &size); 5284: 5285: xml = ConfigBuffer; 5286: if (xml != NULL) 5287: { 5288: xml = XmlFindElementByAttributeValue (xml, "config", "key", configKey); 5289: if (xml != NULL) 1.1.1.6 root 5290: { 1.1.1.11! root 5291: XmlGetNodeText (xml, configValue, maxValueSize); 1.1.1.7 root 5292: return TRUE; 1.1.1.6 root 5293: } 1.1.1.7 root 5294: } 5295: 5296: return FALSE; 5297: } 5298: 5299: 5300: int ConfigReadInt (char *configKey, int defaultValue) 5301: { 5302: char s[32]; 5303: 5304: if (ConfigRead (configKey, s, sizeof (s))) 5305: return atoi (s); 5306: else 5307: return defaultValue; 5308: } 5309: 5310: 5311: char *ConfigReadString (char *configKey, char *defaultValue, char *str, int maxLen) 5312: { 5313: if (ConfigRead (configKey, str, maxLen)) 5314: return str; 5315: else 5316: return defaultValue; 5317: } 5318: 5319: 5320: void OpenPageHelp (HWND hwndDlg, int nPage) 5321: { 5322: int r = (int)ShellExecute (NULL, "open", szHelpFile, NULL, NULL, SW_SHOWNORMAL); 5323: if (nPage); /* Remove warning */ 1.1.1.6 root 5324: 1.1.1.7 root 5325: if (r == ERROR_FILE_NOT_FOUND) 5326: { 5327: // Try the secondary help file 5328: r = (int)ShellExecute (NULL, "open", szHelpFile2, NULL, NULL, SW_SHOWNORMAL); 5329: 5330: if (r == ERROR_FILE_NOT_FOUND) 1.1.1.10 root 5331: { 5332: OpenOnlineHelp (); 5333: return; 5334: } 1.1.1.7 root 5335: } 1.1.1.10 root 5336: 1.1.1.7 root 5337: if (r == SE_ERR_NOASSOC) 1.1.1.10 root 5338: { 5339: if (AskYesNo ("HELP_READER_ERROR") == IDYES) 5340: OpenOnlineHelp (); 5341: } 5342: } 5343: 5344: 5345: void OpenOnlineHelp () 5346: { 1.1.1.11! root 5347: Applink ("help", TRUE, ""); 1.1.1.7 root 5348: } 5349: 5350: 5351: #ifndef SETUP 5352: 5353: void RestoreDefaultKeyFilesParam (void) 5354: { 5355: KeyFileRemoveAll (&FirstKeyFile); 5356: if (defaultKeyFilesParam.FirstKeyFile != NULL) 5357: { 5358: FirstKeyFile = KeyFileCloneAll (defaultKeyFilesParam.FirstKeyFile); 5359: KeyFilesEnable = defaultKeyFilesParam.EnableKeyFiles; 5360: } 5361: else 5362: KeyFilesEnable = FALSE; 5363: } 5364: 5365: 5366: BOOL LoadDefaultKeyFilesParam (void) 5367: { 5368: BOOL status = TRUE; 5369: DWORD size; 5370: char *defaultKeyfilesFile = LoadFile (GetConfigPath (FILE_DEFAULT_KEYFILES), &size); 5371: char *xml = defaultKeyfilesFile; 5372: KeyFile *kf; 5373: 5374: if (xml == NULL) 5375: return FALSE; 5376: 5377: KeyFileRemoveAll (&defaultKeyFilesParam.FirstKeyFile); 5378: 5379: while (xml = XmlFindElement (xml, "keyfile")) 5380: { 5381: kf = malloc (sizeof (KeyFile)); 5382: 1.1.1.11! root 5383: if (XmlGetNodeText (xml, kf->FileName, sizeof (kf->FileName)) != NULL) 1.1.1.7 root 5384: defaultKeyFilesParam.FirstKeyFile = KeyFileAdd (defaultKeyFilesParam.FirstKeyFile, kf); 5385: else 5386: free (kf); 5387: 5388: xml++; 5389: } 5390: 5391: free (defaultKeyfilesFile); 5392: KeyFilesEnable = defaultKeyFilesParam.EnableKeyFiles; 5393: 5394: return status; 5395: } 5396: 5397: #endif /* #ifndef SETUP */ 5398: 5399: 5400: void Debug (char *format, ...) 5401: { 5402: char buf[1024]; 5403: va_list val; 5404: 5405: va_start(val, format); 5406: _vsnprintf (buf, sizeof (buf), format, val); 5407: va_end(val); 5408: 5409: OutputDebugString (buf); 5410: } 5411: 5412: 5413: void DebugMsgBox (char *format, ...) 5414: { 5415: char buf[1024]; 5416: va_list val; 5417: 5418: va_start(val, format); 5419: _vsnprintf (buf, sizeof (buf), format, val); 5420: va_end(val); 5421: 5422: MessageBox (MainDlg, buf, "TrueCrypt debug", 0); 5423: } 5424: 5425: 5426: BOOL Is64BitOs () 5427: { 5428: static BOOL isWow64 = FALSE; 5429: static BOOL valid = FALSE; 5430: typedef BOOL (__stdcall *LPFN_ISWOW64PROCESS ) (HANDLE hProcess,PBOOL Wow64Process); 5431: LPFN_ISWOW64PROCESS fnIsWow64Process; 5432: 5433: if (valid) 5434: return isWow64; 5435: 5436: fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle("kernel32"), "IsWow64Process"); 5437: 5438: if (fnIsWow64Process != NULL) 5439: if (!fnIsWow64Process (GetCurrentProcess(), &isWow64)) 5440: isWow64 = FALSE; 5441: 5442: valid = TRUE; 5443: return isWow64; 5444: } 5445: 5446: 1.1.1.11! root 5447: void Applink (char *dest, BOOL bSendOS, char *extraOutput) ! 5448: { ! 5449: char url [MAX_URL_LENGTH]; ! 5450: char osname [200]; ! 5451: ! 5452: if (bSendOS) ! 5453: { ! 5454: OSVERSIONINFOEXA os; ! 5455: ! 5456: os.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEXA); ! 5457: ! 5458: GetVersionExA ((LPOSVERSIONINFOA) &os); ! 5459: ! 5460: strcpy (osname, "&os="); ! 5461: ! 5462: switch (nCurrentOS) ! 5463: { ! 5464: case WIN_2000: ! 5465: strcat (osname, "win2000"); ! 5466: break; ! 5467: ! 5468: case WIN_XP: ! 5469: case WIN_XP64: ! 5470: strcat (osname, "winxp"); ! 5471: break; ! 5472: ! 5473: case WIN_SERVER_2003: ! 5474: strcat (osname, "win2003"); ! 5475: break; ! 5476: ! 5477: case WIN_VISTA_OR_LATER: ! 5478: if (os.dwMajorVersion >= 7) ! 5479: strcat (osname, "win7-or-later"); ! 5480: else ! 5481: { ! 5482: strcat (osname, "winvista"); ! 5483: ! 5484: if (os.wSuiteMask & VER_SUITE_PERSONAL) ! 5485: strcat (osname, "-home"); ! 5486: else ! 5487: { ! 5488: HKEY hkey = 0; ! 5489: char str[300] = {0}; ! 5490: DWORD size = sizeof (str); ! 5491: ! 5492: ZeroMemory (str, sizeof (str)); ! 5493: if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", ! 5494: 0, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS ! 5495: && (RegQueryValueEx (hkey, "ProductName", 0, 0, (LPBYTE) &str, &size) == ERROR_SUCCESS)) ! 5496: { ! 5497: if (strstr (str, "Enterprise") != 0) ! 5498: strcat (osname, "-enterprise"); ! 5499: else if (strstr (str, "Business") != 0) ! 5500: strcat (osname, "-business"); ! 5501: else if (strstr (str, "Ultimate") != 0) ! 5502: strcat (osname, "-ultimate"); ! 5503: } ! 5504: RegCloseKey (hkey); ! 5505: } ! 5506: } ! 5507: break; ! 5508: ! 5509: default: ! 5510: strcat (osname, "other"); ! 5511: } ! 5512: ! 5513: if (Is64BitOs()) ! 5514: strcat (osname, "-x64"); ! 5515: ! 5516: if (CurrentOSServicePack > 0) ! 5517: { ! 5518: char s[64]; ! 5519: sprintf (s, "-sp%d", CurrentOSServicePack); ! 5520: strcat (osname, s); ! 5521: } ! 5522: ! 5523: } ! 5524: else ! 5525: osname[0] = 0; ! 5526: ! 5527: ArrowWaitCursor (); ! 5528: ! 5529: sprintf (url, TC_APPLINK "%s%s&dest=%s", osname, extraOutput, dest); ! 5530: ShellExecute (NULL, "open", url, NULL, NULL, SW_SHOWNORMAL); ! 5531: ! 5532: Sleep (200); ! 5533: NormalCursor (); ! 5534: } ! 5535: ! 5536: 1.1.1.7 root 5537: char *RelativePath2Absolute (char *szFileName) 5538: { 5539: if (szFileName[0] != '\\' 5540: && strchr (szFileName, ':') == 0 5541: && strstr (szFileName, "Volume{") != szFileName) 5542: { 5543: char path[MAX_PATH*2]; 5544: GetCurrentDirectory (MAX_PATH, path); 5545: 5546: if (path[strlen (path) - 1] != '\\') 5547: strcat (path, "\\"); 5548: 5549: strcat (path, szFileName); 5550: strncpy (szFileName, path, MAX_PATH-1); 5551: } 5552: 5553: return szFileName; 5554: } 5555: 5556: 5557: void CheckSystemAutoMount () 5558: { 5559: HKEY hkey = 0; 5560: DWORD value = 0, size = sizeof (DWORD); 5561: 5562: if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, "SYSTEM\\ControlSet001\\Services\\MountMgr", 5563: 0, KEY_READ, &hkey) != ERROR_SUCCESS) 5564: return; 5565: 5566: if (RegQueryValueEx (hkey, "NoAutoMount", 0, 0, (LPBYTE) &value, &size) == ERROR_SUCCESS 5567: && value != 0) 5568: Warning ("SYS_AUTOMOUNT_DISABLED"); 1.1.1.11! root 5569: else if (nCurrentOS == WIN_VISTA_OR_LATER) ! 5570: Warning ("SYS_ASSIGN_DRIVE_LETTER"); ! 5571: 1.1.1.7 root 5572: RegCloseKey (hkey); 5573: } 5574: 5575: 1.1.1.8 root 5576: BOOL CALLBACK CloseTCWindowsEnum (HWND hwnd, LPARAM lParam) 1.1.1.7 root 5577: { 5578: if (GetWindowLongPtr (hwnd, GWLP_USERDATA) == (LONG_PTR) 'TRUE') 5579: { 5580: char name[32] = { 0 }; 5581: GetWindowText (hwnd, name, sizeof (name) - 1); 5582: if (hwnd != MainDlg && strstr (name, "TrueCrypt") == name) 1.1.1.6 root 5583: { 1.1.1.11! root 5584: PostMessage (hwnd, WM_APP + APPMSG_CLOSE_BKG_TASK, 0, 0); ! 5585: ! 5586: if (DriverVersion < 0x0430) ! 5587: PostMessage (hwnd, WM_ENDSESSION, 0, 0); ! 5588: 1.1.1.7 root 5589: PostMessage (hwnd, WM_CLOSE, 0, 0); 1.1.1.6 root 5590: 1.1.1.7 root 5591: if (lParam != 0) 5592: *((BOOL *)lParam) = TRUE; 1.1.1.6 root 5593: } 5594: } 1.1.1.7 root 5595: return TRUE; 1.1.1.6 root 5596: } 1.1.1.7 root 5597: 5598: 1.1.1.8 root 5599: BOOL CALLBACK FindTCWindowEnum (HWND hwnd, LPARAM lParam) 5600: { 5601: if (*(HWND *)lParam == hwnd) 5602: return TRUE; 5603: 5604: if (GetWindowLongPtr (hwnd, GWLP_USERDATA) == (LONG_PTR) 'TRUE') 5605: { 5606: char name[32] = { 0 }; 5607: GetWindowText (hwnd, name, sizeof (name) - 1); 1.1.1.9 root 5608: if (hwnd != MainDlg && strcmp (name, "TrueCrypt") == 0) 1.1.1.8 root 5609: { 5610: if (lParam != 0) 5611: *((HWND *)lParam) = hwnd; 5612: } 5613: } 5614: return TRUE; 5615: } 5616: 5617: 1.1.1.7 root 5618: BYTE *MapResource (char *resourceType, int resourceId, PDWORD size) 5619: { 5620: HGLOBAL hResL; 5621: HRSRC hRes; 5622: 5623: hRes = FindResource (NULL, MAKEINTRESOURCE(resourceId), resourceType); 5624: hResL = LoadResource (NULL, hRes); 5625: 5626: if (size != NULL) 5627: *size = SizeofResource (NULL, hRes); 5628: 5629: return (BYTE *) LockResource (hResL); 5630: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.