I use the code of Memory.cs of Lazybot as follow, any help is appreciate.
Code:
public static string ReadUtf8(uint dwAddress, int Size)
{
byte[] l = ReadBytes(ProcessHandle, dwAddress, Size);
if (l == null)
return String.Empty;
return UTF8Decoder(l);
}
public static byte[] ReadBytes(IntPtr hProcess, uint dwAddress, int nSize)
{
IntPtr lpBuffer = IntPtr.Zero;
int iBytesRead;
byte[] baRet;
try
{
lpBuffer = Marshal.AllocHGlobal(nSize);
iBytesRead = ReadRawMemory(hProcess, dwAddress, lpBuffer, nSize);
if (iBytesRead != nSize)
throw new Exception("ReadProcessMemory error in ReadBytes");
baRet = new byte[iBytesRead];
Marshal.Copy(lpBuffer, baRet, 0, iBytesRead);
}
catch
{
return null;
}
finally
{
if (lpBuffer != IntPtr.Zero)
Marshal.FreeHGlobal(lpBuffer);
}
return baRet;
}
public static int ReadRawMemory(IntPtr hProcess, uint dwAddress, IntPtr lpBuffer, int nSize)
{
try
{
int lpBytesRead;
if (!ReadProcessMemory(hProcess, dwAddress, lpBuffer, nSize, out lpBytesRead))
throw new Exception("ReadProcessMemory failed");
return lpBytesRead;
}
catch
{
return 0;
}
}
[DllImport("kernel32", EntryPoint = "ReadProcessMemory")]
public static extern bool ReadProcessMemory(
IntPtr hProcess,
uint dwAddress,
IntPtr lpBuffer,
int nSize,
out int lpBytesRead);