SHARE
TWEET

Untitled

a guest Jan 24th, 2020 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class NDC : public IO_OBJECT
  2. {
  3.     virtual ~NDC() { DbgPrint("~NDC(for demo only)\n"); }
  4.  
  5.     union {
  6.         FILE_NOTIFY_INFORMATION fni;
  7.         UCHAR buf[0x1000];
  8.     };
  9.  
  10.     void Start()
  11.     {
  12.         HANDLE hFile;
  13.         if (LockHandle(hFile))
  14.         {
  15.             if (IO_IRP* irp = new IO_IRP(this, 0, 0))
  16.             {
  17.                 irp->CheckError(ReadDirectoryChangesW(hFile, buf, sizeof(buf), TRUE, FILE_NOTIFY_VALID_MASK, 0, irp, 0));
  18.             }
  19.             UnlockHandle();
  20.         }
  21.     }
  22.  
  23.     virtual void IOCompletionRoutine(CDataPacket* /*packet*/, DWORD /*Code*/, NTSTATUS status, ULONG_PTR dwNumberOfBytesTransfered, PVOID /*Pointer*/)
  24.     {
  25.         DbgPrint("IOCompletionRoutine(%u, %p)\n", status, dwNumberOfBytesTransfered);
  26.  
  27.         switch (status)
  28.         {
  29.         case ERROR_NOTIFY_ENUM_DIR:
  30.         case NOERROR:
  31.             union {
  32.                 PBYTE pb;
  33.                 PFILE_NOTIFY_INFORMATION pfni;
  34.             };
  35.  
  36.             pfni = &fni;
  37.             ULONG NextEntryOffset = 0;
  38.             do
  39.             {
  40.                 pb += NextEntryOffset;
  41.                 DbgPrint("[%u] %.*S\n", pfni->Action, pfni->FileNameLength / sizeof(WCHAR), pfni->FileName);
  42.             } while (NextEntryOffset = pfni->NextEntryOffset);
  43.  
  44.             //Sleep(4000);// !!!
  45.  
  46.             Start();
  47.         }
  48.     }
  49.  
  50. public:
  51.     ULONG Create(PCWSTR psz)
  52.     {
  53.         HANDLE hFile = CreateFileW(psz, FILE_GENERIC_READ, FILE_SHARE_VALID_FLAGS, 0, OPEN_EXISTING,
  54.             FILE_FLAG_OVERLAPPED | FILE_FLAG_BACKUP_SEMANTICS, 0);
  55.  
  56.         if (hFile != INVALID_HANDLE_VALUE)
  57.         {
  58.             Assign(hFile);
  59.            
  60.             if (ULONG dwError = IO_IRP::BindIoCompletion(hFile))
  61.             {
  62.                 return dwError;
  63.             }
  64.  
  65.             Start();
  66.  
  67.             return NOERROR;
  68.         }
  69.  
  70.         return GetLastError();
  71.     }
  72. };
  73.  
  74.     initterm();
  75.     if (NDC* p = new NDC)
  76.     {
  77.         p->Create(L"<some folder where you copy/delete/edit files>");
  78.         MessageBoxW(0, 0, L"Start motitor and UI running", MB_ICONINFORMATION);
  79.         p->Close();
  80.         p->Release();
  81.         MessageBoxW(0, 0, L"Stop monitor", MB_ICONINFORMATION);
  82.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top