Exemplo n.º 1
0
        private static bool AddFileToDirectory(FlashDirectory dir, string filePath)
        {
            if (!File.Exists(filePath))
            {
                return(false);
            }

            var amfFile = new AmfFile(filePath);

            if (amfFile.Error != null)
            {
                switch (amfFile.Error.Type)
                {
                case AmfFileError.Error.NoPermission:
                    Result     = FileEnumerationResult.NoPermission;
                    ResultPath = filePath;
                    return(false);

                case AmfFileError.Error.Unreadable:
                    Result     = FileEnumerationResult.Unreadable;
                    ResultPath = filePath;
                    return(false);
                }
            }
            dir.Files.Add(amfFile);
            return(true);
        }
Exemplo n.º 2
0
        void WritePlainDataFile(AmfFile file)
        {
            var data = new AmfObject(AmfTypes.Object);

            foreach (var pair in file)
            {
                data[pair.Key] = pair.Value;
            }

            WriteValue(data);
        }
Exemplo n.º 3
0
        void ReadPlainDataFile(AmfFile file, out string name)
        {
            name = Path.GetFileNameWithoutExtension(file.FilePath);

            var data = (AmfObject)ReadValue();

            foreach (var pair in data)
            {
                file[pair.Key] = pair.Value;
            }
        }
Exemplo n.º 4
0
        void ReadStandardFile(AmfFile file, out string name)
        {
            // Endianness
            if (_reader.ReadByte() != 0)
            {
                throw new NotImplementedException("Unknown endianness");
            }
            if (_reader.ReadByte() != 0xBF)
            {
                throw new NotImplementedException("Unknown endianness");
            }

            // Size
            int size = (int)ReadU32();

            if (size + 6 != _reader.BaseStream.Length)
            {
                throw new InvalidOperationException("Wrong file size");
            }

            // Magic signature
            if (ReadPlainString(4) != "TCSO")
            {
                throw new InvalidOperationException("Wrong file tag");
            }
            _reader.BaseStream.Seek(6, SeekOrigin.Current);

            // Read name
            size = ReadU16();
            name = ReadPlainString(size);

            // Version
            int version = (int)ReadU32();

            if (version < 3)
            {
                throw new NotImplementedException("Wrong AMF version");
            }

            // Read content
            while (true)
            {
                var key   = ReadString();
                var value = ReadValue();
                file[key] = value;

                _reader.ReadByte(); // Trailer. No official documentation. Usually zero.
                if (_reader.BaseStream.Position == _reader.BaseStream.Length)
                {
                    break;
                }
            }
        }
Exemplo n.º 5
0
 public void Run(AmfFile file, out string name, out SerializationFormat format)
 {
     // Case for "save to file". Fenoxo only serializes ones object and there is no header.
     if (_reader.PeekChar() == 0x0A)
     {
         format = SerializationFormat.Exported;
         ReadPlainDataFile(file, out name);
     }
     // Case for "save to slot". Real AMF3 file with a proper header.
     else
     {
         format = SerializationFormat.Slot;
         ReadStandardFile(file, out name);
     }
 }
Exemplo n.º 6
0
        void WritePlainDataFile(AmfFile file)
        {
            var data = new AmfObject(AmfTypes.Object);

            foreach (var pair in file)
            {
                data[pair.Key] = pair.Value;
            }

            var dataContainer = new AmfObject(AmfTypes.Object);

            dataContainer["data"] = data;

            WriteValue(dataContainer);
        }
Exemplo n.º 7
0
        void WriteStandardFile(AmfFile file, string newName)
        {
            // Endianness
            _writer.Write((byte)0x00);
            _writer.Write((byte)0xBF);

            // Placeholder for size
            _writer.Write((int)0);

            // Magic signature
            _writer.Write('T');
            _writer.Write('C');
            _writer.Write('S');
            _writer.Write('O');
            _writer.Write((byte)0x00);
            _writer.Write((byte)0x04);
            _writer.Write((byte)0x00);
            _writer.Write((byte)0x00);
            _writer.Write((byte)0x00);
            _writer.Write((byte)0x00);

            // Name
            var countBytes = BitConverter.GetBytes((UInt16)newName.Length);

            WriteReversedBytes(countBytes);
            _writer.Write(newName.ToArray());

            // AMF version number
            _writer.Write((byte)0x00);
            _writer.Write((byte)0x00);
            _writer.Write((byte)0x00);
            _writer.Write((byte)0x03);

            // Key-value pairs
            foreach (var pair in file)
            {
                WriteString((string)pair.Key);
                WriteValue(pair.Value);
                _writer.Write((byte)0);
            }

            // Replace size
            _writer.BaseStream.Seek(2, SeekOrigin.Begin);
            uint dataSize = (uint)_writer.BaseStream.Length - 6;

            WriteU32(dataSize);
        }
Exemplo n.º 8
0
        public void Run(AmfFile file, string newName, SerializationFormat format)
        {
            switch (format)
            {
            case SerializationFormat.Slot:
                WriteStandardFile(file, newName);
                break;

            case SerializationFormat.Exported:
                WritePlainDataFile(file);
                break;

            default:
                throw new NotImplementedException();
            }


            // Flush
            _writer.Flush();
        }
Exemplo n.º 9
0
        private static bool AddFileToDirectory(FlashDirectory dir, string filePath)
        {
            Logger.Trace(String.Format("AddFileToDirectory({0},{1})", dir, filePath));

            bool added = false;

            if (File.Exists(filePath))
            {
                var amfFile = new AmfFile(filePath);
                if (null != amfFile.Error)
                {
                    ResultPath = filePath;
                    switch (amfFile.Error.Type)
                    {
                    case AmfFileError.Error.NoPermission:
                        Result = FileEnumerationResult.NoPermission;
                        break;

                    case AmfFileError.Error.Unreadable:
                        Result = FileEnumerationResult.Unreadable;
                        break;

                    default:
                        Result = FileEnumerationResult.Unknown;
                        break;
                    }
                }
                else
                {
                    dir.Files.Add(amfFile);
                    added = true;
                }
            }

            Logger.Trace(String.Format("AddFileToDirectory:End {0}", added));
            return(added);
        }