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()); }
public unsafe void EnumStorage() { using (var cleaner = new TestFileCleaner()) { string path = cleaner.GetTestPath(); IStorage storage = (IStorage)Com.CreateStorage(path, InterfaceIds.IID_IStorage); IStream stream = storage.CreateStream("mystream", StorageMode.Create | StorageMode.ReadWrite | StorageMode.ShareExclusive); IStorage subStorage = storage.CreateStorage("substorage", StorageMode.Create | StorageMode.ReadWrite | StorageMode.ShareExclusive); storage.Commit(); IEnumSTATSTG e = storage.EnumElements(); WInterop.Com.STATSTG stat = default; int count = 0; while (e.Next(1, ref stat) > 0) { count++; switch (stat.type) { case StorageType.Storage: stat.GetAndFreeString().Should().Be("substorage"); break; case StorageType.Stream: stat.GetAndFreeString().Should().Be("mystream"); break; default: false.Should().BeTrue($"unexpected type {stat.type}"); break; } } count.Should().Be(2); } }
void IStorage.EnumElements( int reserved1, IntPtr reserved2, int reserved3, out IEnumSTATSTG ppEnum) { SecurityHelper.DemandCompoundFileIOPermission(); UnsafeNativeCompoundFileMethods.UnsafeNativeIEnumSTATSTG enumSTATSTG; _unsafeStorage.EnumElements( reserved1, reserved2, reserved3, out enumSTATSTG); if (enumSTATSTG != null) { ppEnum = new SafeIEnumSTATSTGImplementation(enumSTATSTG); } else { ppEnum = null; } }
private MemoryStream GetStreamFromPackage(IStorage storage, ExcelEncryption encryption) { MemoryStream ret = null; comTypes.STATSTG statstg; storage.Stat(out statstg, (uint)STATFLAG.STATFLAG_DEFAULT); IEnumSTATSTG pIEnumStatStg = null; storage.EnumElements(0, IntPtr.Zero, 0, out pIEnumStatStg); comTypes.STATSTG[] regelt = { statstg }; uint fetched = 0; uint res = pIEnumStatStg.Next(1, regelt, out fetched); //if (regelt[0].pwcsName == "DataSpaces") //{ // PrintStorage(storage, regelt[0],""); //} if (res == 0) { byte[] data; EncryptionInfo encryptionInfo = null; while (res != 1) { switch (statstg.pwcsName) { case "EncryptionInfo": data = GetOleStream(storage, statstg); //File.WriteAllBytes(@"c:\temp\EncInfo1.bin", data); encryptionInfo = new EncryptionInfo(); encryptionInfo.ReadBinary(data); encryption.Algorithm = encryptionInfo.Header.AlgID == AlgorithmID.AES128 ? EncryptionAlgorithm.AES128 : encryptionInfo.Header.AlgID == AlgorithmID.AES192 ? EncryptionAlgorithm.AES192 : EncryptionAlgorithm.AES256; break; case "EncryptedPackage": data = GetOleStream(storage, statstg); ret = DecryptDocument(data, encryptionInfo, encryption.Password); break; } if ((res = pIEnumStatStg.Next(1, regelt, out fetched)) != 1) { statstg = regelt[0]; } } } Marshal.ReleaseComObject(pIEnumStatStg); return(ret); }
// Methods internal StorageElementsCollection(IStorage storage) { StatStg tSSTG; IEnumSTATSTG oEnm = storage.EnumElements(0, 0, 0); Label_0027: var fetched = 0; if (oEnm.Next(1, out tSSTG, out fetched) == 0) { base.InnerList.Add(tSSTG); goto Label_0027; } Marshal.ReleaseComObject(oEnm); oEnm = null; }
void IEnumSTATSTG.Clone( out IEnumSTATSTG ppenum) { UnsafeNativeCompoundFileMethods.UnsafeNativeIEnumSTATSTG enumSTATSTG; _unsafeEnumSTATSTG.Clone( out enumSTATSTG); if (enumSTATSTG != null) { ppenum = new SafeIEnumSTATSTGImplementation(enumSTATSTG); } else { ppenum = null; } }
void IEnumSTATSTG.Clone( out IEnumSTATSTG ppenum) { SecurityHelper.DemandCompoundFileIOPermission(); UnsafeNativeCompoundFileMethods.UnsafeNativeIEnumSTATSTG enumSTATSTG; _unsafeEnumSTATSTG.Clone( out enumSTATSTG); if (enumSTATSTG != null) { ppenum = new SafeIEnumSTATSTGImplementation(enumSTATSTG); } else { ppenum = null; } }
private MemoryStream ReadParts(IStorage storage, StoragePart storagePart) { MemoryStream ret = null; comTypes.STATSTG statstg; storage.Stat(out statstg, (uint)STATFLAG.STATFLAG_DEFAULT); IEnumSTATSTG pIEnumStatStg = null; storage.EnumElements(0, IntPtr.Zero, 0, out pIEnumStatStg); comTypes.STATSTG[] regelt = { statstg }; uint fetched = 0; uint res = pIEnumStatStg.Next(1, regelt, out fetched); //if (regelt[0].pwcsName == "DataSpaces") //{ // PrintStorage(storage, regelt[0],""); //} while (res != 1) { foreach (var item in regelt) { if (item.type == 1) { IStorage subStorage; storage.OpenStorage(item.pwcsName, null, STGM.DIRECT | STGM.READ | STGM.SHARE_EXCLUSIVE, IntPtr.Zero, 0, out subStorage); StoragePart subStoragePart = new StoragePart(); storagePart.SubStorage.Add(item.pwcsName, subStoragePart); ReadParts(subStorage, subStoragePart); } else { storagePart.DataStreams.Add(item.pwcsName, GetOleStream(storage, item)); } } res = pIEnumStatStg.Next(1, regelt, out fetched); } Marshal.ReleaseComObject(pIEnumStatStg); return(ret); }
private IEnumerable <System.Runtime.InteropServices.ComTypes.STATSTG> EnumElements() { IEnumSTATSTG ssenum = null; Storage.EnumElements(0, IntPtr.Zero, 0, out ssenum); var ssstruct = new System.Runtime.InteropServices.ComTypes.STATSTG[1]; uint numReturned; do { ssenum.Next(1, ssstruct, out numReturned); if (numReturned != 0) { yield return(ssstruct[0]); } } while (numReturned > 0); }
public void EnumElements(uint reserved1, IntPtr reserved2, uint reserved3, out IEnumSTATSTG ppEnum) { _stg.EnumElements(reserved1, reserved2, reserved3, out ppEnum); }
public void EnumElements(uint reserved1, IntPtr reserved2, uint reserved3, out IEnumSTATSTG ppEnum) { _stg.EnumElements(reserved1, reserved2, reserved3, out ppEnum); }
internal static void FinalRelease(this IEnumSTATSTG enumerator) { Marshal.FinalReleaseComObject(enumerator); }
void IStorage.EnumElements( int reserved1, IntPtr reserved2, int reserved3, out IEnumSTATSTG ppEnum ) { SecurityHelper.DemandCompoundFileIOPermission(); UnsafeNativeCompoundFileMethods.UnsafeNativeIEnumSTATSTG enumSTATSTG; _unsafeStorage.EnumElements( reserved1, reserved2, reserved3, out enumSTATSTG); if (enumSTATSTG != null) ppEnum = new SafeIEnumSTATSTGImplementation(enumSTATSTG); else ppEnum = null; }
void IEnumSTATSTG.Clone( out IEnumSTATSTG ppenum ) { SecurityHelper.DemandCompoundFileIOPermission(); UnsafeNativeCompoundFileMethods.UnsafeNativeIEnumSTATSTG enumSTATSTG; _unsafeEnumSTATSTG.Clone( out enumSTATSTG ); if (enumSTATSTG != null) ppenum = new SafeIEnumSTATSTGImplementation(enumSTATSTG); else ppenum = null; }
public static void OpenAndExtractStorages(string filename, string dir) { IStorage rootStorage = null; int hresult = Ole32.StgOpenStorage(filename, null, STGM.STGM_READ | STGM.STGM_SHARE_EXCLUSIVE, IntPtr.Zero, 0, out rootStorage); if ((hresult == S_OK) && (rootStorage != null)) { if (IsPatch(rootStorage)) { try { IEnumSTATSTG rootStorageEnum = null; rootStorage.EnumElements(0, IntPtr.Zero, 0, out rootStorageEnum); STATSTG[] enumStg = new STATSTG[] { new STATSTG() }; uint numFetched = 0; rootStorageEnum.Next(1, enumStg, out numFetched); while (numFetched == 1) { if (enumStg[0].type == (uint)STGTY.STGTY_STORAGE) { // Save the nested transform storages with an .mst extension SaveStorage(rootStorage, dir, enumStg[0].pwcsName, ".mst"); } rootStorageEnum.Next(1, enumStg, out numFetched); } if (enumStg != null) { Marshal.ReleaseComObject(rootStorageEnum); } if (rootStorage != null) { Marshal.ReleaseComObject(rootStorage); } using (Database installDatabase = new Database(filename, DatabaseOpenMode.ReadOnly)) using (View view = installDatabase.OpenView("SELECT `Name`, `Data` FROM `_Streams`")) { view.Execute(); foreach (Record record in view) { SaveStream(record, dir); record.Close(); } } } finally { if (rootStorage != null) { Marshal.ReleaseComObject(rootStorage); } } } } }
unsafe public int EnumElements(uint p1, void *p2, uint p3, out IEnumSTATSTG enm) { enm = new XPBurnEnumStorageElements(this); return(CONSTS.S_OK); }
static void Main(string[] args) { string filename = @"f:\temp\treta2.msg"; if (StgIsStorageFile(filename) == 0) { IStorage storage = null; if (StgOpenStorage( filename, null, STGM.DIRECT | STGM.READ | STGM.SHARE_EXCLUSIVE, IntPtr.Zero, 0, out storage) == 0) { System.Runtime.InteropServices.ComTypes.STATSTG statstg; storage.Stat(out statstg, (uint)STATFLAG.STATFLAG_DEFAULT); IEnumSTATSTG pIEnumStatStg = null; storage.EnumElements(0, IntPtr.Zero, 0, out pIEnumStatStg); System.Runtime.InteropServices.ComTypes.STATSTG[] regelt = { statstg }; uint fetched = 0; uint res = pIEnumStatStg.Next(1, regelt, out fetched); if (res == 0) { while (res != 1) { string strNode = statstg.pwcsName; bool bNodeFound = false; Console.WriteLine(strNode); if (strNode == "__substg1.0_0E04001E" || strNode == "__substg1.0_0E1D001E" || strNode == "__substg1.0_1000001E" || strNode == "__substg1.0_1013001E") { bNodeFound = true; } if (bNodeFound) { switch (statstg.type) { case (int)STGTY.STGTY_STORAGE: { IStorage pIChildStorage; storage.OpenStorage(statstg.pwcsName, null, (uint)(STGM.READ | STGM.SHARE_EXCLUSIVE), IntPtr.Zero, 0, out pIChildStorage); } break; case (int)STGTY.STGTY_STREAM: { IStream pIStream; storage.OpenStream(statstg.pwcsName, IntPtr.Zero, (uint)(STGM.READ | STGM.SHARE_EXCLUSIVE), 0, out pIStream); byte[] data = new byte[255]; pIStream.Read(data, 255, IntPtr.Zero); } break; } } res = pIEnumStatStg.Next(1, regelt, out fetched); } } } } Console.ReadLine(); }
int IStorage.EnumElements(uint reserved1, IntPtr reserved2, uint reserved3, out IEnumSTATSTG ppEnum) { return(_storage.EnumElements(reserved1, reserved2, reserved3, out ppEnum)); }
public static List <string> GetUsers(string filename) { List <string> users = new List <string>(); if (StgIsStorageFile(filename) == 0) { IStorage storage = null; if (StgOpenStorage( filename, null, STGM.DIRECT | STGM.READ | STGM.SHARE_EXCLUSIVE, IntPtr.Zero, 0, out storage) == 0) { System.Runtime.InteropServices.ComTypes.STATSTG statstg; storage.Stat(out statstg, (uint)STATFLAG.STATFLAG_DEFAULT); IEnumSTATSTG pIEnumStatStg = null; storage.EnumElements(0, IntPtr.Zero, 0, out pIEnumStatStg); System.Runtime.InteropServices.ComTypes.STATSTG[] regelt = { statstg }; uint fetched = 0; uint res = pIEnumStatStg.Next(1, regelt, out fetched); if (res == 0) { while (res != 1) { string strNode = statstg.pwcsName; bool bNodeFound = false; if (strNode.IndexOf("Container.Contents") != -1) { bNodeFound = true; } if (bNodeFound) { switch (statstg.type) { case (int)STGTY.STGTY_STORAGE: { IStorage pIChildStorage; storage.OpenStorage(statstg.pwcsName, null, (uint)(STGM.READ | STGM.SHARE_EXCLUSIVE), IntPtr.Zero, 0, out pIChildStorage); } break; case (int)STGTY.STGTY_STREAM: { IStream pIStream; storage.OpenStream(statstg.pwcsName, IntPtr.Zero, (uint)(STGM.READ | STGM.SHARE_EXCLUSIVE), 0, out pIStream); if (statstg.cbSize > 0) { byte[] data = new byte[statstg.cbSize]; pIStream.Read(data, (int)statstg.cbSize, IntPtr.Zero); Encoding en = Encoding.Default; string tmpStr = en.GetString(data); int pos = tmpStr.IndexOf("Page"); while (pos > 0) { tmpStr = tmpStr.Remove(0, pos); pos = tmpStr.IndexOf(",\""); if (pos > 0) { tmpStr = tmpStr.Remove(0, pos + 2); users.Add(tmpStr.Substring(0, tmpStr.IndexOf('"'))); } pos = tmpStr.IndexOf("Page"); } } pIStream = null; } break; } } if ((res = pIEnumStatStg.Next(1, regelt, out fetched)) != 1) { statstg = regelt[0]; } } storage = null; } } } return(users); }