Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 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_WM_READ = 0x0010;
  9.  
  10. [DllImport("kernel32.dll")]
  11. public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
  12.  
  13. [DllImport("kernel32.dll")]
  14. public static extern bool ReadProcessMemory(int hProcess, int lpBaseAddress, byte[] lpBuffer, int dwSize, ref int lpNumberOfBytesRead);
  15.  
  16. public static void Main()
  17. {
  18.  
  19. Process process = Process.GetProcessesByName("notepad")[0];
  20. IntPtr processHandle = OpenProcess(PROCESS_WM_READ, false, process.Id);
  21.  
  22. int bytesRead = 0;
  23. byte[] buffer = new byte[24]; //'Hello World!' takes 12*2 bytes because of Unicode
  24.  
  25. // 0x0046A3B8 is the address where I found the string, replace it with what you found
  26. ReadProcessMemory((int)processHandle, 0x0046A3B8, buffer, buffer.Length, ref bytesRead);
  27.  
  28. Console.WriteLine(Encoding.Unicode.GetString(buffer) + " (" + bytesRead.ToString() + "bytes)");
  29. Console.ReadLine();
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement