最后一句出错在 nt!ExpReleasePoolQuota,拷贝缓冲区时,超出缓冲区大小了吧?
ULONG inBufLength = irpStack->Parameters.DeviceIoControl.InputBufferLength;
ULONG outBufLength = irpStack->Parameters.DeviceIoControl.OutputBufferLength;
inBufLength 和 outBufLength 具体值是多少?
您R3往下送的时候,怎么写的?
请贴出来(缓冲区建立的代码, DEVICE_IO_CONTROL 发送时的代码)
您可以尝试少拷贝一些内容,应该就不报错了
/*
do
{
memcpy(pOutBuffer, (void*)(ulNextProcess+dwPIdOffset), sizeof(ULONG));
pOutBuffer += sizeof(ULONG);
memcpy(pOutBuffer, (void*)(ulNextProcess+dwPCreateTimeOffset), sizeof(ULONG));
pOutBuffer += sizeof(ULONG);
memcpy(pOutBuffer, (void*)(ulNextProcess+dwPNameOffset), 15);
pOutBuffer += 15;
ActiveProcessLinks = (LIST_ENTRY*)*(ULONG*)(ulNextProcess + dwPLinkOffset);
ulEprocess = (ULONG)ActiveProcessLinks->Flink;
ulEprocess -=dwPLinkOffset;
ulNextProcess = ulEprocess;
} while (ulNextProcess != ulFirstProcess);
///< 这里记录一个数目,看看向缓冲区一共拷贝了多少内容?
*/
真机上的进程列表很多,虚拟机里面可能较少
{
memcpy(pOutBuffer, (void*)(ulNextProcess+dwPIdOffset), sizeof(ULONG));
pOutBuffer += sizeof(ULONG);
memcpy(pOutBuffer, (void*)(ulNextProcess+dwPCreateTimeOffset), sizeof(ULONG));
pOutBuffer += sizeof(ULONG);
memcpy(pOutBuffer, (void*)(ulNextProcess+dwPNameOffset), 15);
pOutBuffer += 15;
ActiveProcessLinks = (LIST_ENTRY*)*(ULONG*)(ulNextProcess + dwPLinkOffset);
ulEprocess = (ULONG)ActiveProcessLinks->Flink;
ulEprocess -=dwPLinkOffset;
ulNextProcess = ulEprocess;
} ///< 改成这样, 就拷贝一次, 驱动应该不会报错
得进程列表之前,应先发一个 IO_CTRL_CODE 给驱动,驱动报出,当前有多少个进程.
R3根据(进程数 * sizeof(进程结构)) 开辟Buffer.
再发 IO_CTRL_CODE 给驱动, (下发的缓冲区中包含Buffer的数量(sizeof(进程结构) * N))让驱动上报进程具体信息.
有可能进程数量有变化, 当缓冲区不够时,就不再往里面拷贝进程信息了.
这样靠谱些.
看了您的代码实现, 我觉得主要问题,在于没有判断R3提供的缓冲区到底有多大,就一股脑的往里面写,所以引起报错。
STACK_TEXT:
b0891ab8 8413b77f 00000000 877bd4c8 8b04b5e0 nt!ExpReleasePoolQuota+0x21
b0891b18 840bd555 8704abc8 00000000 9a1f90e1 nt!ExFreePoolWithTag+0x779
b0891b64 8408417f 017bd508 b0891bac b0891ba4 nt!IopCompleteRequest+0xe6
b0891bb4 aa9f14fe 00222000 000003e8 00000000 nt!IopfCompleteRequest+0x3b4
WARNING: Stack unwind information not available. Following frames may be wrong.
b0891bfc 8405779c 8a7c1a08 877bd4c8 877bd4c8 AthenyDriver+0x14fe
您看Dump文件的堆栈调用, IoCompleteRequest之后,就是返回,您说可能在返回那错了.
看调用链, 是 IoCompleteRequest 内部会释放一些空间, 应该和pIrp有关, 但是因为我们代码中拷贝多了,覆盖了pIrp的未知空间, 使IoCompleteRequest 内部释放空间的操作失败了,引起报错。