static void Main(string[] args) { var analyzer = new BinarySerializationStreamAnalyzer(); if (args.Length > 1 && ("/s".Equals(args[1], StringComparison.OrdinalIgnoreCase) || "/SessionState".Equals(args[1], StringComparison.OrdinalIgnoreCase))) { StateItemData sessionItems; HttpStaticObjectsCollection staticObjects; using (var stream = File.OpenRead(args[0])) Deserialize(stream, out sessionItems, out staticObjects); if (sessionItems != null) { Console.WriteLine("SessionItems count: " + sessionItems.Count); var buf = sessionItems.Buffer; foreach (var k in sessionItems.Keys) { var si = sessionItems[k]; Console.WriteLine(k + ": " + (si.Length - 1)); if (buf[si.Offset] == 20) { analyzer.Read(new MemoryStream(buf, si.Offset + 1, si.Length - 1)); } } } if (staticObjects != null) { Console.WriteLine("StaticObjects: " + staticObjects.Count); #warning TODO: display stats } } else { using (var stream = File.OpenRead(args[0])) analyzer.Read(stream); } Console.WriteLine(); Console.WriteLine("Analyzer stats:"); Console.WriteLine(analyzer.Analyze()); }
static void AnalyzeStream(string name, Stream stream) { BinarySerializationStreamAnalyzer analyzer = new BinarySerializationStreamAnalyzer(); try { analyzer.Read(stream); } catch (Exception e) { Console.Error.WriteLine(e.GetType().Name + ": " + e.Message); } Console.WriteLine(" ================== " + name + "=============================="); Console.Write(analyzer.Analyze()); Console.WriteLine(); }
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(); }
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(); }