/// <summary>
 ///     Creates this object and reads all the properties from the toplevel stream
 /// </summary>
 /// <param name="stream">The <see cref="CFStream"/></param>
 internal TopLevelPropertiesStream(ICFStream stream)
 {
     using (var memoryStream = new MemoryStream(stream.GetData()))
     using (var binaryReader = new BinaryReader(memoryStream))
     {
         //binaryReader.ReadBytes(8);
         NextRecipientId = Convert.ToInt32(binaryReader.ReadUInt32());
         NextAttachmentId = Convert.ToInt32(binaryReader.ReadUInt32());
         RecipientCount = Convert.ToInt32(binaryReader.ReadUInt32());
         AttachmentCount = Convert.ToInt32(binaryReader.ReadUInt32());
         ReadProperties(binaryReader);
     }
 }
示例#2
0
        /// <summary>
        ///     Creates this object and sets all its properties
        /// </summary>
        /// <param name="stream">The Compound File Storage CompObj <see cref="CFStream" /></param>
        internal ObjInfoStream(ICFStream stream)
        {
            using (var memoryStream = new MemoryStream(stream.GetData()))
            using (var binaryReader = new BinaryReader(memoryStream))
            {
                var bytes = binaryReader.ReadBytes(2);
                var bitArray = new BitArray(bytes);

                // A - reserved1 (1 bit): Undefined and MUST be ignored.

                // B - fDefHandler (1 bit): If this bit is 1, then the application MUST assume that this OLE object’s 
                //     class identifier (CLSID) is {00020907-0000-0000-C000-000000000046}.
                DefHandler = bitArray.Get(1);

                // C - reserved2 (1 bit): Undefined and MUST be ignored.
                // D - reserved3 (1 bit): Undefined and MUST be ignored.

                // E - fLink (1 bit): A bit that specifies whether this OLE object is a link.
                Link = bitArray.Get(4);

                // F - reserved4 (1 bit): Undefined and MUST be ignored.
                // G - fIcon (1 bit): A bit that specifies whether this OLE object is being represented by an icon.
                Icon = bitArray.Get(6);

                // H - fIsOle1 (1 bit): A bit that specifies whether this OLE object is only compatible with OLE 1. 
                //     If this bit is zero, then the object is compatible with OLE 2.
                IsOle1 = bitArray.Get(7);

                // I - fManual (1 bit): A bit that specifies whether the user has requested that this OLE object only 
                //     be updated in response to a user action. If fManual is zero, then the user has requested that 
                //     this OLE object update automatically. If fLink is zero, then fManual is undefined and MUST be ignored.
                Manual = bitArray.Get(8);

                // J - fRecomposeOnResize (1 bit): A bit that specifies whether this OLE object has requested to be notified 
                //     when it is resized by its container.
                RecomposeOnResize = bitArray.Get(9);

                // K - reserved5 (1 bit): MUST be zero and MUST be ignored.
                // L - reserved6 (1 bit): MUST be zero and MUST be ignored.
                // M - fOCX (1 bit): A bit that specifies whether this object is an OLE control.
                Ocx = bitArray.Get(12);

                // N - fStream (1 bit): If fOCX is zero, then this bit MUST be zero. If fOCX is 1, then fStream is a bit that 
                //     specifies whether this OLE control stores its data in a single stream instead of a storage. If fStream 
                //     is 1, then the data for the OLE control is in a stream called "\003OCXDATA" where \003 is the character 
                //     with value 0x0003, not the string literal "\003".
                Stream = bitArray.Get(13);

                // O - reserved7 (1 bit): Undefined and MUST be ignored.
                // P - fViewObject (1 bit): A bit that specifies whether this OLE object supports the IViewObject interface.
                ViewObject = bitArray.Get(15);

                try
                {
                    Cf = (OleCf) binaryReader.ReadUInt16();
                }
                catch (Exception)
                {
                    Cf = OleCf.UnSpecified;
                }
            }
        }
示例#3
0
        /// <summary>
        ///     Creates this object and sets all its properties
        /// </summary>
        /// <param name="stream">The Compound File Storage Ole <see cref="CFStream" /></param>
        internal OleStream(ICFStream stream)
        {
            using (var memoryStream = new MemoryStream(stream.GetData()))
            using (var binaryReader = new BinaryReader(memoryStream))
            {
                Version = binaryReader.ReadUInt16();

                // Flags (4 bytes): If this field is set to 0x00000001, the OLEStream structure MUST be for a linked object and
                // the CLSID field of the Compound File Directory Entry of the OLE Compound File Storage object MUST be set to 
                // CLSID_StdOleLink ({00000300-0000-0000-C000-000000000046}). If this field is set to 0x00000000, then the OLEStream 
                // structure MUST be for an embedded object and the CLSID field of the Compound File Directory Entry
                // of the OLE Compound File Storage object MUST be set to the object class GUID of the creating application.
                var flags = binaryReader.ReadUInt32();

                switch (flags)
                {
                    case 0x00000000:
                    case 0x00001000:
                        Format = OleFormat.File;
                        break;

                    case 0x00000001:
                    case 0x00001001:
                        Format = OleFormat.Link;
                        break;
                }

                // LinkUpdateOption (4 bytes): This field contains an implementation-specific hint supplied by the application or by
                // a higher-level protocol that creates the data structure. The hint MAY be ignored on processing of this data structure
                LinkUpdateOptions = binaryReader.ReadUInt32();

                //Reserved1 (4 bytes): This MUST be set to 0x00000000. Otherwise, the OLEStream structure is invalid
                binaryReader.ReadUInt32();

                // ReservedMonikerStreamSize (4 bytes): This MUST be set to the size, in bytes, of the ReservedMonikerStream field. If this 
                // field has a value 0x00000000, the ReservedMonikerStream field MUST NOT be present.
                var reservedMonikerStreamSize = (int) binaryReader.ReadUInt32();

                // ReservedMonikerStream (variable): This MUST be a MONIKERSTREAM structure that can contain any arbitrary 
                // value and MUST be ignored on processing.
                binaryReader.ReadBytes(reservedMonikerStreamSize);

                // Note The fields that follow MUST NOT be present if the OLEStream structure is for an embedded object.
                if (Format == OleFormat.Link)
                {
                    // RelativeSourceMonikerStreamSize (4 bytes): This MUST be set to the size, in bytes, of the RelativeSourceMonikerStream field. 
                    // If this field has a value 0x00000000, the RelativeSourceMonikerStream field MUST NOT be present.
                    var relativeSourceMonikerStreamSize = (int) binaryReader.ReadUInt32();

                    // RelativeSourceMonikerStream (variable): This MUST be a MONIKERSTREAM structure that specifies the relative 
                    // path to the linked object.
                    if (relativeSourceMonikerStreamSize > 0)
                        RelativeSource = new MonikerStream(binaryReader, relativeSourceMonikerStreamSize);

                    // AbsoluteSourceMonikerStreamSize (4 bytes): This MUST be set to the size, in bytes, of the AbsoluteSourceMonikerStream field. 
                    // This field MUST NOT contain the value 0x00000000.
                    var absoluteSourceMonikerStreamSize = (int) binaryReader.ReadUInt32();

                    // AbsoluteSourceMonikerStream (variable): This MUST be a MONIKERSTREAM structure that specifies the full path 
                    // to the linked object.
                    if (absoluteSourceMonikerStreamSize > 0)
                        AbsoluteSource = new MonikerStream(binaryReader, absoluteSourceMonikerStreamSize);

                    // If the RelativeSourceMonikerStream field is present, it MUST be used by the container application instead of the 
                    // AbsoluteSourceMonikerStream. If the RelativeSourceMonikerStream field is not present, the AbsoluteSourceMonikerStream MUST be used 
                    // by the container application.

                    // ClsidIndicator (4 bytes): This MUST be the LONG as specified in section value -1. Otherwise the OLEStream 
                    // structure is invalid.
                    binaryReader.ReadUInt32();

                    // Clsid (16 bytes): This MUST be the CLSID (Packet) containing the object class GUID of the creating application.
                    Clsid = new CLSID(binaryReader);

                    // ReservedDisplayName (4 bytes): This MUST be a LengthPrefixedUnicodeString that can contain any arbitrary value 
                    // and MUST be ignored on processing.
                    binaryReader.ReadUInt32();

                    // Reserved2 (4 bytes): This can contain any arbitrary value and MUST be ignored on processing.
                    binaryReader.ReadUInt32();

                    // LocalUpdateTime (4 bytes): This MUST be a FILETIME (Packet) that contains the time when the container application 
                    // last updated the RemoteUpdateTime field.
                    var localUpdateTime = binaryReader.ReadBytes(4).Reverse().ToArray();
                    LocalUpdateTime = DateTime.FromFileTime(BitConverter.ToInt32(localUpdateTime, 0));

                    // LocalCheckUpdateTime (4 bytes): This MUST be a FILETIME (Packet) that contains the time when the container application last 
                    // checked the update time of the linked object.
                    var localCheckUpdateTime = binaryReader.ReadBytes(4).Reverse().ToArray();
                    LocalCheckUpdateTime = DateTime.FromFileTime(BitConverter.ToInt32(localCheckUpdateTime, 0));

                    // RemoteUpdateTime (4 bytes): This MUST be a FILETIME (Packet) that contains the time when the linked object was last updated.
                    var remoteUpdateTime = binaryReader.ReadBytes(4).Reverse().ToArray();
                    RemoteUpdateTime = DateTime.FromFileTime(BitConverter.ToInt32(remoteUpdateTime, 0));
                }
            }
        }
示例#4
0
        /// <summary>
        ///     Creates this object and sets all its properties
        /// </summary>
        /// <param name="stream">The Compound File Storage CompObj <see cref="CFStream" /></param>
        internal CompObjStream(ICFStream stream)
        {
            using (var memoryStream = new MemoryStream(stream.GetData()))
            using (var binaryReader = new BinaryReader(memoryStream))
            {
                // Reserved1 (4 bytes): This can be set to any arbitrary value and MUST be ignored on processing.
                // Version (4 bytes): This can be set to any arbitrary value and MUST be ignored on processing.
                // Reserved2 (20 bytes): This can be set to any arbitrary value and MUST be ignored on processing.
                // Skip the first 28 bytes, this is the CompObjHeader
                binaryReader.ReadBytes(28);

                // This MUST be a LengthPrefixedAnsiString structure that contains a display name of the linked 
                // object or embedded object. 
                AnsiUserType = Strings.Read4ByteLengthPrefixedAnsiString(binaryReader);

                // MarkerOrLength (4 bytes): If this is set to 0x00000000, the FormatOrAnsiString field MUST NOT 
                // be present. If this field is set to 0xFFFFFFFF or 0xFFFFFFFE, the FormatOrAnsiString field MUST 
                // be 4 bytes in size and MUST contain a standard clipboard format identifier. 
                // If this set to a value other than 0x00000000, the FormatOrAnsiString field MUST be set to a 
                // null-terminated ANSI string containing the name of a registered clipboard format and the 
                // MarkerOrLength field MUST be set to the number of ANSI characters in the FormatOrAnsiString field, 
                // including the terminating null character.
                var markerOrLength = binaryReader.ReadUInt32();

                switch (markerOrLength)
                {
                    case 0x00000000:
                        // Skip
                        break;

                    case 0xFFFFFFFF:
                    case 0xFFFFFFFE:
                        ClipboardFormat = (OleClipboardFormat) binaryReader.ReadUInt32();
                        break;

                    default:
                        binaryReader.BaseStream.Position -= 4;
                        StringFormat = Strings.Read4ByteLengthPrefixedAnsiString(binaryReader);
                        break;
                }


                // Reserved1 (variable): If present, this MUST be a LengthPrefixedAnsiString structure. If the Length 
                // field of the LengthPrefixedAnsiString contains a value of 0 or a value that is greater than 0x00000028, 
                // the remaining fields of the structure starting with the String field of the LengthPrefixedAnsiString 
                // MUST be ignored on processing. 
                var reserved1Length = binaryReader.ReadUInt32();
                if (reserved1Length <= 0x00000028)
                {
                    binaryReader.BaseStream.Position -= 4;
                    // ReSharper disable once UnusedVariable
                    var reserved1 = Strings.Read4ByteLengthPrefixedAnsiString(binaryReader);
                }

                // UnicodeMarker (variable): If this field is present and is NOT set to 0x71B239F4, the remaining fields 
                // of the structure MUST be ignored on processing.
                var unicodeMarker = binaryReader.ReadUInt32();
                if (unicodeMarker == 0x71B239F4)
                {
                    markerOrLength = binaryReader.ReadUInt32();

                    switch (markerOrLength)
                    {
                        case 0x00000000:
                            // Skip
                            break;

                        case 0xFFFFFFFF:
                        case 0xFFFFFFFE:
                            ClipboardFormat = (OleClipboardFormat) binaryReader.ReadUInt32();
                            break;

                        default:
                            binaryReader.BaseStream.Position -= 4;
                            StringFormat = Strings.Read4ByteLengthPrefixedAnsiString(binaryReader);
                            break;
                    }
                }
            }
        }
 /// <summary>
 ///     Creates this object and sets all its properties
 /// </summary>
 /// <param name="stream">The Compound File Storage AttachDesc <see cref="CFStream" /></param>
 internal AttachDescStream(ICFStream stream)
 {
     using (var memoryStream = new MemoryStream(stream.GetData()))
     using (var binaryReader = new BinaryReader(memoryStream))
     {
         Version = binaryReader.ReadUInt16();
         LongPathName = Strings.Read1ByteLengthPrefixedAnsiString(binaryReader);
         PathName = Strings.Read1ByteLengthPrefixedAnsiString(binaryReader);
         DisplayName = Strings.Read1ByteLengthPrefixedAnsiString(binaryReader);
         LongFileName = Strings.Read1ByteLengthPrefixedAnsiString(binaryReader);
         FileName = Strings.Read1ByteLengthPrefixedAnsiString(binaryReader);
         Extension = Strings.Read1ByteLengthPrefixedAnsiString(binaryReader);
         var fileCreationTime = binaryReader.ReadBytes(8).ToArray();
         FileCreationTime = DateTime.FromFileTime(BitConverter.ToInt64(fileCreationTime, 0));
         var fileLastModifiedTime = binaryReader.ReadBytes(8).ToArray();
         FileLastModifiedTime = DateTime.FromFileTime(BitConverter.ToInt64(fileLastModifiedTime, 0));
     }
 }