Exemple #1
0
BOOL
MulticastAccessControl::IsValidAddress(const char* incomingAddr)
{
    ULONG32 clientAddr = _convertStrToNetLongAddr(incomingAddr,
        strlen(incomingAddr));
    return ValidateAddress(clientAddr);
}
TMsvPartList CSmtpClientMtm::ValidateMessage(TMsvPartList aPartList)
/** Validates the current message context.

The addresses for the message are checked to be well-formed email addresses.

@param aPartList Indicates the message parts for which validation is requested 
@return If valid, KErrNone If invalid, identifies the invalid part(s). The 
error value is the bitmask of the TMsvPartList IDs for each invalid part */
	{
	__ASSERT_DEBUG(iMsvEntry!=NULL,gPanic(ESmtcMTMNoCMsvEntrySet));

	TMsvPartList failed(0);
	if (aPartList & KMsvMessagePartRecipient)
		{
		if (iAddresseeList->Count() == 0)
			failed |= KMsvMessagePartRecipient;
		else
			{
			// check the recipient list for valid 'addresses'
			for (TInt ii=0; ii < iAddresseeList->Count(); ++ii)
				{
				if (((*iAddresseeList)[ii].Length() == 0) || !ValidateAddress((*iAddresseeList)[ii]))
					{
					failed |= KMsvMessagePartRecipient;
					break;
					}
				}
			}
		}
	return failed;
	}
Exemple #3
0
VOID
TransferFromMemToOutBufAndSend (
  IN    UINTN                       Length,
  IN    unsigned char               *Address
  )
{
  // there are Length bytes and every byte is represented as 2 hex chars
  CHAR8   OutBuffer[MAX_BUF_SIZE];
  CHAR8   *OutBufPtr;             // pointer to the output buffer
  CHAR8   Char;

  if (ValidateAddress(Address) == FALSE) {
    SendError(14);
    return;
  }

  OutBufPtr = OutBuffer;
  while (Length > 0) {

    Char = mHexToStr[*Address >> 4];
    if ((Char >= 'A') && (Char <= 'F')) {
      Char = Char - 'A' + 'a';
    }
    *OutBufPtr++ = Char;

    Char = mHexToStr[*Address & 0x0f];
    if ((Char >= 'A') && (Char <= 'F')) {
      Char = Char - 'A' + 'a';
    }
    *OutBufPtr++ = Char;

    Address++;
    Length--;
  }

  *OutBufPtr = '\0' ;  // the end of the buffer
  SendPacket (OutBuffer);
}
Exemple #4
0
BOOL
MulticastAccessControl::IsValidAddress(ULONG32 clientAddr)
{
    return ValidateAddress(clientAddr);
}
Exemple #5
0
void FunctionPass::AnalysisWorker(duint Start, duint End, std::vector<FunctionDef>* Blocks)
{
    //
    // Step 1: Use any defined functions in the PE function table
    //
    FindFunctionWorkerPrepass(Start, End, Blocks);

    //
    // Step 2: for each block that contains a CALL flag,
    // add it to a local function start array
    //
    // NOTE: *Some* indirect calls are included
    auto blockItr = std::next(m_MainBlocks.begin(), Start);

    for(duint i = Start; i < End; i++, ++blockItr)
    {
        if(blockItr->GetFlag(BASIC_BLOCK_FLAG_CALL))
        {
            duint destination = blockItr->Target;

            // Was it a pointer?
            if(blockItr->GetFlag(BASIC_BLOCK_FLAG_INDIRPTR))
            {
                // Read it from memory
                if(!MemRead(destination, &destination, sizeof(duint)))
                    continue;

                // Validity check
                if(!MemIsValidReadPtr(destination))
                    continue;

                dprintf(QT_TRANSLATE_NOOP("DBG", "Indirect pointer: 0x%p 0x%p\n"), blockItr->Target, destination);
            }

            // Destination must be within analysis limits
            if(!ValidateAddress(destination))
                continue;

            Blocks->push_back({ destination, 0, 0, 0, 0 });
        }
    }

    //
    // Step 3: Sort and remove duplicates
    //
    std::sort(Blocks->begin(), Blocks->end());
    Blocks->erase(std::unique(Blocks->begin(), Blocks->end()), Blocks->end());

    //
    // Step 4: Find function ends
    //
    FindFunctionWorker(Blocks);

    //
    // Step 5: Find all orphaned blocks and repeat analysis process
    //
    // Starting from the first global block, scan until an "untouched" block is found
    blockItr = std::next(m_MainBlocks.begin(), Start);

    // Cached final block
    BasicBlock* finalBlock = &m_MainBlocks.back();

    duint virtEnd = 0;
    for(duint i = Start; i < End; i++, ++blockItr)
    {
        if(blockItr->VirtualStart < virtEnd)
            continue;

        // Skip padding
        if(blockItr->GetFlag(BASIC_BLOCK_FLAG_PAD))
            continue;

        // Is the block untouched?
        if(blockItr->GetFlag(BASIC_BLOCK_FLAG_FUNCTION))
            continue;

        // Try to define a function
        FunctionDef def { blockItr->VirtualStart, 0, 0, 0, 0 };

        if(ResolveFunctionEnd(&def, finalBlock))
        {
            Blocks->push_back(def);
            virtEnd = def.VirtualEnd;
        }
    }
}
Exemple #6
0
int main(int argc, char *argv[])
{
    
    fd_set master;                  // master file descriptor list
    fd_set read_fds;                // temp file descriptor list for select()
    struct sockaddr_in remoteaddr;  // client address
    unsigned ServerPort;            // portnumber of server 
    int fdmax,fdmax_used;           // maximum file descriptor number and helper to find new max 
    int listener;                   // listening socket descriptor
    int newfd;                      // newly accept()ed socket descriptor
    char buf[256];                  // buffer for client data
    int nbytes;
    int addrlen;
    int i, j;
    int NewClient;                  // NewClient ID
    struct timeval timeout;         // timeout 
    int ret; 
    struct ClientListType *ptrNewClient;              // ptr to new & Active Client;
    struct ClientListType *ptrClientRightList;                          // array which contains rights of reg.Clients      
    struct ActiveClientStructType ActiveClientStruct;                       // struct which contains array of active cl.
    
    
    // some command line parsing
    
    if (argc>1) {  // first argument might be a port assignment
	if (*argv[1]=='?') { // ask for help
	    printf("Usage : %s PortNum\n",argv[0]);
	    exit(EXIT_SUCCESS);
	} else {
	    ServerPort=atol(argv[1]);
	}
    } else {
	ServerPort=TCP_CLIENT_PORT;
    }
    
    //  Init Client Access list
    InitClientAccessList(ptrClientRightAscList, &ptrClientRightList);
    
    // Init Active Client List
    InitActiveClientStruct(&ActiveClientStruct);
    
    
    printf("Setup instrument server version %s on port %d ...",VERSION, ServerPort);
    listener=InitTCPListener(ServerPort);
    if (listener<1) {
	perror("TCPListener");
    }
    printf("success\n");
    
    // setup master fd
    FD_ZERO(&master);              // clear the master and temp sets
    FD_ZERO(&read_fds);
    FD_SET(listener, &master);     // add the listener to the master set
    
    // keep track of the biggest file descriptor
    
    fdmax = listener; // so far, it's this one

    for(;;) { // main loop

        // setup fd's timeout and wait for incoming request
        read_fds = master;
        timeout.tv_sec=TCP_CLIENT_WDG;
        timeout.tv_usec=0;
        ret=select(fdmax+1, &read_fds, NULL, NULL, &timeout);
        
        if (ret == -1) { // select error we dare not to handle
            perror("select");
            exit(EXIT_FAILURE);
        }
	
        if (ret) { // lets see what we got
	    for(i = 0; i <= fdmax; i++) {
		if (FD_ISSET(i, &read_fds)) {                                // new msg on i. socket ...
		    if (i == listener) {                                     // listener -> new connection request
			addrlen = sizeof(remoteaddr);			
			if ((newfd = accept(listener, (struct sockaddr *)&remoteaddr,           // first we have to accept
					    &addrlen)) == -1) {
			    perror("accept");
			} else {
			    //Valid client ?
			    if ( ((ptrNewClient=ValidateAddress(&remoteaddr,ptrClientRightList))!=NULL) ) {
				//add new client to active list
				if ((NewClient=AddClientToList(&ActiveClientStruct,ptrNewClient,newfd))<0) { // couldn't add Client to list;
				    printf("no available sockets for fd %d\n",newfd);
				    close(newfd); // close connection
				} else {          // give a positive msg to the log and keep track of maxfd
				    printf("accepted new connection from %s\n",
					   ActiveClientStruct.ptrActiveClientArray[NewClient].ClientName);
				    FD_SET(newfd, &master); // add to master set  
				    if (newfd > fdmax) {    // keep trackof the maximum
					fdmax = newfd;
				    }
				} // endif AddClient
			    } else {   // couldn't find applicant in internal rights list, kick him out
				close(newfd);
				printf("deny access from %s closing..\n",inet_ntoa(remoteaddr.sin_addr));
			    } // endif ValidateAddress
			    
			} // endif accept
		    } else {                                                // handle data from a clients
			if ((nbytes = recv(i, buf, sizeof(buf), 0)) <= 0) { // got error or connection closed by client
			    if (nbytes == 0) {                              // connection closed
				ret=RemoveClientFromList(&ActiveClientStruct,i);
				printf("instrumentserver: %s on socket %d hung up\n", 
				       ActiveClientStruct.ptrActiveClientArray[ret].ClientName, i);
			    } else {
				perror("recv");
			    } // EndIf recv
			    close(i); // bye!
			    FD_CLR(i, &master); // remove from master set
			} else { // we got some data from a client
			    
			    // display whats in decimal for first
			    
			    ParseMsg(buf,nbytes,&ActiveClientStruct);
			    
			    for(j = 0; j <= fdmax; j++) {
				// send to everyone
				if (FD_ISSET(j, &master)) {
				    // except the listener and sender
				    if (j != listener && j != i) {
					if (send(j, buf, nbytes, 0) == -1) {
					    perror("send");
					} //endif send					
				    }  // sender and listener
				} // someone in master list
			    } //endfor all clients
			}
		    }
		}
	    }
	} else {
	    for (i = 0; i <= fdmax; i++) {
		if (FD_ISSET(i,&master)) {
		    printf("+");
		    fdmax_used=i;                               // find out what the highest used fd is
		} else {
		    printf(".");
		}
	    }
	    printf("\n");
	    fdmax=fdmax_used;                                  // garbage collection on max fdnum
	}
    } // for main loop
    
    
// release used memory
    
    ReleaseActiveClientStruct(&ActiveClientStruct);            // relase memory of ActiveClientStruct
    ReleaseClientAccessList(ptrClientRightList);               // relase memory of ClientRightList
    
    return EXIT_SUCCESS;
}
Exemple #7
0
void LinearPass::AnalysisOverlapWorker(duint Start, duint End, BBlockArray* Insertions)
{
    // Comparison function to see if two blocks overlap
    auto BlockOverlapsRemove = [](BasicBlock * A, BasicBlock * B) -> BasicBlock*
    {
        // Do the blocks overlap?
        if(max(A->VirtualStart, B->VirtualStart) <= min((A->VirtualEnd - 1), (B->VirtualEnd - 1)))
        {
            // Return the block that should be removed
            if(A->Size() > B->Size())
                return B;

            return A;
        }

        return nullptr;
    };

    // Get a pointer to pure data
    const auto blocks = m_MainBlocks.data();

    for(duint i = Start; i < End; i++)
    {
        const auto curr = &blocks[i];
        const auto next = &blocks[i + 1];

        // Current versus next (overlap -> delete)
        BasicBlock* removal = BlockOverlapsRemove(curr, next);

        if(removal)
            removal->SetFlag(BASIC_BLOCK_FLAG_DELETE);

        // Find blocks that need to be split in two because
        // of CALL/JMP targets
        //
        // Find targets in the virtual range
        if(ValidateAddress(curr->Target))
        {
            removal = FindBBlockInRange(curr->Target);

            if(removal)
            {
                if(curr->GetFlag(BASIC_BLOCK_FLAG_CALL))
                    removal->SetFlag(BASIC_BLOCK_FLAG_CALL_TARGET);

                // If the target does not equal the block start...
                if(curr->Target != removal->VirtualStart)
                {
                    // Mark for deletion
                    removal->SetFlag(BASIC_BLOCK_FLAG_DELETE);

                    // Block part 1
                    BasicBlock block1;
                    block1.VirtualStart = removal->VirtualStart;
                    block1.VirtualEnd = curr->Target;
                    block1.Target = 0;
                    block1.Flags = BASIC_BLOCK_FLAG_CUTOFF; // Attributes of the top half
                    block1.InstrCount = removal->InstrCount;

                    // Block part 2
                    BasicBlock block2;
                    block2.VirtualStart = curr->Target;
                    block2.VirtualEnd = removal->VirtualEnd;
                    block2.Target = removal->Target;
                    block2.Flags = removal->Flags;          // Attributes of the bottom half (taken from original block)
                    block2.InstrCount = removal->InstrCount;

                    Insertions->push_back(block1);
                    Insertions->push_back(block2);
                }
            }
        }
    }
}