Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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;
        }
Exemplo n.º 5
0
        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);
            }
        }
Exemplo n.º 6
0
 public void ExtractEntry(CpioFileEntry entry, string outFile)
 {
     ExtractEntry(entry, new FileStream(outFile, FileMode.Create));
 }
Exemplo n.º 7
0
 public void ExtractEntry(CpioFileEntry entry, string outFile)
 {
     ExtractEntry(entry, new FileStream(outFile, FileMode.Create));
 }