From f61f1552f91cf5c6f57cefef96eba1641171ccbe Mon Sep 17 00:00:00 2001 From: Nima Zare Date: Tue, 23 May 2023 09:27:11 +0330 Subject: [PATCH] Update Utils.cs fix BinaryFormatter usage risk and change to System.Text.Json standard library. --- v2rayN/v2rayN/Tool/Utils.cs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/v2rayN/v2rayN/Tool/Utils.cs b/v2rayN/v2rayN/Tool/Utils.cs index d65bebae..4321cdb1 100644 --- a/v2rayN/v2rayN/Tool/Utils.cs +++ b/v2rayN/v2rayN/Tool/Utils.cs @@ -905,15 +905,15 @@ namespace v2rayN /// public static T DeepCopy(T obj) { - object retval; - MemoryStream ms = new MemoryStream(); - BinaryFormatter bf = new BinaryFormatter(); - //序列化成流 - bf.Serialize(ms, obj); - ms.Seek(0, SeekOrigin.Begin); - //反序列化成对象 - retval = bf.Deserialize(ms); - return (T)retval; + using (MemoryStream stream = new MemoryStream()) + { + // Serialize object to JSON + System.Text.Json.JsonSerializer.Serialize(stream, obj); + stream.Seek(0, SeekOrigin.Begin); + + // Deserialize JSON to new object + return System.Text.Json.JsonSerializer.Deserialize(stream); + } } /// @@ -1274,4 +1274,4 @@ namespace v2rayN #endregion Windows API } -} \ No newline at end of file +}