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.

170 lines
5.0 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. pathutils.h
  5. Abstract:
  6. Contains prototypes for functions from ntdll
  7. on XP that are not available on W2K.
  8. History:
  9. 09/10/2001 rparsons Created
  10. --*/
  11. #ifndef _RTLUTILS_H_
  12. #define _RTLUTILS_H_
  13. #include "ShimHook.h"
  14. namespace ShimLib
  15. {
  16. PVOID
  17. ShimAllocateStringRoutine(
  18. SIZE_T NumberOfBytes
  19. );
  20. VOID
  21. ShimFreeStringRoutine(
  22. PVOID Buffer
  23. );
  24. const PRTL_ALLOCATE_STRING_ROUTINE RtlAllocateStringRoutine = ShimAllocateStringRoutine;
  25. const PRTL_FREE_STRING_ROUTINE RtlFreeStringRoutine = ShimFreeStringRoutine;
  26. RTL_PATH_TYPE
  27. NTAPI
  28. ShimDetermineDosPathNameType_Ustr(
  29. IN PCUNICODE_STRING String
  30. );
  31. NTSTATUS
  32. NTAPI
  33. ShimNtPathNameToDosPathName(
  34. IN ULONG Flags,
  35. IN OUT PRTL_UNICODE_STRING_BUFFER Path,
  36. OUT ULONG* Disposition OPTIONAL,
  37. IN OUT PWSTR* FilePart OPTIONAL
  38. );
  39. NTSTATUS
  40. ShimDuplicateUnicodeString(
  41. ULONG Flags,
  42. PCUNICODE_STRING StringIn,
  43. PUNICODE_STRING StringOut
  44. );
  45. NTSTATUS
  46. NTAPI
  47. ShimpEnsureBufferSize(
  48. IN ULONG Flags,
  49. IN OUT PRTL_BUFFER Buffer,
  50. IN SIZE_T Size
  51. );
  52. NTSTATUS
  53. ShimValidateUnicodeString(
  54. ULONG Flags,
  55. const UNICODE_STRING *String
  56. );
  57. //
  58. // Taken from %SDXROOT%\public\sdk\inc\NtRtlStringAndBuffer.h
  59. //
  60. #define ShimEnsureBufferSize(Flags, Buff, NewSizeBytes) \
  61. ( ((Buff) != NULL && (NewSizeBytes) <= (Buff)->Size) \
  62. ? STATUS_SUCCESS \
  63. : ShimpEnsureBufferSize((Flags), (Buff), (NewSizeBytes)) \
  64. )
  65. #define ShimEnsureUnicodeStringBufferSizeBytes(Buff_, NewSizeBytes_) \
  66. ( ( ((NewSizeBytes_) + sizeof((Buff_)->String.Buffer[0])) > UNICODE_STRING_MAX_BYTES ) \
  67. ? STATUS_NAME_TOO_LONG \
  68. : !NT_SUCCESS(ShimEnsureBufferSize(0, &(Buff_)->ByteBuffer, ((NewSizeBytes_) + sizeof((Buff_)->String.Buffer[0])))) \
  69. ? STATUS_NO_MEMORY \
  70. : (RtlSyncStringToBuffer(Buff_)) \
  71. )
  72. #define ShimEnsureUnicodeStringBufferSizeChars(Buff_, NewSizeChars_) \
  73. (ShimEnsureUnicodeStringBufferSizeBytes((Buff_), (NewSizeChars_) * sizeof((Buff_)->String.Buffer[0])))
  74. //
  75. // Taken from %SDXROOT%\public\sdk\inc\NtRtlStringAndBuffer.h
  76. //
  77. //++
  78. //
  79. // NTSTATUS
  80. // RtlAppendUnicodeStringBuffer(
  81. // OUT PRTL_UNICODE_STRING_BUFFER Destination,
  82. // IN PCUNICODE_STRING Source
  83. // );
  84. //
  85. // Routine Description:
  86. //
  87. //
  88. // Arguments:
  89. //
  90. // Destination -
  91. // Source -
  92. //
  93. // Return Value:
  94. //
  95. // STATUS_SUCCESS
  96. // STATUS_NO_MEMORY
  97. // STATUS_NAME_TOO_LONG (64K UNICODE_STRING length would be exceeded)
  98. //
  99. //--
  100. #define ShimAppendUnicodeStringBuffer(Dest, Source) \
  101. ( ( ( (Dest)->String.Length + (Source)->Length + sizeof((Dest)->String.Buffer[0]) ) > UNICODE_STRING_MAX_BYTES ) \
  102. ? STATUS_NAME_TOO_LONG \
  103. : (!NT_SUCCESS( \
  104. ShimEnsureBufferSize( \
  105. 0, \
  106. &(Dest)->ByteBuffer, \
  107. (Dest)->String.Length + (Source)->Length + sizeof((Dest)->String.Buffer[0]) ) ) \
  108. ? STATUS_NO_MEMORY \
  109. : ( ( (Dest)->String.Buffer = (PWSTR)(Dest)->ByteBuffer.Buffer ), \
  110. ( RtlMoveMemory( \
  111. (Dest)->String.Buffer + (Dest)->String.Length / sizeof((Dest)->String.Buffer[0]), \
  112. (Source)->Buffer, \
  113. (Source)->Length) ), \
  114. ( (Dest)->String.MaximumLength = (RTL_STRING_LENGTH_TYPE)((Dest)->String.Length + (Source)->Length + sizeof((Dest)->String.Buffer[0]))), \
  115. ( (Dest)->String.Length += (Source)->Length ), \
  116. ( (Dest)->String.Buffer[(Dest)->String.Length / sizeof((Dest)->String.Buffer[0])] = 0 ), \
  117. ( STATUS_SUCCESS ) ) ) )
  118. //
  119. // Taken from %SDXROOT%\public\sdk\inc\NtRtlStringAndBuffer.h
  120. //
  121. //++
  122. //
  123. // NTSTATUS
  124. // RtlAssignUnicodeStringBuffer(
  125. // IN OUT PRTL_UNICODE_STRING_BUFFER Buffer,
  126. // PCUNICODE_STRING String
  127. // );
  128. // Routine Description:
  129. //
  130. // Arguments:
  131. //
  132. // Buffer -
  133. // String -
  134. //
  135. // Return Value:
  136. //
  137. // STATUS_SUCCESS
  138. // STATUS_NO_MEMORY
  139. //--
  140. #define ShimAssignUnicodeStringBuffer(Buff, Str) \
  141. (((Buff)->String.Length = 0), (ShimAppendUnicodeStringBuffer((Buff), (Str))))
  142. }; // end of namespace ShimLib
  143. #endif // _RTLUTILS_H_