pastebin - collaborative debugging tool
nrubsig.kpaste.net RSS


test-qfif1.c
Posted by Anonymous on Fri 17th Nov 2023 09:13
raw | new post
modification of post by Anonymous (view diff)

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <wchar.h>
  4. #include <errno.h>
  5. #include <locale.h>
  6. #include <limits.h>
  7. //#include <windows.h>
  8. //#include <ntdef.h>
  9.  
  10. //#include <w32api/wtypesbase.h>
  11. //#include <windef.h>
  12. #include <wdm.h>
  13.  
  14. typedef unsigned int DWORD;
  15. typedef unsigned int HMODULE;
  16. #define MAX_PATH 260
  17.  
  18. #include <sys/cygwin.h>
  19.  
  20.  
  21. int
  22. main (int argc, char **argv)
  23. {
  24.   WCHAR pathbuf[1024]; /* Should be big enough for this test */
  25.   WCHAR *path;
  26.   UNICODE_STRING upath;
  27.   OBJECT_ATTRIBUTES attr, attr2;
  28.   NTSTATUS status;
  29.   HANDLE h;
  30.   IO_STATUS_BLOCK io;
  31.   FILE_NETWORK_OPEN_INFORMATION fnoi;
  32.  
  33.   if (argc < 2)
  34.     {
  35.       fprintf (stderr, "Usage: %s path\n", argv[0]);
  36.       return 1;
  37.     }
  38.   setlocale (LC_ALL, "");
  39.   while (--argc > 0)
  40.     {
  41.       if (cygwin_conv_path (CCP_POSIX_TO_WIN_W, *++argv, pathbuf + 6,
  42.                         1024 * sizeof (WCHAR)))
  43.         {
  44.           fprintf (stderr, "%s: Path conversion failed: %s\n",
  45.                    strerror (errno));
  46.           continue;
  47.         }
  48.       if (pathbuf[6] == L'\\' && pathbuf[7] == L'\\')
  49.         path = wcsncpy (pathbuf, L"\\??\\UNC", 7);
  50.       else
  51.         path = wcsncpy (pathbuf + 2, L"\\??\\", 4);
  52.  
  53.       RtlInitUnicodeString (&upath, path);
  54.       InitializeObjectAttributes (&attr, &upath, OBJ_CASE_INSENSITIVE,
  55.                                   NULL, NULL);
  56.       status = NtQueryFullAttributesFile (&attr, &fnoi);
  57.       if (!NT_SUCCESS (status))
  58.         printf ("NtQueryFullAttributesFile(%ls) by name failed,\n"
  59.                 "status code 0x%08lx\n", path, status);
  60.       else
  61.         printf ("NtQueryFullAttributesFile(%ls) by name works\n", path);
  62.  
  63.       status = NtOpenFile (&h, READ_CONTROL | FILE_READ_ATTRIBUTES, &attr, &io,
  64.                            FILE_SHARE_VALID_FLAGS, 0);
  65.       if (!NT_SUCCESS (status))
  66.         {
  67.           fprintf (stderr, "NtOpenFile(%ls) failed, status code 0x%08lx\n",
  68.                    path, status);
  69.           continue;
  70.         }
  71.  
  72.       RtlInitUnicodeString (&upath, L"");
  73.       InitializeObjectAttributes (&attr, &upath, OBJ_CASE_INSENSITIVE, h, NULL);
  74.       status = NtQueryFullAttributesFile (&attr, &fnoi);
  75.       if (!NT_SUCCESS (status))
  76.         printf ("NtQueryFullAttributesFile(%ls) by handle failed,\n"
  77.                 "status code 0x%08lx\n", path, status);
  78.       else
  79.         printf ("NtQueryFullAttributesFile(%ls) by handle works\n", path);
  80.       NtClose (h);
  81.     }
  82.   return 0;
  83. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at