Пример #1
0
		private bool HasDocumentProtection(FIB fib, DOPHeader dopHeader)
		{
			StructuredStorageInterface.IStorage iStorageDOP;
			IStream iStreamDOP;

			// read the fWhichTblStm bit
			if ((fib.bitData & 0x0200) == 0x0200)
			{
				iStreamDOP = GetStream(out iStorageDOP, "1Table");
			}
			else
			{
				iStreamDOP = GetStream(out iStorageDOP, "0Table");
			}

			if (iStreamDOP != null)
			{
				using (new ComObjectGovernor(iStreamDOP))
				using (new ComObjectGovernor(iStorageDOP))
				{
					StreamWrapper streamDOP = new StreamWrapper(iStreamDOP);

					short bFlags = streamDOP.GetDOPFlag(dopHeader, 0x0006);
					bool bLockAtn = (bFlags & 0x0010) == 0x0010;		// annotations locked for editing
					bool bProtEnabled = (bFlags & 0x0200) == 0x0200;	// document protected for edit operations
					bool bLockRev = (bFlags & 0x4000) == 0x4000;		// revision marking state locked
					if (bLockAtn || bLockRev || bProtEnabled)
					{
						return true;
					}

					if (fib.version >= 217)		// Word 2000 or later
					{
						short bDocumentProtection = streamDOP.GetDOPFlag(dopHeader, 0x0254);
						bool bEnforceProtection = (bDocumentProtection & 0x0008) == 0x0008;
						return bEnforceProtection;
					}
				}
			}

			return false;
		}
Пример #2
0
        private bool InitialiserMethodForWordFileOnDisk()
        {
            StructuredStorageInterface.IStorage iStorage;
            IStream iStream = GetStream(out iStorage, "WordDocument");

            if (null == iStream)
                return false;

            StreamWrapper stream;
            FIB fib;
            DOPHeader dopHeader;
            using (new ComObjectGovernor(iStream))
            using (new ComObjectGovernor(iStorage))
            {
                stream = new StreamWrapper(iStream);
                fib = new FIB();

                dopHeader = new DOPHeader();
                stream.GetDOP(ref dopHeader);

                object fibObject = fib as object;
                stream.GetHeaderStructure(ref fibObject);
                fib = (FIB)fibObject;
            }
            //        \   / 
            //        .\-/. 
            //    /\  () ()  /\ 
            //   /  \ /~-~\ /  \ 
            //       y  Y  V 
            // ,-^-./   |   \,-^-.  
            ///    {    |    }    \ 
            //      \   |   / 
            //      /\  A  /\ 
            //     /  \/ \/  \ 
            //    /           \ 
            //
            // int numLols = 1 // increment every time you see this for the first time

            if (fib.magicNumber != 0)  //THIS ZERO-CHECK IS A HACK FOR PROTECT MOBILE - IT SHOULD BE REMOVED ASAP
            {

                //THIS is the proper code to check for Word file versioning.  This should stay.
                if (fib.magicNumber != 0xA5DC && fib.magicNumber != 0xA5EC)
                    return false;

            }

            //we will get this far with a docx/docm if it is encrypted but the FIB is empty then so we can drop out now
            if (fib.bitData == 0 && fib.lid == 0 && fib.magicNumber == 0 && fib.version == 0 && fib.nProduct == 0)
            {
                return false;
            }

            m_fileData.FileType = FileType.WordDocument;

            if ((fib.bitData & StreamWrapper.fEncrypted) == StreamWrapper.fEncrypted)
                m_fileData.ReadPasswordProtected = true;

            if ((fib.bitData & StreamWrapper.fWriteReservation) == StreamWrapper.fWriteReservation)
                m_fileData.WritePasswordProtected = true;

            // only try to find the document protection flags within the DOP if we know that the
            // file is not encrypted.  Otherwise the offsets are not valid.
            if (!m_fileData.ReadPasswordProtected && !m_fileData.WritePasswordProtected)
            {
                //DOPHeader dopHeader = new DOPHeader();
                //stream.GetDOP(ref dopHeader);
                m_fileData.DocumentProtected = HasDocumentProtection(fib, dopHeader);
            }

            m_impl = new FileImpl(m_fileData);

            return true;
            //}
        }
Пример #3
0
		private bool InitialiseMethodForEncryptedDocXFileOnDisk()
		{
			StructuredStorageInterface.IStorage iStorage;
			IStream iStream = GetStream(out iStorage, "WordDocument");

            bool bIstream = false;
            using (new ComObjectGovernor(iStream))
            using (new ComObjectGovernor(iStorage))
            {
                bIstream = iStream == null ? false : true;
            }

			if (!bIstream && (iStorage == null))
				return false;

			// Office2007 SP2 does not have "WordDocument" stream
			if (!bIstream && (iStorage != null))
			{
                bool bIstream1 = false;
				IStream iStream1 = GetStream(out iStorage, "EncryptionInfo");
                using (new ComObjectGovernor(iStream1))
                using (new ComObjectGovernor(iStorage))
                {
                    bIstream1 = iStream1 == null ? false : true;
                }

                bool bIstream2 = false;
                IStream iStream2 = GetStream(out iStorage, "EncryptedPackage");
                using (new ComObjectGovernor(iStream2))
                using (new ComObjectGovernor(iStorage))
                {
                    bIstream2 = iStream2 == null ? false : true;
                }

				string filename = m_fileData.Filename.ToLower();
				if ((bIstream1 && bIstream2) &&
					   (filename.EndsWith("docx", StringComparison.InvariantCultureIgnoreCase) 
                    ||  filename.EndsWith("docm", StringComparison.InvariantCultureIgnoreCase)
                    ||  filename.EndsWith("doc", StringComparison.InvariantCultureIgnoreCase)))
				{
					m_fileData.FileType = FileType.WordDocumentX;
					m_fileData.ReadPasswordProtected = true;
					m_fileData.WritePasswordProtected = true;

					m_impl = new FileImpl(m_fileData);

					return true;
				}
				else
					return false;
			}

            iStream = GetStream(out iStorage, "WordDocument");
			FIB fib = new FIB();
			using (new ComObjectGovernor(iStream))
			using (new ComObjectGovernor(iStorage))
			{
				StreamWrapper stream = new StreamWrapper(iStream);
				object fibObject = fib as object;
				stream.GetHeaderStructure(ref fibObject);
				fib = (FIB) fibObject;
            }

			if (fib.bitData == 0 && fib.lid == 0 && fib.magicNumber == 0 && fib.version == 0 && fib.nProduct == 0)
			{
                bool bIstream1 = false;
                IStream iStream1 = GetStream(out iStorage, "EncryptionInfo");
                using (new ComObjectGovernor(iStream1))
                using (new ComObjectGovernor(iStorage))
                {
                    bIstream1 = iStream1 == null ? false : true;
                }

                bool bIstream2 = false;
                IStream iStream2 = GetStream(out iStorage, "EncryptedPackage");
                using (new ComObjectGovernor(iStream2))
                using (new ComObjectGovernor(iStorage))
                {
                    bIstream2 = iStream2 == null ? false : true;
                }

				if (bIstream1 && bIstream2)
				{
					m_fileData.FileType = FileType.WordDocumentX;
					m_fileData.ReadPasswordProtected = true;
					m_fileData.WritePasswordProtected = true;

					m_impl = new FileImpl(m_fileData);

					return true;
				}
			}
			return false;
		}