using System.Runtime.InteropServices;
[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; }
byte[] ByteCode = { 0xE8, 0x00, 0x00, 0x00, 0x00, 0x58, 0x83, 0xE8, 0x05, 0xC3 }; int Rez = Asm_Execute(ByteCode);
call @@Next @@Next: pop eax sub eax,5 ret