Compare commits

..

7 Commits

Author SHA1 Message Date
0708c1f45a . 2017-06-22 12:32:00 +03:00
ee577e629a DocFormat - fix user file 2017-06-21 19:50:02 +03:00
f230dc2555 add binary test (file as resource) 2017-06-21 18:36:06 +03:00
11c9d74e68 fix bug #35161 2017-06-21 17:16:00 +03:00
d61a955c38 . 2017-06-20 19:04:55 +03:00
acfb96e3c3 . 2017-06-20 17:53:11 +03:00
d2e3cc47f2 . 2017-06-20 17:16:27 +03:00
19 changed files with 500 additions and 131 deletions

View File

@ -507,9 +507,9 @@ namespace DocFileFormat
class FileInformationBlock
{
public:
bool m_bOlderVersion;
int m_CodePage;
FibBase m_FibBase;
bool m_bOlderVersion;
int m_CodePage;
FibBase m_FibBase;
RgW97 m_RgW97;
RgLw97 m_RgLw97;

View File

@ -0,0 +1,60 @@
/*
* (c) Copyright Ascensio System SIA 2010-2017
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#pragma once
#include "RegularContainer.h"
namespace DocFileFormat
{
class OfficeArtFRITContainer: public RegularContainer
{
public:
static const unsigned short TYPE_CODE_0xF118 = 0xF118;
OfficeArtFRITContainer () : RegularContainer()
{
}
OfficeArtFRITContainer (IBinaryReader* _reader, unsigned int size, unsigned int typeCode, unsigned int version, unsigned int instance) : RegularContainer (_reader, size, typeCode, version, instance)
{
}
virtual ~OfficeArtFRITContainer()
{
}
virtual Record* NewObject (IBinaryReader* _reader, unsigned int bodySize, unsigned int typeCode, unsigned int version, unsigned int instance)
{
return new OfficeArtFRITContainer( _reader, bodySize, typeCode, version, instance );
}
};
}

View File

@ -50,6 +50,7 @@
#include "GroupShapeRecord.h"
#include "OfficeArtClientTextbox.h"
#include "UnknownRecord.h"
#include "OfficeArtFRITContainer.h"
namespace DocFileFormat
{
@ -135,6 +136,7 @@ namespace DocFileFormat
case GroupContainer::TYPE_CODE_0xF003 : return new GroupContainer();
case GroupShapeRecord::TYPE_CODE_0xF009 : return new GroupShapeRecord ();
case OfficeArtClientTextbox::TYPE_CODE_0xF00D : return new OfficeArtClientTextbox ();
case OfficeArtFRITContainer::TYPE_CODE_0xF118 : return new OfficeArtFRITContainer ();
default:
return new UnknownRecord();

View File

@ -247,9 +247,8 @@ namespace DocFileFormat
{
freeform = false;
m_pXmlWriter->WriteAttribute( L"type", (std::wstring(L"#") + VMLShapeTypeMapping::GenerateTypeId(pShape->GetShapeType())));
m_pXmlWriter->WriteAttribute( L"style", FormatUtils::XmlEncode(buildStyle(pShape, pAnchor, options, pContainer->Index)));
}
m_pXmlWriter->WriteAttribute( L"style", FormatUtils::XmlEncode(buildStyle(pShape, pAnchor, options, pContainer->Index)));
if (pShape->is<LineType>())
{
@ -446,7 +445,7 @@ namespace DocFileFormat
{
yCoord = iter->op;
}break;
// OUTLINE
// LINE
case lineColor:
{
RGBColor lineColor((int)iter->op, RedFirst);
@ -493,6 +492,21 @@ namespace DocFileFormat
{
appendValueAttribute(&m_stroke, L"startarrowwidth", getArrowWidth( iter->op ));
}break;
case cxstyle:
{
if (pShape->GetShapeType() == NULL)
{
freeform = false;
m_pXmlWriter->WriteAttribute(L"type", L"#_x0000_t32");
}
switch(iter->op)
{
case 0: m_pXmlWriter->WriteAttribute(L"o:connectortype", L"straight"); break;
case 1: m_pXmlWriter->WriteAttribute(L"o:connectortype", L"elbow"); break;
case 2: m_pXmlWriter->WriteAttribute(L"o:connectortype", L"curved"); break;
case 3: m_pXmlWriter->WriteAttribute(L"o:connectortype", L"none"); break;
}
}break;
// FILL
case fillColor:
{
@ -544,6 +558,14 @@ namespace DocFileFormat
appendValueAttribute(&m_fill, L"r:id", std::wstring(( L"rId" ) + FormatUtils::IntToWideString(m_nImageId) ));
}
}break;
case fillBlipName:
{
std::wstring name;
FormatUtils::GetSTLCollectionFromBytes<std::wstring>(&name, iter->opComplex.get(), iter->op, ENCODING_UTF16);
if (!name.empty())
appendValueAttribute(&m_fill, L"o:title", FormatUtils::XmlEncode(name));
}break;
case fillOpacity:
{
appendValueAttribute(&m_fill, L"opacity", ( FormatUtils::IntToWideString( iter->op ) + L"f" ));

View File

@ -64,7 +64,8 @@ long COfficePPTFile::OpenFile(const std::wstring & sFileName, const std::wstring
m_pReader = new CPPTFileReader(pStgFrom, m_strTempDirectory);
CPPTFileReader* pptReader = (CPPTFileReader*)m_pReader;
pptReader->m_oDocumentInfo.m_strFileDirectory= GetDirectory(sFileName.c_str());
pptReader->m_oDocumentInfo.m_strFileDirectory = GetDirectory(sFileName.c_str());
pptReader->m_oDocumentInfo.m_strPassword = password;
if (pptReader->IsPowerPoint() == false)
{
@ -73,14 +74,14 @@ long COfficePPTFile::OpenFile(const std::wstring & sFileName, const std::wstring
return AVS_ERROR_FILEFORMAT;
}
if (pptReader->ReadPersistDirectory() == false)
return AVS_ERROR_FILEFORMAT;
if (pptReader->ReadPersists() == false)
return AVS_ERROR_FILEFORMAT;
if (pptReader->IsEncrypted())
{
CEncryptionHeader *pEncryptionHeader = pptReader->GetEncryptionHeader();
if (password.empty()) return AVS_ERROR_DRM;
if (!pEncryptionHeader) return AVS_ERROR_FILEFORMAT;
if (password.empty()) return AVS_ERROR_DRM;
if (pEncryptionHeader->bStandard)
{
@ -92,7 +93,8 @@ long COfficePPTFile::OpenFile(const std::wstring & sFileName, const std::wstring
}
if (DecryptOfficeFile(&Decryptor) == false) return AVS_ERROR_DRM;
return OpenFile(m_sTempDecryptFileName, L"");
return AVS_ERROR_PASSWORD;
//return OpenFile(m_sTempDecryptFileName, L"");
}
else
{
@ -106,12 +108,15 @@ long COfficePPTFile::OpenFile(const std::wstring & sFileName, const std::wstring
}
if (DecryptOfficeFile(&Decryptor) == false) return AVS_ERROR_DRM;
return OpenFile(m_sTempDecryptFileName, L"");
return AVS_ERROR_PASSWORD;
pptReader->ReadDocument(&Decryptor);
//return OpenFile(m_sTempDecryptFileName, L"");
}
}
else
{
pptReader->ReadSlideList();
pptReader->ReadDocument(NULL);
m_Status = READMODE;
}

View File

@ -40,6 +40,7 @@ public:
std::vector<CPPTUserInfo*> m_arUsers;
std::wstring m_strFileDirectory;
std::map<int, std::wstring> m_mapStoreImageFile;
std::wstring m_strPassword;
CPPTDocumentInfo() : m_oCurrentUser(), m_arUsers()
{
@ -63,7 +64,7 @@ public:
}
}
bool ReadFromStream(CRecordCurrentUserAtom* pCurrentUser, POLE::Stream* pStream, std::wstring strFolderMem)
bool ReadFromStream(CRecordCurrentUserAtom* pCurrentUser, POLE::Stream* pStream)
{
m_oCurrentUser.FromAtom(pCurrentUser);
@ -86,8 +87,9 @@ public:
pInfo->m_strFileDirectory = m_strFileDirectory;
pInfo->m_bEncrypt = m_oCurrentUser.m_bIsEncrypt;
pInfo->m_strPassword = m_strPassword;
bool bResult = pInfo->ReadFromStream(&oUserAtom, pStream, strFolderMem);
bool bResult = pInfo->ReadFromStream(&oUserAtom, pStream);
offsetToEdit = pInfo->m_oUser.m_nOffsetLastEdit;
@ -104,13 +106,16 @@ public:
pInfo = NULL;
}
if (m_arUsers.empty() == false)
{
if (m_arUsers[0]->m_bEncrypt == false)
{
m_arUsers[0]->FromDocument();
}
}
return true;
}
bool LoadDocument(std::wstring strFolderMem)
{
if (m_arUsers.empty()) return false;
m_arUsers[0]->ReadExtenalObjects(strFolderMem);
m_arUsers[0]->FromDocument();
return true;
}
};

View File

@ -47,6 +47,7 @@ CPPTUserInfo::CPPTUserInfo() : CDocument(),
m_mapMasters(),
m_mapNotes(),
m_mapSlides(),
m_bEncrypt(false),
m_arOffsetPictures()
{
m_pDocumentInfo = NULL;
@ -128,7 +129,7 @@ void CPPTUserInfo::Clear()
m_arOffsetPictures.clear();
}
bool CPPTUserInfo::ReadFromStream(CRecordUserEditAtom* pUser, POLE::Stream* pStream, std::wstring strFolderMem)
bool CPPTUserInfo::ReadFromStream(CRecordUserEditAtom* pUser, POLE::Stream* pStream)
{
m_oUser.FromAtom(pUser);
@ -149,8 +150,9 @@ bool CPPTUserInfo::ReadFromStream(CRecordUserEditAtom* pUser, POLE::Stream* pStr
oPersist.ReadFromStream(oHeader, pStream);
oPersist.ToMap(&m_mapOffsetInPIDs);
//--------------------------------------------------------------------------------------------------
CRYPT::ECMADecryptor *pDecryptor = NULL;
std::map<DWORD, DWORD>::iterator pPair = m_mapOffsetInPIDs.find(m_oUser.m_nEncryptRef);
if (pPair != m_mapOffsetInPIDs.end())
{
StreamUtils::StreamSeek(pPair->second, pStream);
@ -161,7 +163,17 @@ bool CPPTUserInfo::ReadFromStream(CRecordUserEditAtom* pUser, POLE::Stream* pStr
m_bEncrypt = true;
m_oEncryptionHeader.ReadFromStream(oHeader, pStream);
return true;
pDecryptor = new CRYPT::ECMADecryptor();
pDecryptor->SetCryptData(m_oEncryptionHeader.crypt_data_aes);
if (pDecryptor->SetPassword(m_strPassword) == false)
{
delete pDecryptor;
pDecryptor = NULL;
//return true;
}
return true;//read persis decrypt
}
}
//--------------------------------------------------------------------------------------------------
@ -170,15 +182,45 @@ bool CPPTUserInfo::ReadFromStream(CRecordUserEditAtom* pUser, POLE::Stream* pStr
if (pPair == m_mapOffsetInPIDs.end())
return false;
StreamUtils::StreamSeek(pPair->second, pStream);
DWORD offset_stream = pPair->second;
StreamUtils::StreamSeek(offset_stream, pStream);
oHeader.ReadFromStream(pStream);
if (RECORD_TYPE_DOCUMENT != oHeader.RecType)
if (pDecryptor)
{
return false;
}
POLE::Storage *pStorageOut = NULL;
POLE::Stream *pStreamTmp = NULL;
m_oDocument.ReadFromStream(oHeader, pStream);
std::wstring sTemp = m_strFileDirectory + FILE_SEPARATOR_STR + L"~tempFile.ppt";
pStorageOut = new POLE::Storage(sTemp.c_str());
pStorageOut->open(true, true);
pStreamTmp = new POLE::Stream(pStorageOut, "Tmp", true, oHeader.RecLen);
unsigned char* data_stream = new unsigned char[oHeader.RecLen];
pStream->read(data_stream, oHeader.RecLen);
pDecryptor->Decrypt((char*)data_stream, oHeader.RecLen, m_oUser.m_nDocumentRef);
pStreamTmp->write(data_stream, oHeader.RecLen);
pStreamTmp->flush();
pStreamTmp->seek(0);
m_oDocument.ReadFromStream(oHeader, pStreamTmp);
delete pStream;
delete pStorageOut;
//NSFile::DeleteFile(sTemp);
}
else
{
if (RECORD_TYPE_DOCUMENT != oHeader.RecType)
{
return false;
}
m_oDocument.ReadFromStream(oHeader, pStream);
}
Clear();
@ -190,11 +232,12 @@ bool CPPTUserInfo::ReadFromStream(CRecordUserEditAtom* pUser, POLE::Stream* pStr
if (nIndexPsrRef != m_mapOffsetInPIDs.end())
{
long offset = (long)nIndexPsrRef->second;
offset_stream = nIndexPsrRef->second;
StreamUtils::StreamSeek(offset, pStream);
StreamUtils::StreamSeek(offset_stream, pStream);
oHeader.ReadFromStream(pStream);
CRecordSlide* pSlide = new CRecordSlide();
pSlide->ReadFromStream(oHeader, pStream);
pSlide->m_oPersist = m_oDocument.m_arMasterPersists[index];
@ -215,8 +258,8 @@ bool CPPTUserInfo::ReadFromStream(CRecordUserEditAtom* pUser, POLE::Stream* pStr
if (m_mapOffsetInPIDs.end() != nIndexPsrRef)
{
long offset = (long)nIndexPsrRef->second;
StreamUtils::StreamSeek(offset, pStream);
offset_stream = nIndexPsrRef->second;
StreamUtils::StreamSeek(offset_stream, pStream);
oHeader.ReadFromStream(pStream);
CRecordSlide* pSlide = new CRecordSlide();
@ -240,9 +283,9 @@ bool CPPTUserInfo::ReadFromStream(CRecordUserEditAtom* pUser, POLE::Stream* pStr
if (m_mapOffsetInPIDs.end() != nIndexPsrRef)
{
long offset = (long)nIndexPsrRef->second;
offset_stream = (long)nIndexPsrRef->second;
StreamUtils::StreamSeek(offset, pStream);
StreamUtils::StreamSeek(offset_stream, pStream);
oHeader.ReadFromStream(pStream);
@ -283,9 +326,9 @@ bool CPPTUserInfo::ReadFromStream(CRecordUserEditAtom* pUser, POLE::Stream* pStr
if (m_mapOffsetInPIDs.end() != nIndexPsrRef)
{
long offset = (long)nIndexPsrRef->second;
offset_stream = nIndexPsrRef->second;
StreamUtils::StreamSeek(offset, pStream);
StreamUtils::StreamSeek(offset_stream, pStream);
oHeader.ReadFromStream(pStream);
@ -300,9 +343,9 @@ bool CPPTUserInfo::ReadFromStream(CRecordUserEditAtom* pUser, POLE::Stream* pStr
if (m_mapOffsetInPIDs.end() != nIndexPsrRef)
{
long offset = (long)nIndexPsrRef->second;
offset_stream = nIndexPsrRef->second;
StreamUtils::StreamSeek(offset, pStream);
StreamUtils::StreamSeek(offset_stream, pStream);
oHeader.ReadFromStream(pStream);
@ -314,7 +357,11 @@ bool CPPTUserInfo::ReadFromStream(CRecordUserEditAtom* pUser, POLE::Stream* pStr
m_mapHandoutMasters.insert( std::pair<DWORD, CRecordSlide*>(0, pSlide ));
}
}
return true;
}
//--------------------------------------------------------------------------------------------
void CPPTUserInfo::ReadExtenalObjects(std::wstring strFolderMem)
{
// так... теперь берем всю инфу о ExObject -----------------------------
m_oExMedia.m_strPresentationDirectory = strFolderMem;
m_oExMedia.m_strSourceDirectory = m_strFileDirectory;
@ -364,20 +411,12 @@ bool CPPTUserInfo::ReadFromStream(CRecordUserEditAtom* pUser, POLE::Stream* pStr
m_arrFonts.push_back(oFont);
}
//FromDocument();
// FromDocument - должен вызываться после того, как загрузятся все (!!!) юзеры
// теперь заполним пустые картинки
//std::vector<CRecordBlipStoreContainer*> oArray;
m_oDocument.GetRecordsByType(&m_arrBlipStore, true, true);
if (0 < m_arrBlipStore.size())
{
m_bIsSetupEmpty = TRUE;
m_arrBlipStore[0]->SetUpPicturesInfos(&m_arOffsetPictures);
}
return TRUE;
}
void CPPTUserInfo::FromDocument()

View File

@ -50,6 +50,7 @@ public:
CEncryptionHeader m_oEncryptionHeader;
bool m_bEncrypt;
std::wstring m_strPassword;
std::map<DWORD, CRecordSlide*> m_mapSlides;
std::map<DWORD, CRecordSlide*> m_mapMasters;
@ -122,7 +123,8 @@ public:
void Clear();
bool ReadFromStream(CRecordUserEditAtom* pUser, POLE::Stream* pStream, std::wstring strFolderMem);
bool ReadFromStream(CRecordUserEditAtom* pUser, POLE::Stream* pStream);
void ReadExtenalObjects(std::wstring strFolderMem);
void FromDocument();
void NormalizeCoords(long lWidth, long lHeight);

View File

@ -56,7 +56,6 @@ public:
m_bIsPPTFile(false),
m_pDocStream(NULL),
m_pPictureStream(NULL),
m_lImagesCount(0),
m_strMemoryForder(strTemp),
m_oDocumentInfo()
{
@ -114,7 +113,7 @@ public:
if (m_oDocumentInfo.m_arUsers.empty())
return m_oDocumentInfo.m_oCurrentUser.m_bIsEncrypt; //wps не выставляет флаг!
return &m_oDocumentInfo.m_arUsers[0]->m_bEncrypt;
return m_oDocumentInfo.m_arUsers[0]->m_bEncrypt;
}
CEncryptionHeader* GetEncryptionHeader()
{
@ -122,26 +121,14 @@ public:
return &m_oDocumentInfo.m_arUsers[0]->m_oEncryptionHeader;
}
bool ReadPersistDirectory()
bool ReadPersists()
{
// нужно вызывать РОВНО один раз...
bool bRes = SavePictures();
return m_oDocumentInfo.ReadFromStream(&m_oCurrentUser, GetDocStream(), m_strMemoryForder);
return m_oDocumentInfo.ReadFromStream(&m_oCurrentUser, GetDocStream());
}
void ReadSlideList()
void ReadDocument(CRYPT::ECMADecryptor *pDecryptor)
{
if (m_oDocumentInfo.m_arUsers.size() > 0)
{
DWORD nPID = m_oDocumentInfo.m_arUsers[0]->m_oUser.m_nDocumentRef;
std::map<DWORD, DWORD>::iterator pPair = m_oDocumentInfo.m_arUsers[0]->m_mapOffsetInPIDs.find(nPID);
if (pPair == m_oDocumentInfo.m_arUsers[0]->m_mapOffsetInPIDs.end()) return;
DWORD offset = pPair->second;
StreamUtils::StreamSeek((long)offset, GetDocStream());
}
ReadPictures(pDecryptor);
m_oDocumentInfo.LoadDocument(m_strMemoryForder);
}
protected:
@ -194,20 +181,13 @@ protected:
return m_pPictureStream;
}
bool SavePictures()
void ReadPictures(CRYPT::ECMADecryptor *pDecryptor)
{
POLE::Stream* pStream = GetPictureStream();
if (NULL == pStream) return;
if (NULL == pStream)
{
return false;
}
SRecordHeader oHeader;
ULONG nRd = 0;
m_lImagesCount = 0;
// удаление картинок при завершении программы
while (true)
{
@ -220,11 +200,39 @@ protected:
art_blip.m_strMemoryForder = m_strMemoryForder;
art_blip.m_oDocumentInfo = &m_oDocumentInfo;
art_blip.ReadFromStream(oHeader, pStream);
if (pDecryptor)
{
POLE::Storage *pStorageOut = NULL;
POLE::Stream *pStreamTmp = NULL;
std::wstring sTemp = m_strMemoryForder + FILE_SEPARATOR_STR + L"~tempFile.ppt";
pStorageOut = new POLE::Storage(sTemp.c_str());
pStorageOut->open(true, true);
pStreamTmp = new POLE::Stream(pStorageOut, "Tmp", true, oHeader.RecLen);
unsigned char* data_stream = new unsigned char[oHeader.RecLen];
pStream->read(data_stream, oHeader.RecLen);
pDecryptor->Decrypt((char*)data_stream, oHeader.RecLen, 0);
pStreamTmp->write(data_stream, oHeader.RecLen);
pStreamTmp->flush();
pStreamTmp->seek(0);
art_blip.ReadFromStream(oHeader, pStreamTmp);
delete pStream;
delete pStorageOut;
//NSFile::DeleteFile(sTemp);
}
else
{
art_blip.ReadFromStream(oHeader, pStream);
}
}
return true;
}
private:
bool m_bDualStorage;
@ -239,7 +247,6 @@ public:
std::wstring m_strMemoryForder;
std::vector<bool> m_arLoadImageFlags;
DWORD m_lImagesCount;
CPPTDocumentInfo m_oDocumentInfo;
};

View File

@ -35,11 +35,13 @@
#include "../Reader/ReadStructures.h"
#include "../../../ASCOfficePPTXFile/Editor/Drawing/Shapes/BaseShape/PPTShape/Enums.h"
#include "../../../Common/3dParty/pole/pole.h"
#include "../../../OfficeCryptReader/source/CryptTransform.h"
using namespace NSPresentationEditor;
struct SRecordHeader
class SRecordHeader
{
public:
BYTE RecVersion;
USHORT RecInstance;
USHORT RecType;
@ -48,7 +50,8 @@ struct SRecordHeader
SRecordHeader()
{
RecVersion = 0;
RecInstance = RecType = 0;
RecInstance = 0;
RecType = 0;
RecLen = 0;
}

View File

@ -1155,8 +1155,8 @@ namespace NSBinPptxRW
str = L"<Relationship Id=\"rId" + std::to_wstring(m_lNextRelsID++) +
L"\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide\" Target=\"../notesSlides/notesSlide" +
std::to_wstring(nIndexNotes + 1) + L".xml\"/>";
m_pWriter->WriteString(str);
}
m_pWriter->WriteString(str);
}
void CRelsGenerator::StartNotes(int nIndexSlide)
{
@ -1209,7 +1209,7 @@ namespace NSBinPptxRW
m_pWriter->WriteString(strRels);
}
void CRelsGenerator::EndPresentationRels(const bool& bIsCommentsAuthors = false, const bool& bIsNotesMaster = false)
void CRelsGenerator::EndPresentationRels(const bool& bIsCommentsAuthors = false, const bool& bIsNotesMaster)
{
if (bIsNotesMaster)
{

View File

@ -0,0 +1,58 @@
/*
* (c) Copyright Ascensio System SIA 2010-2017
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#include "HiddenMemberSet.h"
#include "BiffString.h"
namespace XLS
{
BiffStructurePtr HiddenMemberSet::clone()
{
return BiffStructurePtr(new HiddenMemberSet(*this));
}
void HiddenMemberSet::load(CFRecord& record)
{
record >> cMemberName;
for (_UINT32 i = 0; i < cMemberName; i++)
{
XLUnicodeString val;
record >> val;
rgMemberName.push_back(val.value());
}
}
} // namespace XLS

View File

@ -0,0 +1,54 @@
/*
* (c) Copyright Ascensio System SIA 2010-2017
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#pragma once
#include "BiffStructure.h"
namespace XLS
{
class HiddenMemberSet : public BiffStructure
{
BASE_STRUCTURE_DEFINE_CLASS_NAME(HiddenMemberSet)
public:
BiffStructurePtr clone();
static const ElementType type = typeHiddenMemberSet;
virtual void load(CFRecord& record);
_UINT32 cMemberName;
std::vector<std::wstring> rgMemberName;
};
} // namespace XLS

View File

@ -0,0 +1,58 @@
/*
* (c) Copyright Ascensio System SIA 2010-2017
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#include "SXVIFlags.h"
#include "BiffString.h"
namespace XLS
{
BiffStructurePtr SXVIFlags::clone()
{
return BiffStructurePtr(new SXVIFlags(*this));
}
void SXVIFlags::load(CFRecord& record)
{
unsigned short flags;
record >> flags;
fDrilledMember = GETBIT(flags, 0);
fHasChildren = GETBIT(flags, 1);
fCollapsedMember = GETBIT(flags, 2);
fHasChildrenEst = GETBIT(flags, 3);
fOlapFilterSelected = GETBIT(flags, 4);
}
} // namespace XLS

View File

@ -0,0 +1,57 @@
/*
* (c) Copyright Ascensio System SIA 2010-2017
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#pragma once
#include "BiffStructure.h"
namespace XLS
{
class SXVIFlags : public BiffStructure
{
BASE_STRUCTURE_DEFINE_CLASS_NAME(SXVIFlags)
public:
BiffStructurePtr clone();
static const ElementType type = typeSXVIFlags;
virtual void load(CFRecord& record);
bool fDrilledMember;
bool fHasChildren;
bool fCollapsedMember;
bool fHasChildrenEst;
bool fOlapFilterSelected;
};
} // namespace XLS

View File

@ -41,7 +41,7 @@ protected:
void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs &params);
virtual unsigned int GetDefaultDiscardBytes() const {return 0;}
FixedSizeSecBlock<byte, 512> m_state;
FixedSizeSecBlock<byte, 256> m_state;
byte m_x, m_y;
};

View File

@ -381,8 +381,8 @@ bool EncryptCipher(_buf & key, _buf & iv, _buf & data_inp, _buf & data_out, CRYP
return true;
}
ARC4::Decryption rc4Decryption;
//CipherARCFOUR rc4Decryption;
//ARC4::Decryption rc4Decryption;
CipherARCFOUR rc4Decryption;
bool DecryptCipher(_buf & key, _buf & iv, _buf & data_inp, _buf & data_out, CRYPT_METHOD::_cipherAlgorithm algorithm,
StreamTransformationFilter::BlockPaddingScheme padding = StreamTransformationFilter::NO_PADDING)
@ -398,8 +398,8 @@ bool DecryptCipher(_buf & key, _buf & iv, _buf & data_inp, _buf & data_out, CRY
}
else if (algorithm == CRYPT_METHOD::RC4)
{
//rc4Decryption.Decode(data_inp.ptr, data_inp.size, data_out.ptr, data_out.size);
rc4Decryption.ProcessData(data_out.ptr, data_inp.ptr, data_inp.size);
rc4Decryption.Decode(data_inp.ptr, data_inp.size, data_out.ptr, data_out.size);
//rc4Decryption.ProcessData(data_out.ptr, data_inp.ptr, data_inp.size);
}
else //AES
{
@ -485,7 +485,10 @@ bool ECMADecryptor::SetPassword(std::wstring _password)
CorrectHashSize(verifierKey, 16, 0); //40-bit crypt key !!!
if (cryptData.cipherAlgorithm == CRYPT_METHOD::RC4)
rc4Decryption.SetKey(verifierKey.ptr, verifierKey.size);
{
//rc4Decryption.SetKey(verifierKey.ptr, verifierKey.size);
rc4Decryption.Init(CipherARCFOUR::rtl_Cipher_DirectionDecode, verifierKey.ptr, verifierKey.size, 0, 0);
}
//--------------------------------------------
_buf decryptedVerifierHashInputBytes;
@ -512,12 +515,12 @@ void ECMADecryptor::SetCryptData(_ecmaCryptData & data)
{
cryptData = data;
}
void ECMADecryptor::Decrypt(char* data , const size_t size, const unsigned long stream_pos)
void ECMADecryptor::Decrypt(char* data , const size_t size, const unsigned long start_iv_block)
{
if (bVerify)
{
unsigned char* data_out = NULL;
Decrypt((unsigned char*)data, size, data_out);
Decrypt((unsigned char*)data, size, data_out, start_iv_block);
if (data_out)
{
@ -565,7 +568,7 @@ bool ECMADecryptor::CheckDataIntegrity(unsigned char* data, int size)
return (hmac == expected);
}
void ECMADecryptor::Decrypt(unsigned char* data_ptr, int data_size, unsigned char*& data_out)
void ECMADecryptor::Decrypt(unsigned char* data_ptr, int data_size, unsigned char*& data_out, int start_iv_block)
{
data_out = NULL;
@ -592,7 +595,7 @@ void ECMADecryptor::Decrypt(unsigned char* data_ptr, int data_size, unsigned ch
_buf iv(cryptData.blockSize);
memset( iv.ptr, 0x00, cryptData.blockSize );
int i = 0, sz = 4096, pos = 0;
int i = start_iv_block, sz = 4096, pos = 0;
while (pos < size)
{
@ -611,50 +614,34 @@ void ECMADecryptor::Decrypt(unsigned char* data_ptr, int data_size, unsigned ch
pos += sz; i++;
}
//--------------------------------------------
_buf pEncVerKeyMac (cryptData.encryptedHmacKey);
_buf pEncVerValueMac (cryptData.encryptedHmacValue);
_buf iv1(cryptData.blockSize);
memset( iv1.ptr, 0x00, cryptData.blockSize );
i = 0;
_buf pIndex1((unsigned char*)&i, 4);
iv1 = HashAppend(pDataSalt, pIndex1, cryptData.hashAlgorithm);
CorrectHashSize(iv1, cryptData.blockSize, 0x36);
_buf pOut1(pEncVerKeyMac.size);
_buf pOut2(pEncVerValueMac.size);
DecryptCipher(pDecryptedKey, iv, pEncVerKeyMac, pOut1, cryptData.cipherAlgorithm);
DecryptCipher(pDecryptedKey, iv, pEncVerValueMac, pOut2, cryptData.cipherAlgorithm);
}
else
{
if (cryptData.cipherAlgorithm == CRYPT_METHOD::RC4)
{
int i = 0, sz = 512, pos = 0;
int i = start_iv_block, sz = 512, pos = 0;
_buf pHashBuf = HashAppend(pSalt, pPassword, cryptData.hashAlgorithm);
while (pos < size)
{
if (pos + sz > size)
sz = size - pos;
_buf hashKey = GenerateHashKey(pSalt, pPassword, cryptData.hashSize, cryptData.spinCount, cryptData.hashAlgorithm, i);
CorrectHashSize(hashKey, cryptData.keySize, 0);
if (cryptData.keySize == 5)
CorrectHashSize(hashKey, 16, 0); //40-bit crypt key !!!
rc4Decryption.SetKey(hashKey.ptr, hashKey.size);
_buf pInp(data_inp + pos, sz, false);
_buf pOut(data_out + pos, sz, false);
_buf block ((unsigned char*)&i, 4, false);
DecryptCipher(empty, empty, pInp, pOut, cryptData.cipherAlgorithm);
_buf pDecryptedKey = HashAppend( pHashBuf, block, cryptData.hashAlgorithm);
CorrectHashSize(pDecryptedKey, cryptData.keySize, 0);
if (cryptData.keySize == 5)
CorrectHashSize(pDecryptedKey, 16, 0); //40-bit crypt key !!!
pos += sz; i++;
CipherARCFOUR rc4;
rc4.Init(CipherARCFOUR::rtl_Cipher_DirectionDecode, pDecryptedKey.ptr, pDecryptedKey.size, 0, 0);
rc4.Decode(data_inp + pos, sz, data_out + pos, sz);
pos += sz, i++;
}
}
else

View File

@ -128,9 +128,9 @@ public:
ECMADecryptor();
virtual ~ECMADecryptor();
void Decrypt (unsigned char* data, int size, unsigned char*& data_out);
void Decrypt (unsigned char* data, int size, unsigned char*& data_out, int start_iv_block = 0);
virtual void Decrypt (char* data, const size_t size, const unsigned long stream_pos);
virtual void Decrypt (char* data, const size_t size, const unsigned long start_iv_block);
virtual bool SetPassword (std::wstring password);
virtual bool IsVerify();

View File

@ -38,7 +38,7 @@ using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Microsoft.Office.Interop.Word;
//using Microsoft.Office.Interop.Word;
namespace WindowsFormsApplication1
{
@ -149,7 +149,17 @@ namespace WindowsFormsApplication1
}
numBytesToRead = bytes.Length;
textBox2.Text = Convert.ToBase64String(bytes, Base64FormattingOptions.None);
//textBox2.Text = Convert.ToBase64String(bytes, Base64FormattingOptions.None);
string s = "static const unsigned char c_res[" + Convert.ToString(bytes.Length) + "] = {";
int nLen = bytes.Length;
for (int i = 0; i < nLen; i++)
{
s += Convert.ToString(bytes[i]);
if (i != (nLen - 1))
s += ",";
}
s += "};";
textBox2.Text = s;
}
}