⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 libewf_string.c

📁 sleuthit-2.09 一个磁盘的工具集
💻 C
📖 第 1 页 / 共 2 页
字号:
	else	{		LIBEWF_VERBOSE_PRINT( "libewf_string_copy_utf16_to_ascii: no byte order in UTF16 string.\n" );		if( ( utf16_string[ 0 ] == (LIBEWF_CHAR) '\0' ) && ( utf16_string[ 1 ] != (LIBEWF_CHAR) '\0' ) )		{			byte_order = LIBEWF_STRING_LITTLE_ENDIAN;		}		else if( ( utf16_string[ 0 ] != (LIBEWF_CHAR) '\0' ) && ( utf16_string[ 1 ] == (LIBEWF_CHAR) '\0' ) )		{			byte_order = LIBEWF_STRING_LITTLE_ENDIAN;		}		else		{			LIBEWF_WARNING_PRINT( "libewf_string_copy_utf16_to_ascii: unable to determine byte order in UTF16 string.\n" );			return( -1 );		}		utf16_iterator = 0;	}	/* Convert string	 */	while( utf16_iterator < size_utf16 )	{		if( byte_order == LIBEWF_STRING_BIG_ENDIAN )		{			if( utf16_string[ utf16_iterator ] == (LIBEWF_CHAR) '\0' )			{				ascii_string[ ascii_iterator ] = utf16_string[ utf16_iterator + 1 ];			}			else			{				/* Add a place holder character				 */				ascii_string[ ascii_iterator ] = '_';			}		}		else if( byte_order == LIBEWF_STRING_LITTLE_ENDIAN )		{			if( utf16_string[ utf16_iterator + 1 ] == (LIBEWF_CHAR) '\0' )			{				ascii_string[ ascii_iterator ] = utf16_string[ utf16_iterator ];			}			else			{				/* Add a place holder character				 */				ascii_string[ ascii_iterator ] = '_';			}		}		utf16_iterator += 2;		ascii_iterator += 1;	}	ascii_string[ size_ascii - 1 ] = (LIBEWF_CHAR) '\0';	return( 1 );}/* Copies a single byte ASCII string to a multi byte UTF16 string * Returns 1 if successful, on -1 on error */int8_t libewf_string_copy_ascii_to_utf16( LIBEWF_CHAR *ascii_string, size_t size_ascii, LIBEWF_CHAR *utf16_string, size_t size_utf16, uint8_t byte_order ){	size_t ascii_iterator = 0;	size_t utf16_iterator = 2;	if( ascii_string == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_ascii_to_utf16: invalid ASCII string.\n" );		return( -1 );	}	if( utf16_string == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_ascii_to_utf16: invalid UTF16 string.\n" );		return( -1 );	}	if( ( size_ascii > (size_t) SSIZE_MAX ) || ( size_utf16 > (size_t) SSIZE_MAX ) )	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_ascii_to_utf16: invalid size value exceeds maximum.\n" );		return( -1 );	}	/* Two additional bytes required for the byte order indicator	 */	if( size_utf16 < ( ( size_ascii * 2 ) + 2 ) )	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_ascii_to_utf16: UTF16 string too small.\n" );		return( -1 );	}	/* Add the endian byte order	 */	if( byte_order == LIBEWF_STRING_LITTLE_ENDIAN )	{		utf16_string[ 0 ] = 0xff;		utf16_string[ 1 ] = 0xfe;	}	else if( byte_order == LIBEWF_STRING_BIG_ENDIAN )	{		utf16_string[ 0 ] = 0xfe;		utf16_string[ 1 ] = 0xff;	}	else	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_ascii_to_utf16: undefined byte order.\n" );		return( -1 );	}	/* Convert the string	 */	while( ascii_iterator < size_ascii )	{		if( byte_order == LIBEWF_STRING_LITTLE_ENDIAN )		{			utf16_string[ utf16_iterator     ] = ascii_string[ ascii_iterator ];			utf16_string[ utf16_iterator + 1 ] = (LIBEWF_CHAR) '\0';		}		else if( byte_order == LIBEWF_STRING_BIG_ENDIAN )		{			utf16_string[ utf16_iterator     ] = (LIBEWF_CHAR) '\0';			utf16_string[ utf16_iterator + 1 ] = ascii_string[ ascii_iterator ];		}		ascii_iterator += 1;		utf16_iterator += 2;	}	utf16_string[ size_utf16 - 2 ] = (LIBEWF_CHAR) '\0';	utf16_string[ size_utf16 - 1 ] = (LIBEWF_CHAR) '\0';	return( 1 );}/* Converts an EWF character string to a LIBEWF character string * Returns 1 if successful, 0 if string was not set, or -1 on error */int8_t libewf_string_copy_from_ewf_char( LIBEWF_CHAR *string, size_t size_string, EWF_CHAR *ewf_char_string, size_t size_ewf_char_string ){	size_t iterator = 0;	if( string == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_from_ewf_char: invalid string.\n" );		return( -1 );	}	if( ewf_char_string == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_from_ewf_char: invalid EWF character string.\n" );		return( -1 );	}	if( ( size_string > (size_t) SSIZE_MAX ) || ( size_ewf_char_string > (size_t) SSIZE_MAX ) )	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_from_ewf_char: invalid size value exceeds maximum.\n" );		return( -1 );	}	if( size_string < size_ewf_char_string )	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_from_ewf_char: string too small.\n" );		return( -1 );	}	for( iterator = 0; iterator < size_ewf_char_string; iterator++ )	{#ifdef HAVE_WIDE_CHARACTER_TYPE		string[ iterator ] = btowc( (int) ewf_char_string[ iterator ] );#else		string[ iterator ] = (char) ewf_char_string[ iterator ];#endif	}	string[ size_ewf_char_string - 1 ] = (LIBEWF_CHAR) '\0';	return( 1 );}/* Converts a LIBEWF character string to an EWF character string * Returns 1 if successful, 0 if string was not set, or -1 on error */int8_t libewf_string_copy_to_ewf_char( LIBEWF_CHAR *string, size_t size_string, EWF_CHAR *ewf_char_string, size_t size_ewf_char_string ){	size_t iterator = 0;	if( string == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_to_ewf_char: invalid string.\n" );		return( -1 );	}	if( ewf_char_string == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_to_ewf_char: invalid EWF character string.\n" );		return( -1 );	}	if( ( size_string > (size_t) SSIZE_MAX ) || ( size_ewf_char_string > (size_t) SSIZE_MAX ) )	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_to_ewf_char: invalid size value exceeds maximum.\n" );		return( -1 );	}	if( size_ewf_char_string < size_string )	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_to_ewf_char: EWF character string too small.\n" );		return( -1 );	}	for( iterator = 0; iterator < size_string; iterator++ )	{#ifdef HAVE_WIDE_CHARACTER_TYPE		ewf_char_string[ iterator ] = (EWF_HEADER) wctob( string[ iterator ] );		/* If character is out of the basic ASCII range use '_' as a place holder		 */		if( ewf_char_string[ iterator ] == (EWF_HEADER) EOF )		{			ewf_char_string[ iterator ] = (EWF_HEADER) '_';		}#else		ewf_char_string[ iterator ] = (EWF_HEADER) string[ iterator ];#endif	}	ewf_char_string[ size_string - 1 ] = (EWF_HEADER) '\0';	return( 1 );}/* Converts the EWF digest hash to a printable string * Returns 1 if successful, 0 if hash was not set, or -1 on error */int8_t libewf_string_copy_from_digest_hash( LIBEWF_CHAR *string, size_t size_string, EWF_DIGEST_HASH *digest_hash, size_t size_digest_hash ){	size_t string_iterator      = 0;	size_t digest_hash_iterator = 0;	uint8_t digest_digit        = 0;	if( string == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_from_digest_hash: invalid string.\n" );		return( -1 );	}	if( ( size_string > (size_t) SSIZE_MAX ) || ( size_digest_hash > (size_t) SSIZE_MAX ) )	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_from_digest_hash: invalid size value exceeds maximum.\n" );		return( -1 );	}	/* The string requires space for 2 characters per digest hash digit and a end of string	 */	if( size_string < ( ( 2 * size_digest_hash ) + 1 ) )	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_from_digest_hash: string too small.\n" );		return( -1 );	}	if( digest_hash == NULL )	{		LIBEWF_VERBOSE_PRINT( "libewf_string_copy_from_digest_hash: invalid digest hash.\n" );		return( 0 );	}	for( digest_hash_iterator = 0; digest_hash_iterator < size_digest_hash; digest_hash_iterator++ )	{		digest_digit = digest_hash[ digest_hash_iterator ] / 16;		if( digest_digit <= 9 )		{			string[ string_iterator++ ] = (LIBEWF_CHAR) ( (uint8_t) '0' + digest_digit );		}		else		{			string[ string_iterator++ ] = (LIBEWF_CHAR) ( (uint8_t) 'a' + ( digest_digit - 10 ) );		}		digest_digit = digest_hash[ digest_hash_iterator ] % 16;		if( digest_digit <= 9 )		{			string[ string_iterator++ ] = (LIBEWF_CHAR) ( (uint8_t) '0' + digest_digit );		}		else		{			string[ string_iterator++ ] = (LIBEWF_CHAR) ( (uint8_t) 'a' + ( digest_digit - 10 ) );		}	}	string[ string_iterator ] = (LIBEWF_CHAR) '\0';	return( 1 );}/* Converts an EWF header2 to a string * Returns 1 if successful, 0 if string was not set, or -1 on error */int8_t libewf_string_copy_from_header2( LIBEWF_CHAR *string, size_t size_string, EWF_HEADER2 *header2, size_t size_header2 ){#ifdef HAVE_WIDE_CHARACTER_TYPE	mbstate_t conversion_state;	char *header2_pointer = NULL;#endif	if( string == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_from_header2: invalid string.\n" );		return( -1 );	}	if( header2 == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_from_header2: invalid header2.\n" );		return( -1 );	}	if( ( size_string > (size_t) SSIZE_MAX ) || ( size_header2 > (size_t) SSIZE_MAX ) )	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_from_header2: invalid size value exceeds maximum.\n" );		return( -1 );	}	if( size_string < ( ( size_header2 - 2 ) / 2 ) )	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_from_header2: string too small.\n" );		return( -1 );	}#ifdef HAVE_WIDE_CHARACTER_TYPE	if( libewf_common_memset( &conversion_state, 0, sizeof( mbstate_t ) ) == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_from_header2: unable to clear converion state.\n" );		return( -1 );	}	if( mbsinit( &conversion_state ) == 0 )	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_from_header2: unable to initialize converion state.\n" );		return( -1 );	}	if( ( header2[ 0 ] == (EWF_HEADER2) 0xff ) || ( header2[ 0 ] == (EWF_HEADER2) 0xfe ) )	{		header2_pointer = (char *) &header2[ 2 ];	}	else	{		header2_pointer = (char *) &header2[ 0 ];	}	if( mbsrtowcs( string, (const char **) &header2_pointer, size_string, &conversion_state ) != ( size_string - 1 ) )#else	if( libewf_string_copy_utf16_to_ascii( (LIBEWF_CHAR *) header2, size_header2, string, size_string ) != 1 )#endif	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_from_header2: unable to copy header2 to string.\n" );		return( -1 );	}	return( 1 );}/* Converts a string to an EWF header2 * Returns 1 if successful, 0 if header2 was not set, or -1 on error */int8_t libewf_string_copy_to_header2( LIBEWF_CHAR *string, size_t size_string, EWF_HEADER2 *header2, size_t size_header2 ){#ifdef HAVE_WIDE_CHARACTER_TYPE	mbstate_t conversion_state;#endif	if( string == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_to_header2: invalid string.\n" );		return( -1 );	}	if( header2 == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_to_header2: invalid header2.\n" );		return( -1 );	}	if( ( size_string > (size_t) SSIZE_MAX ) || ( size_header2 > (size_t) SSIZE_MAX ) )	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_to_header2: invalid size value exceeds maximum.\n" );		return( -1 );	}	if( size_header2 < ( ( size_string * 2 ) + 2 ) )	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_to_header2: header2 too small.\n" );		return( -1 );	}#ifdef HAVE_WIDE_CHARACTER_TYPE	if( libewf_common_memset( &conversion_state, 0, sizeof( mbstate_t ) ) == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_to_header2: unable to clear converion state.\n" );		return( -1 );	}	if( mbsinit( &conversion_state ) == 0 )	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_to_header2: unable to initialize converion state.\n" );		return( -1 );	}	if( wcsrtombs( (char *) &header2[ 2 ], (const wchar_t **) &string, size_header2, &conversion_state ) != ( size_string - 1 ) )#else	if( libewf_string_copy_ascii_to_utf16( string, size_string, (LIBEWF_CHAR *) header2, size_header2, LIBEWF_STRING_LITTLE_ENDIAN ) != 1 )#endif	{		LIBEWF_WARNING_PRINT( "libewf_string_copy_to_header2: unable to copy string to header2.\n" );		return( -1 );	}#ifdef HAVE_WIDE_CHARACTER_TYPE	if( header2[ 4 ] == (EWF_HEADER2) '\0' )	{		header2[ 0 ] = (EWF_HEADER2) 0xfe;		header2[ 1 ] = (EWF_HEADER2) 0xff;	}	else	{		header2[ 0 ] = (EWF_HEADER2) 0xff;		header2[ 1 ] = (EWF_HEADER2) 0xfe;	}#endif	return( 1 );}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -