添加了来自 Visual Studio 的另一个错误图像。 添加了错误的确切来源。
The following bit of code here is :
void update_memblock(MEMBLOCK *mb)
{
static unsigned char tempbuf[128 * 1024];
unsigned int bytes_left;
unsigned int total_read;
unsigned int bytes_to_read;
unsigned int bytes_read;
bytes_left = mb->size;
total_read = 0;
while (bytes_left)
{
bytes_to_read = (bytes_left > sizeof(tempbuf)) ? sizeof(tempbuf) : bytes_left;
ReadProcessMemory(mb->hProc, mb->addr + total_read, tempbuf, bytes_to_read, (DWORD*)&bytes_read);
if (bytes_read != bytes_to_read) break;
memcpy(mb->buffer + total_read, tempbuf, bytes_read);
bytes_left -= bytes_read;
total_read += bytes_read;
}
mb->size = total_read;
}
The Structure looks as follows :
typedef struct _MEMBLOCK {
HANDLE hProc;
unsigned char *addr;
int size;
unsigned char *buffer;
struct _MEMBLOCK *next;
} MEMBLOCK;
尝试了相当多的切换,从更改数组大小到删除变量并将其切换为另一个,显然它仍然会抛出此错误。请帮我找出问题所在。谢谢。
最佳答案
如果您阅读 documentation ,您会注意到 ReadProcessMemory
的参数应该是 SIZE_T
。 DWORD
类型为 32 位,在 64 位平台上大小为 64 位。虽然 bytes_to_read
并不重要,因为它是按值传递的,但 8 个字节将写入 bytes_read
指向的指针,其 sizeof
是 4。
此外,您应该得到一个指针类型不匹配,因为在这种情况下 DWORD *
不与 SIZE_T *
兼容。
关于c - 尝试运行代码时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50269214/