private CpioFileEntry ReadFileEntry() { if (Encoding.ASCII.GetString(reader.ReadBytes(6)) != "070707") { throw new IOException("Invalid CPIO file header. Expected magic number field 070707."); } CpioFileEntry entry = new CpioFileEntry(); entry.dev = ReadFileEntryFieldShort(); entry.ino = ReadFileEntryFieldShort(); entry.mode = ReadFileEntryFieldShort(); entry.uid = ReadFileEntryFieldShort(); entry.gid = ReadFileEntryFieldShort(); entry.nlink = ReadFileEntryFieldShort(); entry.rdev = ReadFileEntryFieldShort(); entry.mtime = ReadFileEntryFieldInt(); entry.namesize = ReadFileEntryFieldShort(); entry.filesize = ReadFileEntryFieldInt(); entry.filename = Encoding.UTF8.GetString(reader.ReadBytes(entry.namesize - 1)); reader.ReadByte(); entry.cpio_offset = stream.Position; return(entry); }
public void ExtractEntry(CpioFileEntry entry, Stream outStream) { stream.Seek(entry.cpio_offset, SeekOrigin.Begin); byte [] block = new byte[4096]; int blocks = entry.filesize / block.Length; int remainder = entry.filesize % block.Length; for (int i = 0; i < blocks; i++) { stream.Read(block, 0, block.Length); outStream.Write(block, 0, block.Length); } if (remainder > 0) { stream.Read(block, 0, remainder); outStream.Write(block, 0, remainder); } }
private void ReadCpioEntries() { stream.Seek(0, SeekOrigin.Begin); while (true) { CpioFileEntry entry = ReadFileEntry(); if (entry.filesize == 0 && entry.filename == "TRAILER!!!") { break; } entries.Add(entry); total_size += entry.filesize; stream.Seek(entry.filesize, SeekOrigin.Current); } stream.Seek(0, SeekOrigin.Begin); }
private CpioFileEntry ReadFileEntry() { if(Encoding.ASCII.GetString(reader.ReadBytes(6)) != "070707") { throw new IOException("Invalid CPIO file header. Expected magic number field 070707."); } CpioFileEntry entry = new CpioFileEntry(); entry.dev = ReadFileEntryFieldShort(); entry.ino = ReadFileEntryFieldShort(); entry.mode = ReadFileEntryFieldShort(); entry.uid = ReadFileEntryFieldShort(); entry.gid = ReadFileEntryFieldShort(); entry.nlink = ReadFileEntryFieldShort(); entry.rdev = ReadFileEntryFieldShort(); entry.mtime = ReadFileEntryFieldInt(); entry.namesize = ReadFileEntryFieldShort(); entry.filesize = ReadFileEntryFieldInt(); entry.filename = Encoding.UTF8.GetString(reader.ReadBytes(entry.namesize - 1)); reader.ReadByte(); entry.cpio_offset = stream.Position; return entry; }
public void ExtractEntry(CpioFileEntry entry, Stream outStream) { stream.Seek(entry.cpio_offset, SeekOrigin.Begin); byte [] block = new byte[4096]; int blocks = entry.filesize / block.Length; int remainder = entry.filesize % block.Length; for(int i = 0; i < blocks; i++) { stream.Read(block, 0, block.Length); outStream.Write(block, 0, block.Length); } if(remainder > 0) { stream.Read(block, 0, remainder); outStream.Write(block, 0, remainder); } }
public void ExtractEntry(CpioFileEntry entry, string outFile) { ExtractEntry(entry, new FileStream(outFile, FileMode.Create)); }