Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,11 @@ static IntPtr CreateNewMethod()
if (s_armed)
flProtect |= 0x40000000 /* TARGETS_INVALID */;

uint allocSize = 4096;

IntPtr address = VirtualAlloc(
lpAddress: IntPtr.Zero,
dwSize: 4096,
dwSize: allocSize,
flAllocationType: 0x00001000 | 0x00002000 /* COMMIT+RESERVE*/,
flProtect: flProtect);

Expand All @@ -196,6 +198,15 @@ static IntPtr CreateNewMethod()
throw new NotSupportedException();
}

[DllImport("kernel32", ExactSpelling = true)]
static extern IntPtr GetCurrentProcess();

[DllImport("kernel32", ExactSpelling = true, SetLastError = true)]
static extern int FlushInstructionCache(IntPtr hProcess, IntPtr lpBaseAddress, nuint dwSize);

if (FlushInstructionCache(GetCurrentProcess(), address, allocSize) == 0)
Console.WriteLine("FlushInstructionCache failed");

return address;
}
}