title: How do I r/w process memory via scanning and replacing solely arrays of bytes?
body: <p>This question may seem extremely noob-ish, I apologize. I've been periodically attempting for the past three months to figure out how to read/write another process memory, or the application running's process memory, simply via arrays of bytes. As far as I know, C# doesn't have the capability to read/write memory process, so it must call the win32 API dlls via P/Invoke.</p>
  
  <pre><code>[DllImport("kernel32.dll")]  
  static extern Int32 ReadProcessMemory(IntPtr OpenedHandle, IntPtr lpBaseAddress, byte[] lpBuffer, UInt32 size, out IntPtr lpNumberOfBytesRead);
  </code></pre>
  
  <p>My goal is to search and replace a few arrays of bytes as simply and efficiently as you would in Cheat Engine. I would normally have two vars either separate or within an array:</p>
  
  <pre><code>private string original = "d0 d0 66 ae 0b 68 b9 0a";
  private string replace = "d0 02 02 24 00 68 b9 0a";
  </code></pre>
  
  <p>In the <code>ReadProcessMemory</code> call, I'm not understanding why <code>lpBaseAddress</code> is necessary. The <code>OpenHandle</code> I would normally place the string of the application, since I am directly editing it. <code>lpBuffer</code> I assume is the actual array of bytes to read/write. The <code>size</code> I am not so sure about, and the <code>lpNumberOfBytesRead</code> is the number to read? Reciprocal questioning for <code>WriteProcessMemory</code> as well.</p>
  
  <pre><code>[DllImport("kernel32.dll")]
  private static unsafe extern Boolean WriteProcessMemory(IntPtr hProcess, uint lpBaseAddress, byte[] lpBuffer, int nSize, void* lpNumberOfBytesWritten);
  </code></pre>
  
  <p>I'd like to cite some of the tutorials I have read, but it seems they no longer exist or have been replaced. Again, I sincerely apologize for asking such a seemingly amateur question, however S.O. was my last resort.</p>