/* Legal Notice: Some portions of the source code contained in this file were derived from the source code of TrueCrypt 7.1a, which is Copyright (c) 2003-2012 TrueCrypt Developers Association and which is governed by the TrueCrypt License 3.0, also from the source code of Encryption for the Masses 2.02a, which is Copyright (c) 1998-2000 Paul Le Roux and which is governed by the 'License Agreement for Encryption for the Masses' Modifications and additions to the original source code (contained in this file) and all other portions of this file are Copyright (c) 2013-2015 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ #ifdef __cplusplus #include "Favorites.h" extern "C" { #endif enum mount_list_item_types { TC_MLIST_ITEM_FREE = 0, TC_MLIST_ITEM_NONSYS_VOL, TC_MLIST_ITEM_SYS_PARTITION, TC_MLIST_ITEM_SYS_DRIVE }; #define TC_MAIN_WINDOW_FLAG_ADMIN_PRIVILEGES 0x1 #define TRAYICON_MENU_DRIVE_OFFSET 9000 #define TC_FAVORITE_MENU_CMD_ID_OFFSET 10000 #define TC_FAVORITE_MENU_CMD_ID_OFFSET_END (TC_FAVORITE_MENU_CMD_ID_OFFSET + 1000) #define WM_COPY_SET_VOLUME_NAME "VNAM" #define ENC_SYSDRIVE_PSEUDO_DRIVE_LETTER ('A' - 1) /* Password Change dialog modes */ enum { PCDM_CHANGE_PASSWORD = 0, PCDM_CHANGE_PKCS5_PRF, PCDM_ADD_REMOVE_VOL_KEYFILES, PCDM_REMOVE_ALL_KEYFILES_FROM_VOL }; typedef struct { BOOL bHidVolDamagePrevReported[26]; } VOLUME_NOTIFICATIONS_LIST; typedef struct { Password *password; int* pkcs5; int* pim; BOOL* truecryptMode; } PasswordDlgParam; extern VOLUME_NOTIFICATIONS_LIST VolumeNotificationsList; extern BOOL bEnableBkgTask; extern BOOL bCloseBkgTaskWhenNoVolumes; extern BOOL bPlaySoundOnSuccessfulHkDismount; extern BOOL bDisplayBalloonOnSuccessfulHkDismount; extern BOOL bExplore; extern BOOL bTryEmptyPasswordWhenKeyfileUsed; static void localcleanup ( void ); void EndMainDlg ( HWND hwndDlg ); void EnableDisableButtons ( HWND hwndDlg ); BOOL VolumeSelected (HWND hwndDlg ); void LoadSettings ( HWND hwndDlg ); void SaveSettings ( HWND hwndDlg ); BOOL SelectItem ( HWND hTree , wchar_t nLetter ); void LoadDriveLetters ( HWND hwndDlg, HWND hTree, int drive ); BOOL CALLBACK PasswordChangeDlgProc ( HWND hwndDlg , UINT msg , WPARAM wParam , LPARAM lParam ); BOOL CALLBACK PasswordDlgProc ( HWND hwndDlg , UINT msg , WPARAM wParam , LPARAM lParam ); BOOL CALLBACK MountOptionsDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); void BuildTree ( HWND hwndDlg, HWND hTree ); LPARAM GetSelectedLong ( HWND hTree ); LPARAM GetItemLong ( HWND hTree, int itemNo ); BOOL CALLBACK CommandHelpDlgProc ( HWND hwndDlg , UINT msg , WPARAM wParam , LPARAM lParam ); BOOL CALLBACK MainDialogProc ( HWND hwndDlg , UINT uMsg , WPARAM wParam , LPARAM lParam ); void ExtractCommandLine ( HWND hwndDlg , wchar_t *lpszCommandLine ); static void WipeCache (HWND hwndDlg, BOOL silent); void OpenVolumeExplorerWindow (int driveNo); BOOL TaskBarIconAdd (HWND hwnd); BOOL TaskBarIconRemove (HWND hwnd); BOOL TaskBarIconChange (HWND hwnd, int iconId); void DismountIdleVolumes (); static void SaveDefaultKeyFilesParam (HWND hwnd); static BOOL Dismount (HWND hwndDlg, int nDosDriveNo); static BOOL DismountAll (HWND hwndDlg, BOOL forceUnmount, BOOL interact, int dismountMaxRetries, int dismountAutoRetryDelay); static void KeyfileDefaultsDlg (HWND hwndDlg); static void HandleHotKey (HWND hwndDlg, WPARAM wParam); static BOOL CheckMountList (HWND hwndDlg, BOOL bForceTaskBarUpdate); int GetCipherBlockSizeByDriveNo (int nDosDriveNo); int GetModeOfOperationByDriveNo (int nDosDriveNo); void ChangeMainWindowVisibility (); void LaunchVolCreationWizard (HWND hwndDlg); BOOL WholeSysDriveEncryption (BOOL bSilent); BOOL CheckSysEncMountWithoutPBA (HWND hwndDlg, const wchar_t *devicePath, BOOL quiet); BOOL TCBootLoaderOnInactiveSysEncDrive (wchar_t *szDevicePath); void CreateRescueDisk (HWND hwndDlg); int BackupVolumeHeader (HWND hwndDlg, BOOL bRequireConfirmation, const wchar_t *lpszVolume); int RestoreVolumeHeader (HWND hwndDlg, const wchar_t *lpszVolume); void SecurityTokenPreferencesDialog (HWND hwndDlg); static BOOL CALLBACK PerformanceSettingsDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); static BOOL CALLBACK BootLoaderPreferencesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); void MountSelectedVolume (HWND hwndDlg, BOOL mountWithOptions); uint32 ReadDriverConfigurationFlags (); void HookMouseWheel (HWND hwndDlg, UINT ctrlId); static BOOL HandleDriveListMouseWheelEvent (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL bListMustBePointed); static BOOL CALLBACK DefaultMountParametersDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); #ifdef __cplusplus } typedef struct { BOOL systemFavorites; BOOL logOnMount; BOOL hotKeyMount; VeraCrypt::FavoriteVolume* favoriteVolumeToMount; } mountFavoriteVolumeThreadParam; void SetDriverConfigurationFlag (uint32 flag, BOOL state); BOOL MountFavoriteVolumes (HWND hwnd, BOOL systemFavorites = FALSE, BOOL logOnMount = FALSE, BOOL hotKeyMount = FALSE, const VeraCrypt::FavoriteVolume &favoriteVolumeToMount = VeraCrypt::FavoriteVolume()); void __cdecl mountFavoriteVolumeThreadFunction (void *pArg); #endif id='n59' href='#n59'>59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
;
; Copyright (c) 2008-2009 TrueCrypt Developers Association. All rights reserved.
;
; Governed by the TrueCrypt License 3.0 the full text of which is contained in
; the file License.txt included in TrueCrypt binary and source code distribution
; packages.
;
.MODEL tiny
.386
_TEXT SEGMENT USE16
INCLUDE BootDefs.i
ORG 7C00h ; Standard boot sector offset
start:
; BIOS executes boot sector from 0:7C00 or 7C0:0000 (default CD boot loader address).
; Far jump to the next instruction sets IP to the standard offset 7C00.
db 0EAh ; jmp 0:main
dw main, 0
loader_name_msg:
db ' VeraCrypt Boot Loader', 13, 10, 0
main:
cli
xor ax, ax
mov ds, ax
mov ss, ax
mov sp, 7C00h
sti
; Display boot loader name
test byte ptr [start + TC_BOOT_SECTOR_USER_CONFIG_OFFSET], TC_BOOT_USER_CFG_FLAG_SILENT_MODE
jnz skip_loader_name_msg
lea si, loader_name_msg
call print
skip_loader_name_msg:
; Determine boot loader segment
mov ax, TC_BOOT_LOADER_SEGMENT
; Check available memory
cmp word ptr [ds:413h], TC_BOOT_LOADER_SEGMENT / 1024 * 16 + TC_BOOT_MEMORY_REQUIRED
jge memory_ok
mov ax, TC_BOOT_LOADER_SEGMENT_LOW
cmp word ptr [ds:413h], TC_BOOT_LOADER_SEGMENT_LOW / 1024 * 16 + TC_BOOT_MEMORY_REQUIRED
jge memory_ok
; Insufficient memory
mov ax, TC_BOOT_LOADER_LOWMEM_SEGMENT
memory_ok:
mov es, ax
; Clear BSS section
xor al, al
mov di, TC_COM_EXECUTABLE_OFFSET
mov cx, TC_BOOT_MEMORY_REQUIRED * 1024 - TC_COM_EXECUTABLE_OFFSET - 1
cld
rep stosb
mov ax, es
sub ax, TC_BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE / 16 ; Decompressor segment
mov es, ax
; Load decompressor
mov cl, TC_BOOT_LOADER_DECOMPRESSOR_START_SECTOR
retry_backup:
mov al, TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT
mov bx, TC_COM_EXECUTABLE_OFFSET
call read_sectors
; Decompressor checksum
xor ebx, ebx
mov si, TC_COM_EXECUTABLE_OFFSET
mov cx, TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT * TC_LB_SIZE
call checksum
push ebx
; Load compressed boot loader
mov bx, TC_BOOT_LOADER_COMPRESSED_BUFFER_OFFSET
mov cl, TC_BOOT_LOADER_START_SECTOR
mov al, TC_MAX_BOOT_LOADER_SECTOR_COUNT
test backup_loader_used, 1
jz non_backup
mov al, TC_BOOT_LOADER_BACKUP_SECTOR_COUNT - TC_BOOT_LOADER_DECOMPRESSOR_SECTOR_COUNT
mov cl, TC_BOOT_LOADER_START_SECTOR + TC_BOOT_LOADER_BACKUP_SECTOR_COUNT
non_backup:
call read_sectors
; Boot loader checksum
pop ebx
mov si, TC_BOOT_LOADER_COMPRESSED_BUFFER_OFFSET
mov cx, word ptr [start + TC_BOOT_SECTOR_LOADER_LENGTH_OFFSET]
call checksum
; Verify checksum
cmp ebx, dword ptr [start + TC_BOOT_SECTOR_LOADER_CHECKSUM_OFFSET]
je checksum_ok
; Checksum incorrect - try using backup if available
test backup_loader_used, 1
jnz loader_damaged
mov backup_loader_used, 1
mov cl, TC_BOOT_LOADER_DECOMPRESSOR_START_SECTOR + TC_BOOT_LOADER_BACKUP_SECTOR_COUNT
test TC_BOOT_CFG_FLAG_BACKUP_LOADER_AVAILABLE, byte ptr [start + TC_BOOT_SECTOR_CONFIG_OFFSET]
jnz retry_backup
loader_damaged:
lea si, loader_damaged_msg
call print
lea si, loader_name_msg
call print
jmp $
checksum_ok:
; Set up decompressor segment
mov ax, es
mov ds, ax
cli
mov ss, ax
mov sp, TC_BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE
sti
push dx
; Decompress boot loader
mov cx, word ptr [start + TC_BOOT_SECTOR_LOADER_LENGTH_OFFSET]
push cx ; Compressed data size
push TC_BOOT_LOADER_COMPRESSED_BUFFER_OFFSET + TC_GZIP_HEADER_SIZE ; Compressed data
push TC_MAX_BOOT_LOADER_DECOMPRESSED_SIZE ; Output buffer size
push TC_BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE + TC_COM_EXECUTABLE_OFFSET ; Output buffer
push cs
push decompressor_ret
push es
push TC_COM_EXECUTABLE_OFFSET
retf
decompressor_ret:
add sp, 8
pop dx
; Restore boot sector segment
push cs
pop ds
; Check decompression result
test ax, ax
jz decompression_ok
lea si, loader_damaged_msg
call print
jmp $
decompression_ok:
; DH = boot sector flags
mov dh, byte ptr [start + TC_BOOT_SECTOR_CONFIG_OFFSET]
; Set up boot loader segment
mov ax, es
add ax, TC_BOOT_LOADER_DECOMPRESSOR_MEMORY_SIZE / 16
mov es, ax
mov ds, ax
cli
mov ss, ax
mov sp, TC_BOOT_LOADER_STACK_TOP
sti
; Execute boot loader
push es
push TC_COM_EXECUTABLE_OFFSET
retf
; Print string
print:
xor bx, bx
mov ah, 0eh
cld
@@: lodsb
test al, al
jz print_end
int 10h
jmp @B
print_end:
ret
; Read sectors of the first cylinder
read_sectors:
mov ch, 0 ; Cylinder
mov dh, 0 ; Head
; DL = drive number passed from BIOS
mov ah, 2
int 13h
jnc read_ok
lea si, disk_error_msg
call print
read_ok:
ret
; Calculate checksum
checksum:
push ds
push es
pop ds
xor eax, eax
cld
@@: lodsb
add ebx, eax
rol ebx, 1
loop @B
pop ds
ret
backup_loader_used db 0
disk_error_msg db 'Disk error', 13, 10, 7, 0
loader_damaged_msg db 7, 'Loader damaged! Use Rescue Disk: Repair Options > Restore', 0
ORG 7C00h + 510
dw 0AA55h ; Boot sector signature
_TEXT ENDS
END start