Exemplo n.º 1
0
        public void Stat(out System.Runtime.InteropServices.ComTypes.STATSTG stg, int flags)
        {
            const int STGTY_STREAM = 2;

            stg         = new System.Runtime.InteropServices.ComTypes.STATSTG();
            stg.type    = STGTY_STREAM;
            stg.cbSize  = _stream.Length;
            stg.grfMode = 0;
            if (_stream.CanRead && _stream.CanWrite)
            {
                const int STGM_READWRITE = 0x00000002;
                stg.grfMode |= STGM_READWRITE;
                return;
            }
            if (_stream.CanRead)
            {
                const int STGM_READ = 0x00000000;
                stg.grfMode |= STGM_READ;
                return;
            }
            if (_stream.CanWrite)
            {
                const int STGM_WRITE = 0x00000001;
                stg.grfMode |= STGM_WRITE;
                return;
            }
            throw new IOException();
        }
 public void Stat(
     out System.Runtime.InteropServices.ComTypes.STATSTG pstatstg,
     int grfStatFlag)
 {
     pstatstg        = new System.Runtime.InteropServices.ComTypes.STATSTG();
     pstatstg.cbSize = base.Length;
 }
Exemplo n.º 3
0
        internal static System.Runtime.InteropServices.ComTypes.STATSTG[] GetElements(this IStorage storage)
        {
            HRESULT      hr         = HRESULT.E_FAIL;
            IEnumSTATSTG enumerator = null;
            List <System.Runtime.InteropServices.ComTypes.STATSTG> list = new List <System.Runtime.InteropServices.ComTypes.STATSTG>();

            try
            {
                if (NativeMethods.Succeeded(hr = storage.EnumElements(0, IntPtr.Zero, 0, out enumerator)))
                {
                    uint celt = 1;
                    System.Runtime.InteropServices.ComTypes.STATSTG[] statstg = new System.Runtime.InteropServices.ComTypes.STATSTG[1];
                    uint fetched = 0;

                    while ((NativeMethods.Succeeded(hr = enumerator.Next(celt, statstg, out fetched))) && (fetched > 0))
                    {
                        list.Add(statstg[0]);
                    }
                }
            }
            catch
            {
            }
            finally
            {
                if (enumerator != null)
                {
                    enumerator.FinalRelease();
                }
            }

            return(list.ToArray());
        }
Exemplo n.º 4
0
        public int Stat(out System.Runtime.InteropServices.ComTypes.STATSTG statstg, uint grfStatFlag)
        {
            System.Runtime.InteropServices.ComTypes.STATSTG statstgOut = new System.Runtime.InteropServices.ComTypes.STATSTG();
            statstg = statstgOut;

            #pragma warning disable 6500

            try
            {
                Verify();

                statstgOut.type              = 2; // STGTY_STREAM
                statstgOut.cbSize            = dataStream.Length;
                statstgOut.grfLocksSupported = 2; //LOCK_EXCLUSIVE
                statstgOut.pwcsName          = null;
                statstg = statstgOut;
            }
            catch (Exception e)
            {
                // store the last exception
                _lastException = e;
                return(SecurityHelper.GetHRForException(e));
            }

            #pragma warning restore 6500

            return(NativeMethods.S_OK);
        }
Exemplo n.º 5
0
        void IStream.Stat(out STATSTG pstatstg, int grfStatFlag)
        {
            pstatstg = new STATSTG
            {
                type   = 2,
                cbSize = m_stream.Length,
            };

            if (m_stream.CanRead && m_stream.CanWrite)
            {
                pstatstg.grfMode = Win32.STGM_READWRITE;
            }
            else if (m_stream.CanWrite)
            {
                pstatstg.grfMode = Win32.STGM_WRITE;
            }
            else if (m_stream.CanRead)
            {
                pstatstg.grfMode = Win32.STGM_READ;
            }
            else
            {
                throw new IOException();
            }
        }
Exemplo n.º 6
0
        public static CompoundFile Open(string path)
        {
            IStorage storage = OpenStorage(path);

            System.Runtime.InteropServices.ComTypes.STATSTG statstg = storage.GetStatistics();
            return(new CompoundFile(storage, statstg));
        }
        internal CompoundFile(IStorage storage, System.Runtime.InteropServices.ComTypes.STATSTG statstg)
        {
            if (storage == null) { throw new ArgumentNullException("storage"); }

            _rootStorage = storage;
            _statstg = statstg;
        }
Exemplo n.º 8
0
        internal static System.Runtime.InteropServices.ComTypes.STATSTG GetStatistics(this IStorage storage, STATFLAG statflag)
        {
            System.Runtime.InteropServices.ComTypes.STATSTG statstg = default(System.Runtime.InteropServices.ComTypes.STATSTG);
            uint grfStatFlag = (uint)statflag;

            storage.Stat(out statstg, grfStatFlag);
            return(statstg);
        }
Exemplo n.º 9
0
 public void Stat(out System.Runtime.InteropServices.ComTypes.STATSTG pstatstg, int grfStatFlag)
 {
     pstatstg = new System.Runtime.InteropServices.ComTypes.STATSTG()
     {
         cbSize = this.stream.Length,
         type   = 2,
     };
 }
Exemplo n.º 10
0
 void IStorage.Stat(
     out System.Runtime.InteropServices.ComTypes.STATSTG pstatstg,
     int grfStatFlag)
 {
     _unsafeStorage.Stat(
         out pstatstg,
         grfStatFlag);
 }
Exemplo n.º 11
0
            void IStorage.Stat(
                out System.Runtime.InteropServices.ComTypes.STATSTG pstatstg,
                int grfStatFlag)
            {
                SecurityHelper.DemandCompoundFileIOPermission();

                _unsafeStorage.Stat(
                    out pstatstg,
                    grfStatFlag);
            }
Exemplo n.º 12
0
        internal CompoundFile(IStorage storage, System.Runtime.InteropServices.ComTypes.STATSTG statstg)
        {
            if (storage == null)
            {
                throw new ArgumentNullException("storage");
            }

            _rootStorage = storage;
            _statstg     = statstg;
        }
Exemplo n.º 13
0
        public static VCSolutionOptions Read(string InputFileName)
        {
            IOleStorage Storage = null;

            StgOpenStorage(InputFileName, null, STGM.Direct | STGM.Read | STGM.ShareExclusive, IntPtr.Zero, 0, out Storage);
            try
            {
                IOleEnumSTATSTG Enumerator = null;
                Storage.EnumElements(0, IntPtr.Zero, 0, out Enumerator);
                try
                {
                    uint      Fetched;
                    STATSTG[] Stats = new STATSTG[200];
                    Enumerator.Next((uint)Stats.Length, Stats, out Fetched);

                    VCSolutionOptions Options = new VCSolutionOptions();
                    foreach (STATSTG Stat in Stats)
                    {
                        if (Stat.pwcsName == "SolutionConfiguration")
                        {
                            IOleStream OleStream;
                            Storage.OpenStream(Stat.pwcsName, IntPtr.Zero, STGM.Read | STGM.ShareExclusive, 0, out OleStream);
                            try
                            {
                                uint   SizeRead;
                                byte[] Buffer = new byte[Stat.cbSize];
                                OleStream.Read(Buffer, (uint)Stat.cbSize, out SizeRead);

                                using (MemoryStream InputStream = new MemoryStream(Buffer, false))
                                {
                                    BinaryReader Reader = new BinaryReader(InputStream, Encoding.Unicode);
                                    while (InputStream.Position < InputStream.Length)
                                    {
                                        Options.SolutionConfiguration.Add(VCBinarySetting.Read(Reader));
                                    }
                                }
                            }
                            finally
                            {
                                Marshal.ReleaseComObject(OleStream);
                            }
                        }
                    }
                    return(Options);
                }
                finally
                {
                    Marshal.ReleaseComObject(Enumerator);
                }
            }
            finally
            {
                Marshal.ReleaseComObject(Storage);
            }
        }
Exemplo n.º 14
0
 /// <summary>
 /// Constructor of the class
 /// </summary>
 /// <param name="workPath">workpath of the storage</param>
 /// <param name="enumStorage">true if the storage should be enumerated automatically</param>
 public IStorageWrapper(string workPath, bool enumStorage)
 {
     Interop.StgOpenStorage(workPath, null, 16, IntPtr.Zero, 0, out storage);
     IBaseStorageWrapper.BaseUrl = workPath;
     System.Runtime.InteropServices.ComTypes.STATSTG sTATSTG = new System.Runtime.InteropServices.ComTypes.STATSTG();
     storage.Stat(out sTATSTG, 1);
     if (enumStorage)
     {
         base.EnumIStorageObject();
     }
 }
Exemplo n.º 15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ComStreamWrapper"/> class.
        /// </summary>
        /// <param name="istream">The istream to wrap.</param>
        /// <param name="isStreamOwner">If set to <c>true</c>, this instance should be the owner of the wrapped stream and thus is responsible for disposing it.</param>
        /// <exception cref="System.ArgumentNullException">istream is null.</exception>
        public ComStreamWrapper(System.Runtime.InteropServices.ComTypes.IStream istream, bool isStreamOwner)
        {
            _istream       = istream ?? throw new ArgumentNullException(nameof(istream));
            _isStreamOwner = isStreamOwner;

            _int64Ptr = Marshal.AllocCoTaskMem(8);
            _int32Ptr = Marshal.AllocCoTaskMem(4);

            _streamStatus = new System.Runtime.InteropServices.ComTypes.STATSTG();
            _istream.Stat(out _streamStatus, STATFLAG.NONAME);
        }
Exemplo n.º 16
0
        void ILockBytes.Stat(out System.Runtime.InteropServices.ComTypes.STATSTG pstatstg, int grfStatFlag)
        {
            ThrowIfDisposed();

            pstatstg = new System.Runtime.InteropServices.ComTypes.STATSTG()
            {
                grfLocksSupported = 0, // No lock supported
                cbSize            = _stream.Length,
                type = (int)STGTY.LOCKBYTES
            };
        }
Exemplo n.º 17
0
        public void Load(Object source)
        {
            XmlSerializer ser = ElementFactory.GetSerializerFor(element);

            if (source is string)
            {
                using (XmlTextReader rdr = new XmlTextReader((string)source))
                {
                    this.element = ser.Deserialize(rdr) as HL7SDK.Xml.Cda.POCD_MT000040ClinicalDocument;
                }
            }

            else if (source is System.IO.Stream)
            {
                var stream = source as System.IO.Stream;
                this.element = ser.Deserialize(stream) as HL7SDK.Xml.Cda.POCD_MT000040ClinicalDocument;
            }

            else if (source is System.IO.TextReader)
            {
                var reader = source as System.IO.TextReader;
                this.element = ser.Deserialize(reader) as HL7SDK.Xml.Cda.POCD_MT000040ClinicalDocument;
            }

            else if (source is System.Xml.XmlReader)
            {
                var reader = source as System.Xml.XmlReader;
                this.element = ser.Deserialize(reader) as HL7SDK.Xml.Cda.POCD_MT000040ClinicalDocument;
            }

            else if (source is System.Runtime.InteropServices.ComTypes.IStream)
            {
                var comStream = source as System.Runtime.InteropServices.ComTypes.IStream;
                System.Runtime.InteropServices.ComTypes.STATSTG s = default(System.Runtime.InteropServices.ComTypes.STATSTG);
                comStream.Stat(out s, 0);
                byte[] b       = new byte[s.cbSize];
                IntPtr pcbRead = default(IntPtr);
                comStream.Read(b, b.Length, pcbRead);

                using (var stream = new System.IO.MemoryStream(b))
                {
                    this.element = ser.Deserialize(stream) as HL7SDK.Xml.Cda.POCD_MT000040ClinicalDocument;
                    stream.Close();
                }
            }

            else
            {
                throw new ArgumentException("Unsupported type.");
            }
        }
Exemplo n.º 18
0
        public void ComEnumeratorTest5()
        {
            // Test IntPtr -> string conversion
            var fn = System.IO.Path.GetTempFileName();
            var hr = StgCreateStorageEx(fn,
                                        STGM.STGM_DELETEONRELEASE | STGM.STGM_CREATE | STGM.STGM_DIRECT | STGM.STGM_READWRITE | STGM.STGM_SHARE_EXCLUSIVE,
                                        STGFMT.STGFMT_DOCFILE, 0, IntPtr.Zero, IntPtr.Zero, typeof(IStorage).GUID, out object iptr);

            Assert.That(hr, Is.EqualTo((HRESULT)HRESULT.S_OK));
            var istg = (IStorage)iptr;

            Assert.That(istg, Is.InstanceOf <IStorage>());
            var istgc = istg.CreateStorage("temp",
                                           STGM.STGM_CREATE | STGM.STGM_DIRECT | STGM.STGM_WRITE | STGM.STGM_SHARE_EXCLUSIVE, 0, 0);

            istgc.Commit(STGC.STGC_DEFAULT);
            var istr = istg.CreateStream("stream1",
                                         STGM.STGM_CREATE | STGM.STGM_DIRECT | STGM.STGM_WRITE | STGM.STGM_SHARE_EXCLUSIVE, 0, 0);
            var strb = "Some string text".GetBytes();

            istr.Write(strb, strb.Length, IntPtr.Zero);
            istr.Commit((int)STGC.STGC_DEFAULT);
            istg.Commit(STGC.STGC_DEFAULT);
            var ee = istg.EnumElements(0, IntPtr.Zero, 0);

            // Test IEnumerable
            bool Next(out STATSTG p)
            {
                var a = new STATSTG[1];
                var b = ee.Next(1, a, out var f).Succeeded&& f == 1;

                p = b ? a[0] : default(STATSTG);
                return(b);
            }

            var e = new IEnumFromNext <STATSTG>(Next, ee.Reset);

            foreach (var p in e)
            {
                //Assert.That(p.cbSize, Is.Not.Zero);
                TestContext.WriteLine(p.pwcsName);
            }

            // Test IEnumerator
            var g = e.GetEnumerator();

            g.Reset();
            Assert.That(g.MoveNext(), Is.True);
            g.Dispose();
            Assert.That(g.MoveNext(), Is.False);
        }
Exemplo n.º 19
0
            void IEnumSTATSTG.Next(
                UInt32 celt,
                out System.Runtime.InteropServices.ComTypes.STATSTG rgelt, // This should really be array, but we're OK if we stick with one item at a time.
                // Because marshalling an array of structs that have pointers to strings are troublesome.
                out UInt32 pceltFetched)
            {
                if (celt != 1)
                {
                    throw new ArgumentException(SR.Get(SRID.InvalidArgumentValue, "celt", celt.ToString(CultureInfo.InvariantCulture)));
                }

                _unsafeEnumSTATSTG.Next(
                    celt,
                    out rgelt,
                    out pceltFetched);
            }
Exemplo n.º 20
0
		void IStream.Stat(out STATSTG pstatstg, int grfStatFlag)
		{
			pstatstg = new STATSTG
			{
				type = 2,
				cbSize = m_stream.Length,
			};

			if (m_stream.CanRead && m_stream.CanWrite)
				pstatstg.grfMode = Win32.STGM_READWRITE;
			else if (m_stream.CanWrite)
				pstatstg.grfMode = Win32.STGM_WRITE;
			else if (m_stream.CanRead)
				pstatstg.grfMode = Win32.STGM_READ;
			else
				throw new IOException();
		}
    private static MemoryStream GetIStream(STGMEDIUM medium)
    {
        //marshal the returned pointer to a IStream object
        IStream iStream = (IStream)Marshal.GetObjectForIUnknown(medium.unionmember);

        Marshal.Release(medium.unionmember);
        //get the STATSTG of the IStream to determine how many bytes are in it
        var iStreamStat = new System.Runtime.InteropServices.ComTypes.STATSTG();

        iStream.Stat(out iStreamStat, 0);
        int iStreamSize = (int)iStreamStat.cbSize;

        //read the data from the IStream into a managed byte array
        byte[] iStreamContent = new byte[iStreamSize];
        iStream.Read(iStreamContent, iStreamContent.Length, IntPtr.Zero);
        //wrapped the managed byte array into a memory stream
        return(new MemoryStream(iStreamContent));
    }
Exemplo n.º 22
0
 public void Stat(out System.Runtime.InteropServices.ComTypes.STATSTG pstatstg, int grfStatFlag)
 {
     pstatstg         = new System.Runtime.InteropServices.ComTypes.STATSTG();
     pstatstg.type    = 2;
     pstatstg.cbSize  = this._stream.Length;
     pstatstg.grfMode = 0;
     if (this._stream.CanRead && this._stream.CanWrite)
     {
         pstatstg.grfMode |= 2;
     }
     else if (this._stream.CanWrite && !_stream.CanRead)
     {
         pstatstg.grfMode |= 1;
     }
     else
     {
         throw new IOException();
     }
 }
Exemplo n.º 23
0
        public VCOleContainer(string InputFileName)
        {
            IOleStorage Storage = null;

            StgOpenStorage(InputFileName, null, STGM.Direct | STGM.Read | STGM.ShareExclusive, IntPtr.Zero, 0, out Storage);
            try
            {
                IOleEnumSTATSTG Enumerator = null;
                Storage.EnumElements(0, IntPtr.Zero, 0, out Enumerator);
                try
                {
                    uint      Fetched;
                    STATSTG[] Stats = new STATSTG[200];
                    Enumerator.Next((uint)Stats.Length, Stats, out Fetched);

                    for (uint Idx = 0; Idx < Fetched; Idx++)
                    {
                        IOleStream OleStream;
                        Storage.OpenStream(Stats[Idx].pwcsName, IntPtr.Zero, STGM.Read | STGM.ShareExclusive, 0, out OleStream);
                        try
                        {
                            uint   SizeRead;
                            byte[] Buffer = new byte[Stats[Idx].cbSize];
                            OleStream.Read(Buffer, (uint)Stats[Idx].cbSize, out SizeRead);
                            Sections.Add(new KeyValuePair <string, byte[]>(Stats[Idx].pwcsName, Buffer));
                        }
                        finally
                        {
                            Marshal.ReleaseComObject(OleStream);
                        }
                    }
                }
                finally
                {
                    Marshal.ReleaseComObject(Enumerator);
                }
            }
            finally
            {
                Marshal.ReleaseComObject(Storage);
            }
        }
            void UnsafeNativeILockBytes.Stat(
                out System.Runtime.InteropServices.ComTypes.STATSTG pstatstg,
                int grfStatFlag)
            {
                CheckDisposed();

                if ((grfStatFlag & ~(SafeNativeCompoundFileConstants.STATFLAG_NONAME |
                                     SafeNativeCompoundFileConstants.STATFLAG_NOOPEN)) != 0)
                {
                    // validate grfStatFlag's value
                    throw new ArgumentException(SR.Get(SRID.InvalidArgumentValue, "grfStatFlag", grfStatFlag.ToString(CultureInfo.InvariantCulture)));
                }

                System.Runtime.InteropServices.ComTypes.STATSTG returnValue = new System.Runtime.InteropServices.ComTypes.STATSTG();

                returnValue.grfLocksSupported = 0;  // No lock supported

                returnValue.cbSize = _baseStream.Length;
                returnValue.type   = SafeNativeCompoundFileConstants.STGTY_LOCKBYTES;

                pstatstg = returnValue;
            }
Exemplo n.º 25
0
 public void Stat(out System.Runtime.InteropServices.ComTypes.STATSTG pstatstg, int grfStatFlag)
 {
     pstatstg = new System.Runtime.InteropServices.ComTypes.STATSTG { cbSize = m_stream.Length };
 }
Exemplo n.º 26
0
		/// <summary>
		/// Initializes a new instance of the <see cref="ComStreamWrapper"/> class.
		/// </summary>
		/// <param name="istream">The istream to wrap.</param>
		/// <param name="isStreamOwner">If set to <c>true</c>, this instance should be the owner of the wrapped stream and thus is responsible for disposing it.</param>
		/// <exception cref="System.ArgumentNullException">istream is null.</exception>
		public ComStreamWrapper(System.Runtime.InteropServices.ComTypes.IStream istream, bool isStreamOwner)
		{
			if (null == istream)
				throw new ArgumentNullException("istream");

			_isStreamOwner = isStreamOwner;
			_istream = istream;

			_int64Ptr = Marshal.AllocCoTaskMem(8);
			_int32Ptr = Marshal.AllocCoTaskMem(4);

			_streamStatus = new System.Runtime.InteropServices.ComTypes.STATSTG();
			_istream.Stat(out _streamStatus, STATFLAG.NONAME);
		}
Exemplo n.º 27
0
        public string SaveHtml()
        {
            if (!this.IsCreated)
            {
                throw new Exception("HtmlControl.SaveHtml : No HTML to save!");
            }
            string input = string.Empty;
            try
            {
                this.OnBeforeSave();

                Interop.IHTMLDocument2 mSHTMLDocument = this._site.MSHTMLDocument;
                if (this._fullDocumentMode)
                {
                    //NOTE: �л������ģʽ�����������������, ʹ��System.Runtime.InteropServices.ComTypes�µ���ͽṹ��������
                    // �滻Interop.IStreamΪSystem.Runtime.InteropServices.ComTypes.IStream
                    IntPtr ptr;
                    Interop.IPersistStreamInit init = (Interop.IPersistStreamInit)mSHTMLDocument;
                    System.Runtime.InteropServices.ComTypes.IStream pStream = null;
                    Interop.CreateStreamOnHGlobal(Interop.NullIntPtr, true, ref pStream);
                    init.Save(pStream, 1);
                    //Interop.STATSTG pstatstg = new Interop.STATSTG();
                    System.Runtime.InteropServices.ComTypes.STATSTG pStat = new System.Runtime.InteropServices.ComTypes.STATSTG();
                    pStream.Stat(out pStat, 1);
                    int cbSize = (int)pStat.cbSize;
                    byte[] destination = new byte[cbSize];
                    Interop.GetHGlobalFromStream(pStream, out ptr);
                    IntPtr source = Interop.GlobalLock(ptr);
                    if (!(source != Interop.NullIntPtr))
                    {
                        goto Label_010B;
                    }
                    Marshal.Copy(source, destination, 0, cbSize);
                    Interop.GlobalUnlock(ptr);
                    StreamReader reader = null;
                    try
                    {
                        reader = new StreamReader(new MemoryStream(destination), Encoding.Default);
                        input = reader.ReadToEnd();
                        goto Label_010B;
                    }
                    finally
                    {
                        if (reader != null)
                        {
                            reader.Close();
                        }
                    }
                }
                Interop.IHTMLElement body = mSHTMLDocument.GetBody();
                if (body != null)
                {
                    input = this.GetContentElement(ElementWrapperTable.GetWrapper(body, this)).InnerHtml;
                }
            }
            catch (Exception)
            {
                input = string.Empty;
            }
            finally
            {
                this.OnAfterSave();
            }
            Label_010B:
            if (input == null)
            {
                input = string.Empty;
            }
            HtmlFormatter formatter = new HtmlFormatter();
            StringWriter output = new StringWriter();
            formatter.Format(input, output, new HtmlFormatterOptions(' ', 4, 80, true));
            return output.ToString();
        }
Exemplo n.º 28
0
 public void Stat(out System.Runtime.InteropServices.ComTypes.STATSTG pstatstg, int grfStatFlag)
 {
     pstatstg = new System.Runtime.InteropServices.ComTypes.STATSTG();
     pstatstg.type = 2;
     pstatstg.cbSize = this._stream.Length;
     pstatstg.grfMode = 0;
     if (this._stream.CanRead && this._stream.CanWrite)
     {
         pstatstg.grfMode |= 2;
     }
     else if (this._stream.CanWrite && !_stream.CanRead)
     {
         pstatstg.grfMode |= 1;
     }
     else
     {
         throw new IOException();
     }
 }
Exemplo n.º 29
0
		public VCOleContainer(string InputFileName)
		{
			IOleStorage Storage = null;
			StgOpenStorage(InputFileName, null, STGM.Direct | STGM.Read | STGM.ShareExclusive, IntPtr.Zero, 0, out Storage);
			try
			{
				IOleEnumSTATSTG Enumerator = null;
				Storage.EnumElements(0, IntPtr.Zero, 0, out Enumerator);
				try
				{
					uint Fetched;
					STATSTG[] Stats = new STATSTG[200];
					Enumerator.Next((uint)Stats.Length, Stats, out Fetched);

					for(uint Idx = 0; Idx < Fetched; Idx++)
					{
						IOleStream OleStream;
						Storage.OpenStream(Stats[Idx].pwcsName, IntPtr.Zero, STGM.Read | STGM.ShareExclusive, 0, out OleStream);
						try
						{
							uint SizeRead;
							byte[] Buffer = new byte[Stats[Idx].cbSize];
							OleStream.Read(Buffer, (uint)Stats[Idx].cbSize, out SizeRead);
							Sections.Add(new KeyValuePair<string, byte[]>(Stats[Idx].pwcsName, Buffer));
						}
						finally
						{
							Marshal.ReleaseComObject(OleStream);
						}
					}
				}
				finally
				{
					Marshal.ReleaseComObject(Enumerator);
				}
			}
			finally
			{
				Marshal.ReleaseComObject(Storage);
			}
		}
 internal SynchronousAssemblyDocument(IStorage storage, System.Runtime.InteropServices.ComTypes.STATSTG statstg)
     : base(storage, statstg)
 {
 }
Exemplo n.º 31
0
        public static VCSolutionOptions Read(string InputFileName)
        {
            IOleStorage Storage = null;
            StgOpenStorage(InputFileName, null, STGM.Direct | STGM.Read | STGM.ShareExclusive, IntPtr.Zero, 0, out Storage);
            try
            {
                IOleEnumSTATSTG Enumerator = null;
                Storage.EnumElements(0, IntPtr.Zero, 0, out Enumerator);
                try
                {
                    uint Fetched;
                    STATSTG[] Stats = new STATSTG[200];
                    Enumerator.Next((uint)Stats.Length, Stats, out Fetched);

                    VCSolutionOptions Options = new VCSolutionOptions();
                    foreach (STATSTG Stat in Stats)
                    {
                        if (Stat.pwcsName == "SolutionConfiguration")
                        {
                            IOleStream OleStream;
                            Storage.OpenStream(Stat.pwcsName, IntPtr.Zero, STGM.Read | STGM.ShareExclusive, 0, out OleStream);
                            try
                            {
                                uint SizeRead;
                                byte[] Buffer = new byte[Stat.cbSize];
                                OleStream.Read(Buffer, (uint)Stat.cbSize, out SizeRead);

                                using (MemoryStream InputStream = new MemoryStream(Buffer, false))
                                {
                                    BinaryReader Reader = new BinaryReader(InputStream, Encoding.Unicode);
                                    while (InputStream.Position < InputStream.Length)
                                    {
                                        Options.SolutionConfiguration.Add(VCBinarySetting.Read(Reader));
                                    }
                                }
                            }
                            finally
                            {
                                Marshal.ReleaseComObject(OleStream);
                            }
                        }
                    }
                    return Options;
                }
                finally
                {
                    Marshal.ReleaseComObject(Enumerator);
                }
            }
            finally
            {
                Marshal.ReleaseComObject(Storage);
            }
        }
Exemplo n.º 32
0
 internal PartDocument(IStorage storage, System.Runtime.InteropServices.ComTypes.STATSTG statstg)
     : base(storage, statstg)
 {
 }
Exemplo n.º 33
0
        public int Stat(out System.Runtime.InteropServices.ComTypes.STATSTG statstg, uint grfStatFlag)
        { 
            System.Runtime.InteropServices.ComTypes.STATSTG statstgOut = new System.Runtime.InteropServices.ComTypes.STATSTG();
            statstg = statstgOut;

            #pragma warning disable 6500 

            try 
            { 
                Verify();
 
                statstgOut.type = 2; // STGTY_STREAM
                statstgOut.cbSize = dataStream.Length;
                statstgOut.grfLocksSupported = 2; //LOCK_EXCLUSIVE
                statstgOut.pwcsName = null; 
                statstg = statstgOut;
            } 
            catch (Exception e) 
            {
                // store the last exception 
                _lastException = e;
                return SecurityHelper.GetHRForException(e);
            }
 
            #pragma warning restore 6500
 
            return NativeMethods.S_OK; 
        }
Exemplo n.º 34
0
 public void Stat(out System.Runtime.InteropServices.ComTypes.STATSTG pstatstg, int grfStatFlag)
 {
     throw new NotImplementedException();
 }
 int IStorage.Stat(out System.Runtime.InteropServices.ComTypes.STATSTG pstatstg, uint grfStatFlag)
 {
     return(_storage.Stat(out pstatstg, grfStatFlag));
 }
Exemplo n.º 36
0
        private static void V8RecurseStorage(IStorage pStorage, string firstName, string name, int level)
        {
            System.Runtime.InteropServices.ComTypes.STATSTG[] entry = new System.Runtime.InteropServices.ComTypes.STATSTG[1];
            uint numReturned;

            string[] typnam = { "STGTY_STORAGE", "STGTY_STREAM", "STGTY_LOCKBYTES", "STGTY_PROPERTY" };

            pStorage.OpenStorage(name, null, (uint)(Stgm.Read | Stgm.ShareExclusive), IntPtr.Zero, 0, out IStorage storage);
            storage.EnumElements(0, IntPtr.Zero, 0, out IEnumSTATSTG pEnum);
            do
            {
                pEnum.Next(1, entry, out numReturned);
                if (numReturned != 0)
                {
                    string pad = new string(' ', level);
                    Logger.Info("{3}{0}, type={1}, size={2}", entry[0].pwcsName, typnam[entry[0].type - 1], entry[0].cbSize, pad);
                    switch (entry[0].type)
                    {
                    case (int)Stgty.StgtyStorage:
                    {
                        string pwzStream;
                        if (firstName == "")
                        {
                            pwzStream = firstName;
                        }
                        else
                        {
                            pwzStream = firstName + "@";
                        }

                        pwzStream += name;
                        V8RecurseStorage(storage, pwzStream, entry[0].pwcsName, level + 1);
                    }
                    break;

                    case (int)Stgty.StgtyStream:
                    {
                        string pwzStream;
                        if (firstName == "")
                        {
                            pwzStream = firstName;
                        }
                        else
                        {
                            pwzStream = firstName + "@";
                        }

                        pwzStream += name;
                        pwzStream += "@";
                        pwzStream += entry[0].pwcsName;

                        uint   cbSize = (uint)entry[0].cbSize;
                        byte[] buf    = new byte[cbSize];
                        storage.OpenStream(entry[0].pwcsName, IntPtr.Zero, (uint)(Stgm.Read | Stgm.ShareExclusive), 0, out IStream stream);
                        stream.Read(buf, cbSize, out var cbRead);
                        pwzStream = pwzStream.Replace(Convert.ToChar(Convert.ToUInt32("0x05", 16)), '$').Replace('^', '_');
                        V8DecodeAndWrite(pwzStream, buf, cbRead);
                        Marshal.ReleaseComObject(stream);
                    }
                    break;

                    case (int)Stgty.StgtyLockbytes:
                        break;

                    case (int)Stgty.StgtyProperty:
                        break;
                    }
                }
            } while (numReturned > 0);

            Marshal.ReleaseComObject(pEnum);
            Marshal.ReleaseComObject(storage);
            GC.Collect();
            GC.Collect();  // call twice for good measure
            GC.WaitForPendingFinalizers();
        }
Exemplo n.º 37
0
        static void ProcessPackage(IStorage pStg, string destinationFolder)
        {
            System.Runtime.InteropServices.ComTypes.IStream pStream;
            IEnumSTATSTG pEnumStatStg;
            uint numReturned;
            pStg.EnumElements(0, IntPtr.Zero, 0, out pEnumStatStg);
            System.Runtime.InteropServices.ComTypes.STATSTG[] ss = new System.Runtime.InteropServices.ComTypes.STATSTG[1];
            // Loop through the STATSTG structures in the storage.
            do
            {
                // Retrieve the STATSTG structure
                pEnumStatStg.Next(1, ss, out numReturned);
                if (numReturned != 0)
                {
                    //System.Runtime.InteropServices.ComTypes.STATSTG statstm;
                    byte[] bytT = new byte[4];
                    // Check if the pwcsName contains "Ole10Native" stream which contain the actual embedded object
                    if (ss[0].pwcsName.Contains("Ole10Native") == true)
                    {
                        // Get the stream objectOpen the stream
                        pStg.OpenStream(ss[0].pwcsName, IntPtr.Zero, (uint)STGM.READ | (uint)STGM.SHARE_EXCLUSIVE, 0, out pStream);
                        //pStream.Stat(out statstm, (int) STATFLAG.STATFLAG_DEFAULT);

                        IntPtr position = IntPtr.Zero;
                        // File name starts from 7th Byte.
                        // Position the cursor to the 7th Byte.
                        pStream.Seek(6, 0, position);

                        IntPtr ulRead = new IntPtr();
                        char[] filename = new char[260];
                        int i;

                        // Read the File name of the embedded object
                        for (i = 0; i < 260; i++)
                        {
                            pStream.Read(bytT, 1, ulRead);
                            pStream.Seek(0, 1, position);
                            filename[i] = (char)bytT[0];
                            if (bytT[0] == 0)
                            {
                                break;
                            }
                        }
                        string path = new string(filename, 0, i);

                        // Next part is the source path of the embedded object.
                        // Length is unknown. Hence, loop through each byte to read the 0 terminated string
                        // Read the source path.
                        for (i = 0; i < 260; i++)
                        {
                            pStream.Read(bytT, 1, ulRead);
                            pStream.Seek(0, 1, position);
                            filename[i] = (char)bytT[0];
                            if (bytT[0] == 0)
                            {
                                break;
                            }
                        }
                        // Source File path
                        string fullpath = new string(filename, 0, i);

                        // Unknown 4 bytes
                        pStream.Seek(4, 1, position);

                        // Next 4 byte gives the length of the temporary file path 
                        // (Office uses a temporary location to copy the files before inserting to the document)
                        // The length is in little endian format. Hence conversion is needed
                        pStream.Read(bytT, 4, ulRead);
                        ulong dwSize, dwTemp;
                        dwSize = 0;
                        dwTemp = (ulong)bytT[3];
                        dwSize += (ulong)(bytT[3] << 24);
                        dwSize += (ulong)(bytT[2] << 16);
                        dwSize += (ulong)(bytT[1] << 8);
                        dwSize += bytT[0];

                        // Skip the temporary file path
                        pStream.Seek((long)dwSize, 1, position);

                        // Next four bytes gives the size of the actual data in little endian format.
                        // Convert the format.
                        pStream.Read(bytT, 4, ulRead);
                        dwTemp = 0;
                        dwSize = 0;
                        dwTemp = (ulong)bytT[3];
                        dwSize += (ulong)(bytT[3] << 24);
                        dwSize += (ulong)(bytT[2] << 16);
                        dwSize += (ulong)(bytT[1] << 8);
                        dwSize += (ulong)bytT[0];

                        // Read the actual file content 
                        byte[] byData = new byte[dwSize];
                        pStream.Read(byData, (int)dwSize, ulRead);

                        // Create the file
                        var bWriter = new BinaryWriter(File.Open(Path.Combine(destinationFolder, path), FileMode.Create));
                        bWriter.Write(byData);
                        bWriter.Close();
                    }
                }
            }
            while (numReturned > 0);
        }
            void UnsafeNativeILockBytes.Stat(
                out System.Runtime.InteropServices.ComTypes.STATSTG pstatstg,
                int grfStatFlag )
            { 
                CheckDisposed();
 
                if ((grfStatFlag & ~(SafeNativeCompoundFileConstants.STATFLAG_NONAME | 
                                     SafeNativeCompoundFileConstants.STATFLAG_NOOPEN  )) != 0)
                { 
                    // validate grfStatFlag's value
                    throw new ArgumentException(SR.Get(SRID.InvalidArgumentValue, "grfStatFlag", grfStatFlag.ToString(CultureInfo.InvariantCulture)));
                }
 
                System.Runtime.InteropServices.ComTypes.STATSTG returnValue = new System.Runtime.InteropServices.ComTypes.STATSTG();
 
                returnValue.grfLocksSupported = 0 ; // No lock supported 

                returnValue.cbSize = _baseStream.Length; 
                returnValue.type = SafeNativeCompoundFileConstants.STGTY_LOCKBYTES;

                pstatstg = returnValue;
            } 
Exemplo n.º 39
0
 void IStream.Stat(out STATSTG pstatstg, int grfStatFlag) =>
 pstatstg = new STATSTG
 {
     cbSize = stream.Length, type = 2                                          /*STGTY_STREAM*/
 };
Exemplo n.º 40
0
 internal static int Stat(ref StreamDescriptor pSD, out System.Runtime.InteropServices.ComTypes.STATSTG statstg, uint grfStatFlag)
 {
     return((StreamAsIStream.FromSD(ref pSD)).Stat(out statstg, grfStatFlag));
 }
Exemplo n.º 41
0
        public static int V8DgnBreak(string fileName)
        {
            System.Runtime.InteropServices.ComTypes.STATSTG[] entry = new System.Runtime.InteropServices.ComTypes.STATSTG[1];
            uint numReturned;

            string[] typnam = { "STGTY_STORAGE", "STGTY_STREAM", "STGTY_LOCKBYTES", "STGTY_PROPERTY" };
            bool     v8Dgn  = false;

            StgOpenStorage(fileName, null, Stgm.Read | Stgm.ShareDenyWrite, IntPtr.Zero, 0, out IStorage storage);
            storage.EnumElements(0, IntPtr.Zero, 0, out IEnumSTATSTG pEnum);
            do
            {
                pEnum.Next(1, entry, out numReturned);

                if (numReturned != 0)
                {
                    switch (entry[0].type)
                    {
                    case (int)Stgty.StgtyStorage:
                        if (entry[0].pwcsName == "Dgn-Md")
                        {
                            v8Dgn = true;
                        }

                        break;

                    case (int)Stgty.StgtyStream:
                        break;

                    case (int)Stgty.StgtyLockbytes:
                        break;

                    case (int)Stgty.StgtyProperty:
                        break;
                    }
                }
            } while (numReturned > 0);

            Marshal.ReleaseComObject(pEnum);
            Marshal.ReleaseComObject(storage);
            GC.Collect();
            GC.Collect();  // call twice for good measure
            GC.WaitForPendingFinalizers();

            if (!v8Dgn)
            {
                return(MError);
            }

            StgOpenStorage(fileName, null, Stgm.Read | Stgm.ShareDenyWrite, IntPtr.Zero, 0, out storage);
            storage.EnumElements(0, IntPtr.Zero, 0, out pEnum);
            do
            {
                pEnum.Next(1, entry, out numReturned);
                if (numReturned != 0)
                {
                    Logger.Info("{0}, type={1}, size={2}", entry[0].pwcsName, typnam[entry[0].type - 1], entry[0].cbSize);
                    switch (entry[0].type)
                    {
                    case (int)Stgty.StgtyStorage:
                        V8RecurseStorage(storage, "", entry[0].pwcsName, 1);
                        break;

                    case (int)Stgty.StgtyStream:
                    {
                        string pwzStream = entry[0].pwcsName;
                        uint   cbSize    = (uint)entry[0].cbSize;
                        byte[] buf       = new byte[cbSize];
                        storage.OpenStream(entry[0].pwcsName, IntPtr.Zero, (uint)(Stgm.Read | Stgm.ShareExclusive), 0, out IStream stream);
                        stream.Read(buf, cbSize, out var cbRead);
                        pwzStream = pwzStream.Replace(Convert.ToChar(Convert.ToUInt32("0x05", 16)), '$').Replace('^', '_');
                        if (!pwzStream.StartsWith("$"))
                        {
                            V8DecodeAndWrite(pwzStream, buf, cbRead);
                        }
                        Marshal.ReleaseComObject(stream);
                    }
                    break;

                    case (int)Stgty.StgtyLockbytes:
                        break;

                    case (int)Stgty.StgtyProperty:
                        break;
                    }
                }
            } while (numReturned > 0);

            Marshal.ReleaseComObject(pEnum);
            Marshal.ReleaseComObject(storage);
            GC.Collect();
            GC.Collect();  // call twice for good measure
            GC.WaitForPendingFinalizers();

            return(MSuccess);
        }