I downloaded a NuGet
package called Process.NET
, and I try to use the Read()
method from the IMemory
interface in my main()
function. I implemented it as in the GIT
tutorial, but I am unable to create an instance of ProcessMemory
like this:
ProcessMemory memory = new ProcessMemory();
I get this error:
"Unable to create instance of the abstract class or interface 'ProcessMemory'. "
I found some threads about that, but nothing could help me yet. Here is my Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Process.NET.Memory;
using Process.NET.Native.Types;
namespace MemoryHacker
{
class Program
{
static void Main(string[] args)
{
ProcessMemory memory = new ProcessMemory();
}
}
//Class with Read() function
public abstract class ProcessMemory : IMemory
{
protected readonly SafeMemoryHandle Handle;
protected ProcessMemory(SafeMemoryHandle handle)
{
Handle = handle;
}
public abstract byte[] Read(IntPtr intPtr, int length);
public string Read(IntPtr intPtr, Encoding encoding, int maxLength)
{
var buffer = Read(intPtr, maxLength);
var ret = encoding.GetString(buffer);
if (ret.IndexOf('\0') != -1)
ret = ret.Remove(ret.IndexOf('\0'));
return ret;
}
public abstract T Read<T>(IntPtr intPtr);
public T[] Read<T>(IntPtr intPtr, int length)
{
var buffer = new T[length];
for (var i = 0; i < buffer.Length; i++)
buffer[i] = Read<T>(intPtr);
return buffer;
}
public abstract int Write(IntPtr intPtr, byte[] bytesToWrite);
public void Write(IntPtr intPtr, string stringToWrite, Encoding encoding)
{
if (stringToWrite[stringToWrite.Length - 1] != '\0')
stringToWrite += '\0';
var bytes = encoding.GetBytes(stringToWrite);
Write(intPtr, bytes);
}
public void Write<T>(IntPtr intPtr, T[] values)
{
foreach (var value in values)
Write(intPtr, value);
}
public abstract void Write<T>(IntPtr intPtr, T value);
}
}
EDIT: Okay, the thing with the instantiating is clear now. But I am still getting an error:
"No argument was specified that corresponds to the formal handle parameter of ProcessMemory.ProcessMemory (SafeMemoryHandle)."
any ideas, while watching the code above?
EDIT2: All you need to solve this problem is said in the answers below. Just a little hint, if you are using Visual Studio
, then rightclick the new class, and click on implement. It writes a lot of stuff for ya!