Пример #1
0
 private void Parse()
 {
     _r.Seek(0);
     if (_r.PeekFor(() => _r.ReadWZStringBlock(true)) == "Property")
     {
         _encrypted = true;
     }
     else if (_r.PeekFor(() => _r.ReadWZStringBlock(false)) == "Property")
     {
         _encrypted = false;
     }
     else
     {
         WZUtil.Die("Failed to determine image encryption!");
     }
     _r.SkipWZStringBlock();
     if (_r.ReadUInt16() != 0)
     {
         WZUtil.Die("WZImage with invalid header (no zero UInt16!)");
     }
     foreach (WZObject child in WZExtendedParser.ParsePropertyList(_r, this, this, _encrypted))
     {
         Add(child);
     }
     _parsed = true;
 }
Пример #2
0
 internal WZSubProperty(string name, WZObject parent, WZBinaryReader r, WZImage container)
     : base(name, parent, default(WZNothing), container, true, WZObjectType.SubProperty)
 {
     foreach (WZObject c in WZExtendedParser.ParsePropertyList(r, this, Image, Image._encrypted))
     {
         Add(c);
     }
 }
Пример #3
0
        internal WZConvexProperty(string name, WZObject parent, WZBinaryReader r, WZImage container)
            : base(name, parent, default(WZNothing), container, true, WZObjectType.Convex)
        {
            int count = r.ReadWZInt();

            for (int i = 0; i < count; ++i)
            {
                Add(WZExtendedParser.ParseExtendedProperty(i.ToString(CultureInfo.InvariantCulture), r, this, Image,
                                                           Image._encrypted));
            }
        }
Пример #4
0
        internal override bool Parse(WZBinaryReader br, bool initial, out Bitmap result)
        {
            bool skip  = (File._flag & WZReadSelection.NeverParseCanvas) == WZReadSelection.NeverParseCanvas,
                 eager = (File._flag & WZReadSelection.EagerParseCanvas) == WZReadSelection.EagerParseCanvas;

            if (initial)
            {
                if (skip && eager)
                {
                    result = null;
                    return(WZUtil.Die <bool>("Both NeverParseCanvas and EagerParseCanvas are set."));
                }
                br.Skip(1);
                if (br.ReadByte() == 1)
                {
                    br.Skip(2);
                    List <WZObject> l = WZExtendedParser.ParsePropertyList(br, this, Image, Image._encrypted);
                    if (ChildCount == 0)
                    {
                        l.ForEach(Add);
                    }
                }
                _afterChildren = br.Position;
            }
            else
            {
                br.Position = _afterChildren;
            }
            int width   = br.ReadWZInt(); // width
            int height  = br.ReadWZInt(); // height
            int format1 = br.ReadWZInt(); // format 1
            int scale   = br.ReadByte();  // format 2

            br.Skip(4);
            int blockLen = br.ReadInt32();

            if ((initial || skip) && !eager)
            {
                br.Skip(blockLen); // block Len & png data
                result = null;
                return(skip);
            }
            else
            {
                br.Skip(1);
                byte[] header = br.ReadBytes(2);
                // FLG bit 5 indicates the presence of a preset dictionary
                // seems like MS doesn't use that?
                if ((header[1] & 0x20) != 0)
                {
                    Debug.WriteLine("Warning; zlib with preset dictionary");
                    result = null;
                    br.Skip(blockLen - 3);
                    return(true);
                }
                // zlib header: CMF (byte), FLG (byte)
                byte[] pngData = br.ReadBytes(blockLen - 3);
                result = ParsePNG(width, height, format1, scale,
                                  // CMF least significant bits 0 to 3 are compression method. only 8 is valid
                                  (header[0] & 0xF) != 8 ||
                                  // CMF << 8 | FLG i.e. header read as a big-endian short is a multiple of 31
                                  (header[0] << 8 | header[1]) % 31 != 0
                        ? DecryptPNG(pngData)
                        : pngData);
                return(true);
            }
        }