' ########################################################################################
' Microsoft Windows
' File: WinEFS.inc
' Contents: EFS Data and prototypes
' Copyright (c) 2011 Jos? Roca
' Portions Copyright (c) Microsoft Corporation.
' All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################
#IF NOT %DEF(PBX_WinEFS_PBI)
#DEFINE PBX_WinEFS_PBI
%EQUATE `WINEFS_INC = 1
#INCLUDE "Legacy/System/WTypes.inc"
'// winefs.h was not available at all pre-W2K
'#if (NTDDI_VERSION >= NTDDI_WIN2K)
%EQUATE `WINEFS_SETUSERKEY_SET_CAPABILITIES = &H00000001
'%WINEFS_SETUSERKEY_BLOCK_CACHE_FLUSH = &H00000002 ' // Removed from Windows 7 SDK
'//+---------------------------------------------------------------------------------/
'// /
'// /
'// Data Structures /
'// /
'// /
'//----------------------------------------------------------------------------------/
'// ALG_ID define is used as part of EFS_KEY_INFO (not available pre-WXP)
'#if (NTDDI_VERSION >= NTDDI_WINXP)
'#ifndef ALGIDDEF
'#define ALGIDDEF
'typedef unsigned int ALG_ID;
'#endif
'#endif
'//
'// Encoded Certificate
'//
' // Size = 12 bytes
TYPE EFS_CERTIFICATE_BLOB
 dwCertEncodingType AS DWORD
 cbData AS DWORD
 pbData AS BYTE PTR
END TYPE
'//
'// Certificate Hash
'//
' // Size = 8 bytes
TYPE EFS_HASH_BLOB DWORD
 cbData AS DWORD
 pbData AS BYTE PTR
END TYPE
'//
'// RPC blob
'//
' // Size = 8 bytes
TYPE EFS_RPC_BLOB DWORD
 cbData AS DWORD
 pbData AS BYTE PTR
END TYPE
'// EFS_PIN_BLOB was not available pre-LH
'#if (NTDDI_VERSION >= NTDDI_VISTA)
' // Size = 12 bytes
TYPE EFS_PIN_BLOB DWORD
 cbPadding AS DWORD
 cbData AS DWORD
 pbData AS BYTE PTR
END TYPE
'#endif // #if (NTDDI_VERSION >= NTDDI_VISTA)
'// EFS_KEY_INFO was not available pre-WXP
'#if (NTDDI_VERSION >= NTDDI_WINXP)
' // Size = 16 bytes
TYPE EFS_KEY_INFO DWORD
 dwVersion AS DWORD
 Entropy AS DWORD ' ULONG
 Algorithm AS DWORD ' ALG_ID
 KeyLength AS DWORD ' ULONG
END TYPE
'#endif // #if (NTDDI_VERSION >= NTDDI_WINXP)
'// EFS_COMPATIBILITY_INFO was not available pre-Windows 7
'#if (NTDDI_VERSION >= NTDDI_WIN7)
' // Size = 4 bytes
TYPE EFS_COMPATIBILITY_INFO DWORD
 EfsVersion AS DWORD
END TYPE
'#endif // #if (NTDDI_VERSION >= NTDDI_WIN7)
'// EFS_(EN/DE)CRYPTION_STATUS_INFO was not available pre-LH
'#if (NTDDI_VERSION >= NTDDI_VISTA)
' // Size = 12 bytes
TYPE EFS_DECRYPTION_STATUS_INFO DWORD
 dwDecryptionError AS DWORD
 dwHashOffset AS DWORD
 cbHash AS DWORD
END TYPE
' // Size = 8 bytes
TYPE EFS_ENCRYPTION_STATUS_INFO DWORD
 bHasCurrentKey AS LONG
 dwEncryptionError AS DWORD
END TYPE
'#endif // #if (NTDDI_VERSION >= NTDDI_VISTA)
'//
'// Input to add a user to an encrypted file
'//
' // Size = 12 bytes
TYPE ENCRYPTION_CERTIFICATE DWORD
 cbTotalLength AS DWORD
 pUserSid AS DWORD ' SID*
 pCertBlob AS EFS_CERTIFICATE_BLOB PTR ' PEFS_CERTIFICATE_BLOB
