void CryptTask::calculateMd5( const QString& path,char * result )
{
	emit titleUpdate( tr( "Calculating md5sum" ) ) ;
	emit disableCancel() ;

	zuluCryptMD5_CTX ctx ;
	zuluCryptMD5_Init( &ctx ) ;

	QByteArray p = path.toLatin1() ;

	int fd = open( p.constData(),O_RDONLY ) ;

	if( fd != -1 ){
		struct stat st ;
		fstat( fd,&st ) ;
		void * map = mmap( 0,st.st_size,PROT_READ,MAP_PRIVATE,fd,0 ) ;
		if( map != MAP_FAILED ){
			zuluCryptMD5_Update( &ctx,map,st.st_size ) ;
			munmap( map,st.st_size ) ;
			char digest[ 32 ] ;
			zuluCryptMD5_Final( ( unsigned char * )digest,&ctx ) ;
			for( int i = 0 ; i < 16 ; i++ ) {
				snprintf( &(result[i*2] ),32,"%02x",( unsigned int )digest[i] ) ;
			}
		}
		close( fd ) ;
	}
	emit enableCancel() ;
}
예제 #2
0
파일: glwidget.cpp 프로젝트: zhiyb/MathPic
void GLWidget::updateTitle()
{
	QString file = data.currentFile == -1 ? data.filePath : fileList[data.currentFile];
	emit titleUpdate(tr("MathPic <(%1, %2) * %3> %4- %5")
			 .arg(data.moveX).arg(data.moveY).arg(1. / pow(2, data.zoom))
			 .arg(data.pause ? tr("[Paused] ") : tr("")).arg(file));
}
예제 #3
0
//--------------------------------------------------------------
void camApp::update(){

	updateAppInfo();

	if( title.state == NODE_ACTIVE && title.introAllDone() ){
		title.setState(NODE_DEACTIVATING);
		state = CAM_APP_NORMAL;
		durationSameDirection = 0.0;
	}
	
	if( title.state != NODE_INACTIVE ){
		titleUpdate();
	}

	if( howTo.state != NODE_INACTIVE ){
		if( howTo.timeActive < 1.0 ){
			magRotZStartHowTo = mag.angleZ;
		}
		
		howTo.update();
		if( fabs( ofAngleDifferenceDegrees(magRotZStartHowTo, mag.angleZ) ) > 120 ){
			howTo.playMovie();
		}
		
	}
		
	if( state == CAM_APP_TITLE && title.holdPerson() ){
		//camMan.setTargetPosX(currentNode->pos.x); 
		camMan.setTargetPosY(title.pos.y);
	}else{

		riseFallUpdate();	
		
		camShiftAmntY = ofLerp(camShiftAmntY, ofMap(riseFallPct, 0, 1, -(float)ofGetHeight() * 0.175, (float)ofGetHeight() * 0.175, true), 0.03);
		
		if( state == CAM_APP_NORMAL ){

			float endGraphicOffset = 210.0;
			percentOver = ofMap( fabs(myPerson.pos.y - (endGraphic.pos.y+endGraphicOffset) ), 1000, endGraphicOffset*0.5, 0.0, 1.0, true);
			
			if( percentOver >= 0.7 ){
				
				float pct	= ofMap(percentOver, 0.7, 1.0, 0.0, 1.0, true);
				float ipct	= 1.0-pct;
				
				myPerson.vel *= 0.7 + 0.3*ipct;
				myPerson.pos.x = ofLerp(myPerson.pos.x, endGraphic.pos.x, 0.01 + pct * 0.02);
				myPerson.pos.y = ofLerp(myPerson.pos.y, endGraphic.pos.y+endGraphicOffset, 0.01 + pct * 0.02);
				
				camMan.setTargetPosY(endGraphic.pos.y * pct + (myPerson.pos.y+camShiftAmntY) * ipct);			
			}else{
				camMan.setTargetPosY(myPerson.pos.y+camShiftAmntY);
			}
						
		}
		
		if( howTo.pct > 0.2 ){
			camMan.setTargetPosY(howToStorePos.y);
		}
			
		if( makeNewNode( ofGetHeight() ) ){

			if( state == CAM_APP_NORMAL && howTo.state == NODE_INACTIVE && ofGetElapsedTimef() - nodeCreatedTime > 1.2 ){

				if( myPerson.vel.y > 0.2 ){
					nextNode(true);
				}else if( myPerson.vel.y < -0.2 ){
					nextNode(false);		
				}
				
				nodeCreatedTime = ofGetElapsedTimef();
			}
		}
		
		if( state == CAM_APP_NORMAL && nodes.size() > 0 ){
			nodes.erase(nodes.begin(), partition(nodes.begin(), nodes.end(), killNodesAndDelete)); 		
		}

	}

	if( state == CAM_APP_HOWTO ){
		limitPersonMovement(howToStorePos, -ofGetWidth()/2, ofGetWidth()/2, -(float)ofGetHeight()*0.4, (float)ofGetHeight()*0.4);
	}	

	soundMan.update(riseFallPct);
	handleRiseFall();	
	
	camMan.update(0.1, 0.04);
	world.camPos = camMan.getPosition();
	world.camRot = camMan.getRotation();
	
	camPos = world.camPos;

	if( state != CAM_APP_TITLE && !( state == CAM_APP_HOWTO && howTo.state == NODE_ACTIVE ) ){
		for(int i = 0; i < nodes.size(); i++){
			nodes[i]->update();
		}
	}
	
	sceneGraph.clearElements();
	sceneGraph.addElement(&myPerson);
	sceneGraph.addElement(&weather);
	
	if( title.state != NODE_INACTIVE ){
		sceneGraph.addElement(&title);
	}
	
	for(int i = 0; i < nodes.size(); i++){
		sceneGraph.addElement(nodes[i]);
	}
	
	//MANUAL NODEs
	weather.update();
	hand.update();
}
CryptTask::status CryptTask::decrypt()
{
	if( utility::pathExists( m_dest ) ){
		return CryptTask::destinationFileExists ;
	}
	QFile fd_1( m_mapperPath ) ;
	if( !fd_1.open( QIODevice::ReadOnly ) ){
		return CryptTask::openMapperReadFail ;
	}
	const int SIZE = 512 ;
	char buffer[SIZE] ;

	fd_1.read( buffer,SIZE ) ;

	if( memcmp( buffer + 100,buffer + 200,100 ) != 0 ){
		return CryptTask::wrongKey ;
	}

	char version[ 32 ] ;
	memcpy( version,buffer + 300,32 ) ;
	char md5sum[ 32 ] ;
	memcpy( md5sum,buffer + 332,32 ) ;

	qint64 size = atoll( buffer ) ;
	qint64 len ;
	qint64 i = 0;
	int j = 0;
	int k = -1 ;

	QFile fd_2( m_dest ) ;
	if( !fd_2.open( QIODevice::WriteOnly ) ){
		return CryptTask::createFileFail ;
	}

	emit titleUpdate( tr( "Copying Data From The Container File" ) ) ;

	if( size <= SIZE ){
		fd_1.read( buffer,size ) ;
		fd_2.write( buffer,size ) ;
		fd_2.flush() ;
	}else{
		len = size / SIZE ;

		for( i = 0 ; i < len ; i++ ){

			if( m_status == CryptTask::quit ){
				return CryptTask::quit ;
			}
			j = ( int )( i * 100 / len ) ;

			if( j > k ){
				emit progressUpdate( j ) ;
			}
			k = j ;

			fd_1.read( buffer,SIZE ) ;
			fd_2.write( buffer,SIZE ) ;
			fd_2.flush() ;
		}

		len = size - ( i * SIZE ) ;

		fd_1.read( buffer,len ) ;
		fd_2.write( buffer,len ) ;
		fd_2.flush() ;
	}

	emit progressUpdate( 100 ) ;

	char md5Data[ 32 ] ;

	char version_1[ 32 ] = { '\0' };
	strcpy( version_1,"1.0" ) ;

	if( memcmp( version,version_1,32 ) == 0 ){
		/*
		 * we are decrypting a volume using new format that embed md5 checksum of the data
		 */
		this->calculateMd5( m_dest,md5Data ) ;

		if( memcmp( md5sum,md5Data,32 ) != 0 ){
			return CryptTask::md5Fail ;
		}else{
			return CryptTask::md5Pass ;
		}
	}else{
		return CryptTask::md5Pass ;
	}
}
CryptTask::status CryptTask::encrypt()
{
	QFile fd_4( m_source ) ;

	if( !fd_4.open( QIODevice::ReadOnly ) ){
		return CryptTask::OpenSourceFail ;
	}

	QFile fd_1( m_dest ) ;

	if( !fd_1.open( QIODevice::WriteOnly ) ){
		return CryptTask::OpenDestinationFail ;
	}

	const int SIZE = 512 ;
	char buffer[ SIZE ] ;

	qint64 size = fd_4.size() ;
	qint64 source_size = size ;
	int i = 0 ;
	int j = -1 ;

	emit titleUpdate( tr( "Creating Encrypted Container File" ) ) ;

	while( size % SIZE != 0 ){
		size++ ;
	}
	size += SIZE ;

	memset( buffer,0,SIZE ) ;

	emit progressUpdate( 0 ) ;

	if( !fd_1.resize( size ) ){
		for( qint64 size_1 = 0 ; size_1 < size ; size_1 += SIZE ){

			if( m_status == CryptTask::quit ){
				return CryptTask::quit ;
			}else{
				i = ( int )( size_1 * 100 / size ) ;
				if( i > j ){
					emit progressUpdate( i ) ;
				}
				j = i ;

				fd_1.write( buffer,SIZE ) ;
				fd_1.flush() ;
			}
		}

		emit progressUpdate( 100 ) ;
	}

	fd_1.close() ;

	if( this->openMapper( m_dest ) != CryptTask::success ){
		return CryptTask::openMapperFail ;
	}

	QFile fd_2( m_mapperPath ) ;
	if( !fd_2.open(QIODevice::WriteOnly ) ){
		return CryptTask::openMapperWriteFail ;
	}

	QString s = QString::number( source_size ) ;

	fd_2.write( s.toLatin1(),s.size() ) ;

	fd_2.putChar( '\0' ) ;

	char bff[ 100 ] ;

	QFile fd_3( QString( "/dev/urandom" ) ) ;
	fd_3.open( QIODevice::ReadOnly ) ;
	fd_3.read( bff,100 ) ;
	fd_3.close() ;

	fd_2.seek( 100 ) ;

	fd_2.write( bff,100 ) ;
	fd_2.write( bff,100 ) ;

	char version[ 32 ] = { 0 };
	strcpy( version,"1.0" ) ;

	fd_2.write( version,32 ) ;

	char md5Data[ 32 ] ;

	this->calculateMd5( m_source,md5Data ) ;

	fd_2.write( md5Data,32 ) ;

	fd_2.flush() ;

	fd_2.seek( SIZE ) ;

	j = -1 ;

	emit titleUpdate( tr( "Copying Data To The Container File" ) ) ;

	emit progressUpdate( 0 ) ;

	for( qint64 size_1 = 0 ; size_1 < size ; size_1 += SIZE ){

		if( m_status == CryptTask::quit ){
			return CryptTask::quit ;
		}
		i = ( int )( size_1 * 100 / size ) ;
		if( i > j ){
			emit progressUpdate( i ) ;
		}
		j = i ;
		fd_4.read( buffer,SIZE ) ;
		fd_2.write( buffer,SIZE ) ;
		fd_2.flush() ;
	}

	fd_2.close() ;

	emit progressUpdate( 100 ) ;

	return CryptTask::success ;
}