如何枚举进程中所有命名管道的名称
How to Enumerate Names of All Named Pipes in a Process?
我需要打开某个命名管道,以便我可以模糊测试它,但是我的测试代码无法访问用于生成命名管道名称的相同数据。 但是,我可以识别管道的名称,然后使用该名称打开管道进行模糊测试。
我使用这个论坛帖子开始枚举系统上句柄的名称:http://forum.sysinternals.com/howto-enumerate-handles_topic18892.html
但是,由于某种原因,这似乎不适用于命名管道。
TL;DR:我需要使用什么 API 来列出 Windows 上当前进程中所有命名管道的名称?
这将枚举系统中的所有命名管道,或者至少使您朝着正确的方向迈出一步。
当使用 -permissive 构建时,这在 MinGW 中有效。它应该适用于 MSVC 中的类似设置。
#ifndef _WIN32_WINNT
// Windows XP
#define _WIN32_WINNT 0x0501
#endif
#include <Windows.h>
#include <Psapi.h>
// mycreatepipeex.c is at http://www.davehart.net/remote/PipeEx.c
// I created a simple header based on that.
#include "mycreatepipeex.h"
#include <iostream>
#include <cstdio>
#include <errno.h>
void EnumeratePipes()
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
#define TARGET_PREFIX "//./pipe/"
const char *target = TARGET_PREFIX "*";
memset(&FindFileData, 0, sizeof(FindFileData));
hFind = FindFirstFileA(target, &FindFileData);
if (hFind == INVALID_HANDLE_VALUE)
{
std::cerr << "FindFirstFileA() failed: " << GetLastError() << std::endl;
return;
}
else
{
do
{
std::cout << "Pipe: " << TARGET_PREFIX << FindFileData.cFileName << std::endl;
}
while (FindNextFile(hFind, &FindFileData));
FindClose(hFind);
}
#undef TARGET_PREFIX
return;
}
int main(int argc, char**argv)
{
HANDLE read = INVALID_HANDLE_VALUE;
HANDLE write = INVALID_HANDLE_VALUE;
unsigned char pipe_name[MAX_PATH+1];
BOOL success = MyCreatePipeEx(&read, &write, NULL, 0, 0, 0, pipe_name);
EnumeratePipes();
if ( success == FALSE )
{
std::cerr << "MyCreatePipeEx() failed: " << GetLastError() << std::endl;
return 1;
}
FILE *f = fopen((const char*)pipe_name, "rwb");
if ( f == NULL )
{
std::cerr << "fopen("" << pipe_name << "") failed: " << (int)errno << std::endl;
}
CloseHandle(read);
CloseHandle(write);
return 0;
}
相关文章:
- 不带大括号的枚举形式
- IPC使用多个管道和分支进程来运行Python程序
- 枚举环境变量的惯用C++14/C++17方法
- 类似枚举的计算常量
- 如何正确实现和访问运算符的各种自定义枚举器
- 错误:从"int"到枚举c++的转换无效
- C++中构造函数中的枚举
- 访问在 C++ 结构中声明的枚举变量
- 枚举类'classname'的多重定义
- 强枚举类型定义:Clang Bug 还是 C++11 标准不确定性?
- 枚举进程模块在有效句柄上返回无效句柄
- 通过进程模块C 枚举时,访问被拒绝
- 枚举已加载特定 DLL 的进程
- 如何枚举进程中所有命名管道的名称
- Win32:如何在C++中枚举属于进程的所有线程
- C++/Win32 枚举属于我的进程的窗口并关闭它们
- 如何在不枚举进程的情况下,通过c++从进程id中获取进程名
- 如何根据进程id枚举所有子窗口句柄?
- 使用Module32First/Next从64位进程中枚举32位进程模块
- 枚举进程句柄,奇怪的问题