END TYPE
'#define MAX_SID_SIZE 256
%EQUATE `MAX_SID_SIZE = 256
' // Size = 16 bytes
TYPE ENCRYPTION_CERTIFICATE_HASH DWORD
 cbTotalLength AS DWORD
 pUserSid AS DWORD ' SID *
 pHash AS EFS_HASH_BLOB PTR ' PEFS_HASH_BLOB
 lpDisplayInformation AS WSTRINGZ PTR
END TYPE
' // Size = 8 bytes
TYPE ENCRYPTION_CERTIFICATE_HASH_LIST DWORD
 nCert_Hash AS DWORD
 pUsers AS ENCRYPTION_CERTIFICATE_HASH PTR ' PENCRYPTION_CERTIFICATE_HASH*
END TYPE
' // Size = 8 bytes
TYPE ENCRYPTION_CERTIFICATE_LIST DWORD
 nUsers AS DWORD
 pUsers AS ENCRYPTION_CERTIFICATE PTR ' PENCRYPTION_CERTIFICATE*
END TYPE
'// ENCRYPTED_FILE_METADATA_SIGNATURE was not available pre-LH
'#if (NTDDI_VERSION >= NTDDI_VISTA)
%EQUATE `EFS_METADATA_ADD_USER = &H00000001
%EQUATE `EFS_METADATA_REMOVE_USER = &H00000002
%EQUATE `EFS_METADATA_REPLACE_USER = &H00000004
%EQUATE `EFS_METADATA_GENERAL_OP = &H00000008
' // Size = 16 bytes
TYPE ENCRYPTED_FILE_METADATA_SIGNATURE DWORD
 dwEfsAccessType AS DWORD
 pCertificatesAdded AS ENCRYPTION_CERTIFICATE_HASH_LIST PTR ' PENCRYPTION_CERTIFICATE_HASH_LIST
 pEncryptionCertificate AS ENCRYPTION_CERTIFICATE PTR ' PENCRYPTION_CERTIFICATE
 pEfsStreamSignature AS EFS_RPC_BLOB PTR ' PEFS_RPC_BLOB
END TYPE
'#endif // #if (NTDDI_VERSION >= NTDDI_VISTA)
'//+---------------------------------------------------------------------------------/
'// /
'// /
'// Prototypes /
'// /
'// /
'//----------------------------------------------------------------------------------/
DECLARE FUNCTION QueryUsersOnEncryptedFile LIB "advapi32.dll" ALIAS "QueryUsersOnEncryptedFile" ( BYREF lpFileName AS WSTRINGZ , BYREF pUsers AS ENCRYPTION_CERTIFICATE_HASH_LIST ) AS QUAD
DECLARE FUNCTION QueryRecoveryAgentsOnEncryptedFile LIB "advapi32.dll" ALIAS "QueryRecoveryAgentsOnEncryptedFile" ( BYREF lpFileName AS WSTRINGZ
 , BYREF pRecoveryAgents AS ENCRYPTION_CERTIFICATE_HASH_LIST
 ) AS DWORD
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION RemoveUsersFromEncryptedFile LIB "ADVAPI32.dll" ALIAS "RemoveUsersFromEncryptedFile" (lpFileName AS WSTRINGZ, BYVAL pHashes AS ENCRYPTION_CERTIFICATE_HASH_LIST PTR) AS QUAD
#ELSE
DECLARE FUNCTION RemoveUsersFromEncryptedFile LIB "advapi32.dll" ALIAS "RemoveUsersFromEncryptedFile" ( BYREF lpFileName AS WSTRINGZ , BYREF pHashes AS ENCRYPTION_CERTIFICATE_HASH_LIST ) AS QUAD
#ENDIF
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION AddUsersToEncryptedFile LIB "ADVAPI32.dll" ALIAS "AddUsersToEncryptedFile" (lpFileName AS WSTRINGZ, BYVAL pEncryptionCertificates AS ENCRYPTION_CERTIFICATE_LIST PTR) AS QUAD
#ELSE
DECLARE FUNCTION AddUsersToEncryptedFile LIB "advapi32.dll" ALIAS "AddUsersToEncryptedFile" ( BYREF lpFileName AS WSTRINGZ , BYREF pUsers AS ENCRYPTION_CERTIFICATE_LIST ) AS QUAD
#ENDIF
DECLARE FUNCTION SetUserFileEncryptionKey LIB "advapi32.dll" ALIAS "SetUserFileEncryptionKey" ( BYREF pEncryptionCertificate AS ENCRYPTION_CERTIFICATE ) AS QUAD
'// SetUserFileEncryptionKeyEx was not available pre-LH
'#if (NTDDI_VERSION >= NTDDI_VISTA)
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION SetUserFileEncryptionKeyEx LIB "ADVAPI32.dll" ALIAS "SetUserFileEncryptionKeyEx" (pEncryptionCertificate AS ENCRYPTION_CERTIFICATE, BYVAL dwCapabilities AS QUAD, BYVAL dwFlags AS QUAD, pvReserved AS ANY) AS QUAD
#ELSE
DECLARE FUNCTION SetUserFileEncryptionKeyEx LIB "advapi32.dll" ALIAS "SetUserFileEncryptionKeyEx" ( BYREF pEncryptionCertificate AS ENCRYPTION_CERTIFICATE , BYVAL dwCapabilities AS QUAD , BYVAL dwFlags AS QUAD , BYVAL pvReserved AS QUAD ) AS QUAD
#ENDIF
'#endif // #if (NTDDI_VERSION >= NTDDI_VISTA)
#IF %DEF(%USEPBDECL)
DECLARE SUB FreeEncryptionCertificateHashList LIB "ADVAPI32.dll" ALIAS "FreeEncryptionCertificateHashList" (BYVAL pUsers AS ENCRYPTION_CERTIFICATE_HASH_LIST PTR)
#ELSE
DECLARE SUB FreeEncryptionCertificateHashList LIB "advapi32.dll" ALIAS "FreeEncryptionCertificateHashList" ( BYREF pHashes AS ENCRYPTION_CERTIFICATE_HASH_LIST ) ' void
#ENDIF
DECLARE FUNCTION EncryptionDisable LIB "advapi32.dll" ALIAS "EncryptionDisable" ( BYREF DirPath AS WSTRINGZ , BYVAL Disable AS LONG ) AS LONG
'// DuplicateEncryptionInfoFile signature changed
'// DuplicateEncryptionInfoFile didn't exist pre-WXP
'#elif (NTDDI_VERSION >= NTDDI_WINXP)
DECLARE FUNCTION DuplicateEncryptionInfoFile LIB "advapi32.dll" ALIAS "DuplicateEncryptionInfoFile" ( BYREF SrcFileName AS WSTRINGZ , BYREF DstFileName AS WSTRINGZ , BYVAL dwCreationDistribution AS QUAD , BYVAL dwAttributes AS QUAD , BYREF lpSecurityAttributes AS SECURITY_ATTRIBUTES ) AS QUAD
'#endif
'// *EncryptedFileMetadata routines were not available pre-LH
'#if (NTDDI_VERSION >= NTDDI_VISTA)
DECLARE FUNCTION GetEncryptedFileMetadata LIB "advapi32.dll" ALIAS "GetEncryptedFileMetadata" ( BYREF lpFileName AS WSTRINGZ , BYREF pcbMetadata AS QUAD , BYREF ppbMetadata AS ANY ) AS QUAD
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION SetEncryptedFileMetadata LIB "ADVAPI32.dll" ALIAS "SetEncryptedFileMetadata" (lpFileName AS WSTRINGZ, BYVAL pbOldMetadata AS BYTE PTR, BYVAL pbNewMetadata AS BYTE PTR, pOwnerHash AS ENCRYPTION_CERTIFICATE_HASH, BYVAL dwOperation AS QUAD, BYVAL pCertificatesAddes AS ENCRYPTION_CERTIFICATE_HASH_LIST PTR) AS QUAD
#ELSE
DECLARE FUNCTION SetEncryptedFileMetadata LIB "advapi32.dll" ALIAS "SetEncryptedFileMetadata" ( BYREF lpFileName AS WSTRINGZ , BYVAL pbOldMetadata AS BYTE PTR , BYVAL pbNewMetadata AS BYTE PTR , BYREF pOwnerHash AS ENCRYPTION_CERTIFICATE_HASH , BYVAL dwOperation AS QUAD , BYREF pCertificatesAdded AS ENCRYPTION_CERTIFICATE_HASH_LIST ) AS QUAD
#ENDIF
DECLARE SUB FreeEncryptedFileMetadata LIB "advapi32.dll" ALIAS "FreeEncryptedFileMetadata" ( BYVAL BYTE PTR ) ' void
'#endif // #if (NTDDI_VERSION >= NTDDI_VISTA)
'#endif // #if (NTDDI_VERSION >= NTDDI_WIN2K)
#ENDIF
