1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| #include <windows.h> #include <stdio.h>
int main(void) { SECURITY_ATTRIBUTES sa; sa.nLength = sizeof(sa); sa.bInheritHandle = TRUE; sa.lpSecurityDescriptor = NULL;
HANDLE hInR, hInW; HANDLE hOutR, hOutW;
if (!CreatePipe(&hInR, &hInW, &sa, 0)) { printf("[!] CreatePipe(in) failed: %lu\n", GetLastError()); return 1; } printf("[*] input pipe : read=%p write=%p\n", (void *)hInR, (void *)hInW);
if (!CreatePipe(&hOutR, &hOutW, &sa, 0)) { printf("[!] CreatePipe(out) failed: %lu\n", GetLastError()); CloseHandle(hInR); CloseHandle(hInW); return 1; } printf("[*] output pipe : read=%p write=%p\n", (void *)hOutR, (void *)hOutW);
const char msg[] = "hello pipe"; DWORD written = 0, readcnt = 0; char buf[64] = {0};
WriteFile(hInW, msg, sizeof(msg), &written, NULL); ReadFile(hInR, buf, sizeof(buf), &readcnt, NULL); printf("[*] wrote %lu bytes, read back: \"%s\" (%lu bytes)\n", written, buf, readcnt);
CloseHandle(hInR); CloseHandle(hInW); CloseHandle(hOutR); CloseHandle(hOutW); return 0; }
|