Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.2 KiB

  1. #include <nt.h>
  2. #include <ntrtl.h>
  3. #include <nturtl.h>
  4. #include <windows.h>
  5. #include <tchar.h> // for wprintf
  6. #include <winsafer.h>
  7. #include "..\..\saferp.h" // for CodeAuthzFullyQualifyFilename
  8. int __cdecl wmain(int argc, wchar_t *argv[])
  9. {
  10. NTSTATUS Status;
  11. HANDLE hFile;
  12. UNICODE_STRING UnicodeResult;
  13. if (argc != 2) {
  14. wprintf(L"Invalid syntax. No filename supplied.\n");
  15. return -1;
  16. }
  17. hFile = CreateFile(argv[1], GENERIC_READ, FILE_SHARE_READ, NULL,
  18. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  19. if (!hFile || hFile == INVALID_HANDLE_VALUE) {
  20. wprintf(L"Unable to open file: %s\n", argv[1]);
  21. return -1;
  22. }
  23. Status = CodeAuthzFullyQualifyFilename(
  24. hFile, FALSE, argv[1], &UnicodeResult);
  25. CloseHandle(hFile);
  26. if (!NT_SUCCESS(Status)) {
  27. wprintf(L"Unable to canonicalize filename: %s\n", argv[1]);
  28. }
  29. wprintf(L"Supplied filename: %s\n", argv[1]);
  30. wprintf(L"Canonocalized result: %*s\n",
  31. UnicodeResult.Length / sizeof(WCHAR), UnicodeResult.Buffer);
  32. RtlFreeUnicodeString(&UnicodeResult);
  33. return 0;
  34. }