简体   繁体   English

MiniDumpWriteDump() 到一个命名管道然后 ReadFile()

[英]MiniDumpWriteDump() into a named pipe then ReadFile()

What I would like to do is use MiniDumpWriteDump() write to a named pipe and then read/write it myself.我想做的是使用 MiniDumpWriteDump() 写入命名管道,然后自己读/写。 I am able to perform the dump successfully if I write the contents to a file directly.如果我直接将内容写入文件,我能够成功执行转储。 However, while writing to the named pipe has been successful the subsequent read/write operation does not go so well.然而,虽然写入命名管道已成功,但随后的读/写操作并不顺利。 I can read all the data out of the pipe but then when it's written the DMP file appears to be corrupted.我可以从管道中读取所有数据,但是当它写入时,DMP 文件似乎已损坏。

Here is the ReadFile() logic:这是 ReadFile() 逻辑:

while (ReadFile(hInboundPipe, &vecBuffer[dwOffset], vecBuffer.size() - dwOffset, &dwRead, NULL)) {
    dwOffset += dwRead;

    while (dwOffset >= vecBuffer.size()) {
        vecBuffer.resize(vecBuffer.size() + iBuffer * sizeof(char));
    }
}

Here is the WriteFile() logic:这是 WriteFile() 逻辑:

HANDLE hDumpFile = CreateFileW(L"C:\\test.dmp", GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
WriteFile(hDumpFile , &vecBuffer[0], dwOffset, &dwOutBytes, NULL);
CloseHandle(hDumpFile);

I'm not certain if it's applicable to the root cause but here is the named pipe setup:我不确定它是否适用于根本原因,但这是命名管道设置:

    HANDLE hInboundPipe = CreateNamedPipe(
    szPipeName,
    PIPE_ACCESS_DUPLEX,
    PIPE_WAIT | PIPE_TYPE_BYTE,
    PIPE_UNLIMITED_INSTANCES,
    0,
    0,
    (DWORD)-1,
    &SecAttrib);

There are not any errors being reported back from GetLastError(). GetLastError() 没有报告任何错误。 Am I missing something obvious?我错过了一些明显的东西吗?

EDIT: Adding how the MiniDumpWriteDump() is being done in response to a comment.编辑:添加 MiniDumpWriteDump() 是如何响应评论的。

HANDLE hDump = CreateFile(szPipeName, GENERIC_ALL, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
MiniDumpWriteDump(hProcess, pid, hDump, mdValue, NULL, NULL, NULL);
CloseHandle(hDump);

UPDATE: I was under the impression that reading by chunks was somehow dropping data.更新:我的印象是,按块读取是以某种方式丢弃数据。 To test this I increased the buffer of the named pipe to accommodate the entire dump without any resizing.为了测试这一点,我增加了命名管道的缓冲区以容纳整个转储,而无需调整大小。 I also increased the vecBuffer size to match.我还增加了vecBuffer大小以匹配。 Now when performing the ReadFile() operation I receive the entire dump but it is still off.现在,当执行ReadFile()操作时,我收到了整个转储,但它仍然处于关闭状态。 I'm still playing with various named pipe settings trying to figure out what needs to be done to get MiniDumpWriteDump() to provide valid output to a named pipe.我仍在尝试各种命名管道设置,试图找出需要做什么才能让MiniDumpWriteDump()向命名管道提供有效输出。

It appears this cannot be done.看来这是做不到的。 See the comments for more information.有关更多信息,请参阅评论。 Writing directly to a named pipe from MiniDumpWriteDump() cannot be done because the handle that is passed in must have the ability to seek.不能直接从MiniDumpWriteDump()写入命名管道,因为传入的句柄必须具有查找能力。 Named pipes do not have that functionality, therefore you must use a legitimate file handle.命名管道没有该功能,因此您必须使用合法的文件句柄。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM