Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
onlyoffice_core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boris Kocherov
onlyoffice_core
Commits
9f98f07f
Commit
9f98f07f
authored
Jun 25, 2017
by
ElenaSubbotina
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Decryptors ... small refactoring
parent
9e1a0e36
Changes
20
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
223 additions
and
164 deletions
+223
-164
ASCOfficeDocFile/DocDocxConverter/WordDocument.cpp
ASCOfficeDocFile/DocDocxConverter/WordDocument.cpp
+1
-19
ASCOfficeXlsFile2/source/XlsFormat/Binary/CFRecord.cpp
ASCOfficeXlsFile2/source/XlsFormat/Binary/CFRecord.cpp
+2
-2
ASCOfficeXlsFile2/source/XlsFormat/Crypt/BiffDecoder_RCF.cpp
ASCOfficeXlsFile2/source/XlsFormat/Crypt/BiffDecoder_RCF.cpp
+36
-34
ASCOfficeXlsFile2/source/XlsFormat/Crypt/BiffDecoder_RCF.h
ASCOfficeXlsFile2/source/XlsFormat/Crypt/BiffDecoder_RCF.h
+13
-18
ASCOfficeXlsFile2/source/XlsFormat/Crypt/BinaryCodec_RCF.h
ASCOfficeXlsFile2/source/XlsFormat/Crypt/BinaryCodec_RCF.h
+1
-1
ASCOfficeXlsFile2/source/XlsFormat/Crypt/Crypt.h
ASCOfficeXlsFile2/source/XlsFormat/Crypt/Crypt.h
+2
-2
ASCOfficeXlsFile2/source/XlsFormat/Crypt/Decryptor.cpp
ASCOfficeXlsFile2/source/XlsFormat/Crypt/Decryptor.cpp
+9
-7
ASCOfficeXlsFile2/source/XlsFormat/Crypt/Decryptor.h
ASCOfficeXlsFile2/source/XlsFormat/Crypt/Decryptor.h
+4
-3
ASCOfficeXlsFile2/source/XlsFormat/Crypt/RC4Crypt.cpp
ASCOfficeXlsFile2/source/XlsFormat/Crypt/RC4Crypt.cpp
+21
-13
ASCOfficeXlsFile2/source/XlsFormat/Crypt/RC4Crypt.h
ASCOfficeXlsFile2/source/XlsFormat/Crypt/RC4Crypt.h
+3
-3
ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_records/FilePass.cpp
...XlsFile2/source/XlsFormat/Logic/Biff_records/FilePass.cpp
+1
-1
ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_records/StyleExt.cpp
...XlsFile2/source/XlsFormat/Logic/Biff_records/StyleExt.cpp
+1
-0
ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_structures/RC4EncryptionHeader.cpp
...e/XlsFormat/Logic/Biff_structures/RC4EncryptionHeader.cpp
+24
-23
ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_structures/RC4EncryptionHeader.h
...rce/XlsFormat/Logic/Biff_structures/RC4EncryptionHeader.h
+1
-1
ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_structures/XFProp.cpp
...lsFile2/source/XlsFormat/Logic/Biff_structures/XFProp.cpp
+4
-1
ASCOfficeXlsFile2/source/XlsXlsxConverter/XlsConverter.cpp
ASCOfficeXlsFile2/source/XlsXlsxConverter/XlsConverter.cpp
+5
-1
ASCOfficeXlsFile2/source/win32/XlsFormat.vcproj
ASCOfficeXlsFile2/source/win32/XlsFormat.vcproj
+0
-4
OfficeCryptReader/source/CryptTransform.cpp
OfficeCryptReader/source/CryptTransform.cpp
+68
-8
OfficeCryptReader/source/CryptTransform.h
OfficeCryptReader/source/CryptTransform.h
+6
-2
OfficeCryptReader/source/ECMACryptFile.cpp
OfficeCryptReader/source/ECMACryptFile.cpp
+21
-21
No files found.
ASCOfficeDocFile/DocDocxConverter/WordDocument.cpp
View file @
9f98f07f
...
...
@@ -139,7 +139,7 @@ namespace DocFileFormat
if
(
encryptionHeader
->
bStandard
)
{
CRYPT
::
RC4Decryptor
Decryptor
(
encryptionHeader
->
crypt_data_rc4
,
m_sPassword
,
1
);
CRYPT
::
RC4Decryptor
Decryptor
(
encryptionHeader
->
crypt_data_rc4
,
m_sPassword
);
if
(
Decryptor
.
IsVerify
()
==
false
)
{
...
...
@@ -153,24 +153,6 @@ namespace DocFileFormat
}
else
{
//POLE::Stream * pStream = NULL;
//if (m_pStorage->GetStream ("EncryptedSummaryInformation", &pStream))
//{
// VirtualStreamReader tStream( pStream, 0, FIB->m_bOlderVersion);
// _UINT32 StreamDescriptorArrayOffset = tStream.ReadUInt32();
// _UINT32 StreamDescriptorArraySize = tStream.ReadUInt32();
// for (int i = 0; i < StreamDescriptorArraySize; i++)
// {
// }
// _UINT32 EncryptedStreamDescriptorCount = tStream.ReadUInt32();
// for (int i = 0; i < EncryptedStreamDescriptorCount; i++)
// {
// }
// RELEASEOBJECT(pStream);
//}
CRYPT
::
ECMADecryptor
Decryptor
;
Decryptor
.
SetCryptData
(
encryptionHeader
->
crypt_data_aes
);
...
...
ASCOfficeXlsFile2/source/XlsFormat/Binary/CFRecord.cpp
View file @
9f98f07f
...
...
@@ -70,10 +70,10 @@ CFRecord::CFRecord(CFStreamPtr stream, GlobalWorkbookInfoPtr global_info)
case
rt_RRDHead
:
break
;
case
rt_BoundSheet8
:
global_info
->
decryptor
->
Decrypt
(
data_
+
sizeof
(
unsigned
int
),
size_
-
sizeof
(
unsigned
int
),
rec_data_pos
+
sizeof
(
unsigned
int
));
global_info
->
decryptor
->
Decrypt
(
data_
+
sizeof
(
unsigned
int
),
size_
-
sizeof
(
unsigned
int
),
rec_data_pos
+
sizeof
(
unsigned
int
)
,
1024
);
break
;
default:
global_info
->
decryptor
->
Decrypt
(
data_
,
size_
,
rec_data_pos
);
global_info
->
decryptor
->
Decrypt
(
data_
,
size_
,
rec_data_pos
,
1024
);
break
;
}
}
...
...
ASCOfficeXlsFile2/source/XlsFormat/Crypt/BiffDecoder_RCF.cpp
View file @
9f98f07f
...
...
@@ -34,10 +34,8 @@
namespace
CRYPT
{
BiffDecoderBase
::
BiffDecoderBase
(
int
BLOCKSIZE
)
:
mbValid
(
false
)
BiffDecoderBase
::
BiffDecoderBase
()
:
mbValid
(
false
)
{
RCF_BLOCKSIZE
=
BLOCKSIZE
;
}
...
...
@@ -51,34 +49,29 @@ bool BiffDecoderBase::verifyPassword(const std::wstring& rPassword)
mbValid
=
implVerify
(
rPassword
);
return
mbValid
;
}
void
BiffDecoderBase
::
decode
(
unsigned
char
*
pnDestData
,
const
unsigned
char
*
pnSrcData
,
const
long
nStreamPos
,
const
unsigned
short
nBytes
)
void
BiffDecoderBase
::
decode
(
unsigned
char
*
pnDestData
,
const
unsigned
char
*
pnSrcData
,
const
unsigned
short
nBytes
,
const
long
block_index
)
{
if
(
pnDestData
&&
pnSrcData
&&
(
nBytes
>
0
))
{
if
(
mbValid
)
implDecode
(
pnDestData
,
pnSrcData
,
n
StreamPos
,
nBytes
);
implDecode
(
pnDestData
,
pnSrcData
,
n
Bytes
,
block_index
);
else
memcpy
(
pnDestData
,
pnSrcData
,
nBytes
);
}
}
}}
/** Returns the block index of the passed stream position for RCF decryption. */
int
BiffDecoderBase
::
lclGetRcfBlock
(
long
nStreamPos
)
void
BiffDecoderBase
::
decode
(
unsigned
char
*
pnDestData
,
const
unsigned
char
*
pnSrcData
,
const
unsigned
short
nBytes
,
const
long
nStreamPos
,
const
unsigned
short
block_size
)
{
return
static_cast
<
int
>
(
nStreamPos
/
RCF_BLOCKSIZE
);
}
/** Returns the offset of the passed stream position in a block for RCF decryption. */
int
BiffDecoderBase
::
lclGetRcfOffset
(
long
nStreamPos
)
{
return
static_cast
<
int
>
(
nStreamPos
%
RCF_BLOCKSIZE
);
if
(
pnDestData
&&
pnSrcData
&&
(
nBytes
>
0
))
{
if
(
mbValid
)
implDecode
(
pnDestData
,
pnSrcData
,
nBytes
,
nStreamPos
,
block_size
);
else
memcpy
(
pnDestData
,
pnSrcData
,
nBytes
);
}
}
BiffDecoder_RCF
::
BiffDecoder_RCF
(
unsigned
char
pnSalt
[
16
],
unsigned
char
pnVerifier
[
16
],
unsigned
char
pnVerifierHash
[
16
],
int
BlockSize
)
:
BiffDecoderBase
(
BlockSize
),
BiffDecoder_RCF
::
BiffDecoder_RCF
(
unsigned
char
pnSalt
[
16
],
unsigned
char
pnVerifier
[
16
],
unsigned
char
pnVerifierHash
[
16
])
:
maPassword
(
16
,
0
),
maSalt
(
pnSalt
,
pnSalt
+
16
),
maVerifier
(
pnVerifier
,
pnVerifier
+
16
),
...
...
@@ -107,28 +100,37 @@ bool BiffDecoder_RCF::implVerify(const std::wstring& rPassword)
}
return
false
;
}
void
BiffDecoder_RCF
::
implDecode
(
unsigned
char
*
pnDestData
,
const
unsigned
char
*
pnSrcData
,
const
long
nStreamPos
,
const
unsigned
short
nBytes
)
void
BiffDecoder_RCF
::
implDecode
(
unsigned
char
*
pnDestData
,
const
unsigned
char
*
pnSrcData
,
const
unsigned
short
nBytes
,
const
long
block_index
)
{
maCodec
.
startBlock
(
block_index
);
maCodec
.
decode
(
pnDestData
,
pnSrcData
,
static_cast
<
int
>
(
nBytes
));
}
void
BiffDecoder_RCF
::
implDecode
(
unsigned
char
*
pnDestData
,
const
unsigned
char
*
pnSrcData
,
const
unsigned
short
nBytes
,
const
long
nStreamPos
,
const
unsigned
short
block_size
)
{
unsigned
char
*
pnCurrDest
=
pnDestData
;
const
unsigned
char
*
pnCurrSrc
=
pnSrcData
;
long
nCurrPos
=
nStreamPos
;
unsigned
short
nBytesLeft
=
nBytes
;
while
(
nBytesLeft
>
0
)
while
(
nBytesLeft
>
0
)
{
// initialize codec for current stream position
maCodec
.
startBlock
(
lclGetRcfBlock
(
nCurrPos
));
maCodec
.
skip
(
lclGetRcfOffset
(
nCurrPos
));
maCodec
.
startBlock
(
nCurrPos
/
block_size
);
const
long
offset
=
nCurrPos
%
block_size
;
maCodec
.
skip
(
offset
);
// decode the block
unsigned
short
nBlockLeft
=
static_cast
<
unsigned
short
>
(
get_BLOCKSIZE
()
-
lclGetRcfOffset
(
nCurrPos
)
);
unsigned
short
nBlockLeft
=
static_cast
<
unsigned
short
>
(
block_size
-
offset
);
unsigned
short
nDecBytes
=
nBytesLeft
<
nBlockLeft
?
nBytesLeft
:
nBlockLeft
;
maCodec
.
decode
(
pnCurrDest
,
pnCurrSrc
,
static_cast
<
int
>
(
nDecBytes
));
// prepare for next block
pnCurrDest
+=
nDecBytes
;
pnCurrSrc
+=
nDecBytes
;
nCurrPos
+=
nDecBytes
;
nBytesLeft
=
nBytesLeft
-
nDecBytes
;
}
}
...
...
ASCOfficeXlsFile2/source/XlsFormat/Crypt/BiffDecoder_RCF.h
View file @
9f98f07f
...
...
@@ -44,11 +44,9 @@ namespace CRYPT
class
BiffDecoderBase
{
public:
explicit
BiffDecoderBase
(
int
BLOCKSIZE
);
explicit
BiffDecoderBase
();
virtual
~
BiffDecoderBase
();
int
get_BLOCKSIZE
(){
return
RCF_BLOCKSIZE
;}
/** Implementation of the ::comphelper::IDocPasswordVerifier interface,
calls the new virtual function implVerify(). */
virtual
bool
verifyPassword
(
const
std
::
wstring
&
rPassword
);
...
...
@@ -57,21 +55,18 @@ public:
inline
bool
isValid
()
const
{
return
mbValid
;
}
/** Decodes nBytes unsigned chars and writes encrypted data into the buffer pnDestData. */
void
decode
(
unsigned
char
*
pnDestData
,
const
unsigned
char
*
pnSrcData
,
const
long
nStreamPos
,
const
unsigned
short
nBytes
);
int
lclGetRcfBlock
(
long
nStreamPos
);
int
lclGetRcfOffset
(
long
nStreamPos
);
virtual
void
decode
(
unsigned
char
*
pnDestData
,
const
unsigned
char
*
pnSrcData
,
const
unsigned
short
nBytes
,
const
long
nStreamPos
,
const
unsigned
short
block_size
);
virtual
void
decode
(
unsigned
char
*
pnDestData
,
const
unsigned
char
*
pnSrcData
,
const
unsigned
short
nBytes
,
const
long
block_index
);
private:
int
RCF_BLOCKSIZE
;
/** Derived classes implement password verification and initialization of
the decoder. */
virtual
bool
implVerify
(
const
std
::
wstring
&
rPassword
)
=
0
;
/** Implementation of decryption of a memory block. */
virtual
void
implDecode
(
unsigned
char
*
pnDestData
,
const
unsigned
char
*
pnSrcData
,
const
long
nStreamPos
,
const
unsigned
short
nBytes
)
=
0
;
virtual
void
implDecode
(
unsigned
char
*
pnDestData
,
const
unsigned
char
*
pnSrcData
,
const
unsigned
short
nBytes
,
const
long
nStreamPos
,
const
unsigned
short
block_size
)
=
0
;
virtual
void
implDecode
(
unsigned
char
*
pnDestData
,
const
unsigned
char
*
pnSrcData
,
const
unsigned
short
nBytes
,
const
long
block_index
)
=
0
;
private:
bool
mbValid
;
/// True = decoder is correctly initialized.
...
...
@@ -83,7 +78,7 @@ typedef ::boost::shared_ptr<BiffDecoderBase> BiffDecoderRef;
class
BiffDecoder_RCF
:
public
BiffDecoderBase
{
public:
explicit
BiffDecoder_RCF
(
unsigned
char
pnSalt
[
16
],
unsigned
char
pnVerifier
[
16
],
unsigned
char
pnVerifierHash
[
16
]
,
int
BlockSize
);
explicit
BiffDecoder_RCF
(
unsigned
char
pnSalt
[
16
],
unsigned
char
pnVerifier
[
16
],
unsigned
char
pnVerifierHash
[
16
]);
private:
...
...
@@ -91,9 +86,9 @@ private:
virtual
bool
implVerify
(
const
std
::
wstring
&
rPassword
);
/** Implementation of decryption of a memory block. */
virtual
void
implDecode
(
unsigned
char
*
pnDestData
,
const
unsigned
char
*
pnSrcData
,
const
long
nStreamPos
,
const
unsigned
short
nBytes
);
virtual
void
implDecode
(
unsigned
char
*
pnDestData
,
const
unsigned
char
*
pnSrcData
,
const
unsigned
short
nBytes
,
const
long
nStreamPos
,
const
unsigned
short
block_size
);
virtual
void
implDecode
(
unsigned
char
*
pnDestData
,
const
unsigned
char
*
pnSrcData
,
const
unsigned
short
nBytes
,
const
long
block_index
);
private:
BinaryCodec_RCF
maCodec
;
/// Cipher algorithm implementation.
std
::
vector
<
unsigned
short
>
maPassword
;
std
::
vector
<
unsigned
char
>
maSalt
;
...
...
ASCOfficeXlsFile2/source/XlsFormat/Crypt/BinaryCodec_RCF.h
View file @
9f98f07f
ASCOfficeXlsFile2/source/XlsFormat/Crypt/Crypt.h
View file @
9f98f07f
...
...
@@ -68,8 +68,8 @@ namespace CRYPT
{
public:
virtual
void
Encrypt
(
char
*
data
,
const
size_t
size
)
=
0
;
virtual
void
Decrypt
(
char
*
data
,
const
size_t
size
,
const
unsigned
long
stream_pos
)
=
0
;
virtual
void
Decrypt
(
char
*
data
,
const
size_t
size
,
const
unsigned
long
stream_pos
,
const
size_t
block_
size
)
=
0
;
virtual
void
Decrypt
(
char
*
data
,
const
size_t
size
,
const
unsigned
long
block_index
)
=
0
;
typedef
enum
{
...
...
ASCOfficeXlsFile2/source/XlsFormat/Crypt/Decryptor.cpp
View file @
9f98f07f
...
...
@@ -37,18 +37,20 @@
namespace
CRYPT
{
RC4Decryptor
::
RC4Decryptor
(
_rc4CryptData
&
header
,
std
::
wstring
_password
,
int
_type
)
:
crypt
(
new
RC4Crypt
(
header
,
_password
,
_type
))
RC4Decryptor
::
RC4Decryptor
(
_rc4CryptData
&
header
,
std
::
wstring
_password
)
:
crypt
(
new
RC4Crypt
(
header
,
_password
))
{
crypt_data
=
header
;
type
=
_type
;
}
void
RC4Decryptor
::
Decrypt
(
char
*
data
,
const
size_t
size
,
const
unsigned
long
stream_pos
)
void
RC4Decryptor
::
Decrypt
(
char
*
data
,
const
size_t
size
,
const
unsigned
long
stream_pos
,
const
size_t
block_size
)
{
crypt
->
Decrypt
(
data
,
size
,
stream_pos
);
crypt
->
Decrypt
(
data
,
size
,
stream_pos
,
block_size
);
}
void
RC4Decryptor
::
Decrypt
(
char
*
data
,
const
size_t
size
,
const
unsigned
long
block_index
)
{
crypt
->
Decrypt
(
data
,
size
,
block_index
);
}
bool
RC4Decryptor
::
IsVerify
()
{
return
crypt
->
IsVerify
();
...
...
@@ -57,7 +59,7 @@ namespace CRYPT
bool
RC4Decryptor
::
SetPassword
(
std
::
wstring
password
)
{
crypt
.
reset
();
crypt
=
CryptPtr
(
new
RC4Crypt
(
crypt_data
,
password
,
type
));
crypt
=
CryptPtr
(
new
RC4Crypt
(
crypt_data
,
password
));
if
(
crypt
)
return
crypt
->
IsVerify
();
else
return
false
;
...
...
ASCOfficeXlsFile2/source/XlsFormat/Crypt/Decryptor.h
View file @
9f98f07f
...
...
@@ -40,15 +40,16 @@ namespace CRYPT
class
RC4Decryptor
:
public
Decryptor
{
public:
RC4Decryptor
(
_rc4CryptData
&
header
,
std
::
wstring
password
,
int
type
);
RC4Decryptor
(
_rc4CryptData
&
header
,
std
::
wstring
password
);
virtual
void
Decrypt
(
char
*
data
,
const
size_t
size
,
const
unsigned
long
stream_pos
,
const
size_t
block_size
);
virtual
void
Decrypt
(
char
*
data
,
const
size_t
size
,
const
unsigned
long
block_index
);
virtual
void
Decrypt
(
char
*
data
,
const
size_t
size
,
const
unsigned
long
stream_pos
);
virtual
bool
SetPassword
(
std
::
wstring
password
);
virtual
bool
IsVerify
();
private:
int
type
;
CryptPtr
crypt
;
_rc4CryptData
crypt_data
;
};
...
...
ASCOfficeXlsFile2/source/XlsFormat/Crypt/RC4Crypt.cpp
View file @
9f98f07f
...
...
@@ -38,7 +38,7 @@
namespace
CRYPT
{
RC4Crypt
::
RC4Crypt
(
CRYPT
::
_rc4CryptData
&
data
,
std
::
wstring
password
,
int
type
)
RC4Crypt
::
RC4Crypt
(
CRYPT
::
_rc4CryptData
&
data
,
std
::
wstring
password
)
{
m_VerifyPassword
=
false
;
...
...
@@ -46,18 +46,11 @@ RC4Crypt::RC4Crypt(CRYPT::_rc4CryptData & data, std::wstring password, int type)
CopyDWORDs2Bytes
(
data
.
EncryptedVerifier
.
b1
,
data
.
EncryptedVerifier
.
b2
,
data
.
EncryptedVerifier
.
b3
,
data
.
EncryptedVerifier
.
b4
,
pnVerifier
);
CopyDWORDs2Bytes
(
data
.
EncryptedVerifierHash
.
b1
,
data
.
EncryptedVerifierHash
.
b2
,
data
.
EncryptedVerifierHash
.
b3
,
data
.
EncryptedVerifierHash
.
b4
,
pnVerifierHash
);
int
BlockSize
=
1024
;
if
(
type
==
1
)
BlockSize
=
512
;
mxDecoder
.
reset
(
new
BiffDecoder_RCF
(
pnSalt
,
pnVerifier
,
pnVerifierHash
,
BlockSize
));
mxDecoder
.
reset
(
new
BiffDecoder_RCF
(
pnSalt
,
pnVerifier
,
pnVerifierHash
));
m_VerifyPassword
=
mxDecoder
->
verifyPassword
(
password
);
}
void
RC4Crypt
::
Encrypt
(
char
*
data
,
const
size_t
size
)
{
}
bool
RC4Crypt
::
IsVerify
()
{
...
...
@@ -87,18 +80,33 @@ void RC4Crypt::CopyDWORDs2Bytes(const unsigned int b1, const unsigned int b2, co
byte_array
[
15
]
=
static_cast
<
unsigned
char
>
((
b4
&
0xff000000
)
>>
24
);
}
void
RC4Crypt
::
Decrypt
(
char
*
data
,
const
size_t
size
,
const
unsigned
long
stream_pos
)
void
RC4Crypt
::
Decrypt
(
char
*
data
,
const
size_t
size
,
const
unsigned
long
block_index
)
{
if
(
size
<=
256
)
{
static
unsigned
char
quick_buf
[
256
];
mxDecoder
->
decode
(
quick_buf
,
reinterpret_cast
<
unsigned
char
*>
(
data
),
size
,
block_index
);
memcpy
(
data
,
quick_buf
,
size
);
}
else
{
boost
::
scoped_array
<
unsigned
char
>
out_data
(
new
unsigned
char
[
size
]);
mxDecoder
->
decode
(
out_data
.
get
(),
reinterpret_cast
<
unsigned
char
*>
(
data
),
size
,
block_index
);
memcpy
(
data
,
out_data
.
get
(),
size
);
}
}
void
RC4Crypt
::
Decrypt
(
char
*
data
,
const
size_t
size
,
const
unsigned
long
stream_pos
,
const
size_t
block_size
)
{
if
(
size
<=
256
)
{
mxDecoder
->
decode
(
quick_buf
,
reinterpret_cast
<
unsigned
char
*>
(
data
),
stream_pos
,
size
);
static
unsigned
char
quick_buf
[
256
];
mxDecoder
->
decode
(
quick_buf
,
reinterpret_cast
<
unsigned
char
*>
(
data
),
size
,
stream_pos
,
block_size
);
memcpy
(
data
,
quick_buf
,
size
);
}
else
{
boost
::
scoped_array
<
unsigned
char
>
out_data
(
new
unsigned
char
[
size
]);
mxDecoder
->
decode
(
out_data
.
get
(),
reinterpret_cast
<
unsigned
char
*>
(
data
),
s
tream_pos
,
size
);
mxDecoder
->
decode
(
out_data
.
get
(),
reinterpret_cast
<
unsigned
char
*>
(
data
),
s
ize
,
stream_pos
,
block_
size
);
memcpy
(
data
,
out_data
.
get
(),
size
);
}
}
...
...
ASCOfficeXlsFile2/source/XlsFormat/Crypt/RC4Crypt.h
View file @
9f98f07f
...
...
@@ -41,10 +41,10 @@ namespace CRYPT
class
RC4Crypt
:
public
Crypt
{
public:
RC4Crypt
(
CRYPT
::
_rc4CryptData
&
data
,
std
::
wstring
password
,
int
type
);
RC4Crypt
(
CRYPT
::
_rc4CryptData
&
data
,
std
::
wstring
password
);
virtual
void
Encrypt
(
char
*
data
,
const
size_t
size
);
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
stream_pos
,
const
size_t
block_
size
);
virtual
void
Decrypt
(
char
*
data
,
const
size_t
size
,
const
unsigned
long
block_index
);
virtual
bool
IsVerify
();
...
...
ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_records/FilePass.cpp
View file @
9f98f07f
...
...
@@ -79,7 +79,7 @@ void FilePass::readFields(CFRecord& record)
if
(
cryptHeaderPtr
->
bStandard
)
{
record
.
getGlobalWorkbookInfo
()
->
decryptor
=
CRYPT
::
DecryptorPtr
(
new
CRYPT
::
RC4Decryptor
(
cryptHeaderPtr
->
crypt_data_rc4
,
record
.
getGlobalWorkbookInfo
()
->
password
,
2
));
CRYPT
::
DecryptorPtr
(
new
CRYPT
::
RC4Decryptor
(
cryptHeaderPtr
->
crypt_data_rc4
,
record
.
getGlobalWorkbookInfo
()
->
password
));
}
else
{
...
...
ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_records/StyleExt.cpp
View file @
9f98f07f
...
...
@@ -61,6 +61,7 @@ void StyleExt::readFields(CFRecord& record)
fHidden
=
GETBIT
(
flags
,
1
);
fCustom
=
GETBIT
(
flags
,
2
);
stName
.
setSize
(
0xff
);
//max size
record
>>
iCategory
>>
builtInData
>>
stName
>>
xfProps
;
}
...
...
ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_structures/RC4EncryptionHeader.cpp
View file @
9f98f07f
...
...
@@ -125,14 +125,21 @@ void RC4EncryptionHeader::load(XLS::CFRecord& record)
pos
=
record
.
getRdPtr
();
//------------------------------------------------------------------------------------------
crypt_data_aes
.
hashAlgorithm
=
CRYPT_METHOD
::
SHA1
;
//by AlgIDHash -> 0x0000(reserved ??) || 0x8004(sha1)
crypt_data_aes
.
spinCount
=
50000
;
switch
(
AlgIDHash
)
{
case
0x8003
:
crypt_data_aes
.
hashAlgorithm
=
CRYPT_METHOD
::
MD5
;
break
;
case
0x0000
:
case
0x8004
:
crypt_data_aes
.
hashAlgorithm
=
CRYPT_METHOD
::
SHA1
;
break
;
}
crypt_data_aes
.
spinCount
=
0
;
switch
(
AlgID
)
{
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
;
...
...
@@ -147,12 +154,6 @@ void RC4EncryptionHeader::load(XLS::CFRecord& record)
crypt_data_aes
.
keySize
=
256
/
8
;
break
;
}
switch
(
ProviderType
)
{
case
0x0001
:
crypt_data_aes
.
cipherAlgorithm
=
CRYPT_METHOD
::
RC4
;
break
;
case
0x0018
:
crypt_data_aes
.
cipherAlgorithm
=
CRYPT_METHOD
::
AES_ECB
;
break
;
}
}
}
...
...
ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_structures/RC4EncryptionHeader.h
View file @
9f98f07f
...
...
@@ -33,7 +33,7 @@
#include "BiffStructure.h"
#include <Logic/Biff_structures/BitMarkedStructs.h>
#include "../../Crypt/Crypt.h"
#include "../../Crypt/
RC4
Crypt.h"
namespace
CRYPTO
{
...
...
ASCOfficeXlsFile2/source/XlsFormat/Logic/Biff_structures/XFProp.cpp
View file @
9f98f07f
...
...
@@ -134,7 +134,10 @@ void XFProp::load(CFRecord& record)
// EXCEPT::RT::WrongBiffRecord("Unsupported type of XFProp.", record.getTypeString());
break
;
}
if
(
xfPropDataBlob
)
{
record
>>
*
xfPropDataBlob
;
}
}
static
void
serialize_color_prop
(
std
::
wostream
&
stream
,
const
std
::
wstring
&
name
,
BiffStructurePtr
&
val
)
{
...
...
ASCOfficeXlsFile2/source/XlsXlsxConverter/XlsConverter.cpp
View file @
9f98f07f
...
...
@@ -530,6 +530,10 @@ void XlsConverter::convert(XLS::FORMATTING* formating)
CP_XML_NODE
(
L"styleSheet"
)
{
CP_XML_ATTR
(
L"xmlns"
,
L"http://schemas.openxmlformats.org/spreadsheetml/2006/main"
);
CP_XML_ATTR
(
L"xmlns:mc"
,
L"http://schemas.openxmlformats.org/markup-compatibility/2006"
);
CP_XML_ATTR
(
L"mc:Ignorable"
,
L"x14ac x16r2"
);
CP_XML_ATTR
(
L"xmlns:x14ac"
,
L"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"
);
CP_XML_ATTR
(
L"xmlns:x16r2"
,
L"http://schemas.microsoft.com/office/spreadsheetml/2015/02/main"
);
formating
->
serialize1
(
CP_XML_STREAM
());
//важен порядок в styles
...
...
ASCOfficeXlsFile2/source/win32/XlsFormat.vcproj
View file @
9f98f07f
...
...
@@ -6202,10 +6202,6 @@
RelativePath=
"..\XlsFormat\Crypt\BinaryCodec_RCF.h"
>
</File>
<File
RelativePath=
"..\XlsFormat\Crypt\Crypt.h"
>
</File>
<File
RelativePath=
"..\XlsFormat\Crypt\Decryptor.cpp"
>
...
...
OfficeCryptReader/source/CryptTransform.cpp
View file @
9f98f07f
...
...
@@ -513,8 +513,8 @@ void ECMADecryptor::SetCryptData(_ecmaCryptData & data)
}
void
ECMADecryptor
::
Decrypt
(
char
*
data
,
const
size_t
size
,
const
unsigned
long
start_iv_block
)
{
if
(
bVerify
)
{
if
(
!
bVerify
)
return
;
unsigned
char
*
data_out
=
NULL
;
Decrypt
((
unsigned
char
*
)
data
,
size
,
data_out
,
start_iv_block
);
...
...
@@ -523,6 +523,65 @@ void ECMADecryptor::Decrypt(char* data , const size_t size, const unsigned long
memcpy
(
data
,
data_out
,
size
);
delete
[]
data_out
;
}
}
void
ECMADecryptor
::
Decrypt
(
char
*
data
,
const
size_t
size
,
const
unsigned
long
stream_pos
,
const
size_t
block_size
)
{
if
(
!
bVerify
)
return
;
//rc4 only
if
(
cryptData
.
cipherAlgorithm
!=
CRYPT_METHOD
::
RC4
)
return
;
unsigned
char
*
data_out
=
new
unsigned
char
[
size
];
unsigned
char
*
pnCurrDest
=
data_out
;
const
unsigned
char
*
pnCurrSrc
=
(
unsigned
char
*
)
data
;
long
nCurrPos
=
stream_pos
;
unsigned
short
nBytesLeft
=
size
;
while
(
nBytesLeft
>
0
)
{
// initialize codec for current stream position
int
block_index
=
(
nCurrPos
/
block_size
);
{
_buf
pPassword
(
password
);
_buf
pSalt
(
cryptData
.
saltValue
);
_buf
hashKey
=
GenerateHashKey
(
pSalt
,
pPassword
,
cryptData
.
hashSize
,
cryptData
.
spinCount
,
cryptData
.
hashAlgorithm
,
block_index
);
CorrectHashSize
(
hashKey
,
cryptData
.
keySize
,
0
);
if
(
cryptData
.
keySize
==
5
)
CorrectHashSize
(
hashKey
,
16
,
0
);
//40-bit crypt key !!!
rc4Decryption
.
SetKey
(
hashKey
.
ptr
,
hashKey
.
size
);
}
const
long
offset
=
nCurrPos
%
block_size
;
{
//skip
unsigned
char
pnDummy
[
1024
];
size_t
nBytesLeft
=
offset
;
bool
bResult
=
true
;
while
(
bResult
&&
(
nBytesLeft
>
0
))
{
size_t
nBlockLen
=
nBytesLeft
<
sizeof
(
pnDummy
)
?
nBytesLeft
:
sizeof
(
pnDummy
);
rc4Decryption
.
ProcessData
(
pnDummy
,
pnDummy
,
nBlockLen
);
nBytesLeft
-=
nBlockLen
;
}
}
unsigned
short
nBlockLeft
=
static_cast
<
unsigned
short
>
(
block_size
-
offset
);
unsigned
short
nDecBytes
=
nBytesLeft
<
nBlockLeft
?
nBytesLeft
:
nBlockLeft
;
rc4Decryption
.
ProcessData
(
pnCurrDest
,
pnCurrSrc
,
static_cast
<
int
>
(
nDecBytes
));
pnCurrDest
+=
nDecBytes
;
pnCurrSrc
+=
nDecBytes
;
nCurrPos
+=
nDecBytes
;
nBytesLeft
=
nBytesLeft
-
nDecBytes
;
}
if
(
data_out
)
{
memcpy
(
data
,
data_out
,
size
);
delete
[]
data_out
;
}
}
bool
ECMADecryptor
::
CheckDataIntegrity
(
unsigned
char
*
data
,
int
size
)
...
...
@@ -564,7 +623,8 @@ bool ECMADecryptor::CheckDataIntegrity(unsigned char* data, int size)
return
(
hmac
==
expected
);
}
void
ECMADecryptor
::
Decrypt
(
unsigned
char
*
data_inp
,
int
size
,
unsigned
char
*&
data_out
,
int
start_iv_block
)
void
ECMADecryptor
::
Decrypt
(
unsigned
char
*
data_inp
,
int
size
,
unsigned
char
*&
data_out
,
unsigned
long
start_iv_block
)
{
data_out
=
new
unsigned
char
[
size
];
...
...
OfficeCryptReader/source/CryptTransform.h
View file @
9f98f07f
...
...
@@ -62,7 +62,8 @@ namespace CRYPT
class
Decryptor
{
public:
virtual
void
Decrypt
(
char
*
data
,
const
size_t
size
,
const
unsigned
long
stream_pos
)
=
0
;
virtual
void
Decrypt
(
char
*
data
,
const
size_t
size
,
const
unsigned
long
stream_pos
,
const
size_t
block_size
)
=
0
;
virtual
void
Decrypt
(
char
*
data
,
const
size_t
size
,
const
unsigned
long
block_index
)
=
0
;
virtual
bool
SetPassword
(
std
::
wstring
password
)
=
0
;
virtual
bool
IsVerify
()
=
0
;
...
...
@@ -128,9 +129,10 @@ public:
ECMADecryptor
();
virtual
~
ECMADecryptor
();
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
,
const
size_t
block_size
);
virtual
void
Decrypt
(
char
*
data
,
const
size_t
size
,
const
unsigned
long
start_iv_block
);
virtual
bool
SetPassword
(
std
::
wstring
password
);
virtual
bool
IsVerify
();
...
...
@@ -138,6 +140,8 @@ public:
void
SetCryptData
(
_ecmaCryptData
&
data
);
void
Decrypt
(
unsigned
char
*
data
,
int
size
,
unsigned
char
*&
data_out
,
unsigned
long
start_iv_block
);
private:
std
::
wstring
password
;
...
...
OfficeCryptReader/source/ECMACryptFile.cpp
View file @
9f98f07f
...
...
@@ -565,26 +565,26 @@ bool ECMACryptFile::EncryptOfficeFile(std::wstring file_name_inp, std::wstring f
pStorage
->
close
();
delete
pStorage
;
//test back---------------------------------------------------------------------------------test back
ECMADecryptor
decryptor
;
decryptor
.
SetCryptData
(
cryptData
);
if
(
decryptor
.
SetPassword
(
password
))
{
unsigned
char
*
data_out2
=
NULL
;
decryptor
.
Decrypt
(
data_out
,
lengthData
,
data_out2
);
bool
bDataIntegrity
=
decryptor
.
CheckDataIntegrity
(
data_out
,
lengthData
);
NSFile
::
CFileBinary
test
;
test
.
CreateFileW
(
file_name_out
+
L"-back.oox"
);
test
.
WriteFile
(
data_out2
,
lengthFileSize
);
test
.
CloseFile
();
}
//test back---------------------------------------------------------------------------------test back
//
//
//
test back---------------------------------------------------------------------------------test back
//
ECMADecryptor decryptor;
//
//
decryptor.SetCryptData(cryptData);
//
//
if (decryptor.SetPassword(password))
//
{
//
unsigned char* data_out2 = NULL;
// decryptor.Decrypt(data_out, lengthData, data_out2, 0
);
//
//
bool bDataIntegrity = decryptor.CheckDataIntegrity(data_out, lengthData);
//
//
NSFile::CFileBinary test;
//
//
test.CreateFileW(file_name_out + L"-back.oox");
//
test.WriteFile(data_out2, lengthFileSize);
//
test.CloseFile();
//
}
//
//
test back---------------------------------------------------------------------------------test back
return
true
;
}
...
...
@@ -717,7 +717,7 @@ bool ECMACryptFile::DecryptOfficeFile(std::wstring file_name_inp, std::wstring f
lengthData
=
*
((
_UINT64
*
)
data
);
decryptor
.
Decrypt
(
data
+
8
,
readData
,
data_out
);
//todoo сделать покусочное чтение декриптование
decryptor
.
Decrypt
(
data
+
8
,
readData
,
data_out
,
0
);
//todoo сделать покусочное чтение декриптование
if
(
data_out
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment