private void ParseSerializedStreamHeader(ParseRecord pr) { this.stack.Push(pr); }
private void RegisterObject(object obj, ParseRecord pr, ParseRecord objectPr) { this.RegisterObject(obj, pr, objectPr, false); }
private void ParseError(ParseRecord processing, ParseRecord onStack) { string[] textArray1 = new string[] { onStack.name, " ", onStack.parseTypeEnum.ToString(), " ", processing.name, " ", processing.parseTypeEnum.ToString() }; throw new SerializationException(RemotingResources.SerializationParseError.Format(string.Concat(textArray1))); }
private void ParseMember(ParseRecord pr) { ParseRecord onStack = (ParseRecord)this.stack.Peek(); //string str = (onStack != null) ? onStack.name : null; MemberTypeEnum ee = pr.memberTypeEnum; if ((ee != MemberTypeEnum.Field) && (ee == MemberTypeEnum.Item)) { this.ParseArrayMember(pr); } else { if ((pr.dtType == null) && onStack.objectInfo.IsTyped) { pr.dtType = onStack.objectInfo.GetType(pr.name); if (pr.dtType != null) { pr.dtTypeCode = Converter.ToCode(pr.dtType); } } if (pr.memberValueEnum == MemberValueEnum.Null) { onStack.objectInfo.AddValue(pr.name, null, ref onStack.si, ref onStack.memberData); } else if (pr.memberValueEnum == MemberValueEnum.Nested) { this.ParseObject(pr); this.stack.Push(pr); if ((pr.objectInfo == null) || ((pr.objectInfo.ObjectType == null) || !pr.objectInfo.ObjectType.IsValueType)) { onStack.objectInfo.AddValue(pr.name, pr.newObj, ref onStack.si, ref onStack.memberData); } else { pr.isValueTypeFixup = true; this.ValueFixupStack.Push(new ValueFixup(onStack.newObj, pr.name, onStack.objectInfo)); } } else if (pr.memberValueEnum == MemberValueEnum.Reference) { object obj2 = this.objectManager.GetObject(pr.idRef); if (obj2 != null) { onStack.objectInfo.AddValue(pr.name, obj2, ref onStack.si, ref onStack.memberData); } else { onStack.objectInfo.AddValue(pr.name, null, ref onStack.si, ref onStack.memberData); onStack.objectInfo.RecordFixup(onStack.objectId, pr.name, pr.idRef); } } else if (pr.memberValueEnum != MemberValueEnum.InlineValue) { this.ParseError(pr, onStack); } else if (object.ReferenceEquals(pr.dtType, Converter.s_typeofString)) { this.ParseString(pr, onStack); onStack.objectInfo.AddValue(pr.name, pr.value, ref onStack.si, ref onStack.memberData); } else if (pr.dtTypeCode != PrimitiveTypeEnum.Invalid) { object obj3 = pr.varValue ?? Converter.FromString(pr.value, pr.dtTypeCode); onStack.objectInfo.AddValue(pr.name, obj3, ref onStack.si, ref onStack.memberData); } else if (pr.arrayTypeEnum == ArrayTypeEnum.Base64) { onStack.objectInfo.AddValue(pr.name, Convert.FromBase64String(pr.value), ref onStack.si, ref onStack.memberData); } else { if (object.ReferenceEquals(pr.dtType, Converter.s_typeofObject)) { throw new SerializationException(RemotingResources.SerializationTypeMissing.Format(pr.name)); } this.ParseString(pr, onStack); if (object.ReferenceEquals(pr.dtType, Converter.s_typeofSystemVoid)) { onStack.objectInfo.AddValue(pr.name, pr.dtType, ref onStack.si, ref onStack.memberData); } else if (onStack.objectInfo.IsSi) { onStack.objectInfo.AddValue(pr.name, pr.value, ref onStack.si, ref onStack.memberData); } } } }
private void ParseArrayMember(ParseRecord pr) { ParseRecord record = (ParseRecord)this.stack.Peek(); if (record.arrayTypeEnum != ArrayTypeEnum.Rectangular) { record.indexMap[0] = !record.isLowerBound ? record.memberIndex : (record.lowerBoundA[0] + record.memberIndex); } else { if (record.memberIndex > 0) { this.NextRectangleMap(record); } if (record.isLowerBound) { for (int i = 0; i < record.rank; i++) { record.indexMap[i] = record.rectangularMap[i] + record.lowerBoundA[i]; } } } if (pr.memberValueEnum == MemberValueEnum.Reference) { object obj2 = this.objectManager.GetObject(pr.idRef); if (obj2 == null) { int[] destinationArray = new int[record.rank]; Array.Copy(record.indexMap, 0, destinationArray, 0, record.rank); this.objectManager.RecordArrayElementFixup(record.objectId, destinationArray, pr.idRef); } else if (record.objectA != null) { record.objectA[record.indexMap[0]] = obj2; } else { ((Array)record.newObj).SetValue(obj2, record.indexMap); } } else if (pr.memberValueEnum == MemberValueEnum.Nested) { if (pr.dtType == null) { pr.dtType = record.arrayElementType; } this.ParseObject(pr); this.stack.Push(pr); if (record.arrayElementType != null) { if (record.arrayElementType.IsValueType && (pr.arrayElementTypeCode == PrimitiveTypeEnum.Invalid)) { pr.isValueTypeFixup = true; this.ValueFixupStack.Push(new ValueFixup((Array)record.newObj, record.indexMap)); } else if (record.objectA != null) { record.objectA[record.indexMap[0]] = pr.newObj; } else { ((Array)record.newObj).SetValue(pr.newObj, record.indexMap); } } } else if (pr.memberValueEnum != MemberValueEnum.InlineValue) { if (pr.memberValueEnum == MemberValueEnum.Null) { record.memberIndex += pr.consecutiveNullArrayEntryCount - 1; } else { this.ParseError(pr, record); } } else if (object.ReferenceEquals(record.arrayElementType, Converter.s_typeofString) || object.ReferenceEquals(pr.dtType, Converter.s_typeofString)) { this.ParseString(pr, record); if (record.objectA != null) { record.objectA[record.indexMap[0]] = pr.value; } else { ((Array)record.newObj).SetValue(pr.value, record.indexMap); } } else if (!record.isArrayVariant) { if (record.primitiveArray != null) { record.primitiveArray.SetValue(pr.value, record.indexMap[0]); } else { object obj4 = pr.varValue ?? Converter.FromString(pr.value, record.arrayElementTypeCode); if (record.objectA != null) { record.objectA[record.indexMap[0]] = obj4; } else { ((Array)record.newObj).SetValue(obj4, record.indexMap); } } } else { if (pr.keyDt == null) { throw new SerializationException(RemotingResources.SerializationArrayTypeObjectNotInitialized); } object uninitializedObject; if (object.ReferenceEquals(pr.dtType, Converter.s_typeofString)) { this.ParseString(pr, record); uninitializedObject = pr.value; } else if (pr.dtTypeCode != PrimitiveTypeEnum.Invalid) { uninitializedObject = pr.varValue ?? Converter.FromString(pr.value, pr.dtTypeCode); } else { this.CheckSerializable(pr.dtType); uninitializedObject = FormatterServices.GetUninitializedObject(pr.dtType); } if (record.objectA != null) { record.objectA[record.indexMap[0]] = uninitializedObject; } else { ((Array)record.newObj).SetValue(uninitializedObject, record.indexMap); } } record.memberIndex++; }
private void ParseArray(ParseRecord pr) { //long num = pr.objectId; if (pr.arrayTypeEnum == ArrayTypeEnum.Base64) { pr.newObj = (pr.value.Length > 0) ? Convert.FromBase64String(pr.value) : Array.Empty <byte>(); if (this.stack.Peek() == pr) { this.stack.Pop(); } if (pr.objectPositionEnum == ObjectPositionEnum.Top) { this.TopObject = pr.newObj; } ParseRecord objectPr = (ParseRecord)this.stack.Peek(); this.RegisterObject(pr.newObj, pr, objectPr); } else if ((pr.newObj != null) && Converter.IsWriteAsByteArray(pr.arrayElementTypeCode)) { if (pr.objectPositionEnum == ObjectPositionEnum.Top) { this.TopObject = pr.newObj; } ParseRecord objectPr = (ParseRecord)this.stack.Peek(); this.RegisterObject(pr.newObj, pr, objectPr); } else if ((pr.arrayTypeEnum != ArrayTypeEnum.Jagged) && (pr.arrayTypeEnum != ArrayTypeEnum.Single)) { if (pr.arrayTypeEnum != ArrayTypeEnum.Rectangular) { throw new SerializationException(RemotingResources.SerializationArrayType.Format(pr.arrayTypeEnum)); } pr.isLowerBound = false; if (pr.lowerBoundA != null) { for (int j = 0; j < pr.rank; j++) { if (pr.lowerBoundA[j] != 0) { pr.isLowerBound = true; } } } if (pr.arrayElementType != null) { pr.newObj = !pr.isLowerBound ? Array.CreateInstance(pr.arrayElementType, pr.lengthA) : Array.CreateInstance(pr.arrayElementType, pr.lengthA, pr.lowerBoundA); } int num2 = 1; for (int i = 0; i < pr.rank; i++) { num2 *= pr.lengthA[i]; } pr.indexMap = new int[pr.rank]; pr.rectangularMap = new int[pr.rank]; pr.linearlength = num2; } else { bool flag = true; if ((pr.lowerBoundA != null) && (pr.lowerBoundA[0] != 0)) { if (pr.arrayElementType != null) { pr.newObj = Array.CreateInstance(pr.arrayElementType, pr.lengthA, pr.lowerBoundA); } pr.isLowerBound = true; } else { if (object.ReferenceEquals(pr.arrayElementType, Converter.s_typeofString)) { pr.objectA = new string[pr.lengthA[0]]; pr.newObj = pr.objectA; flag = false; } else if (object.ReferenceEquals(pr.arrayElementType, Converter.s_typeofObject)) { pr.objectA = new object[pr.lengthA[0]]; pr.newObj = pr.objectA; flag = false; } else if (pr.arrayElementType != null) { pr.newObj = Array.CreateInstance(pr.arrayElementType, pr.lengthA[0]); } pr.isLowerBound = false; } if (pr.arrayTypeEnum == ArrayTypeEnum.Single) { if (!pr.isLowerBound && Converter.IsWriteAsByteArray(pr.arrayElementTypeCode)) { pr.primitiveArray = new PrimitiveArray(pr.arrayElementTypeCode, (Array)pr.newObj); } else if (flag && ((pr.arrayElementType != null) && (!pr.arrayElementType.IsValueType && !pr.isLowerBound))) { pr.objectA = (object[])pr.newObj; } } pr.indexMap = new int[1]; } }
private void ReadArray(BinaryHeaderEnum binaryHeaderEnum) { BinaryArray array = new BinaryArray(binaryHeaderEnum); array.Read(this); BinaryAssemblyInfo assemblyInfo; if (array._binaryTypeEnum != BinaryTypeEnum.ObjectUser) { assemblyInfo = SystemAssemblyInfo; } else { if (array._assemId < 1) { throw new SerializationException(RemotingResources.SerializationAssemblyId.Format(array._typeInformation)); } assemblyInfo = (BinaryAssemblyInfo)AssemIdToAssemblyTable[array._assemId]; } ObjectProgress op = GetOp(); ParseRecord pr = op._pr; op._objectTypeEnum = ObjectTypeEnum.Array; op._binaryTypeEnum = array._binaryTypeEnum; op._typeInformation = array._typeInformation; ObjectProgress progress2 = (ObjectProgress)stack.PeekPeek(); if (progress2 == null || array.ObjectId > 0) { op._name = "System.Array"; pr.parseTypeEnum = ParseTypeEnum.Object; op._memberValueEnum = MemberValueEnum.Empty; } else { pr.parseTypeEnum = ParseTypeEnum.Member; pr.memberValueEnum = MemberValueEnum.Nested; op._memberValueEnum = MemberValueEnum.Nested; ObjectTypeEnum ee = progress2._objectTypeEnum; if (ee == ObjectTypeEnum.Object) { pr.name = progress2._name; pr.memberTypeEnum = MemberTypeEnum.Field; op._memberTypeEnum = MemberTypeEnum.Field; pr.keyDt = progress2._name; pr.dtType = progress2._dtType; } else { if (ee != ObjectTypeEnum.Array) { throw new SerializationException(RemotingResources.SerializationObjectTypeEnum.Format(progress2._objectTypeEnum.ToString())); } pr.memberTypeEnum = MemberTypeEnum.Item; op._memberTypeEnum = MemberTypeEnum.Item; } } pr.objectId = objectReader.GetId((long)array.ObjectId); pr.objectPositionEnum = pr.objectId != topId ? headerId <= 0L || pr.objectId != headerId ? ObjectPositionEnum.Child : ObjectPositionEnum.Headers : ObjectPositionEnum.Top; pr.objectTypeEnum = ObjectTypeEnum.Array; BinaryTypeConverter.TypeFromInfo(array._binaryTypeEnum, array._typeInformation, objectReader, assemblyInfo, out pr.arrayElementTypeCode, out pr.arrayElementTypeString, out pr.arrayElementType, out pr.isArrayVariant); pr.dtTypeCode = PrimitiveTypeEnum.Invalid; pr.rank = array._rank; pr.lengthA = array._lengthA; pr.lowerBoundA = array._lowerBoundA; bool flag = false; switch (array._binaryArrayTypeEnum) { case BinaryArrayTypeEnum.Single: case BinaryArrayTypeEnum.SingleOffset: op._numItems = array._lengthA[0]; pr.arrayTypeEnum = ArrayTypeEnum.Single; if (Converter.IsWriteAsByteArray(pr.arrayElementTypeCode) && array._lowerBoundA[0] == 0) { flag = true; ReadArrayAsBytes(pr); } break; case BinaryArrayTypeEnum.Jagged: case BinaryArrayTypeEnum.JaggedOffset: op._numItems = array._lengthA[0]; pr.arrayTypeEnum = ArrayTypeEnum.Jagged; break; case BinaryArrayTypeEnum.Rectangular: case BinaryArrayTypeEnum.RectangularOffset: { int num = 1; int index = 0; while (true) { if (index >= array._rank) { op._numItems = num; pr.arrayTypeEnum = ArrayTypeEnum.Rectangular; break; } num *= array._lengthA[index]; index++; } break; } default: throw new SerializationException(RemotingResources.SerializationArrayType.Format(array._binaryArrayTypeEnum.ToString())); } if (!flag) { stack.Push(op); } else { PutOp(op); } objectReader.Parse(pr); if (flag) { pr.parseTypeEnum = ParseTypeEnum.ObjectEnd; objectReader.Parse(pr); } }
private void ReadObjectWithMapTyped(BinaryObjectWithMapTyped record) { BinaryAssemblyInfo assemblyInfo = null; ObjectProgress op = GetOp(); ParseRecord pr = op._pr; stack.Push(op); if (record.BinaryHeaderEnum != BinaryHeaderEnum.ObjectWithMapTypedAssemId) { if (record.BinaryHeaderEnum == BinaryHeaderEnum.ObjectWithMapTyped) { assemblyInfo = SystemAssemblyInfo; } } else { if (record.AssemId < 1) { throw new SerializationException(RemotingResources.SerializationAssemblyId.Format(record.Name)); } assemblyInfo = (BinaryAssemblyInfo)AssemIdToAssemblyTable[record.AssemId]; if (assemblyInfo == null) { throw new SerializationException(RemotingResources.SerializationAssemblyId.Format(((int)record.AssemId).ToString() + " " + record.Name)); } } ObjectMap map = ObjectMap.Create(record.Name, record.MemberNames, record.BinaryTypeEnumArray, record.TypeInformationArray, record.MemberAssemIds, objectReader, record.ObjectId, assemblyInfo, AssemIdToAssemblyTable); ObjectMapIdTable[record.ObjectId] = map; op._objectTypeEnum = ObjectTypeEnum.Object; op._binaryTypeEnumA = map._binaryTypeEnumA; op._typeInformationA = map._typeInformationA; op._memberLength = op._binaryTypeEnumA.Length; op._memberNames = map._memberNames; op._memberTypes = map._memberTypes; ObjectProgress progress2 = (ObjectProgress)stack.PeekPeek(); if (progress2 == null || progress2._isInitial) { op._name = record.Name; pr.parseTypeEnum = ParseTypeEnum.Object; op._memberValueEnum = MemberValueEnum.Empty; } else { pr.parseTypeEnum = ParseTypeEnum.Member; pr.memberValueEnum = MemberValueEnum.Nested; op._memberValueEnum = MemberValueEnum.Nested; ObjectTypeEnum ee = progress2._objectTypeEnum; if (ee == ObjectTypeEnum.Object) { pr.name = progress2._name; pr.memberTypeEnum = MemberTypeEnum.Field; op._memberTypeEnum = MemberTypeEnum.Field; } else { if (ee != ObjectTypeEnum.Array) { throw new SerializationException(RemotingResources.SerializationObjectTypeEnum.Format(progress2._objectTypeEnum.ToString())); } pr.memberTypeEnum = MemberTypeEnum.Item; op._memberTypeEnum = MemberTypeEnum.Item; } } pr.objectTypeEnum = ObjectTypeEnum.Object; pr.objectInfo = map.CreateObjectInfo(ref pr.si, ref pr.memberData); pr.objectId = objectReader.GetId((long)record.ObjectId); if (pr.objectId == topId) { pr.objectPositionEnum = ObjectPositionEnum.Top; } pr.keyDt = record.Name; pr.dtType = map._objectType; pr.dtTypeCode = PrimitiveTypeEnum.Invalid; objectReader.Parse(pr); }
private void ReadObject() { if (_binaryObject == null) { _binaryObject = new BinaryObject(); } _binaryObject.Read(this); ObjectMap map = (ObjectMap)ObjectMapIdTable[_binaryObject.MapId]; if (map == null) { throw new SerializationException(RemotingResources.SerializationMap.Format((int)_binaryObject.MapId)); } ObjectProgress op = GetOp(); ParseRecord pr = op._pr; stack.Push(op); op._objectTypeEnum = ObjectTypeEnum.Object; op._binaryTypeEnumA = map._binaryTypeEnumA; op._memberNames = map._memberNames; op._memberTypes = map._memberTypes; op._typeInformationA = map._typeInformationA; op._memberLength = op._binaryTypeEnumA.Length; ObjectProgress progress2 = (ObjectProgress)stack.PeekPeek(); if (progress2 == null || progress2._isInitial) { op._name = map._objectName; pr.parseTypeEnum = ParseTypeEnum.Object; op._memberValueEnum = MemberValueEnum.Empty; } else { pr.parseTypeEnum = ParseTypeEnum.Member; pr.memberValueEnum = MemberValueEnum.Nested; op._memberValueEnum = MemberValueEnum.Nested; ObjectTypeEnum ee = progress2._objectTypeEnum; if (ee == ObjectTypeEnum.Object) { pr.name = progress2._name; pr.memberTypeEnum = MemberTypeEnum.Field; op._memberTypeEnum = MemberTypeEnum.Field; } else { if (ee != ObjectTypeEnum.Array) { throw new SerializationException(RemotingResources.SerializationMap.Format(progress2._objectTypeEnum.ToString())); } pr.memberTypeEnum = MemberTypeEnum.Item; op._memberTypeEnum = MemberTypeEnum.Item; } } pr.objectId = objectReader.GetId((long)_binaryObject.ObjectId); pr.objectInfo = map.CreateObjectInfo(ref pr.si, ref pr.memberData); if (pr.objectId == topId) { pr.objectPositionEnum = ObjectPositionEnum.Top; } pr.objectTypeEnum = ObjectTypeEnum.Object; pr.keyDt = map._objectName; pr.dtType = map._objectType; pr.dtTypeCode = PrimitiveTypeEnum.Invalid; objectReader.Parse(pr); }