public override void Read(BinaryReader file, int positionOffset)
        {
            int size = file.ReadBigEndianInt32();

            this.Position = file.ReadBigEndianInt32() - positionOffset;
            this.Text = Encoding.ASCII.GetString(file.ReadBytes(size - 5));
            file.ReadByte();
        }
        public override void Read(BinaryReader file, int positionOffset)
        {
            int size = file.ReadBigEndianInt32();

            if (size != 8)
            {
                throw new InvalidDataException();
            }

            this.Position = file.ReadBigEndianInt32() - positionOffset;
            this.Length = file.ReadBigEndianInt32();
        }
        public override void Read(BinaryReader file, int positionOffset)
        {
            int size = file.ReadBigEndianInt32();

            if (size != 16)
            {
                throw new InvalidDataException();
            }

            this.Position = file.ReadBigEndianInt32() - positionOffset;
            this.Destination = file.ReadBigEndianInt32() - positionOffset;
            this.HookId = file.ReadBigEndianInt32();
            this.Delay = file.ReadBigEndianInt32();
        }
 /// <summary>
 /// Deserialise FileZilla binary data into object
 /// </summary>
 /// <param name="reader">Binary reader to read data from</param>
 /// <param name="protocolVersion">Current FileZilla protocol version</param>
 /// <param name="index">The 0 based index of this item in relation to any parent list</param>
 public void Deserialize(BinaryReader reader, int protocolVersion, int index)
 {
     SpeedLimit = reader.ReadBigEndianInt32();
     Date = reader.ReadDate();
     FromTime = reader.ReadTime();
     ToTime = reader.ReadTime();
     Days = (Days)reader.ReadByte();
 }
Example #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IndexEntry"/> class.
        /// </summary>
        /// <param name="reader">The reader.</param>
        public IndexEntry(BinaryReader reader)
        {
            var position = reader.BaseStream.Position;
            this.CreationTime = reader.ReadBigEndianInt32() * 1000000000L + (reader.ReadBigEndianInt32() % 1000000000L);
            this.ModifiedTime = reader.ReadBigEndianInt32() * 1000000000L + (reader.ReadBigEndianInt32() % 1000000000L);

            this.Dev = reader.ReadBigEndianInt32();
            this.Ino = reader.ReadBigEndianInt32();
            this.Mode = reader.ReadBigEndianInt32();
            this.Uid = reader.ReadBigEndianInt32();
            this.Gid = reader.ReadBigEndianInt32();
            this.Size = reader.ReadBigEndianInt32();

            var sha = reader.ReadBytes(20);
            this.Id = Helper.ByteArrayToId(sha);

            this.Flags = reader.ReadBigEndianInt16();
            //stages = (1 << getStage());
            this.Name = Encoding.ASCII.GetString(reader.ReadBytes(this.Flags & 0xfff));
            reader.BaseStream.Position = position + ((70 + this.Name.Length) & ~7);
        }
Example #6
0
        private void EnsureLoaded()
        {
            if (_loaded)
                return;

            using (var stream = File.OpenRead(this.Location))
            {
                var reader = new BinaryReader(stream);

                var sig = reader.ReadBytes(4);

                if (!(sig[0] == 'P' &&
                      sig[1] == 'A' &&
                      sig[2] == 'C' &&
                      sig[3] == 'K'))
                {
                    throw new InvalidOperationException("not a pack file");
                }

                this._version = reader.ReadBigEndianInt32();
                this._entryCount = reader.ReadBigEndianInt32();
                this._index = new PackIndex(this.IndexLocation, this._entryCount);
            }
            this._loaded = true;
        }
Example #7
0
        /// <summary>
        /// Gets the PackIndexEntry from the index.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public PackIndexEntry GetEntry(string id)
        {
            //TODO: we need to support 64bit offsets too
            this.EnsureLoaded();

            using (var stream = File.OpenRead(this.Location))
            {
                var reader = new BinaryReader(stream);

                PackIndexEntry entry;
                if (!_entries.TryGetValue(id, out entry))
                    return null;

                reader.BaseStream.Seek(CrcOffset(entry), SeekOrigin.Begin);
                var crc = reader.ReadBigEndianInt32();

                reader.BaseStream.Seek(OffsetOffset(entry), SeekOrigin.Begin);
                var offset = reader.ReadBigEndianInt32();

                return new PackIndexEntry(entry.Id, entry.Index, crc, offset);
            }
        }
        public static ImcFile FromFile(string fileName)
        {
            var imc = new ImcFile();

            imc.FileName = fileName;

            FileStream filestream = null;

            try
            {
                filestream = new FileStream(fileName, FileMode.Open, FileAccess.Read);

                using (BinaryReader file = new BinaryReader(filestream))
                {
                    filestream = null;

                    if (Encoding.ASCII.GetString(file.ReadBytes(4)) != "MCMP")
                    {
                        throw new InvalidDataException();
                    }

                    int entriesCount = file.ReadBigEndianInt16();

                    file.BaseStream.Seek(9, SeekOrigin.Current);

                    for (int i = 0; i < entriesCount - 1; i++)
                    {
                        var entry = new ImcEntry();

                        entry.Codec = file.ReadByte();
                        entry.RawSize = file.ReadBigEndianInt32();
                        entry.CompressedSize = file.ReadBigEndianInt32();

                        imc.Entries.Add(entry);
                    }

                    int codecsCount = file.ReadBigEndianInt16() / 5;

                    for (int i = 0; i < codecsCount; i++)
                    {
                        imc.Codecs.Add(Encoding.ASCII.GetString(file.ReadBytes(4)));
                        file.ReadByte();
                    }

                    if (imc.Codecs.Count != 2
                        || !string.Equals(imc.Codecs[0], "NULL", StringComparison.Ordinal)
                        || !string.Equals(imc.Codecs[1], "VIMA", StringComparison.Ordinal))
                    {
                        throw new NotSupportedException();
                    }

                    if (Encoding.ASCII.GetString(file.ReadBytes(4)) != "iMUS")
                    {
                        throw new InvalidDataException();
                    }

                    int imusRawSize = file.ReadInt32();

                    if (Encoding.ASCII.GetString(file.ReadBytes(4)) != "MAP ")
                    {
                        throw new InvalidDataException();
                    }

                    ImcFile.ReadMap(imc, file, imusRawSize);

                    if (Encoding.ASCII.GetString(file.ReadBytes(4)) != "DATA")
                    {
                        throw new InvalidDataException();
                    }

                    imc.DataRawSize = file.ReadBigEndianInt32();

                    if (imc.DataRawSize != imc.Entries.Sum(t => t.RawSize))
                    {
                        throw new InvalidDataException();
                    }

                    foreach (var entry in imc.Entries)
                    {
                        entry.Data = file.ReadBytes(entry.CompressedSize);
                    }

                    if (file.BaseStream.Position != file.BaseStream.Length)
                    {
                        throw new InvalidDataException("End of file not reached.");
                    }

                    imc.ComputeEntriesOffsets();
                }
            }
            finally
            {
                if (filestream != null)
                {
                    filestream.Dispose();
                }
            }

            return imc;
        }
        private static void ReadMap(ImcFile imc, BinaryReader file, int imusRawSize)
        {
            int mapSize = file.ReadBigEndianInt32();

            if (Encoding.ASCII.GetString(file.ReadBytes(4)) != "FRMT")
            {
                throw new InvalidDataException();
            }

            int frmtSize = file.ReadBigEndianInt32();

            if (frmtSize != 20)
            {
                throw new InvalidDataException();
            }

            int frmtPosition = file.ReadBigEndianInt32();

            if (mapSize + 24 != frmtPosition)
            {
                throw new InvalidDataException();
            }

            int frmtIsBigEndian = file.ReadBigEndianInt32();

            if (frmtIsBigEndian != 1)
            {
                throw new InvalidDataException();
            }

            imc.BitsPerSample = file.ReadBigEndianInt32();
            imc.SampleRate = file.ReadBigEndianInt32();
            imc.Channels = file.ReadBigEndianInt32();

            int blockAlign = imc.BlockAlign;

            while (true)
            {
                string fourcc = Encoding.ASCII.GetString(file.ReadBytes(4));

                if (string.Equals(fourcc, "STOP", StringComparison.Ordinal))
                {
                    int size = file.ReadBigEndianInt32();

                    if (size != 4)
                    {
                        throw new InvalidDataException();
                    }

                    int position = file.ReadBigEndianInt32() - frmtPosition;

                    if (position != imusRawSize - mapSize - 16)
                    {
                        throw new InvalidDataException();
                    }

                    break;
                }

                switch (fourcc)
                {
                    case "REGN":
                        var regn = new ImcRegnBlock();
                        regn.Read(file, frmtPosition);
                        break;

                    case "TEXT":
                        var text = new ImcTextBlock();
                        text.Read(file, frmtPosition);

                        imc.Map.Add(new ImcText
                        {
                            Position = text.Position / blockAlign,
                            Text = text.Text
                        });
                        break;

                    case "JUMP":
                        var jump = new ImcJumpBlock();
                        jump.Read(file, frmtPosition);

                        imc.Map.Add(new ImcJump
                        {
                            Position = jump.Position / blockAlign,
                            Destination = jump.Destination / blockAlign,
                            HookId = jump.HookId,
                            Delay = jump.Delay
                        });
                        break;

                    default:
                        throw new NotSupportedException("Unknown block " + fourcc);
                }
            }
        }