Exemplo n.º 1
0
            public override object ReadScalarValue(System.IO.BinaryReader br)
            {
                VTPropertyType vType = (VTPropertyType)br.ReadUInt16();

                br.ReadUInt16(); // Ushort Padding

                ITypedPropertyValue p = PropertyFactory.Instance.NewProperty(vType, codePage, true);

                p.Read(br);
                return(p);
            }
Exemplo n.º 2
0
        public ITypedPropertyValue NewProperty(VTPropertyType vType, PropertyContext ctx)
        {
            ITypedPropertyValue pr = null;

            switch (vType)
            {
            case VTPropertyType.VT_I2:
                pr = new VT_I2_Property(vType);
                break;

            case VTPropertyType.VT_I4:
                pr = new VT_I4_Property(vType);
                break;

            case VTPropertyType.VT_R4:
                pr = new VT_R4_Property(vType);
                break;

            case VTPropertyType.VT_LPSTR:
                pr = new VT_LPSTR_Property(vType, ctx.CodePage);
                break;

            case VTPropertyType.VT_FILETIME:
                pr = new VT_FILETIME_Property(vType);
                break;

            case VTPropertyType.VT_DECIMAL:
                pr = new VT_DECIMAL_Property(vType);
                break;

            case VTPropertyType.VT_BOOL:
                pr = new VT_BOOL_Property(vType);
                break;

            case VTPropertyType.VT_VECTOR_HEADER:
                pr = new VT_VectorHeader(vType);
                break;

            case VTPropertyType.VT_EMPTY:
                pr = new VT_EMPTY_Property(vType);
                break;

            default:
                throw new Exception("Unrecognized property type");
            }

            return(pr);
        }
Exemplo n.º 3
0
        private IProperty ReadProperty(uint propertyIdentifier, int codePage, BinaryReader br)
        {
            if (propertyIdentifier != 0)
            {
                VTPropertyType vType = (VTPropertyType)br.ReadUInt16();
                br.ReadUInt16(); // Ushort Padding

                ITypedPropertyValue pr = PropertyFactory.Instance.NewProperty(vType, codePage);
                pr.Read(br);

                return(pr);
            }
            else
            {
                IDictionaryProperty dictionaryProperty = new DictionaryProperty(codePage);
                dictionaryProperty.Read(br);
                return(dictionaryProperty);
            }
        }
        public void Save(CFStream cfStream)
        {
            //throw new NotImplementedException("API Unstable - Work in progress - Milestone 2.3.0.0");
            //properties.Sort((a, b) => a.PropertyIdentifier.CompareTo(b.PropertyIdentifier));

            Stream       s  = new StreamDecorator(cfStream);
            BinaryWriter bw = new BinaryWriter(s);

            PropertySetStream ps = new PropertySetStream
            {
                ByteOrder        = 0xFFFE,
                Version          = 0,
                SystemIdentifier = 0x00020006,
                CLSID            = Guid.Empty,

                NumPropertySets = 1,

                FMTID0  = this.ContainerType == ContainerType.SummaryInfo ? new Guid("{F29F85E0-4FF9-1068-AB91-08002B27B3D9}") : new Guid("{D5CDD502-2E9C-101B-9397-08002B2CF9AE}"),
                Offset0 = 0,

                FMTID1  = Guid.Empty,
                Offset1 = 0,

                PropertySet0 = new PropertySet
                {
                    NumProperties = (uint)this.Properties.Count(),
                    PropertyIdentifierAndOffsets = new List <PropertyIdentifierAndOffset>(),
                    Properties      = new List <Interfaces.IProperty>(),
                    PropertyContext = this.Context
                }
            };

            foreach (var op in this.Properties)
            {
                ITypedPropertyValue p = PropertyFactory.Instance.NewProperty(op.VTType, this.Context.CodePage);
                p.Value = op.Value;
                ps.PropertySet0.Properties.Add(p);
                ps.PropertySet0.PropertyIdentifierAndOffsets.Add(new PropertyIdentifierAndOffset()
                {
                    PropertyIdentifier = op.PropertyIdentifier, Offset = 0
                });
            }

            ps.PropertySet0.NumProperties = (uint)this.Properties.Count();

            if (HasUserDefinedProperties)
            {
                ps.NumPropertySets = 2;

                ps.PropertySet1 = new PropertySet
                {
                    NumProperties = (uint)this.UserDefinedProperties.Properties.Count(),
                    PropertyIdentifierAndOffsets = new List <PropertyIdentifierAndOffset>(),
                    Properties      = new List <Interfaces.IProperty>(),
                    PropertyContext = UserDefinedProperties.Context
                };

                ps.FMTID1  = new Guid("{D5CDD502-2E9C-101B-9397-08002B2CF9AE}");
                ps.Offset1 = 0;

                foreach (var op in this.Properties)
                {
                    ITypedPropertyValue p = PropertyFactory.Instance.NewProperty(op.VTType, ps.PropertySet1.PropertyContext.CodePage);
                    p.Value = op.Value;
                    ps.PropertySet1.Properties.Add(p);
                    ps.PropertySet1.PropertyIdentifierAndOffsets.Add(new PropertyIdentifierAndOffset()
                    {
                        PropertyIdentifier = op.PropertyIdentifier, Offset = 0
                    });
                }
            }

            ps.Write(bw);
        }
Exemplo n.º 5
0
        public List <ITypedPropertyValue> ReadProperty(PropertyIdentifiersSummaryInfo propertyIdentifier, BinaryReader br)
        {
            List <ITypedPropertyValue> res = new List <ITypedPropertyValue>();
            bool isVariant         = false;
            PropertyDimensions dim = PropertyDimensions.IsScalar;

            UInt16 pVal = br.ReadUInt16();

            VTPropertyType vType = (VTPropertyType)(pVal & 0x00FF);

            if ((pVal & 0x1000) != 0)
            {
                dim = PropertyDimensions.IsVector;
            }
            else if ((pVal & 0x2000) != 0)
            {
                dim = PropertyDimensions.IsArray;
            }

            isVariant = ((pVal & 0x00FF) == 0x000C);

            br.ReadUInt16(); // Ushort Padding

            switch (dim)
            {
            case PropertyDimensions.IsVector:

                ITypedPropertyValue vectorHeader = factory.NewProperty(VTPropertyType.VT_VECTOR_HEADER, ctx);
                vectorHeader.Read(br);

                uint nItems = (uint)vectorHeader.PropertyValue;

                for (int i = 0; i < nItems; i++)
                {
                    VTPropertyType vTypeItem = VTPropertyType.VT_EMPTY;

                    if (isVariant)
                    {
                        UInt16 pValItem = br.ReadUInt16();
                        vTypeItem = (VTPropertyType)(pValItem & 0x00FF);
                        br.ReadUInt16();     // Ushort Padding
                    }
                    else
                    {
                        vTypeItem = vType;
                    }

                    var p = factory.NewProperty(vTypeItem, ctx);

                    p.Read(br);
                    res.Add(p);
                }

                break;

            default:

                //Scalar property
                ITypedPropertyValue pr = factory.NewProperty(vType, ctx);

                pr.Read(br);

                if (propertyIdentifier == PropertyIdentifiersSummaryInfo.CodePageString)
                {
                    this.ctx.CodePage = (short)pr.PropertyValue;
                }

                res.Add(pr);
                break;
            }

            return(res);
        }
Exemplo n.º 6
0
            public override void WriteScalarValue(BinaryWriter bw, object pValue)
            {
                ITypedPropertyValue p = (ITypedPropertyValue)pValue;

                p.Write(bw);
            }
Exemplo n.º 7
0
        public ITypedPropertyValue NewProperty(VTPropertyType vType, int codePage, bool isVariant = false)
        {
            ITypedPropertyValue pr = null;

            switch ((VTPropertyType)((ushort)vType & 0x00FF))
            {
            case VTPropertyType.VT_I1:
                pr = new VT_I1_Property(vType, isVariant);
                break;

            case VTPropertyType.VT_I2:
                pr = new VT_I2_Property(vType, isVariant);
                break;

            case VTPropertyType.VT_I4:
                pr = new VT_I4_Property(vType, isVariant);
                break;

            case VTPropertyType.VT_R4:
                pr = new VT_R4_Property(vType, isVariant);
                break;

            case VTPropertyType.VT_R8:
                pr = new VT_R8_Property(vType, isVariant);
                break;

            case VTPropertyType.VT_CY:
                pr = new VT_CY_Property(vType, isVariant);
                break;

            case VTPropertyType.VT_DATE:
                pr = new VT_DATE_Property(vType, isVariant);
                break;

            case VTPropertyType.VT_INT:
                pr = new VT_INT_Property(vType, isVariant);
                break;

            case VTPropertyType.VT_UINT:
                pr = new VT_UINT_Property(vType, isVariant);
                break;

            case VTPropertyType.VT_UI1:
                pr = new VT_UI1_Property(vType, isVariant);
                break;

            case VTPropertyType.VT_UI2:
                pr = new VT_UI2_Property(vType, isVariant);
                break;

            case VTPropertyType.VT_UI4:
                pr = new VT_UI4_Property(vType, isVariant);
                break;

            case VTPropertyType.VT_UI8:
                pr = new VT_UI8_Property(vType, isVariant);
                break;

            case VTPropertyType.VT_BSTR:
            case VTPropertyType.VT_LPSTR:
                pr = new VT_LPSTR_Property(vType, codePage, isVariant);
                break;

            case VTPropertyType.VT_LPWSTR:
                pr = new VT_LPWSTR_Property(vType, codePage, isVariant);
                break;

            case VTPropertyType.VT_FILETIME:
                pr = new VT_FILETIME_Property(vType, isVariant);
                break;

            case VTPropertyType.VT_DECIMAL:
                pr = new VT_DECIMAL_Property(vType, isVariant);
                break;

            case VTPropertyType.VT_BOOL:
                pr = new VT_BOOL_Property(vType, isVariant);
                break;

            case VTPropertyType.VT_EMPTY:
                pr = new VT_EMPTY_Property(vType, isVariant);
                break;

            case VTPropertyType.VT_VARIANT_VECTOR:
                pr = new VT_VariantVector(vType, codePage, isVariant);
                break;

            case VTPropertyType.VT_CF:
                pr = new VT_CF_Property(vType, isVariant);
                break;

            case VTPropertyType.VT_BLOB_OBJECT:
            case VTPropertyType.VT_BLOB:
                pr = new VT_BLOB_Property(vType, isVariant);
                break;

            default:
                throw new Exception("Unrecognized property type");
            }

            return(pr);
        }
Exemplo n.º 8
0
        private void treeView1_MouseUp(object sender, MouseEventArgs e)
        {
            // Get the node under the mouse cursor.
            // We intercept both left and right mouse clicks
            // and set the selected treenode according.

            TreeNode n = treeView1.GetNodeAt(e.X, e.Y);

            if (n != null)
            {
                if (this.hexEditor.ByteProvider != null && this.hexEditor.ByteProvider.HasChanges())
                {
                    if (MessageBox.Show("Do you want to save pending changes ?", "Save changes", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                    {
                        this.hexEditor.ByteProvider.ApplyChanges();
                    }
                }

                treeView1.SelectedNode = n;


                // The tag property contains the underlying CFItem.
                CFItem target = (CFItem)n.Tag;

                if (target.IsStream)
                {
                    addStorageStripMenuItem1.Enabled    = false;
                    addStreamToolStripMenuItem.Enabled  = false;
                    importDataStripMenuItem1.Enabled    = true;
                    exportDataToolStripMenuItem.Enabled = true;

#if OLE_PROPERTY
                    if (target.Name == "\u0005SummaryInformation" || target.Name == "\u0005DocumentSummaryInformation")
                    {
                        PropertySetStream mgr = ((CFStream)target).AsOLEProperties();

                        DataTable ds = new DataTable();
                        ds.Columns.Add("Name", typeof(String));
                        ds.Columns.Add("Type", typeof(String));
                        ds.Columns.Add("Value", typeof(String));

                        for (int i = 0; i < mgr.PropertySet0.NumProperties; i++)
                        {
                            ITypedPropertyValue p = mgr.PropertySet0.Properties[i];

                            DataRow dr = ds.NewRow();
                            dr.ItemArray = new Object[] { mgr.PropertySet0.PropertyIdentifierAndOffsets[i].PropertyIdentifier.GetDescription(), p.VTType, p.PropertyValue };
                            ds.Rows.Add(dr);
                        }

                        ds.AcceptChanges();
                        dgvOLEProps.DataSource = ds;
                    }
#endif
                }
            }
            else
            {
                addStorageStripMenuItem1.Enabled    = true;
                addStreamToolStripMenuItem.Enabled  = true;
                importDataStripMenuItem1.Enabled    = false;
                exportDataToolStripMenuItem.Enabled = false;
            }

            if (n != null)
            {
                propertyGrid1.SelectedObject = n.Tag;
            }


            if (n != null)
            {
                CFStream targetStream = n.Tag as CFStream;
                if (targetStream != null)
                {
                    this.hexEditor.ByteProvider = new StreamDataProvider(targetStream);
                }
                else
                {
                    this.hexEditor.ByteProvider = null;
                }
            }
        }