コード例 #1
0
ファイル: back.c プロジェクト: artchula/eLedCube
//图片显示函数
void display_pic()
{
	dis_close(); 
    P1=P0=0xff;
	delay();
	if(T0_S<=179)
	{
		if(Time0_flag)
		{
		 	Time0_flag=0;
			dat1=pic0[T0_S][0];		//改变图片的数组名,可以显示不同的图片,系统内置了6张图片,请查看POVLED_PID.H
			dat2=pic0[T0_S][1];
			dat3=pic0[T0_S][2];
			dat4=pic0[T0_S][3];
			LED1=0;LED0=0;	
			//display(dat1,dat2,dat3,dat4);
			
			Send_data_A(dat2);
			Send_data_B(dat1);
			Send_data_C(0x00,0x00);
			dis_open(); 
		    P0=dat3;
			P1=dat4;
			delay();
			LED0=1;	LED1=1;
			dis_close();
			P1=P0=0xff;
			//display_CLR();
		}		
	}
}
コード例 #2
0
ファイル: bekfile.c プロジェクト: Aorimn/dislocker
/**
 * Get the VMK datum using a bek file (external key)
 *
 * @param dataset The dataset of BitLocker's metadata on the volume
 * @param bek_file The path to the .BEK file to use
 * @param vmk_datum The datum_key_t found, containing the unencrypted VMK
 * @return TRUE if result can be trusted, FALSE otherwise
 */
int get_vmk_from_bekfile2(dis_metadata_t dis_meta,
                          char* bek_file,
                          void** vmk_datum)
{
	// Check parameters
	if(!dis_meta || !vmk_datum)
		return FALSE;

	guid_t key_guid = {0,};
	char rec_id[37] = {0,};

	bitlocker_dataset_t* bek_dataset = NULL;
	uint8_t* recovery_key = NULL;
	size_t rk_size = 0;

	int result = FALSE;
	int fd_bek = 0;


	if(bek_file)
	{
		/* Check if the bek file exists */
		fd_bek = dis_open(bek_file, O_RDONLY);
		if(fd_bek < 0)
		{
			dis_printf(L_ERROR, "Cannot open FVEK file (%s)\n", bek_file);
			return FALSE;
		}
	}
	else
	{
		dis_printf(
			L_ERROR,
			"Using bekfile method (USB) but missing the bekfile name. Abort.\n"
		);
		return FALSE;
	}

	dis_printf(
		L_INFO,
		"Using the bekfile '%s' to decrypt the VMK.\n",
		bek_file
	);

	/*
	 * We need the recovery key id which can be found in the bek file
	 * to find its match in a datum of the volume's metadata
	 */
	if(!get_bek_dataset(fd_bek, (void**) &bek_dataset))
	{
		dis_printf(L_ERROR, "Unable to retrieve the dataset. Abort.\n");
		dis_close(fd_bek);
		return FALSE;
	}

	/* We have what we wanted, so close the file */
	dis_close(fd_bek);


	/* Get the external datum */
	void* dataset = dis_metadata_set_dataset(dis_meta, bek_dataset);
	get_next_datum(
		dis_meta,
		UINT16_MAX,
		DATUMS_VALUE_EXTERNAL_KEY,
		NULL,
		vmk_datum
	);
	dis_metadata_set_dataset(dis_meta, dataset);

	/* Check the result datum */
	if(!*vmk_datum ||
	   !datum_value_type_must_be(*vmk_datum, DATUMS_VALUE_EXTERNAL_KEY))
	{
		dis_printf(
			L_ERROR,
			"Error processing the bekfile: datum of type %hd not found. "
			"Internal failure, abort.\n",
			DATUMS_VALUE_EXTERNAL_KEY
		);
		*vmk_datum = NULL;
		memclean(bek_dataset, bek_dataset->size);
		return FALSE;
	}

	/* Now that we are sure of the type, take care of copying the recovery key id */
	datum_external_t* datum_exte = (datum_external_t*) *vmk_datum;
	memcpy(key_guid, datum_exte->guid, 16);

	format_guid(key_guid, rec_id);
	dis_printf(
		L_INFO,
		"Bekfile GUID found: '%s', looking for the same in metadata...\n",
		rec_id
	);

	/* Grab the datum nested in the last, we will need it to decrypt the VMK */
	if(!get_nested_datumvaluetype(*vmk_datum, DATUMS_VALUE_KEY, vmk_datum) ||
	   !*vmk_datum)
	{
		dis_printf(
			L_ERROR,
			"Error processing the bekfile: no nested datum found. "
			"Internal failure, abort.\n"
		);
		*vmk_datum = NULL;
		memclean(bek_dataset, bek_dataset->size);
		return FALSE;
	}

	if(!get_payload_safe(*vmk_datum, (void**) &recovery_key, &rk_size))
	{
		dis_printf(
			L_ERROR,
			"Error getting the key to decrypt VMK from the bekfile. "
			"Internal failure, abort.\n"
		);
		*vmk_datum = NULL;
		memclean(bek_dataset, bek_dataset->size);
		return FALSE;
	}

	memclean(bek_dataset, bek_dataset->size);


	/*
	 * Now that we have the key to decrypt the VMK, we need to
	 * find the VMK datum in the BitLocker metadata in order to
	 * decrypt the VMK using this already found key in the bekfile
	 */
	if(!get_vmk_datum_from_guid(dis_meta, key_guid, vmk_datum))
	{
		format_guid(key_guid, rec_id);

		dis_printf(
			L_ERROR,
			"\n\tError, can't find a valid and matching VMK datum.\n"
			"\tThe GUID researched was '%s', check if you have the right "
			"bek file for the right volume.\n"
			"\tAbort.\n",
			rec_id
		);
		*vmk_datum = NULL;
		dis_free(recovery_key);
		return FALSE;
	}

	dis_printf(
		L_INFO,
		"VMK datum of id '%s' found. Trying to reach the Key datum...\n",
		rec_id
	);


	/*
	 * We have the datum containing other data, so get in there and take the
	 * nested one with type 5 (aes-ccm)
	 */
	if(!get_nested_datumvaluetype(*vmk_datum, DATUMS_VALUE_AES_CCM, vmk_datum))
	{
		dis_printf(
			L_ERROR,
			"Error looking for the nested datum in the VMK one. "
			"Internal failure, abort.\n"
		);
		*vmk_datum = NULL;
		dis_free(recovery_key);
		return FALSE;
	}


	dis_printf(L_INFO, "Key datum found and payload extracted!\n");

	result = get_vmk(
		(datum_aes_ccm_t*) *vmk_datum,
		recovery_key,
		rk_size,
		(datum_key_t**) vmk_datum
	);

	dis_free(recovery_key);

	return result;
}
コード例 #3
0
ファイル: dislocker.c プロジェクト: LeeGDavis/dislocker
int dis_initialize(dis_context_t dis_ctx)
{
	int ret = DIS_RET_SUCCESS;
	dis_metadata_config_t dis_meta_cfg = NULL;


	/* Initialize outputs */
	dis_stdio_init(dis_ctx->cfg.verbosity, dis_ctx->cfg.log_file);

	dis_printf(L_INFO, PROGNAME " by " AUTHOR ", v" VERSION " (compiled for " __OS "/" __ARCH ")\n");
#ifdef VERSION_DBG
	dis_printf(L_INFO, "Compiled version: " VERSION_DBG "\n");
#endif

	if(dis_ctx->cfg.verbosity >= L_DEBUG)
		dis_print_args(dis_ctx);


	/*
	 * Check parameters given
	 */
	if(!dis_ctx->cfg.volume_path)
	{
		dis_printf(L_CRITICAL, "No BitLocker volume path given. Abort.\n");
		dis_destroy(dis_ctx);
		return DIS_RET_ERROR_VOLUME_NOT_GIVEN;
	}



	/* Open the volume as a (big) normal file */
	dis_printf(L_DEBUG, "Trying to open '%s'...\n", dis_ctx->cfg.volume_path);
	dis_ctx->fve_fd = dis_open(dis_ctx->cfg.volume_path, O_RDWR|O_LARGEFILE);
	if(dis_ctx->fve_fd < 0)
	{
		/* Trying to open it in read-only if O_RDWR doesn't work */
		dis_ctx->fve_fd = dis_open(
			dis_ctx->cfg.volume_path,
			O_RDONLY|O_LARGEFILE
		);

		if(dis_ctx->fve_fd < 0)
		{
			dis_printf(
				L_CRITICAL,
				"Failed to open %s: %s\n",
				dis_ctx->cfg.volume_path, strerror(errno)
			);
			dis_destroy(dis_ctx);
			return DIS_RET_ERROR_FILE_OPEN;
		}

		dis_ctx->cfg.flags |= DIS_FLAG_READ_ONLY;
		dis_printf(
			L_WARNING,
			"Failed to open %s for writing. Falling back to read-only.\n",
			dis_ctx->cfg.volume_path
		);
	}

	dis_printf(L_DEBUG, "Opened (fd #%d).\n", dis_ctx->fve_fd);

	dis_ctx->io_data.volume_fd = dis_ctx->fve_fd;

	checkupdate_dis_state(dis_ctx, DIS_STATE_AFTER_OPEN_VOLUME);


	/* To print UTF-32 strings */
	setlocale(LC_ALL, "");

	/*
	 * The metadata configuration is freed when calling dis_metadata_destroy()
	 */
	dis_meta_cfg = dis_metadata_config_new();
	dis_meta_cfg->fve_fd       = dis_ctx->fve_fd;
	dis_meta_cfg->force_block  = dis_ctx->cfg.force_block;
	dis_meta_cfg->offset       = dis_ctx->cfg.offset;
	dis_meta_cfg->init_stop_at = dis_ctx->cfg.init_stop_at;

	dis_ctx->metadata = dis_metadata_new(dis_meta_cfg);
	if(dis_ctx->metadata == NULL)
	{
		dis_printf(L_CRITICAL, "Can't allocate metadata object. Abort.\n");
		dis_destroy(dis_ctx);
		return DIS_RET_ERROR_ALLOC;
	}

	ret = dis_metadata_initialize(dis_ctx->metadata);
	dis_ctx->curr_state = dis_meta_cfg->curr_state;
	if(ret != DIS_RET_SUCCESS)
	{
		/*
		 * If it's less than 0, then it's an error, if not, it's an early
		 * return of this function.
		 */
		if(ret < 0)
			dis_destroy(dis_ctx);
		return ret;
	}


	/*
	 * If the state of the volume is currently decrypted, there's no key to grab
	 */
	if(dis_ctx->metadata->information->curr_state != METADATA_STATE_DECRYPTED)
	{
		/*
		 * Get the keys -- VMK & FVEK -- for dec/encryption operations
		 */
		if((ret = dis_get_access(dis_ctx)) != DIS_RET_SUCCESS)
		{
			/*
			 * If it's less than 0, then it's an error, if not, it's an early
			 * return of this function.
			 */
			if(ret < 0)
			{
				dis_printf(L_CRITICAL, "Unable to grab VMK or FVEK. Abort.\n");
				dis_destroy(dis_ctx);
			}
			return ret;
		}

		/*
		 * Init the crypto structure
		 */
		dis_ctx->io_data.crypt = dis_crypt_new(
			dis_metadata_sector_size(dis_ctx->metadata),
			dis_ctx->metadata->dataset->algorithm
		);

		/*
		 * Init the decrypt keys' contexts
		 */
		if(init_keys(
			dis_metadata_set_dataset(dis_ctx->metadata, NULL),
			dis_ctx->io_data.fvek,
			dis_ctx->io_data.crypt) != DIS_RET_SUCCESS)
		{
			dis_printf(L_CRITICAL, "Can't initialize keys. Abort.\n");
			dis_destroy(dis_ctx);
			return DIS_RET_ERROR_CRYPTO_INIT;
		}
	}


	/*
	 * Fill the dis_iodata_t structure which will be used for encryption &
	 * decryption afterward
	 */
	if((ret = prepare_crypt(dis_ctx)) != DIS_RET_SUCCESS)
		dis_printf(L_CRITICAL, "Can't prepare the crypt structure. Abort.\n");


	// TODO add the DIS_STATE_BEFORE_DECRYPTION_CHECKING event here, so add the check here too


	/* Don't do the check for each and every enc/decryption operation */
	dis_ctx->io_data.volume_state = TRUE;

	int look_state = dis_ctx->cfg.flags & DIS_FLAG_DONT_CHECK_VOLUME_STATE;
	if(look_state == 0 &&
		!check_state(dis_ctx->metadata))
	{
		dis_ctx->io_data.volume_state = FALSE;
		ret = DIS_RET_ERROR_VOLUME_STATE_NOT_SAFE;
	}

	/* Clean everything before returning if there's an error */
	if(ret != DIS_RET_SUCCESS)
		dis_destroy(dis_ctx);
	else
		dis_ctx->curr_state = DIS_STATE_COMPLETE_EVERYTHING;

	return ret;
}