public void InvalidFileShouldThrowException() { var badFile = Path.Combine(BadPath, @"CALC.EXE-3FBEF7FD.pf"); Action action = () => OleCf.LoadFile(badFile); action.Should().Throw<Exception>().WithMessage("Invalid signature!"); }
public void BaseTests() { foreach (var allPath in _allPaths) { foreach (var fname in Directory.GetFiles(allPath)) { Debug.WriteLine(fname); var o = OleCf.LoadFile(fname); o.Header.Should().NotBeNull(); Debug.WriteLine(o.Header); Debug.WriteLine($"Directory items. total: {o.Directory.Count}"); foreach (var directoryItem in o.Directory) { directoryItem.DirectoryName.Should().NotBeNullOrEmpty(); Debug.WriteLine( $"Name: {directoryItem.DirectoryName}, Size: {directoryItem.DirectorySize}, Type: {directoryItem.DirectoryType}"); } Debug.WriteLine(""); } } }
public void OneOff() { var o =OleCf.LoadFile(@"C:\Temp\f01b4d95cf55d32a.automaticDestinations-ms"); // var o =OleCf.LoadFile(@"C:\Temp\5f7b5f1e01b83767.automaticDestinations-ms"); var destList = o.Directory.SingleOrDefault(t => t.DirectoryName.ToLowerInvariant() == "destlist"); var foo = o.GetPayloadForDirectory(destList); Debug.WriteLine(o.Directory.Count); }
public void OneOff() { var o = OleCf.LoadFile(@"C:\Users\e\Desktop\testjl\5d696d521de238c3.automaticDestinations-ms"); var destList = o.Directory.SingleOrDefault(t => t.DirectoryName.ToLowerInvariant() == "destlist"); var foo = o.GetPayloadForDirectory(destList); Debug.WriteLine(o.Directory.Count); }
/// <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; } } }
/// <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; } } }