Advertisement
Brick

NtPathToDosPath

Jan 26th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. bool NtPathToDosPath(const wchar_t* ntPath, wchar_t* buffer, size_t length)
  2. {
  3.     wchar_t device_name[3] = L"A:";
  4.     wchar_t target_path[128];
  5.  
  6.     for (wchar_t i = L'A'; i <= L'Z'; ++i)
  7.     {
  8.         device_name[0] = i;
  9.  
  10.         if (QueryDosDeviceW(device_name, target_path, 128))
  11.         {
  12.             size_t target_length = wcslen(target_path);
  13.  
  14.             if (!_wcsnicmp(ntPath, target_path, target_length))
  15.             {
  16.                 wcscpy_s(buffer, length, device_name);
  17.                 wcscat_s(buffer, length, ntPath + target_length);
  18.  
  19.                 return true;
  20.             }
  21.         }
  22.     }
  23.  
  24.     return false;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement