public static int CalculateSizeOfbfObject(SimpleBinaryFormatterRootObject inBinaryFormatterRootObject)
        {
            int size = 17; // fized header size

            foreach (SimpleBinaryFormatterObject bfObj in inBinaryFormatterRootObject.binaryFormatterObjects)
            {
                if (bfObj.typeBytes != null)
                    size += bfObj.typeBytes.Length;

                if (bfObj.valueBytes != null)
                    size += bfObj.valueBytes.Length;
            }

            return size;
        }
        public static MemoryStream SimpleBinaryFormatterRootObjectToStream(SimpleBinaryFormatterRootObject inBinaryFormatterRootObject)
        {
            int fullsize = CalculateSizeOfbfObject(inBinaryFormatterRootObject);

            MemoryStream ms = new MemoryStream(fullsize);

            ms.Write(inBinaryFormatterRootObject.headerBytes, 0, inBinaryFormatterRootObject.headerBytes.Length);
            foreach (SimpleBinaryFormatterObject bfObj in inBinaryFormatterRootObject.binaryFormatterObjects)
            {
                if (bfObj.typeBytes != null)
                    ms.Write(bfObj.typeBytes, 0, bfObj.typeBytes.Length);

                if (bfObj.valueBytes != null)
                    ms.Write(bfObj.valueBytes, 0, bfObj.valueBytes.Length);
            }
            return ms;
        }
Exemple #3
0
 public static String JsonNetBinaryFormatterObjectSerializer(SimpleBinaryFormatterRootObject inBinaryFormatterRootObject)
 {
     return(Newtonsoft.Json.JsonConvert.SerializeObject(inBinaryFormatterRootObject, typeof(Helpers.ModifiedVulnerableBinaryFormatters.SimpleBinaryFormatterRootObject), null));
 }
Exemple #4
0
        public static MemoryStream ReconstructFromJsonNetSerializedBinaryFormatterObject(String jsonNet_str)
        {
            SimpleBinaryFormatterRootObject deserialized_obj = (SimpleBinaryFormatterRootObject)Newtonsoft.Json.JsonConvert.DeserializeObject(jsonNet_str, typeof(SimpleBinaryFormatterRootObject));

            return(ReconstructFromBinaryFormatterObject(deserialized_obj));
        }
 public static MemoryStream JsonToStream(String jsonNet_str)
 {
     SimpleBinaryFormatterRootObject deserialized_obj = (SimpleBinaryFormatterRootObject)Newtonsoft.Json.JsonConvert.DeserializeObject(jsonNet_str, typeof(SimpleBinaryFormatterRootObject));
     return SimpleBinaryFormatterRootObjectToStream(deserialized_obj);
 }