pythonnet .net netcore BinaryFormatter 巨坑

逆向.net程序,碰到了BinaryFormatter ,这个类对对象序列化是C#自身特有的逻辑的,python很难还原BinaryFormatter的序列化逻辑,除非对BinaryFormatter底层逻辑非常了解。于是需要在python中通过pythonnet调用C# DLL对数据对象进行序列化,但是BinaryFormatter不仅对语言不友好,同时在.net版本间的兼容性极差,以下代码序列化代码为例:

var dicList = new Dictionary<string, IList<Dictionary<string, object>>>();
dicList.Add("1", new List<Dictionary<string, object>>() { new Dictionary<string, object>() { { "11", "22" } } });
using (MemoryStream memoryStream = new MemoryStream())
{
     using (GZipStream gzipStream = new GZipStream(memoryStream, CompressionMode.Compress, true))
     {
          using (BufferedStream bufferedStream = new BufferedStream(gzipStream))
          {
               IFormatter formatter = new BinaryFormatter();
               formatter.Serialize(bufferedStream, dicList);
          }
     }
     returnData = memoryStream.ToArray();
}

其中NetCore3.1及以上版本对其序列化的程序集信息为:

System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Collections.Generic.IList`1[[System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]
System.Collections.Generic.GenericEqualityComparer`1[[System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]
System.Collections.Generic.KeyValuePair`2[[System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Collections.Generic.IList`1[[System.Collec
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值