Commit ee577e62 authored by ElenaSubbotina's avatar ElenaSubbotina

DocFormat - fix user file

parent f230dc25
......@@ -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;
......
/*
* (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 );
}
};
}
\ No newline at end of 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();
......
......@@ -544,6 +544,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" ));
......
......@@ -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);
_buf block ((unsigned char*)&i, 4, false);
_buf pDecryptedKey = HashAppend( pHashBuf, block, cryptData.hashAlgorithm);
CorrectHashSize(pDecryptedKey, cryptData.keySize, 0);
if (cryptData.keySize == 5)
CorrectHashSize(hashKey, 16, 0); //40-bit crypt key !!!
CorrectHashSize(pDecryptedKey, 16, 0); //40-bit crypt key !!!
rc4Decryption.SetKey(hashKey.ptr, hashKey.size);
CipherARCFOUR rc4;
_buf pInp(data_inp + pos, sz, false);
_buf pOut(data_out + pos, sz, false);
DecryptCipher(empty, empty, pInp, pOut, cryptData.cipherAlgorithm);
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++;
pos += sz, i++;
}
}
else
......
......@@ -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();
......
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