internal static DARC analyze(string path) { DARC darc = new DARC { FileName = Path.GetFileNameWithoutExtension(path), FilePath = Path.GetDirectoryName(path), Extension = Path.GetExtension(path) }; using (BinaryReader br = new BinaryReader(File.OpenRead(path))) { long len = br.BaseStream.Length; darc.Magic = br.ReadUInt32(); UInt32 m = darc.Magic; darc.HeaderOffset = 0; while (m != 0x63726164 && darc.HeaderOffset < len - 4) { m = br.ReadUInt32(); darc.HeaderOffset += 4; } if (darc.HeaderOffset >= len - 4) { darc.valid = false; return darc; } darc.Magic = m; darc.valid = true; darc.BOM = br.ReadUInt16(); darc.HeaderLength = br.ReadUInt16(); darc.Unknown = br.ReadUInt32(); darc.totalLength = br.ReadUInt32(); darc.TableOffset = br.ReadUInt32(); //from start of file darc.TableOffset += darc.HeaderOffset; darc.TableLength = br.ReadUInt32(); darc.DataOffset = br.ReadUInt32(); FileTable ft = new FileTable(); br.BaseStream.Seek(darc.TableOffset + 8, SeekOrigin.Begin); int count = br.ReadByte(); ft.Files = new List<DarcFile>(); ft.FileNames = new List<string>(); br.BaseStream.Seek(darc.TableOffset, SeekOrigin.Begin); for (int i = 0; i < count; i++) { DarcFile file = new DarcFile { NameOffset = br.ReadUInt16(), Parent = br.ReadByte(), Folder = br.ReadByte(), Offset = br.ReadUInt32() + darc.HeaderOffset, Length = br.ReadUInt32() }; DarcFile f2 = file; ft.Files.Add(f2); } uint NameTableOffset = (uint)br.BaseStream.Position; for (int i = 0; i < ft.Files.Count; i++) { br.BaseStream.Seek(NameTableOffset + ft.Files[i].NameOffset, SeekOrigin.Begin); MemoryStream stream = new MemoryStream(); for (byte fb = br.ReadByte(), sb = br.ReadByte(); fb != 0 || sb != 0; fb = br.ReadByte(), sb = br.ReadByte()) { stream.WriteByte(fb); stream.WriteByte(sb); } ft.FileNames.Add(Encoding.Unicode.GetString(stream.ToArray())); stream.Close(); } darc.Files = ft; darc.FileName = Path.GetFileNameWithoutExtension(path); darc.FilePath = Path.GetDirectoryName(path); darc.Extension = Path.GetExtension(path); return darc; } }
internal static DARC analyze(string path) { DARC darc = new DARC { FileName = Path.GetFileNameWithoutExtension(path), FilePath = Path.GetDirectoryName(path), Extension = Path.GetExtension(path) }; using (BinaryReader br = new BinaryReader(File.OpenRead(path))) { long len = br.BaseStream.Length; darc.Magic = br.ReadUInt32(); uint m = darc.Magic; darc.HeaderOffset = 0; while (m != 0x63726164 && darc.HeaderOffset < len - 4) { m = br.ReadUInt32(); darc.HeaderOffset += 4; } if (darc.HeaderOffset >= len - 4) { darc.valid = false; return(darc); } darc.Magic = m; darc.valid = true; darc.BOM = br.ReadUInt16(); darc.HeaderLength = br.ReadUInt16(); darc.Unknown = br.ReadUInt32(); darc.totalLength = br.ReadUInt32(); darc.TableOffset = br.ReadUInt32(); //from start of file darc.TableOffset += darc.HeaderOffset; darc.TableLength = br.ReadUInt32(); darc.DataOffset = br.ReadUInt32(); FileTable ft = new FileTable(); br.BaseStream.Seek(darc.TableOffset + 8, SeekOrigin.Begin); int count = br.ReadByte(); ft.Files = new List <DarcFile>(); ft.FileNames = new List <string>(); br.BaseStream.Seek(darc.TableOffset, SeekOrigin.Begin); for (int i = 0; i < count; i++) { DarcFile file = new DarcFile { NameOffset = br.ReadUInt16(), Parent = br.ReadByte(), Folder = br.ReadByte(), Offset = br.ReadUInt32() + darc.HeaderOffset, Length = br.ReadUInt32() }; DarcFile f2 = file; ft.Files.Add(f2); } uint NameTableOffset = (uint)br.BaseStream.Position; for (int i = 0; i < ft.Files.Count; i++) { br.BaseStream.Seek(NameTableOffset + ft.Files[i].NameOffset, SeekOrigin.Begin); MemoryStream stream = new MemoryStream(); for (byte fb = br.ReadByte(), sb = br.ReadByte(); fb != 0 || sb != 0; fb = br.ReadByte(), sb = br.ReadByte()) { stream.WriteByte(fb); stream.WriteByte(sb); } ft.FileNames.Add(Encoding.Unicode.GetString(stream.ToArray())); stream.Close(); } darc.Files = ft; darc.FileName = Path.GetFileNameWithoutExtension(path); darc.FilePath = Path.GetDirectoryName(path); darc.Extension = Path.GetExtension(path); return(darc); } }