Example #1
0
Attributes	EWFNode::_attributes()
{
  Attributes 	attr;
  uint32_t	numval;
  std::string	identifier;
  std::string	value;
  
  
  if (libewf_handle_set_header_values_date_format(this->ewfso->ewf_ghandle, LIBEWF_DATE_FORMAT_CTIME, NULL) == 1)
    {
      if (libewf_handle_get_number_of_header_values(this->ewfso->ewf_ghandle, &numval, NULL) == 1)
	{
	  for (uint32_t i = 0; i != numval; i++)
	    {
	      try
		{
		  identifier = this->__getIdentifier(i);
		  if (!identifier.empty())
		    {
		      value = this->__getValue(identifier);
		      if (!value.empty())
			attr[identifier] = Variant_p(new Variant(value));
		    }
		}
	      catch (std::exception)
		{
		}
	    }
	}
    }
  if (libewf_handle_get_number_of_hash_values(this->ewfso->ewf_ghandle, &numval, NULL) == 1)
    {
      for (uint32_t i = 0; i != numval; i++)
	{
	  try
	    {
	      identifier = this->__getHashIdentifier(i);
	      if (!identifier.empty())
		{
		  value = this->__getHashValue(identifier);
		  if (!value.empty())
		    attr[identifier] = Variant_p(new Variant(value));
		}
	    }
	  catch (std::exception)
	    {
	    }
	}
    }

  return attr;
}
Example #2
0
/* Retrieves the header values
 * Returns a Python object holding the offset if successful or NULL on error
 */
PyObject *pyewf_handle_get_header_values(
           pyewf_handle_t *pyewf_handle )
{
	char error_string[ PYEWF_ERROR_STRING_SIZE ];

	libcerror_error_t *error               = NULL;
	PyObject *dictionary_object           = NULL;
	PyObject *string_object               = NULL;
	static char *function                 = "pyewf_handle_get_header_values";
	const char *errors                    = NULL;
	char *header_value                    = NULL;
	char *header_value_identifier         = NULL;
	size_t header_value_identifier_length = 0;
	size_t header_value_identifier_size   = 0;
	size_t header_value_size              = 0;
	uint32_t number_of_header_values      = 0;
	uint32_t header_value_index           = 0;
	int result                            = 0;

	if( pyewf_handle == NULL )
	{
		PyErr_Format(
		 PyExc_ValueError,
		 "%s: invalid handle.",
		 function );

		return( NULL );
	}
	Py_BEGIN_ALLOW_THREADS

	result = libewf_handle_get_number_of_header_values(
	          pyewf_handle->handle,
	          &number_of_header_values,
	          &error );

	Py_END_ALLOW_THREADS

	if( result == -1 )
	{
		if( libcerror_error_backtrace_sprint(
		     error,
		     error_string,
		     PYEWF_ERROR_STRING_SIZE ) == -1 )
		{
			PyErr_Format(
			 PyExc_IOError,
			 "%s: failed to retrieve number of header values.",
			 function );
		}
		else
		{
			PyErr_Format(
			 PyExc_IOError,
			 "%s: failed to retrieve number of header values.\n%s",
			 function,
			 error_string );
		}
		libcerror_error_free(
		 &error );

		goto on_error;
	}
	dictionary_object = PyDict_New();

	for( header_value_index = 0;
	     header_value_index < number_of_header_values;
	     header_value_index++ )
	{
		Py_BEGIN_ALLOW_THREADS

		result = libewf_handle_get_header_value_identifier_size(
		          pyewf_handle->handle,
		          header_value_index,
		          &header_value_identifier_size,
		          &error );

		Py_END_ALLOW_THREADS

		if( result != 1 )
		{
			if( libcerror_error_backtrace_sprint(
			     error,
			     error_string,
			     PYEWF_ERROR_STRING_SIZE ) == -1 )
			{
				PyErr_Format(
				 PyExc_IOError,
				 "%s: unable to retrieve header value: %d identifier size.",
				 function,
				 header_value_index );
			}
			else
			{
				PyErr_Format(
				 PyExc_IOError,
				 "%s: unable to retrieve header value: %d identifier size.\n%s",
				 function,
				 header_value_index,
				 error_string );
			}
			libcerror_error_free(
			 &error );

			goto on_error;
		}
		header_value_identifier = (char *) PyMem_Malloc(
		                                    sizeof( char ) * header_value_identifier_size );

		if( header_value_identifier == NULL )
		{
			PyErr_Format(
			 PyExc_MemoryError,
			 "%s: unable to create header value identifier.",
			 function );

			goto on_error;
		}
		Py_BEGIN_ALLOW_THREADS

		result = libewf_handle_get_header_value_identifier(
		          pyewf_handle->handle,
		          header_value_index,
		          (uint8_t *) header_value_identifier,
		          header_value_identifier_size,
		          &error );

		Py_END_ALLOW_THREADS

		if( result != 1 )
		{
			if( libcerror_error_backtrace_sprint(
			     error,
			     error_string,
			     PYEWF_ERROR_STRING_SIZE ) == -1 )
			{
				PyErr_Format(
				 PyExc_IOError,
				 "%s: unable to retrieve header value: %d identifier.",
				 function,
				 header_value_index );
			}
			else
			{
				PyErr_Format(
				 PyExc_IOError,
				 "%s: unable to retrieve header value: %d identifier.\n%s",
				 function,
				 header_value_index,
				 error_string );
			}
			libcerror_error_free(
			 &error );

			goto on_error;
		}
		header_value_identifier_length = libcstring_narrow_string_length(
						  header_value_identifier );

		Py_BEGIN_ALLOW_THREADS

		result = libewf_handle_get_utf8_header_value_size(
		          pyewf_handle->handle,
		          (uint8_t *) header_value_identifier,
		          header_value_identifier_length,
		          &header_value_size,
		          &error );

		Py_END_ALLOW_THREADS

		if( result == -1 )
		{
			if( libcerror_error_backtrace_sprint(
			     error,
			     error_string,
			     PYEWF_ERROR_STRING_SIZE ) == -1 )
			{
				PyErr_Format(
				 PyExc_IOError,
				 "%s: unable to retrieve UTF-8 header value: %s size.",
				 function,
				 header_value_identifier );
			}
			else
			{
				PyErr_Format(
				 PyExc_IOError,
				 "%s: unable to retrieve UTF-8 header value: %s size.\n%s",
				 function,
				 header_value_identifier,
				 error_string );
			}
			libcerror_error_free(
			 &error );

			goto on_error;
		}
		/* Ignore emtpy header values
		 */
		if( ( result != 0 )
		 && ( header_value_size > 0 ) )
		{
			header_value = (char *) PyMem_Malloc(
			                         sizeof( char ) * header_value_size );

			if( header_value == NULL )
			{
				PyErr_Format(
				 PyExc_MemoryError,
				 "%s: unable to create header value.",
				 function );

				goto on_error;
			}
			Py_BEGIN_ALLOW_THREADS

			result = libewf_handle_get_utf8_header_value(
			          pyewf_handle->handle,
			          (uint8_t *) header_value_identifier,
			          header_value_identifier_length,
			          (uint8_t *) header_value,
			          header_value_size,
			          &error );

			Py_END_ALLOW_THREADS

			if( result != 1 )
			{
				if( libcerror_error_backtrace_sprint(
				     error,
				     error_string,
				     PYEWF_ERROR_STRING_SIZE ) == -1 )
				{
					PyErr_Format(
					 PyExc_IOError,
					 "%s: unable to retrieve UTF-8 header value: %s.",
					 function,
					 header_value_identifier );
				}
				else
				{
					PyErr_Format(
					 PyExc_IOError,
					 "%s: unable to retrieve UTF-8 header value: %s.\n%s",
					 function,
					 header_value_identifier,
					 error_string );
				}
				libcerror_error_free(
				 &error );

				goto on_error;
			}
			/* Pass the string length to PyUnicode_DecodeUTF8
			 * otherwise it makes the end of string character is part
			 * of the string
			 */
			string_object = PyUnicode_DecodeUTF8(
			                 header_value,
			                 header_value_size - 1,
			                 errors );

			if( string_object == NULL )
			{
				PyErr_Format(
				 PyExc_IOError,
				 "%s: unable to convert UTF-8 header value: %s into Unicode.",
				 function,
				 header_value_identifier );

				goto on_error;
			}
			if( PyDict_SetItemString(
			     dictionary_object,
			     header_value_identifier,
			     string_object ) != 0 )
			{
				PyErr_Format(
				 PyExc_MemoryError,
				 "%s: unable to set header value: %s in dictionary.",
				 function,
				 header_value_identifier );

				goto on_error;
			}
			string_object = NULL;

			PyMem_Free(
			 header_value );

			header_value = NULL;
		}
		PyMem_Free(
		 header_value_identifier );

		header_value_identifier = NULL;
	}