информационная безопасность
без паники и всерьез
 подробно о проектеRambler's Top100
Где водятся OGRыПортрет посетителяСетевые кракеры и правда о деле Левина
BugTraq.Ru
Русский BugTraq
 Анализ криптографических сетевых... 
 Модель надежности двухузлового... 
 Специальные марковские модели надежности... 
 Три миллиона электронных замков... 
 Doom на газонокосилках 
 Умер Никлаус Вирт 
главная обзор RSN блог библиотека закон бред форум dnet о проекте
bugtraq.ru / форум / programming
Имя Пароль
ФОРУМ
если вы видите этот текст, отключите в настройках форума использование JavaScript
регистрация





Легенда:
  новое сообщение
  закрытая нитка
  новое сообщение
  в закрытой нитке
  старое сообщение
  • Напоминаю, что масса вопросов по функционированию форума снимается после прочтения его описания.
  • Новичкам также крайне полезно ознакомиться с данным документом.
[C++] трабл по дефолту - мастдай :)) 18.05.02 05:39  Число просмотров: 985
Автор: BXS Статус: Незарегистрированный пользователь
Отредактировано 18.05.02 05:44  Количество правок: 3
<"чистая" ссылка>
Спасибо за ответ.
Я разобрался с редиректом. Для тех кому интересно:
я оказался не прав, когда сказал что S7 редиректит иным способом. При более близком рассмотрении я выяснил такой факт:
это чудище выполняло APP REDIRECT дефолтового netstat так:

модуль | приоритет | потоков
- subseven server | 4 | 1
-- redir32.exe | 4 | 3
--- winoad386.mod | 8 | 1
---- netstat.exe | 8 | 1

итак, этот монстр под себя еще загрузил 3 процесса...
итого в сумме цена редиректа: 3 новых процесса, 5 новых потоков.
в пике нетстат брал 79% машинного времени, subseven - 4, промежуточные звенья - по нулю (странно)..

вот такая вот арифметика...
вопрос: это билли один такой криворукий или сама концепция редиректа такая ресурсопожирающая?

вообще в жизни есть кусочек счастья?
<programming>
[C++] Редирект stdout, stdin, stderr другой проги? 15.05.02 06:01  
Автор: BXS Статус: Незарегистрированный пользователь
Отредактировано 15.05.02 07:48  Количество правок: 1
<"чистая" ссылка>
возникла задачка исполнять другие проги и редиректить их ввод/вывод...

попытался решить в лоб: создал процесс, дал на входе в STARTUPINFO stdout -> в файл... вроде как все путем, НО: redirect видимо в винде реализован крайне криво потому что она загружает для этой цели дополнительно REDIR32.EXE и он в свою очередь тоже плодица - порождает какойто процесс...

почему я пишу про это на форуме - потому что вспомнилась мне иная реализация... если помните был старый добрый троян sub7. в нем фича была app redirect. я не поленился - откопал его и проверил - он вроде по другому редиректит потому что винда ничего для него дополнительно не подгружает... а досовские команды на нем идут на ура... вот отсюда вопрос: как это у него получаеца?

есть какие нить ценные соображения?
[C++] Редирект stdout, stdin, stderr другой проги? 15.05.02 22:37  
Автор: + <Mikhail> Статус: Elderman
<"чистая" ссылка>
Creating a Child Process with Redirected Input and Output

The example in this topic demonstrates how to create a child process from
a console process. It also demonstrates a technique for using anonymous pipes
to redirect the child process's standard input and output handles.

The CreatePipe function uses the SECURITY_ATTRIBUTES structure to create
inheritable handles to the read and write ends of two pipes. The read end
of one pipe serves as standard input for the child process, and the write
end of the other pipe is the standard output for the child process. These
pipe handles are specified in the SetStdHandle function, which makes them
the standard handles inherited by the child process. After the child process
is created, SetStdHandle is used again to restore the original standard
handles for the parent process.

The parent process uses the other ends of the pipes to write to the child
process's input and read the child process's output. The handles to these
ends of the pipe are also inheritable. However, the handle must not be
inherited. Before creating the child process, the parent process must use
DuplicateHandle to create a duplicate of the application-defined hChildStdinWr
global variable that cannot be inherited. It then uses CloseHandle to close
the inheritable handle. For more information, see Pipes.

The following is the parent process.

#include <stdio.h> 
#include <windows.h> 
 
#define BUFSIZE 4096 
 
HANDLE hChildStdinRd, hChildStdinWr, hChildStdinWrDup, 
   hChildStdoutRd, hChildStdoutWr, hChildStdoutRdDup, 
   hInputFile, hSaveStdin, hSaveStdout; 
 
BOOL CreateChildProcess(VOID); 
VOID WriteToPipe(VOID); 
VOID ReadFromPipe(VOID); 
VOID ErrorExit(LPTSTR); 
VOID ErrMsg(LPTSTR, BOOL); 
 
DWORD main(int argc, char *argv[]) 
{ 
   SECURITY_ATTRIBUTES saAttr; 
   BOOL fSuccess; 
 
// Set the bInheritHandle flag so pipe handles are inherited. 
 
   saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); 
   saAttr.bInheritHandle = TRUE; 
   saAttr.lpSecurityDescriptor = NULL; 
 
   // The steps for redirecting child process's STDOUT: 
   //     1. Save current STDOUT, to be restored later. 
   //     2. Create anonymous pipe to be STDOUT for child process. 
   //     3. Set STDOUT of the parent process to be write handle to 
   //        the pipe, so it is inherited by the child process. 
   //     4. Create a noninheritable duplicate of the read handle and
   //        close the inheritable read handle. 
 
// Save the handle to the current STDOUT. 
 
   hSaveStdout = GetStdHandle(STD_OUTPUT_HANDLE); 
 
// Create a pipe for the child process's STDOUT. 
 
   if (! CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &saAttr, 0)) 
      ErrorExit("Stdout pipe creation failed\n"); 
 
// Set a write handle to the pipe to be STDOUT. 
 
   if (! SetStdHandle(STD_OUTPUT_HANDLE, hChildStdoutWr)) 
      ErrorExit("Redirecting STDOUT failed"); 
 
// Create noninheritable read handle and close the inheritable read 
// handle. 

    fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdoutRd,
        GetCurrentProcess(), &hChildStdoutRdDup , 0,
        FALSE,
        DUPLICATE_SAME_ACCESS);
    if( !fSuccess )
        ErrorExit("DuplicateHandle failed");
    CloseHandle(hChildStdoutRd);

   // The steps for redirecting child process's STDIN: 
   //     1.  Save current STDIN, to be restored later. 
   //     2.  Create anonymous pipe to be STDIN for child process. 
   //     3.  Set STDIN of the parent to be the read handle to the 
   //         pipe, so it is inherited by the child process. 
   //     4.  Create a noninheritable duplicate of the write handle, 
   //         and close the inheritable write handle. 
 
// Save the handle to the current STDIN. 
 
   hSaveStdin = GetStdHandle(STD_INPUT_HANDLE); 
 
// Create a pipe for the child process's STDIN. 
 
   if (! CreatePipe(&hChildStdinRd, &hChildStdinWr, &saAttr, 0)) 
      ErrorExit("Stdin pipe creation failed\n"); 
 
// Set a read handle to the pipe to be STDIN. 
 
   if (! SetStdHandle(STD_INPUT_HANDLE, hChildStdinRd)) 
      ErrorExit("Redirecting Stdin failed"); 
 
// Duplicate the write handle to the pipe so it is not inherited. 
 
   fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdinWr, 
      GetCurrentProcess(), &hChildStdinWrDup, 0, 
      FALSE,                  // not inherited 
      DUPLICATE_SAME_ACCESS); 
   if (! fSuccess) 
      ErrorExit("DuplicateHandle failed"); 
 
   CloseHandle(hChildStdinWr); 
 
// Now create the child process. 
 
   if (! CreateChildProcess()) 
      ErrorExit("Create process failed"); 
 
// After process creation, restore the saved STDIN and STDOUT. 
 
   if (! SetStdHandle(STD_INPUT_HANDLE, hSaveStdin)) 
      ErrorExit("Re-redirecting Stdin failed\n"); 
 
   if (! SetStdHandle(STD_OUTPUT_HANDLE, hSaveStdout)) 
      ErrorExit("Re-redirecting Stdout failed\n"); 
 
// Get a handle to the parent's input file. 
 
   if (argc > 1) 
      hInputFile = CreateFile(argv[1], GENERIC_READ, 0, NULL, 
         OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL); 
   else 
      hInputFile = hSaveStdin; 
 
   if (hInputFile == INVALID_HANDLE_VALUE) 
      ErrorExit("no input file\n"); 
 
// Write to pipe that is the standard input for a child process. 
 
   WriteToPipe(); 
 
// Read from pipe that is the standard output for child process. 
 
   ReadFromPipe(); 
 
   return 0; 
} 
 
BOOL CreateChildProcess() 
{ 
   PROCESS_INFORMATION piProcInfo; 
   STARTUPINFO siStartInfo; 
 
// Set up members of the PROCESS_INFORMATION structure. 
 
   ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION) );
 
// Set up members of the STARTUPINFO structure. 
 
   ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) );
   siStartInfo.cb = sizeof(STARTUPINFO); 
 
// Create the child process. 
 
   return CreateProcess(NULL, 
      "child",       // command line 
      NULL,          // process security attributes 
      NULL,          // primary thread security attributes 
      TRUE,          // handles are inherited 
      0,             // creation flags 
      NULL,          // use parent's environment 
      NULL,          // use parent's current directory 
      &siStartInfo,  // STARTUPINFO pointer 
      &piProcInfo);  // receives PROCESS_INFORMATION 
}
 
VOID WriteToPipe(VOID) 
{ 
   DWORD dwRead, dwWritten; 
   CHAR chBuf[BUFSIZE]; 
 
// Read from a file and write its contents to a pipe. 
 
   for (;;) 
   { 
      if (! ReadFile(hInputFile, chBuf, BUFSIZE, &dwRead, NULL)|
         dwRead == 0) break; 
      if (! WriteFile(hChildStdinWrDup, chBuf, dwRead, 
         &dwWritten, NULL)) break; 
   } 
 
// Close the pipe handle so the child process stops reading. 
 
   if (! CloseHandle(hChildStdinWrDup)) 
      ErrorExit("Close pipe failed\n"); 
} 
 
VOID ReadFromPipe(VOID) 
{ 
   DWORD dwRead, dwWritten; 
   CHAR chBuf[BUFSIZE]; 
   HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE); 

// Close the write end of the pipe before reading from the 
// read end of the pipe. 
 
   if (!CloseHandle(hChildStdoutWr)) 
      ErrorExit("Closing handle failed"); 
 
// Read output from the child process, and write to parent's STDOUT. 
 
   for (;;) 
   { 
      if( !ReadFile( hChildStdoutRdDup, chBuf, BUFSIZE, &dwRead, 
         NULL)|dwRead == 0) break; 
      if (! WriteFile(hSaveStdout, chBuf, dwRead, &dwWritten, NULL)) 
         break; 
   } 
} 
 
VOID ErrorExit (LPTSTR lpszMessage) 
{ 
   fprintf(stderr, "%s\n", lpszMessage); 
   ExitProcess(0); 
} 
 
// The code for the child process. 

#include <windows.h> 
#define BUFSIZE 4096 
 
VOID main(VOID) 
{ 
   CHAR chBuf[BUFSIZE]; 
   DWORD dwRead, dwWritten; 
   HANDLE hStdin, hStdout; 
   BOOL fSuccess; 
 
   hStdout = GetStdHandle(STD_OUTPUT_HANDLE); 
   hStdin = GetStdHandle(STD_INPUT_HANDLE); 
   if ((hStdout == INVALID_HANDLE_VALUE)|
      (hStdin == INVALID_HANDLE_VALUE)) 
      ExitProcess(1); 
 
   for (;;) 
   { 
   // Read from standard input. 
      fSuccess = ReadFile(hStdin, chBuf, BUFSIZE, &dwRead, NULL); 
      if (! fSuccess|dwRead == 0) 
         break; 
 
   // Write to standard output. 
      fSuccess = WriteFile(hStdout, chBuf, dwRead, &dwWritten, NULL); 
      if (! fSuccess) 
         break; 
   } 
} 

---
[C++] все та же проблема 18.05.02 02:02  
Автор: BXS Статус: Незарегистрированный пользователь
<"чистая" ссылка>
Да, спасибо за исходник.
Но все же это не совсем решает проблему... дело в том что главный процесс порождает процесс WINOA386.MOD который потом уже порождает дочерний.
То же самое и было раньше (я тоже первоначально пытался решить это через пайпы...) В этом то и проблема... WINOA386 - лишнее звено...
являеца ли это необратимым явлением или этого можно избежать?
может ли маздай редиректить более "прямым" способом (без дополнительных модулей)?
[C++] трабл по дефолту - мастдай :)) 18.05.02 05:39  
Автор: BXS Статус: Незарегистрированный пользователь
Отредактировано 18.05.02 05:44  Количество правок: 3
<"чистая" ссылка>
Спасибо за ответ.
Я разобрался с редиректом. Для тех кому интересно:
я оказался не прав, когда сказал что S7 редиректит иным способом. При более близком рассмотрении я выяснил такой факт:
это чудище выполняло APP REDIRECT дефолтового netstat так:

модуль | приоритет | потоков
- subseven server | 4 | 1
-- redir32.exe | 4 | 3
--- winoad386.mod | 8 | 1
---- netstat.exe | 8 | 1

итак, этот монстр под себя еще загрузил 3 процесса...
итого в сумме цена редиректа: 3 новых процесса, 5 новых потоков.
в пике нетстат брал 79% машинного времени, subseven - 4, промежуточные звенья - по нулю (странно)..

вот такая вот арифметика...
вопрос: это билли один такой криворукий или сама концепция редиректа такая ресурсопожирающая?

вообще в жизни есть кусочек счастья?
1




Rambler's Top100
Рейтинг@Mail.ru


  Copyright © 2001-2024 Dmitry Leonov   Page build time: 0 s   Design: Vadim Derkach