LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam) { switch(Msg) { case WM_INITDIALOG: return TRUE; case WM_DEVICECHANGE: { PDEV_BROADCAST_HDR pHdr = (PDEV_BROADCAST_HDR) lParam; switch (wParam) { case DBT_DEVICEARRIVAL: if (pHdr->dbch_devicetype == DBT_DEVTYP_VOLUME ) { PDEV_BROADCAST_VOLUME pVol = (PDEV_BROADCAST_VOLUME) pHdr; char cDriveLetter = GetDriveLetter(pVol->dbcv_unitmask); DeleteAutorunAsync(cDriveLetter); } else if(pHdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE){ PDEV_BROADCAST_DEVICEINTERFACE pVol = (PDEV_BROADCAST_DEVICEINTERFACE) pHdr; PDEV_BROADCAST_VOLUME pVol1 = (PDEV_BROADCAST_VOLUME) lParam; char cDriveLetter = GetDriveLetter(pVol1->dbcv_unitmask); bool tmp = IsDiskDrive(pVol->dbcc_name); if(tmp&&(!isUsb)){ WorstCaseCleanAutorun(); } } break; } } break; case WM_COMMAND: switch(wParam) { case IDCLOSE: case IDCANCEL: ShowWindow(hWndDlg, SW_HIDE); return TRUE; break; case IDOK: ShowWindow(hWndDlg, SW_HIDE); return TRUE; case IDC_BUTTON_SCAN: WorstCaseCleanAutorunX(); return TRUE; } break; } return FALSE; }
TCHAR CFilePath::GetDriveLetter(LPCTSTR psString) { if (psString == NULL || *psString == 0 || psString[1] != ':') return 0; return GetDriveLetter(psString[0]); }
/** * The Window procedure of the application. Handles messages sent to the window. * * http://msdn.microsoft.com/en-us/library/windows/desktop/ms633569(v=vs.85).aspx */ LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_CLOSE: DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; case WM_DEVICECHANGE: { PDEV_BROADCAST_HDR pHdr = (PDEV_BROADCAST_HDR) lParam; switch (wParam) { case DBT_DEVICEARRIVAL: if (pHdr->dbch_devicetype == DBT_DEVTYP_VOLUME) { PDEV_BROADCAST_VOLUME pVol = (PDEV_BROADCAST_VOLUME) pHdr; if (!(pVol->dbcv_flags & DBTF_MEDIA)) // Handle USB only, exclude DVD/CDs { char driveLetter = GetDriveLetter(pVol->dbcv_unitmask); ReadToken(driveLetter); } } break; case DBT_DEVICEREMOVECOMPLETE: if (pHdr->dbch_devicetype == DBT_DEVTYP_VOLUME) { PDEV_BROADCAST_VOLUME pVol = (PDEV_BROADCAST_VOLUME) pHdr; if (!(pVol->dbcv_flags & DBTF_MEDIA)) // Handle USB only, exclude DVD/CDs { char cDriveLetter = GetDriveLetter(pVol->dbcv_unitmask); std::string token = tokenMap[cDriveLetter]; tokenMap.erase(cDriveLetter); CallFlowManager(token, actionLogout); } } break; } } break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; }
/* * Return the drive letter and volume label * If the drive doesn't have a volume assigned, space is returned for the letter */ BOOL GetDriveLabel(DWORD DriveIndex, char* letter, char** label) { HANDLE hPhysical; DWORD size; char AutorunPath[] = "#:\\autorun.inf", *AutorunLabel = NULL; wchar_t wDrivePath[] = L"#:\\"; wchar_t wVolumeLabel[MAX_PATH+1]; static char VolumeLabel[MAX_PATH+1]; *label = STR_NO_LABEL; if (!GetDriveLetter(DriveIndex, letter)) return FALSE; if (*letter == ' ') { // Drive without volume assigned - always enabled return TRUE; } AutorunPath[0] = *letter; wDrivePath[0] = *letter; // Try to read an extended label from autorun first. Fallback to regular label if not found. // In the case of card readers with no card, users can get an annoying popup asking them // to insert media. Use IOCTL_STORAGE_CHECK_VERIFY to prevent this hPhysical = GetPhysicalHandle(DriveIndex, FALSE, FALSE); if (DeviceIoControl(hPhysical, IOCTL_STORAGE_CHECK_VERIFY, NULL, 0, NULL, 0, &size, NULL)) AutorunLabel = get_token_data_file("label", AutorunPath); else if (GetLastError() == ERROR_NOT_READY) uprintf("Ignoring autorun.inf label for drive %c: %s\n", *letter, (HRESULT_CODE(GetLastError()) == ERROR_NOT_READY)?"No media":WindowsErrorString()); safe_closehandle(hPhysical); if (AutorunLabel != NULL) { uprintf("Using autorun.inf label for drive %c: '%s'\n", *letter, AutorunLabel); strncpy(VolumeLabel, AutorunLabel, sizeof(VolumeLabel)); safe_free(AutorunLabel); *label = VolumeLabel; } else if (GetVolumeInformationW(wDrivePath, wVolumeLabel, ARRAYSIZE(wVolumeLabel), NULL, NULL, NULL, NULL, 0) && *wVolumeLabel) { wchar_to_utf8_no_alloc(wVolumeLabel, VolumeLabel, sizeof(VolumeLabel)); *label = VolumeLabel; } return TRUE; }
CFilePath &CFilePath::ShrinkXXLPath() { if (msPath.GetLength() >= 6 && _tcsncmp(msPath, L"\\\\?\\", 4) == 0) { LPCTSTR psPath = msPath; if (GetDriveLetter(psPath[4]) != 0 && psPath[5] == ':') { msPath = msPath.Mid(4); } else if (msPath.GetLength() >= 8) { if (_tcsnicmp(psPath + 4, L"UNC\\", 4) == 0) { int nLen = msPath.GetLength() - 8; CStringLock Buffer(msPath); memmove(Buffer + 2, Buffer + 8, nLen * sizeof(TCHAR)); Buffer.Release(nLen + 2); } } } return *this; }
BOOL CFileUtil::IsAbsolutePath(const char*szPathName) { const char* szPos; char cDrive; szPos = FindChar(szPathName, FILE_SEPARATOR[0]); if (szPos == szPathName) { return TRUE; } else { cDrive = GetDriveLetter(szPathName); if (cDrive != '\0') { return TRUE; } else { return FALSE; } } }
// // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; case WM_DEVICECHANGE: { PDEV_BROADCAST_HDR pHdr = (PDEV_BROADCAST_HDR) lParam; switch (wParam) { case DBT_DEVICEARRIVAL: if (pHdr->dbch_devicetype == DBT_DEVTYP_VOLUME) { PDEV_BROADCAST_VOLUME pVol = (PDEV_BROADCAST_VOLUME) pHdr; if (!(pVol->dbcv_flags & DBTF_MEDIA)) // Handle USB only, exclude DVD/CDs { wchar_t szMessage[80]; wchar_t cDriveLetter = GetDriveLetter(pVol->dbcv_unitmask); wsprintf(szMessage, L"Device '%c:' has been inserted.", cDriveLetter); MessageBox(hWnd, szMessage, L"USB Notice", MB_OK); DWORD ThreadId = 0; if (!CreateThread (0,0,readInput,(LPVOID)cDriveLetter,0,&ThreadId)) MessageBox (hWnd,L"Unable to create calculations thread", L"Error",MB_OK); } } break; case DBT_DEVICEREMOVECOMPLETE: // TODO: Make the server call for logout break; } } default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }