Exemplo n.º 1
0
//=========Functions
SaPlayerWidget::SaPlayerWidget(QWidget *parent)
: QWidget(parent)
{		
		saConfigFilePathString = QDir::currentPath()  + "/../../../Config";
		saConfigFilePathString = QDir::cleanPath(saConfigFilePathString);
		//----------
		createDirModel();
		createFileList();
		readFileData();
		processFileData();
		createInfoDisplayScreen();
		createControlPlane();
		createPlayerPlane();
		//-------Layouts
		QHBoxLayout * hLayout_1 = new QHBoxLayout;
		hLayout_1->addWidget(saFilesComboBox);
		hLayout_1->addWidget(freshDocumentFilesPushButton);
		hLayout_1->addWidget(openSaConfigFilePushButton);
		
		QHBoxLayout * hLayout_2 = new QHBoxLayout;
		hLayout_2->addWidget(openContainerPushButton);
		hLayout_2->addWidget(activePushButton);
		hLayout_2->addWidget(currentStepSpinBox);

		QVBoxLayout * vLayout_1 = new QVBoxLayout;
		vLayout_1->addLayout(hLayout_1);
		vLayout_1->addWidget(recordNowJointsDataPushButton);
		vLayout_1->addLayout(hLayout_2);
		vLayout_1->addWidget(playPlaneGroupBox);
		vLayout_1->addWidget(infoDisplayScreenTreeView);
		//vLayout_1->addWidget(cfgTextEdit);
		setLayout(vLayout_1);
}
Exemplo n.º 2
0
/*  
    Prepare a data packet for sending downstream. This involves reading file data into a suitably sized packet. Return
    the 1 if the packet was sent entirely, return zero if the packet could not be completely sent. Return a negative
    error code for write errors. This may split the packet if it exceeds the downstreams maximum packet size.
 */
static int prepPacket(HttpQueue *q, HttpPacket *packet)
{
    HttpQueue   *nextQ;
    ssize       size, nbytes;	
    nextQ = q->nextQ;
    if (packet->esize > nextQ->packetSize) {
        httpPutBackPacket(q, httpSplitPacket(packet, nextQ->packetSize));
        size = nextQ->packetSize;
    } else {
        size = (ssize) packet->esize;
    }
    if ((size + nextQ->count) > nextQ->max) {
        /*  
            The downstream queue is full, so disable the queue and service downstream queue.
            Will re-enable via a writable event on the connection.
         */
        httpSuspendQueue(q);
        if (!(nextQ->flags & HTTP_QUEUE_SUSPENDED)) {
            httpScheduleQueue(nextQ);
        }
        return 0;
    }
    if ((nbytes = readFileData(q, packet, q->ioPos, size)) != size) {
        return MPR_ERR_CANT_READ;
    }
    q->ioPos += nbytes;
    return 1;
}
Exemplo n.º 3
0
static int fuzzEnvelope( const char *fuzzFileName )
	{
	CRYPT_ENVELOPE cryptEnvelope;
	BYTE buffer[ 4096 ];
	int length, bytesIn, status;

	/* Create the envelope */
	status = cryptCreateEnvelope( &cryptEnvelope, CRYPT_UNUSED, 
								  CRYPT_FORMAT_AUTO );
	if( cryptStatusError( status ) )
		return( status );

	/* We're ready to go, start the forkserver and read the mutable data */
#ifndef __WINDOWS__
	__afl_manual_init();
#endif /* !__WINDOWS__ */
	length = readFileData( fuzzFileName, fuzzFileName, buffer, 4096, 64, 
						   TRUE );
	if( length < 64 )
		return( CRYPT_ERROR_READ );

	/* Process the input file */
	( void ) cryptPushData( cryptEnvelope, buffer, length, &bytesIn );
	cryptDestroyEnvelope( cryptEnvelope );

	return( CRYPT_OK );
	}
Exemplo n.º 4
0
//==============================================================================
bool PEFile::loadFromFile(char* filePath) {
    unloadFile();

    return readFileData(filePath) &&
           readHeaders() &&
           readBody() &&
           readImportTable();
}
Exemplo n.º 5
0
void SaPlayerWidget::freshCurrentFile()
{
	readFileData();
	processFileData();
	currentStepSpinBox->setValue(1);
	freshModelData();
	currentStepSpinBox->setRange(1,jointValueVector.size());
}
Exemplo n.º 6
0
static node_t * createTreeFromFile(const char * definitionsFilePath)
{
    size_t length = 0;
    char * data = readFileData(definitionsFilePath, &length);
    char * buff = malloc(sizeof(char) * 32);
    
    int bytesRead = 0;
    
    float darkness = 0;
    char * letter = 0;
    
    for (int i=0; i<length; i++) {
        char c = data[i];
        
        if (bytesRead > 32) {
            printf("Definitions file contains value that is longer than 32 bytes");
            exit(EXIT_FAILURE);
        }
        
        memcpy(buff+bytesRead, &c, 1);
        
        bytesRead++;
        
        
        if (c == ':' || c == '\n' || c == ';') {
            
            char * str = malloc(bytesRead * sizeof(char));
            memset(str, 0, bytesRead);
            memcpy(str, buff, bytesRead-1);
            
            bytesRead = 0;
            
            if (c == ':') {
                //First section - a letter
                letter = malloc(sizeof(str));
                strcpy(letter, str);
            } else {
                //Second section - a float
                darkness = atof(str);
                
                if (treeRoot == NULL) {
                    treeRoot = newNode(letter, darkness);
                } else {
                    insertLetter(treeRoot, letter, darkness);
                    free(letter);
                }
            }
            
            free(str);
            
        }
    }
    
    free(buff);
    free(data);
    
    return treeRoot;
}
Exemplo n.º 7
0
int main(int argc, char **argv)
{
    int file_id;
    int pipe_fd;
    int read_bytes;
    int open_mode = O_WRONLY;
    int read_bytes_sum = 0;
    char *file_name = argv[1];
    u_int8_t *buffer = (u_int8_t *)malloc(BUFFER_SIZE);

    if (argc < 2) {
        printf("Please use format [fifo_send filename]\n");
        exit(EXIT_FAILURE);
    }

    // Check fifo file exist wether or not.
    if (access(FIFO_NAME, F_OK) == -1) {
        if (mkfifo(FIFO_NAME, 0777) != 0) {
            printf("Error, can not create fifo!\n");
            exit(EXIT_FAILURE);
        }
    }

    printf("--------------------------\n");
    printf("Process Communication Test\n");
    printf("--------------------------\n");
    printf("Waiting fifo receiver.....\n");
    pipe_fd = open(FIFO_NAME, open_mode);

    // Open the file, and type is read-only.
    if (!openReadFile(&file_id, file_name)) {
        printf("Error, can not open file!\n");
        exit(EXIT_FAILURE);
    }

    if (pipe_fd == -1) {
        printf("Error, can not open fifo!\n");
        exit(EXIT_FAILURE);
    }

    printf("Sending data......\n");

    do {
        // Read data from file.
        read_bytes = readFileData(buffer, file_id, BUFFER_SIZE);
        // Write data to fifo.
        if (write(pipe_fd, (char *)buffer, read_bytes) < 0) {
            printf("Error, can not write!\n");
        }
        read_bytes_sum += read_bytes;
        printData(read_bytes_sum / CONVERSION_UNIT);
    } while (read_bytes > 0);

    printf("\nSending data: %d bytes\n", read_bytes_sum);
    closeFile(file_id, file_name);
    return 0;
}
Exemplo n.º 8
0
QPixmap GxtFile::readDDSFile(int index)
{
    if (index > fileCount || index < 1)
        return QPixmap();

    QByteArray dds = readFileData(index);
    QPixmap pixmap;
    pixmap.loadFromData(dds);

    return pixmap;
}
Exemplo n.º 9
0
//普通方式匹配文件内容
bool ThreadWork::matchFileCont( wxString &path )
{
	wxString *cont = new wxString;
	readFileData( path, *cont );
	if( cont->Find( parItems[3] ) != wxNOT_FOUND )
	{
		cont->Clear();
		return true;
	}
	cont->Clear();
	return false;
}
Exemplo n.º 10
0
static int fuzzSpecial( const int fuzzType, const char *fuzzFileName )
	{
	CRYPT_CONTEXT cryptPrivKey;
	BYTE buffer[ 8192 ];
	const int minLength = ( fuzzType == 4000 ) ? 2 : 16;
	int length, status;

	/* If we're fuzzing bignum ops, load the private key that we'll need */
	if( fuzzType == 4000 )
		{
		if( !loadRSAContexts( CRYPT_UNUSED, NULL, &cryptPrivKey ) )
			return( CRYPT_ERROR_FAILED );
		}

	/* We're ready to go, start the forkserver and read the mutable data */
#ifndef __WINDOWS__
	__afl_manual_init();
#endif /* !__WINDOWS__ */
	length = readFileData( fuzzFileName, fuzzFileName, buffer, 8192, 
						   minLength, TRUE );
	if( length < minLength )
		return( CRYPT_ERROR_READ );

	/* Process the input file */
	if( fuzzType == 4000 )
		{
		BYTE tmpBuffer[ 8192 ];

#if 0	/* We don't do an early-out in order to check that the bignum code 
		   can actually reject all invalid input values */
		/* Any value that's larger than the modulus will be trivially 
		   rejected so there's no point in trying to process it */
		if( buffer[ 0 ] > 0x9C )
			{
			cryptDestroyContext( cryptPrivKey );
			return( CRYPT_OK );
			}
#endif /* 0 */

		memcpy( tmpBuffer, buffer, length );
		status = cryptDecrypt( cryptPrivKey, buffer, length );
		if( cryptStatusOK( status ) )
			status = cryptEncrypt( cryptPrivKey, buffer, length );
		if( cryptStatusOK( status ) )
			{
			/* Make sure that we got back what we started with */
			assert( !memcmp( buffer, tmpBuffer, length ) );
			}
		cryptDestroyContext( cryptPrivKey );
		}
Exemplo n.º 11
0
//正则方式匹配文件内容
bool ThreadWork::regexMatchFileCont( wxString &path )
{
	wxString *cont = new wxString;
	readFileData( path, *cont );
	wxRegEx re( parItems[3], wxRE_ADVANCED );

	if( !re.IsValid() )
		return false;
	
	if( re.Matches( *cont ) )
	{
		cont->Clear();
		return true;
	}
	cont->Clear();
	return false;
}
Exemplo n.º 12
0
static int fuzzFile( const char *fuzzFileName )
	{
	CRYPT_CERTIFICATE cryptCert;
	BYTE buffer[ 4096 ];
	int length, status;

	/* Read the data to fuzz */
	length = readFileData( fuzzFileName, fuzzFileName, buffer, 4096, 64, 
						   TRUE );
	if( length < 64 )
		return( CRYPT_ERROR_READ );

	/* Process the input file */
	status = cryptImportCert( buffer, length, CRYPT_UNUSED, &cryptCert );
	if( cryptStatusOK( status ) )
		cryptDestroyCert( cryptCert );

	return( CRYPT_OK );
	}
Exemplo n.º 13
0
int main (int nArgc, char* szArgv[]) {
	int i;
	if (nArgc < 2) {
		fprintf(stderr, "usage: %s { file }\n", szArgv[0]);
		return 1;
	}
	for (i= 1; i < nArgc; i++) {
		char* sData;
		long nDataLen;
		int nResult= readFileData(szArgv[i], &sData, &nDataLen);
		if (nResult != 0) {
			fprintf(stderr, "couldn't read %s (%s).\n", szArgv[i], 
				getReadFileDataErrorDescription(nResult));
		} else {
			parse(sData, nDataLen);
			free(sData);
		}
	}
	topology_status();
	return 0;
}
Exemplo n.º 14
0
//------------------------------------------------------------------------------
GLuint createShader(GLenum shaderType, const std::string &filename ){
  GLuint shader = glCreateShader( shaderType );
  std::string filedata;
  readFileData( filename, filedata );
  const char *strFileData = filedata.c_str();
  glShaderSource( shader, 1, &strFileData, 0 );

  glCompileShader( shader );

  GLint status;
  glGetShaderiv( shader, GL_COMPILE_STATUS, &status );
  if (status == GL_FALSE){
    GLint infoLogLength;
    glGetShaderiv( shader, GL_INFO_LOG_LENGTH, &infoLogLength );

    GLchar *strInfoLog = new GLchar[infoLogLength + 1];
    glGetShaderInfoLog(shader, infoLogLength, 0, strInfoLog);

    const char *strShaderType = 0;
    switch( shaderType ){
    case GL_VERTEX_SHADER:
      strShaderType = "vertex";
      break;
    case GL_GEOMETRY_SHADER:
      strShaderType = "geometry";
      break;
    case GL_FRAGMENT_SHADER:
      strShaderType = "fragment";
      break;
    }

    fprintf( stderr,
	     "Compile failure in %s shader:\n%s\n", strShaderType, strInfoLog );
    delete[] strInfoLog;
  }

  return shader;
}
Exemplo n.º 15
0
/*
 * server class thread.
 * serve one client request.
 */
void
_run_TCP_Server_Class(int clnt_sock,Server* Ser) {
    int         FD;
    uint32_t    Pos,Dsize,Fdpos,Size,Seg;
    uint32_t    Times;
    uint8_t     *Temp;
    string      name;
    name = Ser->get_Dname();
    FD = Ser->get_FD();
    Times = Ser->getmTimes();
    read(clnt_sock,&Size,sizeof(Size));
    read(clnt_sock,&Seg,sizeof(Seg));
    write(clnt_sock,&Seg,sizeof(Seg));
    Temp = (uint8_t*)calloc(Size,sizeof(uint8_t));
    while (read(clnt_sock,&Pos,sizeof(Pos)) != 0) {
        Fdpos = Pos * Size;
        Dsize = readFileData(FD,Fdpos,TOCHARP(Temp),Size);
        usleep(Times);
        if (Pos == Seg - 1) {
            write(clnt_sock,&Dsize,sizeof(Dsize));
        }
        write(clnt_sock,TOCHARP(Temp),Dsize);
    }
    /*
     * delete server form server pool when delete flag on
     * delete flag : serv_Count == 0 && Serv_Map delete
     */
    pthread_mutex_lock(&Serv_lock);
    close(clnt_sock);
    free(Temp);
    Serv_Count[name]--;
    if ((Serv_Count[name] == 0) && (Serv_Map.find(name) == Serv_Map.end())) {
        Serv_Count.erase(name);
        Ser->finish();
        free(Ser);
    }
    pthread_mutex_unlock(&Serv_lock);
}
Exemplo n.º 16
0
static int fuzzSession( const CRYPT_SESSION_TYPE sessionType,
						const char *fuzzFileName )
	{
	CRYPT_SESSION cryptSession;
	CRYPT_CONTEXT cryptPrivKey = CRYPT_UNUSED;
	BYTE buffer[ 4096 ];
	const BOOLEAN isServer = \
			( sessionType == CRYPT_SESSION_SSH_SERVER || \
			  sessionType == CRYPT_SESSION_SSL_SERVER || \
			  sessionType == CRYPT_SESSION_OCSP_SERVER || \
			  sessionType == CRYPT_SESSION_RTCS_SERVER || \
			  sessionType == CRYPT_SESSION_TSP_SERVER || \
			  sessionType == CRYPT_SESSION_CMP_SERVER || \
			  sessionType == CRYPT_SESSION_SCEP_SERVER ) ? \
			TRUE : FALSE;
	int length, status;

	/* Create the session */
	status = cryptCreateSession( &cryptSession, CRYPT_UNUSED, sessionType );
	if( cryptStatusError( status ) )
		return( status );

	/* Set up the various attributes needed to establish a minimal session */
	if( !isServer )
		{
		status = cryptSetAttributeString( cryptSession,
										  CRYPT_SESSINFO_SERVER_NAME,
										  "localhost", 9 );
		if( cryptStatusError( status ) )
			return( status );
		}
	if( isServer )
		{
		if( !loadRSAContexts( CRYPT_UNUSED, NULL, &cryptPrivKey ) )
			return( CRYPT_ERROR_FAILED );
		}
	if( sessionType == CRYPT_SESSION_SSH || \
		sessionType == CRYPT_SESSION_CMP )
		{
		status = cryptSetAttributeString( cryptSession,
										  CRYPT_SESSINFO_USERNAME,
										  SSH_USER_NAME,
										  paramStrlen( SSH_USER_NAME ) );
		if( cryptStatusOK( status ) )
			{
			status = cryptSetAttributeString( cryptSession,
											  CRYPT_SESSINFO_PASSWORD,
											  SSH_PASSWORD,
											  paramStrlen( SSH_PASSWORD ) );
			}
		if( cryptStatusError( status ) )
			return( status );
		}
	if( sessionType == CRYPT_SESSION_CMP )
		{
		status = cryptSetAttribute( cryptSession,
									CRYPT_SESSINFO_CMP_REQUESTTYPE,
									CRYPT_REQUESTTYPE_INITIALISATION );
		if( cryptStatusError( status ) )
			return( status );
		}

	/* Perform any final session initialisation */
	cryptFuzzInit( cryptSession, cryptPrivKey );

	/* We're ready to go, start the forkserver and read the mutable data */
#ifndef __WINDOWS__
	__afl_manual_init();
#endif /* !__WINDOWS__ */
	length = readFileData( fuzzFileName, fuzzFileName, buffer, 4096, 32, 
						   TRUE );
	if( length < 32 )
		return( CRYPT_ERROR_READ );

	/* Perform the fuzzing */
	( void ) cryptSetFuzzData( cryptSession, buffer, length );
	cryptDestroySession( cryptSession );
	if( cryptPrivKey != CRYPT_UNUSED )
		cryptDestroyContext( cryptPrivKey );

	return( CRYPT_OK );
	}
Exemplo n.º 17
0
int main(int argc, char **argv)
{
    int file_id;
    int bytes_num = 0;
    int shared_memory_id;
    void *memory_to_shared = NULL;
    char *file_name = argv[1];
    long long bytes_has_read = 0;
    u_int8_t *buffer = (u_int8_t *)malloc(BUFFER_SIZE);
    MemoryType *shared_memory;

    if (argc < 2) {
        printf("Please use format [shared_send filename]\n");
        exit(EXIT_FAILURE);
    }

    // Open the file, and type is read-only.
    if (!openReadFile(&file_id, file_name)) {
        printf("Error, can not open file!\n");
        exit(EXIT_FAILURE);
    }

    // Create the shared space.
    if ((shared_memory_id = shmget((key_t)11111, sizeof(MemoryType),
                                   0666 | IPC_CREAT)) == -1) {
        printf("Error, can not initial the shared memory!\n");
        exit(EXIT_FAILURE);
    }

    // Get the first address of shared memory.
    if ((memory_to_shared = shmat(shared_memory_id, (void *)0, 0)) ==
        (void *)-1) {
        printf("Error, can not get the shared memory!\n");
        exit(EXIT_FAILURE);
    }

    shared_memory = (MemoryType *)memory_to_shared;
    shared_memory->has_client = FALSE;
    shared_memory->has_data   = TRUE;

    printf("--------------------------\n");
    printf("Process Communication Test\n");
    printf("--------------------------\n");
    printf("Waiting shared receiver...\n");
    printf("Sending data......\n");

    while (TRUE) {
        if (shared_memory->has_client == FALSE) {
            continue;
        }
        if (!shared_memory->has_data) {
            memset(buffer, '\0', BUFFER_SIZE);
            // Read data from file.
            bytes_num = readFileData(buffer, file_id, BUFFER_SIZE);
            bytes_has_read += bytes_num;
            printData(bytes_has_read / CONVERSION_UNIT);
            // Empty the buffer.
            memset(shared_memory->buffer, '\0', BUFFER_SIZE);
            // Write data to shared memory.
            memcpy(shared_memory->buffer, buffer, bytes_num);
            shared_memory->write_byte_num = (bytes_num <= 0) ? -1 : bytes_num;
            shared_memory->has_data = TRUE;
            if (bytes_num <= 0) {
                break;
            }
        }
    }

    printf("\nSending data: %lld bytes\n", bytes_has_read);

    // Separate shared memory from the process.
    if (shmdt((void *)shared_memory) == -1) {
        printf("Error, can not separate shared memory from the process!\n");
        exit(EXIT_FAILURE);
    }

    // Delete shared memory.
    if (shmctl(shared_memory_id, IPC_RMID, 0) == -1) {
        printf("Error, can not delete shared memory!\n");
        exit(EXIT_FAILURE);
    }

    return 0;
}