【发布时间】:2019-08-01 02:59:45
【问题描述】:
我基本上是在尝试将我的结构转换或复制到我的其他进程部分视图,但我不断收到错误
C2760:语法错误:意外的标记“标识符”,预期的“声明”
这就是我正在做的:
type RPM(UINT_PTR ReadAddress)
{
if (hDriver == INVALID_HANDLE_VALUE) {
return {};
}
DWORD64 Bytes;
KM_READ_REQUEST ReadRequest{};
type response{};
ReadRequest.ProcessId = PID;
ReadRequest.Address = ReadAddress;
ReadRequest.Size = sizeof(type);
ReadRequest.Output = &response;
问题出在这里:
auto pBuf = (ReadRequest)MapViewOfFile(hMapFile, FILE_MAP_WRITE, 0, 0, 4096);
if (!pBuf)
{
printf("OpenFileMappingA(write) fail! Error: %u\n", GetLastError());
system("pause");
}
printf("MapViewOfFile(write) created ! \n");
我在尝试从我的内核驱动程序中读取未知值时遇到了另一个问题。它基本上读取内存,然后根据我正在读取的内容(如果它的 int、float 等)将该值更改为另一个值。
PKM_READ_REQUEST ReadInput = (PKM_READ_REQUEST)SharedSection; // cast readRequest to our struct which is in SharedSection.
void* ReadOutput = ReadInput->Output;
Status = ReadKernelMemory(Process, ReadInput->Address, ReadOutput, ReadInput->Size);
我正在尝试将其复制到我的共享部分,以便我可以从用户模式读取它,但不知道如何转换它或值是什么。
memcpy(SharedSection, &ReadOutput, sizeof(ReadOutput));
这就是我想尝试读取它的方式,但将其转换为相同的方式,因为我不想将其读取为 void,我想将其读取为从我的内核模式给出的值。
auto pBuf = MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 4096);
if (!pBuf)
{
printf("OpenFileMappingA(write) fail! Error: %u\n", GetLastError());
system("pause");
}
printf("MapViewOfFile(write) created ! \n");
顺便说一句,我在我的内核驱动程序中使用了未记录的函数mmcopyvirtualmemory。
【问题讨论】:
-
MapViewOfFile返回一个指针 (void*)。您不能将其转换为非指针类型。我建议您在继续使用未记录的函数编写内核驱动程序之前,应该了解指针和其他基本语言特性。 -
@Jonathan Potter 感谢您指出我正在学习 c++,但是我遇到了指针问题,您能否链接任何有用的教程或关于指针算法的良好文档:)