-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMemoryUtils.cs
More file actions
25 lines (22 loc) · 891 Bytes
/
MemoryUtils.cs
File metadata and controls
25 lines (22 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Astrum
{
public static class MemoryUtils
{
const uint PAGE_EXECUTE_READWRITE = 0x40;
public static void WriteBytes(IntPtr address, byte[] bytes)
{
IntPtr process = Process.GetCurrentProcess().Handle;
VirtualProtectEx(process, address, (UIntPtr)bytes.Length, PAGE_EXECUTE_READWRITE, out uint oldProtect);
Marshal.Copy(bytes, 0, address, bytes.Length);
VirtualProtectEx(process, address, (UIntPtr)bytes.Length, oldProtect, out _);
}
[DllImport("kernel32.dll")] static extern bool VirtualProtectEx(IntPtr hProcess, IntPtr lpAddress, UIntPtr dwSize, uint flNewProtect, out uint lpflOldProtect);
}
}