Commit 4015e8ba authored by ElenaSubbotina's avatar ElenaSubbotina

PptFormatReader - decrypt ppt images

parent 276af556
......@@ -147,10 +147,11 @@ namespace DocFileFormat
if (fAES) crypt_data_aes.cipherAlgorithm = CRYPT_METHOD::AES_ECB;
if (fCryptoAPI) crypt_data_aes.cipherAlgorithm = CRYPT_METHOD::RC4;
crypt_data_aes.keySize = KeySize / 8;
break;
case 0x6801:
crypt_data_aes.cipherAlgorithm = CRYPT_METHOD::RC4;
crypt_data_aes.keySize = KeySize / 8;
if (crypt_data_aes.keySize == 0) crypt_data_aes.keySize = 5; // 40 bit
break;
case 0x660E:
crypt_data_aes.cipherAlgorithm = CRYPT_METHOD::AES_ECB;
......
......@@ -96,7 +96,9 @@ public:
if (bResult == false)
{
delete pInfo;
continue;
if (pInfo->m_bEncrypt) return false;
else continue;
}
m_arUsers.push_back(pInfo);
......
......@@ -224,6 +224,7 @@ void CPPTFileReader::ReadDocumentSummary()
void CPPTFileReader::ReadPictures()
{
if (m_oDocumentInfo.m_arUsers.empty()) return;
CFStreamPtr pStream = GetPictureStream();
if (!pStream) return;
......@@ -247,23 +248,17 @@ void CPPTFileReader::ReadPictures()
}
oHeader.ReadFromStream(pStreamTmp);
pStream->seekFromBegin(pos + 8);
CRecordOfficeArtBlip art_blip;
art_blip.m_strTmpDirectory = m_strTmpDirectory;
art_blip.m_oDocumentInfo = &m_oDocumentInfo;
//
pStream->seekFromBegin(pos + 8);
pStreamTmp = pStream->stream_; //каждое поле отдельно нужно
pStreamTmp = pStream->stream_;
if (pDecryptor)
{
m_oDocumentInfo.m_arUsers[0]->DecryptStream(pStreamTmp, 1);
pStreamTmp = m_oDocumentInfo.m_arUsers[0]->m_arStreamDecrypt.back()->stream_;
}
art_blip.ReadFromStream(oHeader, pStreamTmp);
m_oDocumentInfo.m_mapStoreImageFile[ pos ] = art_blip.m_sFileName;
pStream->seekFromBegin(pos + oHeader.RecLen + 8);
m_oDocumentInfo.m_mapStoreImageFile[ pos ] = art_blip.m_sFileName;
}
}
......@@ -33,8 +33,10 @@
#include "ReadStructures.h"
#include <zlib.h>
#include "../../../ASCOfficeDocFile/DocDocxConverter/MemoryStream.h"
#include "../../../OfficeCryptReader/source/CryptTransform.h"
#include <zlib.h>
using namespace NSPresentationEditor;
......@@ -639,22 +641,31 @@ namespace NSPresentationEditor
}
}
//------------------------------------------------------------------------------------
void CMetaHeader::FromStream(POLE::Stream* pStream)
void CMetaHeader::FromStream(POLE::Stream* pStream, CRYPT::ECMADecryptor *pDecryptor)
{
cbSize = StreamUtils::ReadDWORD(pStream);
int size = 34;
BYTE* pData = new BYTE[size];
pStream->read(pData, size);
if (pDecryptor)
{
pDecryptor->Decrypt((char*)pData, size, 0);
}
MemoryStream memStream(pData, size, false);
cbSize = memStream.ReadUInt32();
rcBounds.left = StreamUtils::ReadLONG(pStream);
rcBounds.top = StreamUtils::ReadLONG(pStream);
rcBounds.right = StreamUtils::ReadLONG(pStream);
rcBounds.bottom = StreamUtils::ReadLONG(pStream);
rcBounds.left = memStream.ReadInt32();
rcBounds.top = memStream.ReadInt32();
rcBounds.right = memStream.ReadInt32();
rcBounds.bottom = memStream.ReadInt32();
ptSize.x = StreamUtils::ReadLONG(pStream);
ptSize.y = StreamUtils::ReadLONG(pStream);
ptSize.x = memStream.ReadInt32();
ptSize.y = memStream.ReadInt32();
cbSave = StreamUtils::ReadDWORD(pStream);
cbSave = memStream.ReadUInt32();
compression = StreamUtils::ReadBYTE(pStream);
filter = StreamUtils::ReadBYTE(pStream);
compression = memStream.ReadByte();
filter = memStream.ReadByte();
}
void CMetaHeader::ToEMFHeader(Gdiplus::ENHMETAHEADER3* pHeader)
......
......@@ -43,6 +43,10 @@ namespace NSZLib
bool Decompress(const BYTE* pSrcBuffer, const ULONG& lSrcBufferLen,
BYTE* pDstBuffer, ULONG& lDstBufferLen);
}
namespace CRYPT
{
class ECMADecryptor;
}
/**************************************************************
теперь все структуры...
которые участвуют в записях
......@@ -170,7 +174,7 @@ public:
CMetaHeader()
{
}
void FromStream(POLE::Stream* pStream);
void FromStream(POLE::Stream* pStream, CRYPT::ECMADecryptor *pDecryptor = NULL);
void ToEMFHeader (Gdiplus::ENHMETAHEADER3* pHeader);
void ToWMFHeader (Gdiplus::WmfPlaceableFileHeader* pHeader);
......
......@@ -165,6 +165,8 @@ public:
case 0x6801:
crypt_data_aes.cipherAlgorithm = CRYPT_METHOD::RC4;
crypt_data_aes.keySize = KeySize / 8;
if (crypt_data_aes.keySize == 0)
crypt_data_aes.keySize = 5; // 40 bit
break;
case 0x660E:
crypt_data_aes.cipherAlgorithm = CRYPT_METHOD::AES_ECB;
......
......@@ -39,14 +39,12 @@
void CRecordOfficeArtBlip::ReadFromStream(SRecordHeader & oHeader, POLE::Stream* pStream)
{
CMetaFileBuffer oMetaFile;
std::wstring sExt = L".jpg";
if ((oHeader.RecVersion == PSFLAG_CONTAINER) || ((oHeader.RecVersion & 0x0F) == 0x0F)) return;
int pos = pStream->tell();
CRYPT::ECMADecryptor *pDecryptor = m_oDocumentInfo ? m_oDocumentInfo->m_arUsers[0]->m_pDecryptor : NULL;
if ((oHeader.RecVersion != PSFLAG_CONTAINER) && ((oHeader.RecVersion & 0x0F) != 0x0F))
{
CMetaFileBuffer oMetaFile;
std::wstring sExt = L".jpg";
int lOffset = 0;
switch (oHeader.RecType)
......@@ -63,7 +61,7 @@ void CRecordOfficeArtBlip::ReadFromStream(SRecordHeader & oHeader, POLE::Stream*
oMetaFile.m_sExtension = L".emf";
CMetaHeader oMetaHeader;
oMetaHeader.FromStream(pStream);
oMetaHeader.FromStream(pStream, pDecryptor);
Gdiplus::ENHMETAHEADER3 oEmfHeader;
oMetaHeader.ToEMFHeader(&oEmfHeader);
......@@ -72,7 +70,10 @@ void CRecordOfficeArtBlip::ReadFromStream(SRecordHeader & oHeader, POLE::Stream*
BYTE* pData = new BYTE[oHeader.RecLen - lOffset];
pStream->read(pData, oHeader.RecLen - lOffset);
if (pDecryptor)
{
pDecryptor->Decrypt((char*)pData, oHeader.RecLen - lOffset, 0);
}
oMetaFile.SetData(pData, oMetaHeader.cbSave, oMetaHeader.cbSize, (bool)(oMetaHeader.compression != 0xFE) );
}break;
......@@ -89,7 +90,8 @@ void CRecordOfficeArtBlip::ReadFromStream(SRecordHeader & oHeader, POLE::Stream*
oMetaFile.m_sExtension = L".wmf";
CMetaHeader oMetaHeader;
oMetaHeader.FromStream(pStream);
oMetaHeader.FromStream(pStream, pDecryptor);
Gdiplus::WmfPlaceableFileHeader oWmfHeader;
oMetaHeader.ToWMFHeader(&oWmfHeader);
......@@ -101,7 +103,10 @@ void CRecordOfficeArtBlip::ReadFromStream(SRecordHeader & oHeader, POLE::Stream*
BYTE* pData = new BYTE[oHeader.RecLen - lOffset];
pStream->read(pData, oHeader.RecLen - lOffset);
if (pDecryptor)
{
pDecryptor->Decrypt((char*)pData, oHeader.RecLen - lOffset, 0);
}
oMetaFile.SetData(pData, oMetaHeader.cbSave, oMetaHeader.cbSize, (bool)(oMetaHeader.compression != 0xFE) );
}break;
......@@ -118,11 +123,14 @@ void CRecordOfficeArtBlip::ReadFromStream(SRecordHeader & oHeader, POLE::Stream*
oMetaFile.m_sExtension = L".wmf";//L".pct"; - ВРЕМЕННО пока не сделана конвертация pct(pic) хоть во что нито !!!
CMetaHeader oMetaHeader;
oMetaHeader.FromStream(pStream); //отдельно вынесенный заголовок.. "форматный" находится в блоке данных
oMetaHeader.FromStream(pStream, pDecryptor); //отдельно вынесенный заголовок.. "форматный" находится в блоке данных
BYTE* pData = new BYTE[oHeader.RecLen - lOffset];
pStream->read(pData, oHeader.RecLen - lOffset);
if (pDecryptor)
{
pDecryptor->Decrypt((char*)pData, oHeader.RecLen - lOffset, 0);
}
oMetaFile.SetData(pData, oMetaHeader.cbSave, oMetaHeader.cbSize, (bool)(oMetaHeader.compression != 0xFE) );
}break;
case RECORD_TYPE_ESCHER_BLIP_JPEG:
......@@ -130,8 +138,7 @@ void CRecordOfficeArtBlip::ReadFromStream(SRecordHeader & oHeader, POLE::Stream*
if (0x046A == oHeader.RecInstance || 0x06E2 == oHeader.RecInstance) lOffset = 17;
else if (0x046B == oHeader.RecInstance || 0x06E3 == oHeader.RecInstance) lOffset = 33;
//StreamUtils::StreamSkip(lOffset, pStream);
std::string str = StreamUtils::ReadStringA(pStream, lOffset);
StreamUtils::StreamSkip(lOffset, pStream);
sExt = _T(".jpg");
break;
......@@ -141,8 +148,7 @@ void CRecordOfficeArtBlip::ReadFromStream(SRecordHeader & oHeader, POLE::Stream*
if (0x06E0 == oHeader.RecInstance) lOffset = 17;
else if (0x06E1 == oHeader.RecInstance) lOffset = 33;
//StreamUtils::StreamSkip(lOffset, pStream);
std::string str = StreamUtils::ReadStringA(pStream, lOffset);
StreamUtils::StreamSkip(lOffset, pStream);
sExt = _T(".png");
break;
......@@ -198,7 +204,10 @@ void CRecordOfficeArtBlip::ReadFromStream(SRecordHeader & oHeader, POLE::Stream*
BYTE* pImage = new BYTE[oHeader.RecLen - lOffset];
pStream->read(pImage, oHeader.RecLen - lOffset);
if (pDecryptor)
{
pDecryptor->Decrypt((char*)pImage, oHeader.RecLen - lOffset, 0);
}
std::wstring strFile = L"Image " + std::to_wstring(nImagesCount + 1) + sExt;
CFile fileImage;
......@@ -224,6 +233,4 @@ void CRecordOfficeArtBlip::ReadFromStream(SRecordHeader & oHeader, POLE::Stream*
m_sFileName = strFile;
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment