Пример #1
0
        internal static int SafeStgOpenStorageOnStream(
            Stream s,
            int grfMode,
            out IStorage ppstgOpen
            )
        {
            Invariant.Assert(s != null, "s cannot be null");

            UnsafeNativeCompoundFileMethods.UnsafeNativeIStorage    storage;
            UnsafeNativeCompoundFileMethods.UnsafeLockBytesOnStream lockByteStream = new UnsafeNativeCompoundFileMethods.UnsafeLockBytesOnStream(s);
            int result;

            result = UnsafeNativeCompoundFileMethods.StgOpenStorageOnILockBytes(
                (UnsafeNativeCompoundFileMethods.UnsafeNativeILockBytes)lockByteStream,
                null,
                grfMode,
                new IntPtr(0), // Pointer to SNB struct, not marshalled, must be null.
                0,
                out storage);

            if (result == SafeNativeCompoundFileConstants.S_OK)
            {
                ppstgOpen = new SafeIStorageImplementation(storage);
            }
            else
            {
                ppstgOpen = null;
                lockByteStream.Dispose();
            }

            return(result);
        }
Пример #2
0
        internal static int SafeStgOpenStorageEx(
            string pwcsName,          //Pointer to path of compound file to create
            int grfMode,              // Specifies the access mode for opening the storage object
            int stgfmt,               // Specifies the storage file format, 5 is DocFile
            int grfAttrs,             // Reserved; must be zero
            IntPtr pStgOptions,       // Pointer to STGOPTIONS, not marshalled, must use NULL.
            IntPtr reserved2,         // Reserved; must be null
            ref Guid riid,            // Specifies the GUID of the interface pointer
            out IStorage ppObjectOpen //Pointer to an interface pointer
            )
        {
            UnsafeNativeCompoundFileMethods.UnsafeNativeIStorage storage;
            int result;

            result = UnsafeNativeCompoundFileMethods.StgOpenStorageEx(
                pwcsName,
                grfMode,
                stgfmt,
                grfAttrs,
                pStgOptions,
                reserved2,
                ref riid,
                out storage);

            if (result == SafeNativeCompoundFileConstants.S_OK)
            {
                ppObjectOpen = new SafeIStorageImplementation(storage);
            }
            else
            {
                ppObjectOpen = null;
            }

            return(result);
        }
Пример #3
0
        internal static int SafeStgCreateDocfileOnStream(
            Stream s,
            int grfMode,
            out IStorage ppstgOpen
            )
        {
            Invariant.Assert(s != null, "s cannot be null");

            UnsafeNativeCompoundFileMethods.UnsafeNativeIStorage    storage;
            UnsafeNativeCompoundFileMethods.UnsafeLockBytesOnStream lockByteStream = new UnsafeNativeCompoundFileMethods.UnsafeLockBytesOnStream(s);
            int result;

            result = UnsafeNativeCompoundFileMethods.StgCreateDocfileOnILockBytes(
                (UnsafeNativeCompoundFileMethods.UnsafeNativeILockBytes)lockByteStream,
                grfMode,
                0, // Must be zero
                out storage);

            if (result == SafeNativeCompoundFileConstants.S_OK)
            {
                ppstgOpen = new SafeIStorageImplementation(storage, lockByteStream);
            }
            else
            {
                ppstgOpen = null;
                lockByteStream.Dispose();
            }

            return(result);
        }
Пример #4
0
 internal static int SafePropVariantClear(ref PROPVARIANT pvar)
 {
     return(UnsafeNativeCompoundFileMethods.PropVariantClear(ref pvar));
 }
Пример #5
0
 internal SafeIPropertyStorageImplementation(UnsafeNativeCompoundFileMethods.UnsafeNativeIPropertyStorage propertyStorage)
 {
     _unsafePropertyStorage = propertyStorage;
 }
Пример #6
0
 internal SafeIEnumSTATPROPSETSTGImplementation(UnsafeNativeCompoundFileMethods.UnsafeNativeIEnumSTATPROPSETSTG enumSTATPROPSETSTG)
 {
     _unsafeEnumSTATPROPSETSTG = enumSTATPROPSETSTG;
 }
Пример #7
0
 internal SafeIStreamImplementation(UnsafeNativeCompoundFileMethods.UnsafeNativeIStream stream)
 {
     _unsafeStream = stream;
 }
Пример #8
0
            internal SafeIStorageImplementation(UnsafeNativeCompoundFileMethods.UnsafeNativeIStorage storage,
                                                        UnsafeNativeCompoundFileMethods.UnsafeLockBytesOnStream lockBytesStream)
            {
                SecurityHelper.DemandCompoundFileIOPermission();

                if (storage == null)
                {
                    throw new ArgumentNullException("storage");
                }

                _unsafeStorage = storage;
                _unsafePropertySetStorage = (UnsafeNativeCompoundFileMethods.UnsafeNativeIPropertySetStorage) _unsafeStorage;
                _unsafeLockByteStream = lockBytesStream;
            }
Пример #9
0
 internal SafeIStorageImplementation(UnsafeNativeCompoundFileMethods.UnsafeNativeIStorage storage)
         : this(storage, null)
 {
 }
Пример #10
0
        // <SecurityNote>
        //     Critical:  This method calls security suppressed unmanaged CompoundFile code.
        //     ComoundFileIOPermission needs to be demanded to ensure that the only calls
        //     that can go through must be either done in Full Trust or with under assertion of
        //     CompoundFileIOPermission.
        //     SecurityTreatAsSafe:  Demands CompoundFileIOPermission before it makes any calls to
        //      unmanaged APIs
        // </SecurityNote>
        internal static int SafePropVariantClear(ref PROPVARIANT pvar)
        {
            SecurityHelper.DemandCompoundFileIOPermission();

            return(UnsafeNativeCompoundFileMethods.PropVariantClear(ref pvar));
        }