Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using System.Runtime.InteropServices;
  4. using System.Text;
  5.  
  6. public class MemoryRead
  7. {
  8. const int PROCESS_ALL_ACCESS = 0x1F0FFF;
  9.  
  10. [DllImport("kernel32.dll")]
  11. public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
  12.  
  13. [DllImport("kernel32.dll", SetLastError = true)]
  14. static extern bool WriteProcessMemory(int hProcess, int lpBaseAddress, byte[] lpBuffer, int dwSize, ref int lpNumberOfBytesWritten);
  15.  
  16. public static void Main()
  17. {
  18.  
  19. Process process = Process.GetProcessesByName("notepad")[0];
  20. IntPtr processHandle = OpenProcess(PROCESS_ALL_ACCESS, false, process.Id);
  21.  
  22. int bytesWritten = 0;
  23. byte[] buffer = Encoding.Unicode.GetBytes("It works!\0"); // '\0' marks the end of string
  24.  
  25. // replace 0x0046A3B8 with your address
  26. WriteProcessMemory((int)processHandle, 0x0046A3B8, buffer, buffer.Length, ref bytesWritten);
  27. Console.ReadLine();
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement