summaryrefslogtreecommitdiff
path: root/src/lib/SDWHeader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/SDWHeader.cpp')
-rw-r--r--src/lib/SDWHeader.cpp88
1 files changed, 64 insertions, 24 deletions
diff --git a/src/lib/SDWHeader.cpp b/src/lib/SDWHeader.cpp
index 7f5509c..be1409b 100644
--- a/src/lib/SDWHeader.cpp
+++ b/src/lib/SDWHeader.cpp
@@ -1,50 +1,90 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
-/* libwpd
- * Version: MPL 2.0 / LGPLv2.1+
+/* Version: MPL 2.0 / LGPLv2.1+
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
- * Major Contributor(s):
- * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
- * Copyright (C) 2002-2004 Marc Maurer (uwog@uwog.net)
- *
- * For minor contributions see the git repository.
- *
* Alternatively, the contents of this file may be used under the terms
* of the GNU Lesser General Public License Version 2.1 or later
* (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
* applicable instead of those above.
- *
- * For further information visit http://libwpd.sourceforge.net
- */
-
-/* "This product is not manufactured, approved, or supported by
- * Corel Corporation or Corel Corporation Limited."
*/
#include "SDWHeader.h"
+#include "SDWEncryption.h"
+#include "SDWFileStructure.h"
#include <string.h>
-libsdw::SDWHeader::SDWHeader(WPXInputStream * /* input */, SDWEncryption * /* encryption */, uint32_t documentOffset, uint8_t productType,
- uint8_t fileType, uint8_t majorVersion, uint8_t minorVersion, uint16_t documentEncryption) :
- m_documentOffset(documentOffset),
- m_productType(productType),
- m_fileType(fileType),
- m_majorVersion(majorVersion),
- m_minorVersion(minorVersion),
- m_documentEncryption(documentEncryption)
+libsdw::SDWHeader::SDWHeader(WPXInputStream *input, const char *password) :
+ m_needsPassword(false),
+ m_validHeader(false),
+ m_encryption(0)
{
+ m_validHeader = loadHeader(input, password);
}
libsdw::SDWHeader::~SDWHeader()
{
}
-libsdw::SDWHeader *libsdw::SDWHeader::constructHeader(WPXInputStream * /* input */, SDWEncryption * /* encryption */)
+bool libsdw::SDWHeader::loadHeader(WPXInputStream *input, const char *password)
{
- return 0;
+ WPXString signature = readString(input);
+ SDW_DEBUG_MSG(("SDWHeader signature %s\n", signature.cstr()));
+ if (signature != "SW3HDR" && signature != "SW4HDR" && signature != "SW5HDR")
+ return false;
+
+ uint8_t cLen = readU8(input);
+ long oldOffset = input->tell();
+
+ uint16_t version = readU16(input);
+ uint16_t fileFlags = readU16(input);
+ if (fileFlags & SWGF_BAD_FILE) // Error on write
+ return false;
+ if (fileFlags & SWGF_HAS_PASSWD)
+ m_needsPassword = true;
+ input->seek(4, WPX_SEEK_CUR); // int32_t docFlags = readS32(input);
+ input->seek(4, WPX_SEEK_CUR); // uint32_t recSzPos = readU32(input);
+ input->seek(6, WPX_SEEK_CUR);
+ input->seek(1, WPX_SEEK_CUR); // uint8_t redlineMode = readU8(input);
+ uint8_t compatVer = readU8(input);
+ if (version >= SWG_MAJORVERSION_50 && compatVer > 0)
+ return false;
+
+ unsigned long numBytesRead(0L);
+ const uint8_t *passwd = input->read(16L, numBytesRead);
+ if (!passwd || numBytesRead != 16L)
+ return false;
+
+ input->seek(1, WPX_SEEK_CUR); // uint8_t charSet = readU8(input);
+ input->seek(1, WPX_SEEK_CUR); // uint8_t gui = readU8(input);
+
+ uint32_t date = readU32(input);
+ uint32_t time = readU32(input);
+
+ WPXString blockName;
+ if (fileFlags & SWGF_BLOCKNAME)
+ {
+ const uint8_t *buffer = input->read(64L, numBytesRead);
+ if (numBytesRead != 64L && buffer[63] != 0)
+ return false;
+ blockName.append((const char*)buffer);
+ SDW_DEBUG_MSG(("SDWHeader blockName \"%s\"\n", blockName.cstr()));
+ }
+
+ SDW_DEBUG_MSG(("SDWHeader finished construction\n"));
+ input->seek(oldOffset + cLen, WPX_SEEK_SET);
+
+ if (m_needsPassword && password)
+ m_encryption = new SDWEncryption(password);
+ if (m_encryption && !m_encryption->verifyPassword(passwd, date, time))
+ {
+ delete m_encryption;
+ m_encryption = 0;
+ return false;
+ }
+ return true;
}
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */