Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- using System.Runtime.InteropServices;
- using System.Text;
- public class MemoryRead
- {
- const int PROCESS_ALL_ACCESS = 0x1F0FFF;
- [DllImport("kernel32.dll")]
- public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
- [DllImport("kernel32.dll", SetLastError = true)]
- static extern bool WriteProcessMemory(int hProcess, int lpBaseAddress, byte[] lpBuffer, int dwSize, ref int lpNumberOfBytesWritten);
- public static void Main()
- {
- Process process = Process.GetProcessesByName("notepad")[0];
- IntPtr processHandle = OpenProcess(PROCESS_ALL_ACCESS, false, process.Id);
- int bytesWritten = 0;
- byte[] buffer = Encoding.Unicode.GetBytes("It works!\0"); // '\0' marks the end of string
- // replace 0x0046A3B8 with your address
- WriteProcessMemory((int)processHandle, 0x0046A3B8, buffer, buffer.Length, ref bytesWritten);
- Console.ReadLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement