[DllImport("kernel32.dll", SetLastError = true)]
static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize,
uint flNewProtect, out uint lpflOldProtect);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate int AsmCodeExecutor();
private unsafe int Asm_Execute(byte[] Code)
{
byte* CodePointer;
fixed (byte* p = &Code[0])
CodePointer = p;
uint OldProtect;
VirtualProtect((IntPtr)CodePointer, (uint)Code.Length, (uint)0x40, out OldProtect);
AsmCodeExecutor ExecuteAsmCode = (AsmCodeExecutor)Marshal.GetDelegateForFunctionPointer((IntPtr)CodePointer, typeof(AsmCodeExecutor));
int AsmCodeResult = ExecuteAsmCode();
return AsmCodeResult;
}