using System.Runtime.InteropServices; internal class Program { internal static uint MEM_COMMIT = 0x1000; internal static uint PAGE_EXECUTE_READWRITE = 0x40; [DllImport("kernel32.dll")] static extern unsafe IntPtr VirtualAlloc( IntPtr lpAddress, int dwSize, uint flAllocationType, uint flProtect); internal delegate int BytesLauncher(); static void Main() { byte[] rawBytes = [ 0x90, 0x90, 0xC3 ]; var payload = VirtualAlloc(IntPtr.Zero, rawBytes.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE); Marshal.Copy(rawBytes, 0, payload, rawBytes.Length); if (Marshal.GetDelegateForFunctionPointer( payload, typeof(BytesLauncher)) is BytesLauncher ExecutePayload) { _ = ExecutePayload(); } } }