diff --git a/ASCOfficeDocFile/DocDocxConverter/WordDocument.cpp b/ASCOfficeDocFile/DocDocxConverter/WordDocument.cpp index cbd571da11..318159f1cd 100644 --- a/ASCOfficeDocFile/DocDocxConverter/WordDocument.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/WordDocument.cpp @@ -483,26 +483,27 @@ namespace DocFileFormat delete storageOut; return false; } + DecryptStream( 0, "/", storageIn, storageOut, Decryptor); - std::list listStream = storageIn->entries(); + //std::list listStream = storageIn->entries(); - for (std::list::iterator it = listStream.begin(); it != listStream.end(); it++) - { - if (storageIn->isDirectory(*it)) - { - std::list list_entry = storageIn->GetAllStreams(*it); - - for (std::list::iterator it2 = list_entry.begin(); it2 != list_entry.end(); it2++) - { - DecryptStream(Decryptor, *it2, storageIn, storageOut); - } - } - else - { - DecryptStream(Decryptor, *it, storageIn, storageOut); - } + //for (std::list::iterator it = listStream.begin(); it != listStream.end(); it++) + //{ + // if (storageIn->isDirectory(*it)) + // { + // std::list list_entry = storageIn->GetAllStreams(*it); + // + // for (std::list::iterator it2 = list_entry.begin(); it2 != list_entry.end(); it2++) + // { + // DecryptStream(Decryptor, *it2, storageIn, storageOut); + // } + // } + // else + // { + // DecryptStream(Decryptor, *it, storageIn, storageOut); + // } - } + //} storageOut->close(); delete storageOut; @@ -525,34 +526,28 @@ namespace DocFileFormat } return true; } - bool WordDocument::CopyStream (std::string streamName, POLE::Storage * storageIn, POLE::Storage * storageOut) + void WordDocument::DecryptStream( int level, std::string path, POLE::Storage * storageIn, POLE::Storage * storageOut, CRYPT::Decryptor* Decryptor) { - POLE::Stream *stream = new POLE::Stream(storageIn, streamName); - if (!stream) return false; - - stream->seek(0); - int sz_stream = stream->size(); - - POLE::Stream *streamNew = new POLE::Stream(storageOut, streamName, true, sz_stream); - if (!streamNew) return false; - - unsigned char* data_stream = new unsigned char[sz_stream]; - stream->read(data_stream, sz_stream); - - streamNew->write(data_stream, sz_stream); - - RELEASEARRAYOBJECTS(data_stream); - - streamNew->flush(); - - delete streamNew; - delete stream; - - return true; + std::list entries; + entries = storageIn->entries( path ); + + std::list::iterator it; + for( it = entries.begin(); it != entries.end(); ++it ) + { + std::string name = *it; + std::string fullname = path + name; + + if( storageIn->isDirectory( fullname ) ) + { + DecryptStream( level + 1, fullname + "/", storageIn, storageOut, Decryptor ); + } + else + { + DecryptStream(fullname, storageIn, storageOut, Decryptor ); + } + } } - - - bool WordDocument::DecryptStream(CRYPT::Decryptor* Decryptor, std::string streamName, POLE::Storage * storageIn, POLE::Storage * storageOut) + bool WordDocument::DecryptStream(std::string streamName, POLE::Storage * storageIn, POLE::Storage * storageOut, CRYPT::Decryptor* Decryptor) { POLE::Stream *stream = new POLE::Stream(storageIn, streamName); if (!stream) return false; @@ -567,9 +562,9 @@ namespace DocFileFormat stream->read(data_stream, size_stream); unsigned char* data_store = NULL; - int size_data_store = 0; + int size_data_store = 0; - if ("WordDocument" == streamName) + if ( std::wstring::npos != streamName.find("WordDocument") ) { size_data_store = 68; data_store = new unsigned char[size_data_store]; diff --git a/ASCOfficeDocFile/DocDocxConverter/WordDocument.h b/ASCOfficeDocFile/DocDocxConverter/WordDocument.h index eb667c706f..29fe860014 100644 --- a/ASCOfficeDocFile/DocDocxConverter/WordDocument.h +++ b/ASCOfficeDocFile/DocDocxConverter/WordDocument.h @@ -102,9 +102,10 @@ namespace DocFileFormat private: bool DecryptOfficeFile (CRYPT::Decryptor* Decryptor); - bool DecryptStream (CRYPT::Decryptor* Decryptor, std::string streamName, POLE::Storage * storageIn, POLE::Storage * storageOut); - bool CopyStream (std::string streamName, POLE::Storage * storageIn, POLE::Storage * storageOut); - + + bool DecryptStream (std::string streamName, POLE::Storage * storageIn, POLE::Storage * storageOut, CRYPT::Decryptor* Decryptor); + void DecryptStream (int level, std::string streamName, POLE::Storage * storageIn, POLE::Storage * storageOut, CRYPT::Decryptor* Decryptor); + inline StructuredStorageReader* GetStorage() const { return m_pStorage;