Ejemplo n.º 1
0
 static protected void DetectFileTypes(ArcView file, List <Entry> dir)
 {
     byte[] signature_buffer = new byte[4];
     foreach (PackedEntry entry in dir)
     {
         uint packed_size   = file.View.ReadUInt32(entry.Offset);
         uint unpacked_size = file.View.ReadUInt32(entry.Offset + 4);
         if (0 == packed_size)
         {
             packed_size = unpacked_size;
         }
         entry.IsPacked     = packed_size != unpacked_size;
         entry.Size         = packed_size;
         entry.UnpackedSize = unpacked_size;
         entry.Offset      += 8;
         uint signature;
         if (entry.IsPacked)
         {
             using (var input = file.CreateStream(entry.Offset, Math.Min(packed_size, 0x20u)))
                 using (var reader = new ShsCompression(input))
                 {
                     reader.Unpack(signature_buffer);
                     signature = LittleEndian.ToUInt32(signature_buffer, 0);
                 }
         }
         else
         {
             signature = file.View.ReadUInt32(entry.Offset);
         }
         if (0 != signature)
         {
             IResource res;
             if (0x4D42 == (signature & 0xFFFF))
             {
                 res = ImageFormat.Bmp;
             }
             else if (0x020000 == signature || 0x0A0000 == signature)
             {
                 res = ImageFormat.Tga;
             }
             else
             {
                 res = FormatCatalog.Instance.LookupSignature(signature).FirstOrDefault();
             }
             if (res != null)
             {
                 entry.Type = res.Type;
                 var ext = res.Extensions.FirstOrDefault();
                 if (!string.IsNullOrEmpty(ext))
                 {
                     entry.Name = Path.ChangeExtension(entry.Name, ext);
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 static protected void DetectFileTypes(ArcView file, List <Entry> dir)
 {
     byte[] signature_buffer = new byte[4];
     foreach (PackedEntry entry in dir)
     {
         uint packed_size   = file.View.ReadUInt32(entry.Offset);
         uint unpacked_size = file.View.ReadUInt32(entry.Offset + 4);
         entry.IsPacked = 0 != packed_size;
         if (!entry.IsPacked)
         {
             packed_size = unpacked_size;
         }
         entry.Size         = packed_size;
         entry.UnpackedSize = unpacked_size;
         entry.Offset      += 8;
         uint signature;
         if (entry.IsPacked)
         {
             using (var input = file.CreateStream(entry.Offset, Math.Min(packed_size, 0x20u)))
                 using (var reader = new ShsCompression(input))
                 {
                     reader.Unpack(signature_buffer);
                     signature = LittleEndian.ToUInt32(signature_buffer, 0);
                 }
         }
         else
         {
             signature = file.View.ReadUInt32(entry.Offset);
         }
         if (0 != signature)
         {
             IResource res;
             if (0x020000 == signature || 0x0A0000 == signature)
             {
                 res = ImageFormat.Tga;
             }
             else
             {
                 res = AutoEntry.DetectFileType(signature);
             }
             if (res != null)
             {
                 entry.ChangeType(res);
             }
         }
     }
 }
Ejemplo n.º 3
0
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            var input = arc.File.CreateStream(entry.Offset, entry.Size, entry.Name);
            var pent  = entry as PackedEntry;

            if (null == pent || !pent.IsPacked)
            {
                return(input);
            }
            var data = new byte[pent.UnpackedSize];

            using (var reader = new ShsCompression(input))
            {
                reader.Unpack(data);
                return(new BinMemoryStream(data, entry.Name));
            }
        }
Ejemplo n.º 4
0
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            var input = base.OpenEntry(arc, entry);
            var pent  = entry as PackedEntry;

            if (null == pent || !pent.IsPacked)
            {
                return(input);
            }
            var data = new byte[pent.UnpackedSize];

            using (var reader = new ShsCompression(input))
            {
                reader.Unpack(data);
                return(new MemoryStream(data));
            }
        }
Ejemplo n.º 5
0
 public override Stream OpenEntry(ArcFile arc, Entry entry)
 {
     var input = base.OpenEntry (arc, entry);
     var pent = entry as PackedEntry;
     if (null == pent || !pent.IsPacked)
         return input;
     var data = new byte[pent.UnpackedSize];
     using (var reader = new ShsCompression (input))
     {
         reader.Unpack (data);
         return new MemoryStream (data);
     }
 }
Ejemplo n.º 6
0
 protected static void DetectFileTypes(ArcView file, List<Entry> dir)
 {
     byte[] signature_buffer = new byte[4];
     foreach (PackedEntry entry in dir)
     {
         uint packed_size   = file.View.ReadUInt32 (entry.Offset);
         uint unpacked_size = file.View.ReadUInt32 (entry.Offset+4);
         if (0 == packed_size)
             packed_size = unpacked_size;
         entry.IsPacked = packed_size != unpacked_size;
         entry.Size = packed_size;
         entry.UnpackedSize = unpacked_size;
         entry.Offset += 8;
         uint signature;
         if (entry.IsPacked)
         {
             using (var input = file.CreateStream (entry.Offset, Math.Min (packed_size, 0x20u)))
             using (var reader = new ShsCompression (input))
             {
                 reader.Unpack (signature_buffer);
                 signature = LittleEndian.ToUInt32 (signature_buffer, 0);
             }
         }
         else
         {
             signature = file.View.ReadUInt32 (entry.Offset);
         }
         if (0 != signature)
         {
             IResource res;
             if (0x4D42 == (signature & 0xFFFF))
                 res = ImageFormat.Bmp;
             else if (0x020000 == signature || 0x0A0000 == signature)
                 res = ImageFormat.Tga;
             else
                 res = FormatCatalog.Instance.LookupSignature (signature).FirstOrDefault();
             if (res != null)
             {
                 entry.Type = res.Type;
                 var ext = res.Extensions.FirstOrDefault();
                 if (!string.IsNullOrEmpty (ext))
                     entry.Name = Path.ChangeExtension (entry.Name, ext);
             }
         }
     }
 }