Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

8 роки тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to deal
  5. * in the Software without restriction, including without limitation the rights
  6. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. * copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. * THE SOFTWARE.
  20. */
  21. using Microsoft.Win32.SafeHandles;
  22. using System;
  23. using System.Diagnostics.CodeAnalysis;
  24. using System.Runtime.InteropServices;
  25. using System.Security;
  26. namespace Alphaleonis.Win32.Filesystem
  27. {
  28. internal static partial class NativeMethods
  29. {
  30. /// <summary>The BackupRead function can be used to back up a file or directory, including the security information.
  31. /// <para>The function reads data associated with a specified file or directory into a buffer,</para>
  32. /// <para>which can then be written to the backup medium using the WriteFile function.</para>
  33. /// </summary>
  34. /// <remarks>
  35. /// <para>This function is not intended for use in backing up files encrypted under the Encrypted File System.</para>
  36. /// <para>Use ReadEncryptedFileRaw for that purpose.</para>
  37. /// <para>Minimum supported client: Windows XP [desktop apps only]</para>
  38. /// <para>Minimum supported server: Windows Server 2003 [desktop apps only]</para>
  39. /// </remarks>
  40. /// <param name="hFile">The file.</param>
  41. /// <param name="lpBuffer">The buffer.</param>
  42. /// <param name="nNumberOfBytesToRead">Number of bytes to reads.</param>
  43. /// <param name="lpNumberOfBytesRead">[out] Number of bytes reads.</param>
  44. /// <param name="bAbort">true to abort.</param>
  45. /// <param name="bProcessSecurity">true to process security.</param>
  46. /// <param name="lpContext">[out] The context.</param>
  47. /// <returns>
  48. /// <para>If the function succeeds, the return value is nonzero.</para>
  49. /// <para>If the function fails, the return value is zero, indicating that an I/O error occurred. To get extended error information,
  50. /// call GetLastError.</para>
  51. /// </returns>
  52. [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
  53. [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
  54. [return: MarshalAs(UnmanagedType.Bool)]
  55. internal static extern bool BackupRead(SafeFileHandle hFile, SafeGlobalMemoryBufferHandle lpBuffer, [MarshalAs(UnmanagedType.U4)] uint nNumberOfBytesToRead, [MarshalAs(UnmanagedType.U4)] out uint lpNumberOfBytesRead, [MarshalAs(UnmanagedType.Bool)] bool bAbort, [MarshalAs(UnmanagedType.Bool)] bool bProcessSecurity, ref IntPtr lpContext);
  56. /// <summary>The BackupSeek function seeks forward in a data stream initially accessed by using the <see cref="BackupRead"/> or
  57. /// <see cref="BackupWrite"/> function.
  58. /// <para>The function reads data associated with a specified file or directory into a buffer, which can then be written to the backup
  59. /// medium using the WriteFile function.</para>
  60. /// </summary>
  61. /// <remarks>
  62. /// <para>Applications use the BackupSeek function to skip portions of a data stream that cause errors.</para>
  63. /// <para>This function does not seek across stream headers. For example, this function cannot be used to skip the stream name.</para>
  64. /// <para>If an application attempts to seek past the end of a substream, the function fails, the lpdwLowByteSeeked and
  65. /// lpdwHighByteSeeked parameters</para>
  66. /// <para>indicate the actual number of bytes the function seeks, and the file position is placed at the start of the next stream
  67. /// header.</para>
  68. /// <para>&#160;</para>
  69. /// <para>Minimum supported client: Windows XP [desktop apps only]</para>
  70. /// <para>Minimum supported server: Windows Server 2003 [desktop apps only]</para>
  71. /// </remarks>
  72. /// <param name="hFile">The file.</param>
  73. /// <param name="dwLowBytesToSeek">The low bytes to seek.</param>
  74. /// <param name="dwHighBytesToSeek">The high bytes to seek.</param>
  75. /// <param name="lpdwLowBytesSeeked">[out] The lpdw low bytes seeked.</param>
  76. /// <param name="lpdwHighBytesSeeked">[out] The lpdw high bytes seeked.</param>
  77. /// <param name="lpContext">[out] The context.</param>
  78. /// <returns>
  79. /// <para>If the function could seek the requested amount, the function returns a nonzero value.</para>
  80. /// <para>If the function could not seek the requested amount, the function returns zero. To get extended error information, call
  81. /// GetLastError.</para>
  82. /// </returns>
  83. [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
  84. [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
  85. [return: MarshalAs(UnmanagedType.Bool)]
  86. internal static extern bool BackupSeek(SafeFileHandle hFile, [MarshalAs(UnmanagedType.U4)] uint dwLowBytesToSeek, [MarshalAs(UnmanagedType.U4)] uint dwHighBytesToSeek, [MarshalAs(UnmanagedType.U4)] out uint lpdwLowBytesSeeked, [MarshalAs(UnmanagedType.U4)] out uint lpdwHighBytesSeeked, ref IntPtr lpContext);
  87. /// <summary>The BackupWrite function can be used to restore a file or directory that was backed up using <see cref="BackupRead"/>.
  88. /// <para>Use the ReadFile function to get a stream of data from the backup medium, then use BackupWrite to write the data to the
  89. /// specified file or directory.</para>
  90. /// <para>&#160;</para>
  91. /// </summary>
  92. /// <remarks>
  93. /// <para>This function is not intended for use in restoring files encrypted under the Encrypted File System. Use WriteEncryptedFileRaw
  94. /// for that purpose.</para>
  95. /// <para>Minimum supported client: Windows XP [desktop apps only]</para>
  96. /// <para>Minimum supported server: Windows Server 2003 [desktop apps only]</para>
  97. /// </remarks>
  98. /// <param name="hFile">The file.</param>
  99. /// <param name="lpBuffer">The buffer.</param>
  100. /// <param name="nNumberOfBytesToWrite">Number of bytes to writes.</param>
  101. /// <param name="lpNumberOfBytesWritten">[out] Number of bytes writtens.</param>
  102. /// <param name="bAbort">true to abort.</param>
  103. /// <param name="bProcessSecurity">true to process security.</param>
  104. /// <param name="lpContext">[out] The context.</param>
  105. /// <returns>
  106. /// <para>If the function succeeds, the return value is nonzero.</para>
  107. /// <para>If the function fails, the return value is zero, indicating that an I/O error occurred. To get extended error information,
  108. /// call GetLastError.</para>
  109. /// </returns>
  110. [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
  111. [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
  112. [return: MarshalAs(UnmanagedType.Bool)]
  113. internal static extern bool BackupWrite(SafeFileHandle hFile, SafeGlobalMemoryBufferHandle lpBuffer, [MarshalAs(UnmanagedType.U4)] uint nNumberOfBytesToWrite, [MarshalAs(UnmanagedType.U4)] out uint lpNumberOfBytesWritten, [MarshalAs(UnmanagedType.Bool)] bool bAbort, [MarshalAs(UnmanagedType.Bool)] bool bProcessSecurity, ref IntPtr lpContext);
  114. }
  115. }