SHARE
TWEET

Untitled

a guest Mar 26th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top