Ejemplo n.º 1
0
        /// <summary>
        /// Extracts a OLE v1.0 object from the given <paramref name="stream"/>
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="outputFolder">The output folder</param>
        internal static string ExtractOle10(Stream stream, string outputFolder)
        {
            var ole10 = new Ole10(stream);

            if (ole10.Format != OleFormat.File) return null;
            
            switch (ole10.ClassName)
            {
                case "Package":
                    var package = new Package(ole10.NativeData);
                    if (package.Format == OleFormat.Link) return null;

                    var fileName = Path.GetFileName(package.FileName);
                    if (string.IsNullOrWhiteSpace(fileName))
                        fileName = Extraction.DefaultEmbeddedObjectName;

                    fileName = Path.Combine(outputFolder, fileName);
                    return Extraction.SaveByteArrayToFile(package.Data, fileName);

                default:
                    if (Extraction.IsCompoundFile(ole10.NativeData))
                        return Extraction.SaveFromStorageNode(ole10.NativeData, outputFolder, ole10.ItemName);

                    throw new OEObjectTypeNotSupported("Unsupported OleNative ClassName '" +
                                                       ole10.ClassName + "' found");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Creates this object and sets all its properties
        /// </summary>
        /// <param name="storage">The OLE version 2.0 object as a <see cref="CFStorage" /></param>
        internal Ole10Native(CFStorage storage)
        {
            if (storage == null)
                throw new ArgumentNullException("storage");

            var ole10Native = storage.GetStream("\x0001Ole10Native");
            var compObj = storage.GetStream("\x0001CompObj");
            var compObjStream = new CompObjStream(compObj);

            AnsiUserType = compObjStream.AnsiUserType;
            StringFormat = compObjStream.StringFormat;
            ClipboardFormat = compObjStream.ClipboardFormat;

            switch (compObjStream.AnsiUserType)
            {
                case "OLE Package":
                    var ole10NativeSize = (int) ole10Native.Size - 4;
                    var data = ole10Native.GetData(4, ref ole10NativeSize);
                    var package = new Package(data);
                    Format = package.Format;
                    FileName = Path.GetFileName(package.FileName);
                    FilePath = package.FilePath;
                    NativeData = package.Data;
                    break;

                case "PBrush":
                case "Pakket":
                    // Ignore
                    break;

                default:
                    throw new OEObjectTypeNotSupported("Unsupported OleNative AnsiUserType '" +
                                                        compObjStream.AnsiUserType + "' found");
            }
        }