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