📄 dlgcode.c
字号:
case 0x93: strcpy(partType, "Hidden Linux"); break;
case 0x86:
case 0x87: strcpy(partType, "NTFS volume set"); break;
case 0x9f: strcpy(partType, "BSD/OS"); break;
case 0xa0:
case 0xa1: strcpy(partType, "Hibernation"); break;
case 0xa5: strcpy(partType, "BSD"); break;
case 0xa8: strcpy(partType, "Mac OS-X"); break;
case 0xa9: strcpy(partType, "NetBSD"); break;
case 0xab: strcpy(partType, "Mac OS-X Boot"); break;
case 0xb8: strcpy(partType, "BSDI BSD/386 swap"); break;
case 0xc3: strcpy(partType, "Hidden Linux swap"); break;
case 0xfb: strcpy(partType, "VMware"); break;
case 0xfc: strcpy(partType, "VMware swap"); break;
case 0xfd: strcpy(partType, "Linux RAID"); break;
case 0xfe: strcpy(partType, "WinNT hidden"); break;
default: sprintf(partType, "0x%02X", diskInfo.PartitionType); break;
}
if (diskInfo.PartitionLength.QuadPart > 1024I64*1024*1024*1024*1024*99)
sprintf (item1,"%d PB", diskInfo.PartitionLength.QuadPart/1024/1024/1024/1024/1024);
else if (diskInfo.PartitionLength.QuadPart > 1024I64*1024*1024*1024*1024)
sprintf (item1,"%.1f PB",(double)(diskInfo.PartitionLength.QuadPart/1024.0/1024/1024/1024/1024));
else if (diskInfo.PartitionLength.QuadPart > 1024I64*1024*1024*1024*99)
sprintf (item1,"%d TB",diskInfo.PartitionLength.QuadPart/1024.0/1024/1024/1024);
else if (diskInfo.PartitionLength.QuadPart > 1024I64*1024*1024*1024)
sprintf (item1,"%.1f TB",(double)(diskInfo.PartitionLength.QuadPart/1024.0/1024/1024/1024));
else if (diskInfo.PartitionLength.QuadPart > 1024I64*1024*1024*99)
sprintf (item1,"%d GB",diskInfo.PartitionLength.QuadPart/1024/1024/1024);
else if (diskInfo.PartitionLength.QuadPart > 1024I64*1024*1024)
sprintf (item1,"%.1f GB",(double)(diskInfo.PartitionLength.QuadPart/1024.0/1024/1024));
else
sprintf (item1,"%d MB", diskInfo.PartitionLength.QuadPart/1024/1024);
strcpy (item2, partType);
}
}
if (n == 0)
{
deviceSize = diskInfo.PartitionLength.QuadPart;
sprintf (szTmp, "Harddisk %d:", i);
}
memset (&LvItem,0,sizeof(LvItem));
LvItem.mask = LVIF_TEXT;
LvItem.iItem = line++;
// Device Name
LvItem.pszText = szTmp;
SendMessage (hComboBox,LVM_INSERTITEM,0,(LPARAM)&LvItem);
// Size
LvItem.iSubItem = 2;
LvItem.pszText = item1;
SendMessage (hComboBox,LVM_SETITEM,0,(LPARAM)&LvItem);
// Device type removable
if (n == 0 && removable)
{
LvItem.iSubItem = 3;
LvItem.pszText = "Removable";
SendMessage (hComboBox,LVM_SETITEM,0,(LPARAM)&LvItem);
}
if (n > 0)
{
char drive[] = { 0, ':', 0 };
char device[MAX_PATH * 2];
int driveNo;
// Drive letter
strcpy (device, szTmp);
ToUNICODE (device);
driveNo = GetDiskDeviceDriveLetter ((PWSTR) device);
drive[0] = driveNo == -1 ? 0 : 'A' + driveNo;
LvItem.iSubItem = 1;
LvItem.pszText = drive;
SendMessage (hComboBox,LVM_SETITEM,0,(LPARAM)&LvItem);
// Partition type
LvItem.iSubItem = 3;
LvItem.pszText = item2;
SendMessage (hComboBox,LVM_SETITEM,0,(LPARAM)&LvItem);
}
// Mark device with partitions, removable drives are not marked to allow
// users silent overwrite of existing partitions as system does not
// support partition management of removable drives
if (n == 1 && !removable)
{
LvItem.iItem = line - 2;
LvItem.iSubItem = 3;
LvItem.pszText = " ";
SendMessage (hComboBox,LVM_SETITEM,0,(LPARAM)&LvItem);
}
}
else if (n == 0)
break;
}
if (drivePresent)
{
memset (&LvItem,0,sizeof(LvItem));
LvItem.mask = LVIF_TEXT;
LvItem.iItem = line++;
LvItem.pszText = "";
SendMessage (hComboBox,LVM_INSERTITEM,0,(LPARAM)&LvItem);
}
}
i = SendMessage (hComboBox, LVM_GETITEMCOUNT, 0, 0);
if (i != CB_ERR)
return i;
else
return 0;
}
int
GetAvailableRemovables (HWND hComboBox, char *lpszRootPath)
{
char szTmp[TC_MAX_PATH];
int i;
LVITEM LvItem;
if (lpszRootPath); /* Remove unused parameter warning */
if (nCurrentOS != WIN_NT)
return 0;
memset (&LvItem,0,sizeof(LvItem));
LvItem.mask = LVIF_TEXT;
LvItem.iItem = SendMessage (hComboBox, LVM_GETITEMCOUNT, 0, 0)+1;
if (QueryDosDevice ("A:", szTmp, sizeof (szTmp)) != 0)
{
LvItem.pszText = "\\Device\\Floppy0";
LvItem.iItem = SendMessage (hComboBox,LVM_INSERTITEM,0,(LPARAM)&LvItem);
LvItem.iSubItem = 1;
LvItem.pszText = "A:";
SendMessage (hComboBox,LVM_SETITEM,0,(LPARAM)&LvItem);
}
if (QueryDosDevice ("B:", szTmp, sizeof (szTmp)) != 0)
{
LvItem.pszText = "\\Device\\Floppy1";
LvItem.iSubItem = 0;
LvItem.iItem = SendMessage (hComboBox, LVM_GETITEMCOUNT, 0, 0)+1;
LvItem.iItem = SendMessage (hComboBox,LVM_INSERTITEM,0,(LPARAM)&LvItem);
LvItem.iSubItem = 1;
LvItem.pszText = "B:";
SendMessage (hComboBox,LVM_SETITEM,0,(LPARAM)&LvItem);
}
i = SendMessage (hComboBox, LVM_GETITEMCOUNT, 0, 0);
if (i != CB_ERR)
return i;
else
return 0;
}
BOOL WINAPI
RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
static char *lpszFileName;
WORD lw = LOWORD (wParam);
if (lParam); /* remove warning */
switch (msg)
{
case WM_INITDIALOG:
{
int nCount;
LVCOLUMN LvCol;
HWND hList = GetDlgItem (hwndDlg, IDC_DEVICELIST);
SetDefaultUserFont (hwndDlg);
SendMessage (hList,LVM_SETEXTENDEDLISTVIEWSTYLE,0,
LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP|LVS_EX_TWOCLICKACTIVATE
);
memset (&LvCol,0,sizeof(LvCol));
LvCol.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_FMT;
LvCol.pszText = "Device";
LvCol.cx =154;
LvCol.fmt = LVCFMT_LEFT;
SendMessage (hList,LVM_INSERTCOLUMN,0,(LPARAM)&LvCol);
LvCol.pszText = "Drive";
LvCol.cx = 38;
LvCol.fmt = LVCFMT_LEFT;
SendMessage (hList,LVM_INSERTCOLUMN,1,(LPARAM)&LvCol);
LvCol.pszText = "Size";
LvCol.cx = 62;
LvCol.fmt = LVCFMT_RIGHT;
SendMessage (hList,LVM_INSERTCOLUMN,2,(LPARAM)&LvCol);
LvCol.pszText = "Type";
LvCol.cx = 112;
LvCol.fmt = LVCFMT_LEFT;
SendMessage (hList,LVM_INSERTCOLUMN,3,(LPARAM)&LvCol);
nCount = GetAvailableFixedDisks (hList, "\\Device\\Harddisk%d\\Partition%d");
nCount += GetAvailableRemovables (hList, "\\Device\\Floppy%d");
if (nCount == 0)
{
handleWin32Error (hwndDlg);
MessageBox (hwndDlg, getstr (IDS_RAWDEVICES), lpszTitle, ICON_HAND);
EndDialog (hwndDlg, IDCANCEL);
}
lpszFileName = (char *) lParam;
return 1;
}
case WM_COMMAND:
case WM_NOTIFY:
// catch non-device line selected
if (msg == WM_NOTIFY && ((LPNMHDR) lParam)->code == LVN_ITEMCHANGED && (((LPNMLISTVIEW) lParam)->uNewState & LVIS_FOCUSED ))
{
LVITEM LvItem;
memset(&LvItem,0,sizeof(LvItem));
LvItem.mask = LVIF_TEXT;
LvItem.iItem = ((LPNMLISTVIEW) lParam)->iItem;
LvItem.pszText = lpszFileName;
LvItem.cchTextMax = TC_MAX_PATH;
SendMessage (GetDlgItem (hwndDlg, IDC_DEVICELIST), LVM_GETITEMTEXT, LvItem.iItem, (LPARAM) &LvItem);
EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), lpszFileName[0] != 0 && lpszFileName[0] != ' ');
return 1;
}
if (msg == WM_COMMAND && lw == IDOK || msg == WM_NOTIFY && ((NMHDR *)lParam)->code == LVN_ITEMACTIVATE)
{
LVITEM LvItem;
memset (&LvItem,0,sizeof(LvItem));
LvItem.mask = LVIF_TEXT;
LvItem.iItem = SendMessage (GetDlgItem (hwndDlg, IDC_DEVICELIST), LVM_GETSELECTIONMARK, 0, 0);
LvItem.pszText = lpszFileName;
LvItem.cchTextMax = TC_MAX_PATH;
SendMessage (GetDlgItem (hwndDlg, IDC_DEVICELIST), LVM_GETITEMTEXT, LvItem.iItem, (LPARAM) &LvItem);
if (lpszFileName[0] == 'H')
{
// Whole device selected
int driveNo;
sscanf (lpszFileName, "Harddisk %d", &driveNo);
sprintf (lpszFileName, "\\Device\\Harddisk%d\\Partition0", driveNo);
#ifdef VOLFORMAT
// Warn if device contains partitions
{
char tmp[10];
LvItem.iSubItem = 3;
LvItem.pszText = tmp;
SendMessage (GetDlgItem (hwndDlg, IDC_DEVICELIST), LVM_GETITEMTEXT, LvItem.iItem, (LPARAM) &LvItem);
if (tmp[0] == ' ')
{
if (IDNO == MessageBox (hwndDlg, getstr (IDS_DEVICE_PARTITIONS_WARN),
lpszTitle, MB_YESNO|MB_ICONWARNING|MB_DEFBUTTON2))
break;
}
}
#endif
}
if (lpszFileName[0] == 0)
break; // non-device line selected
EndDialog (hwndDlg, IDOK);
return 0;
}
if (lw == IDCANCEL)
{
EndDialog (hwndDlg, IDCANCEL);
return 0;
}
return 0;
}
return 0;
}
// Install and start driver service and mark it for removal (non-install mode)
static int DriverLoad ()
{
HANDLE file;
WIN32_FIND_DATA find;
SC_HANDLE hManager, hService = NULL;
char driverPath[TC_MAX_PATH*2];
BOOL res;
char *tmp;
GetModuleFileName (NULL, driverPath, sizeof (driverPath));
tmp = strrchr (driverPath, '\\');
if (!tmp)
{
strcpy (driverPath, ".");
tmp = driverPath + 1;
}
strcpy (tmp, "\\truecrypt.sys");
file = FindFirstFile (driverPath, &find);
if (file == INVALID_HANDLE_VALUE)
{
MessageBox (0, getstr (IDS_DRIVER_NOT_FOUND), lpszTitle, ICON_HAND);
return ERR_DONT_REPORT;
}
FindClose (file);
hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (hManager == NULL)
{
if (GetLastError () == ERROR_ACCESS_DENIED)
{
MessageBox (0, getstr (IDS_ADMIN_PRIVILEGES_DRIVER), lpszTitle, ICON_HAND);
return ERR_DONT_REPORT;
}
return ERR_OS_ERROR;
}
hService = CreateService (hManager, "truecrypt", "truecrypt",
SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,
driverPath, NULL, NULL, NULL, NULL, NULL);
if (hService == NULL)
{
CloseServiceHandle (hManager);
return ERR_OS_ERROR;
}
res = StartService (hService, 0, NULL);
DeleteService (hService);
CloseServiceHandle (hManager);
CloseServiceHandle (hService);
return !res ? ERR_OS_ERROR : ERROR_SUCCESS;
}
BOOL DriverUnload ()
{
MOUNT_LIST_STRUCT driver;
int refCount;
DWORD dwResult;
BOOL bResult;
SC_HANDLE hManager, hService = NULL;
BOOL bOK = FALSE, bRet;
SERVICE_STATUS status;
int x;
if (hDriver == INVALID_HANDLE_VALUE)
return TRUE;
// Test for mounted volumes
bResult = DeviceIoControl (hDriver, MOUNT_LIST, &driver, sizeof (driver), &driver,
sizeof (driver), &dwResult, NULL);
if (bResult == TRUE)
{
if (driver.ulMountedDrives != 0)
return FALSE;
}
else
return TRUE;
// Test for any applications attached to driver
bResult = DeviceIoControl (hDriver, DEVICE_REFCOUNT, &refCount, sizeof (refCount), &refCount,
sizeof (refCount), &dwResult, NULL);
if (bResult == TRUE)
{
if (refCount > 1)
return FALSE;
}
else
return TRUE;
CloseHandle (hDriver);
// Stop driver service
hManager = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (hManager == NULL)
goto error;
hService = OpenService (hManager, "truecrypt", SERVICE_ALL_ACCESS);
if (hService == NULL)
goto error;
bRet = QueryServiceStatus (hService, &status);
if (bRet != TRUE)
goto error;
if (status.dwCurrentState != SERVICE_STOPPED)
{
ControlService (hService, SERVICE_CONTROL_STOP, &status);
for (x = 0; x < 5; x++)
{
bRet = QueryServiceStatus (hService, &status);
if (bRet != TRUE)
goto error;
if (status.dwCurrentState == SERVICE_STOPPED)
break;
Sleep (200);
}
}
error:
if (hService != NULL)
CloseServiceHandle (hService);
if (hManager != NULL)
CloseServiceHandle (hManager);
if (status.dwCurrentState == SERVICE_STOPPED)
{
hDriver = INVALID_HANDLE_VALUE;
return TRUE;
}
return FALSE;
}
int
DriverAttach (void)
{
/* Try to open a handle to the device driver. It will be closed later. */
hDriver = CreateFile (WIN32_ROOT_PREFIX, 0, 0, NULL, OPEN_EXISTING, 0, NULL);
if (hDriver == INVALID_HANDLE_VALUE)
{
#ifndef SETUP
// Attempt to load driver (non-install mode)
BOOL res = DriverLoad ();
if (res != ERROR_SUCCESS)
return res;
hDriver = CreateFile (WIN32_ROOT_PREFIX, 0, 0, NULL, OPEN_EXISTING, 0, NULL);
#endif
if (hDriver == INVALID_HANDLE_VALUE)
return ERR_OS_ERROR;
}
#ifndef SETUP // Don't check version during setup to allow removal of another version
if (hDriver != INVALID_HANDLE_VALUE)
{
LONG driver = 0;
DWORD dwResult;
BOOL bResult = DeviceIoControl (hDriver, DRIVER_VERSION,
&driver, 4, &driver, 4, &dwResult, NULL);
if (bResult == FALSE)
return ERR_OS_ERROR;
else if (driver != VERSION_NUM)
return ERR_DRIVER_VERSION;
}
#endif
return 0;
}
// Sets file pointer to hidden volume header
BOOL SeekHiddenVolHeader (HFILE dev, unsigned __int64 volSize, BOOL deviceFlag)
{
LARGE_INTEGER offset, offsetNew;
if (deviceFlag)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -