-
Notifications
You must be signed in to change notification settings - Fork 12
/
Program.cs
50 lines (40 loc) · 1.47 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.IO;
namespace BinarySerializationAnalysis
{
static class Program
{
static void Main()
{
//create a new Dummy Class
DummyClass test = new DummyClass();
//set some properties
test.someList = new List<int>();
test.someList.Add(1);
test.someList.Add(2);
test.someList.Add(3);
test.someString = "Some Value";
//set up a recursive reference
test.subObject = test;
//set up our serializer/formatter and analyser
System.Runtime.Serialization.IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
BinarySerializationStreamAnalyzer analyzer = new BinarySerializationStreamAnalyzer();
using (Stream stream = new MemoryStream())
{
//serialize the object to a new memory stream
formatter.Serialize(stream, test);
//reset the stream to the start
stream.Position = 0;
//analyse the binary serialization stream
analyzer.Read(stream);
}
//output the results to the console
Console.Write(analyzer.Analyze());
Console.WriteLine();
Console.Write("Press any key to exit");
Console.ReadKey();
}
}
}