Answer the question
In order to leave comments, you need to log in
How to pass an array through Pipe?
I am injecting a dll file into a process, I need to pass the DWORD array from the dll to another program.
Decided to use pipes.
How to pass DWORD[2048] array using pipe?
The code for writing and reading from the pipe:
void Write(LPCVOID Buffer)
{
HANDLE hPipe;
DWORD dwWritten;
hPipe = CreateFile(TEXT("\\\\.\\pipe\\Pipe"), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (hPipe != INVALID_HANDLE_VALUE)
{
WriteFile(hPipe, Buffer, 1024, &dwWritten, NULL);
CloseHandle(hPipe);
}
}
DWORD* Read()
{
HANDLE hPipe;
DWORD buffer[1024];
DWORD dwRead;
hPipe = CreateNamedPipe(TEXT("\\\\.\\pipe\\Pipe"),
PIPE_ACCESS_DUPLEX,
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, // FILE_FLAG_FIRST_PIPE_INSTANCE is not needed but forces CreateNamedPipe(..) to fail if the pipe already exists...
1,
1024 * 16,
1024 * 16,
NMPWAIT_USE_DEFAULT_WAIT,
NULL);
while (hPipe != INVALID_HANDLE_VALUE)
{
if (ConnectNamedPipe(hPipe, NULL) != FALSE) // wait for someone to connect to the pipe
{
while (ReadFile(hPipe, buffer, sizeof(buffer) - 1, &dwRead, NULL) != FALSE)
{
/* add terminating zero */
buffer[dwRead] = '\0';
if (buffer != NULL) {
WriteFile(hPipe, NULL, 1, NULL, NULL);
return buffer;
}
break;
/* do something with data in buffer */
}
}
DisconnectNamedPipe(hPipe);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question