Fix PVOID arguments in function generated + add some func/struct from CryptoAPI

This commit is contained in:
hakril
2016-12-30 10:02:23 +01:00
committed by Clement Rouault
parent 50e7a1f2e3
commit 28b2596483
7 changed files with 76 additions and 40 deletions
+8 -1
View File
@@ -2785,4 +2785,11 @@ typedef struct _CERT_KEY_CONTEXT {
DWORD cbSize;
HCRYPTPROV hCryptProv;
DWORD dwKeySpec;
} CERT_KEY_CONTEXT, *PCERT_KEY_CONTEXT;
} CERT_KEY_CONTEXT, *PCERT_KEY_CONTEXT;
typedef struct _CRYPT_ENCODE_PARA {
DWORD cbSize;
PVOID pfnAlloc;
PVOID pfnFree;
} CRYPT_ENCODE_PARA, *PCRYPT_ENCODE_PARA;
@@ -213,8 +213,18 @@ PCCERT_CONTEXT WINAPI CertDuplicateCertificateContext(
_In_ PCCERT_CONTEXT pCertContext
);
PCCERT_CONTEXT WINAPI CertEnumCertificatesInStore(
_In_ HCERTSTORE hCertStore,
_In_ PCCERT_CONTEXT pPrevCertContext
);
BOOL WINAPI CryptEncodeObjectEx(
_In_ DWORD dwCertEncodingType,
_In_ LPCSTR lpszStructType,
_In_ VOID *pvStructInfo,
_In_ DWORD dwFlags,
_In_ PCRYPT_ENCODE_PARA pEncodePara,
_Out_ VOID *pvEncoded,
_Inout_ DWORD *pcbEncoded
);
+1 -1
View File
@@ -27,7 +27,7 @@ class WinFunc(object):
model = "{0} = WINFUNCTYPE({1})"
ctypes_param = [self.return_type]
for type, name in self.params:
if type == "POINTER(void)":
if type.upper() == "POINTER(VOID)":
type = "PVOID"
ctypes_param.append(type)
#ctypes_param = [self.return_type] + [type for type, name in self.params]
+4 -4
View File
@@ -193,11 +193,11 @@ class InitialDefGenerator(CtypesGenerator):
return "{0}({1})".format(self.name, hex(self))
__str__ = __repr__
class StrFlags(str):
def __new__(cls, name, value):
return super(StrFlags, cls).__new__(cls, value)
def __init__(self, name, value):
self.name = name
@@ -205,12 +205,12 @@ class InitialDefGenerator(CtypesGenerator):
return "{0}({1})".format(self.name, str.__repr__(self))
__str__ = __repr__
def make_flag(name, value):
if isinstance(value, (int, long)):
return Flag(name, value)
return StrFlags(name, value)
""")
File diff suppressed because one or more lines are too long
+9
View File
@@ -3459,6 +3459,15 @@ class _CERT_KEY_CONTEXT(Structure):
CERT_KEY_CONTEXT = _CERT_KEY_CONTEXT
PCERT_KEY_CONTEXT = POINTER(_CERT_KEY_CONTEXT)
class _CRYPT_ENCODE_PARA(Structure):
_fields_ = [
("cbSize", DWORD),
("pfnAlloc", PVOID),
("pfnFree", PVOID),
]
PCRYPT_ENCODE_PARA = POINTER(_CRYPT_ENCODE_PARA)
CRYPT_ENCODE_PARA = _CRYPT_ENCODE_PARA
class tagRECT(Structure):
_fields_ = [
("left", LONG),
+25 -20
View File
@@ -1012,7 +1012,7 @@ def CertStrToNameW(dwCertEncodingType, pszX500, dwStrType, pvReserved, pbEncoded
def CertCreateSelfSignCertificate(hCryptProvOrNCryptKey, pSubjectIssuerBlob, dwFlags, pKeyProvInfo, pSignatureAlgorithm, pStartTime, pEndTime, pExtensions):
return CertCreateSelfSignCertificate.ctypes_function(hCryptProvOrNCryptKey, pSubjectIssuerBlob, dwFlags, pKeyProvInfo, pSignatureAlgorithm, pStartTime, pEndTime, pExtensions)
@Crypt32Proxy('CertOpenStore')
def CertOpenStore(lpszStoreProvider, dwMsgAndCertEncodingType, hCryptProv, dwFlags, pvPara):
return CertOpenStore.ctypes_function(lpszStoreProvider, dwMsgAndCertEncodingType, hCryptProv, dwFlags, pvPara)
@@ -1022,7 +1022,7 @@ def CertOpenStore(lpszStoreProvider, dwMsgAndCertEncodingType, hCryptProv, dwFla
def CertAddCertificateContextToStore(hCertStore, pCertContext, dwAddDisposition, ppStoreContext):
return CertAddCertificateContextToStore.ctypes_function(hCertStore, pCertContext, dwAddDisposition, ppStoreContext)
@Crypt32Proxy('PFXExportCertStoreEx')
def PFXExportCertStoreEx(hStore, pPFX, szPassword, pvPara, dwFlags):
return PFXExportCertStoreEx.ctypes_function(hStore, pPFX, szPassword, pvPara, dwFlags)
@@ -1032,7 +1032,7 @@ def PFXExportCertStoreEx(hStore, pPFX, szPassword, pvPara, dwFlags):
def CryptGenKey(hProv, Algid, dwFlags, phKey):
return CryptGenKey.ctypes_function(hProv, Algid, dwFlags, phKey)
@Advapi32Proxy('CryptAcquireContextA')
def CryptAcquireContextA(phProv, pszContainer, pszProvider, dwProvType, dwFlags):
return CryptAcquireContextA.ctypes_function(phProv, pszContainer, pszProvider, dwProvType, dwFlags)
@@ -1042,11 +1042,11 @@ def CryptAcquireContextA(phProv, pszContainer, pszProvider, dwProvType, dwFlags)
def CryptAcquireContextW(phProv, pszContainer, pszProvider, dwProvType, dwFlags):
return CryptAcquireContextW.ctypes_function(phProv, pszContainer, pszProvider, dwProvType, dwFlags)
@Advapi32Proxy('CryptExportKey')
def CryptExportKey(hKey, hExpKey, dwBlobType, dwFlags, pbData, pdwDataLen):
return CryptExportKey.ctypes_function(hKey, hExpKey, dwBlobType, dwFlags, pbData, pdwDataLen)
@Crypt32Proxy('PFXImportCertStore')
def PFXImportCertStore(pPFX, szPassword, dwFlags):
@@ -1067,7 +1067,7 @@ def CertEnumCertificateContextProperties(pCertContext, dwPropId):
return CertEnumCertificateContextProperties.ctypes_function(pCertContext, dwPropId)
@Crypt32Proxy('CryptEncryptMessage')
@Crypt32Proxy('CryptEncryptMessage')
def CryptEncryptMessage(pEncryptPara, cRecipientCert, rgpRecipientCert, pbToBeEncrypted, cbToBeEncrypted, pbEncryptedBlob, pcbEncryptedBlob):
if isinstance(pbToBeEncrypted, basestring):
# Transform string to array of byte
@@ -1075,41 +1075,46 @@ def CryptEncryptMessage(pEncryptPara, cRecipientCert, rgpRecipientCert, pbToBeEn
if cbToBeEncrypted is None and pbToBeEncrypted is not None:
cbToBeEncrypted = len(pbToBeEncrypted)
return CryptEncryptMessage.ctypes_function(pEncryptPara, cRecipientCert, rgpRecipientCert, pbToBeEncrypted, cbToBeEncrypted, pbEncryptedBlob, pcbEncryptedBlob)
@Crypt32Proxy('CryptDecryptMessage')
@Crypt32Proxy('CryptDecryptMessage')
def CryptDecryptMessage(pDecryptPara, pbEncryptedBlob, cbEncryptedBlob, pbDecrypted, pcbDecrypted, ppXchgCert):
return CryptDecryptMessage.ctypes_function(pDecryptPara, pbEncryptedBlob, cbEncryptedBlob, pbDecrypted, pcbDecrypted, ppXchgCert)
@Crypt32Proxy('CryptAcquireCertificatePrivateKey')
@Crypt32Proxy('CryptAcquireCertificatePrivateKey')
def CryptAcquireCertificatePrivateKey(pCert, dwFlags, pvParameters, phCryptProvOrNCryptKey, pdwKeySpec, pfCallerFreeProvOrNCryptKey):
return CryptAcquireCertificatePrivateKey.ctypes_function(pCert, dwFlags, pvParameters, phCryptProvOrNCryptKey, pdwKeySpec, pfCallerFreeProvOrNCryptKey)
@Crypt32Proxy('CertGetNameStringA')
def CertGetNameStringA(pCertContext, dwType, dwFlags, pvTypePara, pszNameString, cchNameString):
return CertGetNameStringA.ctypes_function(pCertContext, dwType, dwFlags, pvTypePara, pszNameString, cchNameString)
@Crypt32Proxy('CertGetNameStringW')
def CertGetNameStringW(pCertContext, dwType, dwFlags, pvTypePara, pszNameString, cchNameString):
return CertGetNameStringW.ctypes_function(pCertContext, dwType, dwFlags, pvTypePara, pszNameString, cchNameString)
@Crypt32Proxy('CertGetCertificateChain')
def CertGetCertificateChain(hChainEngine, pCertContext, pTime, hAdditionalStore, pChainPara, dwFlags, pvReserved, ppChainContext):
return CertGetCertificateChain.ctypes_function(hChainEngine, pCertContext, pTime, hAdditionalStore, pChainPara, dwFlags, pvReserved, ppChainContext)
@Crypt32Proxy('CertDuplicateCertificateContext')
@Crypt32Proxy('CertDuplicateCertificateContext')
def CertDuplicateCertificateContext(pCertContext):
return CertDuplicateCertificateContext.ctypes_function(pCertContext)
@Crypt32Proxy('CertEnumCertificatesInStore')
return CertDuplicateCertificateContext.ctypes_function(pCertContext)
@Crypt32Proxy('CertEnumCertificatesInStore')
def CertEnumCertificatesInStore(hCertStore, pPrevCertContext):
return CertEnumCertificatesInStore.ctypes_function(hCertStore, pPrevCertContext)
@Crypt32Proxy('CryptEncodeObjectEx')
def CryptEncodeObjectEx(dwCertEncodingType, lpszStructType, pvStructInfo, dwFlags, pEncodePara, pvEncoded, pcbEncoded):
return CryptEncodeObjectEx.ctypes_function(dwCertEncodingType, lpszStructType, pvStructInfo, dwFlags, pEncodePara, pvEncoded, pcbEncoded)
# ## User32 stuff ## #
EnumWindows = TransparentUser32Proxy('EnumWindows')