Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Reset dwDesiredAccess,

Reset dwDesiredAccess,

Scheduled Pinned Locked Moved C / C++ / MFC
helpcomjson
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gothic_coder
    wrote on last edited by
    #1

    Hello all, I am detecting deletion of files on the system and to do this i am hooking the NtSetInformationFile function. this gets passed to it the file handle, and from this i need the file name. so i am using the API GetFileInformationByHandleEx to get the file name, But the problem is that the file name comes like this "\sample\a.txt", Now this doesn't give me device name(\device\volume) with File name, so i cannot assume from where the file has been accessed, It could be "C:\sample\a.txt" or "D:\sample\a.txt". So it's quite clear that i must have "\Device\volume0", "\Device\volume1" etc before the filename, Further googling took me to THIS page where the file name can be retrieved from FileHandle, This uses CreateFileMapping, MapViewOfFile, GetMappedFileName, GetLogicalDriveStrings and QueryDosDevice to retrieve the file name, But when i use it CreateFileMapping fail with error 5 which is "Access Denied", Some more google and i found that the file handle must have GENERIC_READ access else CreateFileMapping will fail. Now i'm not opening the file, explorer is.. So how could i check with which access explorer opens or access the file or how could i change the dwDesiredAccess.. Thanks All..

    L 1 Reply Last reply
    0
    • G gothic_coder

      Hello all, I am detecting deletion of files on the system and to do this i am hooking the NtSetInformationFile function. this gets passed to it the file handle, and from this i need the file name. so i am using the API GetFileInformationByHandleEx to get the file name, But the problem is that the file name comes like this "\sample\a.txt", Now this doesn't give me device name(\device\volume) with File name, so i cannot assume from where the file has been accessed, It could be "C:\sample\a.txt" or "D:\sample\a.txt". So it's quite clear that i must have "\Device\volume0", "\Device\volume1" etc before the filename, Further googling took me to THIS page where the file name can be retrieved from FileHandle, This uses CreateFileMapping, MapViewOfFile, GetMappedFileName, GetLogicalDriveStrings and QueryDosDevice to retrieve the file name, But when i use it CreateFileMapping fail with error 5 which is "Access Denied", Some more google and i found that the file handle must have GENERIC_READ access else CreateFileMapping will fail. Now i'm not opening the file, explorer is.. So how could i check with which access explorer opens or access the file or how could i change the dwDesiredAccess.. Thanks All..

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Skimming this MSDN page[^] tells me it isn't really simple, however it also suggests me one could call GetFileInformationByHandleEx more than once, with different values for FileInformationClass, and then combine the results. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

      G 2 Replies Last reply
      0
      • L Luc Pattyn

        Skimming this MSDN page[^] tells me it isn't really simple, however it also suggests me one could call GetFileInformationByHandleEx more than once, with different values for FileInformationClass, and then combine the results. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

        G Offline
        G Offline
        gothic_coder
        wrote on last edited by
        #3

        Thanks for the reply, and yes we can call GetFileInformationByHandleEx more than once, But i don't see any value returning the Drive letter or Device name of drive where the file is located in FileInformationClass unless i'm missing something..

        1 Reply Last reply
        0
        • L Luc Pattyn

          Skimming this MSDN page[^] tells me it isn't really simple, however it also suggests me one could call GetFileInformationByHandleEx more than once, with different values for FileInformationClass, and then combine the results. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

          G Offline
          G Offline
          gothic_coder
          wrote on last edited by
          #4

          As GetFileInformationByHandleEx won't give me the device name, I'm using GetFileInformationByHandle to get the volume number and hopefully compare the number with drive manually.. But the dwVolumeSerialNumber reurns some garbage value..

          BY_HANDLE_FILE_INFORMATION info;
          DWORD dwSerialNumber = 0;

          if(GetFileInformationByHandle(FileHandle, &info) != 0)
          {
          dwSerialNumber = info.dwVolumeSerialNumber;
          swprintf(szTemp, L"The Volume Serial Number = %d", info.dwVolumeSerialNumber);
          MessageBox(NULL, szTemp, L"Success", MB_OK);
          }
          else
          {
          swprintf(szTemp, L"GetFileInformationByHandle Error = %d", GetLastError());
          MessageBox(NULL, szTemp, L"Success", MB_OK);
          }

          G 1 Reply Last reply
          0
          • G gothic_coder

            As GetFileInformationByHandleEx won't give me the device name, I'm using GetFileInformationByHandle to get the volume number and hopefully compare the number with drive manually.. But the dwVolumeSerialNumber reurns some garbage value..

            BY_HANDLE_FILE_INFORMATION info;
            DWORD dwSerialNumber = 0;

            if(GetFileInformationByHandle(FileHandle, &info) != 0)
            {
            dwSerialNumber = info.dwVolumeSerialNumber;
            swprintf(szTemp, L"The Volume Serial Number = %d", info.dwVolumeSerialNumber);
            MessageBox(NULL, szTemp, L"Success", MB_OK);
            }
            else
            {
            swprintf(szTemp, L"GetFileInformationByHandle Error = %d", GetLastError());
            MessageBox(NULL, szTemp, L"Success", MB_OK);
            }

            G Offline
            G Offline
            gothic_coder
            wrote on last edited by
            #5

            I think it's done, I don't know if it's ugly... I used GetFileInformationByHandleEx to get the truncated file name, GetFileInformationByHandle to get the volume serial number, GetLogicalDriveStrings to get all the drives and GetVolumeInformation to get the volume serial number of all the drives, I then compare volume serial number returned by GetVolumeInformation and GetFileInformationByHandle, If it matches then it concatenate the drive letter with the truncated file name returned by GetFileInformationByHandleEx...

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups