netcat源代码分析,doexec.c中的句柄

    Result = CreatePipe(&Session->ReadPipeHandle, &ShellStdoutPipe,
                          &SecurityAttributes, 0);
    if (!Result) {
        holler("Failed to create shell stdout pipe, error = %s",
            itoa(GetLastError(), smbuff, 10), NULL, NULL, NULL, NULL, NULL);
        goto Failure;
    }

    fprintf (stderr," Session->ReadPipeHandle = %x\n",Session->ReadPipeHandle);
    fprintf (stderr," ShellStdoutPipe = %x\n",ShellStdoutPipe);


    Result = CreatePipe(&ShellStdinPipe, &Session->WritePipeHandle,
                        &SecurityAttributes, 0);

    if (!Result) {
        holler("Failed to create shell stdin pipe, error = %s",  
            itoa(GetLastError(), smbuff, 10), NULL, NULL, NULL, NULL, NULL);
        goto Failure;
    }

    fprintf (stderr," Session->WritePipeHandle = %x\n",Session->WritePipeHandle);
    fprintf (stderr," ShellStdinPipe = %x\n",ShellStdinPipe);


 


Session->ReadPipeHandle = 738

 ShellStdoutPipe = 734
 Session->WritePipeHandle = 72c

 ShellStdinPipe = 730


 上面是调试的结果,下面的是创建的两个管道,4个句柄,其中netcat.exe用到了2个句柄

cmd.exe用到了两个句柄。


ShellStdoutPipe(stdout)   --->   Session->ReadPipeHandle   ReadFile()  --> net  
   cmd.exe                                         netcat.exe
ShellStdinPipe (stdin )    <---   Session->WritePipeHandle WriteFile() <-- net 

你可能感兴趣的:(netcat源代码分析,doexec.c中的句柄)