mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
Fix bug #72685
This commit is contained in:
@ -12,7 +12,7 @@ PWD_ROOT_DIR = $$PWD
|
||||
|
||||
include($$CORE_ROOT_DIR/Common/base.pri)
|
||||
|
||||
ADD_DEPENDENCY(kernel, UnicodeConverter, graphics)
|
||||
ADD_DEPENDENCY(kernel, UnicodeConverter, graphics, CryptoPPLib)
|
||||
|
||||
DEFINES += HWPFILE_USE_DYNAMIC_LIBRARY
|
||||
|
||||
|
||||
@ -4,6 +4,12 @@
|
||||
#include "../OfficeUtils/src/OfficeUtils.h"
|
||||
#include "../DesktopEditor/common/Directory.h"
|
||||
|
||||
// For decrypt
|
||||
#include "../../Common/3dParty/cryptopp/modes.h"
|
||||
#include "../../Common/3dParty/cryptopp/aes.h"
|
||||
#include "../../Common/3dParty/cryptopp/filters.h"
|
||||
// ----------
|
||||
|
||||
#define DEFAULT_BUFFER_SIZE 8096
|
||||
|
||||
namespace HWP
|
||||
@ -67,7 +73,7 @@ bool CHWPFile::Open()
|
||||
if (!m_oFileHeader.Distributable() && !GetBodyText(m_nVersion))
|
||||
return false;
|
||||
|
||||
if (!m_oFileHeader.Distributable() && !GetViewText(m_nVersion))
|
||||
if (m_oFileHeader.Distributable() && !GetViewText(m_nVersion))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@ -292,8 +298,43 @@ bool CHWPFile::Decrypt(CHWPStream& oInput, CHWPStream& oBuffer)
|
||||
if (256 != nSize)
|
||||
return false;
|
||||
|
||||
//TODO:: реализовать
|
||||
return false;
|
||||
CHWPStream oDocData(256);
|
||||
oDocData.Copy(oInput, 256);
|
||||
oInput.Skip(256);
|
||||
|
||||
int nSeed;
|
||||
oDocData.ReadInt(nSeed);
|
||||
oDocData.Skip(-4);
|
||||
|
||||
srand(nSeed);
|
||||
|
||||
unsigned char chKey;
|
||||
|
||||
for (unsigned int unIndex = 0, unCount = 0; unIndex < 256; ++unIndex)
|
||||
{
|
||||
if (0 == unCount)
|
||||
{
|
||||
chKey = rand() & 0xFF;
|
||||
unCount = (rand() & 0xF) + 1;
|
||||
}
|
||||
if (unIndex >= 4)
|
||||
*(oDocData.GetCurPtr() + unIndex) = oDocData[unIndex] ^ chKey;
|
||||
|
||||
--unCount;
|
||||
}
|
||||
|
||||
int nHashOffset = (nSeed & 0x0f) + 4;
|
||||
|
||||
oBuffer.Expand(oInput.SizeToEnd());
|
||||
|
||||
using namespace CryptoPP;
|
||||
|
||||
ECB_Mode<AES>::Decryption oDecryptor;
|
||||
oDecryptor.SetKey((byte*)(oDocData.GetCurPtr() + nHashOffset), 16);
|
||||
|
||||
ArraySource((byte*)oInput.GetCurPtr(), oInput.SizeToEnd(), true, new StreamTransformationFilter(oDecryptor, new ArraySink( (byte*)oBuffer.GetCurPtr(), oBuffer.GetSize()), StreamTransformationFilter::NO_PADDING));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CHWPFile::GetBodyText(int nVersion)
|
||||
|
||||
@ -529,8 +529,6 @@ int CHWPSection::ParseCtrlRecurse(CCtrl* pCurrCtrl, int nRunLevel, CHWPStream& o
|
||||
ParseRecurse(pNewPara, nLevel, oBuffer, 0, nVersion);
|
||||
}
|
||||
else if (ECtrlObjectType::Shape == pCtrl->GetCtrlType())
|
||||
// else if (nullptr != dynamic_cast<CCtrlShapeRect*>(pCtrl) ||
|
||||
// nullptr != dynamic_cast<CCtrlGeneralShape*>(pCtrl))
|
||||
{
|
||||
CCtrlCommon* pCtrlCommon = (CCtrlCommon*)pCtrl;
|
||||
oBuffer.Skip(-6);
|
||||
@ -573,7 +571,6 @@ int CHWPSection::ParseCtrlRecurse(CCtrl* pCurrCtrl, int nRunLevel, CHWPStream& o
|
||||
case HWPTAG_SHAPE_COMPONENT_TEXTART:
|
||||
case HWPTAG_SHAPE_COMPONENT_UNKNOWN:
|
||||
{
|
||||
// if (nullptr != dynamic_cast<CCtrlGeneralShape*>(pCtrl))
|
||||
if (ECtrlObjectType::Shape == pCtrl->GetCtrlType())
|
||||
ParseCtrlRecurse((CCtrlGeneralShape*)pCtrl, nLevel, oBuffer, 0, nVersion);
|
||||
else
|
||||
@ -856,6 +853,8 @@ int CHWPSection::ParseCtrlRecurse(CCtrl* pCurrCtrl, int nRunLevel, CHWPStream& o
|
||||
}
|
||||
}
|
||||
|
||||
oBuffer.RemoveLastSavedPos();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -895,6 +894,7 @@ int CHWPSection::ParseContainerRecurse(CCtrlContainer* pContainer, int nRunLevel
|
||||
while (oBuffer.CanRead())
|
||||
{
|
||||
oBuffer.ReadInt(nHeader);
|
||||
oBuffer.Skip(-4);
|
||||
nTagNum = nHeader & 0x3FF; // 10 bits (0 - 9 bit)
|
||||
nLevel = (nHeader & 0xFFC00) >> 10; // 10 bits (10-19 bit)
|
||||
nSize = (nHeader & 0xFFF00000) >> 20; // 12 bits (20-31 bit)
|
||||
|
||||
@ -36,6 +36,11 @@ void CHWPStream::Clear()
|
||||
m_arSavedPositions.pop();
|
||||
}
|
||||
|
||||
void CHWPStream::Copy(CHWPStream& oStream, unsigned long ulSize)
|
||||
{
|
||||
memcpy(m_pCur, oStream.GetCurPtr(), (std::min)(SizeToEnd(), (unsigned long)(std::min)(ulSize, oStream.SizeToEnd())));
|
||||
}
|
||||
|
||||
void CHWPStream::SetStream(HWP_BYTE* pBuffer, unsigned long ulSize, bool bExternalBuffer)
|
||||
{
|
||||
m_pBegin = pBuffer;
|
||||
|
||||
@ -28,6 +28,7 @@ public:
|
||||
~CHWPStream();
|
||||
|
||||
void Clear();
|
||||
void Copy(CHWPStream& oStream, unsigned long ulSize);
|
||||
|
||||
void SetStream(HWP_BYTE* pBuffer, unsigned long ulSize, bool bExternalBuffer = true);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user