Advertisement
FlyFar

inject/src/Output.cpp

Sep 24th, 2023
766
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | Cybersecurity | 0 0
  1. #include "Output.h"
  2.  
  3. BOOL Run = FALSE;
  4. std::ostringstream OUTPUT;
  5. HANDLE hThread;
  6.  
  7. DWORD WINAPI PIPETHREAD(LPVOID lpParameter) {
  8.     HANDLE hPipe;
  9.     char buffer[BUFFER];
  10.     DWORD dwRead;
  11.  
  12.  
  13.     hPipe = CreateNamedPipe(TEXT("\\\\.\\pipe\\quantumcore"),
  14.         PIPE_ACCESS_DUPLEX,
  15.         PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT,  
  16.         1,
  17.         1024 * 16,
  18.         1024 * 16,
  19.         NMPWAIT_USE_DEFAULT_WAIT,
  20.         NULL);
  21.    
  22.     OUTPUT.clear();
  23.     OUTPUT.str("");
  24.     while (Run)
  25.     {
  26.        
  27.         while (hPipe != INVALID_HANDLE_VALUE)
  28.         {
  29.             if (ConnectNamedPipe(hPipe, NULL) != FALSE)
  30.             {
  31.                 memset(buffer, '\0', BUFFER);
  32.                 while (ReadFile(hPipe, buffer, sizeof(buffer) , &dwRead, NULL) != FALSE)
  33.                 {
  34.                     buffer[dwRead] = '\0';
  35.  
  36.                     OUTPUT << buffer;
  37.                 }
  38.             }
  39.  
  40.             DisconnectNamedPipe(hPipe);
  41.         }
  42.  
  43.         if (!Run)
  44.         {
  45.             break;
  46.         }
  47.     }
  48.  
  49.     return 0;
  50. }
  51.  
  52. void Prepare()
  53. {
  54.     Run = TRUE;
  55.     hThread = CreateThread(NULL, 0, PIPETHREAD, NULL, 0, NULL);
  56.     if (hThread == NULL)
  57.     {
  58.         printf("Error Creating Thread: %ld\n", GetLastError());
  59.     }
  60. }
  61.  
  62. BOOL isPipeThreadRunning()
  63. {
  64.     DWORD exitCode;
  65.     return GetExitCodeThread(hThread, &exitCode);
  66. }
  67.  
  68. std::string ReadReflectiveDllOutput(int Timeout)
  69. {
  70.     int x = 0;
  71.     if (Run)
  72.     {
  73.         do {
  74.             Sleep(1000);
  75.             x++;
  76.         } while (x != Timeout);
  77.  
  78.         Run = FALSE; // The thread ends.
  79.  
  80.     }
  81.     return OUTPUT.str();
  82. }
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement