📄 dcomshow.cpp
字号:
else { sprintf (m_pBinding, "From %s port %d to target port %d", m_pHost, m_peerPort, m_hostPort); } return m_pBinding; } /************************************************************************* * * DataPacket::getChannelBinding - Returns the binding ip/port binding for * this packet. * * This method gives a channel binding as a string containing ip and port * addresses. It is always of the form: * ip:host port:peer port * so that easy string comps can be done. It is virtual so that the base * classes can access it. * * RETURNS: The ip/port binding for the packet as a string. * NOMANUAL */ virtual const char * getChannelBinding () { if (m_pBinding) { delete [] m_pBinding; m_pBinding = NULL; } m_pBinding = new char [strlen (m_pHost) + 32]; sprintf (m_pBinding, "%s:%d:%d", m_pHost, m_hostPort, m_peerPort); return m_pBinding; } /************************************************************************* * * DataPacket::getFlags - Return the stored flags BYTE. * * Return the stored flags BYTE. * * RETURNS: The DCE header flags byte. * NOMANUAL */ BYTE getFlags () { return m_DceFlags; } /************************************************************************* * * DataPacket::setFlags - Set the stored flags BYTE. * * Set the stored flags BYTE. * * RETURNS: Nothing. * NOMANUAL */ void setFlags (const BYTE flags) { m_DceFlags = flags; } private: /************************************************************************* * * DataPacket::ReadBYTE - Read a BYTE from the packet. * * This method reads a BYTE from the packet and advances the current byte * pointer by one BYTE. The value is also displayed. If a decode table is * given the value is matched against the table and the symbolic value is * displayed. * * RETURNS: The value read from the packet. * NOMANUAL */ virtual BYTE ReadBYTE ( const char * pName, /* The field name to */ /* display */ TABLE * pDecodeTable = NULL /* The decode table, */ /* or NULL for none. */ ) { BYTE * pValue = ReadBytes (sizeof (BYTE)); FIELD(pName, *pValue); if (pDecodeTable) { outputSpace (); outputDash (); outputSpace (); output (DecodeFromTable ((ULONG)(*pValue), pDecodeTable)); } endOfLine (); return *pValue; } /************************************************************************* * * DataPacket::ReadARRAY - Read an array of BYTE from the packet. * * This method reads an array of BYTE from the packet and advances the * current byte pointer by the length of the read array. The data is also * displayed. * * RETURNS: Nothing. * NOMANUAL */ virtual void ReadARRAY ( const char * pName, /* The field name to display */ ULONG number /* The number of BYTEs to read. */ ) { ULONG count; BYTE * pValue = ReadBytes (number, false); FIELD(pName, ""); for (count = 0; count < number; count++) { outputSpace (); output (pValue [count]); } endOfLine (); } /************************************************************************* * * DataPacket::ReadUSHORT - Read a USHORT from the packet. * * This method reads a USHORT from the packet and advances the current byte * pointer by one USHORT. The value is also displayed. If a decode table * is given the value is matched against the table and the symbolic value * is displayed. The data is correctly byte swapped if required and an EOL * is emited if required. * * RETURNS: The value read from the packet. * NOMANUAL */ virtual USHORT ReadUSHORT ( const char * pName, /* Name of the field */ bool swap = true, /* If true swap data */ TABLE * pDecodeTable = NULL, /* Pointer to the decode */ /* table, or NULL for none */ bool doEndOfLine = true /* If false emit and EOL */ ) { USHORT * pValue = (USHORT *)ReadBytes (sizeof (USHORT), swap); FIELD(pName, *pValue); if (pDecodeTable) { outputSpace (); outputDash (); outputSpace (); output (DecodeFromTable ((ULONG)(*pValue), pDecodeTable)); } if (doEndOfLine) endOfLine (); return *pValue; } /************************************************************************** * * DataPacket::ReadULONG - Read a ULONG from the packet. * * This method reads a ULONG from the packet and advances the current byte * pointer by one ULONG. The value is also displayed. If a decode table is * given the value is matched against the table and the symbolic value is * displayed. The data is correctly byte swapped if required. * * RETURNS: The value read from the packet. * NOMANUAL */ virtual ULONG ReadULONG ( const char * pName, /* Name of the field */ bool swap = true, /* If PURE swap data */ TABLE * pDecodeTable = NULL /* Pointer to the decode */ /* table, or NULL for none */ ) { ULONG * pValue = (ULONG *)ReadBytes (sizeof (ULONG), swap); FIELD(pName, *pValue); if (pDecodeTable) { outputSpace (); outputDash (); outputSpace (); output (DecodeFromTable (*pValue, pDecodeTable)); } endOfLine (); return *pValue; } /************************************************************************** * * DataPacket::ReadBytes - Reads n bytes from the packet * * Reads n bytes from the packet and performs byte swamping if swap is set * to true. If all data has been read 0x00 bytes are returned in the buffer. * * RETURNS: A pointer to a temp buffer containing the formated bytes. * NOMANUAL */ virtual BYTE * ReadBytes ( DWORD number, /* Number of BYTEs to read */ bool swap = true /* Swap bytes if true. */ ) { if (m_pResult) { delete [] m_pResult; m_pResult = NULL; } m_pResult = new BYTE [number]; COM_ASSERT (m_pResult != NULL); memset (m_pResult, 0x00, number); BYTE * ptr; DWORD count; /* since we're copying data we can swap data 'in-place', */ /* so we may need to start filling in the buffer at the end */ if (m_byteSwap && swap) { ptr = m_pResult + number - 1; } else { ptr = m_pResult; } for (count = 0; count < number; count++) { if (m_pData < m_pEnd) { *ptr = *m_pData; m_pData++; /* increment/decrement count depending on swap order */ /* and whether we want to swap. */ if (m_byteSwap && swap) { ptr--; } else { ptr++; } } else { return m_pResult; } } return m_pResult; } /************************************************************************** * * DataPacket::BytesRemaining - Number of BYTEs unread in buffer. * * Returns number of unread BYTEs in the buffer. * * RETURNS: Bytes remaining. * NOMANUAL */ virtual DWORD BytesRemaining () { return m_pEnd - m_pData; } /************************************************************************** * * DataPacket::DecodeFromTable - Converts a numeric value to a string via * a table. * * Converts a numeric value to a string via a lookup table. If the value * doesn't exist in the table "Unknown Value" is returned. * * RETURNS: The string contained in the lookup table or "Unknown Value" * if not found. * NOMANUAL */ const char * DecodeFromTable ( ULONG value, /* Value to decode */ TABLE * pDecodeTable /* Decode table */ ) { TABLE * ptr = pDecodeTable; while (ptr->m_name) { if (ptr->m_value == value) { return ptr->m_name; } ptr++; } return "Unknown value"; } const BYTE * m_pData; BYTE * m_pEnd; bool m_byteSwap; BYTE m_DceFlags; char * m_pHost; int m_hostPort; int m_peerPort; bool m_outbound; BYTE * m_pResult; char * m_pBinding; };/**************************************************************************** dcomShowClientOutput - Processes packet sent from a client object to* a server.** Processes an outbound packet from a client object.** RETURNS: Nothing.* NOMANUAL*/extern "C" void dcomShowClientOutput ( const BYTE * pPacket, /* Packet to be sent */ DWORD length, /* Length of packet */ const char * pHost, /* Hostname */ int hostPort, /* Host endpoint */ int peerPort /* Peer endpoint */ ) { VxCritSec exclude (s_mutex); DataPacket data(pPacket, length, pHost, hostPort, peerPort, true); data.Read (data.getDesc ()); }/**************************************************************************** dcomShowClientInput - Processes packet sent to a client object from a* server object.** Processes an inbound packet to a client object.** RETURNS: Nothing.* NOMANUAL*/extern "C" void dcomShowClientInput ( const BYTE * pPacket, /* Packet to be sent */ DWORD length, /* Length of packet */ const char * pHost, /* Hostname */ int hostPort, /* Host endpoint */ int peerPort /* Peer endpoint */ ) { VxCritSec exclude (s_mutex); DataPacket data(pPacket, length, pHost, hostPort, peerPort, false); data.Read (data.getDesc ()); }/**************************************************************************** dcomShowServerOutput - Processes packet sent from a server object to a* client object.** Processes an outbound packet from a server object.** RETURNS: Nothing.* NOMANUAL*/extern "C" void dcomShowServerOutput ( const BYTE * pPacket, /* Packet to be sent */ DWORD length, /* Length of packet */ const char * pHost, /* Hostname */ int hostPort, /* Host endpoint */ int peerPort /* Peer endpoint */ ) { VxCritSec exclude (s_mutex); DataPacket data(pPacket, length, pHost, hostPort, peerPort, true); data.Read (data.getDesc ()); }/**************************************************************************** dcomShowServerInput - Processes packet sent to a server object.** Processes an inbound packet from a server object.** RETURNS: Nothing.* NOMANUAL*/extern "C" void dcomShowServerInput ( const BYTE * pPacket, /* Packet to be sent */ DWORD length, /* Length of packet */ const char * pHost, /* Hostname */ int hostPort, /* Host endpoint */ int peerPort /* Peer endpoint */ ) { VxCritSec exclude (s_mutex); DataPacket data(pPacket, length, pHost, hostPort, peerPort, false); data.Read (data.getDesc ()); }/**************************************************************************** listenerTask - task that listens for network connections** Task that listens for network connections. If a socket is successfully* established the appropriate debug hook is initialized.** RETURNS: Nothing.* NOMANUAL*/extern "C" void listenerTask ( int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10 ) {#ifdef VXDCOM_PLATFORM_VXWORKS int fromLen;#else socklen_t fromLen;#endif int s; int ns; struct sockaddr_in s_addr; PRINT_STR("DCOM_SHOW setting up socket\n"); if ((s = ::socket(PF_INET, SOCK_STREAM, 0)) < 0) { PRINT_STR("DCOM_SHOW can't open a socket\n"); return; } s_addr.sin_family = AF_INET; s_addr.sin_port = htons(s_listenPort); s_addr.sin_addr.s_addr = htonl (INADDR_ANY); PRINT_STR("DCOM_SHOW binding socket to port\n"); if (bind(s, (struct sockaddr *)(&s_addr), sizeof (s_addr)) < 0) { PRINT_STR("DCOM_SHOW can't bind to specified port\n"); close (s); return; } PRINT_STR("DCOM_SHOW listening for a connection\n"); if (listen(s, 5) < 0) { PRINT_STR("DCOM_SHOW can't listen on specified port\n"); close (s); return; } fromLen = sizeof (s_addr); if ((ns = accept(s, (struct sockaddr *)(&s_addr), &fromLen)) < 0) { PRINT_STR("DCOM_SHOW has dropped out of accept without connecting\n"); close (s); startListenerTask (); return; } close(s); s_outputSocket = ns; PRINT_STR("DCOM_SHOW has set up a connection\n"); SETDEBUGHOOK(pDcomShowPrintStr, networkPrint); }/**************************************************************************** networkPrint - output a string to a socket** Output's a string to a network socket. If an error occurs it is assumed* that the socket has been closed by the client and so a new connection* listener is started.** RETURNS: Nothing.* NOMANUAL*/extern "C" void networkPrint (const char * str) { if (write (s_outputSocket, const_cast<char *>(str), strlen (str)) < 0) { CLEARDEBUGHOOK(pDcomShowPrintStr); close (s_outputSocket); s_outputSocket = 0; PRINT_STR(str); PRINT_STR("DCOM_SHOW has disconnected from output client\n"); startListenerTask (); } }/**************************************************************************** startListenerTask - starts the task to listen for connections** Starts a task to listen for network connections.** RETURNS: Nothing.* NOMANUAL*/extern "C" void startListenerTask (void) { COM_ASSERT (taskSpawn ("tDcomShow", 55, VX_FP_TASK, 10240, (FUNCPTR)listenerTask, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) != ERROR); }/**************************************************************************** dcomShowInit - Init routine for the DCOM Show routines. ** This initializes the module and installs the required hooks into the* client/server structure to capture and process the network data.* * This routine takes one parameter which defines a network port to listen* for telnet style connections on. If a telnet style client is connected to* this port all output will be sent via this network connection, rather than* to the system console.** RETURNS: Nothing.*/extern "C" void dcomShowInit ( int listenPort /* Port number to listen for */ /* connections on, 0 to disable. */ ) { SETDEBUGHOOK(pRpcClientOutput, dcomShowClientOutput); SETDEBUGHOOK(pRpcClientInput, dcomShowClientInput); SETDEBUGHOOK(pRpcServerOutput, dcomShowServerOutput); SETDEBUGHOOK(pRpcServerInput, dcomShowServerInput); /* Initialize listen port */ if (listenPort != 0) { s_listenPort = listenPort; startListenerTask (); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -