Пример #1
0
        int CTcpHandler::OnRead(const char *pData, int iLength)
        {
            int iNeed = m_pProtocol->Need(pData, iLength); 
		    NsqLogPrintf(LOG_DEBUG, "OnRead iNeed = %d", iNeed);	
            if (iLength == 0)
            {
            }

            int i = 0;

            while (iNeed == 0)
            {
                m_pProtocol->Decode();
                if (ProcessRead() != 0)
                {
                    return -1;     
                }

                m_pProtocol->NextPkg();
                iNeed = m_pProtocol->Need(NULL, 0);

            }

            return iNeed;
        }
Пример #2
0
	void SecureBaseServer::HandleHandshake(SecureSocket* nsock,
		const boost::system::error_code& error){
			if(!error)
			{
				ProcessRead(nsock, error);

			}else
			{
				delete nsock;
			}
	}
Пример #3
0
int SerialThread::Run()
{
	// Check signal controlling and status to open serial communication.
	// enter if there is command of openning and port has be closed before.
	// 先打开 COM1 端口
	if (! OpenCOM1Port())
		return -1;

	m_dwToDo = SMS_READ;

	char *mess = new char[MAX_MESSAGE];
	unsigned int lenBuff;
	unsigned long lenMessage;

	while(ptrDlg->m_bSMSActiveProccess)
	{
		ProcessWrite();

		// 别太急,先等等
		Sleep(1888);
		lenMessage = 0;
		memset(mess, 0, MAX_MESSAGE);
		lenBuff = MAX_MESSAGE;

	//	ptrDlg->AddErrorInfo("reading");
		if (SCC::serialCtl().read_scc(mess,lenBuff,lenMessage))
		{
			if (lenMessage > 0)
			{
				ProcessRead(mess);
			}
			else // 超时
			{
			//	ReadTimeOut(mess);
			}
		}
		else
		{
			ptrDlg->m_bSMSActiveProccess = FALSE;
		}
	} // while(ptrDlg->activeProccess == TRUE)
	delete [] mess;

	return 0;
}
Пример #4
0
void XPump::OnReadEvent(base::Socket *sock) {
    // Read the socket
    Assert(sock == sock_);
    ProcessRead();

    // If there are messages, notify that there are messages. This allows the
    // notifyee to do per-message procesing.

    if (Peek()) {
        if (!notify_->OnMessages()) {
            // OnMessages returning false means execute the default,
            // which is to dispatch them all.
            while (Dispatch()) {
                ;
            }
        }
    }
}
void CListener::ProcessSocketMsg(WPARAM wParam, LPARAM lParam)
{

	if (WSAGETSELECTERROR(lParam))
	{
		// Display the error and close the socket
		CloseConnection(wParam);
		return;
	}

	switch(WSAGETSELECTEVENT(lParam))
	{
		case FD_ACCEPT:
			{
				SOCKADDR_IN ClientAddr = {0};
				int	iLen = sizeof(ClientAddr);
				accept(wParam, (LPSOCKADDR)&ClientAddr, &iLen);
				break;
			}
		case FD_READ:
			{
				// Receive data from the socket in
				// wParam
				ProcessRead(wParam);
				break;
			}

		case FD_WRITE:
			{
				// The socket in wParam is ready
				// for sending data
				break;
			}

		case FD_CLOSE:
			{
				// The connection is now closed	
				CloseConnection(wParam);
				break;
			}
	}
}
Пример #6
0
int main(int argc, char ** argv)
{
	if(argc < 2)
	{
		printf("Usage: init_execve <filename> [args]\n");
		return 1;
	}
	
	if (ptrace(PTRACE_ATTACH, INIT_PID, NULL, NULL))
	{
		printf("ERROR: Couldn't attach to /init.\n");
		return 1;
	}
	
	wait(NULL); //Why do i need this?

	void * initBase;
	unsigned long initSize;
	ProcessGetCodeSectionInfo(INIT_PID, &initBase, &initSize);

	if (!initBase || initSize == 0)
	{
		printf("ERROR: Couldn't get the image base of /init.\n");
		printf("Detaching...\n");
		ptrace(PTRACE_DETACH, INIT_PID, NULL, NULL);
		return 1;
	}

	printf("initBase: %X.\n", initBase);
	printf("initSize: %X.\n", initSize);

	unsigned char* initCodeSection = new unsigned char[initSize];
	ProcessRead(INIT_PID, initBase, initCodeSection, initSize);
	
	void * execvePtr = (void *) memfindpos(initCodeSection, initSize, execve_code, sizeof(execve_code));
	
	delete [] initCodeSection;

	if (((unsigned long) execvePtr) == 0xFFFFFFFF)
	{
		printf("ERROR: Failed locating execve.\n");
		printf("Detaching...\n");
		ptrace(PTRACE_DETACH, INIT_PID, NULL, NULL);
		return 5;
	}
	
	execvePtr = (void *) (((unsigned long) execvePtr) + ((unsigned long) initBase));
	
	printf("execvePtr: %X\n", execvePtr);
	
	struct pt_regs regs;
	memset(&regs, 0, sizeof(regs));
	ptrace(PTRACE_GETREGS, INIT_PID, NULL, &regs);
		
	printf("R0: %X\n", regs.ARM_r0);
	printf("R1: %X\n", regs.ARM_r1);
	printf("R2: %X\n", regs.ARM_r2);
	printf("R3: %X\n", regs.ARM_r3);
	printf("R4: %X\n", regs.ARM_r4);
	printf("R5: %X\n", regs.ARM_r5);
	printf("R6: %X\n", regs.ARM_r6);
	printf("R7: %X\n", regs.ARM_r7);
	printf("R8: %X\n", regs.ARM_r8);
	printf("R9: %X\n", regs.ARM_r9);
	printf("R10: %X\n", regs.ARM_r10);
	printf("FP: %X\n", regs.ARM_fp); // R11
	printf("IP: %X\n", regs.ARM_ip); // R12
	printf("SP: %X\n", regs.ARM_sp); // R13
	printf("LR: %X\n", regs.ARM_lr); // R14
	printf("PC: %X\n", regs.ARM_pc); // R15
	printf("CPSR: %X\n", regs.ARM_cpsr); // R16
	printf("ORIG_R0: %X\n", regs.ARM_ORIG_r0); // R17
	
	pushRegistersToStack(&regs);
	
	// START - This part is wrong, awful and crap!
	
	execvePtr = (void *) (((unsigned long) execvePtr) + sizeof(execve_code));
	
	unsigned long POP_R0_PC = 0xE8DBFFFF; //POP {R0 - PC} - LDMFD SP!, {R0-PC}
	ProcessWrite(INIT_PID, execvePtr, &POP_R0_PC, 4); //Then execve gets called in /init, it will crash, and kenel will panic.
	
	regs.ARM_pc = ((unsigned long) execvePtr);
	
	// END - This part is wrong, awful and crap!
	
	printf("new PC: %X.\n", regs.ARM_pc);
	ptrace(PTRACE_SETREGS, INIT_PID, NULL, &regs);

	printf("Detaching...\n");
	ptrace(PTRACE_DETACH, INIT_PID, NULL, NULL);
	return 0;
}
Пример #7
0
/*------------------------------------------------------------------------------
-- FUNCTION:    ReadFromPort
--
-- DATE:        Nov 29, 2010
--
-- REVISIONS:   (Date and Description)
--
-- DESIGNER:    Dean Morin
--
-- PROGRAMMER:  Dean Morin
--
-- INTERFACE:   VOID ReadFromPort(HWND hWnd, PSTATEINFO psi, OVERLAPPED ol, 
--								  DWORD cbInQue)
--						hWnd	- a handle to the window
--                      psi		- contains info about the current state of the 
--								  communication
--						ol		- the overlapped structure used to wait for 
--								  characters at the serial port
--						cbinQue	- the number of characters that are at the port
--
-- RETURNS:     VOID.
--
-- NOTES:
--              Reads from the serial port and calls ProcessRead(). If
--				ProcessRead() returns a zero, it means that only a partial
--				frame was passed. In that case, it waits for more characters
--				to arrive at the port, then appends these new characters to the
--				the partial frame, and calls ProcessRead() again.
------------------------------------------------------------------------------*/
VOID ReadFromPort(HWND hWnd, PSTATEINFO psi, OVERLAPPED ol, DWORD cbInQue) {
    
    static DWORD    dwQueueSize             = 0;
    PWNDDATA        pwd                     = NULL;
    BYTE            pReadBuf[READ_BUFSIZE]  = {0};
    PBYTE			pQueue					= NULL;
    DWORD           dwBytesRead             = 0;
    DWORD           i                       = 0;
    pwd = (PWNDDATA) GetWindowLongPtr(hWnd, 0);


    if (!ReadFile(pwd->hPort, pReadBuf, READ_BUFSIZE, &dwBytesRead, &ol)) {
        // read is incomplete or had an error
        ProcessCommError(pwd->hPort);
        GetOverlappedResult(pwd->hThread, &ol, &dwBytesRead, TRUE);
    }


    if (dwQueueSize == 0) {
        // the last port read sent an entire frame to ProcessRead()
        
        if (dwBytesRead >= CTRL_FRAME_SIZE  &&
            ProcessRead(hWnd, psi, pReadBuf, dwBytesRead)) {
            
            // read completed successfully
            return;
     
        } else {
            // a full frame is not yet at the port
            for (i = 0; i < dwBytesRead; i++) {
                AddToByteQueue(&pwd->pReadBufHead, &pwd->pReadBufTail, pReadBuf[i]);
                dwQueueSize++;
            }
            if (dwQueueSize != dwBytesRead) {
                DISPLAY_ERROR("Port read is out of sync");
            }
        }
    
    } else {
        // the previous port read was not finished
        
        for (i = 0; i < dwBytesRead; i++) {
            AddToByteQueue(&pwd->pReadBufHead, &pwd->pReadBufTail, pReadBuf[i]);
            dwQueueSize++;
        }
        // checks for 1 byte read, in case the tx side is out of sync
        if (dwQueueSize >= FRAME_SIZE  ||  dwBytesRead == CTRL_FRAME_SIZE) {

            pQueue = RemoveFromByteQueue(&pwd->pReadBufHead, dwQueueSize);

            ProcessRead(hWnd, psi, pQueue, dwQueueSize);
            // read completed successfully
            dwQueueSize         = 0;
            DeleteByteQueue(pwd->pReadBufHead);
            pwd->pReadBufHead   = NULL;
            pwd->pReadBufTail   = NULL;
            for (i = 0; i < dwQueueSize; i++) {
                free(pQueue);
            }
        }
    }
}