internal ObjectMap(string objectName, string[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, object[] typeInformationA, int[] memberAssemIds, ObjectReader objectReader, int objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable) { this.isInitObjectInfo = true; this.objectName = objectName; this.memberNames = memberNames; this.binaryTypeEnumA = binaryTypeEnumA; this.typeInformationA = typeInformationA; this.objectReader = objectReader; this.objectId = objectId; this.assemblyInfo = assemblyInfo; if (assemblyInfo == null) { throw new SerializationException(Environment.GetResourceString("Serialization_Assembly", new object[] { objectName })); } this.objectType = objectReader.GetType(assemblyInfo, objectName); this.memberTypes = new Type[memberNames.Length]; for (int i = 0; i < memberNames.Length; i++) { InternalPrimitiveTypeE ee; string str; Type type; bool flag; BinaryConverter.TypeFromInfo(binaryTypeEnumA[i], typeInformationA[i], objectReader, (BinaryAssemblyInfo) assemIdToAssemblyTable[memberAssemIds[i]], out ee, out str, out type, out flag); this.memberTypes[i] = type; } this.objectInfo = objectReader.CreateReadObjectInfo(this.objectType, memberNames, null); if (!this.objectInfo.isSi) { this.objectInfo.GetMemberTypes(memberNames, this.objectInfo.objectType); } }
internal object Deserialize(Stream serializationStream, bool check) { if (serializationStream == null) { throw new ArgumentNullException(nameof(serializationStream)); } if (serializationStream.CanSeek && (serializationStream.Length == 0)) { throw new SerializationException(SR.Serialization_Stream); } var formatterEnums = new InternalFE() { _typeFormat = _typeFormat, _serializerTypeEnum = InternalSerializerTypeE.Binary, _assemblyFormat = _assemblyFormat, _securityLevel = _securityLevel, }; var reader = new ObjectReader(serializationStream, _surrogates, _context, formatterEnums, _binder) { _crossAppDomainArray = _crossAppDomainArray }; var parser = new BinaryParser(serializationStream, reader); return reader.Deserialize(parser, check); }
internal ObjectMap(string objectName, Type objectType, string[] memberNames, ObjectReader objectReader, int objectId, BinaryAssemblyInfo assemblyInfo) { this.isInitObjectInfo = true; this.objectName = objectName; this.objectType = objectType; this.memberNames = memberNames; this.objectReader = objectReader; this.objectId = objectId; this.assemblyInfo = assemblyInfo; this.objectInfo = objectReader.CreateReadObjectInfo(objectType); this.memberTypes = this.objectInfo.GetMemberTypes(memberNames, objectType); this.binaryTypeEnumA = new BinaryTypeEnum[this.memberTypes.Length]; this.typeInformationA = new object[this.memberTypes.Length]; for (int i = 0; i < this.memberTypes.Length; i++) { object typeInformation = null; this.binaryTypeEnumA[i] = BinaryConverter.GetParserBinaryTypeInfo(this.memberTypes[i], out typeInformation); this.typeInformationA[i] = typeInformation; } }
internal object Deserialize(Stream serializationStream, HeaderHandler handler, bool fCheck, bool isCrossAppDomain, IMethodCallMessage methodCallMessage) { if (serializationStream == null) { throw new ArgumentNullException("serializationStream", Environment.GetResourceString("ArgumentNull_WithParamName", new object[] { serializationStream })); } if (serializationStream.CanSeek && (serializationStream.Length == 0L)) { throw new SerializationException(Environment.GetResourceString("Serialization_Stream")); } InternalFE formatterEnums = new InternalFE { FEtypeFormat = this.m_typeFormat, FEserializerTypeEnum = InternalSerializerTypeE.Binary, FEassemblyFormat = this.m_assemblyFormat, FEsecurityLevel = this.m_securityLevel }; ObjectReader objectReader = new ObjectReader(serializationStream, this.m_surrogates, this.m_context, formatterEnums, this.m_binder) { crossAppDomainArray = this.m_crossAppDomainArray }; return objectReader.Deserialize(handler, new __BinaryParser(serializationStream, objectReader), fCheck, isCrossAppDomain, methodCallMessage); }
public static object ReadMethodResponse (BinaryElement elem, BinaryReader reader, bool hasHeaders, HeaderHandler headerHandler, IMethodCallMessage methodCallMessage, BinaryFormatter formatter) { if (elem != BinaryElement.MethodResponse) throw new SerializationException("Invalid format. Expected BinaryElement.MethodResponse, found " + elem); MethodFlags flags = (MethodFlags) reader.ReadByte (); ReturnTypeTag typeTag = (ReturnTypeTag) reader.ReadByte (); bool hasContextInfo = (flags & MethodFlags.IncludesLogicalCallContext) > 0; // FIXME: find a meaning for those 2 bytes reader.ReadByte(); reader.ReadByte(); object returnValue = null; object[] outArgs = null; LogicalCallContext callContext = null; Exception exception = null; object[] extraProperties = null; Header[] headers = null; if ((typeTag & ReturnTypeTag.PrimitiveType) > 0) { Type type = BinaryCommon.GetTypeFromCode (reader.ReadByte()); returnValue = ObjectReader.ReadPrimitiveTypeValue (reader, type); } if ((flags & MethodFlags.PrimitiveArguments) > 0) { uint count = reader.ReadUInt32(); outArgs = new object[count]; for (int n=0; n<count; n++) { Type type = BinaryCommon.GetTypeFromCode (reader.ReadByte()); outArgs[n] = ObjectReader.ReadPrimitiveTypeValue (reader, type); } } if (hasContextInfo || (typeTag & ReturnTypeTag.ObjectType) > 0 || (typeTag & ReturnTypeTag.Exception) > 0 || (flags & MethodFlags.ArgumentsInSimpleArray) > 0 || (flags & MethodFlags.ArgumentsInMultiArray) > 0) { // There objects that need to be deserialized using an ObjectReader ObjectReader objectReader = new ObjectReader (formatter); object result; objectReader.ReadObjectGraph (reader, hasHeaders, out result, out headers); object[] msgInfo = (object[]) result; if ((typeTag & ReturnTypeTag.Exception) > 0) { exception = (Exception) msgInfo[0]; if (hasContextInfo) callContext = (LogicalCallContext)msgInfo[1]; } else if ((flags & MethodFlags.NoArguments) > 0 || (flags & MethodFlags.PrimitiveArguments) > 0) { int n = 0; if ((typeTag & ReturnTypeTag.ObjectType) > 0) returnValue = msgInfo [n++]; if (hasContextInfo) callContext = (LogicalCallContext)msgInfo[n++]; if (n < msgInfo.Length) extraProperties = (object[]) msgInfo[n]; } else if ((flags & MethodFlags.ArgumentsInSimpleArray) > 0) { outArgs = msgInfo; } else { int n = 0; outArgs = (object[]) msgInfo[n++]; if ((typeTag & ReturnTypeTag.ObjectType) > 0) returnValue = msgInfo[n++]; if (hasContextInfo) callContext = (LogicalCallContext)msgInfo[n++]; if (n < msgInfo.Length) extraProperties = (object[]) msgInfo[n]; } } else { reader.ReadByte (); // Reads the stream ender } if (headerHandler != null) headerHandler(headers); if (exception != null) return new ReturnMessage (exception, methodCallMessage); else { int argCount = (outArgs!=null) ? outArgs.Length : 0; ReturnMessage result = new ReturnMessage (returnValue, outArgs, argCount, callContext, methodCallMessage); if (extraProperties != null) { foreach (DictionaryEntry entry in extraProperties) result.Properties [(string)entry.Key] = entry.Value; } return result; } }
public static object ReadMethodCall(BinaryElement elem, BinaryReader reader, bool hasHeaders, HeaderHandler headerHandler, BinaryFormatter formatter) { if (elem != BinaryElement.MethodCall) { throw new SerializationException("Invalid format. Expected BinaryElement.MethodCall, found " + elem); } MethodFlags methodFlags = (MethodFlags)reader.ReadInt32(); if (reader.ReadByte() != 18) { throw new SerializationException("Invalid format"); } string value = reader.ReadString(); if (reader.ReadByte() != 18) { throw new SerializationException("Invalid format"); } string value2 = reader.ReadString(); object[] array = null; object value3 = null; object value4 = null; object[] array2 = null; Header[] headers = null; Type[] value5 = null; if ((methodFlags & MethodFlags.PrimitiveArguments) > (MethodFlags)0) { uint num = reader.ReadUInt32(); array = new object[num]; int num2 = 0; while ((long)num2 < (long)((ulong)num)) { Type typeFromCode = BinaryCommon.GetTypeFromCode((int)reader.ReadByte()); array[num2] = ObjectReader.ReadPrimitiveTypeValue(reader, typeFromCode); num2++; } } if ((methodFlags & MethodFlags.NeedsInfoArrayMask) > (MethodFlags)0) { ObjectReader objectReader = new ObjectReader(formatter); object obj; objectReader.ReadObjectGraph(reader, hasHeaders, out obj, out headers); object[] array3 = (object[])obj; if ((methodFlags & MethodFlags.ArgumentsInSimpleArray) > (MethodFlags)0) { array = array3; } else { int num3 = 0; if ((methodFlags & MethodFlags.ArgumentsInMultiArray) > (MethodFlags)0) { if (array3.Length > 1) { array = (object[])array3[num3++]; } else { array = new object[0]; } } if ((methodFlags & MethodFlags.GenericArguments) > (MethodFlags)0) { value5 = (Type[])array3[num3++]; } if ((methodFlags & MethodFlags.IncludesSignature) > (MethodFlags)0) { value3 = array3[num3++]; } if ((methodFlags & MethodFlags.IncludesLogicalCallContext) > (MethodFlags)0) { value4 = array3[num3++]; } if (num3 < array3.Length) { array2 = (object[])array3[num3]; } } } else { reader.ReadByte(); } if (array == null) { array = new object[0]; } string value6 = null; if (headerHandler != null) { value6 = (headerHandler(headers) as string); } MethodCall methodCall = new MethodCall(new Header[] { new Header("__MethodName", value), new Header("__MethodSignature", value3), new Header("__TypeName", value2), new Header("__Args", array), new Header("__CallContext", value4), new Header("__Uri", value6), new Header("__GenericArguments", value5) }); if (array2 != null) { foreach (DictionaryEntry dictionaryEntry in array2) { methodCall.Properties[(string)dictionaryEntry.Key] = dictionaryEntry.Value; } } return(methodCall); }
public static object ReadMethodCall (BinaryElement elem, BinaryReader reader, bool hasHeaders, HeaderHandler headerHandler, BinaryFormatter formatter) { if (elem != BinaryElement.MethodCall) throw new SerializationException("Invalid format. Expected BinaryElement.MethodCall, found " + elem); MethodFlags flags = (MethodFlags) reader.ReadInt32(); if (((BinaryTypeCode)reader.ReadByte()) != BinaryTypeCode.String) throw new SerializationException ("Invalid format"); string methodName = reader.ReadString(); if (((BinaryTypeCode)reader.ReadByte()) != BinaryTypeCode.String) throw new SerializationException ("Invalid format"); string className = reader.ReadString(); //bool hasContextInfo = (flags & MethodFlags.IncludesLogicalCallContext) > 0; object[] arguments = null; object methodSignature = null; object callContext = null; object[] extraProperties = null; Header[] headers = null; #if NET_2_0 Type[] genericArguments = null; #endif if ((flags & MethodFlags.PrimitiveArguments) > 0) { uint count = reader.ReadUInt32(); arguments = new object[count]; for (int n=0; n<count; n++) { Type type = BinaryCommon.GetTypeFromCode (reader.ReadByte()); arguments[n] = ObjectReader.ReadPrimitiveTypeValue (reader, type); } } if ((flags & MethodFlags.NeedsInfoArrayMask) > 0) { ObjectReader objectReader = new ObjectReader (formatter); object result; objectReader.ReadObjectGraph (reader, hasHeaders, out result, out headers); object[] msgInfo = (object[]) result; if ((flags & MethodFlags.ArgumentsInSimpleArray) > 0) { arguments = msgInfo; } else { int n = 0; if ((flags & MethodFlags.ArgumentsInMultiArray) > 0) { if (msgInfo.Length > 1) arguments = (object[]) msgInfo[n++]; else arguments = new object[0]; } #if NET_2_0 if ((flags & MethodFlags.GenericArguments) > 0) genericArguments = (Type[]) msgInfo[n++]; #endif if ((flags & MethodFlags.IncludesSignature) > 0) methodSignature = msgInfo[n++]; if ((flags & MethodFlags.IncludesLogicalCallContext) > 0) callContext = msgInfo[n++]; if (n < msgInfo.Length) extraProperties = (object[]) msgInfo[n]; } } else { reader.ReadByte (); // Reads the stream ender } if (arguments == null) arguments = new object[0]; string uri = null; if (headerHandler != null) uri = headerHandler(headers) as string; #if NET_2_0 Header[] methodInfo = new Header[7]; #else Header[] methodInfo = new Header[6]; #endif methodInfo[0] = new Header("__MethodName", methodName); methodInfo[1] = new Header("__MethodSignature", methodSignature); methodInfo[2] = new Header("__TypeName", className); methodInfo[3] = new Header("__Args", arguments); methodInfo[4] = new Header("__CallContext", callContext); methodInfo[5] = new Header("__Uri", uri); #if NET_2_0 methodInfo[6] = new Header("__GenericArguments", genericArguments); #endif MethodCall call = new MethodCall (methodInfo); if (extraProperties != null) { foreach (DictionaryEntry entry in extraProperties) call.Properties [(string)entry.Key] = entry.Value; } return call; }
internal __BinaryParser(Stream stream, ObjectReader objectReader) { input = stream; this.objectReader = objectReader; dataReader = new BinaryReader(input, new UTF8Encoding(false, true)); }
public static object ReadMethodResponse(BinaryElement elem, BinaryReader reader, bool hasHeaders, HeaderHandler headerHandler, IMethodCallMessage methodCallMessage, BinaryFormatter formatter) { if (elem != BinaryElement.MethodResponse) { throw new SerializationException("Invalid format. Expected BinaryElement.MethodResponse, found " + elem); } MethodFlags methodFlags = (MethodFlags)reader.ReadByte(); ReturnTypeTag returnTypeTag = (ReturnTypeTag)reader.ReadByte(); bool flag = (methodFlags & MethodFlags.IncludesLogicalCallContext) > (MethodFlags)0; reader.ReadByte(); reader.ReadByte(); object ret = null; object[] array = null; LogicalCallContext callCtx = null; Exception ex = null; object[] array2 = null; Header[] headers = null; if ((byte)(returnTypeTag & ReturnTypeTag.PrimitiveType) > 0) { Type typeFromCode = BinaryCommon.GetTypeFromCode((int)reader.ReadByte()); ret = ObjectReader.ReadPrimitiveTypeValue(reader, typeFromCode); } if ((methodFlags & MethodFlags.PrimitiveArguments) > (MethodFlags)0) { uint num = reader.ReadUInt32(); array = new object[num]; int num2 = 0; while ((long)num2 < (long)((ulong)num)) { Type typeFromCode2 = BinaryCommon.GetTypeFromCode((int)reader.ReadByte()); array[num2] = ObjectReader.ReadPrimitiveTypeValue(reader, typeFromCode2); num2++; } } if (flag || (byte)(returnTypeTag & ReturnTypeTag.ObjectType) > 0 || (byte)(returnTypeTag & ReturnTypeTag.Exception) > 0 || (methodFlags & MethodFlags.ArgumentsInSimpleArray) > (MethodFlags)0 || (methodFlags & MethodFlags.ArgumentsInMultiArray) > (MethodFlags)0) { ObjectReader objectReader = new ObjectReader(formatter); object obj; objectReader.ReadObjectGraph(reader, hasHeaders, out obj, out headers); object[] array3 = (object[])obj; if ((byte)(returnTypeTag & ReturnTypeTag.Exception) > 0) { ex = (Exception)array3[0]; if (flag) { callCtx = (LogicalCallContext)array3[1]; } } else if ((methodFlags & MethodFlags.NoArguments) > (MethodFlags)0 || (methodFlags & MethodFlags.PrimitiveArguments) > (MethodFlags)0) { int num3 = 0; if ((byte)(returnTypeTag & ReturnTypeTag.ObjectType) > 0) { ret = array3[num3++]; } if (flag) { callCtx = (LogicalCallContext)array3[num3++]; } if (num3 < array3.Length) { array2 = (object[])array3[num3]; } } else if ((methodFlags & MethodFlags.ArgumentsInSimpleArray) > (MethodFlags)0) { array = array3; } else { int num4 = 0; array = (object[])array3[num4++]; if ((byte)(returnTypeTag & ReturnTypeTag.ObjectType) > 0) { ret = array3[num4++]; } if (flag) { callCtx = (LogicalCallContext)array3[num4++]; } if (num4 < array3.Length) { array2 = (object[])array3[num4]; } } } else { reader.ReadByte(); } if (headerHandler != null) { headerHandler(headers); } if (ex != null) { return(new ReturnMessage(ex, methodCallMessage)); } int outArgsCount = (array == null) ? 0 : array.Length; ReturnMessage returnMessage = new ReturnMessage(ret, array, outArgsCount, callCtx, methodCallMessage); if (array2 != null) { foreach (DictionaryEntry dictionaryEntry in array2) { returnMessage.Properties[(string)dictionaryEntry.Key] = dictionaryEntry.Value; } } return(returnMessage); }
[System.Security.SecurityCritical] // auto-generated internal ObjectMap(String objectName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, int[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable) { SerTrace.Log( this, "Constructor 2 objectName ",objectName); this.objectName = objectName; this.memberNames = memberNames; this.binaryTypeEnumA = binaryTypeEnumA; this.typeInformationA = typeInformationA; this.objectReader = objectReader; this.objectId = objectId; this.assemblyInfo = assemblyInfo; if (assemblyInfo == null) throw new SerializationException(Environment.GetResourceString("Serialization_Assembly",objectName)); objectType = objectReader.GetType(assemblyInfo, objectName); memberTypes = new Type[memberNames.Length]; for (int i=0; i<memberNames.Length; i++) { InternalPrimitiveTypeE primitiveTypeEnum; String typeString; Type type; bool isVariant; BinaryConverter.TypeFromInfo(binaryTypeEnumA[i], typeInformationA[i], objectReader, (BinaryAssemblyInfo)assemIdToAssemblyTable[memberAssemIds[i]], out primitiveTypeEnum, out typeString, out type, out isVariant); //if ((object)type == null) // throw new SerializationException(String.Format(Environment.GetResourceString("Serialization_TypeResolved"),objectName+" "+memberNames[i]+" "+typeInformationA[i])); memberTypes[i] = type; } objectInfo = objectReader.CreateReadObjectInfo(objectType, memberNames, null); if (!objectInfo.isSi) objectInfo.GetMemberTypes(memberNames, objectInfo.objectType); // Check version match }
// Given the wire type information, returns the actual type and additional information internal static void TypeFromInfo(BinaryTypeEnum binaryTypeEnum, object typeInformation, ObjectReader objectReader, BinaryAssemblyInfo assemblyInfo, out InternalPrimitiveTypeE primitiveTypeEnum, out string typeString, out Type type, out bool isVariant) { isVariant = false; primitiveTypeEnum = InternalPrimitiveTypeE.Invalid; typeString = null; type = null; switch (binaryTypeEnum) { case BinaryTypeEnum.Primitive: primitiveTypeEnum = (InternalPrimitiveTypeE)typeInformation; typeString = Converter.ToComType(primitiveTypeEnum); type = Converter.ToType(primitiveTypeEnum); break; case BinaryTypeEnum.String: type = Converter.s_typeofString; break; case BinaryTypeEnum.Object: type = Converter.s_typeofObject; isVariant = true; break; case BinaryTypeEnum.ObjectArray: type = Converter.s_typeofObjectArray; break; case BinaryTypeEnum.StringArray: type = Converter.s_typeofStringArray; break; case BinaryTypeEnum.PrimitiveArray: primitiveTypeEnum = (InternalPrimitiveTypeE)typeInformation; type = Converter.ToArrayType(primitiveTypeEnum); break; case BinaryTypeEnum.ObjectUser: case BinaryTypeEnum.ObjectUrt: if (typeInformation != null) { typeString = typeInformation.ToString(); type = objectReader.GetType(assemblyInfo, typeString); if (ReferenceEquals(type, Converter.s_typeofObject)) { isVariant = true; } } break; default: throw new SerializationException(SR.Format(SR.Serialization_TypeRead, binaryTypeEnum.ToString())); } }
internal static ObjectMap Create(string name, string[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, object[] typeInformationA, int[] memberAssemIds, ObjectReader objectReader, int objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable) { return(new ObjectMap(name, memberNames, binaryTypeEnumA, typeInformationA, memberAssemIds, objectReader, objectId, assemblyInfo, assemIdToAssemblyTable)); }
[System.Security.SecurityCritical] // auto-generated internal static ObjectMap Create(String name, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, int[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable) { return new ObjectMap(name, memberNames, binaryTypeEnumA, typeInformationA, memberAssemIds, objectReader, objectId, assemblyInfo, assemIdToAssemblyTable); }
internal ObjectMap(string objectName, string[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, object[] typeInformationA, int[] memberAssemIds, ObjectReader objectReader, int objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable) { this.objectName = objectName; this.memberNames = memberNames; this.binaryTypeEnumA = binaryTypeEnumA; this.typeInformationA = typeInformationA; this.objectReader = objectReader; this.objectId = objectId; this.assemblyInfo = assemblyInfo; if (assemblyInfo == null) { throw new SerializationException(Environment.GetResourceString("Serialization_Assembly", (object)objectName)); } this.objectType = objectReader.GetType(assemblyInfo, objectName); this.memberTypes = new Type[memberNames.Length]; for (int index = 0; index < memberNames.Length; ++index) { InternalPrimitiveTypeE primitiveTypeEnum; string typeString; Type type; bool isVariant; BinaryConverter.TypeFromInfo(binaryTypeEnumA[index], typeInformationA[index], objectReader, (BinaryAssemblyInfo)assemIdToAssemblyTable[memberAssemIds[index]], out primitiveTypeEnum, out typeString, out type, out isVariant); this.memberTypes[index] = type; } this.objectInfo = objectReader.CreateReadObjectInfo(this.objectType, memberNames, (Type[])null); if (this.objectInfo.isSi) { return; } this.objectInfo.GetMemberTypes(memberNames, this.objectInfo.objectType); }
internal static ObjectMap Create(string name, Type objectType, string[] memberNames, ObjectReader objectReader, int objectId, BinaryAssemblyInfo assemblyInfo) { return(new ObjectMap(name, objectType, memberNames, objectReader, objectId, assemblyInfo)); }
internal ObjectMap(string objectName, string[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, object[] typeInformationA, int[] memberAssemIds, ObjectReader objectReader, int objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable) { this.objectName = objectName; this.memberNames = memberNames; this.binaryTypeEnumA = binaryTypeEnumA; this.typeInformationA = typeInformationA; this.objectReader = objectReader; this.objectId = objectId; this.assemblyInfo = assemblyInfo; if (assemblyInfo == null) { throw new SerializationException(Environment.GetResourceString("Serialization_Assembly", new object[] { objectName })); } this.objectType = objectReader.GetType(assemblyInfo, objectName); this.memberTypes = new Type[memberNames.Length]; for (int i = 0; i < memberNames.Length; i++) { InternalPrimitiveTypeE internalPrimitiveTypeE; string text; Type type; bool flag; BinaryConverter.TypeFromInfo(binaryTypeEnumA[i], typeInformationA[i], objectReader, (BinaryAssemblyInfo)assemIdToAssemblyTable[memberAssemIds[i]], out internalPrimitiveTypeE, out text, out type, out flag); this.memberTypes[i] = type; } this.objectInfo = objectReader.CreateReadObjectInfo(this.objectType, memberNames, null); if (!this.objectInfo.isSi) { this.objectInfo.GetMemberTypes(memberNames, this.objectInfo.objectType); } }
internal Type FastBindToType(string assemblyName, string typeName) { Type type = (Type)null; ObjectReader.TypeNAssembly typeNassembly = (ObjectReader.TypeNAssembly) this.typeCache.GetCachedValue(typeName); if (typeNassembly == null || typeNassembly.assemblyName != assemblyName) { Assembly assembly = (Assembly)null; if (this.bSimpleAssembly) { try { ObjectReader.sfileIOPermission.Assert(); try { assembly = ObjectReader.ResolveSimpleAssemblyName(new AssemblyName(assemblyName)); } finally { CodeAccessPermission.RevertAssert(); } } catch (Exception ex) { } if (assembly == (Assembly)null) { return((Type)null); } ObjectReader.GetSimplyNamedTypeFromAssembly(assembly, typeName, ref type); } else { try { ObjectReader.sfileIOPermission.Assert(); try { assembly = Assembly.Load(assemblyName); } finally { CodeAccessPermission.RevertAssert(); } } catch (Exception ex) { } if (assembly == (Assembly)null) { return((Type)null); } type = FormatterServices.GetTypeFromAssembly(assembly, typeName); } if (type == null) { return((Type)null); } ObjectReader.CheckTypeForwardedTo(assembly, type.Assembly, type); typeNassembly = new ObjectReader.TypeNAssembly(); typeNassembly.type = type; typeNassembly.assemblyName = assemblyName; this.typeCache.SetCachedValue((object)typeNassembly); } return(typeNassembly.type); }
internal static void TypeFromInfo(BinaryTypeEnum binaryTypeEnum, object typeInformation, ObjectReader objectReader, BinaryAssemblyInfo assemblyInfo, out InternalPrimitiveTypeE primitiveTypeEnum, out string typeString, out Type type, out bool isVariant) { isVariant = false; primitiveTypeEnum = InternalPrimitiveTypeE.Invalid; typeString = null; type = null; switch (binaryTypeEnum) { case BinaryTypeEnum.Primitive: primitiveTypeEnum = (InternalPrimitiveTypeE)typeInformation; typeString = Converter.ToComType(primitiveTypeEnum); type = Converter.ToType(primitiveTypeEnum); return; case BinaryTypeEnum.String: type = Converter.typeofString; return; case BinaryTypeEnum.Object: type = Converter.typeofObject; isVariant = true; return; case BinaryTypeEnum.ObjectUrt: case BinaryTypeEnum.ObjectUser: if (typeInformation != null) { typeString = typeInformation.ToString(); type = objectReader.GetType(assemblyInfo, typeString); if (type == Converter.typeofObject) { isVariant = true; return; } } return; case BinaryTypeEnum.ObjectArray: type = Converter.typeofObjectArray; return; case BinaryTypeEnum.StringArray: type = Converter.typeofStringArray; return; case BinaryTypeEnum.PrimitiveArray: primitiveTypeEnum = (InternalPrimitiveTypeE)typeInformation; type = Converter.ToArrayType(primitiveTypeEnum); return; default: throw new SerializationException(Environment.GetResourceString("Serialization_TypeRead", new object[] { binaryTypeEnum.ToString() })); } }
[System.Security.SecurityCritical] // auto-generated internal static void TypeFromInfo(BinaryTypeEnum binaryTypeEnum, Object typeInformation, ObjectReader objectReader, BinaryAssemblyInfo assemblyInfo, out InternalPrimitiveTypeE primitiveTypeEnum, out String typeString, out Type type, out bool isVariant) { SerTrace.Log( "BinaryConverter", "TypeFromInfo Entry ",((Enum)binaryTypeEnum).ToString()); isVariant = false; primitiveTypeEnum = InternalPrimitiveTypeE.Invalid; typeString = null; type = null; switch (binaryTypeEnum) { case BinaryTypeEnum.Primitive: primitiveTypeEnum = (InternalPrimitiveTypeE)typeInformation; typeString = Converter.ToComType(primitiveTypeEnum); type = Converter.ToType(primitiveTypeEnum); break; case BinaryTypeEnum.String: //typeString = "System.String"; type = Converter.typeofString; break; case BinaryTypeEnum.Object: //typeString = "System.Object"; type = Converter.typeofObject; isVariant = true; break; case BinaryTypeEnum.ObjectArray: //typeString = "System.Object[]"; type = Converter.typeofObjectArray; break; case BinaryTypeEnum.StringArray: //typeString = "System.String[]"; type = Converter.typeofStringArray; break; case BinaryTypeEnum.PrimitiveArray: primitiveTypeEnum = (InternalPrimitiveTypeE)typeInformation; type = Converter.ToArrayType(primitiveTypeEnum); break; case BinaryTypeEnum.ObjectUser: case BinaryTypeEnum.ObjectUrt: if (typeInformation != null) { typeString = typeInformation.ToString(); type = objectReader.GetType(assemblyInfo, typeString); // Temporary for backward compatibility if (Object.ReferenceEquals(type, Converter.typeofObject)) isVariant = true; } break; default: throw new SerializationException(Environment.GetResourceString("Serialization_TypeRead",((Enum)binaryTypeEnum).ToString())); } #if _DEBUG SerTrace.Log( "BinaryConverter", "TypeFromInfo Exit " ,((Enum)primitiveTypeEnum).ToString(),",typeString ",Util.PString(typeString) ,", type ",Util.PString(type),", isVariant ",isVariant); #endif }
internal static void TypeFromInfo(BinaryTypeEnum binaryTypeEnum, object typeInformation, ObjectReader objectReader, BinaryAssemblyInfo assemblyInfo, out InternalPrimitiveTypeE primitiveTypeEnum, out string typeString, out Type type, out bool isVariant) { isVariant = false; primitiveTypeEnum = InternalPrimitiveTypeE.Invalid; typeString = null; type = null; switch (binaryTypeEnum) { case BinaryTypeEnum.Primitive: primitiveTypeEnum = (InternalPrimitiveTypeE) typeInformation; typeString = Converter.ToComType(primitiveTypeEnum); type = Converter.ToType(primitiveTypeEnum); return; case BinaryTypeEnum.String: type = Converter.typeofString; return; case BinaryTypeEnum.Object: type = Converter.typeofObject; isVariant = true; return; case BinaryTypeEnum.ObjectUrt: case BinaryTypeEnum.ObjectUser: if (typeInformation == null) { break; } typeString = typeInformation.ToString(); type = objectReader.GetType(assemblyInfo, typeString); if (!object.ReferenceEquals(type, Converter.typeofObject)) { break; } isVariant = true; return; case BinaryTypeEnum.ObjectArray: type = Converter.typeofObjectArray; return; case BinaryTypeEnum.StringArray: type = Converter.typeofStringArray; return; case BinaryTypeEnum.PrimitiveArray: primitiveTypeEnum = (InternalPrimitiveTypeE) typeInformation; type = Converter.ToArrayType(primitiveTypeEnum); return; default: throw new SerializationException(Environment.GetResourceString("Serialization_TypeRead", new object[] { binaryTypeEnum.ToString() })); } }
[System.Security.SecurityCritical] // auto-generated internal ObjectMap(String objectName, Type objectType, String[] memberNames, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo) { SerTrace.Log( this, "Constructor 1 objectName ",objectName, ", objectType ",objectType); this.objectName = objectName; this.objectType = objectType; this.memberNames = memberNames; this.objectReader = objectReader; this.objectId = objectId; this.assemblyInfo = assemblyInfo; objectInfo = objectReader.CreateReadObjectInfo(objectType); memberTypes = objectInfo.GetMemberTypes(memberNames, objectType); binaryTypeEnumA = new BinaryTypeEnum[memberTypes.Length]; typeInformationA = new Object[memberTypes.Length]; for (int i=0; i<memberTypes.Length; i++) { Object typeInformation = null; BinaryTypeEnum binaryTypeEnum = BinaryConverter.GetParserBinaryTypeInfo(memberTypes[i], out typeInformation); binaryTypeEnumA[i] = binaryTypeEnum; typeInformationA[i] = typeInformation; } }
internal __BinaryParser(Stream stream, ObjectReader objectReader) { input = stream; this.objectReader = objectReader; dataReader = new BinaryReader(input, encoding); }
[System.Security.SecurityCritical] // auto-generated internal static ObjectMap Create(String name, Type objectType, String[] memberNames, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo) { return new ObjectMap(name, objectType, memberNames, objectReader, objectId, assemblyInfo); }
internal BinaryParser(Stream stream, ObjectReader objectReader) { _input = stream; _objectReader = objectReader; _dataReader = new BinaryReader(_input, s_encoding); }
// shared by Deserialize and UnsafeDeserialize which both involve different security checks private object NoCheckDeserialize (Stream serializationStream, HeaderHandler handler) { if(serializationStream==null) { throw new ArgumentNullException("serializationStream"); } if(serializationStream.CanSeek && serializationStream.Length==0) { throw new SerializationException("serializationStream supports seeking, but its length is 0"); } BinaryReader reader = new BinaryReader (serializationStream); bool hasHeader; ReadBinaryHeader (reader, out hasHeader); // Messages are read using a special static method, which does not use ObjectReader // if it is not needed. This saves time and memory. BinaryElement elem = (BinaryElement) reader.Read (); if (elem == BinaryElement.MethodCall) { return MessageFormatter.ReadMethodCall (elem, reader, hasHeader, handler, this); } else if (elem == BinaryElement.MethodResponse) { return MessageFormatter.ReadMethodResponse (elem, reader, hasHeader, handler, null, this); } else { ObjectReader serializer = new ObjectReader (this); object result; Header[] headers; serializer.ReadObjectGraph (elem, reader, hasHeader, out result, out headers); if (handler != null) handler(headers); return result; } }
// Deserialize the stream into an object graph. internal Object Deserialize(Stream serializationStream, HeaderHandler handler, bool fCheck, bool isCrossAppDomain, IMethodCallMessage methodCallMessage) { if (serializationStream==null) { throw new ArgumentNullException("serializationStream", String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentNull_WithParamName"),serializationStream)); } if (serializationStream.CanSeek && (serializationStream.Length == 0)) throw new SerializationException(Environment.GetResourceString("Serialization_Stream")); SerTrace.Log(this, "Deserialize Entry"); InternalFE formatterEnums = new InternalFE(); formatterEnums.FEtypeFormat = m_typeFormat; formatterEnums.FEserializerTypeEnum = InternalSerializerTypeE.Binary; formatterEnums.FEassemblyFormat = m_assemblyFormat; formatterEnums.FEsecurityLevel = m_securityLevel; ObjectReader sor = new ObjectReader(serializationStream, m_surrogates, m_context, formatterEnums, m_binder); sor.crossAppDomainArray = m_crossAppDomainArray; return sor.Deserialize(handler, new __BinaryParser(serializationStream, sor), fCheck, isCrossAppDomain, methodCallMessage); }
[System.Security.SecurityCritical] // auto-generated internal Object Deserialize(Stream serializationStream, HeaderHandler handler, bool fCheck) { #if FEATURE_REMOTING return Deserialize(serializationStream, handler, fCheck, null); #else if (serializationStream == null) { throw new ArgumentNullException("serializationStream", Environment.GetResourceString("ArgumentNull_WithParamName", serializationStream)); } Contract.EndContractBlock(); if (serializationStream.CanSeek && (serializationStream.Length == 0)) throw new SerializationException(Environment.GetResourceString("Serialization_Stream")); SerTrace.Log(this, "Deserialize Entry"); InternalFE formatterEnums = new InternalFE(); formatterEnums.FEtypeFormat = m_typeFormat; formatterEnums.FEserializerTypeEnum = InternalSerializerTypeE.Binary; formatterEnums.FEassemblyFormat = m_assemblyFormat; formatterEnums.FEsecurityLevel = m_securityLevel; ObjectReader sor = new ObjectReader(serializationStream, m_surrogates, m_context, formatterEnums, m_binder); sor.crossAppDomainArray = m_crossAppDomainArray; return sor.Deserialize(handler, new __BinaryParser(serializationStream, sor), fCheck); #endif }