public IReflectionOptimizer GetReflectionOptimizer(Type type, ClassDefinition classDefinition, AMFReader reader, object instance) { if( classDefinition == null ) return new AMF0ReflectionOptimizer(type, reader).Generate(instance); else return new AMF3ReflectionOptimizer(type, classDefinition, reader).Generate(instance); }
public void Read(byte[] data) { using (MemoryStream ms = new MemoryStream(data)) { using (AMFReader amf = new AMFReader(ms)) { Header = new List<object>(); Bodies = new List<object>(); // AMF0_VERSION = 0; // AMF1_VERSION = 1; // There is no AMF1 but FMS uses it for some reason, hence special casing. // AMF3_VERSION = 3; ushort version = amf.ReadUInt16(); // Number of headers ushort numHeaders = amf.ReadUInt16(); while (numHeaders-- > 0) { var head = DsoAmfHeader.Read(amf); if (head != null) { Bodies.Add(head); } } // Number of bodys ushort numBodies = amf.ReadUInt16(); while (numBodies-- > 0) { var body = DsoAmfBody.Read(amf); if (body != null) { Bodies.Add(body); } } } } }
public static DsoAmfBody Read(AMFReader reader, bool isAmf3) { reader.Reset(); ushort targetUriLen = reader.ReadUInt16(); string targetUri = reader.ReadUTF(targetUriLen); // When the message holds a response from a remote endpoint, the target URI specifies which method on the local client (i.e. reader request originator) should be invoked to handle the response. ushort responseUriLen = reader.ReadUInt16(); string responseUri = reader.ReadUTF(responseUriLen); // The response's target URI is set to the request's response URI with an '/onResult' suffix to denote a success or an '/onStatus' suffix to denote a failure. long dataLen = reader.ReadUInt32(); if (dataLen >= 2147483648) { dataLen = -4294967296; } object bodyObj; // Check for AMF3 kAvmPlusObjectType object type if (isAmf3) { byte typeMarker = reader.ReadByte(); if (typeMarker == 17) { bodyObj = reader.ReadAMF3Data(); } else { bodyObj = reader.ReadData(); } } else { bodyObj = reader.ReadData(); } DsoAmfBody body = new DsoAmfBody(targetUri, responseUri, bodyObj); return body; }
public AMF0ReflectionOptimizer(Type type, AMFReader reader, object instance) { _createInstanceMethod = CreateCreateInstanceMethod(type); #if !(MONO) && !(NET_2_0) && !(NET_3_5) && !(SILVERLIGHT) _ps = new PermissionSet(PermissionState.None); _ps.AddPermission(new ReflectionPermission(ReflectionPermissionFlag.MemberAccess)); #endif _readDataMethod = CreateReadDataMethod(type, reader, instance); }
/// <summary> /// Initializes a new instance of the ByteArray class. /// </summary> public ByteArray() { _memoryStream = new MemoryStream(); AMFReader amfReader = new AMFReader(_memoryStream); AMFWriter amfWriter = new AMFWriter(_memoryStream); _dataOutput = new DataOutput(amfWriter); _dataInput = new DataInput(amfReader); _objectEncoding = ObjectEncoding.AMF3; }
public IReflectionOptimizer GetReflectionOptimizer(Type type, ClassDefinition classDefinition, AMFReader reader, object instance) { #if NET_1_1 return null; #else if (classDefinition == null) return new AMF0ReflectionOptimizer(type, reader, instance); return new AMF3ReflectionOptimizer(type, classDefinition, reader, instance); #endif }
public static DsoAmfHeader Read(AMFReader reader) { reader.Reset(); ushort nameLen = reader.ReadUInt16(); string name = reader.ReadUTF(nameLen); bool required = (reader.ReadByte() > 0); // find the must understand flag uint dataLen = reader.ReadUInt32(); object headObj = reader.ReadData(); DsoAmfHeader header = new DsoAmfHeader(name, required, headObj); return header; }
public object ReadData(AMFReader reader, ClassDefinition classDefinition) { ASObject aso = new ASObject(_typeIdentifier); reader.AddAMF3ObjectReference(aso); string key = reader.ReadAMF3String(); aso.TypeName = _typeIdentifier; while (key != string.Empty) { object value = reader.ReadAMF3Data(); aso.Add(key, value); key = reader.ReadAMF3String(); } return aso; }
public object ReadData(AMFReader reader, ClassDefinition classDefinition) { var instance = ObjectFactory.CreateInstance(classDefinition.ClassName); if (instance == null) { throw new FluorineException(String.Format(Resources.Type_InitError, classDefinition.ClassName)); } reader.AddAMF3ObjectReference(instance); if (instance is IExternalizable) { var externalizable = instance as IExternalizable; var dataInput = new DataInput(reader); externalizable.ReadExternal(dataInput); return instance; } throw new FluorineException(String.Format(Resources.Externalizable_CastFail, instance.GetType().FullName)); }
public object ReadData(AMFReader reader, ClassDefinition classDefinition) { object instance = ObjectFactory.CreateInstance(classDefinition.ClassName); if (instance == null) { string msg = __Res.GetString(__Res.Type_InitError, classDefinition.ClassName); throw new FluorineException(msg); } reader.AddAMF3ObjectReference(instance); if (instance is IExternalizable) { IExternalizable externalizable = instance as IExternalizable; DataInput dataInput = new DataInput(reader); externalizable.ReadExternal(dataInput); return instance; } else { string msg = __Res.GetString(__Res.Externalizable_CastFail, instance.GetType().FullName); throw new FluorineException(msg); } }
private IPersistable LoadObject(string name, IPersistable obj) { string fileName = PersistenceUtils.GetFilename(_scope, _path, name, _extension); FileInfo file = _scope.Context.GetResource(fileName).File; if (!file.Exists) return null;// No such file IPersistable result = obj; lock (this.SyncRoot) { using (FileStream fs = new FileStream(file.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { AMFReader reader = new AMFReader(fs); string typeName = reader.ReadData() as string; result = ObjectFactory.CreateInstance(typeName) as IPersistable; //result.Path = GetObjectPath(name, result.Name); //result = amfDeserializer.ReadData() as IPersistable; result.Deserialize(reader); } } return result; }
public static DsoAmfBody Read(AMFReader reader) { reader.Reset(); ushort targetUriLen = reader.ReadUInt16(); string targetUri = reader.ReadUTF(targetUriLen); // When the message holds a response from a remote endpoint, the target URI specifies which method on the local client (i.e. reader request originator) should be invoked to handle the response. ushort responseUriLen = reader.ReadUInt16(); string responseUri = reader.ReadUTF(responseUriLen); // The response's target URI is set to the request's response URI with an '/onResult' suffix to denote a success or an '/onStatus' suffix to denote a failure. int numBytes = 4; uint dataLen = 0; while (numBytes-- > 0) dataLen = (dataLen << 8) | reader.ReadByte(); // Need to skip 1 byte more, dont know why.. reader.ReadByte(); object bodyObj = reader.ReadData(); // turn the element into real data DsoAmfBody body = new DsoAmfBody(targetUri, responseUri, bodyObj); return body; }
public object ReadData(AMFReader reader) { object instance = null; string typeIdentifier = reader.ReadString(); #if LOGGING if (log.IsDebugEnabled) { string msg = string.Format("Attempt to read custom object {0}", typeIdentifier); log.Debug(msg); } #endif IReflectionOptimizer reflectionOptimizer = _optimizedReaders[typeIdentifier] as IReflectionOptimizer; if (reflectionOptimizer == null) { lock (_optimizedReaders) { if (!_optimizedReaders.Contains(typeIdentifier)) { #if LOGGING if (log.IsDebugEnabled) { string msg = string.Format("Generating optimizer for type {0}", typeIdentifier); log.Debug(msg); } #endif //Temporary reader _optimizedReaders[typeIdentifier] = new AMF0TempObjectReader(); Type type = ObjectFactory.Locate(typeIdentifier); if (type != null) { instance = ObjectFactory.CreateInstance(type); reader.AddReference(instance); if (type != null) { IBytecodeProvider bytecodeProvider = null; #if NET_1_1 //codedom only if (FluorineConfiguration.Instance.OptimizerSettings != null) { bytecodeProvider = new FluorineFx.IO.Bytecode.CodeDom.BytecodeProvider(); } #else if (FluorineConfiguration.Instance.OptimizerSettings.Provider == "codedom") { bytecodeProvider = new FluorineFx.IO.Bytecode.CodeDom.BytecodeProvider(); } if (FluorineConfiguration.Instance.OptimizerSettings.Provider == "il") { bytecodeProvider = new FluorineFx.IO.Bytecode.Lightweight.BytecodeProvider(); } #endif reflectionOptimizer = bytecodeProvider.GetReflectionOptimizer(type, null, reader, instance); //Fixup if (reflectionOptimizer != null) { _optimizedReaders[typeIdentifier] = reflectionOptimizer; } else { _optimizedReaders[typeIdentifier] = new AMF0TempObjectReader(); } } } else { #if LOGGING if (log.IsWarnEnabled) { log.Warn("Custom object " + typeIdentifier + " could not be loaded. An ActionScript typed object (ASObject) will be created"); } #endif reflectionOptimizer = new AMF0TypedASObjectReader(typeIdentifier); _optimizedReaders[typeIdentifier] = reflectionOptimizer; instance = reflectionOptimizer.ReadData(reader, null); } } else { reflectionOptimizer = _optimizedReaders[typeIdentifier] as IReflectionOptimizer; instance = reflectionOptimizer.ReadData(reader, null); } } } else { instance = reflectionOptimizer.ReadData(reader, null); } return(instance); }
public object ReadData(AMFReader reader) { return(reader.ReadDouble()); }
/// <summary> /// Decompresses the byte array. The byte array must have been previously compressed with the Compress() method. /// </summary> /// <param name="algorithm">The compression algorithm to use when decompressing. This must be the same compression algorithm used to compress the data. Valid values are defined as constants in the CompressionAlgorithm class. The default is to use zlib format.</param> public void Uncompress(string algorithm) { ValidationUtils.ArgumentConditionTrue(algorithm == CompressionAlgorithm.Deflate || algorithm == CompressionAlgorithm.Zlib, "algorithm", "Invalid parameter"); #if SILVERLIGHT throw new NotSupportedException(); #else if (algorithm == CompressionAlgorithm.Zlib) { //The zlib format is specified by RFC 1950. Zlib also uses deflate, plus 2 or 6 header bytes, and a 4 byte checksum at the end. //The first 2 bytes indicate the compression method and flags. If the dictionary flag is set, then 4 additional bytes will follow. //Preset dictionaries aren't very common and we don't support them Position = 0; ZlibStream deflateStream = new ZlibStream(_memoryStream, CompressionMode.Decompress, false); MemoryStream ms = new MemoryStream(); byte[] buffer = new byte[1024]; // Chop off the first two bytes //int b = _memoryStream.ReadByte(); //b = _memoryStream.ReadByte(); while (true) { int readCount = deflateStream.Read(buffer, 0, buffer.Length); if (readCount > 0) { ms.Write(buffer, 0, readCount); } else { break; } } deflateStream.Close(); _memoryStream.Close(); _memoryStream.Dispose(); _memoryStream = ms; _memoryStream.Position = 0; } if (algorithm == CompressionAlgorithm.Deflate) { Position = 0; DeflateStream deflateStream = new DeflateStream(_memoryStream, CompressionMode.Decompress, false); MemoryStream ms = new MemoryStream(); byte[] buffer = new byte[1024]; while (true) { int readCount = deflateStream.Read(buffer, 0, buffer.Length); if (readCount > 0) { ms.Write(buffer, 0, readCount); } else { break; } } deflateStream.Close(); _memoryStream.Close(); _memoryStream.Dispose(); _memoryStream = ms; _memoryStream.Position = 0; } AMFReader amfReader = new AMFReader(_memoryStream); AMFWriter amfWriter = new AMFWriter(_memoryStream); _dataOutput = new DataOutput(amfWriter); _dataInput = new DataInput(amfReader); #endif }
public object ReadData(AMFReader reader) { int index = reader.ReadUInt16(); return(reader.ReadAMF0ObjectReference(index)); }
public object ReadData(AMFReader reader) { return reader.ReadDouble(); }
public void Deserialize(AMFReader reader) { _name = reader.ReadData() as string; _path = reader.ReadData() as string; _attributes.Clear(); #if !(NET_1_1) _attributes = new CopyOnWriteDictionary<string, object>(reader.ReadData() as IDictionary<string, object>); #else _attributes = new CopyOnWriteDictionary(reader.ReadData() as IDictionary); #endif _persistent = true; _persistentSO = true; _ownerMessage.SetName(_name); _ownerMessage.SetIsPersistent(true); }
public object ReadData(AMFReader reader) { return reader.ReadString(); }
public IReflectionOptimizer GetReflectionOptimizer(Type type, ClassDefinition classDefinition, AMFReader reader, object instance) { if (classDefinition == null) { return(new AMF0ReflectionOptimizer(type, reader).Generate(instance)); } else { return(new AMF3ReflectionOptimizer(type, classDefinition, reader).Generate(instance)); } }
public object ReadData(AMFReader reader) { return(reader.ReadString()); }
public object ReadData(AMFReader reader) { int length = reader.ReadInt32(); return(reader.ReadUTF(length)); }
public IReflectionOptimizer GetReflectionOptimizer(Type type, ClassDefinition classDefinition, AMFReader reader, object instance) { #if NET_1_1 return(null); #else if (classDefinition == null) { return(new AMF0ReflectionOptimizer(type, reader, instance)); } else { return(new AMF3ReflectionOptimizer(type, classDefinition, reader, instance)); } #endif }
public object ReadData(AMFReader reader) { int handle = reader.ReadAMF3IntegerData(); bool inline = ((handle & 1) != 0); handle = handle >> 1; if (!inline) { //An object reference return(reader.ReadAMF3ObjectReference(handle)); } else { ClassDefinition classDefinition = reader.ReadClassDefinition(handle); object instance = null; IReflectionOptimizer reflectionOptimizer = _optimizedReaders[classDefinition.ClassName] as IReflectionOptimizer; if (reflectionOptimizer == null) { lock (_optimizedReaders) { if (classDefinition.IsTypedObject) { if (!_optimizedReaders.Contains(classDefinition.ClassName)) { //Temporary reader _optimizedReaders[classDefinition.ClassName] = new AMF3TempObjectReader(); Type type = ObjectFactory.Locate(classDefinition.ClassName); if (type != null) { instance = ObjectFactory.CreateInstance(type); if (classDefinition.IsExternalizable) { reflectionOptimizer = new AMF3ExternalizableReader(); _optimizedReaders[classDefinition.ClassName] = reflectionOptimizer; instance = reflectionOptimizer.ReadData(reader, classDefinition); } else { reader.AddAMF3ObjectReference(instance); IBytecodeProvider bytecodeProvider = null; #if NET_1_1 //codedom only if (FluorineConfiguration.Instance.OptimizerSettings != null) { bytecodeProvider = new FluorineFx.IO.Bytecode.CodeDom.BytecodeProvider(); } #else if (FluorineConfiguration.Instance.OptimizerSettings.Provider == "codedom") { bytecodeProvider = new FluorineFx.IO.Bytecode.CodeDom.BytecodeProvider(); } if (FluorineConfiguration.Instance.OptimizerSettings.Provider == "il") { bytecodeProvider = new FluorineFx.IO.Bytecode.Lightweight.BytecodeProvider(); } #endif reflectionOptimizer = bytecodeProvider.GetReflectionOptimizer(type, classDefinition, reader, instance); //Fixup if (reflectionOptimizer != null) { _optimizedReaders[classDefinition.ClassName] = reflectionOptimizer; } else { _optimizedReaders[classDefinition.ClassName] = new AMF3TempObjectReader(); } } } else { reflectionOptimizer = new AMF3TypedASObjectReader(classDefinition.ClassName); _optimizedReaders[classDefinition.ClassName] = reflectionOptimizer; instance = reflectionOptimizer.ReadData(reader, classDefinition); } } else { reflectionOptimizer = _optimizedReaders[classDefinition.ClassName] as IReflectionOptimizer; instance = reflectionOptimizer.ReadData(reader, classDefinition); } } else { reflectionOptimizer = new AMF3TypedASObjectReader(classDefinition.ClassName); _optimizedReaders[classDefinition.ClassName] = reflectionOptimizer; instance = reflectionOptimizer.ReadData(reader, classDefinition); } } } else { instance = reflectionOptimizer.ReadData(reader, classDefinition); } return(instance); } }
public object ReadData(AMFReader reader, ClassDefinition classDefinition) { object obj = reader.ReadAMF3Object(classDefinition); return(obj); }
/// <summary> /// Compresses the byte array using zlib compression. The entire byte array is compressed. /// </summary> /// <param name="algorithm">The compression algorithm to use when compressing. Valid values are defined as constants in the CompressionAlgorithm class. The default is to use zlib format.</param> /// <remarks> /// After the call, the Length property of the ByteArray is set to the new length. The position property is set to the end of the byte array. /// </remarks> public void Compress(string algorithm) { ValidationUtils.ArgumentConditionTrue(algorithm == CompressionAlgorithm.Deflate || algorithm == CompressionAlgorithm.Zlib, "algorithm", "Invalid parameter"); #if SILVERLIGHT throw new NotSupportedException(); #else if (algorithm == CompressionAlgorithm.Deflate) { byte[] buffer = _memoryStream.ToArray(); MemoryStream ms = new MemoryStream(); DeflateStream deflateStream = new DeflateStream(ms, CompressionMode.Compress, true); deflateStream.Write(buffer, 0, buffer.Length); deflateStream.Close(); _memoryStream.Close(); _memoryStream = ms; AMFReader amfReader = new AMFReader(_memoryStream); AMFWriter amfWriter = new AMFWriter(_memoryStream); _dataOutput = new DataOutput(amfWriter); _dataInput = new DataInput(amfReader); } if (algorithm == CompressionAlgorithm.Zlib) { byte[] buffer = _memoryStream.ToArray(); MemoryStream ms = new MemoryStream(); ZlibStream zlibStream = new ZlibStream(ms, CompressionMode.Compress, true); zlibStream.Write(buffer, 0, buffer.Length); zlibStream.Flush(); zlibStream.Close(); zlibStream.Dispose(); _memoryStream.Close(); _memoryStream = ms; AMFReader amfReader = new AMFReader(_memoryStream); AMFWriter amfWriter = new AMFWriter(_memoryStream); _dataOutput = new DataOutput(amfWriter); _dataInput = new DataInput(amfReader); } #endif }
public object ReadData(AMFReader reader, ClassDefinition classDefinition) { object amfObject = reader.ReadObject(); return amfObject; }
public object ReadData(AMFReader reader) { throw new UnexpectedAMF(); }
public object ReadData(AMFReader reader) { return(reader.ReadAMF3XmlDocument()); }
public object ReadData(AMFReader reader) { return reader.ReadAMF3Int(); }
public object ReadData(AMFReader reader) { return(null); }
public DataInput(AMFReader amfReader) { this._amfReader = amfReader; this._objectEncoding = FluorineFx.ObjectEncoding.AMF3; }
public object ReadData(AMFReader reader) { throw new Exception("MovieclipMarker"); }
public object ReadData(AMFReader reader) { return(reader.ReadAMF3IntVector()); }
public FlvWriter(Stream stream, bool append) { _writer = new AMFWriter(stream); _append = append; if (_append) { if (stream.Length > 9 + 15) { try { //Skip header stream.Position = 9; byte[] tagBuffer = new byte[15]; //previousTagSize stream.Read(tagBuffer, 0, 4); //start of flv tag byte dataType = (byte)stream.ReadByte(); if (dataType == IOConstants.TYPE_METADATA) { _metaPosition = stream.Position - 1; //body size stream.Read(tagBuffer, 5, 3); int bodySize = tagBuffer[5] << 16 | tagBuffer[6] << 8 | tagBuffer[7]; //timestamp stream.Read(tagBuffer, 8, 4); //streamid stream.Read(tagBuffer, 12, 3); byte[] buffer = new byte[bodySize]; stream.Read(buffer, 0, buffer.Length); MemoryStream ms = new MemoryStream(buffer); AMFReader input = new AMFReader(ms); string onMetaData = input.ReadData() as string;//input.ReadString(); IDictionary properties = input.ReadData() as IDictionary; if (properties.Contains("duration")) { _duration = System.Convert.ToInt32(properties["duration"]); } else { #if LOGGING && !SILVERLIGHT log.Warn("Could not read Flv duration from metadata"); #endif } } else { #if LOGGING && !SILVERLIGHT log.Warn("Could not read Flv duration"); #endif } } catch (Exception ex) { #if LOGGING && !SILVERLIGHT log.Warn("Error reading Flv duration", ex); #endif } } stream.Seek(0, SeekOrigin.End);//Appending } }
public object ReadData(AMFReader reader) { return(reader.ReadAssociativeArray()); }
public object ReadData(AMFReader reader) { return(reader.ReadAMF3Data()); }
public object ReadData(AMFReader reader, ClassDefinition classDefinition) { object amfObject = reader.ReadObject(); return(amfObject); }
public virtual object ReadData(AMFReader reader, ClassDefinition classDefinition) { return(_readDataMethod(reader, classDefinition)); }
/// <summary> /// Initializes a new instance of the ByteArray class. /// </summary> /// <param name="buffer">The array of unsigned bytes from which to create the current ByteArray.</param> public ByteArray(byte[] buffer) { _memoryStream = new MemoryStream(); _memoryStream.Write(buffer, 0, buffer.Length); _memoryStream.Position = 0; AMFReader amfReader = new AMFReader(_memoryStream); AMFWriter amfWriter = new AMFWriter(_memoryStream); _dataOutput = new DataOutput(amfWriter); _dataInput = new DataInput(amfReader); _objectEncoding = ObjectEncoding.AMF3; }
protected virtual ReadDataInvoker CreateReadDataMethod(Type type, AMFReader reader, object instance) { #if !(MONO) && !(NET_2_0) && !(NET_3_5) && !(SILVERLIGHT) bool canSkipChecks = _ps.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet); #else bool canSkipChecks = SecurityManager.IsGranted(new ReflectionPermission(ReflectionPermissionFlag.MemberAccess)); #endif DynamicMethod method = new DynamicMethod(string.Empty, typeof(object), new Type[] { typeof(AMFReader), typeof(ClassDefinition) }, this.GetType(), canSkipChecks); ILGenerator il = method.GetILGenerator(); LocalBuilder instanceLocal = il.DeclareLocal(type); //[0] instance LocalBuilder typeCodeLocal = il.DeclareLocal(typeof(byte)); //[1] uint8 typeCode LocalBuilder keyLocal = il.DeclareLocal(typeof(string)); //[2] string key LocalBuilder objTmp = il.DeclareLocal(typeof(object)); //[3] temp object store LocalBuilder intTmp1 = il.DeclareLocal(typeof(int)); //[4] temp int store, length LocalBuilder intTmp2 = il.DeclareLocal(typeof(int)); //[5] temp int store, index LocalBuilder objTmp2 = il.DeclareLocal(typeof(object)); //[6] temp object store LocalBuilder typeTmp = il.DeclareLocal(typeof(Type)); //[7] temp Type store EmitHelper emit = new EmitHelper(il); ConstructorInfo typeConstructor = type.GetConstructor(EmitHelper.AnyVisibilityInstance, null, CallingConventions.HasThis, System.Type.EmptyTypes, null); MethodInfo miAddReference = typeof(AMFReader).GetMethod("AddReference"); MethodInfo miReadString = typeof(AMFReader).GetMethod("ReadString"); MethodInfo miReadByte = typeof(AMFReader).GetMethod("ReadByte"); emit //object instance = new object(); .newobj(typeConstructor) //Create the new instance and push the object reference onto the evaluation stack .stloc_0 //Pop from the top of the evaluation stack and store it in a the local variable list at index 0 //reader.AddReference(instance); .ldarg_0 //Push the argument indexed at 1 onto the evaluation stack 'reader' .ldloc_0 //Loads the local variable at index 0 onto the evaluation stack 'instance' .callvirt(miAddReference) //Arguments are popped from the stack, the method call is performed, return value is pushed onto the stack //typeCode = 0; .ldc_i4_0 //Push the integer value of 0 onto the evaluation stack as an int32 .stloc_1 //Pop and store it in a the local variable list at index 1 //string key = null; .ldnull //Push a null reference onto the evaluation stack .stloc_2 //Pop and store it in a the local variable list at index 2 'key' .end() ; string key = reader.ReadString(); for (byte typeCode = reader.ReadByte(); typeCode != AMF0TypeCode.EndOfObject; typeCode = reader.ReadByte()) { emit .ldarg_0 .callvirt(miReadString) .stloc_2 .ldarg_0 .callvirt(miReadByte) .stloc_1 .end() ; object value = reader.ReadData(typeCode); reader.SetMember(instance, key, value); MemberInfo[] memberInfos = type.GetMember(key); if (memberInfos != null && memberInfos.Length > 0) { GeneratePropertySet(emit, typeCode, memberInfos[0]); } else { //Log this error (do not throw exception), otherwise our current AMF stream becomes unreliable log.Warn(__Res.GetString(__Res.Optimizer_Warning)); string msg = __Res.GetString(__Res.Reflection_MemberNotFound, string.Format("{0}.{1}", type.FullName, key)); log.Warn(msg); //reader.ReadAMF3Data(typeCode); emit .ldarg_0 //Push 'reader' .ldloc_1 //Push 'typeCode' .callvirt(typeof(AMFReader).GetMethod("ReadData", new Type[] { typeof(byte) })) .pop .end() ; } key = reader.ReadString(); } Label labelExit = emit.DefineLabel(); ConstructorInfo exceptionConstructor = typeof(UnexpectedAMF).GetConstructor(EmitHelper.AnyVisibilityInstance, null, CallingConventions.HasThis, Type.EmptyTypes, null); //key = reader.ReadString(); emit .ldarg_0 //Push 'reader' .callvirt(miReadString) .stloc_2 //Pop 'key' //typeCode = reader.ReadByte(); .ldarg_0 //Push 'reader' .callvirt(miReadByte) .stloc_1 //Pop 'typeCode' .ldloc_1 .ldc_i4_s(AMF0TypeCode.EndOfObject) .ceq .brtrue_s(labelExit) //if( typeCode != AMF0TypeCode.EndOfObject ) throw new UnexpectedAMF(); .newobj(exceptionConstructor) .@throw .end() ; emit .MarkLabel(labelExit) //return instance; .ldloc_0 //Load the local variable at index 0 onto the evaluation stack .ret() //Return ; return((ReadDataInvoker)method.CreateDelegate(typeof(ReadDataInvoker))); }
/// <summary> /// Decompresses the byte array. The byte array must have been previously compressed with the Compress() method. /// </summary> /// <param name="algorithm">The compression algorithm to use when decompressing. This must be the same compression algorithm used to compress the data. Valid values are defined as constants in the CompressionAlgorithm class. The default is to use zlib format.</param> public void Uncompress(string algorithm) { ValidationUtils.ArgumentConditionTrue(algorithm == CompressionAlgorithm.Deflate || algorithm == CompressionAlgorithm.Zlib, "algorithm", "Invalid parameter"); #if SILVERLIGHT throw new NotSupportedException(); #else if (algorithm == CompressionAlgorithm.Zlib) { //The zlib format is specified by RFC 1950. Zlib also uses deflate, plus 2 or 6 header bytes, and a 4 byte checksum at the end. //The first 2 bytes indicate the compression method and flags. If the dictionary flag is set, then 4 additional bytes will follow. //Preset dictionaries aren't very common and we don't support them Position = 0; ZlibStream deflateStream = new ZlibStream(_memoryStream, CompressionMode.Decompress, false); MemoryStream ms = new MemoryStream(); byte[] buffer = new byte[1024]; // Chop off the first two bytes //int b = _memoryStream.ReadByte(); //b = _memoryStream.ReadByte(); while (true) { int readCount = deflateStream.Read(buffer, 0, buffer.Length); if (readCount > 0) ms.Write(buffer, 0, readCount); else break; } deflateStream.Close(); _memoryStream.Close(); _memoryStream.Dispose(); _memoryStream = ms; _memoryStream.Position = 0; } if (algorithm == CompressionAlgorithm.Deflate) { Position = 0; DeflateStream deflateStream = new DeflateStream(_memoryStream, CompressionMode.Decompress, false); MemoryStream ms = new MemoryStream(); byte[] buffer = new byte[1024]; while (true) { int readCount = deflateStream.Read(buffer, 0, buffer.Length); if (readCount > 0) ms.Write(buffer, 0, readCount); else break; } deflateStream.Close(); _memoryStream.Close(); _memoryStream.Dispose(); _memoryStream = ms; _memoryStream.Position = 0; } AMFReader amfReader = new AMFReader(_memoryStream); AMFWriter amfWriter = new AMFWriter(_memoryStream); _dataOutput = new DataOutput(amfWriter); _dataInput = new DataInput(amfReader); #endif }
public object ReadData(AMFReader reader) { return(true); }
public object ReadData(AMFReader reader) { object instance = null; string typeIdentifier = reader.ReadString(); if(log.IsDebugEnabled ) { string msg = string.Format("Attempt to read custom object {0}", typeIdentifier); log.Debug(msg); } IReflectionOptimizer reflectionOptimizer = _optimizedReaders[typeIdentifier] as IReflectionOptimizer; if( reflectionOptimizer == null ) { lock(_optimizedReaders) { if (!_optimizedReaders.Contains(typeIdentifier)) { if(log.IsDebugEnabled ) { string msg = string.Format("Generating optimizer for type {0}", typeIdentifier); log.Debug(msg); } //Temporary reader _optimizedReaders[typeIdentifier] = new AMF0TempObjectReader(); Type type = ObjectFactory.Locate(typeIdentifier); if( type != null ) { instance = ObjectFactory.CreateInstance(type); reader.AddReference(instance); if (type != null) { IBytecodeProvider bytecodeProvider = null; #if NET_1_1 //codedom only if( FluorineConfiguration.Instance.OptimizerSettings != null ) bytecodeProvider = new FluorineFx.IO.Bytecode.CodeDom.BytecodeProvider(); #else if (FluorineConfiguration.Instance.OptimizerSettings.Provider == "codedom") bytecodeProvider = new FluorineFx.IO.Bytecode.CodeDom.BytecodeProvider(); if (FluorineConfiguration.Instance.OptimizerSettings.Provider == "il") bytecodeProvider = new FluorineFx.IO.Bytecode.Lightweight.BytecodeProvider(); #endif reflectionOptimizer = bytecodeProvider.GetReflectionOptimizer(type, null, reader, instance); //Fixup if (reflectionOptimizer != null) _optimizedReaders[typeIdentifier] = reflectionOptimizer; else _optimizedReaders[typeIdentifier] = new AMF0TempObjectReader(); } } else { if( log.IsWarnEnabled ) log.Warn("Custom object " + typeIdentifier + " could not be loaded. An ActionScript typed object (ASObject) will be created"); reflectionOptimizer = new AMF0TypedASObjectReader(typeIdentifier); _optimizedReaders[typeIdentifier] = reflectionOptimizer; instance = reflectionOptimizer.ReadData(reader, null); } } else { reflectionOptimizer = _optimizedReaders[typeIdentifier] as IReflectionOptimizer; instance = reflectionOptimizer.ReadData(reader, null); } } } else { instance = reflectionOptimizer.ReadData(reader, null); } return instance; }
public AMF0ReflectionOptimizer(Type type, AMFReader reader) { _mappedClass = type; _reader = reader; _layouter = new Layouter(); }
public object ReadData(AMFReader reader) { int length = reader.ReadInt32(); return reader.ReadUTF(length); }
protected virtual ReadDataInvoker CreateReadDataMethod(Type type, AMFReader reader, object instance) { #if !(MONO) && !(NET_2_0) && !(NET_3_5) && !(SILVERLIGHT) bool canSkipChecks = _ps.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet); #else bool canSkipChecks = SecurityManager.IsGranted(new ReflectionPermission(ReflectionPermissionFlag.MemberAccess)); #endif DynamicMethod method = new DynamicMethod(string.Empty, typeof(object), new Type[] { typeof(AMFReader), typeof(ClassDefinition) }, this.GetType(), canSkipChecks); ILGenerator il = method.GetILGenerator(); LocalBuilder instanceLocal = il.DeclareLocal(type);//[0] instance LocalBuilder typeCodeLocal = il.DeclareLocal(typeof(byte));//[1] uint8 typeCode LocalBuilder keyLocal = il.DeclareLocal(typeof(string));//[2] string key LocalBuilder objTmp = il.DeclareLocal(typeof(object));//[3] temp object store LocalBuilder intTmp1 = il.DeclareLocal(typeof(int));//[4] temp int store, length LocalBuilder intTmp2 = il.DeclareLocal(typeof(int));//[5] temp int store, index LocalBuilder objTmp2 = il.DeclareLocal(typeof(object));//[6] temp object store LocalBuilder typeTmp = il.DeclareLocal(typeof(Type));//[7] temp Type store EmitHelper emit = new EmitHelper(il); ConstructorInfo typeConstructor = type.GetConstructor(EmitHelper.AnyVisibilityInstance, null, CallingConventions.HasThis, System.Type.EmptyTypes, null); MethodInfo miAddReference = typeof(AMFReader).GetMethod("AddReference"); MethodInfo miReadString = typeof(AMFReader).GetMethod("ReadString"); MethodInfo miReadByte = typeof(AMFReader).GetMethod("ReadByte"); emit //object instance = new object(); .newobj(typeConstructor) //Create the new instance and push the object reference onto the evaluation stack .stloc_0 //Pop from the top of the evaluation stack and store it in a the local variable list at index 0 //reader.AddReference(instance); .ldarg_0 //Push the argument indexed at 1 onto the evaluation stack 'reader' .ldloc_0 //Loads the local variable at index 0 onto the evaluation stack 'instance' .callvirt(miAddReference) //Arguments are popped from the stack, the method call is performed, return value is pushed onto the stack //typeCode = 0; .ldc_i4_0 //Push the integer value of 0 onto the evaluation stack as an int32 .stloc_1 //Pop and store it in a the local variable list at index 1 //string key = null; .ldnull //Push a null reference onto the evaluation stack .stloc_2 //Pop and store it in a the local variable list at index 2 'key' .end() ; string key = reader.ReadString(); for (byte typeCode = reader.ReadByte(); typeCode != AMF0TypeCode.EndOfObject; typeCode = reader.ReadByte()) { emit .ldarg_0 .callvirt(miReadString) .stloc_2 .ldarg_0 .callvirt(miReadByte) .stloc_1 .end() ; object value = reader.ReadData(typeCode); reader.SetMember(instance, key, value); MemberInfo[] memberInfos = type.GetMember(key); if (memberInfos != null && memberInfos.Length > 0) GeneratePropertySet(emit, typeCode, memberInfos[0]); else { //Log this error (do not throw exception), otherwise our current AMF stream becomes unreliable log.Warn(__Res.GetString(__Res.Optimizer_Warning)); string msg = __Res.GetString(__Res.Reflection_MemberNotFound, string.Format("{0}.{1}", type.FullName, key)); log.Warn(msg); //reader.ReadAMF3Data(typeCode); emit .ldarg_0 //Push 'reader' .ldloc_1 //Push 'typeCode' .callvirt(typeof(AMFReader).GetMethod("ReadData", new Type[] { typeof(byte) })) .pop .end() ; } key = reader.ReadString(); } Label labelExit = emit.DefineLabel(); ConstructorInfo exceptionConstructor = typeof(UnexpectedAMF).GetConstructor(EmitHelper.AnyVisibilityInstance, null, CallingConventions.HasThis, Type.EmptyTypes, null); //key = reader.ReadString(); emit .ldarg_0 //Push 'reader' .callvirt(miReadString) .stloc_2 //Pop 'key' //typeCode = reader.ReadByte(); .ldarg_0 //Push 'reader' .callvirt(miReadByte) .stloc_1 //Pop 'typeCode' .ldloc_1 .ldc_i4_s(AMF0TypeCode.EndOfObject) .ceq .brtrue_s(labelExit) //if( typeCode != AMF0TypeCode.EndOfObject ) throw new UnexpectedAMF(); .newobj(exceptionConstructor) .@throw .end() ; emit .MarkLabel(labelExit) //return instance; .ldloc_0 //Load the local variable at index 0 onto the evaluation stack .ret() //Return ; return (ReadDataInvoker)method.CreateDelegate(typeof(ReadDataInvoker)); }
public object ReadData(AMFReader reader) { return reader.ReadAssociativeArray(); }
public object ReadData(AMFReader reader) { return(reader.ReadReference()); }
public object ReadData(AMFReader reader) { return reader.ReadAMF3XmlDocument(); }
public object ReadData(AMFReader reader) { throw new Exception("UnsupportedMarker"); }
public object ReadData(AMFReader reader) { return(reader.ReadBoolean()); }
public object ReadData(AMFReader reader) { return(reader.ReadDouble()); //AMF3 undefined = double.NaN }
/// <summary> /// Reads the Metadata. /// </summary> /// <param name="buffer">Byte buffer source.</param> /// <returns>Metadata.</returns> public MetaData ReadMetaData(byte[] buffer) { MetaData retMeta = new MetaData(); MemoryStream ms = new MemoryStream(buffer); AMFReader reader = new AMFReader(ms); string metaType = reader.ReadData() as string; IDictionary data = reader.ReadData() as IDictionary; retMeta.PutAll(data); return retMeta; }
public object ReadData(AMFReader reader, ClassDefinition classDefinition) { return(reader.ReadObject()); }
public virtual object ReadData(AMFReader reader, ClassDefinition classDefinition) { return _readDataMethod(reader, classDefinition); }
public object ReadData(AMFReader reader) { return(false); }
/// <summary> /// Loads the object from the specified input stream. /// </summary> /// <param name="reader">Reader to load from.</param> public void Deserialize(AMFReader reader) { this.RemoveAttributes(); IDictionary persistentAttributes = reader.ReadData() as IDictionary; this.SetAttributes(persistentAttributes); }
public DataInput(AMFReader amfReader) { _amfReader = amfReader; _objectEncoding = ObjectEncoding.AMF3; }