如何解码未知的二进制图像编码?

时间:2013-10-31 20:33:40

标签: c# svg base64 gzip reverse-engineering

我有包含SVG图像的XML文件。图像用base64编码,可能是gzip(根据制造商的说法)。

内容是这样的

<Image ID="ID_IMG57" ElementID="ID_IMG57" PMD="svg" X="1281" Y="370" ZIndex="-2" 
      W="36" H="56" MirrorX="False" MirrorY="False" Angle="0" ViewID="" Locked="False" 
      PlacementAngle="-360" PlacementX="1" PlacementY="27" PlacementScale="0" 
      Format="image/svg+base64" IncludeRelevantModules="True">
   <ImageValue>7b0HYBxJliUmL23Ke39K9UrX4HShCIBgEyTYkEAQ7MGIzeaS7B1pRyMpqyqBymVWZV1mFkDM7Z28995777333nvvvfe6O51OJ/ff/z9cZmQBbPbOStrJniGAqsgfP358Hz8iHjeXF2l6WeRXT6p3n320vTvevb+7d+9hur33YLz74MH9g/Te/fEBPkvv3x8/eLj36d5H6VUxa+effbS7s/O7f5TO8+Ji3pq/3i3KZfPZR/O2XT26e/fq6mp8dW9c1Rd393Z2du5Sbx8dPV43eZpOy6yhhpPVSl969K4slm9jr+4+fPjwLn9LTfHj0bzOzz/7iP767KOd8d4e4fzpR+k14b8zvndw/+Dhg4/Su0ePqSl19G4XjXb39u8dUBv6Y3vvUxkavb/H78iY6Vv6c+/+eOfT+/u7H6VNe13mn33UtHX1Nn/04zv8HKby9zbT4NHuYXpelOWjZbXMDz8K+twb7+083Lu3q53uPhjfu0cdSae7u+P7e/t7B9Kn9+XX6nRVldfS8aoqli2R9R5N1ac0baPt3YPx/t7Op/dS6nH33u6DhyP0tn9vZ28/vTf+FGP9lD76lD56ePDp10TAjXp3fEA88uk9GTWBfbC78+mndtB7Ow8e7Mmg3Xdfq8vYmO8TEe/tj3bvjz+9f49Yl/rbf7j/6e6I+vqUxveARnyPqL53MCIafHpv/979r9l7m79rU7AfjZc4afchs98eU3GnB5RfEwgW/nm1bLeb4gf5o/3VO/3zPFsU5fWj47rIysMUfWxny+m8qh81bVa3hx8dPSmL6du6mM7b9fLi8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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
   </ImageValue>
   <ImageAttributes>
       <ImageAttribute Name="FileNameSVG" Value="Blickrichtung1.svg" Source="User" />
   </ImageAttributes>
</Image>

实际的图片位于ImageValue元素中。但我无法将其提取出来。我试过了

byte[] compressed = Convert.FromBase64String(image.Value);
using (GZipStream stream = new GZipStream(new MemoryStream(compressed),
                                                     CompressionMode.Decompress))
{
     const int size = 4096;
     byte[] buffer = new byte[size];
     using (MemoryStream memory = new MemoryStream())  {
         int count = 0;
         do {
             count = stream.Read(buffer, 0, size);
             if (count > 0) {
                 memory.Write(buffer, 0, count);
             }
         }
         while (count > 0)
         File.WriteAllBytes(@"Blickrichtung1.svg", memory.ToArray());
     }
}

但图像没有显示任何内容。我如何确定这背后的格式?

我也尝试过base64解码并将数据保存到文件中。我希望我会在二进制文件中看到类似文件类型但没有运气的东西。

1 个答案:

答案 0 :(得分:1)

如怀疑@BigBadaboom,它是一个Deflated流。以下内容在svg中生成可读的XML。

    string svg;
    using (var stream = new DeflateStream(new MemoryStream(compressed),  
        CompressionMode.Decompress))
    {
        using (MemoryStream memory = new MemoryStream())
        {
            stream.CopyTo(memory);
            byte[] decompressed = memory.GetBuffer();
            svg = Encoding.UTF8.GetString(decompressed);  
        }     
    }