public CASEntry ReadEntry(uint offset, uint size_) { CASEntry result = new CASEntry(); MemoryStream s = new MemoryStream(ReadBlock(offset - 0x20, size_ + 0x20)); result.magic = Tools.ReadUInt(s); result.SHA1 = new byte[20]; s.Read(result.SHA1, 0, 20); result.datasize = Tools.ReadUInt(s); result.padding = Tools.ReadUInt(s); long totalread = 0; MemoryStream res = new MemoryStream(); while (totalread < result.datasize) { int ucsize = Tools.ReadLEInt(s); int csize = Tools.ReadLEInt(s); totalread += 8; int size = csize & 0xFFFF; int type = (int)((csize & 0xFFFF0000) >> 16); if (type == 0x270) { byte[] buff = new byte[size]; s.Read(buff, 0, size); byte[] r = Tools.DecompressZlib(buff, ucsize); res.Write(r, 0, r.Length); totalread += size; } else { byte[] buff = new byte[size]; s.Read(buff, 0, size); res.Write(buff, 0, size); totalread += size; } } result.data = res.ToArray(); byte[] buf = new byte[s.Length - 0x20]; s.Seek(0x20, 0); s.Read(buf, 0, (int)(s.Length - 0x20)); result.compressed = buf; return(result); }
public CASEntry ReadEntry(uint offset, uint size_, int maxsize) { CASEntry result = new CASEntry(); MemoryStream s = new MemoryStream(ReadBlock(offset - 0x20, size_ + 0x20)); result.magic = Helpers.ReadUInt(s); result.SHA1 = new byte[20]; s.Read(result.SHA1, 0, 20); result.datasize = Helpers.ReadUInt(s); result.padding = Helpers.ReadUInt(s); long totalread = 0; MemoryStream res = new MemoryStream(); while (totalread < result.datasize && totalread < maxsize && totalread < size_) { int ucsize = Helpers.ReadLEInt(s); int csize = Helpers.ReadLEInt(s); totalread += 8; int size = csize & 0xFFFF; int type = (int)(csize >> 16); if (type == 0x270) { byte[] buff = new byte[size]; s.Read(buff, 0, size); byte[] r = Helpers.DecompressZlib(buff, ucsize); res.Write(r, 0, r.Length); totalread += size; } else { byte[] buff = new byte[size]; s.Read(buff, 0, size); res.Write(buff, 0, size); totalread += size; } } result.data = res.ToArray(); return result; }