public DscDecoder(ArcView.Frame input) : base(new ArcViewStream(input, input.Offset + 0x20, input.Reserved - 0x20)) { m_magic = (uint)input.ReadUInt16(input.Offset) << 16; m_key = input.ReadUInt32(input.Offset + 0x10); m_dst_size = input.ReadUInt32(input.Offset + 0x14); m_dec_count = input.ReadUInt32(input.Offset + 0x18); m_output = new byte[m_dst_size]; }
public bool ReadIndex(string root, long base_offset, uint size) { uint signature = m_view.ReadUInt32(base_offset); if (0x0042494C != signature) { return(false); } int count = m_view.ReadInt16(base_offset + 8); if (count <= 0) { return(false); } long index_offset = base_offset + 0x10; uint index_size = (uint)(0x30 * count); if (index_size > size) { return(false); } if (index_size > m_view.Reserve(index_offset, index_size)) { return(false); } long data_offset = index_offset + index_size; if (m_dir.Capacity < m_dir.Count + count) { m_dir.Capacity = m_dir.Count + count; } for (int i = 0; i < count; ++i) { string name = m_view.ReadString(index_offset, 0x24); uint entry_size = m_view.ReadUInt32(index_offset + 0x24); long offset = base_offset + m_view.ReadUInt32(index_offset + 0x28); index_offset += 0x30; string ext = Path.GetExtension(name); name = Path.Combine(root, name); if (string.IsNullOrEmpty(ext) && ReadIndex(name, offset, entry_size)) { continue; } if (offset < data_offset || offset + entry_size > base_offset + size) { return(false); } var entry = FormatCatalog.Instance.Create <Entry> (name); entry.Offset = offset; entry.Size = entry_size; m_dir.Add(entry); } return(true); }
static byte[] ReadBlock(ArcView.Frame view, INekoFormat enc, long offset, out int length) { uint hash = view.ReadUInt32(offset); length = view.ReadInt32(offset + 4); int aligned_size = (length + 7) & ~7; byte[] buffer = new byte[aligned_size]; length = view.Read(offset + 8, buffer, 0, (uint)length); if (0 != hash) { enc.Decrypt(hash, buffer, 0, aligned_size); } return(buffer); }
static byte[] ReadBlock(ArcView.Frame view, INekoEncryption enc, long offset, out int length) { uint hash = view.ReadUInt32(offset); length = view.ReadInt32(offset + 4); // parity check // if (CalcParity (((NekoEncryption32bit)enc).Parity, (uint)length) != hash) // throw new InvalidFormatException(); int aligned_size = (length + 7) & ~7; byte[] buffer = new byte[aligned_size]; length = view.Read(offset + 8, buffer, 0, (uint)length); if (0 != hash) { enc.Decrypt(hash, buffer, 0, aligned_size); } return(buffer); }