Example #1
0
status_t
Header::Write(int fd)
{
	// Try to write the protective MBR
	PartitionMap partitionMap;
	PrimaryPartition *partition = NULL;
	uint32 index = 0;
	while ((partition = partitionMap.PrimaryPartitionAt(index)) != NULL) {
		if (index == 0) {
			uint64 deviceSize = fHeader.AlternateBlock() * fBlockSize;
			partition->SetTo(fBlockSize, deviceSize, 0xEE, false, fBlockSize);
		} else
			partition->Unset();
		++index;
	}
	PartitionMapWriter writer(fd, fBlockSize);
	writer.WriteMBR(&partitionMap, true);
		// We also write the bootcode, so we can boot GPT disks from BIOS

	status_t status = _Write(fd, fHeader.EntriesBlock() * fBlockSize, fEntries,
		_EntryArraySize());
	if (status != B_OK)
		return status;

	// First write the header, so that we have at least one completely correct
	// data set
	status = _WriteHeader(fd);


	// Write backup entries
	status_t backupStatus = _Write(fd,
		fBackupHeader.EntriesBlock() * fBlockSize, fEntries, _EntryArraySize());

	return status == B_OK ? backupStatus : status;
}
Example #2
0
status_t
VolumeCryptContext::Setup(int fd, const uint8* key, uint32 keyLength,
	const uint8* random, uint32 randomLength)
{
	off_t size;
	status_t status = get_size(fd, size);
	if (status != B_OK)
		return status;

	fOffset = max_c(4096, BLOCK_SIZE);
	fSize = size - fOffset;
	fHidden = false;

	const uint8* salt = random;
	random += PKCS5_SALT_SIZE;

	uint8 buffer[BLOCK_SIZE];
	memcpy(buffer, salt, PKCS5_SALT_SIZE);
	memset(buffer + PKCS5_SALT_SIZE, 0, BLOCK_SIZE - PKCS5_SALT_SIZE);

	true_crypt_header& header = *(true_crypt_header*)&buffer[PKCS5_SALT_SIZE];
	header.magic = B_HOST_TO_BENDIAN_INT32(kTrueCryptMagic);
	header.version = B_HOST_TO_BENDIAN_INT16(0x4);
	header.required_program_version = B_HOST_TO_BENDIAN_INT16(0x600);
	header.volume_size = B_HOST_TO_BENDIAN_INT64(fSize);
	header.encrypted_offset = B_HOST_TO_BENDIAN_INT64(fOffset);
	header.encrypted_size = B_HOST_TO_BENDIAN_INT64(fSize);
	header.flags = 0;
	memcpy(header.disk_key, random, sizeof(header.disk_key));
	header.crc_checksum = B_HOST_TO_BENDIAN_INT32(crc32(header.disk_key, 256));
	header.header_crc_checksum
		= B_HOST_TO_BENDIAN_INT32(crc32((uint8*)&header, 188));

	return _WriteHeader(fd, key, keyLength, 0, buffer);
}
Example #3
0
status_t
Header::Write(int fd)
{
	status_t status = _Write(fd, fHeader.EntriesBlock() * fBlockSize, fEntries,
		_EntryArraySize());
	if (status != B_OK)
		return status;

	// First write the header, so that we have at least one completely correct
	// data set
	status = _WriteHeader(fd);

	// Write backup entries
	status_t backupStatus = _Write(fd,
		fBackupHeader.EntriesBlock() * fBlockSize, fEntries, _EntryArraySize());

	return status == B_OK ? backupStatus : status;
}
Example #4
0
status_t
Header::WriteEntry(int fd, uint32 entryIndex)
{
	off_t entryOffset = entryIndex * fHeader.EntrySize();

	status_t status = _Write(fd,
		fHeader.EntriesBlock() * fBlockSize + entryOffset,
		fEntries + entryOffset, fHeader.EntrySize());
	if (status != B_OK)
		return status;

	// Update header, too -- the entries CRC changed
	status = _WriteHeader(fd);

	// Write backup
	status_t backupStatus = _Write(fd,
		fBackupHeader.EntriesBlock() * fBlockSize + entryOffset,
		fEntries + entryOffset, fHeader.EntrySize());

	return status == B_OK ? backupStatus : status;
}
Example #5
0
status_t
VolumeCryptContext::SetPassword(int fd, const uint8* oldKey,
	uint32 oldKeyLength, const uint8* newKey, uint32 newKeyLength)
{
	off_t headerOffset;
	uint8 buffer[BLOCK_SIZE];
	true_crypt_header header;
	status_t status = _Detect(fd, oldKey, oldKeyLength, headerOffset, buffer,
		header);
	if (status != B_OK)
		return status;

//	header.required_program_version = B_HOST_TO_BENDIAN_INT16(0x800);
	header.volume_size = B_HOST_TO_BENDIAN_INT64(fSize);
	header.crc_checksum = B_HOST_TO_BENDIAN_INT32(crc32(header.disk_key, 256));
	header.header_crc_checksum
		= B_HOST_TO_BENDIAN_INT32(crc32((uint8*)&header, 188));
	memcpy(buffer + PKCS5_SALT_SIZE, &header, sizeof(true_crypt_header));

dprintf("HEADER OFFSET: %Ld\n", headerOffset);
dprintf("NEW KEY: %s\n", newKey);
	return _WriteHeader(fd, newKey, newKeyLength, headerOffset, buffer);
}
Example #6
0
status_t
Header::WriteEntry(int fd, uint32 entryIndex)
{
	// Determine block to write
	off_t blockOffset =
		+ entryIndex * fHeader.EntrySize() / fBlockSize;
	uint32 entryOffset = entryIndex * fHeader.EntrySize() % fBlockSize;

	status_t status = _Write(fd,
		(fHeader.EntriesBlock() + blockOffset) * fBlockSize,
		fEntries + entryOffset, fBlockSize);
	if (status != B_OK)
		return status;

	// Update header, too -- the entries CRC changed
	status = _WriteHeader(fd);

	// Write backup
	status_t backupStatus = _Write(fd,
		(fBackupHeader.EntriesBlock() + blockOffset) * fBlockSize,
		fEntries + entryOffset, fBlockSize);

	return status == B_OK ? backupStatus : status;
}
Example #7
0
int _tmain(int argc, _TCHAR* argv[])
{
  splash(argv[0]);

  if((argc < 4) || ((argc > 5) && (strcmp("log", argv[5])))){
    printf("Usage: %s <ServerIP> <ClientIP> <OSCIP> <OSCPort> [\"log\"]", argv[0]);
  }else{


    int retCode;
    char* OSCIP = argv[3];
    int OSCPort = atoi(argv[4]);

    //EU
    printf("\n\nBanana hammock!!\n\n");

    // Set callback handlers
    theClient.SetMessageCallback(MessageHandler);
    theClient.SetVerbosityLevel(Verbosity_Debug);
    theClient.SetDataCallback( DataHandler, &theClient );	// this function will receive data from the server

    // Connect to NatNet server
    strcpy(szServerIPAddress, argv[1]);	// specified on command line
    strcpy(szMyIPAddress, argv[2]);	// specified on command line
    printf("Connecting to server at %s from %s...\n", szServerIPAddress, szMyIPAddress);

    // Connect to NatNet server


    retCode = theClient.Initialize(szMyIPAddress, szServerIPAddress);
    if (retCode != ErrorCode_OK)
      {
	printf("Unable to connect to server.  Error code: %d. Exiting", retCode);
	return 1;
      }
    else
      {

	// print server info
	sServerDescription ServerDescription;
	memset(&ServerDescription, 0, sizeof(ServerDescription));
	theClient.GetServerDescription(&ServerDescription);
	if(!ServerDescription.HostPresent)
	  {
	    printf("Unable to connect to server. Host not present. Exiting.");
	    return 1;
	  }
	printf("[OSCNatNetClient] Server application info:\n");
	printf("Application: %s (ver. %d.%d.%d.%d)\n",
	       ServerDescription.szHostApp,
	       ServerDescription.HostAppVersion[0],
	       ServerDescription.HostAppVersion[1],
	       ServerDescription.HostAppVersion[2],
	       ServerDescription.HostAppVersion[3]);
	printf("NatNet Version: %d.%d.%d.%d\n",
	       ServerDescription.NatNetVersion[0],
	       ServerDescription.NatNetVersion[1],
	       ServerDescription.NatNetVersion[2],
	       ServerDescription.NatNetVersion[3]);
	printf("Server IP:%s\n", szServerIPAddress);
	printf("Server Name:%s\n\n", ServerDescription.szHostComputerName);

	//EU - init UDP socket
	transmitSocket = new UdpTransmitSocket(IpEndpointName(OSCIP, OSCPort));
	printf("OSC IP:%s\n", OSCIP);
	printf("OSC Port:%d\n", OSCPort);
      }

    // send/receive test request
    printf("[OSCNatNetClient] Sending Test Request\n");
    void* response;
    int nBytes;
    retCode = theClient.SendMessageAndWait("TestRequest", &response, &nBytes);
    if (retCode == ErrorCode_OK)
      {
	printf("[OSCNatNetClient] Received: %s", (char*)response);
      }




    //Writing Session data to file

    char szFile[MAX_PATH];
    char szFolder[MAX_PATH];
#ifdef __linux__
    sprintf(szFolder, "./");
#else
    GetCurrentDirectory(MAX_PATH, szFolder);
#endif
    char timeLabel[50];
    time_t rawtime;
    struct tm* timeinfo;
    time(&rawtime);
    timeinfo = localtime(&rawtime);

    //create time label for files
    strftime (timeLabel,80,"%d.%m.%y %H.%M.%S",timeinfo);

    // Retrieve MarkerSets from server
    printf("\n\n[OSCNatNetClient] Requesting all data definitions for current session...");
    sDataDescriptions* pDataDefs = NULL;
    theClient.GetDataDescriptions(&pDataDefs);
    if(!pDataDefs){

      printf("[OSCNatNetClient] Unable to retrieve current session.");
      //return 1;

    }else{
      sprintf(szFile, "%s\\SessionData %s.txt", szFolder, timeLabel);
      fps = fopen(szFile, "w");
      if(!fps)
	{
	  printf("error opening output file %s.  Exiting.", szFile);
	  exit(1);
	}
      _WriteHeader(fps, pDataDefs);
      fclose(fps);
    }


    // Prepare data file for frame info

    if(argc > 5){

      sprintf(szFile, "%s\\FrameData %s.txt", szFolder, timeLabel);
      fpf = fopen(szFile, "w");
      if(!fpf){
	printf("error opening output file %s.  Exiting.", szFile);
	exit(1);
      }
    }



    // Ready to receive marker stream!
    printf("\nOSCNatNetClient is connected to server and listening for data... press 'q' for quitting\n");
    int c;
    bool bExit = false;
    while(c =_getch()){
      switch(c){
      case 'q':
	bExit = true;
	printf("\nQuitting...\n\n");
	break;
      case 'r':
	printf("\nReseting Client...\n\n");
	resetClient();
	break;
      default:
	printf("not an option\n\n");
	break;
      }
      if(bExit)
	break;
    }

    printf("clean up\n\n");
    // Done - clean up.
    theClient.Uninitialize();
    if(fpf != NULL) fclose(fpf);

    return ErrorCode_OK;
  }
}
int _tmain(int argc, _TCHAR* argv[])
{
	dest_cont.dests[0] = KITCHEN;
	dest_cont.dests[1] = TABLE_ONE;
	dest_cont.dests[2] = TABLE_TWO;
	dest_cont.dests[3] = KITCHEN;
	dest_cont.dests[4] = TABLE_THREE;
	dest_cont.dests[5] = -1;
	InitializeCriticalSection(&(dest_cont.lock));
	//memset(dest_cont.dests, -1, 11);
	dest_cont.step_num = 0;
	dest_cont.num_dests = 5;
	acommand.packet_counter = 1;
		for (int i = 0; i < 10; i++) {
		//dest_cont.dests[i] = -1;
		//cout << dest_cont.dests[i];
	}
	for(int j = 0; j < 5; j++) {
		dest_cont.active_orders[j] = 0;
		dest_cont.inactive_orders[j] = 0;
	}
	HANDLE thread = (HANDLE)::_beginthreadex(NULL, 0, update_orders,  NULL, 0, NULL);
    int iResult;
    int iConnectionType = ConnectionType_Multicast;
    //int iConnectionType = ConnectionType_Unicast;
    
    // parse command line args
    if(argc>1)
    {
        strcpy(szServerIPAddress, argv[1]);	// specified on command line
        printf("Connecting to server at %s...\n", szServerIPAddress);
    }
    else
    {
        strcpy(szServerIPAddress, "10.10.67.12");		// not specified - assume server is local machine
        printf("Connecting to server at LocalMachine\n");
    }
    if(argc>2)
    {
        strcpy(szMyIPAddress, argv[2]);	    // specified on command line
        printf("Connecting from %s...\n", szMyIPAddress);
    }
    else
    {
        strcpy(szMyIPAddress, "10.10.67.32");          // not specified - assume server is local machine
        printf("Connecting from LocalMachine...\n");
    }

    // Create NatNet Client
    iResult = CreateClient(iConnectionType);
    if(iResult != ErrorCode_OK)
    {
        printf("Error initializing client.  See log for details.  Exiting");
        return 1;
    }
    else
    {
        printf("Client initialized and ready.\n");
    }


	// send/receive test request
	printf("[SampleClient] Sending Test Request\n");
	void* response;
	int nBytes;
	iResult = theClient->SendMessageAndWait("TestRequest", &response, &nBytes);
	if (iResult == ErrorCode_OK)
	{
		printf("[SampleClient] Received: %s", (char*)response);
	}

	// Retrieve Data Descriptions from server
	printf("\n\n[SampleClient] Requesting Data Descriptions...");
	sDataDescriptions* pDataDefs = NULL;
	int nBodies = theClient->GetDataDescriptions(&pDataDefs);
	if(!pDataDefs)
	{
		printf("[SampleClient] Unable to retrieve Data Descriptions.");
	}
	else
	{
        printf("[SampleClient] Received %d Data Descriptions:\n", pDataDefs->nDataDescriptions );
        for(int i=0; i < pDataDefs->nDataDescriptions; i++)
        {
            printf("Data Description # %d (type=%d)\n", i, pDataDefs->arrDataDescriptions[i].type);
            if(pDataDefs->arrDataDescriptions[i].type == Descriptor_MarkerSet)
            {
                // MarkerSet
                sMarkerSetDescription* pMS = pDataDefs->arrDataDescriptions[i].Data.MarkerSetDescription;
                printf("MarkerSet Name : %s\n", pMS->szName);
                for(int i=0; i < pMS->nMarkers; i++)
                    printf("%s\n", pMS->szMarkerNames[i]);

            }
            else if(pDataDefs->arrDataDescriptions[i].type == Descriptor_RigidBody)
            {
                // RigidBody
                sRigidBodyDescription* pRB = pDataDefs->arrDataDescriptions[i].Data.RigidBodyDescription;
                printf("RigidBody Name : %s\n", pRB->szName);
                printf("RigidBody ID : %d\n", pRB->ID);
                printf("RigidBody Parent ID : %d\n", pRB->parentID);
                printf("Parent Offset : %3.2f,%3.2f,%3.2f\n", pRB->offsetx, pRB->offsety, pRB->offsetz);
            }
            else if(pDataDefs->arrDataDescriptions[i].type == Descriptor_Skeleton)
            {
                // Skeleton
                sSkeletonDescription* pSK = pDataDefs->arrDataDescriptions[i].Data.SkeletonDescription;
                printf("Skeleton Name : %s\n", pSK->szName);
                printf("Skeleton ID : %d\n", pSK->skeletonID);
                printf("RigidBody (Bone) Count : %d\n", pSK->nRigidBodies);
                for(int j=0; j < pSK->nRigidBodies; j++)
                {
                    sRigidBodyDescription* pRB = &pSK->RigidBodies[j];
                    printf("  RigidBody Name : %s\n", pRB->szName);
                    printf("  RigidBody ID : %d\n", pRB->ID);
                    printf("  RigidBody Parent ID : %d\n", pRB->parentID);
                    printf("  Parent Offset : %3.2f,%3.2f,%3.2f\n", pRB->offsetx, pRB->offsety, pRB->offsetz);
                }
            }
            else
            {
                printf("Unknown data type.");
                // Unknown
            }
        }
	}

	
	// Create data file for writing received stream into
	char szFile[MAX_PATH];
	char szFolder[MAX_PATH];
	GetCurrentDirectory(MAX_PATH, szFolder);
	if(argc > 3)
		sprintf(szFile, "%s\\%s", szFolder, argv[3]);
	else
		sprintf(szFile, "%s\\Client-output.pts",szFolder);
	fp = fopen(szFile, "w");
	if(!fp)
	{
		printf("error opening output file %s.  Exiting.", szFile);
		exit(1);
	}
	if(pDataDefs)
		_WriteHeader(fp, pDataDefs);

	// Ready to receive marker stream!
	printf("\nClient is connected to server and listening for data...\n");
	int c;
	bool bExit = false;
	while(c =_getch())
	{
		switch(c)
		{
			case 'q':
				bExit = true;		
				break;	
			case 'r':
				resetClient();
				break;	
            case 'p':
                sServerDescription ServerDescription;
                memset(&ServerDescription, 0, sizeof(ServerDescription));
                theClient->GetServerDescription(&ServerDescription);
                if(!ServerDescription.HostPresent)
                {
                    printf("Unable to connect to server. Host not present. Exiting.");
                    return 1;
                }
                break;	
            case 'f':
                {
                    sFrameOfMocapData* pData = theClient->GetLastFrameOfData();
                    printf("Most Recent Frame: %d", pData->iFrame);
                }
                break;	
            case 'm':	                        // change to multicast
                iResult = CreateClient(ConnectionType_Multicast);
                if(iResult == ErrorCode_OK)
                    printf("Client connection type changed to Multicast.\n\n");
                else
                    printf("Error changing client connection type to Multicast.\n\n");
                break;
            case 'u':	                        // change to unicast
                iResult = CreateClient(ConnectionType_Unicast);
                if(iResult == ErrorCode_OK)
                    printf("Client connection type changed to Unicast.\n\n");
                else
                    printf("Error changing client connection type to Unicast.\n\n");
                break;


			default:
				break;
		}
		if(bExit)
			break;
	}

	// Done - clean up.
	theClient->Uninitialize();
	_WriteFooter(fp);
	fclose(fp);

	return ErrorCode_OK;
}