can anyone tell me wats wrong with following code its giving me error like :
Error1The best overloaded method match for 'p.Program.ReadProcessMemory(System.IntPtr, System.IntPtr, byte[], uint, out System.IntPtr)' has some invalid argumentsE:\ani\p\p\Program.cs4727p
Error2Argument '3' should not be passed with the 'out' keywordE:\ani\p\p\Program.cs4775p
using
System;
using
System.Collections.Generic;
using
System.Text;
using
System.Diagnostics; // For the Process class
using
System.Runtime.InteropServices;
namespace
p
{
class Program
{
[
DllImport("Kernel32.dll")]
public static extern IntPtr OpenProcess(int dwDesiredAccess, bool
bInheritHandle,
Int32 dwProcessId);
[
DllImport("Kernel32.dll")]
public static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte[] lpBuffer, UInt32 nSize, out IntPtr lpNumberOfBytesRead);
[
DllImport("Kernel32.dll")]
public static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr
lpBaseAddress, [
In, Out] byte[] lpBuffer, UInt32 nSize, out IntPtr lpNumberOfBytesWritten);
[
DllImport("Kernel32.dll")]
public static extern int GetLastError();
public static readonly int PROCESS_VM_READ = 0x0010;
public static readonly int PROCESS_VM_WRITE = 0x0020;
static void Main(string[] args)
{
Process[] p = Process.GetProcessesByName("notepad");
ProcessModule pm = p[0].MainModule;
Console.WriteLine(pm.BaseAddress + ":" + p[0].Id);
IntPtr hProcess = OpenProcess(PROCESS_VM_READ, false, p[0].Id);
Console.WriteLine(hProcess);
byte[] cptr = new byte[4];
IntPtr xptr;
bool result = ReadProcessMemory(hProcess, pm.BaseAddress, out cptr, 200, out xptr);
Console.WriteLine(result + ":" + xptr);
}
}
}