コード例 #1
0
ファイル: libwrc_string.c プロジェクト: UIKit0/libwrc
/* Retrieves the string index for a specific identifier
 * Returns 1 if successful, 0 if no such string identifier or -1 on error
 */
int libwrc_string_get_index_by_identifier(
     libwrc_resource_t *resource,
     uint32_t language_identifier,
     uint32_t string_identifier,
     int *string_index,
     libcerror_error_t **error )
{
	libfvalue_value_t *string_value               = NULL;
	libwrc_internal_resource_t *internal_resource = NULL;
	libwrc_language_entry_t *language_entry       = NULL;
	uint8_t *string_value_identifier              = NULL;
	static char *function                         = "libwrc_string_get_index_by_identifier";
	size_t string_value_identifier_size           = 0;
	uint32_t identifier                           = 0;
	int number_of_strings                         = 0;

	if( resource == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid resource.",
		 function );

		return( -1 );
	}
	internal_resource = (libwrc_internal_resource_t *) resource;

	if( internal_resource->resource_values == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
		 "%s: invalid resource - missing resource values.",
		 function );

		return( -1 );
	}
	if( internal_resource->resource_values->identifier != LIBWRC_RESOURCE_IDENTIFIER_STRING )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
		 "%s: unsupported resource type: 0x%08" PRIx32 ".",
		 function,
		 internal_resource->resource_values->identifier );

		return( -1 );
	}
	if( internal_resource->value == NULL )
	{
		if( libwrc_resource_read_value(
		     internal_resource,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_IO,
			 LIBCERROR_IO_ERROR_READ_FAILED,
			 "%s: unable to read resource value.",
			 function );

			return( -1 );
		}
	}
	if( libwrc_language_table_get_entry_by_identifier(
	     (libwrc_language_table_t *) internal_resource->value,
	     language_identifier,
	     &language_entry,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
		 "%s: unable to retrieve language entry for identifier: 0x%08" PRIx32 ".",
		 function,
		 language_identifier );

		return( -1 );
	}
	if( libwrc_language_entry_get_number_of_values(
	     language_entry,
	     &number_of_strings,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
		 "%s: unable to retrieve number of strings.",
		 function );

		return( -1 );
	}
	for( *string_index = 0;
	     *string_index < number_of_strings;
	     *string_index += 1 )
	{
		if( libwrc_language_entry_get_value_by_index(
		     language_entry,
		     *string_index,
		     (intptr_t **) &string_value,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
			 "%s: unable to retrieve string value: %d.",
			 function,
			 string_index );

			return( -1 );
		}
		if( libfvalue_value_get_identifier(
		     string_value,
		     &string_value_identifier,
		     &string_value_identifier_size,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
			 "%s: unable to retrieve string value: %d identifier.",
			 function,
			 string_index );

			return( -1 );
		}
		if( string_value_identifier == NULL )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
			 "%s: missing string value identifier.",
			 function );

			return( -1 );
		}
		if( string_value_identifier_size != 4 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
			 "%s: string size value out of bound.",
			 function );

			return( -1 );
		}
		byte_stream_copy_to_uint32_little_endian(
		 string_value_identifier,
		 identifier );

		if( identifier == string_identifier )
		{
			return( 1 );
		}
	}
	return( 0 );
}
コード例 #2
0
/* Generate an xhash
 * Sets xhash and xhash size
 * Returns 1 if successful or -1 on error
 */
int libewf_hash_values_generate_xhash(
     libfvalue_table_t *hash_values,
     uint8_t **xhash,
     size_t *xhash_size,
     libcerror_error_t **error )
{
	libfvalue_value_t *hash_value     = NULL;
	uint8_t *identifier               = NULL;
	char *xml_head                    = NULL;
	char *xml_xhash_close_tag         = NULL;
	char *xml_xhash_open_tag          = NULL;
	static char *function             = "libewf_hash_values_generate_xhash";
	size_t xhash_index                = 0;
	size_t identifier_size            = 0;
	size_t value_string_size          = 0;
	size_t xml_head_length            = 0;
	size_t xml_xhash_close_tag_length = 0;
	size_t xml_xhash_open_tag_length  = 0;
	int hash_value_index              = 0;
	int number_of_hash_values         = 0;
	int result                        = 0;

	if( xhash == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid xhash.",
		 function );

		return( -1 );
	}
	if( *xhash != NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: xhash already created.",
		 function );

		return( -1 );
	}
	if( xhash_size == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid xhash size.",
		 function );

		return( -1 );
	}
	if( libfvalue_table_get_number_of_values(
	     hash_values,
	     &number_of_hash_values,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
		 "%s: unable to retrieve number of hash values.",
		 function );

		goto on_error;
	}
	xml_head = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";

	xml_head_length = libcstring_narrow_string_length(
	                   xml_head );

	xml_xhash_open_tag = "<xhash>\n";

	xml_xhash_open_tag_length = libcstring_narrow_string_length(
	                             xml_xhash_open_tag );

	xml_xhash_close_tag = "</xhash>\n\n";

	xml_xhash_close_tag_length = libcstring_narrow_string_length(
	                              xml_xhash_close_tag );

	/* Reserve space for the UTF-8 byte order mark and the XML skeleton data
	 */
	*xhash_size = 3 + xml_head_length + xml_xhash_open_tag_length + xml_xhash_close_tag_length;

	for( hash_value_index = 0;
	     hash_value_index < number_of_hash_values;
	     hash_value_index++ )
	{
		if( libfvalue_table_get_value_by_index(
		     hash_values,
		     hash_value_index,
		     &hash_value,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
			 "%s: unable to retrieve hash value: %d.",
			 function,
			 hash_value_index );

			goto on_error;
		}
		if( libfvalue_value_get_identifier(
		     hash_value,
		     &identifier,
		     &identifier_size,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
			 "%s: unable to retrieve identifier of hash value: %d.",
			 function,
			 hash_value_index );

			goto on_error;
		}
		if( ( identifier == NULL )
		 || ( identifier_size == 0 ) )
		{
#if defined( HAVE_VERBOSE_OUTPUT )
			if( libcnotify_verbose != 0 )
			{
				libcnotify_printf(
				 "%s: missing identifier for hash value: %d.\n",
				 function,
				 hash_value_index );
			}
#endif
			continue;
		}
		result = libfvalue_value_get_utf8_string_size(
		          hash_value,
		          0,
		          &value_string_size,
		          error );

		if( result != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
			 "%s: unable to retrieve string size of hash value: %s.",
			 function,
			 (char *) identifier );

			goto on_error;
		}
		if( ( result != 0 )
		 && ( value_string_size > 1 ) )
		{
			/* Reserve space for a leading tab, <identifier>value</identifier> and a newline
			 */
			*xhash_size += 7 + ( 2 * ( identifier_size - 1 ) ) + ( value_string_size - 1 );
		}
	}
	/* Reserve space for the end-of-string character
	 */
	*xhash_size += 1;

	*xhash = (uint8_t *) memory_allocate(
                              sizeof( uint8_t ) * *xhash_size );

	if( *xhash == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: unable to create xhash.",
		 function );

		goto on_error;
	}
	( *xhash )[ xhash_index++ ] = 0xef;
	( *xhash )[ xhash_index++ ] = 0xbb;
	( *xhash )[ xhash_index++ ] = 0xbf;

	if( libcstring_narrow_string_copy(
	     (char *) &( ( *xhash )[ xhash_index ] ),
	     xml_head,
	     xml_head_length ) == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
		 "%s: unable to copy XML head string.",
		 function );

		goto on_error;
	}
	xhash_index += xml_head_length;

	if( libcstring_narrow_string_copy(
	     (char *) &( ( *xhash )[ xhash_index ] ),
	     xml_xhash_open_tag,
	     xml_xhash_open_tag_length ) == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
		 "%s: unable to copy xhash open tag string.",
		 function );

		goto on_error;
	}
	xhash_index += xml_xhash_open_tag_length;

	for( hash_value_index = 0;
	     hash_value_index < number_of_hash_values;
	     hash_value_index++ )
	{
		if( libfvalue_table_get_value_by_index(
		     hash_values,
		     hash_value_index,
		     &hash_value,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
			 "%s: unable to retrieve hash value: %d.",
			 function,
			 hash_value_index );

			goto on_error;
		}
		if( libfvalue_value_get_identifier(
		     hash_value,
		     &identifier,
		     &identifier_size,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
			 "%s: unable to retrieve identifier of hash value: %d.",
			 function,
			 hash_value_index );

			goto on_error;
		}
		if( ( identifier == NULL )
		 || ( identifier_size == 0 ) )
		{
#if defined( HAVE_VERBOSE_OUTPUT )
			if( libcnotify_verbose != 0 )
			{
				libcnotify_printf(
				 "%s: missing identifier for hash value: %d.\n",
				 function,
				 hash_value_index );
			}
#endif
			continue;
		}
		result = libfvalue_value_get_utf8_string_size(
		          hash_value,
		          0,
		          &value_string_size,
		          error );

		if( result == -1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
			 "%s: unable to retrieve string size of hash value: %s.",
			 function,
			 (char *) identifier );

			goto on_error;
		}
		if( ( result != 0 )
		 && ( value_string_size > 1 ) )
		{
			( *xhash )[ xhash_index++ ] = (uint8_t) '\t';
			( *xhash )[ xhash_index++ ] = (uint8_t) '<';

			if( libcstring_narrow_string_copy(
			     (char *) &( ( *xhash )[ xhash_index ] ),
			     (char *) identifier,
			     identifier_size - 1 ) == NULL )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
				 "%s: unable to copy %s open tag string.",
				 function,
				 (char *) identifier );

				goto on_error;
			}
			xhash_index += identifier_size - 1;

			( *xhash )[ xhash_index++ ] = (uint8_t) '>';

			if( libfvalue_value_copy_to_utf8_string_with_index(
			     hash_value,
			     0,
			     *xhash,
			     *xhash_size,
			     &xhash_index,
			     error ) != 1 )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
				 "%s: unable to copy string of hash value: %s.",
				 function,
				 (char *) identifier );

				goto on_error;
			}
			( *xhash )[ xhash_index - 1 ] = (uint8_t) '<';
			( *xhash )[ xhash_index++   ] = (uint8_t) '/';

			if( libcstring_narrow_string_copy(
			     (char *) &( ( *xhash )[ xhash_index ] ),
			     (char *) identifier,
			     identifier_size - 1 ) == NULL )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
				 "%s: unable to copy %s close tag string.",
				 function,
				 (char *) identifier );

				goto on_error;
			}
			xhash_index += identifier_size - 1;

			( *xhash )[ xhash_index++ ] = (uint8_t) '>';
			( *xhash )[ xhash_index++ ] = (uint8_t) '\n';
		}
	}
	if( libcstring_narrow_string_copy(
	     (char *) &( ( *xhash )[ xhash_index ] ),
	     xml_xhash_close_tag,
	     xml_xhash_close_tag_length ) == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
		 "%s: unable to copy xhash close tag string.",
		 function );

		goto on_error;
	}
	xhash_index += xml_xhash_close_tag_length;

	/* Make sure the string is terminated
	 */
	( *xhash )[ xhash_index ] = 0;

	return( 1 );

on_error:
	if( *xhash != NULL )
	{
		memory_free(
		 *xhash );

		*xhash = NULL;
	}
	*xhash_size = 0;

	return( -1 );
}
コード例 #3
0
ファイル: libwrc_string.c プロジェクト: UIKit0/libwrc
/* Retrieves a specific string identifier
 * Returns 1 if successful or -1 on error
 */
int libwrc_string_get_identifier(
     libwrc_resource_t *resource,
     uint32_t language_identifier,
     int string_index,
     uint32_t *string_identifier,
     libcerror_error_t **error )
{
	libfvalue_value_t *string_values    = NULL;
	uint8_t *string_value_identifier    = NULL;
	static char *function               = "libwrc_string_get_identifier";
	size_t string_value_identifier_size = 0;

	if( libwrc_resource_get_value_by_language_identifier(
	     resource,
	     LIBWRC_RESOURCE_TYPE_STRING,
	     language_identifier,
	     string_index,
	     (intptr_t **) &string_values,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
		 "%s: unable to retrieve string values.",
		 function );

		return( -1 );
	}
/* TODO move to string values function */
	if( string_identifier == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid string identifier.",
		 function );

		return( -1 );
	}
	if( libfvalue_value_get_identifier(
	     string_values,
	     &string_value_identifier,
	     &string_value_identifier_size,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
		 "%s: unable to retrieve string value: %d identifier.",
		 function,
		 string_index );

		return( -1 );
	}
	if( string_value_identifier == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
		 "%s: missing string value identifier.",
		 function );

		return( -1 );
	}
	if( string_value_identifier_size != 4 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
		 "%s: string value dentifier size value out of bound.",
		 function );

		return( -1 );
	}
	byte_stream_copy_to_uint32_little_endian(
	 string_value_identifier,
	 *string_identifier );

	return( 1 );
}