0

我以前使用以下代码从指针和偏移量中读取内存地址,但是现在我再次使用它并且无法弄清楚我上次是如何工作的,我收到错误“值“字节的一维数组”类型的无法转换为整数”,突出显示 ReadProcessMemory 调用中的 BytesAtAddress 变量。

我已经坚持了大约 25 分钟,任何人都可以向我指出问题所在,因为我确信这很简单。

谢谢!

Public Shared Function ReadPointerFromMemory(ByVal BaseAddress As Integer, ByVal PointerOffset As Integer, ByVal BytesToRead As Integer, ByVal pHandle As IntPtr) As Integer
    Dim BytesAtAddress As Byte() = New Byte(BytesToRead - 1) {}
    Dim BytesRead As Integer
    Dim MemoryBase As Integer
    Dim ReturnVal As Integer
    ReadProcessMemory(pHandle, CType(BaseAddress, IntPtr), BytesAtAddress, BytesToRead, BytesRead)
    MemoryBase = BitConverter.ToInt32(BytesAtAddress, 0)
    MemoryBase += PointerOffset
    ReadProcessMemory(pHandle, CType(MemoryBase, IntPtr), BytesAtAddress, BytesToRead, BytesRead)
    ReturnVal = BitConverter.ToInt32(BytesAtAddress, 0)
    Return ReturnVal
End Function
4

1 回答 1

1

我假设您使用ReadProcessMemory来自:http: //msdn.microsoft.com/en-us/library/ms886794.aspx作为参考。

BOOL ReadProcessMemory( 
  HANDLE hProcess, 
  LPCVOID lpBaseAddress, 
  LPVOID lpBuffer, 
  DWORD nSize, 
  LPDWORD lpNumberOfBytesRead 
);

因此,根据错误,您需要的是缓冲区上的指针而BytesAtAddress不是数组本身。您也可以更改MemoryBase As IntegerMemoryBase As IntPtr和。或者甚至更好地将所有需要的变量 ByRef 而不是 ByVal 传递给您的函数。 ReturnVal As IntegerReturnVal As IntPtr

于 2012-06-05T18:56:36.677 回答