internal ObjectWriter(ISurrogateSelector selector, StreamingContext context, InternalFE formatterEnums, SerializationBinder binder) { _currentId = 1; _surrogates = selector; _context = context; _binder = binder; _formatterEnums = formatterEnums; _objectManager = new SerializationObjectManager(context); }
/// <summary> /// Initializes a new instance of the <see cref="JsonSerializer"/> class. /// </summary> public JsonSerializer() { _referenceLoopHandling = JsonSerializerSettings.DefaultReferenceLoopHandling; _missingMemberHandling = JsonSerializerSettings.DefaultMissingMemberHandling; _nullValueHandling = JsonSerializerSettings.DefaultNullValueHandling; _defaultValueHandling = JsonSerializerSettings.DefaultDefaultValueHandling; _objectCreationHandling = JsonSerializerSettings.DefaultObjectCreationHandling; _preserveReferencesHandling = JsonSerializerSettings.DefaultPreserveReferencesHandling; _typeNameHandling = JsonSerializerSettings.DefaultTypeNameHandling; _binder = DefaultSerializationBinder.Instance; }
internal ObjectReader(Stream stream, ISurrogateSelector selector, StreamingContext context, InternalFE formatterEnums, SerializationBinder binder) { if (stream == null) { throw new ArgumentNullException(nameof(stream)); } _stream = stream; _surrogates = selector; _context = context; _binder = binder; _formatterEnums = formatterEnums; }
// Write constructor internal void InitSerialize(object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder) { _context = context; _obj = obj; _serObjectInfoInit = serObjectInfoInit; _objectType = obj.GetType(); if (_objectType.IsArray) { _isArray = true; InitNoMembers(); return; } InvokeSerializationBinder(binder); objectWriter.ObjectManager.RegisterObject(obj); ISurrogateSelector surrogateSelectorTemp; if (surrogateSelector != null && (_serializationSurrogate = surrogateSelector.GetSurrogate(_objectType, context, out surrogateSelectorTemp)) != null) { _si = new SerializationInfo(_objectType, converter); if (!_objectType.IsPrimitive) { _serializationSurrogate.GetObjectData(obj, _si, context); } InitSiWrite(); } else if (obj is ISerializable) { if (!_objectType.IsSerializable) { throw new SerializationException(SR.Format(SR.Serialization_NonSerType, _objectType.FullName, _objectType.Assembly.FullName)); } _si = new SerializationInfo(_objectType, converter); ((ISerializable)obj).GetObjectData(_si, context); InitSiWrite(); CheckTypeForwardedFrom(_cache, _objectType, _binderAssemblyString); } else { InitMemberInfo(); CheckTypeForwardedFrom(_cache, _objectType, _binderAssemblyString); } }
private void InvokeSerializationBinder(SerializationBinder binder) => binder?.BindToName(_objectType, out _binderAssemblyString, out _binderTypeName);
public static string GetTypeName(Type t, FormatterAssemblyStyle assemblyFormat, SerializationBinder binder) { string fullyQualifiedTypeName; #if !(NET20 || NET35) if (binder != null) { string assemblyName, typeName; binder.BindToName(t, out assemblyName, out typeName); fullyQualifiedTypeName = typeName + (assemblyName == null ? "" : ", " + assemblyName); } else { fullyQualifiedTypeName = t.AssemblyQualifiedName; } #else fullyQualifiedTypeName = t.AssemblyQualifiedName; #endif switch (assemblyFormat) { case FormatterAssemblyStyle.Simple: return(RemoveAssemblyDetails(fullyQualifiedTypeName)); case FormatterAssemblyStyle.Full: return(fullyQualifiedTypeName); default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// This function serves to centralize file reads within this class. /// </summary> /// <param name="mode">the payload reading mode</param> /// <param name="key"></param> /// <param name="objectBinder"></param> /// <returns></returns> // TODO: This was protected, but since Simon Thum's additions other methods require this. We need to merge with that change to move whatever is relevant behind this interface // and restore the visibility to protected public virtual FileCachePayload ReadFile(FileCache.PayloadMode mode, string key, string regionName = null, SerializationBinder objectBinder = null) { string cachePath = GetCachePath(key, regionName); string policyPath = GetPolicyPath(key, regionName); FileCachePayload payload = new FileCachePayload(null); switch (mode) { case FileCache.PayloadMode.Filename: payload.Payload = cachePath; break; case FileCache.PayloadMode.Serializable: payload.Payload = Deserialize(cachePath); break; case FileCache.PayloadMode.RawBytes: payload.Payload = LoadRawPayloadData(cachePath); break; default: throw new ArgumentOutOfRangeException(nameof(mode), mode, null); } try { // TODO: In part of the merge it looked like the policy was force serialized with LocalCacheBinder(), is this intended? payload.Policy = Deserialize(policyPath) as SerializableCacheItemPolicy; } catch { payload.Policy = new SerializableCacheItemPolicy(); } return(payload); }
internal void InitSerialize(object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder) { this.context = context; this.obj = obj; this.serObjectInfoInit = serObjectInfoInit; if (RemotingServices.IsTransparentProxy(obj)) { this.objectType = Converter.typeofMarshalByRefObject; } else { this.objectType = obj.GetType(); } if (this.objectType.IsArray) { this.isArray = true; this.InitNoMembers(); return; } this.InvokeSerializationBinder(binder); objectWriter.ObjectManager.RegisterObject(obj); ISurrogateSelector surrogateSelector2; if (surrogateSelector != null && (this.serializationSurrogate = surrogateSelector.GetSurrogate(this.objectType, context, out surrogateSelector2)) != null) { this.si = new SerializationInfo(this.objectType, converter); if (!this.objectType.IsPrimitive) { this.serializationSurrogate.GetObjectData(obj, this.si, context); } this.InitSiWrite(); return; } if (!(obj is ISerializable)) { this.InitMemberInfo(); WriteObjectInfo.CheckTypeForwardedFrom(this.cache, this.objectType, this.binderAssemblyString); return; } if (!this.objectType.IsSerializable) { throw new SerializationException(Environment.GetResourceString("Serialization_NonSerType", new object[] { this.objectType.FullName, this.objectType.Assembly.FullName })); } this.si = new SerializationInfo(this.objectType, converter, !FormatterServices.UnsafeTypeForwardersIsEnabled()); ((ISerializable)obj).GetObjectData(this.si, context); this.InitSiWrite(); WriteObjectInfo.CheckTypeForwardedFrom(this.cache, this.objectType, this.binderAssemblyString); }
internal void InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SerializationBinder binder) { this.objectType = objectType; this.context = context; this.serObjectInfoInit = serObjectInfoInit; if (objectType.IsArray) { this.InitNoMembers(); return; } this.InvokeSerializationBinder(binder); ISurrogateSelector surrogateSelector2 = null; if (surrogateSelector != null) { this.serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelector2); } if (this.serializationSurrogate != null) { this.si = new SerializationInfo(objectType, converter); this.cache = new SerObjectInfoCache(objectType); this.isSi = true; } else if (objectType != Converter.typeofObject && Converter.typeofISerializable.IsAssignableFrom(objectType)) { this.si = new SerializationInfo(objectType, converter, !FormatterServices.UnsafeTypeForwardersIsEnabled()); this.cache = new SerObjectInfoCache(objectType); WriteObjectInfo.CheckTypeForwardedFrom(this.cache, objectType, this.binderAssemblyString); this.isSi = true; } if (!this.isSi) { this.InitMemberInfo(); WriteObjectInfo.CheckTypeForwardedFrom(this.cache, objectType, this.binderAssemblyString); } }
static Type \u202C([In] SerializationBinder obj0, [In] string obj1, [In] string obj2) { // ISSUE: unable to decompile the method. }
public \u206F(SerializationBinder _param1);
public static string GetTypeName(Type t, FormatterAssemblyStyle assemblyFormat, SerializationBinder binder) { string assemblyQualifiedName; if (binder != null) { binder.BindToName(t, out string str, out string str2); assemblyQualifiedName = str2 + ((str == null) ? "" : (", " + str)); } else { assemblyQualifiedName = t.AssemblyQualifiedName; } if (assemblyFormat != FormatterAssemblyStyle.Simple) { if (assemblyFormat != FormatterAssemblyStyle.Full) { throw new ArgumentOutOfRangeException(); } return(assemblyQualifiedName); } return(RemoveAssemblyDetails(assemblyQualifiedName)); }
private bool load(Stream stream, SerializationBinder binder, bool post) { stream.Position = 0; BinaryFormatter bformatter = new BinaryFormatter(); if (binder != null) { bformatter.Binder = binder; } try { objects = new List <IObjectLabel>(); arrows = new List <IArrowLabel>(); ArrayList objs = bformatter.Deserialize(stream) as ArrayList; ArrayList arrs = bformatter.Deserialize(stream) as ArrayList; if (objs != null) { objects = new List <IObjectLabel>(); foreach (IObjectLabel l in objs) { objects.Add(l); } } if (arrs != null) { arrows = new List <IArrowLabel>(); foreach (IArrowLabel l in arrs) { arrows.Add(l); } } foreach (object o in objects) { if (o is INamedComponent) { INamedComponent nc = o as INamedComponent; nc.Desktop = this; string n = nc.Name; if (!table.ContainsKey(n)) { table[n] = nc; } } if (o is IObjectLabel) { IObjectLabel l = o as IObjectLabel; object os = l.Object; if (os is IAssociatedObject) { IAssociatedObject ass = os as IAssociatedObject; ass.Object = l; PostSetObject(ass); } if (os is IObjectContainer) { IObjectContainer oc = os as IObjectContainer; bool lb = oc.Load(); if (!lb) { return(false); } } } } foreach (object o in arrows) { if (o is INamedComponent) { if (o is IArrowLabel) { IArrowLabel l = o as IArrowLabel; object os = l.Arrow; if (os is IAssociatedObject) { IAssociatedObject ass = os as IAssociatedObject; ass.Object = l; PostSetObject(ass); } } INamedComponent nc = o as INamedComponent; string n = nc.Name; if (!table.ContainsKey(n)) { table[n] = nc; } nc.Desktop = this; } } if (post) { bool b = PostLoad(); if (!b) { return(false); } return(PostDeserialize()); } return(true); } catch (Exception ex) { ex.ShowError(10); if (exceptions != null) { exceptions.Add(ex); } } return(false); }
internal bool Load(byte[] buffer, SerializationBinder binder, bool post) { MemoryStream stream = new MemoryStream(buffer); return(Load(stream, binder, post)); }
/// <summary> /// Loads from bytes /// </summary> /// <param name="buffer">Buffer</param> /// <param name="binder">Serialization binder</param> /// <returns>True in success and false otherwise</returns> public bool Load(byte[] buffer, SerializationBinder binder) { return(Load(buffer, binder, true)); }
public static T DeserializeToObject <T>(this StringBuilder objectToSerialize, SerializationBinder binder) { DeSerializerSettings.Binder = binder; var serialize = Deserialize <T>(objectToSerialize); return(serialize); }
public static object DeserializeToObject(this string objectToSerialize, Type type, SerializationBinder binder) { DeSerializerSettings.Binder = binder; var deserializeObject = JsonConvert.DeserializeObject(objectToSerialize, type, DeSerializerSettings); return(deserializeObject); }
static void \u206A([In] SerializationBinder obj0, [In] Type obj1, [In] ref string obj2, [In] ref string obj3) { // ISSUE: unable to decompile the method. }
internal static WriteObjectInfo Serialize(object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder) { WriteObjectInfo objectInfo = WriteObjectInfo.GetObjectInfo(serObjectInfoInit); objectInfo.InitSerialize(obj, surrogateSelector, context, serObjectInfoInit, converter, objectWriter, binder); return(objectInfo); }
[System.Security.SecurityCritical] // auto-generated internal void InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder) { SerTrace.Log(this, objectInfoId, " Constructor 1 ", obj); this.context = context; this.obj = obj; this.serObjectInfoInit = serObjectInfoInit; ISurrogateSelector surrogateSelectorTemp; #if FEATURE_REMOTING if (RemotingServices.IsTransparentProxy(obj)) { objectType = Converter.typeofMarshalByRefObject; } else #endif objectType = obj.GetType(); if (objectType.IsArray) { isArray = true; InitNoMembers(); return; } InvokeSerializationBinder(binder); SerTrace.Log(this, objectInfoId, " Constructor 1 trace 2"); objectWriter.ObjectManager.RegisterObject(obj); if (surrogateSelector != null && (serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp)) != null) { SerTrace.Log(this, objectInfoId, " Constructor 1 trace 3"); si = new SerializationInfo(objectType, converter); if (!objectType.IsPrimitive) { serializationSurrogate.GetObjectData(obj, si, context); } InitSiWrite(); } else if (obj is ISerializable) { if (!objectType.IsSerializable) { throw new SerializationException(Environment.GetResourceString("Serialization_NonSerType", objectType.FullName, objectType.Assembly.FullName)); } si = new SerializationInfo(objectType, converter, !FormatterServices.UnsafeTypeForwardersIsEnabled()); #if FEATURE_SERIALIZATION ((ISerializable)obj).GetObjectData(si, context); #endif SerTrace.Log(this, objectInfoId, " Constructor 1 trace 4 ISerializable " + objectType); InitSiWrite(); CheckTypeForwardedFrom(cache, objectType, binderAssemblyString); } else { SerTrace.Log(this, objectInfoId, " Constructor 1 trace 5"); InitMemberInfo(); CheckTypeForwardedFrom(cache, objectType, binderAssemblyString); } }
public StringFormatter(SerializationBinder binder) { this.Binder = binder; this.Context = new StreamingContext(StreamingContextStates.File); this.SerilizedData = ""; }
[System.Security.SecurityCritical] // auto-generated internal static WriteObjectInfo Serialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SerializationBinder binder) { WriteObjectInfo soi = GetObjectInfo(serObjectInfoInit); soi.InitSerialize(objectType, surrogateSelector, context, serObjectInfoInit, converter, binder); return(soi); }
public IBinaryConfiguration WithBinder(SerializationBinder binder) { _binaryFormatter.Binder = binder; return(this); }
[System.Security.SecurityCritical] // auto-generated internal void InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SerializationBinder binder) { SerTrace.Log(this, objectInfoId, " Constructor 2 ", objectType); this.objectType = objectType; this.context = context; this.serObjectInfoInit = serObjectInfoInit; if (objectType.IsArray) { InitNoMembers(); return; } InvokeSerializationBinder(binder); ISurrogateSelector surrogateSelectorTemp = null; if (surrogateSelector != null) { serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp); } if (serializationSurrogate != null) { // surrogate does not have this problem since user has pass in through the BF's ctor si = new SerializationInfo(objectType, converter); cache = new SerObjectInfoCache(objectType); isSi = true; } else if (Object.ReferenceEquals(objectType, Converter.typeofObject)) { } else if (Converter.typeofISerializable.IsAssignableFrom(objectType)) { si = new SerializationInfo(objectType, converter, !FormatterServices.UnsafeTypeForwardersIsEnabled()); cache = new SerObjectInfoCache(objectType); CheckTypeForwardedFrom(cache, objectType, binderAssemblyString); isSi = true; } if (!isSi) { InitMemberInfo(); CheckTypeForwardedFrom(cache, objectType, binderAssemblyString); } SerTrace.Log(this, objectInfoId, " ", objectType, " InitSerialize Exit ", isSi); }
/// <summary> /// Initializes a new instance of the <see cref="KinectTypeBinder"/> class. /// </summary> /// <param name="defaultBinder">The default binder.</param> public KinectTypeBinder(SerializationBinder defaultBinder) { _defaultBinder = defaultBinder; }
public static T DeserializeObject <T>(string serializedGraph, SerializationFormatterType formatterType, SerializationBinder binder = null) { if (string.IsNullOrEmpty(serializedGraph.Trim())) { throw new ArgumentNullException("serializedGraph"); } if (SerializationFormatterType.Xml == formatterType) { return(XmlDeserializeObject <T>(serializedGraph)); } byte[] arrGraph = Convert.FromBase64String(serializedGraph); using (MemoryStream memoryStream = new MemoryStream(arrGraph)) { IRemotingFormatter formatter = GetFormatter(formatterType); if (binder != null) { formatter.Binder = binder; } return((T)formatter.Deserialize(memoryStream)); } }
public static T DeserializeObjectFromFile <T>(string path, SerializationFormatterType formatterType, SerializationBinder binder = null) { if (!File.Exists(path)) { throw new FileNotFoundException("path"); } if (SerializationFormatterType.Xml == formatterType) { return(XmlDeserializeObjectFromFile <T>(path)); } using (FileStream fileStream = new FileStream(path, FileMode.Open)) { IRemotingFormatter formatter = GetFormatter(formatterType); if (binder != null) { formatter.Binder = binder; } return((T)formatter.Deserialize(fileStream)); } }
public static object DecryptObject(byte[] input, string cipherText, string passPhrase, SerializationBinder serializationBinder) { return(DecryptObject_Private(input, cipherText, passPhrase, serializationBinder)); }
// Write Constructor used for array types or null members internal void InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SerializationBinder binder) { _objectType = objectType; _context = context; _serObjectInfoInit = serObjectInfoInit; if (objectType.IsArray) { InitNoMembers(); return; } InvokeSerializationBinder(binder); ISurrogateSelector surrogateSelectorTemp = null; if (surrogateSelector != null) { _serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp); } if (_serializationSurrogate != null) { // surrogate does not have this problem since user has pass in through the BF's ctor _si = new SerializationInfo(objectType, converter); _cache = new SerObjectInfoCache(objectType); _isSi = true; } else if (!ReferenceEquals(objectType, Converter.s_typeofObject) && Converter.s_typeofISerializable.IsAssignableFrom(objectType)) { _si = new SerializationInfo(objectType, converter); _cache = new SerObjectInfoCache(objectType); CheckTypeForwardedFrom(_cache, objectType, _binderAssemblyString); _isSi = true; } if (!_isSi) { InitMemberInfo(); CheckTypeForwardedFrom(_cache, objectType, _binderAssemblyString); } }
/// <summary> /// Decrypts specified ciphertext using Rijndael symmetric key algorithm. /// </summary> /// <param name="cipherText"> /// Base64-formatted ciphertext value. /// </param> /// <param name="passPhrase"> /// Passphrase from which a pseudo-random password will be derived. The /// derived password will be used to generate the encryption key. /// Passphrase can be any string. In this example we assume that this /// passphrase is an ASCII string. /// </param> /// <returns> /// Decrypted string value. /// </returns> /// <remarks> /// Most of the logic in this function is similar to the Encrypt /// logic. In order for decryption to work, all parameters of this function /// - except cipherText value - must match the corresponding parameters of /// the Encrypt function which was called to generate the /// ciphertext. /// </remarks> private static object DecryptObject_Private(byte[] encryptedObject, string cipherText, string passPhrase, SerializationBinder serializationBinder) { // Convert strings defining encryption key characteristics into byte // arrays. Let us assume that strings only contain ASCII codes. // If strings include Unicode characters, use Unicode, UTF7, or UTF8 // encoding. if (string.IsNullOrEmpty(cipherText)) { throw new InvalidOperationException("Invalid cipherText"); } if (cipherText.Length < 23) { throw new InvalidOperationException("Invalid cipherText"); } string strIv = cipherText.Substring(0, 16); string strSalt = cipherText.Substring(16, 8); byte[] initVectorBytes = Encoding.ASCII.GetBytes(strIv); byte[] saltValueBytes = Encoding.ASCII.GetBytes(strSalt); // Convert our ciphertext into a byte array. byte[] cipherTextBytes = encryptedObject; // First, we must create a password, from which the key will be // derived. This password will be generated from the specified // passphrase and salt value. The password will be created using // the specified hash algorithm. Password creation can be done in // several iterations. //Dim password As New PasswordDeriveBytes(passPhrase, saltValueBytes, hashAlgorithm, passwordIterations) Rfc2898DeriveBytes pw = new Rfc2898DeriveBytes(passPhrase, saltValueBytes, 2); // Use the password to generate pseudo-random bytes for the encryption // key. Specify the size of the key in bytes (instead of bits). byte[] keyBytes = pw.GetBytes(256 / 8); // Create uninitialized Rijndael encryption object. RijndaelManaged symmetricKey = new RijndaelManaged(); // It is reasonable to set encryption mode to Cipher Block Chaining // (CBC). Use default options for other symmetric key parameters. symmetricKey.Mode = CipherMode.CBC; try { // Generate decryptor from the existing key bytes and initialization // vector. Key size will be defined based on the number of the key // bytes. ICryptoTransform decryptor = symmetricKey.CreateDecryptor(keyBytes, initVectorBytes); // Define memory stream which will be used to hold encrypted data. MemoryStream memoryStream = new MemoryStream(cipherTextBytes); // Define cryptographic stream (always use Read mode for encryption). CryptoStream cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read); // Since at this point we don't know what the size of decrypted data // will be, allocate the buffer long enough to hold ciphertext; // plaintext is never longer than ciphertext. byte[] plainBytes = new byte[cipherTextBytes.Length]; // Start decrypting. int decryptedByteCount = cryptoStream.Read(plainBytes, 0, plainBytes.Length); // Close both streams. memoryStream.Close(); cryptoStream.Close(); object output; if (serializationBinder == null) { output = Serializer.DeserializeFromByteArray(plainBytes); } else { output = Serializer.DeserializeFromByteArray(plainBytes, serializationBinder); } return(output); } catch (Exception ex) { throw ex; } }
internal static WriteObjectInfo Serialize(object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder) { WriteObjectInfo woi = GetObjectInfo(serObjectInfoInit); woi.InitSerialize(obj, surrogateSelector, context, serObjectInfoInit, converter, objectWriter, binder); return woi; }
public Expression Bind(Expression node) { return(SerializationBinder.Bind(node, this)); }
// Constructor used by SoapReader public SoapTypeMapper(SerializationBinder binder) { _binder = binder; }
public static string GetTypeName(Type t, FormatterAssemblyStyle assemblyFormat, SerializationBinder binder) { string fullyQualifiedTypeName; fullyQualifiedTypeName = t.AssemblyQualifiedName; switch (assemblyFormat) { case FormatterAssemblyStyle.Simple: return(RemoveAssemblyDetails(fullyQualifiedTypeName)); case FormatterAssemblyStyle.Full: return(t.AssemblyQualifiedName); default: throw new ArgumentOutOfRangeException(); } }