From 168783af9d38581b669486b01a6ff0ea7ebfe003 Mon Sep 17 00:00:00 2001 From: hakril Date: Mon, 12 Aug 2019 13:50:08 +0200 Subject: [PATCH] Improved CryptMsg API with some more properties --- windows/crypto/cryptmsg.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/windows/crypto/cryptmsg.py b/windows/crypto/cryptmsg.py index 078e83c..825866c 100644 --- a/windows/crypto/cryptmsg.py +++ b/windows/crypto/cryptmsg.py @@ -100,4 +100,30 @@ class CryptMessage(gdef.HCRYPTMSG): @property def recipients(self): """TODO: DOC""" - return [self.get_recipient_data(i) for i in range(self.nb_recipient)] \ No newline at end of file + return [self.get_recipient_data(i) for i in range(self.nb_recipient)] + + @property + def content(self): + return self.get_param(gdef.CMSG_CONTENT_PARAM)[:] + + @property + def content_type(self): + data = self.get_param(gdef.CMSG_INNER_CONTENT_TYPE_PARAM) + assert data[-1] == "\x00", "CMSG_INNER_CONTENT_TYPE_PARAM not NULL TERMINATED" + return data[:-1] + + + def update(self, blob, final): + # Test isinstance string ? + if isinstance(blob, (basestring, bytearray)): + buffer = windows.utils.BUFFER(gdef.BYTE).from_buffer_copy(blob) + return winproxy.CryptMsgUpdate(self, buffer, len(blob), final) + return winproxy.CryptMsgUpdate(self, blob.pbData, blob.cbData, final) + + # constructor + @classmethod + def from_data(self, data): + hmsg = winproxy.CryptMsgOpenToDecode(windows.crypto.DEFAULT_ENCODING, 0, 0, None, None, None) + newmsg = CryptMessage(hmsg) + newmsg.update(data, final=True) + return newmsg