Ejemplo n.º 1
0
//图片显示函数
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();
		}		
	}
}
Ejemplo n.º 2
0
int dis_destroy(dis_context_t dis_ctx)
{
	/* Finish cleaning things */
	if(dis_ctx->io_data.vmk)
		dis_free(dis_ctx->io_data.vmk);

	if(dis_ctx->io_data.fvek)
		dis_free(dis_ctx->io_data.fvek);

	dis_crypt_destroy(dis_ctx->io_data.crypt);

	dis_metadata_destroy(dis_ctx->metadata);

	dis_free_args(dis_ctx);

	dis_close(dis_ctx->io_data.volume_fd);

	dis_stdio_end();

	dis_free(dis_ctx);

	return EXIT_SUCCESS;
}
Ejemplo n.º 3
0
/**
 * 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;
}