zoukankan      html  css  js  c++  java
  • netcat源代码分析(4)doexec.c文件中的SessionWriteShellThreadFn ()函数

    // **********************************************************************
    // SessionWriteShellThreadFn
    //
    // The write thread procedure. Reads from socket, writes to pipe connected
    // to shell process.  


    static VOID
    SessionWriteShellThreadFn(
        LPVOID Parameter
        )
    {
        PSESSION_DATA Session = Parameter;
        BYTE    RecvBuffer[1];
        BYTE    Buffer[BUFFER_SIZE];
        DWORD   BytesWritten;
        DWORD   BufferCnt;

        BufferCnt = 0;

        //
        // Loop, reading one byte at a time from the socket.    
        //
        while (recv(Session->ClientSocket, RecvBuffer, sizeof(RecvBuffer), 0) != 0) {

            Buffer[BufferCnt++] = RecvBuffer[0];
            if (RecvBuffer[0] == '\r')
                    Buffer[BufferCnt++] = '\n';


            // Trap exit as it causes problems
            if (strnicmp(Buffer, "exit\r\n", 6) == 0)        //注意,如果接受到exit回车,则结束。
                ExitThread(0);


            //
            // If we got a CR, it's time to send what we've buffered up down to the
            // shell process.
            // SECURITY FIX: CW 12/27/04 Add BufferCnt size check.  If we hit end of buffer, flush it
            if (RecvBuffer[0] == '\n' || RecvBuffer[0] == '\r' || BufferCnt > BUFFER_SIZE-1) {
                if (! WriteFile(Session->WritePipeHandle, Buffer, BufferCnt,
                                &BytesWritten, NULL))
                {
                    break;
                }
                BufferCnt = 0;
            }
        }

        ExitThread(0);
    }

  • 相关阅读:
    软件工程之开发过程
    软件工程设计之四则运算
    Android笔记-5-EditText密码和Checkbox二选一
    Android笔记-4-实现登陆页面并跳转和简单的注册页面
    Android笔记-3-EditText的属性介绍
    Android笔记-2-TextView的属性详解
    Android笔记-1
    Microsoft Build 2015
    网络受限是个什么东东?
    几乎所有编程语言的hello, world程序(3)
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3037473.html
Copyright © 2011-2022 走看看