string DecryptName(byte[] name_buf, int name_length, TpRandom key) { for (int i = 0; i < name_length; ++i) { name_buf[i] ^= (byte)key.GetRand32(); } return(Encodings.cp932.GetString(name_buf, 0, name_length)); }
static IEnumerable <int> RandomSequence(int count, uint seed) { var tp = new TpRandom(seed); var order = Enumerable.Range(0, count).ToList <int>(); for (int i = 0; i < count; ++i) { int n = (int)(tp.GetRand32() % (uint)order.Count); yield return(order[n]); order.RemoveAt(n); } }
List <Entry> ReadIndex(ArcView file, uint base_offset, int count) { uint index_offset = base_offset + 0xA; var name_buffer = new byte[0x100]; var rnd = new TpRandom(0x75D6EE39u); var dir = new List <Entry> (count); for (int i = 0; i < count; ++i) { uint name_length = file.View.ReadUInt32(index_offset); index_offset += 4; if (0 == name_length || name_length > name_buffer.Length) { return(null); } if (name_length != file.View.Read(index_offset, name_buffer, 0, name_length)) { return(null); } index_offset += name_length; var name = DecryptName(name_buffer, (int)name_length, rnd); dir.Add(Create <VfEntry> (name)); } rnd.Reset(); long offset = base_offset + (file.View.ReadInt64(index_offset) ^ (int)rnd.GetRand32()); foreach (var entry in dir) { index_offset += 8; long next_offset = base_offset + (file.View.ReadInt64(index_offset) ^ (int)rnd.GetRand32()); entry.Offset = offset; entry.Size = (uint)(next_offset - offset); offset = next_offset; } index_offset += 8; foreach (VfEntry entry in dir) { byte flags = file.View.ReadByte(index_offset++); entry.IsPacked = 0 == flags || 3 == flags; entry.IsScrambled = 2 == flags || 3 == flags; } return(dir); }