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.

NativeMethods.EncryptedFileRaw.cs 5.0 KiB

пре 8 година
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Diagnostics.CodeAnalysis;
  3. using System.Runtime.InteropServices;
  4. using System.Security;
  5. namespace Alphaleonis.Win32.Filesystem
  6. {
  7. partial class NativeMethods
  8. {
  9. /// <summary>Opens an encrypted file in order to backup (export) or restore (import) the file.</summary>
  10. /// <returns>If the function succeeds, it returns ERROR_SUCCESS.</returns>
  11. /// <returns>If the function fails, it returns a nonzero error code defined in WinError.h. You can use FormatMessage with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic text description of the error.</returns>
  12. /// <remarks>Minimum supported client: Windows XP Professional [desktop apps only]</remarks>
  13. /// <remarks>Minimum supported server: Windows Server 2003 [desktop apps only]</remarks>
  14. /// <param name="lpFileName">The name of the file to be opened.</param>
  15. /// <param name="ulFlags">The operation to be performed.</param>
  16. /// <param name="pvContext">[out] The address of a context block that must be presented in subsequent calls to
  17. /// ReadEncryptedFileRaw, WriteEncryptedFileRaw, or CloseEncryptedFileRaw.</param>
  18. [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
  19. [DllImport("Advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "OpenEncryptedFileRawW"), SuppressUnmanagedCodeSecurity]
  20. [return: MarshalAs(UnmanagedType.U4)]
  21. internal static extern uint OpenEncryptedFileRaw([MarshalAs(UnmanagedType.LPWStr)] string lpFileName, EncryptedFileRawMode ulFlags, out SafeEncryptedFileRawHandle pvContext);
  22. /// <summary>Closes an encrypted file after a backup or restore operation, and frees associated system resources.</summary>
  23. /// <remarks>Minimum supported client: Windows XP Professional [desktop apps only]</remarks>
  24. /// <remarks>Minimum supported server: Windows Server 2003 [desktop apps only]</remarks>
  25. /// <param name="pvContext">A pointer to a system-defined context block. The OpenEncryptedFileRaw function returns the context block.</param>
  26. [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
  27. [DllImport("Advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
  28. internal static extern void CloseEncryptedFileRaw(IntPtr pvContext);
  29. /// <summary>Backs up (export) encrypted files. This is one of a group of Encrypted File System (EFS) functions that is intended to implement backup and restore functionality, while maintaining files in their encrypted state.</summary>
  30. /// <returns>If the function succeeds, it returns ERROR_SUCCESS.</returns>
  31. /// <returns>If the function fails, it returns a nonzero error code defined in WinError.h. You can use FormatMessage with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic text description of the error.</returns>
  32. /// <remarks>Minimum supported client: Windows XP Professional [desktop apps only]</remarks>
  33. /// <remarks>Minimum supported server: Windows Server 2003 [desktop apps only]</remarks>
  34. [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule"), SuppressUnmanagedCodeSecurity]
  35. [DllImport("Advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
  36. [return: MarshalAs(UnmanagedType.U4)]
  37. internal static extern uint ReadEncryptedFileRaw([MarshalAs(UnmanagedType.FunctionPtr)] EncryptedFileRawExportCallback pfExportCallback, IntPtr pvCallbackContext, SafeEncryptedFileRawHandle pvContext);
  38. /// <summary>Restores (import) encrypted files. This is one of a group of Encrypted File System (EFS) functions that is intended to implement backup and restore functionality, while maintaining files in their encrypted state.</summary>
  39. /// <returns>If the function succeeds, it returns ERROR_SUCCESS.</returns>
  40. /// <returns>If the function fails, it returns a nonzero error code defined in WinError.h. You can use FormatMessage with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic text description of the error.</returns>
  41. /// <remarks>Minimum supported client: Windows XP Professional [desktop apps only]</remarks>
  42. /// <remarks>Minimum supported server: Windows Server 2003 [desktop apps only]</remarks>
  43. [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")]
  44. [DllImport("Advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
  45. [return: MarshalAs(UnmanagedType.U4)]
  46. internal static extern uint WriteEncryptedFileRaw([MarshalAs(UnmanagedType.FunctionPtr)] EncryptedFileRawImportCallback pfExportCallback, IntPtr pvCallbackContext, SafeEncryptedFileRawHandle pvContext);
  47. [SuppressUnmanagedCodeSecurity]
  48. internal delegate int EncryptedFileRawExportCallback(IntPtr pbData, IntPtr pvCallbackContext, uint ulLength);
  49. [SuppressUnmanagedCodeSecurity]
  50. internal delegate int EncryptedFileRawImportCallback(IntPtr pbData, IntPtr pvCallbackContext, ref uint ulLength);
  51. }
  52. }