diff --git a/.codecov.yml b/.codecov.yml index 46eeace..d1e174f 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -13,6 +13,6 @@ coverage: - "libcthreads/*" - "libfdatetime/*" - "libfguid/*" - - "libfvalue/*" + - "libfwnt/*" - "libuna/*" - "tests/*" diff --git a/.gitignore b/.gitignore index 8b06c5d..4b15171 100644 --- a/.gitignore +++ b/.gitignore @@ -130,6 +130,7 @@ stamp-h[1-9] /setup.cfg /tests/*.exe /tests/fwevt_test_channel +/tests/fwevt_test_data_segment /tests/fwevt_test_date_time /tests/fwevt_test_error /tests/fwevt_test_event @@ -159,5 +160,5 @@ stamp-h[1-9] /libcthreads /libfdatetime /libfguid -/libfvalue +/libfwnt /libuna diff --git a/ChangeLog b/ChangeLog index 4817147..e4839ec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,13 +1,17 @@ TODO * add pyfwevt_xml_document, pyfwevt_xml_tag and pyfwevt_xml_value +* add support for hexadecimal integers in data_as_integer functions +* improve integer XML value formatting +* add codepage support * remove deprecated API functions +** libfwevt_template_get_data - Remove the need to create a copy of the template data at worst only have a copy of the BinXML +** libfwevt_xml_tag_get_utf8_value_size and libfwevt_xml_tag_get_utf8_value +** libfwevt_xml_tag_get_utf16_value_size and libfwevt_xml_tag_get_utf16_value +** libfwevt_xml_value_get_utf8_string_size and libfwevt_xml_value_copy_to_utf8_string +** libfwevt_xml_value_get_utf16_string_size and libfwevt_xml_value_copy_to_utf16_string -* Replace libfvalue by native functions -** Check use of libfwevt_xml_tag_get_value - -* Remove the need to create a copy of the template data at worst only have a copy of the BinXML -** remove libfwevt_template_get_data +* refactor: move value to XML string from XML tag into XML value * Rename _read() functions to _read_data() ** libfwevt_manifest_read diff --git a/Makefile.am b/Makefile.am index dcf0add..8198d53 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,7 +10,7 @@ SUBDIRS = \ libuna \ libfdatetime \ libfguid \ - libfvalue \ + libfwnt \ libfwevt \ pyfwevt \ po \ @@ -84,7 +84,7 @@ library: (cd $(srcdir)/libuna && $(MAKE) $(AM_MAKEFLAGS)) (cd $(srcdir)/libfdatetime && $(MAKE) $(AM_MAKEFLAGS)) (cd $(srcdir)/libfguid && $(MAKE) $(AM_MAKEFLAGS)) - (cd $(srcdir)/libfvalue && $(MAKE) $(AM_MAKEFLAGS)) + (cd $(srcdir)/libfwnt && $(MAKE) $(AM_MAKEFLAGS)) (cd $(srcdir)/libfwevt && $(MAKE) $(AM_MAKEFLAGS)) (cd $(srcdir)/po && $(MAKE) $(AM_MAKEFLAGS)) diff --git a/configure.ac b/configure.ac index c5caf2e..47af1bb 100644 --- a/configure.ac +++ b/configure.ac @@ -82,8 +82,8 @@ AX_LIBFDATETIME_CHECK_ENABLE dnl Check if libfguid or required headers and functions are available AX_LIBFGUID_CHECK_ENABLE -dnl Check if libfvalue or required headers and functions are available -AX_LIBFVALUE_CHECK_ENABLE +dnl Check if libfwnt or required headers and functions are available +AX_LIBFWNT_CHECK_ENABLE dnl Check if libfwevt required headers and functions are available AX_LIBFWEVT_CHECK_LOCAL @@ -116,7 +116,7 @@ CFLAGS="$CFLAGS -Wall"; dnl Check if requires and build requires should be set in spec file AS_IF( - [test "x$ac_cv_libcerror" = xyes || test "x$ac_cv_libcthreads" = xyes || test "x$ac_cv_libcdata" = xyes || test "x$ac_cv_libcnotify" = xyes || test "x$ac_cv_libuna" = xyes || test "x$ac_cv_libfdatetime" = xyes || test "x$ac_cv_libfguid" = xyes || test "x$ac_cv_libfvalue" = xyes], + [test "x$ac_cv_libcerror" = xyes || test "x$ac_cv_libcthreads" = xyes || test "x$ac_cv_libcdata" = xyes || test "x$ac_cv_libcnotify" = xyes || test "x$ac_cv_libuna" = xyes || test "x$ac_cv_libfdatetime" = xyes || test "x$ac_cv_libfguid" = xyes || test "x$ac_cv_libfwnt" = xyes], [AC_SUBST( [libfwevt_spec_requires], [Requires:]) @@ -143,7 +143,7 @@ AC_CONFIG_FILES([libcnotify/Makefile]) AC_CONFIG_FILES([libuna/Makefile]) AC_CONFIG_FILES([libfdatetime/Makefile]) AC_CONFIG_FILES([libfguid/Makefile]) -AC_CONFIG_FILES([libfvalue/Makefile]) +AC_CONFIG_FILES([libfwnt/Makefile]) AC_CONFIG_FILES([libfwevt/Makefile]) AC_CONFIG_FILES([pyfwevt/Makefile]) AC_CONFIG_FILES([po/Makefile.in]) @@ -180,7 +180,7 @@ Building: libuna support: $ac_cv_libuna libfdatetime support: $ac_cv_libfdatetime libfguid support: $ac_cv_libfguid - libfvalue support: $ac_cv_libfvalue + libfwnt support: $ac_cv_libfwnt Features: Multi-threading support: $ac_cv_libcthreads_multi_threading diff --git a/include/libfwevt.h.in b/include/libfwevt.h.in index 7b530dd..55b85d2 100644 --- a/include/libfwevt.h.in +++ b/include/libfwevt.h.in @@ -1077,36 +1077,6 @@ int libfwevt_xml_value_copy_data( size_t data_size, libfwevt_error_t **error ); -/* Copies the value data to an 8-bit value - * Returns 1 if successful, 0 if value not be retrieved or -1 on error - */ -LIBFWEVT_DEPRECATED \ -LIBFWEVT_EXTERN \ -int libfwevt_xml_value_copy_to_8bit( - libfwevt_xml_value_t *xml_value, - uint8_t *value_8bit, - libfwevt_error_t **error ); - -/* Copies the value data to an 32-bit value - * Returns 1 if successful, 0 if value not be retrieved or -1 on error - */ -LIBFWEVT_DEPRECATED \ -LIBFWEVT_EXTERN \ -int libfwevt_xml_value_copy_to_32bit( - libfwevt_xml_value_t *xml_value, - uint32_t *value_32bit, - libfwevt_error_t **error ); - -/* Copies the value data to an 64-bit value - * Returns 1 if successful, 0 if value not be retrieved or -1 on error - */ -LIBFWEVT_DEPRECATED \ -LIBFWEVT_EXTERN \ -int libfwevt_xml_value_copy_to_64bit( - libfwevt_xml_value_t *xml_value, - uint64_t *value_64bit, - libfwevt_error_t **error ); - /* Retrieves the value data as a 8-bit integer value * Returns 1 if successful, 0 if value not be retrieved or -1 on error */ @@ -1144,8 +1114,9 @@ int libfwevt_value_get_data_as_filetime( libfwevt_error_t **error ); /* Retrieves the size of an UTF-8 encoded string of the value data - * Returns 1 if successful, 0 if value not be retrieved or -1 on error + * Returns 1 if successful or -1 on error */ +LIBFWEVT_DEPRECATED \ LIBFWEVT_EXTERN \ int libfwevt_xml_value_get_utf8_string_size( libfwevt_xml_value_t *xml_value, @@ -1153,8 +1124,9 @@ int libfwevt_xml_value_get_utf8_string_size( libfwevt_error_t **error ); /* Copies the value data to an UTF-8 encoded string - * Returns 1 if successful, 0 if value not be retrieved or -1 on error + * Returns 1 if successful or -1 on error */ +LIBFWEVT_DEPRECATED \ LIBFWEVT_EXTERN \ int libfwevt_xml_value_copy_to_utf8_string( libfwevt_xml_value_t *xml_value, @@ -1163,8 +1135,9 @@ int libfwevt_xml_value_copy_to_utf8_string( libfwevt_error_t **error ); /* Retrieves the size of an UTF-16 encoded string of the value data - * Returns 1 if successful, 0 if value not be retrieved or -1 on error + * Returns 1 if successful or -1 on error */ +LIBFWEVT_DEPRECATED \ LIBFWEVT_EXTERN \ int libfwevt_xml_value_get_utf16_string_size( libfwevt_xml_value_t *xml_value, @@ -1172,8 +1145,9 @@ int libfwevt_xml_value_get_utf16_string_size( libfwevt_error_t **error ); /* Copies the value data to an UTF-16 encoded string - * Returns 1 if successful, 0 if value not be retrieved or -1 on error + * Returns 1 if successful or -1 on error */ +LIBFWEVT_DEPRECATED \ LIBFWEVT_EXTERN \ int libfwevt_xml_value_copy_to_utf16_string( libfwevt_xml_value_t *xml_value, @@ -1181,6 +1155,48 @@ int libfwevt_xml_value_copy_to_utf16_string( size_t utf16_string_size, libfwevt_error_t **error ); +/* Retrieves the size of the value data formatted as an UTF-8 string + * The string size includes the end of string character + * Returns 1 if successful or -1 on error + */ +LIBFWEVT_EXTERN \ +int libfwevt_xml_value_get_data_as_utf8_string_size( + libfwevt_xml_value_t *xml_value, + size_t *utf8_string_size, + libfwevt_error_t **error ); + +/* Retrieves the data formatted as an UTF-8 string + * The string size should include the end of string character + * Returns 1 if successful or -1 on error + */ +LIBFWEVT_EXTERN \ +int libfwevt_xml_value_get_data_as_utf8_string( + libfwevt_xml_value_t *xml_value, + uint8_t *utf8_string, + size_t utf8_string_size, + libfwevt_error_t **error ); + +/* Retrieves the size of the value data formatted as an UTF-16 string + * The string size includes the end of string character + * Returns 1 if successful or -1 on error + */ +LIBFWEVT_EXTERN \ +int libfwevt_xml_value_get_data_as_utf16_string_size( + libfwevt_xml_value_t *xml_value, + size_t *utf16_string_size, + libfwevt_error_t **error ); + +/* Retrieves the data formatted as an UTF-16 string + * The string size should include the end of string character + * Returns 1 if successful or -1 on error + */ +LIBFWEVT_EXTERN \ +int libfwevt_xml_value_get_data_as_utf16_string( + libfwevt_xml_value_t *xml_value, + uint16_t *utf16_string, + size_t utf16_string_size, + libfwevt_error_t **error ); + #if defined( __cplusplus ) } #endif diff --git a/libfwevt.pc.in b/libfwevt.pc.in index 4dd5171..d872b43 100644 --- a/libfwevt.pc.in +++ b/libfwevt.pc.in @@ -7,6 +7,6 @@ Name: libfwevt Description: Library to support the Windows XML Event Log (EVTX) data types Version: @VERSION@ Libs: -L${libdir} -lfwevt -Libs.private: @ax_libcdata_pc_libs_private@ @ax_libcerror_pc_libs_private@ @ax_libcnotify_pc_libs_private@ @ax_libcthreads_pc_libs_private@ @ax_libfdatetime_pc_libs_private@ @ax_libfguid_pc_libs_private@ @ax_libfvalue_pc_libs_private@ @ax_libuna_pc_libs_private@ @ax_pthread_pc_libs_private@ +Libs.private: @ax_libcdata_pc_libs_private@ @ax_libcerror_pc_libs_private@ @ax_libcnotify_pc_libs_private@ @ax_libcthreads_pc_libs_private@ @ax_libfdatetime_pc_libs_private@ @ax_libfguid_pc_libs_private@ @ax_libfwnt_pc_libs_private@ @ax_libuna_pc_libs_private@ @ax_pthread_pc_libs_private@ Cflags: -I${includedir} diff --git a/libfwevt.spec.in b/libfwevt.spec.in index 7f03edb..4799bf5 100644 --- a/libfwevt.spec.in +++ b/libfwevt.spec.in @@ -6,8 +6,8 @@ Group: System Environment/Libraries License: LGPL-3.0-or-later Source: %{name}-%{version}.tar.gz URL: https://github.com/libyal/libfwevt -@libfwevt_spec_requires@ @ax_libcdata_spec_requires@ @ax_libcerror_spec_requires@ @ax_libcnotify_spec_requires@ @ax_libcthreads_spec_requires@ @ax_libfdatetime_spec_requires@ @ax_libfguid_spec_requires@ @ax_libfvalue_spec_requires@ @ax_libuna_spec_requires@ -BuildRequires: gcc @ax_libcdata_spec_build_requires@ @ax_libcerror_spec_build_requires@ @ax_libcnotify_spec_build_requires@ @ax_libcthreads_spec_build_requires@ @ax_libfdatetime_spec_build_requires@ @ax_libfguid_spec_build_requires@ @ax_libfvalue_spec_build_requires@ @ax_libuna_spec_build_requires@ +@libfwevt_spec_requires@ @ax_libcdata_spec_requires@ @ax_libcerror_spec_requires@ @ax_libcnotify_spec_requires@ @ax_libcthreads_spec_requires@ @ax_libfdatetime_spec_requires@ @ax_libfguid_spec_requires@ @ax_libfwnt_spec_requires@ @ax_libuna_spec_requires@ +BuildRequires: gcc @ax_libcdata_spec_build_requires@ @ax_libcerror_spec_build_requires@ @ax_libcnotify_spec_build_requires@ @ax_libcthreads_spec_build_requires@ @ax_libfdatetime_spec_build_requires@ @ax_libfguid_spec_build_requires@ @ax_libfwnt_spec_build_requires@ @ax_libuna_spec_build_requires@ %description -n libfwevt Library to support the Windows XML Event Log (EVTX) data types diff --git a/libfwevt/Makefile.am b/libfwevt/Makefile.am index 8c1b24a..6df7239 100644 --- a/libfwevt/Makefile.am +++ b/libfwevt/Makefile.am @@ -7,7 +7,7 @@ AM_CPPFLAGS = \ @LIBCNOTIFY_CPPFLAGS@ \ @LIBFDATETIME_CPPFLAGS@ \ @LIBFGUID_CPPFLAGS@ \ - @LIBFVALUE_CPPFLAGS@ \ + @LIBFWNT_CPPFLAGS@ \ @LIBUNA_CPPFLAGS@ \ @PTHREAD_CPPFLAGS@ \ @LIBFWEVT_DLL_EXPORT@ @@ -18,17 +18,21 @@ libfwevt_la_SOURCES = \ fwevt_template.h \ libfwevt.c \ libfwevt_channel.c libfwevt_channel.h \ + libfwevt_data_segment.c libfwevt_data_segment.h \ libfwevt_date_time.c libfwevt_date_time.h \ libfwevt_debug.c libfwevt_debug.h \ libfwevt_definitions.h \ libfwevt_extern.h \ libfwevt_error.c libfwevt_error.h \ libfwevt_event.c libfwevt_event.h \ + libfwevt_floating_point.c libfwevt_floating_point.h \ + libfwevt_integer.c libfwevt_integer.h \ libfwevt_libcdata.h \ libfwevt_libcerror.h \ libfwevt_libcnotify.h \ + libfwevt_libfdatetime.h \ libfwevt_libfguid.h \ - libfwevt_libfvalue.h \ + libfwevt_libfwnt.h \ libfwevt_libuna.h \ libfwevt_keyword.c libfwevt_keyword.h \ libfwevt_level.c libfwevt_level.h \ @@ -57,7 +61,7 @@ libfwevt_la_LIBADD = \ @LIBUNA_LIBADD@ \ @LIBFDATETIME_LIBADD@ \ @LIBFGUID_LIBADD@ \ - @LIBFVALUE_LIBADD@ \ + @LIBFWNT_LIBADD@ \ @PTHREAD_LIBADD@ libfwevt_la_LDFLAGS = -no-undefined -version-info 1:0:0 diff --git a/libfwevt/libfwevt_data_segment.c b/libfwevt/libfwevt_data_segment.c new file mode 100644 index 0000000..5c7c915 --- /dev/null +++ b/libfwevt/libfwevt_data_segment.c @@ -0,0 +1,274 @@ +/* + * Data segment functions + * + * Copyright (C) 2011-2024, Joachim Metz + * + * Refer to AUTHORS for acknowledgements. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include +#include +#include + +#include "libfwevt_data_segment.h" +#include "libfwevt_definitions.h" +#include "libfwevt_libcerror.h" +#include "libfwevt_libfdatetime.h" +#include "libfwevt_libfguid.h" +#include "libfwevt_libfwnt.h" + +/* Creates a data segment + * Make sure the value data_segment is referencing, is set to NULL + * Returns 1 if successful or -1 on error + */ +int libfwevt_data_segment_initialize( + libfwevt_data_segment_t **data_segment, + const uint8_t *data, + size_t data_size, + libcerror_error_t **error ) +{ + static char *function = "libfwevt_data_segment_initialize"; + + if( data_segment == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid data segment.", + function ); + + return( -1 ); + } + if( *data_segment != NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, + "%s: invalid data segment value already set.", + function ); + + return( -1 ); + } + if( data == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid data.", + function ); + + return( -1 ); + } + if( data_size > (size_t) MEMORY_MAXIMUM_ALLOCATION_SIZE ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, + "%s: invalid data size value out of bounds.", + function ); + + return( -1 ); + } + *data_segment = memory_allocate_structure( + libfwevt_data_segment_t ); + + if( *data_segment == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_MEMORY, + LIBCERROR_MEMORY_ERROR_INSUFFICIENT, + "%s: unable to create data segment.", + function ); + + goto on_error; + } + if( memory_set( + *data_segment, + 0, + sizeof( libfwevt_data_segment_t ) ) == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_MEMORY, + LIBCERROR_MEMORY_ERROR_SET_FAILED, + "%s: unable to clear data segment.", + function ); + + memory_free( + *data_segment ); + + *data_segment = NULL; + + return( -1 ); + } + if( data_size > 0 ) + { + ( *data_segment)->data = (uint8_t *) memory_allocate( + sizeof( uint8_t ) * data_size ); + + if( ( *data_segment)->data == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_MEMORY, + LIBCERROR_MEMORY_ERROR_INSUFFICIENT, + "%s: unable to create data.", + function ); + + goto on_error; + } + ( *data_segment)->data_size = data_size; + + if( memory_copy( + ( *data_segment)->data, + data, + data_size ) == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_MEMORY, + LIBCERROR_MEMORY_ERROR_COPY_FAILED, + "%s: unable to copy data.", + function ); + + goto on_error; + } + } + return( 1 ); + +on_error: + if( *data_segment != NULL ) + { + if( ( *data_segment )->data != NULL ) + { + memory_free( + ( *data_segment )->data ); + } + memory_free( + *data_segment ); + + *data_segment = NULL; + } + return( -1 ); +} + +/* Frees a data segment + * Returns 1 if successful or -1 on error + */ +int libfwevt_data_segment_free( + libfwevt_data_segment_t **data_segment, + libcerror_error_t **error ) +{ + static char *function = "libfwevt_data_segment_free"; + int result = 1; + + if( data_segment == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid data segment.", + function ); + + return( -1 ); + } + if( *data_segment != NULL ) + { + switch( ( *data_segment )->cached_value_type & 0x7f ) + { + case LIBFWEVT_VALUE_TYPE_GUID: + if( libfguid_identifier_free( + &( ( *data_segment )->guid ), + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, + "%s: unable to free GUID.", + function ); + + result = -1; + } + break; + + case LIBFWEVT_VALUE_TYPE_FILETIME: + if( libfdatetime_filetime_free( + &( ( *data_segment )->filetime ), + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, + "%s: unable to free FILETIME.", + function ); + + result = -1; + } + break; + + case LIBFWEVT_VALUE_TYPE_SYSTEMTIME: + if( libfdatetime_systemtime_free( + &( ( *data_segment )->systemtime ), + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, + "%s: unable to free SYSTEMTIME.", + function ); + + result = -1; + } + break; + + case LIBFWEVT_VALUE_TYPE_NT_SECURITY_IDENTIFIER: + if( libfwnt_security_identifier_free( + &( ( *data_segment )->security_identifier ), + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, + "%s: unable to free NT security identifier.", + function ); + + result = -1; + } + break; + } + if( ( *data_segment )->data != NULL ) + { + memory_free( + ( *data_segment )->data ); + } + memory_free( + *data_segment ); + + *data_segment = NULL; + } + return( result ); +} + diff --git a/libfwevt/libfwevt_data_segment.h b/libfwevt/libfwevt_data_segment.h new file mode 100644 index 0000000..fd6aa85 --- /dev/null +++ b/libfwevt/libfwevt_data_segment.h @@ -0,0 +1,94 @@ +/* + * Data segment functions + * + * Copyright (C) 2011-2024, Joachim Metz + * + * Refer to AUTHORS for acknowledgements. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#if !defined( _LIBFWEVT_DATA_SEGMENT_H ) +#define _LIBFWEVT_DATA_SEGMENT_H + +#include +#include + +#include "libfwevt_libcerror.h" +#include "libfwevt_libfdatetime.h" +#include "libfwevt_libfguid.h" +#include "libfwevt_libfwnt.h" + +#if defined( __cplusplus ) +extern "C" { +#endif + +typedef struct libfwevt_data_segment libfwevt_data_segment_t; + +struct libfwevt_data_segment +{ + /* The data + */ + uint8_t *data; + + /* The data size + */ + size_t data_size; + + /* The cached value type + */ + uint8_t cached_value_type; + + /* The cached value + */ + union + { + /* Cached 64-bit value + */ + uint64_t value_64bit; + + /* Cached GUID value + */ + libfguid_identifier_t *guid; + + /* Cached FILETIME value + */ + libfdatetime_filetime_t *filetime; + + /* Cached SYSTEMTIME value + */ + libfdatetime_systemtime_t *systemtime; + + /* Cached NT security identifier value + */ + libfwnt_security_identifier_t *security_identifier; + }; +}; + +int libfwevt_data_segment_initialize( + libfwevt_data_segment_t **data_segment, + const uint8_t *data, + size_t data_size, + libcerror_error_t **error ); + +int libfwevt_data_segment_free( + libfwevt_data_segment_t **data_segment, + libcerror_error_t **error ); + +#if defined( __cplusplus ) +} +#endif + +#endif /* !defined( _LIBFWEVT_DATA_SEGMENT_H ) */ + diff --git a/libfwevt/libfwevt_date_time.c b/libfwevt/libfwevt_date_time.c index 7e87932..5d6a67c 100644 --- a/libfwevt/libfwevt_date_time.c +++ b/libfwevt/libfwevt_date_time.c @@ -1,5 +1,5 @@ /* - * Date and time values functions + * Date and time functions * * Copyright (C) 2011-2024, Joachim Metz * @@ -33,16 +33,17 @@ #endif #endif -/* Copies an ISO 8601 UTF-8 formatted string to a FILETIME value +/* Copies an ISO 8601 UTF-16 stream to a FILETIME value * Returns 1 if successful or -1 on error */ -int libfwevt_utf8_string_copy_to_filetime( - const uint8_t *utf8_string, - size_t utf8_string_size, +int libfwevt_filetime_copy_from_utf16_stream( uint64_t *filetime, + const uint8_t *utf16_stream, + size_t utf16_stream_size, libcerror_error_t **error ) { - static char *function = "libfwevt_utf8_string_copy_to_filetime"; + static char *function = "libfwevt_filetime_copy_from_utf16_stream"; + size_t utf16_stream_offset = 0; uint64_t safe_filetime = 0; uint32_t fraction_of_second = 0; uint16_t current_year = 0; @@ -54,50 +55,58 @@ int libfwevt_utf8_string_copy_to_filetime( uint8_t month = 0; uint8_t is_leap_year = 0; uint8_t seconds = 0; - size_t utf8_string_index = 0; - if( utf8_string == NULL ) + if( filetime == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid UTF-8 string.", + "%s: invalid FILETIME.", function ); return( -1 ); } - if( ( utf8_string_size < 31 ) - || ( utf8_string_size > (size_t) SSIZE_MAX ) ) + if( utf16_stream == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, - "%s: invalid UTF-8 string size value out of bounds.", + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-16 stream.", function ); return( -1 ); } - if( filetime == NULL ) + if( ( utf16_stream_size < 62 ) + || ( utf16_stream_size > (size_t) SSIZE_MAX ) + || ( ( utf16_stream_size % 2 ) != 0 ) ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid FILETIME value.", + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, + "%s: unsupported UTF-16 stream size.", function ); return( -1 ); } - if( ( utf8_string[ 4 ] != (uint8_t) '-' ) - || ( utf8_string[ 7 ] != (uint8_t) '-' ) - || ( utf8_string[ 10 ] != (uint8_t) 'T' ) - || ( utf8_string[ 13 ] != (uint8_t) ':' ) - || ( utf8_string[ 16 ] != (uint8_t) ':' ) - || ( utf8_string[ 19 ] != (uint8_t) '.' ) - || ( utf8_string[ 29 ] != (uint8_t) 'Z' ) - || ( utf8_string[ 30 ] != (uint8_t) 0 ) ) + if( ( utf16_stream[ 8 ] != (uint8_t) '-' ) + || ( utf16_stream[ 9 ] != 0 ) + || ( utf16_stream[ 14 ] != (uint8_t) '-' ) + || ( utf16_stream[ 15 ] != 0 ) + || ( utf16_stream[ 20 ] != (uint8_t) 'T' ) + || ( utf16_stream[ 21 ] != 0 ) + || ( utf16_stream[ 26 ] != (uint8_t) ':' ) + || ( utf16_stream[ 27 ] != 0 ) + || ( utf16_stream[ 32 ] != (uint8_t) ':' ) + || ( utf16_stream[ 33 ] != 0 ) + || ( utf16_stream[ 38 ] != (uint8_t) '.' ) + || ( utf16_stream[ 39 ] != 0 ) + || ( utf16_stream[ 58 ] != (uint8_t) 'Z' ) + || ( utf16_stream[ 59 ] != 0 ) + || ( utf16_stream[ 60 ] != 0 ) + || ( utf16_stream[ 61 ] != 0 ) ) { libcerror_error_set( error, @@ -108,12 +117,12 @@ int libfwevt_utf8_string_copy_to_filetime( return( -1 ); } - for( utf8_string_index = 0; - utf8_string_index < 4; - utf8_string_index++ ) + for( utf16_stream_offset = 0; + utf16_stream_offset < 8; + utf16_stream_offset += 2 ) { - if( ( utf8_string[ utf8_string_index ] < (uint8_t) '0' ) - || ( utf8_string[ utf8_string_index ] > (uint8_t) '9' ) ) + if( ( utf16_stream[ utf16_stream_offset ] < (uint8_t) '0' ) + || ( utf16_stream[ utf16_stream_offset ] > (uint8_t) '9' ) ) { libcerror_error_set( error, @@ -125,14 +134,15 @@ int libfwevt_utf8_string_copy_to_filetime( return( -1 ); } year *= 10; - year += utf8_string[ utf8_string_index ] - (uint8_t) '0'; + year += utf16_stream[ utf16_stream_offset ] - (uint8_t) '0'; } - for( utf8_string_index = 5; - utf8_string_index < 7; - utf8_string_index++ ) + for( utf16_stream_offset = 10; + utf16_stream_offset < 14; + utf16_stream_offset += 2 ) { - if( ( utf8_string[ utf8_string_index ] < (uint8_t) '0' ) - || ( utf8_string[ utf8_string_index ] > (uint8_t) '9' ) ) + if( ( utf16_stream[ utf16_stream_offset ] < (uint8_t) '0' ) + || ( utf16_stream[ utf16_stream_offset ] > (uint8_t) '9' ) + || ( utf16_stream[ utf16_stream_offset + 1 ] != 0 ) ) { libcerror_error_set( error, @@ -144,14 +154,15 @@ int libfwevt_utf8_string_copy_to_filetime( return( -1 ); } month *= 10; - month += utf8_string[ utf8_string_index ] - (uint8_t) '0'; + month += utf16_stream[ utf16_stream_offset ] - (uint8_t) '0'; } - for( utf8_string_index = 8; - utf8_string_index < 10; - utf8_string_index++ ) + for( utf16_stream_offset = 16; + utf16_stream_offset < 20; + utf16_stream_offset += 2 ) { - if( ( utf8_string[ utf8_string_index ] < (uint8_t) '0' ) - || ( utf8_string[ utf8_string_index ] > (uint8_t) '9' ) ) + if( ( utf16_stream[ utf16_stream_offset ] < (uint8_t) '0' ) + || ( utf16_stream[ utf16_stream_offset ] > (uint8_t) '9' ) + || ( utf16_stream[ utf16_stream_offset + 1 ] != 0 ) ) { libcerror_error_set( error, @@ -163,14 +174,15 @@ int libfwevt_utf8_string_copy_to_filetime( return( -1 ); } day_of_month *= 10; - day_of_month += utf8_string[ utf8_string_index ] - (uint8_t) '0'; + day_of_month += utf16_stream[ utf16_stream_offset ] - (uint8_t) '0'; } - for( utf8_string_index = 11; - utf8_string_index < 13; - utf8_string_index++ ) + for( utf16_stream_offset = 22; + utf16_stream_offset < 26; + utf16_stream_offset += 2 ) { - if( ( utf8_string[ utf8_string_index ] < (uint8_t) '0' ) - || ( utf8_string[ utf8_string_index ] > (uint8_t) '9' ) ) + if( ( utf16_stream[ utf16_stream_offset ] < (uint8_t) '0' ) + || ( utf16_stream[ utf16_stream_offset ] > (uint8_t) '9' ) + || ( utf16_stream[ utf16_stream_offset + 1 ] != 0 ) ) { libcerror_error_set( error, @@ -182,14 +194,15 @@ int libfwevt_utf8_string_copy_to_filetime( return( -1 ); } hours *= 10; - hours += utf8_string[ utf8_string_index ] - (uint8_t) '0'; + hours += utf16_stream[ utf16_stream_offset ] - (uint8_t) '0'; } - for( utf8_string_index = 14; - utf8_string_index < 16; - utf8_string_index++ ) + for( utf16_stream_offset = 28; + utf16_stream_offset < 32; + utf16_stream_offset += 2 ) { - if( ( utf8_string[ utf8_string_index ] < (uint8_t) '0' ) - || ( utf8_string[ utf8_string_index ] > (uint8_t) '9' ) ) + if( ( utf16_stream[ utf16_stream_offset ] < (uint8_t) '0' ) + || ( utf16_stream[ utf16_stream_offset ] > (uint8_t) '9' ) + || ( utf16_stream[ utf16_stream_offset + 1 ] != 0 ) ) { libcerror_error_set( error, @@ -201,14 +214,15 @@ int libfwevt_utf8_string_copy_to_filetime( return( -1 ); } minutes *= 10; - minutes += utf8_string[ utf8_string_index ] - (uint8_t) '0'; + minutes += utf16_stream[ utf16_stream_offset ] - (uint8_t) '0'; } - for( utf8_string_index = 17; - utf8_string_index < 19; - utf8_string_index++ ) + for( utf16_stream_offset = 34; + utf16_stream_offset < 38; + utf16_stream_offset += 2 ) { - if( ( utf8_string[ utf8_string_index ] < (uint8_t) '0' ) - || ( utf8_string[ utf8_string_index ] > (uint8_t) '9' ) ) + if( ( utf16_stream[ utf16_stream_offset ] < (uint8_t) '0' ) + || ( utf16_stream[ utf16_stream_offset ] > (uint8_t) '9' ) + || ( utf16_stream[ utf16_stream_offset + 1 ] != 0 ) ) { libcerror_error_set( error, @@ -220,14 +234,15 @@ int libfwevt_utf8_string_copy_to_filetime( return( -1 ); } seconds *= 10; - seconds += utf8_string[ utf8_string_index ] - (uint8_t) '0'; + seconds += utf16_stream[ utf16_stream_offset ] - (uint8_t) '0'; } - for( utf8_string_index = 20; - utf8_string_index < 29; - utf8_string_index++ ) + for( utf16_stream_offset = 40; + utf16_stream_offset < 58; + utf16_stream_offset += 2 ) { - if( ( utf8_string[ utf8_string_index ] < (uint8_t) '0' ) - || ( utf8_string[ utf8_string_index ] > (uint8_t) '9' ) ) + if( ( utf16_stream[ utf16_stream_offset ] < (uint8_t) '0' ) + || ( utf16_stream[ utf16_stream_offset ] > (uint8_t) '9' ) + || ( utf16_stream[ utf16_stream_offset + 1 ] != 0 ) ) { libcerror_error_set( error, @@ -239,7 +254,7 @@ int libfwevt_utf8_string_copy_to_filetime( return( -1 ); } fraction_of_second *= 10; - fraction_of_second += utf8_string[ utf8_string_index ] - (uint8_t) '0'; + fraction_of_second += utf16_stream[ utf16_stream_offset ] - (uint8_t) '0'; } if( year < 1600 ) { diff --git a/libfwevt/libfwevt_date_time.h b/libfwevt/libfwevt_date_time.h index a4ec720..9d00483 100644 --- a/libfwevt/libfwevt_date_time.h +++ b/libfwevt/libfwevt_date_time.h @@ -1,5 +1,5 @@ /* - * Date and time values functions + * Date and time functions * * Copyright (C) 2011-2024, Joachim Metz * @@ -19,8 +19,8 @@ * along with this program. If not, see . */ -#if !defined( _LIBFWEVT_DATE_TIME_VALUES_H ) -#define _LIBFWEVT_DATE_TIME_VALUES_H +#if !defined( _LIBFWEVT_DATE_TIME_H ) +#define _LIBFWEVT_DATE_TIME_H #include #include @@ -31,15 +31,15 @@ extern "C" { #endif -int libfwevt_utf8_string_copy_to_filetime( - const uint8_t *utf8_string, - size_t utf8_string_size, +int libfwevt_filetime_copy_from_utf16_stream( uint64_t *filetime, + const uint8_t *utf16_stream, + size_t utf16_stream_size, libcerror_error_t **error ); #if defined( __cplusplus ) } #endif -#endif /* !defined( _LIBFWEVT_DATE_TIME_VALUES_H ) */ +#endif /* !defined( _LIBFWEVT_DATE_TIME_H ) */ diff --git a/libfwevt/libfwevt_floating_point.c b/libfwevt/libfwevt_floating_point.c new file mode 100644 index 0000000..8dd1bed --- /dev/null +++ b/libfwevt/libfwevt_floating_point.c @@ -0,0 +1,1296 @@ +/* + * Floating point (IEEE 754) functions + * + * Copyright (C) 2011-2024, Joachim Metz + * + * Refer to AUTHORS for acknowledgements. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include +#include +#include + +#include "libfwevt_floating_point.h" +#include "libfwevt_libcerror.h" + +/* Deterimes the size of the string of a 32-bit floating point + * The string size includes the end of string character + * Returns 1 if successful or -1 on error + */ +int libfwevt_float32_get_string_size( + uint32_t value_32bit, + size_t *string_size, + libcerror_error_t **error ) +{ + static char *function = "libfwevt_float32_get_string_size"; + uint8_t is_indeterminate = 0; + uint8_t is_infinite = 0; + uint8_t is_not_a_number = 0; + uint8_t is_negative = 0; + uint8_t number_of_characters = 0; + + if( string_size == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid string size.", + function ); + + return( -1 ); + } + is_negative = (uint8_t) ( value_32bit >> 31 ); + + if( is_negative != 0 ) + { + value_32bit &= ~( (uint32_t) 1 << 31 ); + } + if( value_32bit == 0x7f800000UL ) + { + is_infinite = 1; + } + else if( ( is_negative != 0 ) + && ( value_32bit == 0x7fc00000UL ) ) + { + is_indeterminate = 1; + } + else if( ( value_32bit >= 0x7f800001UL ) + && ( value_32bit <= 0x7fffffffUL ) ) + { + is_not_a_number = 1; + } + if( is_indeterminate != 0 ) + { + /* "Ind" + end-of-string character */ + number_of_characters = 4; + } + else if( is_infinite != 0 ) + { + /* "Inf" + end-of-string character */ + number_of_characters = 4; + } + else if( is_not_a_number != 0 ) + { + /* "Nan" + end-of-string character */ + number_of_characters = 4; + } + else + { + /* "[-]0.000000e[+-]000" + end-of-string character */ + if( is_negative != 0 ) + { + number_of_characters = 15; + } + else + { + number_of_characters = 14; + } + } + *string_size = number_of_characters; + + return( 1 ); +} + +/* Copies a 32-bit floating point to an UTF-8 string + * The string size should include the end of string character + * Returns 1 if successful or -1 on error + */ +int libfwevt_float32_copy_to_utf8_string_with_index( + uint32_t value_32bit, + uint8_t *utf8_string, + size_t utf8_string_size, + size_t *utf8_string_index, + libcerror_error_t **error ) +{ + byte_stream_float32_t value_float32; + + static char *function = "libfwevt_float32_copy_to_utf8_string_with_index"; + size_t safe_utf8_string_index = 0; + uint32_t divider = 0; + uint32_t value_fraction = 0; + int16_t exponent10 = 0; + int16_t exponent2 = 0; + uint8_t digit_index = 0; + uint8_t exponent_sign = 0; + uint8_t is_indeterminate = 0; + uint8_t is_infinite = 0; + uint8_t is_not_a_number = 0; + uint8_t is_negative = 0; + uint8_t number_of_characters = 0; + double exponent_value = 0.0; + double value_float = 0.0; + + if( utf8_string == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-8 string.", + function ); + + return( -1 ); + } + if( utf8_string_size > (size_t) SSIZE_MAX ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, + "%s: invalid UTF-8 string size value exceeds maximum.", + function ); + + return( -1 ); + } + if( utf8_string_index == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-8 string index.", + function ); + + return( -1 ); + } + safe_utf8_string_index = *utf8_string_index; + + is_negative = (uint8_t) ( value_32bit >> 31 ); + + if( is_negative != 0 ) + { + value_32bit &= ~( (uint32_t) 1 << 31 ); + } + if( value_32bit == 0x7f800000UL ) + { + is_infinite = 1; + } + else if( ( is_negative != 0 ) + && ( value_32bit == 0x7fc00000UL ) ) + { + is_indeterminate = 1; + } + else if( ( value_32bit >= 0x7f800001UL ) + && ( value_32bit <= 0x7fffffffUL ) ) + { + is_not_a_number = 1; + } + else if( value_32bit != 0 ) + { + value_float32.integer = value_32bit; + value_float = (double) value_float32.floating_point; + + exponent2 = (int16_t) ( value_32bit >> 23 ); + + if( exponent2 == 0 ) + { + exponent2 = -126; + } + else + { + exponent2 -= 127; + } + } + if( is_indeterminate != 0 ) + { + /* "Ind" + end-of-string character */ + number_of_characters = 4; + } + else if( is_infinite != 0 ) + { + /* "Inf" + end-of-string character */ + number_of_characters = 4; + } + else if( is_not_a_number != 0 ) + { + /* "Nan" + end-of-string character */ + number_of_characters = 4; + } + else + { + /* "[-]0.000000e[+-]000" + end-of-string character */ + if( is_negative != 0 ) + { + number_of_characters = 15; + } + else + { + number_of_characters = 14; + } + } + if( ( number_of_characters > utf8_string_size ) + || ( safe_utf8_string_index > ( utf8_string_size - number_of_characters ) ) ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, + "%s: invalid UTF-8 string size value too small.", + function ); + + return( -1 ); + } + if( is_indeterminate != 0 ) + { + /* "Ind" + end-of-string character */ + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'I'; + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'n'; + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'd'; + } + else if( is_infinite != 0 ) + { + /* "Inf" + end-of-string character */ + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'I'; + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'n'; + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'f'; + } + else if( is_not_a_number != 0 ) + { + /* "Nan" + end-of-string character */ + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'N'; + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'a'; + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'N'; + } + else + { + /* "[-]0.000000e[+-]000" + end-of-string character */ + if( is_negative != 0 ) + { + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) '-'; + } + if( exponent2 < 0 ) + { + exponent_sign = (uint8_t) '-'; + exponent2 *= -1; + } + else + { + exponent_sign = (uint8_t) '+'; + } + exponent_value = 1.0; + exponent10 = 0; + + while( exponent2 > 0 ) + { + exponent_value *= 2; + exponent2--; + + if( exponent_value >= 10.0 ) + { + exponent_value /= 10.0; + exponent10++; + + if( exponent_sign == (uint8_t) '-' ) + { + value_float *= 10.0; + } + else + { + value_float /= 10.0; + } + } + } + if( value_float != 0.0 ) + { + while( ( value_float < 1.0 ) + || ( value_float >= 10.0 ) ) + { + exponent10++; + + if( exponent_sign == (uint8_t) '-' ) + { + value_float *= 10; + } + else + { + value_float /= 10; + } + } + } + for( digit_index = 0; + digit_index < 7; + digit_index++ ) + { + value_fraction *= 10; + value_fraction += (uint8_t) value_float; + + value_float -= (uint8_t) value_float; + value_float *= 10.0; + } + if( value_float >= 5.0 ) + { + value_fraction += 1; + } + divider = 1000000; + + for( digit_index = 0; + digit_index < 7; + digit_index++ ) + { + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) '0' + (uint8_t) ( value_fraction / divider ); + + if( digit_index == 0 ) + { + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) '.'; + } + value_fraction %= divider; + divider /= 10; + } + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'e'; + utf8_string[ safe_utf8_string_index++ ] = exponent_sign; + + divider = 100; + + for( digit_index = 0; + digit_index < 3; + digit_index++ ) + { + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) '0' + (uint8_t) ( exponent10 / divider ); + + exponent10 %= divider; + divider /= 10; + } + } + utf8_string[ safe_utf8_string_index++ ] = 0; + + *utf8_string_index = safe_utf8_string_index; + + return( 1 ); +} + +/* Copies a 32-bit floating point to an UTF-16 string + * The string size should include the end of string character + * Returns 1 if successful or -1 on error + */ +int libfwevt_float32_copy_to_utf16_string_with_index( + uint32_t value_32bit, + uint16_t *utf16_string, + size_t utf16_string_size, + size_t *utf16_string_index, + libcerror_error_t **error ) +{ + byte_stream_float32_t value_float32; + + static char *function = "libfwevt_float32_copy_to_utf16_string_with_index"; + size_t safe_utf16_string_index = 0; + uint32_t divider = 0; + uint32_t value_fraction = 0; + uint16_t exponent_sign = 0; + int16_t exponent10 = 0; + int16_t exponent2 = 0; + uint8_t digit_index = 0; + uint8_t is_indeterminate = 0; + uint8_t is_infinite = 0; + uint8_t is_not_a_number = 0; + uint8_t is_negative = 0; + uint8_t number_of_characters = 0; + double exponent_value = 0.0; + double value_float = 0.0; + + if( utf16_string == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-16 string.", + function ); + + return( -1 ); + } + if( utf16_string_size > (size_t) SSIZE_MAX ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, + "%s: invalid UTF-16 string size value exceeds maximum.", + function ); + + return( -1 ); + } + if( utf16_string_index == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-16 string index.", + function ); + + return( -1 ); + } + safe_utf16_string_index = *utf16_string_index; + + is_negative = (uint8_t) ( value_32bit >> 31 ); + + if( is_negative != 0 ) + { + value_32bit &= ~( (uint32_t) 1 << 31 ); + } + if( value_32bit == 0x7f800000UL ) + { + is_infinite = 1; + } + else if( ( is_negative != 0 ) + && ( value_32bit == 0x7fc00000UL ) ) + { + is_indeterminate = 1; + } + else if( ( value_32bit >= 0x7f800001UL ) + && ( value_32bit <= 0x7fffffffUL ) ) + { + is_not_a_number = 1; + } + else if( value_32bit != 0 ) + { + value_float32.integer = value_32bit; + value_float = (double) value_float32.floating_point; + + exponent2 = (int16_t) ( value_32bit >> 23 ); + + if( exponent2 == 0 ) + { + exponent2 = -126; + } + else + { + exponent2 -= 127; + } + } + if( is_indeterminate != 0 ) + { + /* "Ind" + end-of-string character */ + number_of_characters = 4; + } + else if( is_infinite != 0 ) + { + /* "Inf" + end-of-string character */ + number_of_characters = 4; + } + else if( is_not_a_number != 0 ) + { + /* "Nan" + end-of-string character */ + number_of_characters = 4; + } + else + { + /* "[-]0.000000e[+-]000" + end-of-string character */ + if( is_negative != 0 ) + { + number_of_characters = 15; + } + else + { + number_of_characters = 14; + } + } + if( ( number_of_characters > utf16_string_size ) + || ( safe_utf16_string_index > ( utf16_string_size - number_of_characters ) ) ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, + "%s: invalid UTF-16 string size value too small.", + function ); + + return( -1 ); + } + if( is_indeterminate != 0 ) + { + /* "Ind" + end-of-string character */ + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'I'; + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'n'; + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'd'; + } + else if( is_infinite != 0 ) + { + /* "Inf" + end-of-string character */ + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'I'; + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'n'; + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'f'; + } + else if( is_not_a_number != 0 ) + { + /* "Nan" + end-of-string character */ + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'N'; + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'a'; + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'N'; + } + else + { + /* "[-]0.000000e[+-]000" + end-of-string character */ + if( is_negative != 0 ) + { + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) '-'; + } + if( exponent2 < 0 ) + { + exponent_sign = (uint16_t) '-'; + exponent2 *= -1; + } + else + { + exponent_sign = (uint16_t) '+'; + } + exponent_value = 1.0; + exponent10 = 0; + + while( exponent2 > 0 ) + { + exponent_value *= 2; + exponent2--; + + if( exponent_value >= 10.0 ) + { + exponent_value /= 10.0; + exponent10++; + + if( exponent_sign == (uint16_t) '-' ) + { + value_float *= 10.0; + } + else + { + value_float /= 10.0; + } + } + } + if( value_float != 0.0 ) + { + while( ( value_float < 1.0 ) + || ( value_float >= 10.0 ) ) + { + exponent10++; + + if( exponent_sign == (uint16_t) '-' ) + { + value_float *= 10; + } + else + { + value_float /= 10; + } + } + } + for( digit_index = 0; + digit_index < 7; + digit_index++ ) + { + value_fraction *= 10; + value_fraction += (uint8_t) value_float; + + value_float -= (uint8_t) value_float; + value_float *= 10.0; + } + if( value_float >= 5.0 ) + { + value_fraction += 1; + } + divider = 1000000; + + for( digit_index = 0; + digit_index < 7; + digit_index++ ) + { + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) '0' + (uint16_t) ( value_fraction / divider ); + + if( digit_index == 0 ) + { + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) '.'; + } + value_fraction %= divider; + divider /= 10; + } + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'e'; + utf16_string[ safe_utf16_string_index++ ] = exponent_sign; + + divider = 100; + + for( digit_index = 0; + digit_index < 3; + digit_index++ ) + { + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) '0' + (uint16_t) ( exponent10 / divider ); + + exponent10 %= divider; + divider /= 10; + } + } + utf16_string[ safe_utf16_string_index++ ] = 0; + + *utf16_string_index = safe_utf16_string_index; + + return( 1 ); +} + +/* Deterimes the size of the string of a 64-bit floating point + * The string size includes the end of string character + * Returns 1 if successful or -1 on error + */ +int libfwevt_float64_get_string_size( + uint64_t value_64bit, + size_t *string_size, + libcerror_error_t **error ) +{ + static char *function = "libfwevt_float64_get_string_size"; + uint8_t is_indeterminate = 0; + uint8_t is_infinite = 0; + uint8_t is_not_a_number = 0; + uint8_t is_negative = 0; + uint8_t number_of_characters = 0; + + if( string_size == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid string size.", + function ); + + return( -1 ); + } + is_negative = (uint8_t) ( value_64bit >> 63 ); + + if( is_negative != 0 ) + { + value_64bit &= ~( (uint64_t) 1 << 63 ); + } +#if defined( __BORLANDC__ ) && ( __BORLANDC__ < 0x0560 ) + if( value_64bit == 0x7ff0000000000000UL ) +#else + if( value_64bit == 0x7ff0000000000000ULL ) +#endif + { + is_infinite = 1; + } +#if defined( __BORLANDC__ ) && ( __BORLANDC__ < 0x0560 ) + else if( ( is_negative != 0 ) + && ( value_64bit == 0x7ff8000000000000UL ) ) +#else + else if( ( is_negative != 0 ) + && ( value_64bit == 0x7ff8000000000000ULL ) ) +#endif + { + is_indeterminate = 1; + } +#if defined( __BORLANDC__ ) && ( __BORLANDC__ < 0x0560 ) + else if( ( value_64bit >= 0x7ff0000000000001UL ) + && ( value_64bit <= 0x7fffffffffffffffUL ) ) +#else + else if( ( value_64bit >= 0x7ff0000000000001ULL ) + && ( value_64bit <= 0x7fffffffffffffffULL ) ) +#endif + { + is_not_a_number = 1; + } + if( is_indeterminate != 0 ) + { + /* "Ind" + end-of-string character */ + number_of_characters = 4; + } + else if( is_infinite != 0 ) + { + /* "Inf" + end-of-string character */ + number_of_characters = 4; + } + else if( is_not_a_number != 0 ) + { + /* "Nan" + end-of-string character */ + number_of_characters = 4; + } + else + { + /* "[-]0.000000e[+-]000" + end-of-string character */ + if( is_negative != 0 ) + { + number_of_characters = 15; + } + else + { + number_of_characters = 14; + } + } + *string_size = number_of_characters; + + return( 1 ); +} + +/* Copies a 64-bit floating point to an UTF-8 string + * The string size should include the end of string character + * Returns 1 if successful or -1 on error + */ +int libfwevt_float64_copy_to_utf8_string_with_index( + uint64_t value_64bit, + uint8_t *utf8_string, + size_t utf8_string_size, + size_t *utf8_string_index, + libcerror_error_t **error ) +{ + byte_stream_float64_t value_float64; + + static char *function = "libfwevt_float64_copy_to_utf8_string_with_index"; + size_t safe_utf8_string_index = 0; + uint64_t divider = 0; + uint64_t value_fraction = 0; + int16_t exponent10 = 0; + int16_t exponent2 = 0; + uint8_t digit_index = 0; + uint8_t exponent_sign = 0; + uint8_t is_indeterminate = 0; + uint8_t is_infinite = 0; + uint8_t is_not_a_number = 0; + uint8_t is_negative = 0; + uint8_t number_of_characters = 0; + double exponent_value = 0.0; + double value_float = 0.0; + + if( utf8_string == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-8 string.", + function ); + + return( -1 ); + } + if( utf8_string_size > (size_t) SSIZE_MAX ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, + "%s: invalid UTF-8 string size value exceeds maximum.", + function ); + + return( -1 ); + } + if( utf8_string_index == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-8 string index.", + function ); + + return( -1 ); + } + safe_utf8_string_index = *utf8_string_index; + + is_negative = (uint8_t) ( value_64bit >> 63 ); + + if( is_negative != 0 ) + { + value_64bit &= ~( (uint64_t) 1 << 63 ); + } +#if defined( __BORLANDC__ ) && ( __BORLANDC__ < 0x0560 ) + if( value_64bit == 0x7ff0000000000000UL ) +#else + if( value_64bit == 0x7ff0000000000000ULL ) +#endif + { + is_infinite = 1; + } +#if defined( __BORLANDC__ ) && ( __BORLANDC__ < 0x0560 ) + else if( ( is_negative != 0 ) + && ( value_64bit == 0x7ff8000000000000UL ) ) +#else + else if( ( is_negative != 0 ) + && ( value_64bit == 0x7ff8000000000000ULL ) ) +#endif + { + is_indeterminate = 1; + } +#if defined( __BORLANDC__ ) && ( __BORLANDC__ < 0x0560 ) + else if( ( value_64bit >= 0x7ff0000000000001UL ) + && ( value_64bit <= 0x7fffffffffffffffUL ) ) +#else + else if( ( value_64bit >= 0x7ff0000000000001ULL ) + && ( value_64bit <= 0x7fffffffffffffffULL ) ) +#endif + { + is_not_a_number = 1; + } + else if( value_64bit != 0 ) + { + value_float64.integer = value_64bit; + value_float = (double) value_float64.floating_point; + + exponent2 = (int16_t) ( value_64bit >> 52 ); + + if( exponent2 == 0 ) + { + exponent2 = -1023; + } + else + { + exponent2 -= 1023; + } + } + if( is_indeterminate != 0 ) + { + /* "Ind" + end-of-string character */ + number_of_characters = 4; + } + else if( is_infinite != 0 ) + { + /* "Inf" + end-of-string character */ + number_of_characters = 4; + } + else if( is_not_a_number != 0 ) + { + /* "Nan" + end-of-string character */ + number_of_characters = 4; + } + else + { + /* "[-]0.000000e[+-]000" + end-of-string character */ + if( is_negative != 0 ) + { + number_of_characters = 15; + } + else + { + number_of_characters = 14; + } + } + if( ( number_of_characters > utf8_string_size ) + || ( safe_utf8_string_index > ( utf8_string_size - number_of_characters ) ) ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, + "%s: invalid UTF-8 string size value too small.", + function ); + + return( -1 ); + } + if( is_indeterminate != 0 ) + { + /* "Ind" + end-of-string character */ + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'I'; + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'n'; + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'd'; + } + else if( is_infinite != 0 ) + { + /* "Inf" + end-of-string character */ + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'I'; + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'n'; + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'f'; + } + else if( is_not_a_number != 0 ) + { + /* "Nan" + end-of-string character */ + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'N'; + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'a'; + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'N'; + } + else + { + /* "[-]0.000000e[+-]000" + end-of-string character */ + if( is_negative != 0 ) + { + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) '-'; + } + if( exponent2 < 0 ) + { + exponent_sign = (uint8_t) '-'; + exponent2 *= -1; + } + else + { + exponent_sign = (uint8_t) '+'; + } + exponent_value = 1.0; + exponent10 = 0; + + while( exponent2 > 0 ) + { + exponent_value *= 2; + exponent2--; + + if( exponent_value >= 10.0 ) + { + exponent_value /= 10.0; + exponent10++; + + if( exponent_sign == (uint8_t) '-' ) + { + value_float *= 10.0; + } + else + { + value_float /= 10.0; + } + } + } + if( value_float != 0.0 ) + { + while( ( value_float < 1.0 ) + || ( value_float >= 10.0 ) ) + { + exponent10++; + + if( exponent_sign == (uint8_t) '-' ) + { + value_float *= 10; + } + else + { + value_float /= 10; + } + } + } + for( digit_index = 0; + digit_index < 7; + digit_index++ ) + { + value_fraction *= 10; + value_fraction += (uint8_t) value_float; + + value_float -= (uint8_t) value_float; + value_float *= 10.0; + } + if( value_float >= 5.0 ) + { + value_fraction += 1; + } + divider = 1000000; + + for( digit_index = 0; + digit_index < 7; + digit_index++ ) + { + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) '0' + (uint8_t) ( value_fraction / divider ); + + if( digit_index == 0 ) + { + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) '.'; + } + value_fraction %= divider; + divider /= 10; + } + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'e'; + utf8_string[ safe_utf8_string_index++ ] = exponent_sign; + + divider = 100; + + for( digit_index = 0; + digit_index < 3; + digit_index++ ) + { + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) '0' + (uint8_t) ( exponent10 / divider ); + + exponent10 %= divider; + divider /= 10; + } + } + utf8_string[ safe_utf8_string_index++ ] = 0; + + *utf8_string_index = safe_utf8_string_index; + + return( 1 ); +} + +/* Copies a 64-bit floating point to an UTF-16 string + * The string size should include the end of string character + * Returns 1 if successful or -1 on error + */ +int libfwevt_float64_copy_to_utf16_string_with_index( + uint64_t value_64bit, + uint16_t *utf16_string, + size_t utf16_string_size, + size_t *utf16_string_index, + libcerror_error_t **error ) +{ + byte_stream_float64_t value_float64; + + static char *function = "libfwevt_float64_copy_to_utf16_string_with_index"; + size_t safe_utf16_string_index = 0; + uint64_t divider = 0; + uint64_t value_fraction = 0; + uint16_t exponent_sign = 0; + int16_t exponent10 = 0; + int16_t exponent2 = 0; + uint8_t digit_index = 0; + uint8_t is_indeterminate = 0; + uint8_t is_infinite = 0; + uint8_t is_not_a_number = 0; + uint8_t is_negative = 0; + uint8_t number_of_characters = 0; + double exponent_value = 0.0; + double value_float = 0.0; + + if( utf16_string == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-16 string.", + function ); + + return( -1 ); + } + if( utf16_string_size > (size_t) SSIZE_MAX ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, + "%s: invalid UTF-16 string size value exceeds maximum.", + function ); + + return( -1 ); + } + if( utf16_string_index == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-16 string index.", + function ); + + return( -1 ); + } + safe_utf16_string_index = *utf16_string_index; + + is_negative = (uint8_t) ( value_64bit >> 63 ); + + if( is_negative != 0 ) + { + value_64bit &= ~( (uint64_t) 1 << 63 ); + } +#if defined( __BORLANDC__ ) && ( __BORLANDC__ < 0x0560 ) + if( value_64bit == 0x7ff0000000000000UL ) +#else + if( value_64bit == 0x7ff0000000000000ULL ) +#endif + { + is_infinite = 1; + } +#if defined( __BORLANDC__ ) && ( __BORLANDC__ < 0x0560 ) + else if( ( is_negative != 0 ) + && ( value_64bit == 0x7ff8000000000000UL ) ) +#else + else if( ( is_negative != 0 ) + && ( value_64bit == 0x7ff8000000000000ULL ) ) +#endif + { + is_indeterminate = 1; + } +#if defined( __BORLANDC__ ) && ( __BORLANDC__ < 0x0560 ) + else if( ( value_64bit >= 0x7ff0000000000001UL ) + && ( value_64bit <= 0x7fffffffffffffffUL ) ) +#else + else if( ( value_64bit >= 0x7ff0000000000001ULL ) + && ( value_64bit <= 0x7fffffffffffffffULL ) ) +#endif + { + is_not_a_number = 1; + } + else if( value_64bit != 0 ) + { + value_float64.integer = value_64bit; + value_float = (double) value_float64.floating_point; + + exponent2 = (int16_t) ( value_64bit >> 52 ); + + if( exponent2 == 0 ) + { + exponent2 = -1023; + } + else + { + exponent2 -= 1023; + } + } + if( is_indeterminate != 0 ) + { + /* "Ind" + end-of-string character */ + number_of_characters = 4; + } + else if( is_infinite != 0 ) + { + /* "Inf" + end-of-string character */ + number_of_characters = 4; + } + else if( is_not_a_number != 0 ) + { + /* "Nan" + end-of-string character */ + number_of_characters = 4; + } + else + { + /* "[-]0.000000e[+-]000" + end-of-string character */ + if( is_negative != 0 ) + { + number_of_characters = 15; + } + else + { + number_of_characters = 14; + } + } + if( ( number_of_characters > utf16_string_size ) + || ( safe_utf16_string_index > ( utf16_string_size - number_of_characters ) ) ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, + "%s: invalid UTF-16 string size value too small.", + function ); + + return( -1 ); + } + if( is_indeterminate != 0 ) + { + /* "Ind" + end-of-string character */ + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'I'; + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'n'; + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'd'; + } + else if( is_infinite != 0 ) + { + /* "Inf" + end-of-string character */ + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'I'; + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'n'; + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'f'; + } + else if( is_not_a_number != 0 ) + { + /* "Nan" + end-of-string character */ + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'N'; + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'a'; + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'N'; + } + else + { + /* "[-]0.000000e[+-]000" + end-of-string character */ + if( is_negative != 0 ) + { + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) '-'; + } + if( exponent2 < 0 ) + { + exponent_sign = (uint16_t) '-'; + exponent2 *= -1; + } + else + { + exponent_sign = (uint16_t) '+'; + } + exponent_value = 1.0; + exponent10 = 0; + + while( exponent2 > 0 ) + { + exponent_value *= 2; + exponent2--; + + if( exponent_value >= 10.0 ) + { + exponent_value /= 10.0; + exponent10++; + + if( exponent_sign == (uint16_t) '-' ) + { + value_float *= 10.0; + } + else + { + value_float /= 10.0; + } + } + } + if( value_float != 0.0 ) + { + while( ( value_float < 1.0 ) + || ( value_float >= 10.0 ) ) + { + exponent10++; + + if( exponent_sign == (uint16_t) '-' ) + { + value_float *= 10; + } + else + { + value_float /= 10; + } + } + } + for( digit_index = 0; + digit_index < 7; + digit_index++ ) + { + value_fraction *= 10; + value_fraction += (uint8_t) value_float; + + value_float -= (uint8_t) value_float; + value_float *= 10.0; + } + if( value_float >= 5.0 ) + { + value_fraction += 1; + } + divider = 1000000; + + for( digit_index = 0; + digit_index < 7; + digit_index++ ) + { + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) '0' + (uint16_t) ( value_fraction / divider ); + + if( digit_index == 0 ) + { + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) '.'; + } + value_fraction %= divider; + divider /= 10; + } + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'e'; + utf16_string[ safe_utf16_string_index++ ] = exponent_sign; + + divider = 100; + + for( digit_index = 0; + digit_index < 3; + digit_index++ ) + { + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) '0' + (uint16_t) ( exponent10 / divider ); + + exponent10 %= divider; + divider /= 10; + } + } + utf16_string[ safe_utf16_string_index++ ] = 0; + + *utf16_string_index = safe_utf16_string_index; + + return( 1 ); +} + diff --git a/libfwevt/libfwevt_floating_point.h b/libfwevt/libfwevt_floating_point.h new file mode 100644 index 0000000..b6e5423 --- /dev/null +++ b/libfwevt/libfwevt_floating_point.h @@ -0,0 +1,77 @@ +/* + * Floating point (IEEE 754) functions + * + * Copyright (C) 2011-2024, Joachim Metz + * + * Refer to AUTHORS for acknowledgements. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#if !defined( _LIBFWEVT_FLOATING_POINT_H ) +#define _LIBFWEVT_FLOATING_POINT_H + +#include +#include + +#include "libfwevt_libcerror.h" + +#if defined( __cplusplus ) +extern "C" { +#endif + +int libfwevt_float32_get_string_size( + uint32_t value_32bit, + size_t *string_size, + libcerror_error_t **error ); + +int libfwevt_float32_copy_to_utf8_string_with_index( + uint32_t value_32bit, + uint8_t *utf8_string, + size_t utf8_string_size, + size_t *utf8_string_index, + libcerror_error_t **error ); + +int libfwevt_float32_copy_to_utf16_string_with_index( + uint32_t value_32bit, + uint16_t *utf16_string, + size_t utf16_string_size, + size_t *utf16_string_index, + libcerror_error_t **error ); + +int libfwevt_float64_get_string_size( + uint64_t value_64bit, + size_t *string_size, + libcerror_error_t **error ); + +int libfwevt_float64_copy_to_utf8_string_with_index( + uint64_t value_64bit, + uint8_t *utf8_string, + size_t utf8_string_size, + size_t *utf8_string_index, + libcerror_error_t **error ); + +int libfwevt_float64_copy_to_utf16_string_with_index( + uint64_t value_64bit, + uint16_t *utf16_string, + size_t utf16_string_size, + size_t *utf16_string_index, + libcerror_error_t **error ); + +#if defined( __cplusplus ) +} +#endif + +#endif /* !defined( _LIBFWEVT_FLOATING_POINT_H ) */ + diff --git a/libfwevt/libfwevt_integer.c b/libfwevt/libfwevt_integer.c new file mode 100644 index 0000000..4be6284 --- /dev/null +++ b/libfwevt/libfwevt_integer.c @@ -0,0 +1,843 @@ +/* + * Integer functions + * + * Copyright (C) 2011-2024, Joachim Metz + * + * Refer to AUTHORS for acknowledgements. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include +#include + +#include "libfwevt_integer.h" +#include "libfwevt_libcerror.h" + +/* Copies an integer from an UTF-16 stream + * Returns 1 if successful or -1 on error + */ +int libfwevt_integer_copy_from_utf16_stream( + uint64_t *integer_value, + const uint8_t *utf16_stream, + size_t utf16_stream_size, + libcerror_error_t **error ) +{ + static char *function = "libfwevt_integer_copy_from_utf16_stream"; + size_t utf16_stream_offset = 0; + uint64_t safe_integer_value = 0; + uint8_t digit = 0; + + if( integer_value == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid integer value.", + function ); + + return( -1 ); + } + if( utf16_stream == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-16 stream.", + function ); + + return( -1 ); + } + if( ( utf16_stream_size < 2 ) + || ( utf16_stream_size > 42 ) + || ( ( utf16_stream_size % 2 ) != 0 ) ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, + "%s: unsupported UTF-16 stream size.", + function ); + + return( -1 ); + } + for( utf16_stream_offset = 0; + utf16_stream_offset < utf16_stream_size; + utf16_stream_offset += 2 ) + { + if( utf16_stream[ utf16_stream_offset + 1 ] != 0 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, + "%s: invalid integer string.", + function ); + + return( -1 ); + } + digit = utf16_stream[ utf16_stream_offset ]; + + if( digit == 0 ) + { + break; + } + if( ( digit < (uint8_t) '0' ) + || ( digit > (uint8_t) '9' ) ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, + "%s: invalid integer string.", + function ); + + return( -1 ); + } + safe_integer_value *= 10; + safe_integer_value += digit - (uint8_t) '0'; + } + *integer_value = safe_integer_value; + + return( 1 ); +} + +/* Deterimes the size of the string of the integer as a signed decimal + * The string size includes the end of string character + * Returns 1 if successful or -1 on error + */ +int libfwevt_integer_as_signed_decimal_get_string_size( + uint64_t integer_value, + uint8_t integer_size, + size_t *string_size, + libcerror_error_t **error ) +{ + static char *function = "libfwevt_integer_as_signed_decimal_get_string_size"; + uint64_t divider = 0; + uint8_t is_negative = 0; + uint8_t number_of_characters = 0; + int8_t bit_shift = integer_size - 1; + + if( string_size == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid string size.", + function ); + + return( -1 ); + } + /* The string is at least a single digit with an end of string character + */ + number_of_characters = 2; + + is_negative = (uint8_t) ( integer_value >> bit_shift ); + + if( is_negative != 0 ) + { + number_of_characters += 1; + + integer_value &= ~( (uint64_t) 1 << bit_shift ); + + if( integer_value == 0 ) + { + integer_value |= (uint64_t) 1 << bit_shift; + } + } + divider = 1; + + while( ( integer_value / divider ) >= 10 ) + { + divider *= 10; + + number_of_characters += 1; + } + *string_size = number_of_characters; + + return( 1 ); +} + +/* Copies an integer as an unsigned decimal to an UTF-8 string + * The string size should include the end of string character + * Returns 1 if successful or -1 on error + */ +int libfwevt_integer_as_signed_decimal_copy_to_utf8_string_with_index( + uint64_t integer_value, + uint8_t integer_size, + uint8_t *utf8_string, + size_t utf8_string_size, + size_t *utf8_string_index, + libcerror_error_t **error ) +{ + static char *function = "libfwevt_integer_as_signed_decimal_copy_to_utf8_string_with_index"; + size_t safe_utf8_string_index = 0; + uint64_t divider = 0; + uint8_t is_negative = 0; + uint8_t number_of_characters = 0; + int8_t bit_shift = integer_size - 1; + + if( utf8_string == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-8 string.", + function ); + + return( -1 ); + } + if( utf8_string_size > (size_t) SSIZE_MAX ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, + "%s: invalid UTF-8 string size value exceeds maximum.", + function ); + + return( -1 ); + } + if( utf8_string_index == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-8 string index.", + function ); + + return( -1 ); + } + safe_utf8_string_index = *utf8_string_index; + + /* The string is at least a single digit with an end of string character + */ + number_of_characters = 2; + + is_negative = (uint8_t) ( integer_value >> bit_shift ); + + if( is_negative != 0 ) + { + number_of_characters += 1; + + integer_value &= ~( (uint64_t) 1 << bit_shift ); + + if( integer_value == 0 ) + { + integer_value |= (uint64_t) 1 << bit_shift; + } + } + divider = 1; + + while( ( integer_value / divider ) >= 10 ) + { + divider *= 10; + + number_of_characters += 1; + } + if( ( number_of_characters > utf8_string_size ) + || ( safe_utf8_string_index > ( utf8_string_size - number_of_characters ) ) ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, + "%s: invalid UTF-8 string size value too small.", + function ); + + return( -1 ); + } + if( is_negative != 0 ) + { + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) '-'; + } + while( divider > 1 ) + { + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) '0' + (uint8_t) ( integer_value / divider ); + + integer_value %= divider; + + divider /= 10; + } + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) '0' + (uint8_t) ( integer_value / divider ); + utf8_string[ safe_utf8_string_index++ ] = 0; + + *utf8_string_index = safe_utf8_string_index; + + return( 1 ); +} + +/* Copies an integer as an unsigned decimal to an UTF-16 string + * The string size should include the end of string character + * Returns 1 if successful or -1 on error + */ +int libfwevt_integer_as_signed_decimal_copy_to_utf16_string_with_index( + uint64_t integer_value, + uint8_t integer_size, + uint16_t *utf16_string, + size_t utf16_string_size, + size_t *utf16_string_index, + libcerror_error_t **error ) +{ + static char *function = "libfwevt_integer_as_signed_decimal_copy_to_utf16_string_with_index"; + size_t safe_utf16_string_index = 0; + uint64_t divider = 0; + uint8_t is_negative = 0; + uint8_t number_of_characters = 0; + int8_t bit_shift = integer_size - 1; + + if( utf16_string == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-16 string.", + function ); + + return( -1 ); + } + if( utf16_string_size > (size_t) SSIZE_MAX ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, + "%s: invalid UTF-16 string size value exceeds maximum.", + function ); + + return( -1 ); + } + if( utf16_string_index == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-16 string index.", + function ); + + return( -1 ); + } + safe_utf16_string_index = *utf16_string_index; + + /* The string is at least a single digit with an end of string character + */ + number_of_characters = 2; + + is_negative = (uint8_t) ( integer_value >> bit_shift ); + + if( is_negative != 0 ) + { + number_of_characters += 1; + + integer_value &= ~( (uint64_t) 1 << bit_shift ); + + if( integer_value == 0 ) + { + integer_value |= (uint64_t) 1 << bit_shift; + } + } + divider = 1; + + while( ( integer_value / divider ) >= 10 ) + { + divider *= 10; + + number_of_characters += 1; + } + if( ( number_of_characters > utf16_string_size ) + || ( safe_utf16_string_index > ( utf16_string_size - number_of_characters ) ) ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, + "%s: invalid UTF-16 string size value too small.", + function ); + + return( -1 ); + } + if( is_negative != 0 ) + { + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) '-'; + } + while( divider > 1 ) + { + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) '0' + (uint16_t) ( integer_value / divider ); + + integer_value %= divider; + + divider /= 10; + } + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) '0' + (uint16_t) ( integer_value / divider ); + utf16_string[ safe_utf16_string_index++ ] = 0; + + *utf16_string_index = safe_utf16_string_index; + + return( 1 ); +} + +/* Deterimes the size of the string of the integer as an unsigned decimal + * The string size includes the end of string character + * Returns 1 if successful or -1 on error + */ +int libfwevt_integer_as_unsigned_decimal_get_string_size( + uint64_t integer_value, + size_t *string_size, + libcerror_error_t **error ) +{ + static char *function = "libfwevt_integer_as_decimal_get_string_size"; + uint64_t divider = 0; + uint8_t number_of_characters = 0; + + if( string_size == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid string size.", + function ); + + return( -1 ); + } + /* The string is at least a single digit with an end of string character + */ + number_of_characters = 2; + + divider = 1; + + while( ( integer_value / divider ) >= 10 ) + { + divider *= 10; + + number_of_characters += 1; + } + *string_size = number_of_characters; + + return( 1 ); +} + +/* Copies an integer as an unsigned decimal to an UTF-8 string + * The string size should include the end of string character + * Returns 1 if successful or -1 on error + */ +int libfwevt_integer_as_unsigned_decimal_copy_to_utf8_string_with_index( + uint64_t integer_value, + uint8_t *utf8_string, + size_t utf8_string_size, + size_t *utf8_string_index, + libcerror_error_t **error ) +{ + static char *function = "libfwevt_integer_as_unsigned_decimal_copy_to_utf8_string_with_index"; + size_t safe_utf8_string_index = 0; + uint64_t divider = 0; + uint8_t number_of_characters = 0; + + if( utf8_string == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-8 string.", + function ); + + return( -1 ); + } + if( utf8_string_size > (size_t) SSIZE_MAX ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, + "%s: invalid UTF-8 string size value exceeds maximum.", + function ); + + return( -1 ); + } + if( utf8_string_index == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-8 string index.", + function ); + + return( -1 ); + } + safe_utf8_string_index = *utf8_string_index; + + /* The string is at least a single digit with an end of string character + */ + number_of_characters = 2; + + divider = 1; + + while( ( integer_value / divider ) >= 10 ) + { + divider *= 10; + + number_of_characters += 1; + } + if( ( number_of_characters > utf8_string_size ) + || ( safe_utf8_string_index > ( utf8_string_size - number_of_characters ) ) ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, + "%s: invalid UTF-8 string size value too small.", + function ); + + return( -1 ); + } + while( divider > 1 ) + { + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) '0' + (uint8_t) ( integer_value / divider ); + + integer_value %= divider; + + divider /= 10; + } + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) '0' + (uint8_t) ( integer_value / divider ); + utf8_string[ safe_utf8_string_index++ ] = 0; + + *utf8_string_index = safe_utf8_string_index; + + return( 1 ); +} + +/* Copies an integer as an unsigned decimal to an UTF-16 string + * The string size should include the end of string character + * Returns 1 if successful or -1 on error + */ +int libfwevt_integer_as_unsigned_decimal_copy_to_utf16_string_with_index( + uint64_t integer_value, + uint16_t *utf16_string, + size_t utf16_string_size, + size_t *utf16_string_index, + libcerror_error_t **error ) +{ + static char *function = "libfwevt_integer_as_unsigned_decimal_copy_to_utf16_string_with_index"; + size_t safe_utf16_string_index = 0; + uint64_t divider = 0; + uint8_t number_of_characters = 0; + + if( utf16_string == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-16 string.", + function ); + + return( -1 ); + } + if( utf16_string_size > (size_t) SSIZE_MAX ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, + "%s: invalid UTF-16 string size value exceeds maximum.", + function ); + + return( -1 ); + } + if( utf16_string_index == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-16 string index.", + function ); + + return( -1 ); + } + safe_utf16_string_index = *utf16_string_index; + + /* The string is at least a single digit with an end of string character + */ + number_of_characters = 2; + + divider = 1; + + while( ( integer_value / divider ) >= 10 ) + { + divider *= 10; + + number_of_characters += 1; + } + if( ( number_of_characters > utf16_string_size ) + || ( safe_utf16_string_index > ( utf16_string_size - number_of_characters ) ) ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, + "%s: invalid UTF-16 string size value too small.", + function ); + + return( -1 ); + } + while( divider > 1 ) + { + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) '0' + (uint16_t) ( integer_value / divider ); + + integer_value %= divider; + + divider /= 10; + } + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) '0' + (uint16_t) ( integer_value / divider ); + utf16_string[ safe_utf16_string_index++ ] = 0; + + *utf16_string_index = safe_utf16_string_index; + + return( 1 ); +} + +/* Copies an integer as hexadecimal to an UTF-8 string + * The string size should include the end of string character + * Returns 1 if successful or -1 on error + */ +int libfwevt_integer_as_hexadecimal_copy_to_utf8_string_with_index( + uint64_t integer_value, + uint8_t integer_size, + uint8_t *utf8_string, + size_t utf8_string_size, + size_t *utf8_string_index, + libcerror_error_t **error ) +{ + static char *function = "libfwevt_integer_as_hexadecimal_copy_to_utf8_string_with_index"; + size_t safe_utf8_string_index = 0; + uint8_t number_of_characters = 0; + uint8_t byte_value = 0; + int8_t bit_shift = 0; + + if( integer_size == 32 ) + { + number_of_characters = 11; + } + else if( integer_size == 64 ) + { + number_of_characters = 19; + } + else + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, + "%s: unsupported integer size.", + function ); + + return( -1 ); + } + if( utf8_string == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-8 string.", + function ); + + return( -1 ); + } + if( utf8_string_size > (size_t) SSIZE_MAX ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, + "%s: invalid UTF-8 string size value exceeds maximum.", + function ); + + return( -1 ); + } + if( utf8_string_index == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-8 string index.", + function ); + + return( -1 ); + } + safe_utf8_string_index = *utf8_string_index; + + if( ( number_of_characters > utf8_string_size ) + || ( safe_utf8_string_index > ( utf8_string_size - number_of_characters ) ) ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, + "%s: invalid UTF-8 string size value too small.", + function ); + + return( -1 ); + } + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) '0'; + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'x'; + + bit_shift = (uint8_t) ( integer_size - 4 ); + + do + { + byte_value = (uint8_t) ( ( integer_value >> bit_shift ) & 0x0f ); + + if( byte_value <= 9 ) + { + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) '0' + byte_value; + } + else + { + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'a' + byte_value - 10; + } + bit_shift -= 4; + } + while( bit_shift >= 0 ); + + utf8_string[ safe_utf8_string_index++ ] = 0; + + *utf8_string_index = safe_utf8_string_index; + + return( 1 ); +} + +/* Copies an integer as hexadecimal to an UTF-16 string + * The string size should include the end of string character + * Returns 1 if successful or -1 on error + */ +int libfwevt_integer_as_hexadecimal_copy_to_utf16_string_with_index( + uint64_t integer_value, + uint8_t integer_size, + uint16_t *utf16_string, + size_t utf16_string_size, + size_t *utf16_string_index, + libcerror_error_t **error ) +{ + static char *function = "libfwevt_integer_as_hexadecimal_copy_to_utf16_string_with_index"; + size_t safe_utf16_string_index = 0; + uint8_t number_of_characters = 0; + uint8_t byte_value = 0; + int8_t bit_shift = 0; + + if( integer_size == 32 ) + { + number_of_characters = 11; + } + else if( integer_size == 64 ) + { + number_of_characters = 19; + } + else + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, + "%s: unsupported integer size.", + function ); + + return( -1 ); + } + if( utf16_string == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-16 string.", + function ); + + return( -1 ); + } + if( utf16_string_size > (size_t) SSIZE_MAX ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, + "%s: invalid UTF-16 string size value exceeds maximum.", + function ); + + return( -1 ); + } + if( utf16_string_index == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-16 string index.", + function ); + + return( -1 ); + } + safe_utf16_string_index = *utf16_string_index; + + if( ( number_of_characters > utf16_string_size ) + || ( safe_utf16_string_index > ( utf16_string_size - number_of_characters ) ) ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, + "%s: invalid UTF-16 string size value too small.", + function ); + + return( -1 ); + } + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) '0'; + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'x'; + + bit_shift = (uint16_t) ( integer_size - 4 ); + + do + { + byte_value = (uint16_t) ( ( integer_value >> bit_shift ) & 0x0f ); + + if( byte_value <= 9 ) + { + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) '0' + byte_value; + } + else + { + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'a' + byte_value - 10; + } + bit_shift -= 4; + } + while( bit_shift >= 0 ); + + utf16_string[ safe_utf16_string_index++ ] = 0; + + *utf16_string_index = safe_utf16_string_index; + + return( 1 ); +} + diff --git a/libfwevt/libfwevt_integer.h b/libfwevt/libfwevt_integer.h new file mode 100644 index 0000000..904e559 --- /dev/null +++ b/libfwevt/libfwevt_integer.h @@ -0,0 +1,102 @@ +/* + * Integer functions + * + * Copyright (C) 2011-2024, Joachim Metz + * + * Refer to AUTHORS for acknowledgements. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#if !defined( _LIBFWEVT_INTEGER_H ) +#define _LIBFWEVT_INTEGER_H + +#include +#include + +#include "libfwevt_libcerror.h" + +#if defined( __cplusplus ) +extern "C" { +#endif + +int libfwevt_integer_copy_from_utf16_stream( + uint64_t *integer_value, + const uint8_t *utf16_stream, + size_t utf16_stream_size, + libcerror_error_t **error ); + +int libfwevt_integer_as_signed_decimal_get_string_size( + uint64_t integer_value, + uint8_t integer_size, + size_t *string_size, + libcerror_error_t **error ); + +int libfwevt_integer_as_signed_decimal_copy_to_utf8_string_with_index( + uint64_t integer_value, + uint8_t integer_size, + uint8_t *utf8_string, + size_t utf8_string_size, + size_t *utf8_string_index, + libcerror_error_t **error ); + +int libfwevt_integer_as_signed_decimal_copy_to_utf16_string_with_index( + uint64_t integer_value, + uint8_t integer_size, + uint16_t *utf16_string, + size_t utf16_string_size, + size_t *utf16_string_index, + libcerror_error_t **error ); + +int libfwevt_integer_as_unsigned_decimal_get_string_size( + uint64_t integer_value, + size_t *string_size, + libcerror_error_t **error ); + +int libfwevt_integer_as_unsigned_decimal_copy_to_utf8_string_with_index( + uint64_t integer_value, + uint8_t *utf8_string, + size_t utf8_string_size, + size_t *utf8_string_index, + libcerror_error_t **error ); + +int libfwevt_integer_as_unsigned_decimal_copy_to_utf16_string_with_index( + uint64_t integer_value, + uint16_t *utf16_string, + size_t utf16_string_size, + size_t *utf16_string_index, + libcerror_error_t **error ); + +int libfwevt_integer_as_hexadecimal_copy_to_utf8_string_with_index( + uint64_t integer_value, + uint8_t integer_size, + uint8_t *utf8_string, + size_t utf8_string_size, + size_t *utf8_string_index, + libcerror_error_t **error ); + +int libfwevt_integer_as_hexadecimal_copy_to_utf16_string_with_index( + uint64_t integer_value, + uint8_t integer_size, + uint16_t *utf16_string, + size_t utf16_string_size, + size_t *utf16_string_index, + libcerror_error_t **error ); + +#if defined( __cplusplus ) +} +#endif + +#endif /* !defined( _LIBFWEVT_INTEGER_H ) */ + diff --git a/libfwevt/libfwevt_libfdatetime.h b/libfwevt/libfwevt_libfdatetime.h new file mode 100644 index 0000000..c6dea7f --- /dev/null +++ b/libfwevt/libfwevt_libfdatetime.h @@ -0,0 +1,56 @@ +/* + * The libfdatetime header wrapper + * + * Copyright (C) 2011-2024, Joachim Metz + * + * Refer to AUTHORS for acknowledgements. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#if !defined( _LIBFWEVT_LIBFDATETIME_H ) +#define _LIBFWEVT_LIBFDATETIME_H + +#include + +/* Define HAVE_LOCAL_LIBFDATETIME for local use of libfdatetime + */ +#if defined( HAVE_LOCAL_LIBFDATETIME ) + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#else + +/* If libtool DLL support is enabled set LIBFDATETIME_DLL_IMPORT + * before including libfdatetime.h + */ +#if defined( _WIN32 ) && defined( DLL_IMPORT ) +#define LIBFDATETIME_DLL_IMPORT +#endif + +#include + +#endif /* defined( HAVE_LOCAL_LIBFDATETIME ) */ + +#endif /* !defined( _LIBFWEVT_LIBFDATETIME_H ) */ + diff --git a/libfwevt/libfwevt_libfvalue.h b/libfwevt/libfwevt_libfvalue.h deleted file mode 100644 index 9ad4b4e..0000000 --- a/libfwevt/libfwevt_libfvalue.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * The libfvalue header wrapper - * - * Copyright (C) 2011-2024, Joachim Metz - * - * Refer to AUTHORS for acknowledgements. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -#if !defined( _LIBFWEVT_LIBFVALUE_H ) -#define _LIBFWEVT_LIBFVALUE_H - -#include - -/* Define HAVE_LOCAL_LIBFVALUE for local use of libfvalue - */ -#if defined( HAVE_LOCAL_LIBFVALUE ) - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#else - -/* If libtool DLL support is enabled set LIBFVALUE_DLL_IMPORT - * before including libfvalue.h - */ -#if defined( _WIN32 ) && defined( DLL_IMPORT ) -#define LIBFVALUE_DLL_IMPORT -#endif - -#include - -#endif /* defined( HAVE_LOCAL_LIBFVALUE ) */ - -#endif /* !defined( _LIBFWEVT_LIBFVALUE_H ) */ - diff --git a/libfwevt/libfwevt_libfwnt.h b/libfwevt/libfwevt_libfwnt.h new file mode 100644 index 0000000..fedfcc8 --- /dev/null +++ b/libfwevt/libfwevt_libfwnt.h @@ -0,0 +1,58 @@ +/* + * The libfwnt header wrapper + * + * Copyright (C) 2011-2024, Joachim Metz + * + * Refer to AUTHORS for acknowledgements. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#if !defined( _LIBFWEVTF_LIBFWNT_H ) +#define _LIBFWEVTF_LIBFWNT_H + +#include + +/* Define HAVE_LOCAL_LIBFWNT for local use of libfwnt + */ +#if defined( HAVE_LOCAL_LIBFWNT ) + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#else + +/* If libtool DLL support is enabled set LIBFWNT_DLL_IMPORT + * before including libfwnt.h + */ +#if defined( _WIN32 ) && defined( DLL_IMPORT ) +#define LIBFWNT_DLL_IMPORT +#endif + +#include + +#endif /* defined( HAVE_LOCAL_LIBFWNT ) */ + +#endif /* !defined( _LIBFWEVTF_LIBFWNT_H ) */ + diff --git a/libfwevt/libfwevt_xml_document.c b/libfwevt/libfwevt_xml_document.c index 22fac58..e052a19 100644 --- a/libfwevt/libfwevt_xml_document.c +++ b/libfwevt/libfwevt_xml_document.c @@ -27,11 +27,11 @@ #include "libfwevt_debug.h" #include "libfwevt_definitions.h" +#include "libfwevt_integer.h" #include "libfwevt_libcdata.h" #include "libfwevt_libcerror.h" #include "libfwevt_libcnotify.h" #include "libfwevt_libfguid.h" -#include "libfwevt_libfvalue.h" #include "libfwevt_types.h" #include "libfwevt_xml_document.h" #include "libfwevt_xml_template_value.h" @@ -1162,7 +1162,7 @@ int libfwevt_xml_document_read_cdata_section( #endif if( libfwevt_xml_tag_set_value_type( xml_tag, - LIBFVALUE_VALUE_TYPE_STRING_UTF16, + LIBFWEVT_VALUE_TYPE_STRING_UTF16, error ) != 1 ) { libcerror_error_set( @@ -1178,7 +1178,6 @@ int libfwevt_xml_document_read_cdata_section( xml_tag, &( binary_data[ binary_data_offset ] ), value_data_size, - LIBFVALUE_CODEPAGE_UTF16_LITTLE_ENDIAN, error ) != 1 ) { libcerror_error_set( @@ -1371,11 +1370,9 @@ int libfwevt_xml_document_read_character_reference( #endif xml_token->size = 3; - if( libfvalue_string_size_from_integer( - &character_value_string_size, + if( libfwevt_integer_as_unsigned_decimal_get_string_size( (uint64_t) character_value, - 16, - 0, + &character_value_string_size, error ) != 1 ) { libcerror_error_set( @@ -1417,13 +1414,11 @@ int libfwevt_xml_document_read_character_reference( character_value_string[ character_value_string_index++ ] = (uint16_t) '&'; character_value_string[ character_value_string_index++ ] = (uint16_t) '#'; - if( libfvalue_utf16_string_with_index_copy_from_integer( + if( libfwevt_integer_as_unsigned_decimal_copy_to_utf16_string_with_index( + (uint64_t) character_value, character_value_string, character_value_string_size, &character_value_string_index, - (uint64_t) character_value, - 16, - 0, error ) != 1 ) { libcerror_error_set( @@ -1440,7 +1435,7 @@ int libfwevt_xml_document_read_character_reference( if( libfwevt_xml_tag_set_value_type( xml_tag, - LIBFVALUE_VALUE_TYPE_STRING_UTF16, + LIBFWEVT_VALUE_TYPE_STRING_UTF16, error ) != 1 ) { libcerror_error_set( @@ -1501,7 +1496,6 @@ int libfwevt_xml_document_read_character_reference( xml_tag, character_value_utf16_stream, character_value_utf16_stream_size, - LIBFVALUE_CODEPAGE_UTF16_LITTLE_ENDIAN, &value_entry_index, error ) != 1 ) { @@ -2871,7 +2865,7 @@ int libfwevt_xml_document_read_entity_reference( } if( libfwevt_xml_tag_set_value_type( xml_tag, - LIBFVALUE_VALUE_TYPE_STRING_UTF16, + LIBFWEVT_VALUE_TYPE_STRING_UTF16, error ) != 1 ) { libcerror_error_set( @@ -2977,7 +2971,6 @@ int libfwevt_xml_document_read_entity_reference( xml_tag, entity_value_utf16_stream, 4, - LIBFVALUE_CODEPAGE_UTF16_LITTLE_ENDIAN, &value_entry_index, error ) != 1 ) { @@ -4183,7 +4176,7 @@ int libfwevt_xml_document_read_pi_data( #endif if( libfwevt_xml_tag_set_value_type( xml_tag, - LIBFVALUE_VALUE_TYPE_STRING_UTF16, + LIBFWEVT_VALUE_TYPE_STRING_UTF16, error ) != 1 ) { libcerror_error_set( @@ -4199,7 +4192,6 @@ int libfwevt_xml_document_read_pi_data( xml_tag, &( binary_data[ binary_data_offset ] ), value_data_size, - LIBFVALUE_CODEPAGE_UTF16_LITTLE_ENDIAN, error ) != 1 ) { libcerror_error_set( @@ -5561,10 +5553,8 @@ int libfwevt_xml_document_read_value( static char *function = "libfwevt_xml_document_read_value"; size_t value_data_size = 0; size_t xml_document_data_size = 0; - uint8_t xml_value_type = 0; - int value_encoding = 0; + uint8_t value_type = 0; int value_entry_index = 0; - int value_type = 0; if( internal_xml_document == NULL ) { @@ -5675,7 +5665,7 @@ int libfwevt_xml_document_read_value( 0 ); } #endif - xml_value_type = xml_document_data[ 1 ]; + value_type = xml_document_data[ 1 ]; #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) @@ -5688,9 +5678,9 @@ int libfwevt_xml_document_read_value( libcnotify_printf( "%s: value type\t\t\t\t: 0x%02" PRIx8 " (", function, - xml_value_type ); + value_type ); libfwevt_debug_print_value_type( - xml_value_type ); + value_type ); libcnotify_printf( ")\n" ); } @@ -5698,7 +5688,7 @@ int libfwevt_xml_document_read_value( xml_token->size = 4; binary_data_offset += 4; - switch( xml_value_type ) + switch( value_type ) { case LIBFWEVT_VALUE_TYPE_STRING_UTF16: byte_stream_copy_to_uint16_little_endian( @@ -5716,9 +5706,6 @@ int libfwevt_xml_document_read_value( #endif value_data_size *= 2; - value_encoding = LIBFVALUE_CODEPAGE_UTF16_LITTLE_ENDIAN; - value_type = LIBFVALUE_VALUE_TYPE_STRING_UTF16; - break; default: @@ -5779,7 +5766,6 @@ int libfwevt_xml_document_read_value( xml_tag, &( binary_data[ binary_data_offset ] ), value_data_size, - value_encoding, &value_entry_index, error ) != 1 ) { @@ -5841,15 +5827,12 @@ int libfwevt_xml_document_substitute_template_value( static char *function = "libfwevt_xml_document_substitute_template_value"; size_t binary_data_offset = 0; size_t safe_template_value_offset = 0; + size_t template_value_data_offset = 0; size_t template_value_data_size = 0; size_t template_value_size = 0; - ssize_t read_count = 0; - uint32_t value_format_flags = 0; uint16_t substitution_value_data_size = 0; uint8_t substitution_value_type = 0; uint8_t template_value_flags = 0; - int value_encoding = 0; - int value_type = 0; if( internal_xml_document == NULL ) { @@ -6176,147 +6159,88 @@ int libfwevt_xml_document_substitute_template_value( { case LIBFWEVT_VALUE_TYPE_STRING_UTF16: case LIBFWEVT_VALUE_TYPE_ARRAY_OF_STRING_UTF16: - value_encoding = LIBFVALUE_CODEPAGE_UTF16_LITTLE_ENDIAN; - value_type = LIBFVALUE_VALUE_TYPE_STRING_UTF16; break; case LIBFWEVT_VALUE_TYPE_STRING_BYTE_STREAM: case LIBFWEVT_VALUE_TYPE_ARRAY_OF_STRING_BYTE_STREAM: - value_encoding = ascii_codepage; - value_type = LIBFVALUE_VALUE_TYPE_STRING_BYTE_STREAM; break; case LIBFWEVT_VALUE_TYPE_INTEGER_8BIT: case LIBFWEVT_VALUE_TYPE_ARRAY_OF_INTEGER_8BIT: template_value_size = 1; - value_encoding = LIBFVALUE_ENDIAN_LITTLE; - value_format_flags = LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_SIGNED; - value_type = LIBFVALUE_VALUE_TYPE_INTEGER_8BIT; break; case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_8BIT: case LIBFWEVT_VALUE_TYPE_ARRAY_OF_UNSIGNED_INTEGER_8BIT: template_value_size = 1; - value_encoding = LIBFVALUE_ENDIAN_LITTLE; - value_format_flags = LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED; - value_type = LIBFVALUE_VALUE_TYPE_UNSIGNED_INTEGER_8BIT; break; case LIBFWEVT_VALUE_TYPE_INTEGER_16BIT: case LIBFWEVT_VALUE_TYPE_ARRAY_OF_INTEGER_16BIT: template_value_size = 2; - value_encoding = LIBFVALUE_ENDIAN_LITTLE; - value_format_flags = LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_SIGNED; - value_type = LIBFVALUE_VALUE_TYPE_INTEGER_16BIT; break; case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_16BIT: case LIBFWEVT_VALUE_TYPE_ARRAY_OF_UNSIGNED_INTEGER_16BIT: template_value_size = 2; - value_encoding = LIBFVALUE_ENDIAN_LITTLE; - value_format_flags = LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED; - value_type = LIBFVALUE_VALUE_TYPE_UNSIGNED_INTEGER_16BIT; break; case LIBFWEVT_VALUE_TYPE_INTEGER_32BIT: case LIBFWEVT_VALUE_TYPE_ARRAY_OF_INTEGER_32BIT: template_value_size = 4; - value_encoding = LIBFVALUE_ENDIAN_LITTLE; - value_format_flags = LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_SIGNED; - value_type = LIBFVALUE_VALUE_TYPE_INTEGER_32BIT; break; case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_32BIT: case LIBFWEVT_VALUE_TYPE_ARRAY_OF_UNSIGNED_INTEGER_32BIT: template_value_size = 4; - value_encoding = LIBFVALUE_ENDIAN_LITTLE; - value_format_flags = LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED; - value_type = LIBFVALUE_VALUE_TYPE_UNSIGNED_INTEGER_32BIT; break; case LIBFWEVT_VALUE_TYPE_HEXADECIMAL_INTEGER_32BIT: case LIBFWEVT_VALUE_TYPE_ARRAY_OF_HEXADECIMAL_INTEGER_32BIT: template_value_size = 4; - value_encoding = LIBFVALUE_ENDIAN_LITTLE; - value_format_flags = LIBFVALUE_INTEGER_FORMAT_TYPE_HEXADECIMAL; - value_type = LIBFVALUE_VALUE_TYPE_UNSIGNED_INTEGER_32BIT; break; case LIBFWEVT_VALUE_TYPE_INTEGER_64BIT: case LIBFWEVT_VALUE_TYPE_ARRAY_OF_INTEGER_64BIT: template_value_size = 8; - value_encoding = LIBFVALUE_ENDIAN_LITTLE; - value_format_flags = LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_SIGNED; - value_type = LIBFVALUE_VALUE_TYPE_INTEGER_64BIT; break; case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_64BIT: case LIBFWEVT_VALUE_TYPE_ARRAY_OF_UNSIGNED_INTEGER_64BIT: template_value_size = 8; - value_encoding = LIBFVALUE_ENDIAN_LITTLE; - value_format_flags = LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED; - value_type = LIBFVALUE_VALUE_TYPE_UNSIGNED_INTEGER_64BIT; break; case LIBFWEVT_VALUE_TYPE_HEXADECIMAL_INTEGER_64BIT: case LIBFWEVT_VALUE_TYPE_ARRAY_OF_HEXADECIMAL_INTEGER_64BIT: template_value_size = 8; - value_encoding = LIBFVALUE_ENDIAN_LITTLE; - value_format_flags = LIBFVALUE_INTEGER_FORMAT_TYPE_HEXADECIMAL; - value_type = LIBFVALUE_VALUE_TYPE_UNSIGNED_INTEGER_64BIT; break; case LIBFWEVT_VALUE_TYPE_FLOATING_POINT_32BIT: case LIBFWEVT_VALUE_TYPE_ARRAY_OF_FLOATING_POINT_32BIT: template_value_size = 4; - value_encoding = LIBFVALUE_ENDIAN_LITTLE; - value_format_flags = LIBFVALUE_FLOATING_POINT_FORMAT_TYPE_DECIMAL; - value_type = LIBFVALUE_VALUE_TYPE_FLOATING_POINT_32BIT; break; case LIBFWEVT_VALUE_TYPE_FLOATING_POINT_64BIT: case LIBFWEVT_VALUE_TYPE_ARRAY_OF_FLOATING_POINT_64BIT: template_value_size = 8; - value_encoding = LIBFVALUE_ENDIAN_LITTLE; - value_format_flags = LIBFVALUE_FLOATING_POINT_FORMAT_TYPE_DECIMAL; - value_type = LIBFVALUE_VALUE_TYPE_FLOATING_POINT_64BIT; break; case LIBFWEVT_VALUE_TYPE_BOOLEAN: template_value_size = 4; - value_encoding = LIBFVALUE_ENDIAN_LITTLE; - value_format_flags = LIBFVALUE_INTEGER_FORMAT_TYPE_BOOLEAN; - value_type = LIBFVALUE_VALUE_TYPE_BOOLEAN; break; case LIBFWEVT_VALUE_TYPE_BINARY_DATA: - value_format_flags = LIBFVALUE_BINARY_DATA_FORMAT_TYPE_BASE16 - | LIBFVALUE_BINARY_DATA_FORMAT_FLAG_CASE_UPPER; - value_type = LIBFVALUE_VALUE_TYPE_BINARY_DATA; break; case LIBFWEVT_VALUE_TYPE_GUID: case LIBFWEVT_VALUE_TYPE_ARRAY_OF_GUID: template_value_size = 16; - value_encoding = LIBFVALUE_ENDIAN_LITTLE; - value_format_flags = LIBFVALUE_GUID_FORMAT_FLAG_USE_UPPER_CASE | LIBFVALUE_GUID_FORMAT_FLAG_USE_SURROUNDING_BRACES; - value_type = LIBFVALUE_VALUE_TYPE_GUID; break; /* TODO how to deal with array types ? */ case LIBFWEVT_VALUE_TYPE_SIZE: - value_encoding = LIBFVALUE_ENDIAN_LITTLE; - value_format_flags = LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED; - - if( substitution_value_data_size == 4 ) - { - value_type = LIBFVALUE_VALUE_TYPE_UNSIGNED_INTEGER_32BIT; - } - else if( substitution_value_data_size == 8 ) - { - value_type = LIBFVALUE_VALUE_TYPE_UNSIGNED_INTEGER_64BIT; - } - else + if( ( substitution_value_data_size != 4 ) + && ( substitution_value_data_size != 8 ) ) { libcerror_error_set( error, @@ -6333,22 +6257,14 @@ int libfwevt_xml_document_substitute_template_value( case LIBFWEVT_VALUE_TYPE_FILETIME: case LIBFWEVT_VALUE_TYPE_ARRAY_OF_FILETIME: template_value_size = 8; - value_encoding = LIBFVALUE_ENDIAN_LITTLE; - value_format_flags = (uint32_t) ( LIBFVALUE_DATE_TIME_FORMAT_TYPE_ISO8601 | LIBFVALUE_DATE_TIME_FORMAT_FLAG_DATE_TIME_NANO_SECONDS | LIBFVALUE_DATE_TIME_FORMAT_FLAG_TIMEZONE_INDICATOR ); - value_type = LIBFVALUE_VALUE_TYPE_FILETIME; break; case LIBFWEVT_VALUE_TYPE_SYSTEMTIME: case LIBFWEVT_VALUE_TYPE_ARRAY_OF_SYSTEMTIME: template_value_size = 16; - value_encoding = LIBFVALUE_ENDIAN_LITTLE; - value_format_flags = (uint32_t) ( LIBFVALUE_DATE_TIME_FORMAT_TYPE_ISO8601 | LIBFVALUE_DATE_TIME_FORMAT_FLAG_DATE_TIME_MILLI_SECONDS | LIBFVALUE_DATE_TIME_FORMAT_FLAG_TIMEZONE_INDICATOR ); - value_type = LIBFVALUE_VALUE_TYPE_SYSTEMTIME; break; case LIBFWEVT_VALUE_TYPE_NT_SECURITY_IDENTIFIER: - value_encoding = LIBFVALUE_ENDIAN_LITTLE; - value_type = LIBFVALUE_VALUE_TYPE_NT_SECURITY_IDENTIFIER; break; default: @@ -6364,7 +6280,7 @@ int libfwevt_xml_document_substitute_template_value( } if( libfwevt_xml_tag_set_value_type( xml_tag, - value_type, + substitution_value_type, error ) != 1 ) { libcerror_error_set( @@ -6376,23 +6292,6 @@ int libfwevt_xml_document_substitute_template_value( goto on_error; } - if( value_format_flags != 0 ) - { - if( libfwevt_xml_tag_set_value_format_flags( - xml_tag, - value_format_flags, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_SET_FAILED, - "%s: unable to set value format flags.", - function ); - - goto on_error; - } - } if( ( substitution_value_type & LIBFWEVT_VALUE_TYPE_ARRAY ) != 0 ) { safe_template_value_offset = *template_value_offset; @@ -6413,44 +6312,71 @@ int libfwevt_xml_document_substitute_template_value( template_value_data = &( binary_data[ binary_data_offset + safe_template_value_offset ] ); template_value_data_size = substitution_value_data_size - (uint16_t) safe_template_value_offset; } - /* An empty XML tag should be created if template_value_data_size == 0 - */ if( template_value_data_size > 0 ) { - if( ( substitution_value_type == LIBFWEVT_VALUE_TYPE_ARRAY_OF_STRING_BYTE_STREAM ) - || ( substitution_value_type == LIBFWEVT_VALUE_TYPE_ARRAY_OF_STRING_UTF16 ) ) +#if defined( HAVE_DEBUG_OUTPUT ) + if( libcnotify_verbose != 0 ) { - if( ( value_type == LIBFVALUE_VALUE_TYPE_STRING_UTF16 ) - && ( ( template_value_data_size % 2 ) != 0 ) ) + libcnotify_printf( + "%s: template value data:\n", + function ); + libcnotify_print_data( + template_value_data, + template_value_data_size, + LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); + } +#endif + if( substitution_value_type == LIBFWEVT_VALUE_TYPE_ARRAY_OF_STRING_BYTE_STREAM ) + { + if( template_value_data_size < 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, - "%s: invalid UTF-16 template value data size value out of bounds.", + "%s: invalid byte string template value data size value out of bounds.", function ); goto on_error; } - read_count = libfwevt_xml_tag_set_value_strings_array( - xml_tag, - template_value_data, - template_value_data_size, - value_encoding, - error ); - - if( read_count == -1 ) + while( template_value_data_offset < template_value_data_size ) + { + if( template_value_data[ template_value_data_offset ] == 0 ) + { + template_value_data_offset += 1; + + break; + } + template_value_data_offset += 1; + } + template_value_data_size = template_value_data_offset; + } + else if( substitution_value_type == LIBFWEVT_VALUE_TYPE_ARRAY_OF_STRING_UTF16 ) + { + if( ( template_value_data_size < 2 ) + && ( ( template_value_data_size % 2 ) != 0 ) ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_SET_FAILED, - "%s: unable to set value data.", + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, + "%s: invalid UTF-16 template value data size value out of bounds.", function ); goto on_error; } - safe_template_value_offset += read_count; + while( template_value_data_offset < template_value_data_size ) + { + if( ( template_value_data[ template_value_data_offset ] == 0 ) + && ( template_value_data[ template_value_data_offset + 1 ] == 0 ) ) + { + template_value_data_offset += 2; + + break; + } + template_value_data_offset += 2; + } + template_value_data_size = template_value_data_offset; } else { @@ -6465,24 +6391,30 @@ int libfwevt_xml_document_substitute_template_value( goto on_error; } - if( libfwevt_xml_tag_set_value_data( - xml_tag, - template_value_data, - template_value_size, - value_encoding, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_SET_FAILED, - "%s: unable to set value data.", - function ); + template_value_data_size = template_value_size; + } + } + /* An empty XML tag should be created if template_value_data_size == 0 + */ +/* TODO create empty XML tag if template value data is an empty string */ + if( template_value_data_size > 0 ) + { + if( libfwevt_xml_tag_set_value_data( + xml_tag, + template_value_data, + template_value_data_size, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_SET_FAILED, + "%s: unable to set value data.", + function ); - goto on_error; - } - safe_template_value_offset += template_value_size; + goto on_error; } + safe_template_value_offset += template_value_data_size; } if( safe_template_value_offset == substitution_value_data_size ) { @@ -6503,7 +6435,7 @@ int libfwevt_xml_document_substitute_template_value( goto on_error; } - else if( ( value_type == LIBFVALUE_VALUE_TYPE_STRING_UTF16 ) + else if( ( substitution_value_type == LIBFWEVT_VALUE_TYPE_STRING_UTF16 ) && ( ( substitution_value_data_size % 2 ) != 0 ) ) { libcerror_error_set( @@ -6519,7 +6451,6 @@ int libfwevt_xml_document_substitute_template_value( xml_tag, &( binary_data[ binary_data_offset ] ), (size_t) substitution_value_data_size, - value_encoding, error ) != 1 ) { libcerror_error_set( diff --git a/libfwevt/libfwevt_xml_tag.c b/libfwevt/libfwevt_xml_tag.c index 006c26f..a81359c 100644 --- a/libfwevt/libfwevt_xml_tag.c +++ b/libfwevt/libfwevt_xml_tag.c @@ -442,12 +442,12 @@ int libfwevt_xml_tag_set_name_data( */ int libfwevt_xml_tag_set_value_type( libfwevt_xml_tag_t *xml_tag, - int value_type, + uint8_t value_type, libcerror_error_t **error ) { libfwevt_internal_xml_tag_t *internal_xml_tag = NULL; static char *function = "libfwevt_xml_tag_set_value_type"; - int current_value_type = 0; + uint8_t current_value_type = 0; if( xml_tag == NULL ) { @@ -510,47 +510,6 @@ int libfwevt_xml_tag_set_value_type( return( 1 ); } -/* Sets the value format flags - * Returns 1 if successful or -1 on error - */ -int libfwevt_xml_tag_set_value_format_flags( - libfwevt_xml_tag_t *xml_tag, - uint32_t format_flags, - libcerror_error_t **error ) -{ - libfwevt_internal_xml_tag_t *internal_xml_tag = NULL; - static char *function = "libfwevt_xml_tag_set_value_format_flags"; - - if( xml_tag == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid XML tag.", - function ); - - return( -1 ); - } - internal_xml_tag = (libfwevt_internal_xml_tag_t *) xml_tag; - - if( libfwevt_xml_value_set_format_flags( - internal_xml_tag->value, - format_flags, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_SET_FAILED, - "%s: unable to set value format flags.", - function ); - - return( -1 ); - } - return( 1 ); -} - /* Sets the value data * Returns 1 if successful or -1 on error */ @@ -558,11 +517,11 @@ int libfwevt_xml_tag_set_value_data( libfwevt_xml_tag_t *xml_tag, const uint8_t *data, size_t data_size, - int encoding, libcerror_error_t **error ) { libfwevt_internal_xml_tag_t *internal_xml_tag = NULL; static char *function = "libfwevt_xml_tag_set_value_data"; + int data_segment_index = 0; if( xml_tag == NULL ) { @@ -577,19 +536,18 @@ int libfwevt_xml_tag_set_value_data( } internal_xml_tag = (libfwevt_internal_xml_tag_t *) xml_tag; - if( libfwevt_xml_value_set_data( + if( libfwevt_xml_value_append_data_segment( internal_xml_tag->value, data, data_size, - encoding, - LIBFVALUE_VALUE_DATA_FLAG_NON_MANAGED, + &data_segment_index, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, - "%s: unable to set value data.", + "%s: unable to append data segment.", function ); return( -1 ); @@ -597,15 +555,14 @@ int libfwevt_xml_tag_set_value_data( return( 1 ); } -/* Appends the value data +/* Appends value data * Returns 1 if successful or -1 on error */ int libfwevt_xml_tag_append_value_data( libfwevt_xml_tag_t *xml_tag, const uint8_t *data, size_t data_size, - int encoding, - int *value_entry_index, + int *data_segment_index, libcerror_error_t **error ) { libfwevt_internal_xml_tag_t *internal_xml_tag = NULL; @@ -624,12 +581,11 @@ int libfwevt_xml_tag_append_value_data( } internal_xml_tag = (libfwevt_internal_xml_tag_t *) xml_tag; - if( libfwevt_xml_value_append_data( + if( libfwevt_xml_value_append_data_segment( internal_xml_tag->value, - value_entry_index, data, data_size, - encoding, + data_segment_index, error ) != 1 ) { libcerror_error_set( @@ -644,55 +600,6 @@ int libfwevt_xml_tag_append_value_data( return( 1 ); } -/* Sets the value strings array - * Returns the number of bytes read if successful or -1 on error - */ -ssize_t libfwevt_xml_tag_set_value_strings_array( - libfwevt_xml_tag_t *xml_tag, - const uint8_t *strings_array_data, - size_t strings_array_data_size, - int encoding, - libcerror_error_t **error ) -{ - libfwevt_internal_xml_tag_t *internal_xml_tag = NULL; - static char *function = "libfwevt_xml_tag_set_value_strings_array"; - ssize_t read_count = 0; - - if( xml_tag == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid XML tag.", - function ); - - return( -1 ); - } - internal_xml_tag = (libfwevt_internal_xml_tag_t *) xml_tag; - - read_count = libfwevt_xml_value_type_set_data_string( - internal_xml_tag->value, - strings_array_data, - strings_array_data_size, - encoding, - LIBFVALUE_VALUE_DATA_FLAG_NON_MANAGED, - error ); - - if( read_count == -1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_SET_FAILED, - "%s: unable to set value data.", - function ); - - return( -1 ); - } - return( read_count ); -} - /* Appends an element * Returns 1 if successful or -1 on error */ @@ -976,7 +883,7 @@ int libfwevt_xml_tag_get_utf8_value_size( } internal_xml_tag = (libfwevt_internal_xml_tag_t *) xml_tag; - if( libfwevt_xml_value_get_utf8_string_size( + if( libfwevt_xml_value_get_data_as_utf8_string_size( internal_xml_tag->value, utf8_string_size, error ) != 1 ) @@ -1018,7 +925,7 @@ int libfwevt_xml_tag_get_utf8_value( } internal_xml_tag = (libfwevt_internal_xml_tag_t *) xml_tag; - if( libfwevt_xml_value_copy_to_utf8_string( + if( libfwevt_xml_value_get_data_as_utf8_string( internal_xml_tag->value, utf8_string, utf8_string_size, @@ -1060,7 +967,7 @@ int libfwevt_xml_tag_get_utf16_value_size( } internal_xml_tag = (libfwevt_internal_xml_tag_t *) xml_tag; - if( libfwevt_xml_value_get_utf16_string_size( + if( libfwevt_xml_value_get_data_as_utf16_string_size( internal_xml_tag->value, utf16_string_size, error ) != 1 ) @@ -1102,7 +1009,7 @@ int libfwevt_xml_tag_get_utf16_value( } internal_xml_tag = (libfwevt_internal_xml_tag_t *) xml_tag; - if( libfwevt_xml_value_copy_to_utf16_string( + if( libfwevt_xml_value_get_data_as_utf16_string( internal_xml_tag->value, utf16_string, utf16_string_size, @@ -2177,10 +2084,9 @@ int libfwevt_xml_tag_get_utf8_xml_value_string_size( size_t safe_utf8_string_size = 0; size_t value_string_index = 0; size_t value_string_size = 0; - int number_of_value_entries = 0; - int result = 0; - int value_entry_index = 0; - int value_type = 0; + uint8_t value_type = 0; + int data_segment_index = 0; + int number_of_data_segments = 0; if( internal_xml_tag == NULL ) { @@ -2218,64 +2124,62 @@ int libfwevt_xml_tag_get_utf8_xml_value_string_size( goto on_error; } - if( libfwevt_xml_value_get_number_of_value_entries( + if( libfwevt_xml_value_get_number_of_data_segments( internal_xml_tag->value, - &number_of_value_entries, + &number_of_data_segments, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve element value number of value entries.", + "%s: unable to retrieve element value number of data segments.", function ); goto on_error; } - for( value_entry_index = 0; - value_entry_index < number_of_value_entries; - value_entry_index++ ) + for( data_segment_index = 0; + data_segment_index < number_of_data_segments; + data_segment_index++ ) { - result = libfwevt_xml_value_get_utf8_string_size_with_index( - internal_xml_tag->value, - value_entry_index, - &value_string_size, - error ); - - if( result == -1 ) + if( libfwevt_internal_xml_value_get_data_segment_as_utf8_string_size( + (libfwevt_internal_xml_value_t *) internal_xml_tag->value, + data_segment_index, + &value_string_size, + error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve UTF-8 string size of element value entry: %d.", + "%s: unable to retrieve UTF-8 string size of element data segment: %d.", function, - value_entry_index ); + data_segment_index ); goto on_error; } - if( ( result == 0 ) - && ( number_of_value_entries != 1 ) ) + if( ( value_string_size == 0 ) + && ( number_of_data_segments != 1 ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, - "%s: missing element value entry: %d.", + "%s: missing element data segment: %d.", function, - value_entry_index ); + data_segment_index ); goto on_error; } - if( result != 0 ) + if( value_string_size != 0 ) { - if( ( number_of_value_entries == 1 ) + if( ( number_of_data_segments == 1 ) && ( value_string_size == 2 ) ) { value_string_index = 0; - if( libfwevt_xml_value_copy_to_utf8_string_with_index( - internal_xml_tag->value, + if( libfwevt_internal_xml_value_get_data_segment_as_utf8_string( + (libfwevt_internal_xml_value_t *) internal_xml_tag->value, 0, static_value_string, 2, @@ -2298,7 +2202,7 @@ int libfwevt_xml_tag_get_utf8_xml_value_string_size( value_string_size -= 1; } } - else if( value_type == LIBFVALUE_VALUE_TYPE_STRING_UTF16 ) + else if( ( value_type & 0x7f ) == LIBFWEVT_VALUE_TYPE_STRING_UTF16 ) { if( ( value_string_size == 0 ) || ( value_string_size > ( MEMORY_MAXIMUM_ALLOCATION_SIZE / sizeof( uint8_t ) ) ) ) @@ -2328,9 +2232,9 @@ int libfwevt_xml_tag_get_utf8_xml_value_string_size( } value_string_index = 0; - if( libfwevt_xml_value_copy_to_utf8_string_with_index( - internal_xml_tag->value, - value_entry_index, + if( libfwevt_internal_xml_value_get_data_segment_as_utf8_string( + (libfwevt_internal_xml_value_t *) internal_xml_tag->value, + data_segment_index, value_string, value_string_size, &value_string_index, @@ -2342,7 +2246,7 @@ int libfwevt_xml_tag_get_utf8_xml_value_string_size( LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy element value: %d to UTF-8 string.", function, - value_entry_index ); + data_segment_index ); goto on_error; } @@ -2424,10 +2328,9 @@ int libfwevt_xml_tag_get_utf8_xml_value_string_with_index( size_t string_index = 0; size_t value_string_index = 0; size_t value_string_size = 0; - int number_of_value_entries = 0; - int result = 0; - int value_entry_index = 0; - int value_type = 0; + uint8_t value_type = 0; + int data_segment_index = 0; + int number_of_data_segments = 0; if( internal_xml_tag == NULL ) { @@ -2489,59 +2392,57 @@ int libfwevt_xml_tag_get_utf8_xml_value_string_with_index( goto on_error; } - if( libfwevt_xml_value_get_number_of_value_entries( + if( libfwevt_xml_value_get_number_of_data_segments( internal_xml_tag->value, - &number_of_value_entries, + &number_of_data_segments, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve element value number of value entries.", + "%s: unable to retrieve element value number of data segments.", function ); goto on_error; } - for( value_entry_index = 0; - value_entry_index < number_of_value_entries; - value_entry_index++ ) + for( data_segment_index = 0; + data_segment_index < number_of_data_segments; + data_segment_index++ ) { - result = libfwevt_xml_value_get_utf8_string_size_with_index( - internal_xml_tag->value, - value_entry_index, - &value_string_size, - error ); - - if( result == -1 ) + if( libfwevt_internal_xml_value_get_data_segment_as_utf8_string_size( + (libfwevt_internal_xml_value_t *) internal_xml_tag->value, + data_segment_index, + &value_string_size, + error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve UTF-8 string size of element value entry: %d.", + "%s: unable to retrieve UTF-8 string size of element data segment: %d.", function, - value_entry_index ); + data_segment_index ); goto on_error; } - if( ( result == 0 ) - && ( number_of_value_entries != 1 ) ) + if( ( value_string_size == 0 ) + && ( number_of_data_segments != 1 ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, - "%s: missing element value entry: %d.", + "%s: missing element data segment: %d.", function, - value_entry_index ); + data_segment_index ); goto on_error; } - if( ( result != 0 ) + if( ( value_string_size != 0 ) && ( value_string_size > 1 ) ) { - if( value_type == LIBFVALUE_VALUE_TYPE_STRING_UTF16 ) + if( ( value_type & 0x7f ) == LIBFWEVT_VALUE_TYPE_STRING_UTF16 ) { if( ( value_string_size == 0 ) || ( value_string_size > ( MEMORY_MAXIMUM_ALLOCATION_SIZE / sizeof( uint8_t ) ) ) ) @@ -2571,9 +2472,9 @@ int libfwevt_xml_tag_get_utf8_xml_value_string_with_index( } value_string_index = 0; - if( libfwevt_xml_value_copy_to_utf8_string_with_index( - internal_xml_tag->value, - value_entry_index, + if( libfwevt_internal_xml_value_get_data_segment_as_utf8_string( + (libfwevt_internal_xml_value_t *) internal_xml_tag->value, + data_segment_index, value_string, value_string_size, &value_string_index, @@ -2585,7 +2486,7 @@ int libfwevt_xml_tag_get_utf8_xml_value_string_with_index( LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy element value: %d to UTF-8 string.", function, - value_entry_index ); + data_segment_index ); goto on_error; } @@ -2728,9 +2629,9 @@ int libfwevt_xml_tag_get_utf8_xml_value_string_with_index( } else { - if( libfwevt_xml_value_copy_to_utf8_string_with_index( - internal_xml_tag->value, - value_entry_index, + if( libfwevt_internal_xml_value_get_data_segment_as_utf8_string( + (libfwevt_internal_xml_value_t *) internal_xml_tag->value, + data_segment_index, utf8_string, utf8_string_size, &string_index, @@ -2797,7 +2698,6 @@ int libfwevt_xml_tag_get_utf8_xml_string_size( int element_index = 0; int number_of_attributes = 0; int number_of_elements = 0; - int value_type = 0; if( xml_tag == NULL ) { @@ -2939,23 +2839,8 @@ int libfwevt_xml_tag_get_utf8_xml_string_size( */ safe_utf8_string_size += attribute_name_size + 2; - if( libfwevt_xml_value_get_type( - internal_attribute_xml_tag->value, - &value_type, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve attribute value type.", - function ); - - return( -1 ); - } - if( libfwevt_xml_value_get_utf8_string_size_with_index( + if( libfwevt_xml_value_get_data_as_utf8_string_size( internal_attribute_xml_tag->value, - 0, &string_size, error ) != 1 ) { @@ -3074,9 +2959,8 @@ int libfwevt_xml_tag_get_utf8_xml_string_size( } else if( internal_xml_tag->type == LIBFWEVT_XML_TAG_TYPE_CDATA ) { - if( libfwevt_xml_value_get_utf8_string_size_with_index( + if( libfwevt_xml_value_get_data_as_utf8_string_size( internal_xml_tag->value, - 0, &string_size, error ) != 1 ) { @@ -3120,9 +3004,8 @@ int libfwevt_xml_tag_get_utf8_xml_string_size( */ safe_utf8_string_size += element_name_size; - if( libfwevt_xml_value_get_utf8_string_size_with_index( + if( libfwevt_xml_value_get_data_as_utf8_string_size( internal_xml_tag->value, - 0, &string_size, error ) != 1 ) { @@ -3176,7 +3059,6 @@ int libfwevt_xml_tag_get_utf8_xml_string_with_index( int indentation_iterator = 0; int number_of_attributes = 0; int number_of_elements = 0; - int value_type = 0; if( xml_tag == NULL ) { @@ -3378,23 +3260,8 @@ int libfwevt_xml_tag_get_utf8_xml_string_with_index( utf8_string[ string_index++ ] = (uint8_t) '='; utf8_string[ string_index++ ] = (uint8_t) '"'; - if( libfwevt_xml_value_get_type( - internal_attribute_xml_tag->value, - &value_type, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve attribute value type.", - function ); - - return( -1 ); - } - if( libfwevt_xml_value_copy_to_utf8_string_with_index( + if( libfwevt_xml_value_get_data_as_utf8_string_with_index( internal_attribute_xml_tag->value, - 0, utf8_string, utf8_string_size, &string_index, @@ -3682,9 +3549,8 @@ int libfwevt_xml_tag_get_utf8_xml_string_with_index( utf8_string[ string_index++ ] = (uint8_t) 'A'; utf8_string[ string_index++ ] = (uint8_t) '['; - if( libfwevt_xml_value_copy_to_utf8_string_with_index( + if( libfwevt_xml_value_get_data_as_utf8_string_with_index( internal_xml_tag->value, - 0, utf8_string, utf8_string_size, &string_index, @@ -3763,9 +3629,8 @@ int libfwevt_xml_tag_get_utf8_xml_string_with_index( } utf8_string[ string_index++ ] = (uint8_t) ' '; - if( libfwevt_xml_value_copy_to_utf8_string_with_index( + if( libfwevt_xml_value_get_data_as_utf8_string_with_index( internal_xml_tag->value, - 0, utf8_string, utf8_string_size, &string_index, @@ -3819,10 +3684,9 @@ int libfwevt_xml_tag_get_utf16_xml_value_string_size( size_t safe_utf16_string_size = 0; size_t value_string_index = 0; size_t value_string_size = 0; - int number_of_value_entries = 0; - int result = 0; - int value_entry_index = 0; - int value_type = 0; + uint8_t value_type = 0; + int data_segment_index = 0; + int number_of_data_segments = 0; if( internal_xml_tag == NULL ) { @@ -3860,64 +3724,62 @@ int libfwevt_xml_tag_get_utf16_xml_value_string_size( goto on_error; } - if( libfwevt_xml_value_get_number_of_value_entries( + if( libfwevt_xml_value_get_number_of_data_segments( internal_xml_tag->value, - &number_of_value_entries, + &number_of_data_segments, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve element value number of value entries.", + "%s: unable to retrieve element value number of data segments.", function ); goto on_error; } - for( value_entry_index = 0; - value_entry_index < number_of_value_entries; - value_entry_index++ ) + for( data_segment_index = 0; + data_segment_index < number_of_data_segments; + data_segment_index++ ) { - result = libfwevt_xml_value_get_utf16_string_size_with_index( - internal_xml_tag->value, - value_entry_index, - &value_string_size, - error ); - - if( result == -1 ) + if( libfwevt_internal_xml_value_get_data_segment_as_utf16_string_size( + (libfwevt_internal_xml_value_t *) internal_xml_tag->value, + data_segment_index, + &value_string_size, + error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve UTF-16 string size of element value entry: %d.", + "%s: unable to retrieve UTF-16 string size of element data segment: %d.", function, - value_entry_index ); + data_segment_index ); goto on_error; } - if( ( result == 0 ) - && ( number_of_value_entries != 1 ) ) + if( ( value_string_size == 0 ) + && ( number_of_data_segments != 1 ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, - "%s: missing element value entry: %d.", + "%s: missing element data segment: %d.", function, - value_entry_index ); + data_segment_index ); goto on_error; } - if( result != 0 ) + if( value_string_size != 0 ) { - if( ( number_of_value_entries == 1 ) + if( ( number_of_data_segments == 1 ) && ( value_string_size == 2 ) ) { value_string_index = 0; - if( libfwevt_xml_value_copy_to_utf16_string_with_index( - internal_xml_tag->value, + if( libfwevt_internal_xml_value_get_data_segment_as_utf16_string( + (libfwevt_internal_xml_value_t *) internal_xml_tag->value, 0, static_value_string, 2, @@ -3940,7 +3802,7 @@ int libfwevt_xml_tag_get_utf16_xml_value_string_size( value_string_size -= 1; } } - else if( value_type == LIBFVALUE_VALUE_TYPE_STRING_UTF16 ) + else if( ( value_type & 0x7f ) == LIBFWEVT_VALUE_TYPE_STRING_UTF16 ) { if( ( value_string_size == 0 ) || ( value_string_size > ( MEMORY_MAXIMUM_ALLOCATION_SIZE / sizeof( uint16_t ) ) ) ) @@ -3955,7 +3817,7 @@ int libfwevt_xml_tag_get_utf16_xml_value_string_size( goto on_error; } value_string = (uint16_t *) memory_allocate( - sizeof( uint16_t ) * value_string_size ); + sizeof( uint16_t ) * value_string_size ); if( value_string == NULL ) { @@ -3970,9 +3832,9 @@ int libfwevt_xml_tag_get_utf16_xml_value_string_size( } value_string_index = 0; - if( libfwevt_xml_value_copy_to_utf16_string_with_index( - internal_xml_tag->value, - value_entry_index, + if( libfwevt_internal_xml_value_get_data_segment_as_utf16_string( + (libfwevt_internal_xml_value_t *) internal_xml_tag->value, + data_segment_index, value_string, value_string_size, &value_string_index, @@ -3984,12 +3846,12 @@ int libfwevt_xml_tag_get_utf16_xml_value_string_size( LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy element value: %d to UTF-16 string.", function, - value_entry_index ); + data_segment_index ); goto on_error; } for( value_string_index = 0; - value_string_index < value_string_size; + value_string_index < ( value_string_size - 1 ); value_string_index++ ) { switch( value_string[ value_string_index ] ) @@ -4066,10 +3928,9 @@ int libfwevt_xml_tag_get_utf16_xml_value_string_with_index( size_t string_index = 0; size_t value_string_index = 0; size_t value_string_size = 0; - int number_of_value_entries = 0; - int result = 0; - int value_entry_index = 0; - int value_type = 0; + uint8_t value_type = 0; + int data_segment_index = 0; + int number_of_data_segments = 0; if( internal_xml_tag == NULL ) { @@ -4131,59 +3992,57 @@ int libfwevt_xml_tag_get_utf16_xml_value_string_with_index( goto on_error; } - if( libfwevt_xml_value_get_number_of_value_entries( + if( libfwevt_xml_value_get_number_of_data_segments( internal_xml_tag->value, - &number_of_value_entries, + &number_of_data_segments, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve element value number of value entries.", + "%s: unable to retrieve element value number of data segments.", function ); goto on_error; } - for( value_entry_index = 0; - value_entry_index < number_of_value_entries; - value_entry_index++ ) + for( data_segment_index = 0; + data_segment_index < number_of_data_segments; + data_segment_index++ ) { - result = libfwevt_xml_value_get_utf16_string_size_with_index( - internal_xml_tag->value, - value_entry_index, - &value_string_size, - error ); - - if( result == -1 ) + if( libfwevt_internal_xml_value_get_data_segment_as_utf16_string_size( + (libfwevt_internal_xml_value_t *) internal_xml_tag->value, + data_segment_index, + &value_string_size, + error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve UTF-16 string size of element value entry: %d.", + "%s: unable to retrieve UTF-16 string size of element data segment: %d.", function, - value_entry_index ); + data_segment_index ); goto on_error; } - if( ( result == 0 ) - && ( number_of_value_entries != 1 ) ) + if( ( value_string_size == 0 ) + && ( number_of_data_segments != 1 ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, - "%s: missing element value entry: %d.", + "%s: missing element data segment: %d.", function, - value_entry_index ); + data_segment_index ); goto on_error; } - if( ( result != 0 ) + if( ( value_string_size != 0 ) && ( value_string_size > 1 ) ) { - if( value_type == LIBFVALUE_VALUE_TYPE_STRING_UTF16 ) + if( ( value_type & 0x7f ) == LIBFWEVT_VALUE_TYPE_STRING_UTF16 ) { if( ( value_string_size == 0 ) || ( value_string_size > ( MEMORY_MAXIMUM_ALLOCATION_SIZE / sizeof( uint16_t ) ) ) ) @@ -4213,9 +4072,9 @@ int libfwevt_xml_tag_get_utf16_xml_value_string_with_index( } value_string_index = 0; - if( libfwevt_xml_value_copy_to_utf16_string_with_index( - internal_xml_tag->value, - value_entry_index, + if( libfwevt_internal_xml_value_get_data_segment_as_utf16_string( + (libfwevt_internal_xml_value_t *) internal_xml_tag->value, + data_segment_index, value_string, value_string_size, &value_string_index, @@ -4227,7 +4086,7 @@ int libfwevt_xml_tag_get_utf16_xml_value_string_with_index( LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy element value: %d to UTF-16 string.", function, - value_entry_index ); + data_segment_index ); goto on_error; } @@ -4370,9 +4229,9 @@ int libfwevt_xml_tag_get_utf16_xml_value_string_with_index( } else { - if( libfwevt_xml_value_copy_to_utf16_string_with_index( - internal_xml_tag->value, - value_entry_index, + if( libfwevt_internal_xml_value_get_data_segment_as_utf16_string( + (libfwevt_internal_xml_value_t *) internal_xml_tag->value, + data_segment_index, utf16_string, utf16_string_size, &string_index, @@ -4439,7 +4298,6 @@ int libfwevt_xml_tag_get_utf16_xml_string_size( int element_index = 0; int number_of_attributes = 0; int number_of_elements = 0; - int value_type = 0; if( xml_tag == NULL ) { @@ -4512,7 +4370,7 @@ int libfwevt_xml_tag_get_utf16_xml_string_size( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve size of UTF-16 string of element name.", + "%s: unable to retrieve UTF-16 string size of element name.", function ); return( -1 ); @@ -4581,23 +4439,8 @@ int libfwevt_xml_tag_get_utf16_xml_string_size( */ safe_utf16_string_size += attribute_name_size + 2; - if( libfwevt_xml_value_get_type( + if( libfwevt_xml_value_get_data_as_utf16_string_size( internal_attribute_xml_tag->value, - &value_type, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve attribute value type.", - function ); - - return( -1 ); - } - if( libfwevt_xml_value_get_utf16_string_size_with_index( - internal_attribute_xml_tag->value, - 0, &string_size, error ) != 1 ) { @@ -4716,9 +4559,8 @@ int libfwevt_xml_tag_get_utf16_xml_string_size( } else if( internal_xml_tag->type == LIBFWEVT_XML_TAG_TYPE_CDATA ) { - if( libfwevt_xml_value_get_utf16_string_size_with_index( + if( libfwevt_xml_value_get_data_as_utf16_string_size( internal_xml_tag->value, - 0, &string_size, error ) != 1 ) { @@ -4762,9 +4604,8 @@ int libfwevt_xml_tag_get_utf16_xml_string_size( */ safe_utf16_string_size += element_name_size; - if( libfwevt_xml_value_get_utf16_string_size_with_index( + if( libfwevt_xml_value_get_data_as_utf16_string_size( internal_xml_tag->value, - 0, &string_size, error ) != 1 ) { @@ -4818,7 +4659,6 @@ int libfwevt_xml_tag_get_utf16_xml_string_with_index( int indentation_iterator = 0; int number_of_attributes = 0; int number_of_elements = 0; - int value_type = 0; if( xml_tag == NULL ) { @@ -5020,23 +4860,8 @@ int libfwevt_xml_tag_get_utf16_xml_string_with_index( utf16_string[ string_index++ ] = (uint16_t) '='; utf16_string[ string_index++ ] = (uint16_t) '"'; - if( libfwevt_xml_value_get_type( - internal_attribute_xml_tag->value, - &value_type, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve attribute value type.", - function ); - - return( -1 ); - } - if( libfwevt_xml_value_copy_to_utf16_string_with_index( + if( libfwevt_xml_value_get_data_as_utf16_string_with_index( internal_attribute_xml_tag->value, - 0, utf16_string, utf16_string_size, &string_index, @@ -5324,9 +5149,8 @@ int libfwevt_xml_tag_get_utf16_xml_string_with_index( utf16_string[ string_index++ ] = (uint16_t) 'A'; utf16_string[ string_index++ ] = (uint16_t) '['; - if( libfwevt_xml_value_copy_to_utf16_string_with_index( + if( libfwevt_xml_value_get_data_as_utf16_string_with_index( internal_xml_tag->value, - 0, utf16_string, utf16_string_size, &string_index, @@ -5405,9 +5229,8 @@ int libfwevt_xml_tag_get_utf16_xml_string_with_index( } utf16_string[ string_index++ ] = (uint16_t) ' '; - if( libfwevt_xml_value_copy_to_utf16_string_with_index( + if( libfwevt_xml_value_get_data_as_utf16_string_with_index( internal_xml_tag->value, - 0, utf16_string, utf16_string_size, &string_index, @@ -5544,8 +5367,8 @@ int libfwevt_xml_tag_debug_print_name_string( libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_SET_FAILED, - "%s: unable to set name string.", + LIBCERROR_RUNTIME_ERROR_GET_FAILED, + "%s: unable to retrieve name string.", function ); goto on_error; @@ -5579,10 +5402,10 @@ int libfwevt_xml_tag_debug_print_value_string( static char *function = "libfwevt_xml_tag_debug_print_value_string"; size_t value_string_index = 0; size_t value_string_size = 0; - int number_of_value_entries = 0; + uint8_t value_type = 0; + int data_segment_index = 0; + int number_of_data_segments = 0; int result = 0; - int value_entry_index = 0; - int value_type = 0; if( internal_xml_tag == NULL ) { @@ -5609,65 +5432,65 @@ int libfwevt_xml_tag_debug_print_value_string( goto on_error; } - if( libfwevt_xml_value_get_number_of_value_entries( + if( libfwevt_xml_value_get_number_of_data_segments( internal_xml_tag->value, - &number_of_value_entries, + &number_of_data_segments, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve element value number of value entries.", + "%s: unable to retrieve element value number of data segments.", function ); goto on_error; } - for( value_entry_index = 0; - value_entry_index < number_of_value_entries; - value_entry_index++ ) + for( data_segment_index = 0; + data_segment_index < number_of_data_segments; + data_segment_index++ ) { #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) - result = libfwevt_xml_value_get_utf16_string_size_with_index( - internal_xml_tag->value, - value_entry_index, + result = libfwevt_internal_xml_value_get_data_segment_as_utf16_string_size( + (libfwevt_internal_xml_value_t *) internal_xml_tag->value, + data_segment_index, &value_string_size, error ); #else - result = libfwevt_xml_value_get_utf8_string_size_with_index( - internal_xml_tag->value, - value_entry_index, + result = libfwevt_internal_xml_value_get_data_segment_as_utf8_string_size( + (libfwevt_internal_xml_value_t *) internal_xml_tag->value, + data_segment_index, &value_string_size, error ); #endif - if( result == -1 ) + if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve string size of element value entry: %d.", + "%s: unable to retrieve string size of element data segment: %d.", function, - value_entry_index ); + data_segment_index ); goto on_error; } if( ( result == 0 ) - && ( number_of_value_entries != 1 ) ) + && ( number_of_data_segments != 1 ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, - "%s: missing element value entry: %d.", + "%s: missing element data segment: %d.", function, - value_entry_index ); + data_segment_index ); goto on_error; } if( result != 0 ) { - if( value_type == LIBFVALUE_VALUE_TYPE_STRING_UTF16 ) + if( ( value_type & 0x7f ) == LIBFWEVT_VALUE_TYPE_STRING_UTF16 ) { value_string = system_string_allocate( value_string_size ); @@ -5686,17 +5509,17 @@ int libfwevt_xml_tag_debug_print_value_string( value_string_index = 0; #if defined( HAVE_WIDE_SYSTEM_CHARACTER ) - result = libfwevt_xml_value_copy_to_utf16_string_with_index( - internal_xml_tag->value, - value_entry_index, + result = libfwevt_internal_xml_value_get_data_segment_as_utf16_string( + (libfwevt_internal_xml_value_t *) internal_xml_tag->value, + data_segment_index, (uint16_t *) value_string, value_string_size, &value_string_index, error ); #else - result = libfwevt_xml_value_copy_to_utf8_string_with_index( - internal_xml_tag->value, - value_entry_index, + result = libfwevt_internal_xml_value_get_data_segment_as_utf8_string( + (libfwevt_internal_xml_value_t *) internal_xml_tag->value, + data_segment_index, (uint8_t *) value_string, value_string_size, &value_string_index, @@ -5710,7 +5533,7 @@ int libfwevt_xml_tag_debug_print_value_string( LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy element value: %d to string.", function, - value_entry_index ); + data_segment_index ); goto on_error; } @@ -5774,10 +5597,9 @@ int libfwevt_xml_tag_debug_print_value_string( } else { - if( libfwevt_debug_print_xml_value( + if( libfwevt_debug_print_xml_value_with_index( internal_xml_tag->value, - value_entry_index, - 0, + data_segment_index, error ) != 1 ) { libcerror_error_set( @@ -5821,7 +5643,6 @@ int libfwevt_xml_tag_debug_print( int indentation_iterator = 0; int number_of_attributes = 0; int number_of_elements = 0; - int value_type = 0; if( xml_tag == NULL ) { @@ -5942,23 +5763,8 @@ int libfwevt_xml_tag_debug_print( libcnotify_printf( "=\"" ); - if( libfwevt_xml_value_get_type( + if( libfwevt_debug_print_xml_value_with_index( internal_attribute_xml_tag->value, - &value_type, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve attribute value type.", - function ); - - return( -1 ); - } - if( libfwevt_debug_print_xml_value( - internal_attribute_xml_tag->value, - 0, 0, error ) != 1 ) { @@ -6108,10 +5914,9 @@ int libfwevt_xml_tag_debug_print( libcnotify_printf( "![CDATA[" ); - if( libfwevt_debug_print_xml_value( + if( libfwevt_debug_print_xml_value_with_index( internal_xml_tag->value, 0, - 0, error ) != 1 ) { libcerror_error_set( @@ -6147,10 +5952,9 @@ int libfwevt_xml_tag_debug_print( libcnotify_printf( " " ); - if( libfwevt_debug_print_xml_value( + if( libfwevt_debug_print_xml_value_with_index( internal_xml_tag->value, 0, - 0, error ) != 1 ) { libcerror_error_set( @@ -6225,7 +6029,7 @@ int libfwevt_xml_tag_name_debug_print( */ int libfwevt_xml_tag_value_debug_print( libfwevt_xml_tag_t *xml_tag, - int value_entry_index, + int data_segment_index, libcerror_error_t **error ) { libfwevt_internal_xml_tag_t *internal_xml_tag = NULL; @@ -6248,10 +6052,9 @@ int libfwevt_xml_tag_value_debug_print( "%s: value\t\t\t\t: ", function ); - if( libfwevt_debug_print_xml_value( + if( libfwevt_debug_print_xml_value_with_index( internal_xml_tag->value, - value_entry_index, - 0, + data_segment_index, error ) != 1 ) { libcerror_error_set( diff --git a/libfwevt/libfwevt_xml_tag.h b/libfwevt/libfwevt_xml_tag.h index cedc0af..9acda05 100644 --- a/libfwevt/libfwevt_xml_tag.h +++ b/libfwevt/libfwevt_xml_tag.h @@ -93,36 +93,22 @@ int libfwevt_xml_tag_set_name_data( int libfwevt_xml_tag_set_value_type( libfwevt_xml_tag_t *xml_tag, - int value_type, - libcerror_error_t **error ); - -int libfwevt_xml_tag_set_value_format_flags( - libfwevt_xml_tag_t *xml_tag, - uint32_t format_flags, + uint8_t value_type, libcerror_error_t **error ); int libfwevt_xml_tag_set_value_data( libfwevt_xml_tag_t *xml_tag, const uint8_t *data, size_t data_size, - int encoding, libcerror_error_t **error ); int libfwevt_xml_tag_append_value_data( libfwevt_xml_tag_t *xml_tag, const uint8_t *data, size_t data_size, - int encoding, - int *value_entry_index, + int *data_segment_index, libcerror_error_t **error ); -ssize_t libfwevt_xml_tag_set_value_strings_array( - libfwevt_xml_tag_t *xml_tag, - const uint8_t *strings_array_data, - size_t strings_array_data_size, - int encoding, - libcerror_error_t **error ); - int libfwevt_xml_tag_append_attribute( libfwevt_xml_tag_t *xml_tag, libfwevt_xml_tag_t *attribute_xml_tag, diff --git a/libfwevt/libfwevt_xml_value.c b/libfwevt/libfwevt_xml_value.c index fec2721..fc62b5a 100644 --- a/libfwevt/libfwevt_xml_value.c +++ b/libfwevt/libfwevt_xml_value.c @@ -21,11 +21,22 @@ #include #include +#include +#include #include +#include +#include "libfwevt_data_segment.h" #include "libfwevt_date_time.h" +#include "libfwevt_definitions.h" +#include "libfwevt_floating_point.h" +#include "libfwevt_integer.h" +#include "libfwevt_libcdata.h" #include "libfwevt_libcerror.h" -#include "libfwevt_libfvalue.h" +#include "libfwevt_libfdatetime.h" +#include "libfwevt_libfguid.h" +#include "libfwevt_libfwnt.h" +#include "libfwevt_libuna.h" #include "libfwevt_types.h" #include "libfwevt_xml_value.h" @@ -35,7 +46,7 @@ */ int libfwevt_xml_value_initialize( libfwevt_xml_value_t **xml_value, - int type, + uint8_t value_type, libcerror_error_t **error ) { libfwevt_internal_xml_value_t *internal_xml_value = NULL; @@ -94,20 +105,22 @@ int libfwevt_xml_value_initialize( return( -1 ); } - if( libfvalue_value_type_initialize( - &( internal_xml_value->value ), - type, + if( libcdata_array_initialize( + &( internal_xml_value->data_segments ), + 0, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, - "%s: unable to create value.", + "%s: unable to create data segments array.", function ); goto on_error; } + internal_xml_value->value_type = value_type; + *xml_value = (libfwevt_xml_value_t *) internal_xml_value; return( 1 ); @@ -171,15 +184,16 @@ int libfwevt_internal_xml_value_free( } if( *internal_xml_value != NULL ) { - if( libfvalue_value_free( - &( ( *internal_xml_value )->value ), + if( libcdata_array_free( + &( ( *internal_xml_value )->data_segments ), + (int (*)(intptr_t **, libcerror_error_t **)) &libfwevt_data_segment_free, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, - "%s: unable to free value.", + "%s: unable to free data segments array.", function ); result = -1; @@ -192,19 +206,16 @@ int libfwevt_internal_xml_value_free( return( result ); } -/* Sets the data +/* Retrieves the value type * Returns 1 if successful or -1 on error */ -int libfwevt_xml_value_set_data( +int libfwevt_xml_value_get_type( libfwevt_xml_value_t *xml_value, - const uint8_t *data, - size_t data_size, - int encoding, - uint8_t flags, + uint8_t *value_type, libcerror_error_t **error ) { libfwevt_internal_xml_value_t *internal_xml_value = NULL; - static char *function = "libfwevt_xml_value_set_data"; + static char *function = "libfwevt_xml_value_get_type"; if( xml_value == NULL ) { @@ -219,36 +230,32 @@ int libfwevt_xml_value_set_data( } internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value; - if( libfvalue_value_set_data( - internal_xml_value->value, - data, - data_size, - encoding, - flags, - error ) != 1 ) + if( value_type == NULL ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_SET_FAILED, - "%s: unable to set value data.", + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid value type.", function ); return( -1 ); } + *value_type = internal_xml_value->value_type; + return( 1 ); } -/* Sets the format flags +/* Retrieves the number of data segments * Returns 1 if successful or -1 on error */ -int libfwevt_xml_value_set_format_flags( +int libfwevt_xml_value_get_number_of_data_segments( libfwevt_xml_value_t *xml_value, - uint32_t format_flags, + int *number_of_data_segments, libcerror_error_t **error ) { libfwevt_internal_xml_value_t *internal_xml_value = NULL; - static char *function = "libfwevt_xml_value_set_format_flags"; + static char *function = "libfwevt_xml_value_get_number_of_data_segments"; if( xml_value == NULL ) { @@ -263,16 +270,16 @@ int libfwevt_xml_value_set_format_flags( } internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value; - if( libfvalue_value_set_format_flags( - internal_xml_value->value, - format_flags, + if( libcdata_array_get_number_of_entries( + internal_xml_value->data_segments, + number_of_data_segments, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_SET_FAILED, - "%s: unable to set value format flags.", + LIBCERROR_RUNTIME_ERROR_GET_FAILED, + "%s: unable to retrieve number of data segments.", function ); return( -1 ); @@ -280,21 +287,19 @@ int libfwevt_xml_value_set_format_flags( return( 1 ); } -/* Appends data +/* Retrieves a specific data segment and initialized its cached value * Returns 1 if successful or -1 on error */ -int libfwevt_xml_value_append_data( - libfwevt_xml_value_t *xml_value, - int *value_entry_index, - const uint8_t *data, - size_t data_size, - int encoding, +int libfwevt_internal_xml_value_get_data_segment_with_cached_value( + libfwevt_internal_xml_value_t *internal_xml_value, + int data_segment_index, + libfwevt_data_segment_t **data_segment, libcerror_error_t **error ) { - libfwevt_internal_xml_value_t *internal_xml_value = NULL; - static char *function = "libfwevt_xml_value_append_data"; + libfwevt_data_segment_t *safe_data_segment = NULL; + static char *function = "libfwevt_internal_xml_value_get_data_segment_with_cached_value"; - if( xml_value == NULL ) + if( internal_xml_value == NULL ) { libcerror_error_set( error, @@ -305,90 +310,280 @@ int libfwevt_xml_value_append_data( return( -1 ); } - internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value; - - if( libfvalue_value_append_entry_data( - internal_xml_value->value, - value_entry_index, - data, - data_size, - encoding, - error ) != 1 ) + if( data_segment == NULL ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, - "%s: unable to append value data.", + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid data segment.", function ); return( -1 ); } - return( 1 ); -} - -/* Sets the data of a variable sized string - * This function will look for a end-of-string character as the indicator - * of the end of the string upto data size - * Returns data size of the string if successful or -1 on error - */ -ssize_t libfwevt_xml_value_type_set_data_string( - libfwevt_xml_value_t *xml_value, - const uint8_t *data, - size_t data_size, - int encoding, - uint8_t flags, - libcerror_error_t **error ) -{ - libfwevt_internal_xml_value_t *internal_xml_value = NULL; - static char *function = "libfwevt_xml_value_type_set_data_string"; - ssize_t read_count = 0; - - if( xml_value == NULL ) + if( libcdata_array_get_entry_by_index( + internal_xml_value->data_segments, + data_segment_index, + (intptr_t **) &safe_data_segment, + error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid XML value.", - function ); + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_GET_FAILED, + "%s: unable to retrieve data segment: %d.", + function, + data_segment_index ); return( -1 ); } - internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value; - - read_count = libfvalue_value_type_set_data_string( - internal_xml_value->value, - data, - data_size, - encoding, - flags, - error ); - - if( read_count == -1 ) + if( safe_data_segment == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_SET_FAILED, - "%s: unable to set value data.", - function ); + LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, + "%s: missing data segment: %d.", + function, + data_segment_index ); return( -1 ); } - return( read_count ); + if( safe_data_segment->cached_value_type == 0 ) + { + switch( internal_xml_value->value_type & 0x7f ) + { + case LIBFWEVT_VALUE_TYPE_INTEGER_8BIT: + case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_8BIT: + if( safe_data_segment->data_size != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, + "%s: invalid data segment: %d - unsupported data size.", + function, + safe_data_segment ); + + return( -1 ); + } + safe_data_segment->value_64bit = safe_data_segment->data[ 0 ]; + + break; + + case LIBFWEVT_VALUE_TYPE_INTEGER_16BIT: + case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_16BIT: + if( safe_data_segment->data_size != 2 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, + "%s: invalid data segment: %d - unsupported data size.", + function, + safe_data_segment ); + + return( -1 ); + } + byte_stream_copy_to_uint16_little_endian( + safe_data_segment->data, + safe_data_segment->value_64bit ); + + break; + + case LIBFWEVT_VALUE_TYPE_INTEGER_32BIT: + case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_32BIT: + case LIBFWEVT_VALUE_TYPE_HEXADECIMAL_INTEGER_32BIT: + case LIBFWEVT_VALUE_TYPE_FLOATING_POINT_32BIT: + case LIBFWEVT_VALUE_TYPE_BOOLEAN: + if( safe_data_segment->data_size != 4 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, + "%s: invalid data segment: %d - unsupported data size.", + function, + safe_data_segment ); + + return( -1 ); + } + byte_stream_copy_to_uint32_little_endian( + safe_data_segment->data, + safe_data_segment->value_64bit ); + + break; + + case LIBFWEVT_VALUE_TYPE_INTEGER_64BIT: + case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_64BIT: + case LIBFWEVT_VALUE_TYPE_HEXADECIMAL_INTEGER_64BIT: + case LIBFWEVT_VALUE_TYPE_FLOATING_POINT_64BIT: + if( safe_data_segment->data_size != 8 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, + "%s: invalid data segment: %d - unsupported data size.", + function, + safe_data_segment ); + + return( -1 ); + } + byte_stream_copy_to_uint64_little_endian( + safe_data_segment->data, + safe_data_segment->value_64bit ); + + break; + + case LIBFWEVT_VALUE_TYPE_GUID: + if( libfguid_identifier_initialize( + &( safe_data_segment->guid ), + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, + "%s: unable to create GUID.", + function ); + + return( -1 ); + } + if( libfguid_identifier_copy_from_byte_stream( + safe_data_segment->guid, + safe_data_segment->data, + safe_data_segment->data_size, + LIBFGUID_ENDIAN_LITTLE, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_COPY_FAILED, + "%s: unable to copy byte stream to GUID.", + function ); + + return( -1 ); + } + break; + + case LIBFWEVT_VALUE_TYPE_FILETIME: + if( libfdatetime_filetime_initialize( + &( safe_data_segment->filetime ), + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, + "%s: unable to create FILETIME.", + function ); + + return( -1 ); + } + if( libfdatetime_filetime_copy_from_byte_stream( + safe_data_segment->filetime, + safe_data_segment->data, + safe_data_segment->data_size, + LIBFDATETIME_ENDIAN_LITTLE, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_COPY_FAILED, + "%s: unable to copy byte stream to FILETIME.", + function ); + + return( -1 ); + } + break; + + case LIBFWEVT_VALUE_TYPE_SYSTEMTIME: + if( libfdatetime_systemtime_initialize( + &( safe_data_segment->systemtime ), + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, + "%s: unable to create SYSTEMTIME.", + function ); + + return( -1 ); + } + if( libfdatetime_systemtime_copy_from_byte_stream( + safe_data_segment->systemtime, + safe_data_segment->data, + safe_data_segment->data_size, + LIBFDATETIME_ENDIAN_LITTLE, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_COPY_FAILED, + "%s: unable to copy byte stream to SYSTEMTIME.", + function ); + + return( -1 ); + } + break; + + case LIBFWEVT_VALUE_TYPE_NT_SECURITY_IDENTIFIER: + if( libfwnt_security_identifier_initialize( + &( safe_data_segment->security_identifier ), + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, + "%s: unable to create NT security identifier.", + function ); + + return( -1 ); + } + if( libfwnt_security_identifier_copy_from_byte_stream( + safe_data_segment->security_identifier, + safe_data_segment->data, + safe_data_segment->data_size, + LIBFWNT_ENDIAN_LITTLE, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_COPY_FAILED, + "%s: unable to copy byte stream to NT security identifier.", + function ); + + return( -1 ); + } + break; + } + safe_data_segment->cached_value_type = internal_xml_value->value_type & 0x7f; + } + *data_segment = safe_data_segment; + + return( 1 ); } -/* Retrieves the value type +/* Appends a data segment * Returns 1 if successful or -1 on error */ -int libfwevt_xml_value_get_type( +int libfwevt_xml_value_append_data_segment( libfwevt_xml_value_t *xml_value, - int *value_type, + const uint8_t *data, + size_t data_size, + int *data_segment_index, libcerror_error_t **error ) { + libfwevt_data_segment_t *data_segment = NULL; libfwevt_internal_xml_value_t *internal_xml_value = NULL; - static char *function = "libfwevt_xml_value_get_type"; + static char *function = "libfwevt_xml_value_append_data_segment"; if( xml_value == NULL ) { @@ -403,62 +598,48 @@ int libfwevt_xml_value_get_type( } internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value; - if( libfvalue_value_get_type( - internal_xml_value->value, - value_type, + if( libfwevt_data_segment_initialize( + &data_segment, + data, + data_size, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve value type.", - function ); - - return( -1 ); - } - return( 1 ); -} - -/* Retrieves the number of values entries - * Returns 1 if successful or -1 on error - */ -int libfwevt_xml_value_get_number_of_value_entries( - libfwevt_xml_value_t *xml_value, - int *number_of_value_entries, - libcerror_error_t **error ) -{ - libfwevt_internal_xml_value_t *internal_xml_value = NULL; - static char *function = "libfwevt_xml_value_get_number_of_value_entries"; - - if( xml_value == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid XML value.", + LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, + "%s: unable to create data segment.", function ); - return( -1 ); + goto on_error; } - internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value; - - if( libfvalue_value_get_number_of_value_entries( - internal_xml_value->value, - number_of_value_entries, + if( libcdata_array_append_entry( + internal_xml_value->data_segments, + data_segment_index, + (intptr_t *) data_segment, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve element value number of value entries.", + LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, + "%s: unable to append data segment to array.", function ); return( -1 ); } + internal_xml_value->data_size += data_size; + return( 1 ); + +on_error: + if( data_segment != NULL ) + { + libfwevt_data_segment_free( + &data_segment, + NULL ); + } + return( -1 ); } /* Retrieves the data size @@ -485,20 +666,19 @@ int libfwevt_xml_value_get_data_size( } internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value; - if( libfvalue_value_get_data_size( - internal_xml_value->value, - data_size, - error ) != 1 ) + if( data_size == NULL ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve value data size.", + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid data size.", function ); return( -1 ); } + *data_size = internal_xml_value->data_size; + return( 1 ); } @@ -511,8 +691,12 @@ int libfwevt_xml_value_copy_data( size_t data_size, libcerror_error_t **error ) { + libfwevt_data_segment_t *data_segment = NULL; libfwevt_internal_xml_value_t *internal_xml_value = NULL; static char *function = "libfwevt_xml_value_copy_data"; + size_t data_offset = 0; + int data_segment_index = 0; + int number_of_data_segments = 0; if( xml_value == NULL ) { @@ -527,125 +711,132 @@ int libfwevt_xml_value_copy_data( } internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value; - if( libfvalue_value_copy_data( - internal_xml_value->value, - data, - data_size, - error ) != 1 ) + if( data == NULL ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_COPY_FAILED, - "%s: unable to value data.", + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid data.", function ); return( -1 ); } - return( 1 ); -} - -/* Copies the value data to a 8-bit integer - * Returns 1 if successful, 0 if value not be retrieved or -1 on error - */ -int libfwevt_xml_value_copy_to_8bit( - libfwevt_xml_value_t *xml_value, - uint8_t *value_8bit, - libcerror_error_t **error ) -{ - libfwevt_internal_xml_value_t *internal_xml_value = NULL; - static char *function = "libfwevt_xml_value_copy_to_8bit"; - int result = 0; - - if( xml_value == NULL ) + if( ( data_size < internal_xml_value->data_size ) + || ( data_size > (size_t) SSIZE_MAX ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid XML value.", + LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, + "%s: invalid data size value out of bounds.", function ); return( -1 ); } - internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value; - - result = libfvalue_value_copy_to_8bit( - internal_xml_value->value, - 0, - value_8bit, - error ); - - if( result == -1 ) + if( libcdata_array_get_number_of_entries( + internal_xml_value->data_segments, + &number_of_data_segments, + error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_COPY_FAILED, - "%s: unable to copy value to 8-bit integer.", + LIBCERROR_RUNTIME_ERROR_GET_FAILED, + "%s: unable to retrieve number of data segments.", function ); return( -1 ); } - return( result ); -} - -/* Copies the value data to a 32-bit integer - * Returns 1 if successful, 0 if value not be retrieved or -1 on error - */ -int libfwevt_xml_value_copy_to_32bit( - libfwevt_xml_value_t *xml_value, - uint32_t *value_32bit, - libcerror_error_t **error ) -{ - libfwevt_internal_xml_value_t *internal_xml_value = NULL; - static char *function = "libfwevt_xml_value_copy_to_32bit"; - int result = 0; - - if( xml_value == NULL ) + for( data_segment_index = 0; + data_segment_index < number_of_data_segments; + data_segment_index++ ) { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid XML value.", - function ); + if( libcdata_array_get_entry_by_index( + internal_xml_value->data_segments, + data_segment_index, + (intptr_t **) &data_segment, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_GET_FAILED, + "%s: unable to retrieve data segment: %d.", + function, + data_segment_index ); - return( -1 ); - } - internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value; + return( -1 ); + } + if( data_segment == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, + "%s: missing data segment: %d.", + function, + data_segment_index ); - result = libfvalue_value_copy_to_32bit( - internal_xml_value->value, - 0, - value_32bit, - error ); + return( -1 ); + } + if( data_segment->data == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, + "%s: invalid data segment: %d - missing data.", + function, + data_segment_index ); - if( result == -1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_COPY_FAILED, - "%s: unable to copy value to 32-bit integer.", - function ); + return( -1 ); + } + if( ( data_segment->data_size > data_size ) + || ( data_offset > ( data_size - data_segment->data_size ) ) ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, + "%s: invalid data segment: %d - data size value out of bounds.", + function, + data_segment_index ); - return( -1 ); + return( -1 ); + } + if( memory_copy( + &( data[ data_offset ] ), + data_segment->data, + data_segment->data_size ) == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_MEMORY, + LIBCERROR_MEMORY_ERROR_COPY_FAILED, + "%s: unable to copy data segment: %d.", + function, + data_segment_index ); + + return( -1 ); + } + data_offset += data_segment->data_size; } - return( result ); + return( 1 ); } -/* Copies the value data to a 64-bit integer +/* Retrieves the value data as a 8-bit integer value * Returns 1 if successful, 0 if value not be retrieved or -1 on error */ -int libfwevt_xml_value_copy_to_64bit( +int libfwevt_value_get_data_as_8bit_integer( libfwevt_xml_value_t *xml_value, - uint64_t *value_64bit, + uint8_t *value_8bit, libcerror_error_t **error ) { + libfwevt_data_segment_t *data_segment = NULL; libfwevt_internal_xml_value_t *internal_xml_value = NULL; - static char *function = "libfwevt_xml_value_copy_to_64bit"; - int result = 0; + static char *function = "libfwevt_value_get_data_as_8bit_integer"; + uint64_t integer_value = 0; if( xml_value == NULL ) { @@ -660,167 +851,107 @@ int libfwevt_xml_value_copy_to_64bit( } internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value; - result = libfvalue_value_copy_to_64bit( - internal_xml_value->value, - 0, - value_64bit, - error ); - - if( result == -1 ) + if( value_8bit == NULL ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_COPY_FAILED, - "%s: unable to copy value to 64-bit integer.", + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid value 8-bit.", function ); return( -1 ); } - return( result ); -} - -/* Retrieves the value data as a 8-bit integer value - * Returns 1 if successful, 0 if value not be retrieved or -1 on error - */ -int libfwevt_value_get_data_as_8bit_integer( - libfwevt_xml_value_t *xml_value, - uint8_t *value_8bit, - libcerror_error_t **error ) -{ - uint8_t utf8_string[ 4 ]; - - libfwevt_internal_xml_value_t *internal_xml_value = NULL; - static char *function = "libfwevt_value_get_data_as_8bit_integer"; - size_t utf8_string_index = 0; - uint8_t safe_value_8bit = 0; - int result = 0; - int value_type = 0; - - if( xml_value == NULL ) + if( ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_INTEGER_8BIT ) + && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_8BIT ) + && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_STRING_UTF16 ) ) + { + return( 0 ); + } + if( libcdata_array_get_entry_by_index( + internal_xml_value->data_segments, + 0, + (intptr_t **) &data_segment, + error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid XML value.", + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_GET_FAILED, + "%s: unable to retrieve data segment: 0.", function ); return( -1 ); } - internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value; - - if( libfvalue_value_get_type( - internal_xml_value->value, - &value_type, - error ) != 1 ) + if( data_segment == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve value type.", + LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, + "%s: missing data segment: 0.", function ); return( -1 ); } - if( ( value_type != LIBFVALUE_VALUE_TYPE_STRING_UTF16 ) - && ( value_type != LIBFVALUE_VALUE_TYPE_INTEGER_8BIT ) ) - { - return( 0 ); - } - if( value_type == LIBFVALUE_VALUE_TYPE_STRING_UTF16 ) + if( internal_xml_value->value_type == LIBFWEVT_VALUE_TYPE_STRING_UTF16 ) { - if( value_8bit == NULL ) + if( libfwevt_integer_copy_from_utf16_stream( + &integer_value, + data_segment->data, + data_segment->data_size, + error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid value 8-bit.", + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_COPY_FAILED, + "%s: unable to retrieve integer value from data segment: 0.", function ); return( -1 ); } - result = libfvalue_value_copy_to_utf8_string( - internal_xml_value->value, - 0, - utf8_string, - 4, - error ); - - if( result == -1 ) + if( integer_value > (uint64_t) UINT8_MAX ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_COPY_FAILED, - "%s: unable to copy value to UTF-8 string.", + LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, + "%s: invalid data segment: 0 - integer value out of bounds.", function ); return( -1 ); } - else if( result != 0 ) - { -/* TODO optimize by direclty using value data */ - for( utf8_string_index = 0; - utf8_string_index < 4; - utf8_string_index++ ) - { - if( utf8_string[ utf8_string_index ] == 0 ) - { - break; - } - if( ( utf8_string[ utf8_string_index ] < (uint8_t) '0' ) - || ( utf8_string[ utf8_string_index ] > (uint8_t) '9' ) ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, - "%s: invalid integer string.", - function ); - - return( -1 ); - } - safe_value_8bit *= 10; - safe_value_8bit += utf8_string[ utf8_string_index ] - (uint8_t) '0'; - } - if( utf8_string[ utf8_string_index ] != 0 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, - "%s: unsupported integer string.", - function ); - - return( -1 ); - } - *value_8bit = safe_value_8bit; - } } - else if( value_type == LIBFVALUE_VALUE_TYPE_INTEGER_8BIT ) + else { - result = libfvalue_value_copy_to_8bit( - internal_xml_value->value, - 0, - value_8bit, - error ); + if( data_segment->data == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, + "%s: invalid data segment: 0 - missing data.", + function ); - if( result == -1 ) + return( -1 ); + } + if( data_segment->data_size != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_COPY_FAILED, - "%s: unable to copy value to 8-bit integer.", + LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, + "%s: invalid data segment: 0 - unsupported data size.", function ); return( -1 ); } + integer_value = data_segment->data[ 0 ]; } - return( result ); + *value_8bit = (uint8_t) integer_value; + + return( 1 ); } /* Retrieves the value data as a 32-bit integer value @@ -831,14 +962,10 @@ int libfwevt_value_get_data_as_32bit_integer( uint32_t *value_32bit, libcerror_error_t **error ) { - uint8_t utf8_string[ 12 ]; - + libfwevt_data_segment_t *data_segment = NULL; libfwevt_internal_xml_value_t *internal_xml_value = NULL; static char *function = "libfwevt_value_get_data_as_32bit_integer"; - size_t utf8_string_index = 0; - uint32_t safe_value_32bit = 0; - int result = 0; - int value_type = 0; + uint64_t integer_value = 0; if( xml_value == NULL ) { @@ -853,117 +980,109 @@ int libfwevt_value_get_data_as_32bit_integer( } internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value; - if( libfvalue_value_get_type( - internal_xml_value->value, - &value_type, + if( value_32bit == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid value 32-bit.", + function ); + + return( -1 ); + } + if( ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_INTEGER_32BIT ) + && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_32BIT ) + && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_STRING_UTF16 ) ) + { + return( 0 ); + } + if( libcdata_array_get_entry_by_index( + internal_xml_value->data_segments, + 0, + (intptr_t **) &data_segment, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve value type.", + "%s: unable to retrieve data segment: 0.", function ); return( -1 ); } - if( ( value_type != LIBFVALUE_VALUE_TYPE_STRING_UTF16 ) - && ( value_type != LIBFVALUE_VALUE_TYPE_INTEGER_32BIT ) ) + if( data_segment == NULL ) { - return( 0 ); + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, + "%s: missing data segment: 0.", + function ); + + return( -1 ); } - if( value_type == LIBFVALUE_VALUE_TYPE_STRING_UTF16 ) + if( internal_xml_value->value_type == LIBFWEVT_VALUE_TYPE_STRING_UTF16 ) { - if( value_32bit == NULL ) + if( libfwevt_integer_copy_from_utf16_stream( + &integer_value, + data_segment->data, + data_segment->data_size, + error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid value 32-bit.", + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_COPY_FAILED, + "%s: unable to retrieve integer value from data segment: 0.", function ); return( -1 ); } - result = libfvalue_value_copy_to_utf8_string( - internal_xml_value->value, - 0, - utf8_string, - 12, - error ); - - if( result == -1 ) + if( integer_value > (uint64_t) UINT32_MAX ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_COPY_FAILED, - "%s: unable to copy value to UTF-8 string.", + LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, + "%s: invalid data segment: 0 - integer value out of bounds.", function ); return( -1 ); } - else if( result != 0 ) - { -/* TODO optimize by direclty using value data */ - for( utf8_string_index = 0; - utf8_string_index < 11; - utf8_string_index++ ) - { - if( utf8_string[ utf8_string_index ] == 0 ) - { - break; - } - if( ( utf8_string[ utf8_string_index ] < (uint8_t) '0' ) - || ( utf8_string[ utf8_string_index ] > (uint8_t) '9' ) ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, - "%s: invalid integer string.", - function ); - - return( -1 ); - } - safe_value_32bit *= 10; - safe_value_32bit += utf8_string[ utf8_string_index ] - (uint8_t) '0'; - } - if( utf8_string[ utf8_string_index ] != 0 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, - "%s: unsupported integer string.", - function ); - - return( -1 ); - } - *value_32bit = safe_value_32bit; - } } - else if( value_type == LIBFVALUE_VALUE_TYPE_INTEGER_32BIT ) + else { - result = libfvalue_value_copy_to_32bit( - internal_xml_value->value, - 0, - value_32bit, - error ); + if( data_segment->data == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, + "%s: invalid data segment: 0 - missing data.", + function ); - if( result == -1 ) + return( -1 ); + } + if( data_segment->data_size != 4 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_COPY_FAILED, - "%s: unable to copy value to 32-bit integer.", + LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, + "%s: invalid data segment: 0 - unsupported data size.", function ); return( -1 ); } + byte_stream_copy_to_uint32_little_endian( + data_segment->data, + integer_value ); } - return( result ); + *value_32bit = (uint32_t) integer_value; + + return( 1 ); } /* Retrieves the value data as a 64-bit integer value @@ -974,14 +1093,10 @@ int libfwevt_value_get_data_as_64bit_integer( uint64_t *value_64bit, libcerror_error_t **error ) { - uint8_t utf8_string[ 24 ]; - + libfwevt_data_segment_t *data_segment = NULL; libfwevt_internal_xml_value_t *internal_xml_value = NULL; static char *function = "libfwevt_value_get_data_as_64bit_integer"; - size_t utf8_string_index = 0; - uint64_t safe_value_64bit = 0; - int result = 0; - int value_type = 0; + uint64_t integer_value = 0; if( xml_value == NULL ) { @@ -996,117 +1111,98 @@ int libfwevt_value_get_data_as_64bit_integer( } internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value; - if( libfvalue_value_get_type( - internal_xml_value->value, - &value_type, + if( value_64bit == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid value 64-bit.", + function ); + + return( -1 ); + } + if( ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_INTEGER_64BIT ) + && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_64BIT ) + && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_STRING_UTF16 ) ) + { + return( 0 ); + } + if( libcdata_array_get_entry_by_index( + internal_xml_value->data_segments, + 0, + (intptr_t **) &data_segment, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve value type.", + "%s: unable to retrieve data segment: 0.", function ); return( -1 ); } - if( ( value_type != LIBFVALUE_VALUE_TYPE_STRING_UTF16 ) - && ( value_type != LIBFVALUE_VALUE_TYPE_INTEGER_64BIT ) ) + if( data_segment == NULL ) { - return( 0 ); + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, + "%s: missing data segment: 0.", + function ); + + return( -1 ); } - if( value_type == LIBFVALUE_VALUE_TYPE_STRING_UTF16 ) + if( internal_xml_value->value_type == LIBFWEVT_VALUE_TYPE_STRING_UTF16 ) { - if( value_64bit == NULL ) + if( libfwevt_integer_copy_from_utf16_stream( + &integer_value, + data_segment->data, + data_segment->data_size, + error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid value 64-bit.", + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_COPY_FAILED, + "%s: unable to retrieve integer value from data segment: 0.", function ); return( -1 ); } - result = libfvalue_value_copy_to_utf8_string( - internal_xml_value->value, - 0, - utf8_string, - 12, - error ); - - if( result == -1 ) + } + else + { + if( data_segment->data == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_COPY_FAILED, - "%s: unable to copy value to UTF-8 string.", + LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, + "%s: invalid data segment: 0 - missing data.", function ); return( -1 ); } - else if( result != 0 ) - { -/* TODO optimize by direclty using value data */ - for( utf8_string_index = 0; - utf8_string_index < 21; - utf8_string_index++ ) - { - if( utf8_string[ utf8_string_index ] == 0 ) - { - break; - } - if( ( utf8_string[ utf8_string_index ] < (uint8_t) '0' ) - || ( utf8_string[ utf8_string_index ] > (uint8_t) '9' ) ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, - "%s: invalid integer string.", - function ); - - return( -1 ); - } - safe_value_64bit *= 10; - safe_value_64bit += utf8_string[ utf8_string_index ] - (uint8_t) '0'; - } - if( utf8_string[ utf8_string_index ] != 0 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, - "%s: unsupported integer string.", - function ); - - return( -1 ); - } - *value_64bit = safe_value_64bit; - } - } - else if( value_type == LIBFVALUE_VALUE_TYPE_INTEGER_64BIT ) - { - result = libfvalue_value_copy_to_64bit( - internal_xml_value->value, - 0, - value_64bit, - error ); - - if( result == -1 ) + if( data_segment->data_size != 8 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_COPY_FAILED, - "%s: unable to copy value to 64-bit integer.", + LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, + "%s: invalid data segment: 0 - unsupported data size.", function ); return( -1 ); } + byte_stream_copy_to_uint64_little_endian( + data_segment->data, + integer_value ); } - return( result ); + *value_64bit = integer_value; + + return( 1 ); } /* Retrieves the value data as a 64-bit FILETIME value @@ -1117,12 +1213,10 @@ int libfwevt_value_get_data_as_filetime( uint64_t *filetime, libcerror_error_t **error ) { - uint8_t utf8_string[ 32 ]; - + libfwevt_data_segment_t *data_segment = NULL; libfwevt_internal_xml_value_t *internal_xml_value = NULL; static char *function = "libfwevt_value_get_data_as_filetime"; - int result = 0; - int value_type = 0; + uint64_t safe_filetime = 0; if( xml_value == NULL ) { @@ -1137,100 +1231,850 @@ int libfwevt_value_get_data_as_filetime( } internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value; - if( libfvalue_value_get_type( - internal_xml_value->value, - &value_type, - error ) != 1 ) + if( filetime == NULL ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve value type.", + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid FILETIME value.", function ); return( -1 ); } - if( ( value_type != LIBFVALUE_VALUE_TYPE_STRING_UTF16 ) - && ( value_type != LIBFVALUE_VALUE_TYPE_FILETIME ) ) + if( ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_FILETIME ) + && ( internal_xml_value->value_type != LIBFWEVT_VALUE_TYPE_STRING_UTF16 ) ) { return( 0 ); } - if( value_type == LIBFVALUE_VALUE_TYPE_STRING_UTF16 ) + if( libcdata_array_get_entry_by_index( + internal_xml_value->data_segments, + 0, + (intptr_t **) &data_segment, + error ) != 1 ) { - result = libfvalue_value_copy_to_utf8_string( - internal_xml_value->value, - 0, - utf8_string, - 32, - error ); - - if( result == -1 ) - { - libcerror_error_set( - error, + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_GET_FAILED, + "%s: unable to retrieve data segment: 0.", + function ); + + return( -1 ); + } + if( data_segment == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, + "%s: missing data segment: 0.", + function ); + + return( -1 ); + } + if( data_segment->data == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, + "%s: invalid data segment: 0 - missing data.", + function ); + + return( -1 ); + } + if( internal_xml_value->value_type == LIBFWEVT_VALUE_TYPE_STRING_UTF16 ) + { + if( libfwevt_filetime_copy_from_utf16_stream( + &safe_filetime, + data_segment->data, + data_segment->data_size, + error ) != 1 ) + { + libcerror_error_set( + error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, - "%s: unable to copy value to UTF-8 string.", + "%s: unable to copy data segment: 0 to FILTEIME.", function ); return( -1 ); } - else if( result != 0 ) + } + else + { + if( data_segment->data_size != 8 ) { -/* TODO optimize by direclty using value data */ - if( libfwevt_utf8_string_copy_to_filetime( - utf8_string, - 32, - filetime, - error ) != 1 ) + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, + "%s: invalid data segment: 0 - unsupported data size.", + function ); + + return( -1 ); + } + byte_stream_copy_to_uint64_little_endian( + data_segment->data, + safe_filetime ); + } + *filetime = safe_filetime; + + return( 1 ); +} + +/* Retrieves the size of the data segment formatted as an UTF-8 string + * The string size includes the end of string character + * Returns 1 if successful or -1 on error + */ +int libfwevt_internal_xml_value_get_data_segment_as_utf8_string_size( + libfwevt_internal_xml_value_t *internal_xml_value, + int data_segment_index, + size_t *utf8_string_size, + libcerror_error_t **error ) +{ + libfwevt_data_segment_t *data_segment = NULL; + static char *function = "libfwevt_internal_xml_value_get_data_segment_as_utf8_string_size"; + size_t base16_stream_size = 0; + size_t safe_utf8_string_size = 0; + uint32_t format_flags = 0; + int result = 0; + + if( internal_xml_value == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid XML value.", + function ); + + return( -1 ); + } + if( utf8_string_size == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-8 string size.", + function ); + + return( -1 ); + } + if( libfwevt_internal_xml_value_get_data_segment_with_cached_value( + internal_xml_value, + data_segment_index, + &data_segment, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_GET_FAILED, + "%s: unable to retrieve data segment: %d.", + function, + data_segment_index ); + + return( -1 ); + } + switch( internal_xml_value->value_type & 0x7f ) + { + case LIBFWEVT_VALUE_TYPE_STRING_UTF16: + if( data_segment->data_size == 0 ) + { + result = 1; + } + else + { + result = libuna_utf8_string_size_from_utf16_stream( + data_segment->data, + data_segment->data_size, + LIBUNA_ENDIAN_LITTLE, + &safe_utf8_string_size, + error ); + } + break; + + case LIBFWEVT_VALUE_TYPE_STRING_BYTE_STREAM: + if( data_segment->data_size == 0 ) + { + result = 1; + } + else + { +/* TODO pass codepage */ + result = libuna_utf8_string_size_from_byte_stream( + data_segment->data, + data_segment->data_size, + LIBUNA_CODEPAGE_WINDOWS_1252, + &safe_utf8_string_size, + error ); + } + break; + + case LIBFWEVT_VALUE_TYPE_INTEGER_8BIT: + result = libfwevt_integer_as_signed_decimal_get_string_size( + data_segment->value_64bit, + 8, + &safe_utf8_string_size, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_INTEGER_16BIT: + result = libfwevt_integer_as_signed_decimal_get_string_size( + data_segment->value_64bit, + 16, + &safe_utf8_string_size, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_INTEGER_32BIT: + result = libfwevt_integer_as_signed_decimal_get_string_size( + data_segment->value_64bit, + 32, + &safe_utf8_string_size, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_INTEGER_64BIT: + result = libfwevt_integer_as_signed_decimal_get_string_size( + data_segment->value_64bit, + 64, + &safe_utf8_string_size, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_8BIT: + case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_16BIT: + case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_32BIT: + case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_64BIT: + result = libfwevt_integer_as_unsigned_decimal_get_string_size( + data_segment->value_64bit, + &safe_utf8_string_size, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_FLOATING_POINT_32BIT: + result = libfwevt_float32_get_string_size( + (uint32_t) data_segment->value_64bit, + &safe_utf8_string_size, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_FLOATING_POINT_64BIT: + result = libfwevt_float64_get_string_size( + data_segment->value_64bit, + &safe_utf8_string_size, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_BOOLEAN: + if( data_segment->value_64bit == 0 ) + { + safe_utf8_string_size += 6; + } + else + { + safe_utf8_string_size += 5; + } + result = 1; + + break; + + case LIBFWEVT_VALUE_TYPE_BINARY_DATA: + if( data_segment->data_size == 0 ) + { + result = 1; + } + else + { + format_flags = LIBUNA_BASE16_VARIANT_CASE_UPPER | LIBUNA_BASE16_VARIANT_CHARACTER_LIMIT_NONE; + + result = libuna_base16_stream_size_from_byte_stream( + data_segment->data, + data_segment->data_size, + &base16_stream_size, + format_flags, + error ); + + if( result == 1 ) + { + safe_utf8_string_size += base16_stream_size + 1; + } + } + break; + + case LIBFWEVT_VALUE_TYPE_GUID: + result = libfguid_identifier_get_string_size( + data_segment->guid, + &safe_utf8_string_size, + LIBFGUID_STRING_FORMAT_FLAG_USE_UPPER_CASE | LIBFGUID_STRING_FORMAT_FLAG_USE_SURROUNDING_BRACES, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_FILETIME: + result = libfdatetime_filetime_get_string_size( + data_segment->filetime, + &safe_utf8_string_size, + LIBFDATETIME_STRING_FORMAT_TYPE_ISO8601 | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS | LIBFDATETIME_STRING_FORMAT_FLAG_TIMEZONE_INDICATOR, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_SYSTEMTIME: + result = libfdatetime_systemtime_get_string_size( + data_segment->systemtime, + &safe_utf8_string_size, + LIBFDATETIME_STRING_FORMAT_TYPE_ISO8601 | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS | LIBFDATETIME_STRING_FORMAT_FLAG_TIMEZONE_INDICATOR, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_NT_SECURITY_IDENTIFIER: + result = libfwnt_security_identifier_get_string_size( + data_segment->security_identifier, + &safe_utf8_string_size, + 0, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_HEXADECIMAL_INTEGER_32BIT: + safe_utf8_string_size = 11; + + result = 1; + break; + + case LIBFWEVT_VALUE_TYPE_HEXADECIMAL_INTEGER_64BIT: + safe_utf8_string_size = 19; + + result = 1; + break; + + default: + break; + } + if( result != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_COPY_FAILED, + "%s: unable to determine size UTF-8 string of data segment: %d.", + function, + data_segment_index ); + + return( -1 ); + } + *utf8_string_size = safe_utf8_string_size; + + return( 1 ); +} + +/* Retrieves the data segment formatted as an UTF-8 string + * Returns 1 if successful or -1 on error + */ +int libfwevt_internal_xml_value_get_data_segment_as_utf8_string( + libfwevt_internal_xml_value_t *internal_xml_value, + int data_segment_index, + uint8_t *utf8_string, + size_t utf8_string_size, + size_t *utf8_string_index, + libcerror_error_t **error ) +{ + libfwevt_data_segment_t *data_segment = NULL; + static char *function = "libfwevt_internal_xml_value_get_data_segment_as_utf8_string"; + size_t base16_stream_index = 0; + size_t safe_utf8_string_index = 0; + uint32_t format_flags = 0; + uint8_t number_of_characters = 0; + int result = 0; + + if( internal_xml_value == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid XML value.", + function ); + + return( -1 ); + } + if( utf8_string == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-8 string.", + function ); + + return( -1 ); + } + if( utf8_string_size > (size_t) SSIZE_MAX ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, + "%s: invalid UTF-8 string size value exceeds maximum.", + function ); + + return( -1 ); + } + if( utf8_string_index == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-8 string index.", + function ); + + return( -1 ); + } + if( libfwevt_internal_xml_value_get_data_segment_with_cached_value( + internal_xml_value, + data_segment_index, + &data_segment, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_GET_FAILED, + "%s: unable to retrieve data segment: %d.", + function, + data_segment_index ); + + return( -1 ); + } + switch( internal_xml_value->value_type & 0x7f ) + { + case LIBFWEVT_VALUE_TYPE_STRING_UTF16: + result = libuna_utf8_string_with_index_copy_from_utf16_stream( + utf8_string, + utf8_string_size, + utf8_string_index, + data_segment->data, + data_segment->data_size, + LIBUNA_ENDIAN_LITTLE, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_STRING_BYTE_STREAM: +/* TODO pass codepage */ + result = libuna_utf8_string_with_index_copy_from_byte_stream( + utf8_string, + utf8_string_size, + utf8_string_index, + data_segment->data, + data_segment->data_size, + LIBUNA_CODEPAGE_WINDOWS_1252, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_INTEGER_8BIT: + result = libfwevt_integer_as_signed_decimal_copy_to_utf8_string_with_index( + data_segment->value_64bit, + 8, + utf8_string, + utf8_string_size, + utf8_string_index, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_INTEGER_16BIT: + result = libfwevt_integer_as_signed_decimal_copy_to_utf8_string_with_index( + data_segment->value_64bit, + 16, + utf8_string, + utf8_string_size, + utf8_string_index, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_INTEGER_32BIT: + result = libfwevt_integer_as_signed_decimal_copy_to_utf8_string_with_index( + data_segment->value_64bit, + 32, + utf8_string, + utf8_string_size, + utf8_string_index, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_INTEGER_64BIT: + result = libfwevt_integer_as_signed_decimal_copy_to_utf8_string_with_index( + data_segment->value_64bit, + 64, + utf8_string, + utf8_string_size, + utf8_string_index, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_8BIT: + case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_16BIT: + case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_32BIT: + case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_64BIT: + result = libfwevt_integer_as_unsigned_decimal_copy_to_utf8_string_with_index( + data_segment->value_64bit, + utf8_string, + utf8_string_size, + utf8_string_index, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_FLOATING_POINT_32BIT: + result = libfwevt_float32_copy_to_utf8_string_with_index( + (uint32_t) data_segment->value_64bit, + utf8_string, + utf8_string_size, + utf8_string_index, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_FLOATING_POINT_64BIT: + result = libfwevt_float64_copy_to_utf8_string_with_index( + data_segment->value_64bit, + utf8_string, + utf8_string_size, + utf8_string_index, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_BOOLEAN: + if( data_segment->value_64bit == 0 ) + { + number_of_characters = 6; + } + else + { + number_of_characters = 5; + } + safe_utf8_string_index = *utf8_string_index; + + if( ( number_of_characters > utf8_string_size ) + || ( safe_utf8_string_index > ( utf8_string_size - number_of_characters ) ) ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_COPY_FAILED, - "%s: unable to copy UTF-8 string to FILETIME.", + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, + "%s: invalid UTF-8 string size value too small.", function ); return( -1 ); } - } + if( data_segment->value_64bit == 0 ) + { + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'f'; + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'a'; + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'l'; + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 's'; + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'e'; + } + else + { + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 't'; + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'r'; + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'u'; + utf8_string[ safe_utf8_string_index++ ] = (uint8_t) 'e'; + } + utf8_string[ safe_utf8_string_index++ ] = 0; + + *utf8_string_index = safe_utf8_string_index; + + result = 1; + + break; + + case LIBFWEVT_VALUE_TYPE_BINARY_DATA: + base16_stream_index = *utf8_string_index; + format_flags = LIBUNA_BASE16_VARIANT_CASE_UPPER | LIBUNA_BASE16_VARIANT_CHARACTER_LIMIT_NONE; + + result = libuna_base16_stream_with_index_copy_from_byte_stream( + (uint8_t *) utf8_string, + utf8_string_size, + &base16_stream_index, + data_segment->data, + data_segment->data_size, + format_flags, + error ); + + if( result == 1 ) + { + *utf8_string_index = base16_stream_index + 1; + } + break; + + case LIBFWEVT_VALUE_TYPE_GUID: + result = libfguid_identifier_copy_to_utf8_string_with_index( + data_segment->guid, + utf8_string, + utf8_string_size, + utf8_string_index, + LIBFGUID_STRING_FORMAT_FLAG_USE_UPPER_CASE | LIBFGUID_STRING_FORMAT_FLAG_USE_SURROUNDING_BRACES, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_FILETIME: + result = libfdatetime_filetime_copy_to_utf8_string_with_index( + data_segment->filetime, + utf8_string, + utf8_string_size, + utf8_string_index, + LIBFDATETIME_STRING_FORMAT_TYPE_ISO8601 | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS | LIBFDATETIME_STRING_FORMAT_FLAG_TIMEZONE_INDICATOR, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_SYSTEMTIME: + result = libfdatetime_systemtime_copy_to_utf8_string_with_index( + data_segment->systemtime, + utf8_string, + utf8_string_size, + utf8_string_index, + LIBFDATETIME_STRING_FORMAT_TYPE_ISO8601 | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS | LIBFDATETIME_STRING_FORMAT_FLAG_TIMEZONE_INDICATOR, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_NT_SECURITY_IDENTIFIER: + result = libfwnt_security_identifier_copy_to_utf8_string_with_index( + data_segment->security_identifier, + utf8_string, + utf8_string_size, + utf8_string_index, + 0, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_HEXADECIMAL_INTEGER_32BIT: + result = libfwevt_integer_as_hexadecimal_copy_to_utf8_string_with_index( + data_segment->value_64bit, + 32, + utf8_string, + utf8_string_size, + utf8_string_index, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_HEXADECIMAL_INTEGER_64BIT: + result = libfwevt_integer_as_hexadecimal_copy_to_utf8_string_with_index( + data_segment->value_64bit, + 64, + utf8_string, + utf8_string_size, + utf8_string_index, + error ); + break; + + default: + break; + } + if( result != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_COPY_FAILED, + "%s: unable to copy data segment: %d to UTF-8 string.", + function, + data_segment_index ); + + return( -1 ); } - else if( value_type == LIBFVALUE_VALUE_TYPE_FILETIME ) + return( 1 ); +} + +/* Retrieves the size of an UTF-8 encoded string of the value data + * Returns 1 if successful or -1 on error + */ +int libfwevt_xml_value_get_utf8_string_size( + libfwevt_xml_value_t *xml_value, + size_t *utf8_string_size, + libcerror_error_t **error ) +{ + static char *function = "libfwevt_xml_value_get_utf8_string_size"; + + if( libfwevt_xml_value_get_data_as_utf8_string_size( + xml_value, + utf8_string_size, + error ) != 1 ) { - result = libfvalue_value_copy_to_64bit( - internal_xml_value->value, - 0, - filetime, - error ); + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_GET_FAILED, + "%s: unable to retrieve size of UTF-8 string.", + function ); + + return( -1 ); + } + return( 1 ); +} - if( result == -1 ) +/* Copies the value data to an UTF-8 encoded string + * Returns 1 if successful or -1 on error + */ +int libfwevt_xml_value_copy_to_utf8_string( + libfwevt_xml_value_t *xml_value, + uint8_t *utf8_string, + size_t utf8_string_size, + libcerror_error_t **error ) +{ + static char *function = "libfwevt_xml_value_copy_to_utf8_string"; + + if( libfwevt_xml_value_get_data_as_utf8_string( + xml_value, + utf8_string, + utf8_string_size, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_GET_FAILED, + "%s: unable to retrieve size of UTF-8 string.", + function ); + + return( -1 ); + } + return( 1 ); +} + +/* Retrieves the size of the value data formatted as an UTF-8 string + * The string size includes the end of string character + * Returns 1 if successful or -1 on error + */ +int libfwevt_xml_value_get_data_as_utf8_string_size( + libfwevt_xml_value_t *xml_value, + size_t *utf8_string_size, + libcerror_error_t **error ) +{ + libfwevt_internal_xml_value_t *internal_xml_value = NULL; + static char *function = "libfwevt_xml_value_get_data_as_utf8_string_size"; + size_t data_segment_size = 0; + size_t safe_utf8_string_size = 0; + int data_segment_index = 0; + int number_of_data_segments = 0; + + if( xml_value == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid XML value.", + function ); + + return( -1 ); + } + internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value; + + if( utf8_string_size == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-8 string size.", + function ); + + return( -1 ); + } + if( libcdata_array_get_number_of_entries( + internal_xml_value->data_segments, + &number_of_data_segments, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_GET_FAILED, + "%s: unable to retrieve number of data segments.", + function ); + + return( -1 ); + } + for( data_segment_index = 0; + data_segment_index < number_of_data_segments; + data_segment_index++ ) + { + if( libfwevt_internal_xml_value_get_data_segment_as_utf8_string_size( + internal_xml_value, + data_segment_index, + &data_segment_size, + error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_COPY_FAILED, - "%s: unable to copy value to 64-bit integer.", - function ); + LIBCERROR_RUNTIME_ERROR_GET_FAILED, + "%s: unable to retrieve UTF-8 string size of element data segment: %d.", + function, + data_segment_index ); return( -1 ); } + if( data_segment_size > 1 ) + { + safe_utf8_string_size += data_segment_size - 1; + } } - return( result ); + *utf8_string_size = safe_utf8_string_size + 1; + + return( 1 ); } -/* Retrieves the size of an UTF-8 encoded string of the value data - * Returns 1 if successful, 0 if value could not be retrieved or -1 on error +/* Retrieves the data formatted as an UTF-8 string + * The string size should include the end of string character + * Returns 1 if successful or -1 on error */ -int libfwevt_xml_value_get_utf8_string_size_with_index( +int libfwevt_xml_value_get_data_as_utf8_string( libfwevt_xml_value_t *xml_value, - int value_entry_index, - size_t *utf8_string_size, + uint8_t *utf8_string, + size_t utf8_string_size, + libcerror_error_t **error ) +{ + static char *function = "libfwevt_xml_value_get_data_as_utf8_string"; + size_t utf8_string_index = 0; + + if( libfwevt_xml_value_get_data_as_utf8_string_with_index( + xml_value, + utf8_string, + utf8_string_size, + &utf8_string_index, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_GET_FAILED, + "%s: unable to retrieve size of UTF-8 string.", + function ); + + return( -1 ); + } + return( 1 ); +} + +/* Retrieves the data formatted as an UTF-8 string + * The string size should include the end of string character + * Returns 1 if successful or -1 on error + */ +int libfwevt_xml_value_get_data_as_utf8_string_with_index( + libfwevt_xml_value_t *xml_value, + uint8_t *utf8_string, + size_t utf8_string_size, + size_t *utf8_string_index, libcerror_error_t **error ) { libfwevt_internal_xml_value_t *internal_xml_value = NULL; - static char *function = "libfwevt_xml_value_get_utf8_string_size_with_index"; - int result = 0; + static char *function = "libfwevt_xml_value_get_data_as_utf8_string_with_index"; + size_t safe_utf8_string_index = 0; + int data_segment_index = 0; + int number_of_data_segments = 0; if( xml_value == NULL ) { @@ -1238,95 +2082,755 @@ int libfwevt_xml_value_get_utf8_string_size_with_index( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid XML value.", + "%s: invalid XML value.", + function ); + + return( -1 ); + } + internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value; + + if( utf8_string == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-8 string.", + function ); + + return( -1 ); + } + if( utf8_string_size > (size_t) SSIZE_MAX ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, + "%s: invalid UTF-8 string size value exceeds maximum.", + function ); + + return( -1 ); + } + if( utf8_string_index == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-8 string index.", + function ); + + return( -1 ); + } + safe_utf8_string_index = *utf8_string_index; + + if( libcdata_array_get_number_of_entries( + internal_xml_value->data_segments, + &number_of_data_segments, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_GET_FAILED, + "%s: unable to retrieve number of data segments.", + function ); + + return( -1 ); + } + for( data_segment_index = 0; + data_segment_index < number_of_data_segments; + data_segment_index++ ) + { + if( libfwevt_internal_xml_value_get_data_segment_as_utf8_string( + internal_xml_value, + data_segment_index, + utf8_string, + utf8_string_size, + &safe_utf8_string_index, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_COPY_FAILED, + "%s: unable to copy data segment: %d to UTF-8 string.", + function, + data_segment_index ); + + return( -1 ); + } + safe_utf8_string_index--; + } + if( safe_utf8_string_index >= utf8_string_size ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, + "%s: invalid UTF-8 string size value too small.", + function ); + + return( -1 ); + } + utf8_string[ safe_utf8_string_index++ ] = 0; + + *utf8_string_index = safe_utf8_string_index; + + return( 1 ); +} + +/* Retrieves the size of the data segment formatted as an UTF-16 string + * The string size includes the end of string character + * Returns 1 if successful or -1 on error + */ +int libfwevt_internal_xml_value_get_data_segment_as_utf16_string_size( + libfwevt_internal_xml_value_t *internal_xml_value, + int data_segment_index, + size_t *utf16_string_size, + libcerror_error_t **error ) +{ + libfwevt_data_segment_t *data_segment = NULL; + static char *function = "libfwevt_internal_xml_value_get_data_segment_as_utf16_string_size"; + size_t base16_stream_size = 0; + size_t safe_utf16_string_size = 0; + uint32_t format_flags = 0; + int result = 0; + + if( internal_xml_value == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid XML value.", + function ); + + return( -1 ); + } + if( utf16_string_size == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-16 string size.", + function ); + + return( -1 ); + } + if( libfwevt_internal_xml_value_get_data_segment_with_cached_value( + internal_xml_value, + data_segment_index, + &data_segment, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_GET_FAILED, + "%s: unable to retrieve data segment: %d.", + function, + data_segment_index ); + + return( -1 ); + } + switch( internal_xml_value->value_type & 0x7f ) + { + case LIBFWEVT_VALUE_TYPE_STRING_UTF16: + if( data_segment->data_size == 0 ) + { + result = 1; + } + else + { + result = libuna_utf16_string_size_from_utf16_stream( + data_segment->data, + data_segment->data_size, + LIBUNA_ENDIAN_LITTLE, + &safe_utf16_string_size, + error ); + } + break; + + case LIBFWEVT_VALUE_TYPE_STRING_BYTE_STREAM: + if( data_segment->data_size == 0 ) + { + result = 1; + } + else + { +/* TODO pass codepage */ + result = libuna_utf16_string_size_from_byte_stream( + data_segment->data, + data_segment->data_size, + LIBUNA_CODEPAGE_WINDOWS_1252, + &safe_utf16_string_size, + error ); + } + break; + + case LIBFWEVT_VALUE_TYPE_INTEGER_8BIT: + result = libfwevt_integer_as_signed_decimal_get_string_size( + data_segment->value_64bit, + 8, + &safe_utf16_string_size, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_INTEGER_16BIT: + result = libfwevt_integer_as_signed_decimal_get_string_size( + data_segment->value_64bit, + 16, + &safe_utf16_string_size, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_INTEGER_32BIT: + result = libfwevt_integer_as_signed_decimal_get_string_size( + data_segment->value_64bit, + 32, + &safe_utf16_string_size, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_INTEGER_64BIT: + result = libfwevt_integer_as_signed_decimal_get_string_size( + data_segment->value_64bit, + 64, + &safe_utf16_string_size, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_8BIT: + case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_16BIT: + case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_32BIT: + case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_64BIT: + result = libfwevt_integer_as_unsigned_decimal_get_string_size( + data_segment->value_64bit, + &safe_utf16_string_size, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_FLOATING_POINT_32BIT: + result = libfwevt_float32_get_string_size( + (uint32_t) data_segment->value_64bit, + &safe_utf16_string_size, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_FLOATING_POINT_64BIT: + result = libfwevt_float64_get_string_size( + data_segment->value_64bit, + &safe_utf16_string_size, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_BOOLEAN: + if( data_segment->value_64bit == 0 ) + { + safe_utf16_string_size += 6; + } + else + { + safe_utf16_string_size += 5; + } + result = 1; + + break; + + case LIBFWEVT_VALUE_TYPE_BINARY_DATA: + if( data_segment->data_size == 0 ) + { + result = 1; + } + else + { + format_flags = LIBUNA_BASE16_VARIANT_CASE_UPPER | LIBUNA_BASE16_VARIANT_CHARACTER_LIMIT_NONE; + + if( _BYTE_STREAM_HOST_IS_ENDIAN_BIG ) + { + format_flags |= LIBUNA_BASE16_VARIANT_ENCODING_UTF16_BIG_ENDIAN; + } + else if( _BYTE_STREAM_HOST_IS_ENDIAN_LITTLE ) + { + format_flags |= LIBUNA_BASE16_VARIANT_ENCODING_UTF16_LITTLE_ENDIAN; + } + result = libuna_base16_stream_size_from_byte_stream( + data_segment->data, + data_segment->data_size, + &base16_stream_size, + format_flags, + error ); + + if( result == 1 ) + { + safe_utf16_string_size += ( base16_stream_size / 2 ) + 1; + } + } + break; + + case LIBFWEVT_VALUE_TYPE_GUID: + result = libfguid_identifier_get_string_size( + data_segment->guid, + &safe_utf16_string_size, + LIBFGUID_STRING_FORMAT_FLAG_USE_UPPER_CASE | LIBFGUID_STRING_FORMAT_FLAG_USE_SURROUNDING_BRACES, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_FILETIME: + result = libfdatetime_filetime_get_string_size( + data_segment->filetime, + &safe_utf16_string_size, + LIBFDATETIME_STRING_FORMAT_TYPE_ISO8601 | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS | LIBFDATETIME_STRING_FORMAT_FLAG_TIMEZONE_INDICATOR, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_SYSTEMTIME: + result = libfdatetime_systemtime_get_string_size( + data_segment->systemtime, + &safe_utf16_string_size, + LIBFDATETIME_STRING_FORMAT_TYPE_ISO8601 | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS | LIBFDATETIME_STRING_FORMAT_FLAG_TIMEZONE_INDICATOR, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_NT_SECURITY_IDENTIFIER: + result = libfwnt_security_identifier_get_string_size( + data_segment->security_identifier, + &safe_utf16_string_size, + 0, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_HEXADECIMAL_INTEGER_32BIT: + safe_utf16_string_size = 11; + + result = 1; + break; + + case LIBFWEVT_VALUE_TYPE_HEXADECIMAL_INTEGER_64BIT: + safe_utf16_string_size = 19; + + result = 1; + break; + + default: + break; + } + if( result != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_COPY_FAILED, + "%s: unable to determine size UTF-16 string of data segment: %d.", + function, + data_segment_index ); + + return( -1 ); + } + *utf16_string_size = safe_utf16_string_size; + + return( 1 ); +} + +/* Retrieves the data segment formatted as an UTF-16 string + * Returns 1 if successful or -1 on error + */ +int libfwevt_internal_xml_value_get_data_segment_as_utf16_string( + libfwevt_internal_xml_value_t *internal_xml_value, + int data_segment_index, + uint16_t *utf16_string, + size_t utf16_string_size, + size_t *utf16_string_index, + libcerror_error_t **error ) +{ + libfwevt_data_segment_t *data_segment = NULL; + static char *function = "libfwevt_internal_xml_value_get_data_segment_as_utf16_string"; + size_t base16_stream_index = 0; + size_t safe_utf16_string_index = 0; + uint32_t format_flags = 0; + uint8_t number_of_characters = 0; + int result = 0; + + if( internal_xml_value == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid XML value.", + function ); + + return( -1 ); + } + if( utf16_string == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-16 string.", + function ); + + return( -1 ); + } + if( utf16_string_size > (size_t) SSIZE_MAX ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, + "%s: invalid UTF-16 string size value exceeds maximum.", + function ); + + return( -1 ); + } + if( utf16_string_index == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-16 string index.", function ); return( -1 ); } - internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value; + if( libfwevt_internal_xml_value_get_data_segment_with_cached_value( + internal_xml_value, + data_segment_index, + &data_segment, + error ) != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_GET_FAILED, + "%s: unable to retrieve data segment: %d.", + function, + data_segment_index ); + + return( -1 ); + } + switch( internal_xml_value->value_type & 0x7f ) + { + case LIBFWEVT_VALUE_TYPE_STRING_UTF16: + result = libuna_utf16_string_with_index_copy_from_utf16_stream( + utf16_string, + utf16_string_size, + utf16_string_index, + data_segment->data, + data_segment->data_size, + LIBUNA_ENDIAN_LITTLE, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_STRING_BYTE_STREAM: +/* TODO pass codepage */ + result = libuna_utf16_string_with_index_copy_from_byte_stream( + utf16_string, + utf16_string_size, + utf16_string_index, + data_segment->data, + data_segment->data_size, + LIBUNA_CODEPAGE_WINDOWS_1252, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_INTEGER_8BIT: + result = libfwevt_integer_as_signed_decimal_copy_to_utf16_string_with_index( + data_segment->value_64bit, + 8, + utf16_string, + utf16_string_size, + utf16_string_index, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_INTEGER_16BIT: + result = libfwevt_integer_as_signed_decimal_copy_to_utf16_string_with_index( + data_segment->value_64bit, + 16, + utf16_string, + utf16_string_size, + utf16_string_index, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_INTEGER_32BIT: + result = libfwevt_integer_as_signed_decimal_copy_to_utf16_string_with_index( + data_segment->value_64bit, + 32, + utf16_string, + utf16_string_size, + utf16_string_index, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_INTEGER_64BIT: + result = libfwevt_integer_as_signed_decimal_copy_to_utf16_string_with_index( + data_segment->value_64bit, + 64, + utf16_string, + utf16_string_size, + utf16_string_index, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_8BIT: + case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_16BIT: + case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_32BIT: + case LIBFWEVT_VALUE_TYPE_UNSIGNED_INTEGER_64BIT: + result = libfwevt_integer_as_unsigned_decimal_copy_to_utf16_string_with_index( + data_segment->value_64bit, + utf16_string, + utf16_string_size, + utf16_string_index, + error ); + break; + + + case LIBFWEVT_VALUE_TYPE_FLOATING_POINT_32BIT: + result = libfwevt_float32_copy_to_utf16_string_with_index( + (uint32_t) data_segment->value_64bit, + utf16_string, + utf16_string_size, + utf16_string_index, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_FLOATING_POINT_64BIT: + result = libfwevt_float64_copy_to_utf16_string_with_index( + data_segment->value_64bit, + utf16_string, + utf16_string_size, + utf16_string_index, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_BOOLEAN: + if( data_segment->value_64bit == 0 ) + { + number_of_characters = 6; + } + else + { + number_of_characters = 5; + } + safe_utf16_string_index = *utf16_string_index; + + if( ( number_of_characters > utf16_string_size ) + || ( safe_utf16_string_index > ( utf16_string_size - number_of_characters ) ) ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, + "%s: invalid UTF-16 string size value too small.", + function ); + + return( -1 ); + } + if( data_segment->value_64bit == 0 ) + { + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'f'; + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'a'; + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'l'; + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 's'; + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'e'; + } + else + { + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 't'; + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'r'; + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'u'; + utf16_string[ safe_utf16_string_index++ ] = (uint16_t) 'e'; + } + utf16_string[ safe_utf16_string_index++ ] = 0; + + *utf16_string_index = safe_utf16_string_index; + + result = 1; + + break; - result = libfvalue_value_get_utf8_string_size( - internal_xml_value->value, - value_entry_index, - utf8_string_size, - error ); + case LIBFWEVT_VALUE_TYPE_BINARY_DATA: + base16_stream_index = *utf16_string_index * 2; + format_flags = LIBUNA_BASE16_VARIANT_CASE_UPPER | LIBUNA_BASE16_VARIANT_CHARACTER_LIMIT_NONE; - if( result == -1 ) + if( _BYTE_STREAM_HOST_IS_ENDIAN_BIG ) + { + format_flags |= LIBUNA_BASE16_VARIANT_ENCODING_UTF16_BIG_ENDIAN; + } + else if( _BYTE_STREAM_HOST_IS_ENDIAN_LITTLE ) + { + format_flags |= LIBUNA_BASE16_VARIANT_ENCODING_UTF16_LITTLE_ENDIAN; + } + result = libuna_base16_stream_with_index_copy_from_byte_stream( + (uint8_t *) utf16_string, + utf16_string_size * 2, + &base16_stream_index, + data_segment->data, + data_segment->data_size, + format_flags, + error ); + + if( result == 1 ) + { + *utf16_string_index = ( base16_stream_index / 2 ) + 1; + } + break; + + case LIBFWEVT_VALUE_TYPE_GUID: + result = libfguid_identifier_copy_to_utf16_string_with_index( + data_segment->guid, + utf16_string, + utf16_string_size, + utf16_string_index, + LIBFGUID_STRING_FORMAT_FLAG_USE_UPPER_CASE | LIBFGUID_STRING_FORMAT_FLAG_USE_SURROUNDING_BRACES, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_FILETIME: + result = libfdatetime_filetime_copy_to_utf16_string_with_index( + data_segment->filetime, + utf16_string, + utf16_string_size, + utf16_string_index, + LIBFDATETIME_STRING_FORMAT_TYPE_ISO8601 | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS | LIBFDATETIME_STRING_FORMAT_FLAG_TIMEZONE_INDICATOR, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_SYSTEMTIME: + result = libfdatetime_systemtime_copy_to_utf16_string_with_index( + data_segment->systemtime, + utf16_string, + utf16_string_size, + utf16_string_index, + LIBFDATETIME_STRING_FORMAT_TYPE_ISO8601 | LIBFDATETIME_STRING_FORMAT_FLAG_DATE_TIME_NANO_SECONDS | LIBFDATETIME_STRING_FORMAT_FLAG_TIMEZONE_INDICATOR, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_NT_SECURITY_IDENTIFIER: + result = libfwnt_security_identifier_copy_to_utf16_string_with_index( + data_segment->security_identifier, + utf16_string, + utf16_string_size, + utf16_string_index, + 0, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_HEXADECIMAL_INTEGER_32BIT: + result = libfwevt_integer_as_hexadecimal_copy_to_utf16_string_with_index( + data_segment->value_64bit, + 32, + utf16_string, + utf16_string_size, + utf16_string_index, + error ); + break; + + case LIBFWEVT_VALUE_TYPE_HEXADECIMAL_INTEGER_64BIT: + result = libfwevt_integer_as_hexadecimal_copy_to_utf16_string_with_index( + data_segment->value_64bit, + 64, + utf16_string, + utf16_string_size, + utf16_string_index, + error ); + break; + + default: + break; + } + if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, - "%s: unable to determine size UTF-8 string of value: %d.", + "%s: unable to copy data segment: %d to UTF-16 string.", function, - value_entry_index ); + data_segment_index ); return( -1 ); } - return( result ); + return( 1 ); } -/* Copies the value data to an UTF-8 encoded string - * Returns 1 if successful, 0 if value could not be retrieved or -1 on error +/* Retrieves the size of an UTF-16 encoded string of the value data + * Returns 1 if successful or -1 on error */ -int libfwevt_xml_value_copy_to_utf8_string_with_index( +int libfwevt_xml_value_get_utf16_string_size( libfwevt_xml_value_t *xml_value, - int value_entry_index, - uint8_t *utf8_string, - size_t utf8_string_size, - size_t *utf8_string_index, + size_t *utf16_string_size, libcerror_error_t **error ) { - libfwevt_internal_xml_value_t *internal_xml_value = NULL; - static char *function = "libfwevt_xml_value_copy_to_utf8_string_with_index"; - int result = 0; + static char *function = "libfwevt_xml_value_get_utf16_string_size"; - if( xml_value == NULL ) + if( libfwevt_xml_value_get_data_as_utf16_string_size( + xml_value, + utf16_string_size, + error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid XML value.", + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_GET_FAILED, + "%s: unable to retrieve size of UTF-16 string.", function ); return( -1 ); } - internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value; + return( 1 ); +} - result = libfvalue_value_copy_to_utf8_string_with_index( - internal_xml_value->value, - value_entry_index, - utf8_string, - utf8_string_size, - utf8_string_index, - error ); +/* Copies the value data to an UTF-16 encoded string + * Returns 1 if successful or -1 on error + */ +int libfwevt_xml_value_copy_to_utf16_string( + libfwevt_xml_value_t *xml_value, + uint16_t *utf16_string, + size_t utf16_string_size, + libcerror_error_t **error ) +{ + static char *function = "libfwevt_xml_value_copy_to_utf16_string"; - if( result == -1 ) + if( libfwevt_xml_value_get_data_as_utf16_string( + xml_value, + utf16_string, + utf16_string_size, + error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_COPY_FAILED, - "%s: unable to copy value to UTF-8 string.", + LIBCERROR_RUNTIME_ERROR_GET_FAILED, + "%s: unable to retrieve size of UTF-16 string.", function ); return( -1 ); } - return( result ); + return( 1 ); } -/* Retrieves the size of an UTF-8 encoded string of the value data +/* Retrieves the size of the value data formatted as an UTF-16 string + * The string size includes the end of string character * Returns 1 if successful or -1 on error */ -int libfwevt_xml_value_get_utf8_string_size( +int libfwevt_xml_value_get_data_as_utf16_string_size( libfwevt_xml_value_t *xml_value, - size_t *utf8_string_size, + size_t *utf16_string_size, libcerror_error_t **error ) { libfwevt_internal_xml_value_t *internal_xml_value = NULL; - static char *function = "libfwevt_xml_value_get_utf8_string_size"; - int result = 0; + static char *function = "libfwevt_xml_value_get_data_as_utf16_string_size"; + size_t data_segment_size = 0; + size_t safe_utf16_string_size = 0; + int data_segment_index = 0; + int number_of_data_segments = 0; if( xml_value == NULL ) { @@ -1341,102 +2845,109 @@ int libfwevt_xml_value_get_utf8_string_size( } internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value; - result = libfvalue_value_get_utf8_string_size( - internal_xml_value->value, - 0, - utf8_string_size, - error ); + if( utf16_string_size == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid UTF-16 string size.", + function ); - if( result == -1 ) + return( -1 ); + } + if( libcdata_array_get_number_of_entries( + internal_xml_value->data_segments, + &number_of_data_segments, + error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_COPY_FAILED, - "%s: unable to determine size UTF-8 string.", + LIBCERROR_RUNTIME_ERROR_GET_FAILED, + "%s: unable to retrieve number of data segments.", function ); return( -1 ); } - else if( result == 0 ) + for( data_segment_index = 0; + data_segment_index < number_of_data_segments; + data_segment_index++ ) { - if( utf8_string_size == NULL ) + if( libfwevt_internal_xml_value_get_data_segment_as_utf16_string_size( + internal_xml_value, + data_segment_index, + &data_segment_size, + error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid UTF-8 string size.", - function ); + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_GET_FAILED, + "%s: unable to retrieve UTF-16 string size of element data segment: %d.", + function, + data_segment_index ); return( -1 ); } - *utf8_string_size = 0; + if( data_segment_size > 1 ) + { + safe_utf16_string_size += data_segment_size - 1; + } } + *utf16_string_size = safe_utf16_string_size + 1; + return( 1 ); } -/* Copies the value data to an UTF-8 encoded string - * Returns 1 if successful, 0 if value could not be retrieved or -1 on error +/* Retrieves the data formatted as an UTF-16 string + * The string size should include the end of string character + * Returns 1 if successful or -1 on error */ -int libfwevt_xml_value_copy_to_utf8_string( +int libfwevt_xml_value_get_data_as_utf16_string( libfwevt_xml_value_t *xml_value, - uint8_t *utf8_string, - size_t utf8_string_size, + uint16_t *utf16_string, + size_t utf16_string_size, libcerror_error_t **error ) { - libfwevt_internal_xml_value_t *internal_xml_value = NULL; - static char *function = "libfwevt_xml_value_copy_to_utf8_string"; - size_t utf8_string_index = 0; - int result = 0; - - if( xml_value == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid XML value.", - function ); - - return( -1 ); - } - internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value; - - result = libfvalue_value_copy_to_utf8_string_with_index( - internal_xml_value->value, - 0, - utf8_string, - utf8_string_size, - &utf8_string_index, - error ); - - if( result == -1 ) + static char *function = "libfwevt_xml_value_get_data_as_utf16_string"; + size_t utf16_string_index = 0; + + if( libfwevt_xml_value_get_data_as_utf16_string_with_index( + xml_value, + utf16_string, + utf16_string_size, + &utf16_string_index, + error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_COPY_FAILED, - "%s: unable to copy value: %d to UTF-8 string.", + LIBCERROR_RUNTIME_ERROR_GET_FAILED, + "%s: unable to retrieve size of UTF-16 string.", function ); return( -1 ); } - return( result ); + return( 1 ); } -/* Retrieves the size of an UTF-16 encoded string of the value data - * Returns 1 if successful, 0 if value could not be retrieved or -1 on error +/* Retrieves the data formatted as an UTF-16 string + * The string size should include the end of string character + * Returns 1 if successful or -1 on error */ -int libfwevt_xml_value_get_utf16_string_size_with_index( +int libfwevt_xml_value_get_data_as_utf16_string_with_index( libfwevt_xml_value_t *xml_value, - int value_entry_index, - size_t *utf16_string_size, + uint16_t *utf16_string, + size_t utf16_string_size, + size_t *utf16_string_index, libcerror_error_t **error ) { libfwevt_internal_xml_value_t *internal_xml_value = NULL; - static char *function = "libfwevt_xml_value_get_utf16_string_size_with_index"; - int result = 0; + static char *function = "libfwevt_xml_value_get_data_as_utf16_string_with_index"; + size_t safe_utf16_string_index = 0; + int data_segment_index = 0; + int number_of_data_segments = 0; if( xml_value == NULL ) { @@ -1451,200 +2962,113 @@ int libfwevt_xml_value_get_utf16_string_size_with_index( } internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value; - result = libfvalue_value_get_utf16_string_size( - internal_xml_value->value, - value_entry_index, - utf16_string_size, - error ); - - if( result == -1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_COPY_FAILED, - "%s: unable to determine size UTF-16 string of value: %d.", - function, - value_entry_index ); - - return( -1 ); - } - return( result ); -} - -/* Copies the value data to an UTF-16 encoded string - * Returns 1 if successful, 0 if value could not be retrieved or -1 on error - */ -int libfwevt_xml_value_copy_to_utf16_string_with_index( - libfwevt_xml_value_t *xml_value, - int value_entry_index, - uint16_t *utf16_string, - size_t utf16_string_size, - size_t *utf16_string_index, - libcerror_error_t **error ) -{ - libfwevt_internal_xml_value_t *internal_xml_value = NULL; - static char *function = "libfwevt_xml_value_copy_to_utf16_string_with_index"; - int result = 0; - - if( xml_value == NULL ) + if( utf16_string == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid XML value.", + "%s: invalid UTF-16 string.", function ); return( -1 ); } - internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value; - - result = libfvalue_value_copy_to_utf16_string_with_index( - internal_xml_value->value, - value_entry_index, - utf16_string, - utf16_string_size, - utf16_string_index, - error ); - - if( result == -1 ) + if( utf16_string_size > (size_t) SSIZE_MAX ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_COPY_FAILED, - "%s: unable to copy value: %d to UTF-16 string.", - function, - value_entry_index ); + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, + "%s: invalid UTF-16 string size value exceeds maximum.", + function ); return( -1 ); } - return( result ); -} - -/* Retrieves the size of an UTF-16 encoded string of the value data - * Returns 1 if successful or -1 on error - */ -int libfwevt_xml_value_get_utf16_string_size( - libfwevt_xml_value_t *xml_value, - size_t *utf16_string_size, - libcerror_error_t **error ) -{ - libfwevt_internal_xml_value_t *internal_xml_value = NULL; - static char *function = "libfwevt_xml_value_get_utf16_string_size"; - int result = 0; - - if( xml_value == NULL ) + if( utf16_string_index == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid XML value.", + "%s: invalid UTF-16 string index.", function ); return( -1 ); } - internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value; - - result = libfvalue_value_get_utf16_string_size( - internal_xml_value->value, - 0, - utf16_string_size, - error ); + safe_utf16_string_index = *utf16_string_index; - if( result == -1 ) + if( libcdata_array_get_number_of_entries( + internal_xml_value->data_segments, + &number_of_data_segments, + error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_COPY_FAILED, - "%s: unable to determine size UTF-16 string.", + LIBCERROR_RUNTIME_ERROR_GET_FAILED, + "%s: unable to retrieve number of data segments.", function ); return( -1 ); } - else if( result == 0 ) + for( data_segment_index = 0; + data_segment_index < number_of_data_segments; + data_segment_index++ ) { - if( utf16_string_size == NULL ) + if( libfwevt_internal_xml_value_get_data_segment_as_utf16_string( + internal_xml_value, + data_segment_index, + utf16_string, + utf16_string_size, + &safe_utf16_string_index, + error ) != 1 ) { libcerror_error_set( error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid UTF-16 string size.", - function ); + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_COPY_FAILED, + "%s: unable to copy data segment: %d to UTF-16 string.", + function, + data_segment_index ); return( -1 ); } - *utf16_string_size = 0; + safe_utf16_string_index--; } - return( 1 ); -} - -/* Copies the value data to an UTF-16 encoded string - * Returns 1 if successful, 0 if value could not be retrieved or -1 on error - */ -int libfwevt_xml_value_copy_to_utf16_string( - libfwevt_xml_value_t *xml_value, - uint16_t *utf16_string, - size_t utf16_string_size, - libcerror_error_t **error ) -{ - libfwevt_internal_xml_value_t *internal_xml_value = NULL; - static char *function = "libfwevt_xml_value_copy_to_utf16_string"; - size_t utf16_string_index = 0; - int result = 0; - - if( xml_value == NULL ) + if( safe_utf16_string_index >= utf16_string_size ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid XML value.", + LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, + "%s: invalid UTF-16 string size value too small.", function ); return( -1 ); } - internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value; - - result = libfvalue_value_copy_to_utf16_string_with_index( - internal_xml_value->value, - 0, - utf16_string, - utf16_string_size, - &utf16_string_index, - error ); + utf16_string[ safe_utf16_string_index++ ] = 0; - if( result == -1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_COPY_FAILED, - "%s: unable to copy value to UTF-16 string.", - function ); + *utf16_string_index = safe_utf16_string_index; - return( -1 ); - } - return( result ); + return( 1 ); } #if defined( HAVE_DEBUG_OUTPUT ) -/* Prints the XML value +/* Prints the value of a specific data segment * Returns 1 if successful or -1 on error */ -int libfwevt_debug_print_xml_value( +int libfwevt_debug_print_xml_value_with_index( libfwevt_xml_value_t *xml_value, - int value_entry_index, - uint8_t flags, + int data_segment_index, libcerror_error_t **error ) { + system_character_t *value_string = NULL; libfwevt_internal_xml_value_t *internal_xml_value = NULL; - static char *function = "libfwevt_debug_print_xml_value"; + static char *function = "libfwevt_debug_print_xml_value_with_index"; + size_t value_string_index = 0; + size_t value_string_size = 0; + int result = 0; if( xml_value == NULL ) { @@ -1659,22 +3083,101 @@ int libfwevt_debug_print_xml_value( } internal_xml_value = (libfwevt_internal_xml_value_t *) xml_value; - if( libfvalue_value_print( - internal_xml_value->value, - value_entry_index, - flags, - error ) != 1 ) +#if defined( HAVE_WIDE_SYSTEM_CHARACTER ) + result = libfwevt_internal_xml_value_get_data_segment_as_utf16_string_size( + internal_xml_value, + data_segment_index, + &value_string_size, + error ); +#else + result = libfwevt_internal_xml_value_get_data_segment_as_utf8_string_size( + internal_xml_value, + data_segment_index, + &value_string_size, + error ); +#endif + if( result != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, - "%s: unable to print value.", + LIBCERROR_RUNTIME_ERROR_GET_FAILED, + "%s: unable to determine size of value string.", function ); - return( -1 ); + goto on_error; + } + if( value_string_size > 0 ) + { + if( value_string_size > (size_t) ( SSIZE_MAX / sizeof( system_character_t ) ) ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, + "%s: invalid name string size value exceeds maximum.", + function ); + + goto on_error; + } + value_string = system_string_allocate( + value_string_size ); + + if( value_string == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_MEMORY, + LIBCERROR_MEMORY_ERROR_INSUFFICIENT, + "%s: unable to create value string.", + function ); + + goto on_error; + } +#if defined( HAVE_WIDE_SYSTEM_CHARACTER ) + result = libfwevt_internal_xml_value_get_data_segment_as_utf16_string( + internal_xml_value, + data_segment_index, + (libuna_utf16_character_t *) value_string, + value_string_size, + &value_string_index, + error ); +#else + result = libfwevt_internal_xml_value_get_data_segment_as_utf8_string( + internal_xml_value, + data_segment_index, + (libuna_utf8_character_t *) value_string, + value_string_size, + &value_string_index, + error ); +#endif + if( result != 1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_GET_FAILED, + "%s: unable to retrieve value string.", + function ); + + goto on_error; + } + libcnotify_printf( + "%" PRIs_SYSTEM "", + value_string ); + + memory_free( + value_string ); } return( 1 ); + +on_error: + if( value_string != NULL ) + { + memory_free( + value_string ); + } + return( -1 ); } #endif /* defined( HAVE_DEBUG_OUTPUT ) */ diff --git a/libfwevt/libfwevt_xml_value.h b/libfwevt/libfwevt_xml_value.h index c3f9c66..a910c2d 100644 --- a/libfwevt/libfwevt_xml_value.h +++ b/libfwevt/libfwevt_xml_value.h @@ -25,9 +25,11 @@ #include #include +#include "libfwevt_data_segment.h" #include "libfwevt_extern.h" +#include "libfwevt_libcdata.h" #include "libfwevt_libcerror.h" -#include "libfwevt_libfvalue.h" +#include "libfwevt_libcnotify.h" #include "libfwevt_types.h" #if defined( __cplusplus ) @@ -40,16 +42,20 @@ struct libfwevt_internal_xml_value { /* The value type */ - int value_type; + uint8_t value_type; - /* The value (value) + /* The data segments */ - libfvalue_value_t *value; + libcdata_array_t *data_segments; + + /* The data size + */ + size_t data_size; }; int libfwevt_xml_value_initialize( libfwevt_xml_value_t **xml_value, - int type, + uint8_t value_type, libcerror_error_t **error ); LIBFWEVT_EXTERN \ @@ -61,43 +67,27 @@ int libfwevt_internal_xml_value_free( libfwevt_internal_xml_value_t **internal_xml_value, libcerror_error_t **error ); -int libfwevt_xml_value_set_data( +int libfwevt_xml_value_get_type( libfwevt_xml_value_t *xml_value, - const uint8_t *data, - size_t data_size, - int encoding, - uint8_t flags, + uint8_t *value_type, libcerror_error_t **error ); -int libfwevt_xml_value_set_format_flags( +int libfwevt_xml_value_get_number_of_data_segments( libfwevt_xml_value_t *xml_value, - uint32_t format_flags, + int *number_of_data_segments, libcerror_error_t **error ); -int libfwevt_xml_value_append_data( - libfwevt_xml_value_t *xml_value, - int *value_entry_index, - const uint8_t *data, - size_t data_size, - int encoding, +int libfwevt_internal_xml_value_get_data_segment_with_cached_value( + libfwevt_internal_xml_value_t *internal_xml_value, + int data_segment_index, + libfwevt_data_segment_t **data_segment, libcerror_error_t **error ); -ssize_t libfwevt_xml_value_type_set_data_string( - libfwevt_xml_value_t *xml_value, - const uint8_t *data, - size_t data_size, - int encoding, - uint8_t flags, - libcerror_error_t **error ); - -int libfwevt_xml_value_get_type( - libfwevt_xml_value_t *xml_value, - int *value_type, - libcerror_error_t **error ); - -int libfwevt_xml_value_get_number_of_value_entries( +int libfwevt_xml_value_append_data_segment( libfwevt_xml_value_t *xml_value, - int *number_of_value_entries, + const uint8_t *data, + size_t data_size, + int *data_segment_index, libcerror_error_t **error ); LIBFWEVT_EXTERN \ @@ -113,24 +103,6 @@ int libfwevt_xml_value_copy_data( size_t data_size, libcerror_error_t **error ); -LIBFWEVT_EXTERN \ -int libfwevt_xml_value_copy_to_8bit( - libfwevt_xml_value_t *xml_value, - uint8_t *value_8bit, - libcerror_error_t **error ); - -LIBFWEVT_EXTERN \ -int libfwevt_xml_value_copy_to_32bit( - libfwevt_xml_value_t *xml_value, - uint32_t *value_32bit, - libcerror_error_t **error ); - -LIBFWEVT_EXTERN \ -int libfwevt_xml_value_copy_to_64bit( - libfwevt_xml_value_t *xml_value, - uint64_t *value_64bit, - libcerror_error_t **error ); - LIBFWEVT_EXTERN \ int libfwevt_value_get_data_as_8bit_integer( libfwevt_xml_value_t *xml_value, @@ -155,15 +127,15 @@ int libfwevt_value_get_data_as_filetime( uint64_t *filetime, libcerror_error_t **error ); -int libfwevt_xml_value_get_utf8_string_size_with_index( - libfwevt_xml_value_t *xml_value, - int value_entry_index, +int libfwevt_internal_xml_value_get_data_segment_as_utf8_string_size( + libfwevt_internal_xml_value_t *internal_xml_value, + int data_segment_index, size_t *utf8_string_size, libcerror_error_t **error ); -int libfwevt_xml_value_copy_to_utf8_string_with_index( - libfwevt_xml_value_t *xml_value, - int value_entry_index, +int libfwevt_internal_xml_value_get_data_segment_as_utf8_string( + libfwevt_internal_xml_value_t *internal_xml_value, + int data_segment_index, uint8_t *utf8_string, size_t utf8_string_size, size_t *utf8_string_index, @@ -182,15 +154,35 @@ int libfwevt_xml_value_copy_to_utf8_string( size_t utf8_string_size, libcerror_error_t **error ); -int libfwevt_xml_value_get_utf16_string_size_with_index( +LIBFWEVT_EXTERN \ +int libfwevt_xml_value_get_data_as_utf8_string_size( + libfwevt_xml_value_t *xml_value, + size_t *utf8_string_size, + libcerror_error_t **error ); + +LIBFWEVT_EXTERN \ +int libfwevt_xml_value_get_data_as_utf8_string( + libfwevt_xml_value_t *xml_value, + uint8_t *utf8_string, + size_t utf8_string_size, + libcerror_error_t **error ); + +int libfwevt_xml_value_get_data_as_utf8_string_with_index( libfwevt_xml_value_t *xml_value, - int value_entry_index, + uint8_t *utf8_string, + size_t utf8_string_size, + size_t *utf8_string_index, + libcerror_error_t **error ); + +int libfwevt_internal_xml_value_get_data_segment_as_utf16_string_size( + libfwevt_internal_xml_value_t *internal_xml_value, + int data_segment_index, size_t *utf16_string_size, libcerror_error_t **error ); -int libfwevt_xml_value_copy_to_utf16_string_with_index( - libfwevt_xml_value_t *xml_value, - int value_entry_index, +int libfwevt_internal_xml_value_get_data_segment_as_utf16_string( + libfwevt_internal_xml_value_t *internal_xml_value, + int data_segment_index, uint16_t *utf16_string, size_t utf16_string_size, size_t *utf16_string_index, @@ -209,12 +201,31 @@ int libfwevt_xml_value_copy_to_utf16_string( size_t utf16_string_size, libcerror_error_t **error ); +LIBFWEVT_EXTERN \ +int libfwevt_xml_value_get_data_as_utf16_string_size( + libfwevt_xml_value_t *xml_value, + size_t *utf16_string_size, + libcerror_error_t **error ); + +LIBFWEVT_EXTERN \ +int libfwevt_xml_value_get_data_as_utf16_string( + libfwevt_xml_value_t *xml_value, + uint16_t *utf16_string, + size_t utf16_string_size, + libcerror_error_t **error ); + +int libfwevt_xml_value_get_data_as_utf16_string_with_index( + libfwevt_xml_value_t *xml_value, + uint16_t *utf16_string, + size_t utf16_string_size, + size_t *utf16_string_index, + libcerror_error_t **error ); + #if defined( HAVE_DEBUG_OUTPUT ) -int libfwevt_debug_print_xml_value( +int libfwevt_debug_print_xml_value_with_index( libfwevt_xml_value_t *xml_value, - int value_entry_index, - uint8_t flags, + int data_segment_index, libcerror_error_t **error ); #endif /* defined( HAVE_DEBUG_OUTPUT ) */ diff --git a/m4/libfvalue.m4 b/m4/libfvalue.m4 deleted file mode 100644 index 2a79f7d..0000000 --- a/m4/libfvalue.m4 +++ /dev/null @@ -1,691 +0,0 @@ -dnl Checks for libfvalue required headers and functions -dnl -dnl Version: 20240413 - -dnl Function to detect if libfvalue is available -dnl ac_libfvalue_dummy is used to prevent AC_CHECK_LIB adding unnecessary -l arguments -AC_DEFUN([AX_LIBFVALUE_CHECK_LIB], - [AS_IF( - [test "x$ac_cv_enable_shared_libs" = xno || test "x$ac_cv_with_libfvalue" = xno], - [ac_cv_libfvalue=no], - [ac_cv_libfvalue=check - dnl Check if the directory provided as parameter exists - dnl For both --with-libfvalue which returns "yes" and --with-libfvalue= which returns "" - dnl treat them as auto-detection. - AS_IF( - [test "x$ac_cv_with_libfvalue" != x && test "x$ac_cv_with_libfvalue" != xauto-detect && test "x$ac_cv_with_libfvalue" != xyes], - [AS_IF( - [test -d "$ac_cv_with_libfvalue"], - [CFLAGS="$CFLAGS -I${ac_cv_with_libfvalue}/include" - LDFLAGS="$LDFLAGS -L${ac_cv_with_libfvalue}/lib"], - [AC_MSG_FAILURE( - [no such directory: $ac_cv_with_libfvalue], - [1]) - ]) - ], - [dnl Check for a pkg-config file - AS_IF( - [test "x$cross_compiling" != "xyes" && test "x$PKGCONFIG" != "x"], - [PKG_CHECK_MODULES( - [libfvalue], - [libfvalue >= 20200711], - [ac_cv_libfvalue=yes], - [ac_cv_libfvalue=check]) - ]) - AS_IF( - [test "x$ac_cv_libfvalue" = xyes], - [ac_cv_libfvalue_CPPFLAGS="$pkg_cv_libfvalue_CFLAGS" - ac_cv_libfvalue_LIBADD="$pkg_cv_libfvalue_LIBS"]) - ]) - - AS_IF( - [test "x$ac_cv_libfvalue" = xcheck], - [dnl Check for headers - AC_CHECK_HEADERS([libfvalue.h]) - - AS_IF( - [test "x$ac_cv_header_libfvalue_h" = xno], - [ac_cv_libfvalue=no], - [dnl Check for the individual functions - ac_cv_libfvalue=yes - - AC_CHECK_LIB( - fvalue, - libfvalue_get_version, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - dnl Data handle functions - AC_CHECK_LIB( - fvalue, - libfvalue_data_handle_initialize, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_data_handle_free, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_data_handle_clone, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_data_handle_clear, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_data_handle_get_data, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_data_handle_set_data, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_data_handle_get_data_flags, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_data_handle_set_data_flags, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_data_handle_get_number_of_value_entries, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_data_handle_get_value_entry, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_data_handle_set_value_entry, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_data_handle_append_value_entry, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - dnl Integer functions - AC_CHECK_LIB( - fvalue, - libfvalue_string_size_from_integer, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_utf8_string_copy_from_integer, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_utf8_string_with_index_copy_from_integer, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_utf8_string_copy_to_integer, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_utf8_string_with_index_copy_to_integer, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_utf16_string_copy_from_integer, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_utf16_string_with_index_copy_from_integer, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_utf16_string_copy_to_integer, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_utf16_string_with_index_copy_to_integer, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_utf32_string_copy_from_integer, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_utf32_string_with_index_copy_from_integer, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_utf32_string_copy_to_integer, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_utf32_string_with_index_copy_to_integer, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - dnl String functions - AC_CHECK_LIB( - fvalue, - libfvalue_utf8_string_split, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_utf16_string_split, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - dnl Split string functions - AC_CHECK_LIB( - fvalue, - libfvalue_split_utf8_string_free, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_split_utf8_string_get_string, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_split_utf8_string_get_number_of_segments, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_split_utf8_string_get_segment_by_index, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_split_utf16_string_free, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_split_utf16_string_get_string, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_split_utf16_string_get_number_of_segments, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_split_utf16_string_get_segment_by_index, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - dnl Table functions - AC_CHECK_LIB( - fvalue, - libfvalue_table_initialize, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_table_free, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_table_resize, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_table_clone, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_table_get_number_of_values, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_table_get_index_by_identifier, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_table_get_value_by_index, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_table_get_value_by_identifier, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_table_set_value_by_index, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_table_set_value, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_table_copy_from_utf8_xml_string, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - dnl Value functions - AC_CHECK_LIB( - fvalue, - libfvalue_value_initialize, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_free, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_clone, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_clear, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_value_get_type, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_value_get_identifier, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_set_identifier, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_value_get_data_handle, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_has_data, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_get_data_size, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_get_data, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_set_data, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_copy_data, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_value_get_format_flags, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_set_format_flags, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_value_get_number_of_value_entries, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_get_value_entry, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_set_value_entry, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_append_value_entry, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_value_copy_from_boolean, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_copy_to_boolean, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_value_copy_from_8bit, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_copy_to_8bit, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_value_copy_from_16bit, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_copy_to_16bit, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_value_copy_from_32bit, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_copy_to_32bit, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_value_copy_from_64bit, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_copy_to_64bit, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_value_copy_from_float, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_copy_to_float, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_value_copy_from_double, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_copy_to_double, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_value_copy_from_utf8_string, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_get_utf8_string_size, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_copy_to_utf8_string, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_copy_to_utf8_string_with_index, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_value_copy_from_utf16_string, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_get_utf16_string_size, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_copy_to_utf16_string, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_copy_to_utf16_string_with_index, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_value_copy_from_utf32_string, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_get_utf32_string_size, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_copy_to_utf32_string, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_copy_to_utf32_string_with_index, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_value_read_from_file_stream, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_write_to_file_stream, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - dnl Value type functions - AC_CHECK_LIB( - fvalue, - libfvalue_value_type_initialize, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_type_initialize_with_data_handle, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_value_type_set_data_string, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - AC_CHECK_LIB( - fvalue, - libfvalue_value_type_append_data_string, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - AC_CHECK_LIB( - fvalue, - libfvalue_value_type_set_data_strings_array, - [ac_cv_libfvalue_dummy=yes], - [ac_cv_libfvalue=no]) - - ac_cv_libfvalue_LIBADD="-lfvalue"]) - ]) - - AS_IF( - [test "x$ac_cv_libfvalue" != xyes && test "x$ac_cv_with_libfvalue" != x && test "x$ac_cv_with_libfvalue" != xauto-detect && test "x$ac_cv_with_libfvalue" != xyes], - [AC_MSG_FAILURE( - [unable to find supported libfvalue in directory: $ac_cv_with_libfvalue], - [1]) - ]) - ]) - - AS_IF( - [test "x$ac_cv_libfvalue" = xyes], - [AC_DEFINE( - [HAVE_LIBFVALUE], - [1], - [Define to 1 if you have the `fvalue' library (-lfvalue).]) - ]) - - AS_IF( - [test "x$ac_cv_libfvalue" = xyes], - [AC_SUBST( - [HAVE_LIBFVALUE], - [1]) ], - [AC_SUBST( - [HAVE_LIBFVALUE], - [0]) - ]) - ]) - -dnl Function to detect if libfvalue dependencies are available -AC_DEFUN([AX_LIBFVALUE_CHECK_LOCAL], - [dnl No additional checks. - - ac_cv_libfvalue_CPPFLAGS="-I../libfvalue -I\$(top_srcdir)/libfvalue"; - ac_cv_libfvalue_LIBADD="../libfvalue/libfvalue.la"; - - ac_cv_libfvalue=local - ]) - -dnl Function to detect how to enable libfvalue -AC_DEFUN([AX_LIBFVALUE_CHECK_ENABLE], - [AX_COMMON_ARG_WITH( - [libfvalue], - [libfvalue], - [search for libfvalue in includedir and libdir or in the specified DIR, or no if to use local version], - [auto-detect], - [DIR]) - - dnl Check for a shared library version - AX_LIBFVALUE_CHECK_LIB - - dnl Check if the dependencies for the local library version - AS_IF( - [test "x$ac_cv_libfvalue" != xyes], - [AX_LIBFVALUE_CHECK_LOCAL - - AC_DEFINE( - [HAVE_LOCAL_LIBFVALUE], - [1], - [Define to 1 if the local version of libfvalue is used.]) - AC_SUBST( - [HAVE_LOCAL_LIBFVALUE], - [1]) - ]) - - AM_CONDITIONAL( - [HAVE_LOCAL_LIBFVALUE], - [test "x$ac_cv_libfvalue" = xlocal]) - AS_IF( - [test "x$ac_cv_libfvalue_CPPFLAGS" != "x"], - [AC_SUBST( - [LIBFVALUE_CPPFLAGS], - [$ac_cv_libfvalue_CPPFLAGS]) - ]) - AS_IF( - [test "x$ac_cv_libfvalue_LIBADD" != "x"], - [AC_SUBST( - [LIBFVALUE_LIBADD], - [$ac_cv_libfvalue_LIBADD]) - ]) - - AS_IF( - [test "x$ac_cv_libfvalue" = xyes], - [AC_SUBST( - [ax_libfvalue_pc_libs_private], - [-lfvalue]) - ]) - - AS_IF( - [test "x$ac_cv_libfvalue" = xyes], - [AC_SUBST( - [ax_libfvalue_spec_requires], - [libfvalue]) - AC_SUBST( - [ax_libfvalue_spec_build_requires], - [libfvalue-devel]) - ]) - ]) - diff --git a/m4/libfwnt.m4 b/m4/libfwnt.m4 new file mode 100644 index 0000000..5337c17 --- /dev/null +++ b/m4/libfwnt.m4 @@ -0,0 +1,320 @@ +dnl Checks for libfwnt required headers and functions +dnl +dnl Version: 20240413 + +dnl Function to detect if libfwnt is available +dnl ac_libfwnt_dummy is used to prevent AC_CHECK_LIB adding unnecessary -l arguments +AC_DEFUN([AX_LIBFWNT_CHECK_LIB], + [AS_IF( + [test "x$ac_cv_enable_shared_libs" = xno || test "x$ac_cv_with_libfwnt" = xno], + [ac_cv_libfwnt=no], + [ac_cv_libfwnt=check + dnl Check if the directory provided as parameter exists + dnl For both --with-libfwnt which returns "yes" and --with-libfwnt= which returns "" + dnl treat them as auto-detection. + AS_IF( + [test "x$ac_cv_with_libfwnt" != x && test "x$ac_cv_with_libfwnt" != xauto-detect && test "x$ac_cv_with_libfwnt" != xyes], + [AS_IF( + [test -d "$ac_cv_with_libfwnt"], + [CFLAGS="$CFLAGS -I${ac_cv_with_libfwnt}/include" + LDFLAGS="$LDFLAGS -L${ac_cv_with_libfwnt}/lib"], + [AC_MSG_FAILURE( + [no such directory: $ac_cv_with_libfwnt], + [1]) + ]) + ], + [dnl Check for a pkg-config file + AS_IF( + [test "x$cross_compiling" != "xyes" && test "x$PKGCONFIG" != "x"], + [PKG_CHECK_MODULES( + [libfwnt], + [libfwnt >= 20191217], + [ac_cv_libfwnt=yes], + [ac_cv_libfwnt=check]) + ]) + AS_IF( + [test "x$ac_cv_libfwnt" = xyes], + [ac_cv_libfwnt_CPPFLAGS="$pkg_cv_libfwnt_CFLAGS" + ac_cv_libfwnt_LIBADD="$pkg_cv_libfwnt_LIBS"]) + ]) + + AS_IF( + [test "x$ac_cv_libfwnt" = xcheck], + [dnl Check for headers + AC_CHECK_HEADERS([libfwnt.h]) + + AS_IF( + [test "x$ac_cv_header_libfwnt_h" = xno], + [ac_cv_libfwnt=no], + [dnl Check for the individual functions + ac_cv_libfwnt=yes + + AC_CHECK_LIB( + fwnt, + libfwnt_get_version, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + + dnl Security descriptor functions + AC_CHECK_LIB( + fwnt, + libfwnt_security_descriptor_initialize, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + AC_CHECK_LIB( + fwnt, + libfwnt_security_descriptor_free, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + + AC_CHECK_LIB( + fwnt, + libfwnt_security_descriptor_copy_from_byte_stream, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + AC_CHECK_LIB( + fwnt, + libfwnt_security_descriptor_get_owner, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + AC_CHECK_LIB( + fwnt, + libfwnt_security_descriptor_get_group, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + AC_CHECK_LIB( + fwnt, + libfwnt_security_descriptor_get_discretionary_acl, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + AC_CHECK_LIB( + fwnt, + libfwnt_security_descriptor_get_system_acl, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + + dnl Security identifier (SID) functions + AC_CHECK_LIB( + fwnt, + libfwnt_security_identifier_initialize, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + AC_CHECK_LIB( + fwnt, + libfwnt_security_identifier_free, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + + AC_CHECK_LIB( + fwnt, + libfwnt_security_identifier_copy_from_byte_stream, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + AC_CHECK_LIB( + fwnt, + libfwnt_security_identifier_get_string_size, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + AC_CHECK_LIB( + fwnt, + libfwnt_security_identifier_copy_to_utf8_string, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + AC_CHECK_LIB( + fwnt, + libfwnt_security_identifier_copy_to_utf8_string_with_index, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + AC_CHECK_LIB( + fwnt, + libfwnt_security_identifier_copy_to_utf16_string, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + AC_CHECK_LIB( + fwnt, + libfwnt_security_identifier_copy_to_utf16_string_with_index, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + AC_CHECK_LIB( + fwnt, + libfwnt_security_identifier_copy_to_utf32_string, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + AC_CHECK_LIB( + fwnt, + libfwnt_security_identifier_copy_to_utf32_string_with_index, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + + dnl Access control list (ACL) functions + AC_CHECK_LIB( + fwnt, + libfwnt_access_control_list_free, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + + AC_CHECK_LIB( + fwnt, + libfwnt_access_control_list_get_number_of_entries, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + AC_CHECK_LIB( + fwnt, + libfwnt_access_control_list_get_entry_by_index, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + + dnl Access control entry (ACE) functions + AC_CHECK_LIB( + fwnt, + libfwnt_access_control_entry_free, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + + AC_CHECK_LIB( + fwnt, + libfwnt_access_control_entry_get_type, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + AC_CHECK_LIB( + fwnt, + libfwnt_access_control_entry_get_flags, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + AC_CHECK_LIB( + fwnt, + libfwnt_access_control_entry_get_access_mask, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + AC_CHECK_LIB( + fwnt, + libfwnt_access_control_entry_get_security_identifier, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + + dnl LZNT1 functions + AC_CHECK_LIB( + fwnt, + libfwnt_lznt1_decompress, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + + dnl LZXPRESS functions + AC_CHECK_LIB( + fwnt, + libfwnt_lzx_decompress, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + + dnl LZXPRESS functions + AC_CHECK_LIB( + fwnt, + libfwnt_lzxpress_decompress, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + AC_CHECK_LIB( + fwnt, + libfwnt_lzxpress_huffman_decompress, + [ac_cv_libfwnt_dummy=yes], + [ac_cv_libfwnt=no]) + + ac_cv_libfwnt_LIBADD="-lfwnt"]) + ]) + + AS_IF( + [test "x$ac_cv_libfwnt" != xyes && test "x$ac_cv_with_libfwnt" != x && test "x$ac_cv_with_libfwnt" != xauto-detect && test "x$ac_cv_with_libfwnt" != xyes], + [AC_MSG_FAILURE( + [unable to find supported libfwnt in directory: $ac_cv_with_libfwnt], + [1]) + ]) + ]) + + AS_IF( + [test "x$ac_cv_libfwnt" = xyes], + [AC_DEFINE( + [HAVE_LIBFWNT], + [1], + [Define to 1 if you have the `fwnt' library (-lfwnt).]) + ]) + + AS_IF( + [test "x$ac_cv_libfwnt" = xyes], + [AC_SUBST( + [HAVE_LIBFWNT], + [1]) ], + [AC_SUBST( + [HAVE_LIBFWNT], + [0]) + ]) + ]) + +dnl Function to detect if libfwnt dependencies are available +AC_DEFUN([AX_LIBFWNT_CHECK_LOCAL], + [dnl No additional checks. + + ac_cv_libfwnt_CPPFLAGS="-I../libfwnt -I\$(top_srcdir)/libfwnt"; + ac_cv_libfwnt_LIBADD="../libfwnt/libfwnt.la"; + + ac_cv_libfwnt=local + ]) + +dnl Function to detect how to enable libfwnt +AC_DEFUN([AX_LIBFWNT_CHECK_ENABLE], + [AX_COMMON_ARG_WITH( + [libfwnt], + [libfwnt], + [search for libfwnt in includedir and libdir or in the specified DIR, or no if to use local version], + [auto-detect], + [DIR]) + + dnl Check for a shared library version + AX_LIBFWNT_CHECK_LIB + + dnl Check if the dependencies for the local library version + AS_IF( + [test "x$ac_cv_libfwnt" != xyes], + [AX_LIBFWNT_CHECK_LOCAL + + AC_DEFINE( + [HAVE_LOCAL_LIBFWNT], + [1], + [Define to 1 if the local version of libfwnt is used.]) + AC_SUBST( + [HAVE_LOCAL_LIBFWNT], + [1]) + ]) + + AM_CONDITIONAL( + [HAVE_LOCAL_LIBFWNT], + [test "x$ac_cv_libfwnt" = xlocal]) + AS_IF( + [test "x$ac_cv_libfwnt_CPPFLAGS" != "x"], + [AC_SUBST( + [LIBFWNT_CPPFLAGS], + [$ac_cv_libfwnt_CPPFLAGS]) + ]) + AS_IF( + [test "x$ac_cv_libfwnt_LIBADD" != "x"], + [AC_SUBST( + [LIBFWNT_LIBADD], + [$ac_cv_libfwnt_LIBADD]) + ]) + + AS_IF( + [test "x$ac_cv_libfwnt" = xyes], + [AC_SUBST( + [ax_libfwnt_pc_libs_private], + [-lfwnt]) + ]) + + AS_IF( + [test "x$ac_cv_libfwnt" = xyes], + [AC_SUBST( + [ax_libfwnt_spec_requires], + [libfwnt]) + AC_SUBST( + [ax_libfwnt_spec_build_requires], + [libfwnt-devel]) + ]) + ]) + diff --git a/manuals/libfwevt.3 b/manuals/libfwevt.3 index aef5b9e..3113624 100644 --- a/manuals/libfwevt.3 +++ b/manuals/libfwevt.3 @@ -1,4 +1,4 @@ -.Dd April 27, 2024 +.Dd April 28, 2024 .Dt libfwevt 3 .Os libfwevt .Sh NAME @@ -245,13 +245,13 @@ XML value functions .Ft int .Fn libfwevt_value_get_data_as_64bit_integer "libfwevt_xml_value_t *xml_value" "uint64_t *value_64bit" "libfwevt_error_t **error" .Ft int -.Fn libfwevt_xml_value_get_utf8_string_size "libfwevt_xml_value_t *xml_value" "size_t *utf8_string_size" "libfwevt_error_t **error" +.Fn libfwevt_xml_value_get_data_as_utf8_string_size "libfwevt_xml_value_t *xml_value" "size_t *utf8_string_size" "libfwevt_error_t **error" .Ft int -.Fn libfwevt_xml_value_copy_to_utf8_string "libfwevt_xml_value_t *xml_value" "uint8_t *utf8_string" "size_t utf8_string_size" "libfwevt_error_t **error" +.Fn libfwevt_xml_value_get_data_as_utf8_string "libfwevt_xml_value_t *xml_value" "uint8_t *utf8_string" "size_t utf8_string_size" "libfwevt_error_t **error" .Ft int -.Fn libfwevt_xml_value_get_utf16_string_size "libfwevt_xml_value_t *xml_value" "size_t *utf16_string_size" "libfwevt_error_t **error" +.Fn libfwevt_xml_value_get_data_as_utf16_string_size "libfwevt_xml_value_t *xml_value" "size_t *utf16_string_size" "libfwevt_error_t **error" .Ft int -.Fn libfwevt_xml_value_copy_to_utf16_string "libfwevt_xml_value_t *xml_value" "uint16_t *utf16_string" "size_t utf16_string_size" "libfwevt_error_t **error" +.Fn libfwevt_xml_value_get_data_as_utf16_string "libfwevt_xml_value_t *xml_value" "uint16_t *utf16_string" "size_t utf16_string_size" "libfwevt_error_t **error" .Sh DESCRIPTION The .Fn libfwevt_get_version diff --git a/msvscpp/Makefile.am b/msvscpp/Makefile.am index 4494639..c0a2e63 100644 --- a/msvscpp/Makefile.am +++ b/msvscpp/Makefile.am @@ -1,5 +1,6 @@ MSVSCPP_FILES = \ fwevt_test_channel/fwevt_test_channel.vcproj \ + fwevt_test_data_segment/fwevt_test_data_segment.vcproj \ fwevt_test_date_time/fwevt_test_date_time.vcproj \ fwevt_test_error/fwevt_test_error.vcproj \ fwevt_test_event/fwevt_test_event.vcproj \ @@ -25,8 +26,8 @@ MSVSCPP_FILES = \ libcthreads/libcthreads.vcproj \ libfdatetime/libfdatetime.vcproj \ libfguid/libfguid.vcproj \ - libfvalue/libfvalue.vcproj \ libfwevt/libfwevt.vcproj \ + libfwnt/libfwnt.vcproj \ libuna/libuna.vcproj \ pyfwevt/pyfwevt.vcproj \ libfwevt.sln diff --git a/msvscpp/fwevt_test_channel/fwevt_test_channel.vcproj b/msvscpp/fwevt_test_channel/fwevt_test_channel.vcproj index 7c136de..b51beda 100644 --- a/msvscpp/fwevt_test_channel/fwevt_test_channel.vcproj +++ b/msvscpp/fwevt_test_channel/fwevt_test_channel.vcproj @@ -41,8 +41,8 @@ /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/msvscpp/fwevt_test_date_time/fwevt_test_date_time.vcproj b/msvscpp/fwevt_test_date_time/fwevt_test_date_time.vcproj index d668a83..5d9bbeb 100644 --- a/msvscpp/fwevt_test_date_time/fwevt_test_date_time.vcproj +++ b/msvscpp/fwevt_test_date_time/fwevt_test_date_time.vcproj @@ -41,8 +41,8 @@ /> - - diff --git a/msvscpp/fwevt_test_xml_template_value/fwevt_test_xml_template_value.vcproj b/msvscpp/fwevt_test_xml_template_value/fwevt_test_xml_template_value.vcproj index 8bb8ac2..d2d4bf9 100644 --- a/msvscpp/fwevt_test_xml_template_value/fwevt_test_xml_template_value.vcproj +++ b/msvscpp/fwevt_test_xml_template_value/fwevt_test_xml_template_value.vcproj @@ -41,8 +41,8 @@ /> - - diff --git a/msvscpp/libfwevt.sln b/msvscpp/libfwevt.sln index 28e5e36..894bed5 100644 --- a/msvscpp/libfwevt.sln +++ b/msvscpp/libfwevt.sln @@ -15,7 +15,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libfwevt", "libfwevt\libfwe {5C6EAD13-CCA8-4B03-8495-EEE2E3092468} = {5C6EAD13-CCA8-4B03-8495-EEE2E3092468} {B306CB83-6915-4684-A67B-55CE66C9C4C4} = {B306CB83-6915-4684-A67B-55CE66C9C4C4} {9B4ACD98-1EDF-40A6-9866-CEB40FF75082} = {9B4ACD98-1EDF-40A6-9866-CEB40FF75082} - {4A81A573-8E94-4C37-96C6-AAB627CA2D9B} = {4A81A573-8E94-4C37-96C6-AAB627CA2D9B} + {43C6AFAD-E3EF-49C1-AA9B-A85E91A94684} = {43C6AFAD-E3EF-49C1-AA9B-A85E91A94684} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pyfwevt", "pyfwevt\pyfwevt.vcproj", "{5A75D56F-262C-499A-9874-E44CA99DAE30}" @@ -43,6 +43,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fwevt_test_channel", "fwevt {C5D33EBC-535D-474C-870A-B96A4B30850D} = {C5D33EBC-535D-474C-870A-B96A4B30850D} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fwevt_test_data_segment", "fwevt_test_data_segment\fwevt_test_data_segment.vcproj", "{3C123E2E-5CF0-405A-8E41-ADC0465AE9E0}" + ProjectSection(ProjectDependencies) = postProject + {B97706AC-46E5-4C2A-836E-582A74DC6A68} = {B97706AC-46E5-4C2A-836E-582A74DC6A68} + {C5D33EBC-535D-474C-870A-B96A4B30850D} = {C5D33EBC-535D-474C-870A-B96A4B30850D} + EndProjectSection +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fwevt_test_date_time", "fwevt_test_date_time\fwevt_test_date_time.vcproj", "{51112D1D-1694-4F1B-B82F-6C1C1EDA954E}" ProjectSection(ProjectDependencies) = postProject {B97706AC-46E5-4C2A-836E-582A74DC6A68} = {B97706AC-46E5-4C2A-836E-582A74DC6A68} @@ -155,20 +161,17 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fwevt_test_xml_value", "fwe {C5D33EBC-535D-474C-870A-B96A4B30850D} = {C5D33EBC-535D-474C-870A-B96A4B30850D} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libuna", "libuna\libuna.vcproj", "{5C6EAD13-CCA8-4B03-8495-EEE2E3092468}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libfwnt", "libfwnt\libfwnt.vcproj", "{43C6AFAD-E3EF-49C1-AA9B-A85E91A94684}" ProjectSection(ProjectDependencies) = postProject {C5D33EBC-535D-474C-870A-B96A4B30850D} = {C5D33EBC-535D-474C-870A-B96A4B30850D} + {D9A25DD4-1F17-4546-B662-5986E82720FC} = {D9A25DD4-1F17-4546-B662-5986E82720FC} + {D3AB00F9-6704-4899-90C4-CB3BED88E7AA} = {D3AB00F9-6704-4899-90C4-CB3BED88E7AA} + {5816A0E4-0A0A-4F38-8BDE-8B5B209E2B41} = {5816A0E4-0A0A-4F38-8BDE-8B5B209E2B41} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libfvalue", "libfvalue\libfvalue.vcproj", "{4A81A573-8E94-4C37-96C6-AAB627CA2D9B}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libuna", "libuna\libuna.vcproj", "{5C6EAD13-CCA8-4B03-8495-EEE2E3092468}" ProjectSection(ProjectDependencies) = postProject {C5D33EBC-535D-474C-870A-B96A4B30850D} = {C5D33EBC-535D-474C-870A-B96A4B30850D} - {D9A25DD4-1F17-4546-B662-5986E82720FC} = {D9A25DD4-1F17-4546-B662-5986E82720FC} - {D3AB00F9-6704-4899-90C4-CB3BED88E7AA} = {D3AB00F9-6704-4899-90C4-CB3BED88E7AA} - {5816A0E4-0A0A-4F38-8BDE-8B5B209E2B41} = {5816A0E4-0A0A-4F38-8BDE-8B5B209E2B41} - {5C6EAD13-CCA8-4B03-8495-EEE2E3092468} = {5C6EAD13-CCA8-4B03-8495-EEE2E3092468} - {B306CB83-6915-4684-A67B-55CE66C9C4C4} = {B306CB83-6915-4684-A67B-55CE66C9C4C4} - {9B4ACD98-1EDF-40A6-9866-CEB40FF75082} = {9B4ACD98-1EDF-40A6-9866-CEB40FF75082} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcnotify", "libcnotify\libcnotify.vcproj", "{5816A0E4-0A0A-4F38-8BDE-8B5B209E2B41}" @@ -213,6 +216,10 @@ Global {788051B4-9B85-41C8-AA28-27D538F53E0B}.Release|Win32.Build.0 = Release|Win32 {788051B4-9B85-41C8-AA28-27D538F53E0B}.VSDebug|Win32.ActiveCfg = VSDebug|Win32 {788051B4-9B85-41C8-AA28-27D538F53E0B}.VSDebug|Win32.Build.0 = VSDebug|Win32 + {3C123E2E-5CF0-405A-8E41-ADC0465AE9E0}.Release|Win32.ActiveCfg = Release|Win32 + {3C123E2E-5CF0-405A-8E41-ADC0465AE9E0}.Release|Win32.Build.0 = Release|Win32 + {3C123E2E-5CF0-405A-8E41-ADC0465AE9E0}.VSDebug|Win32.ActiveCfg = VSDebug|Win32 + {3C123E2E-5CF0-405A-8E41-ADC0465AE9E0}.VSDebug|Win32.Build.0 = VSDebug|Win32 {51112D1D-1694-4F1B-B82F-6C1C1EDA954E}.Release|Win32.ActiveCfg = Release|Win32 {51112D1D-1694-4F1B-B82F-6C1C1EDA954E}.Release|Win32.Build.0 = Release|Win32 {51112D1D-1694-4F1B-B82F-6C1C1EDA954E}.VSDebug|Win32.ActiveCfg = VSDebug|Win32 @@ -289,14 +296,14 @@ Global {703A33A3-1A6A-4D9C-B25F-F84BE52BAEA3}.Release|Win32.Build.0 = Release|Win32 {703A33A3-1A6A-4D9C-B25F-F84BE52BAEA3}.VSDebug|Win32.ActiveCfg = VSDebug|Win32 {703A33A3-1A6A-4D9C-B25F-F84BE52BAEA3}.VSDebug|Win32.Build.0 = VSDebug|Win32 + {43C6AFAD-E3EF-49C1-AA9B-A85E91A94684}.Release|Win32.ActiveCfg = Release|Win32 + {43C6AFAD-E3EF-49C1-AA9B-A85E91A94684}.Release|Win32.Build.0 = Release|Win32 + {43C6AFAD-E3EF-49C1-AA9B-A85E91A94684}.VSDebug|Win32.ActiveCfg = VSDebug|Win32 + {43C6AFAD-E3EF-49C1-AA9B-A85E91A94684}.VSDebug|Win32.Build.0 = VSDebug|Win32 {5C6EAD13-CCA8-4B03-8495-EEE2E3092468}.Release|Win32.ActiveCfg = Release|Win32 {5C6EAD13-CCA8-4B03-8495-EEE2E3092468}.Release|Win32.Build.0 = Release|Win32 {5C6EAD13-CCA8-4B03-8495-EEE2E3092468}.VSDebug|Win32.ActiveCfg = VSDebug|Win32 {5C6EAD13-CCA8-4B03-8495-EEE2E3092468}.VSDebug|Win32.Build.0 = VSDebug|Win32 - {4A81A573-8E94-4C37-96C6-AAB627CA2D9B}.Release|Win32.ActiveCfg = Release|Win32 - {4A81A573-8E94-4C37-96C6-AAB627CA2D9B}.Release|Win32.Build.0 = Release|Win32 - {4A81A573-8E94-4C37-96C6-AAB627CA2D9B}.VSDebug|Win32.ActiveCfg = VSDebug|Win32 - {4A81A573-8E94-4C37-96C6-AAB627CA2D9B}.VSDebug|Win32.Build.0 = VSDebug|Win32 {5816A0E4-0A0A-4F38-8BDE-8B5B209E2B41}.Release|Win32.ActiveCfg = Release|Win32 {5816A0E4-0A0A-4F38-8BDE-8B5B209E2B41}.Release|Win32.Build.0 = Release|Win32 {5816A0E4-0A0A-4F38-8BDE-8B5B209E2B41}.VSDebug|Win32.ActiveCfg = VSDebug|Win32 diff --git a/msvscpp/libfwevt/libfwevt.vcproj b/msvscpp/libfwevt/libfwevt.vcproj index 5cd5f57..2c0d7ed 100644 --- a/msvscpp/libfwevt/libfwevt.vcproj +++ b/msvscpp/libfwevt/libfwevt.vcproj @@ -39,8 +39,8 @@ /> + + @@ -193,6 +197,14 @@ RelativePath="..\..\libfwevt\libfwevt_event.c" > + + + + @@ -271,6 +283,10 @@ RelativePath="..\..\libfwevt\libfwevt_channel.h" > + + @@ -295,6 +311,14 @@ RelativePath="..\..\libfwevt\libfwevt_extern.h" > + + + + @@ -315,12 +339,16 @@ RelativePath="..\..\libfwevt\libfwevt_libcnotify.h" > + + @@ -39,8 +39,8 @@ /> - - - - @@ -221,115 +213,87 @@ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > - - - - - - - - - - - - - - diff --git a/synclibs.ps1 b/synclibs.ps1 index 7640ac0..396f15a 100644 --- a/synclibs.ps1 +++ b/synclibs.ps1 @@ -7,7 +7,7 @@ Param ( ) $GitUrlPrefix = "https://github.com/libyal" -$LocalLibs = "libcdata libcerror libcnotify libcthreads libfdatetime libfguid libfvalue libuna" +$LocalLibs = "libcdata libcerror libcnotify libcthreads libfdatetime libfguid libfwnt libuna" $LocalLibs = ${LocalLibs} -split " " $Git = "git" diff --git a/synclibs.sh b/synclibs.sh index 0909f5c..d244139 100755 --- a/synclibs.sh +++ b/synclibs.sh @@ -7,7 +7,7 @@ EXIT_SUCCESS=0; EXIT_FAILURE=1; GIT_URL_PREFIX="https://github.com/libyal"; -LOCAL_LIBS="libcdata libcerror libcnotify libcthreads libfdatetime libfguid libfvalue libuna"; +LOCAL_LIBS="libcdata libcerror libcnotify libcthreads libfdatetime libfguid libfwnt libuna"; OLDIFS=$IFS; IFS=" "; diff --git a/tests/Makefile.am b/tests/Makefile.am index b7315e5..830d5f1 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -7,7 +7,7 @@ AM_CPPFLAGS = \ @LIBCNOTIFY_CPPFLAGS@ \ @LIBFDATETIME_CPPFLAGS@ \ @LIBFGUID_CPPFLAGS@ \ - @LIBFVALUE_CPPFLAGS@ \ + @LIBFWNT_CPPFLAGS@ \ @LIBUNA_CPPFLAGS@ \ @PTHREAD_CPPFLAGS@ \ @LIBFWEVT_DLL_IMPORT@ @@ -36,6 +36,7 @@ EXTRA_DIST = \ check_PROGRAMS = \ fwevt_test_channel \ + fwevt_test_data_segment \ fwevt_test_date_time \ fwevt_test_error \ fwevt_test_event \ @@ -68,6 +69,18 @@ fwevt_test_channel_LDADD = \ ../libfwevt/libfwevt.la \ @LIBCERROR_LIBADD@ +fwevt_test_data_segment_SOURCES = \ + fwevt_test_data_segment.c \ + fwevt_test_libcerror.h \ + fwevt_test_libfwevt.h \ + fwevt_test_macros.h \ + fwevt_test_memory.c fwevt_test_memory.h \ + fwevt_test_unused.h + +fwevt_test_data_segment_LDADD = \ + ../libfwevt/libfwevt.la \ + @LIBCERROR_LIBADD@ + fwevt_test_date_time_SOURCES = \ fwevt_test_date_time.c \ fwevt_test_libcerror.h \ @@ -243,7 +256,6 @@ fwevt_test_xml_document_LDADD = \ fwevt_test_xml_tag_SOURCES = \ fwevt_test_libcerror.h \ - fwevt_test_libfvalue.h \ fwevt_test_libfwevt.h \ fwevt_test_libuna.h \ fwevt_test_macros.h \ @@ -281,7 +293,6 @@ fwevt_test_xml_token_LDADD = \ fwevt_test_xml_value_SOURCES = \ fwevt_test_libcerror.h \ - fwevt_test_libfvalue.h \ fwevt_test_libfwevt.h \ fwevt_test_libuna.h \ fwevt_test_macros.h \ diff --git a/tests/fwevt_test_data_segment.c b/tests/fwevt_test_data_segment.c new file mode 100644 index 0000000..4d78d76 --- /dev/null +++ b/tests/fwevt_test_data_segment.c @@ -0,0 +1,358 @@ +/* + * Library data_segment type test program + * + * Copyright (C) 2011-2024, Joachim Metz + * + * Refer to AUTHORS for acknowledgements. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include +#include +#include + +#if defined( HAVE_STDLIB_H ) || defined( WINAPI ) +#include +#endif + +#include "fwevt_test_libcerror.h" +#include "fwevt_test_libfwevt.h" +#include "fwevt_test_macros.h" +#include "fwevt_test_memory.h" +#include "fwevt_test_unused.h" + +#include "../libfwevt/libfwevt_data_segment.h" + +#if defined( __GNUC__ ) && !defined( LIBFWEVT_DLL_IMPORT ) + +/* Tests the libfwevt_data_segment_initialize function + * Returns 1 if successful or 0 if not + */ +int fwevt_test_data_segment_initialize( + void ) +{ + uint8_t test_data[ 5 ] = { 't', 'e', 's', 't', 0 }; + libcerror_error_t *error = NULL; + libfwevt_data_segment_t *data_segment = NULL; + int result = 0; + +#if defined( HAVE_FWEVT_TEST_MEMORY ) + int number_of_malloc_fail_tests = 1; + int number_of_memset_fail_tests = 1; + int test_number = 0; +#endif + + /* Test regular cases + */ + result = libfwevt_data_segment_initialize( + &data_segment, + test_data, + 5, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "data_segment", + data_segment ); + + FWEVT_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = libfwevt_data_segment_free( + &data_segment, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FWEVT_TEST_ASSERT_IS_NULL( + "data_segment", + data_segment ); + + FWEVT_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test error cases + */ + result = libfwevt_data_segment_initialize( + NULL, + test_data, + 5, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + data_segment = (libfwevt_data_segment_t *) 0x12345678UL; + + result = libfwevt_data_segment_initialize( + &data_segment, + test_data, + 5, + &error ); + + data_segment = NULL; + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + result = libfwevt_data_segment_initialize( + &data_segment, + NULL, + 5, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + result = libfwevt_data_segment_initialize( + &data_segment, + test_data, + (size_t) SSIZE_MAX + 1, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + +#if defined( HAVE_FWEVT_TEST_MEMORY ) + + for( test_number = 0; + test_number < number_of_malloc_fail_tests; + test_number++ ) + { + /* Test libfwevt_data_segment_initialize with malloc failing + */ + fwevt_test_malloc_attempts_before_fail = test_number; + + result = libfwevt_data_segment_initialize( + &data_segment, + test_data, + 5, + &error ); + + if( fwevt_test_malloc_attempts_before_fail != -1 ) + { + fwevt_test_malloc_attempts_before_fail = -1; + + if( data_segment != NULL ) + { + libfwevt_data_segment_free( + &data_segment, + NULL ); + } + } + else + { + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_TEST_ASSERT_IS_NULL( + "data_segment", + data_segment ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + } + } + for( test_number = 0; + test_number < number_of_memset_fail_tests; + test_number++ ) + { + /* Test libfwevt_data_segment_initialize with memset failing + */ + fwevt_test_memset_attempts_before_fail = test_number; + + result = libfwevt_data_segment_initialize( + &data_segment, + test_data, + 5, + &error ); + + if( fwevt_test_memset_attempts_before_fail != -1 ) + { + fwevt_test_memset_attempts_before_fail = -1; + + if( data_segment != NULL ) + { + libfwevt_data_segment_free( + &data_segment, + NULL ); + } + } + else + { + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_TEST_ASSERT_IS_NULL( + "data_segment", + data_segment ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + } + } +#endif /* defined( HAVE_FWEVT_TEST_MEMORY ) */ + + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + if( data_segment != NULL ) + { + libfwevt_data_segment_free( + &data_segment, + NULL ); + } + return( 0 ); +} + +/* Tests the libfwevt_data_segment_free function + * Returns 1 if successful or 0 if not + */ +int fwevt_test_data_segment_free( + void ) +{ + libcerror_error_t *error = NULL; + int result = 0; + + /* Test error cases + */ + result = libfwevt_data_segment_free( + NULL, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + return( 0 ); +} + +#endif /* defined( __GNUC__ ) && !defined( LIBFWEVT_DLL_IMPORT ) */ + +/* The main program + */ +#if defined( HAVE_WIDE_SYSTEM_CHARACTER ) +int wmain( + int argc FWEVT_TEST_ATTRIBUTE_UNUSED, + wchar_t * const argv[] FWEVT_TEST_ATTRIBUTE_UNUSED ) +#else +int main( + int argc FWEVT_TEST_ATTRIBUTE_UNUSED, + char * const argv[] FWEVT_TEST_ATTRIBUTE_UNUSED ) +#endif +{ + FWEVT_TEST_UNREFERENCED_PARAMETER( argc ) + FWEVT_TEST_UNREFERENCED_PARAMETER( argv ) + +#if defined( __GNUC__ ) && !defined( LIBFWEVT_DLL_IMPORT ) + + FWEVT_TEST_RUN( + "libfwevt_data_segment_initialize", + fwevt_test_data_segment_initialize ); + + FWEVT_TEST_RUN( + "libfwevt_data_segment_free", + fwevt_test_data_segment_free ); + +#endif /* defined( __GNUC__ ) && !defined( LIBFWEVT_DLL_IMPORT ) */ + + return( EXIT_SUCCESS ); + +#if defined( __GNUC__ ) && !defined( LIBFWEVT_DLL_IMPORT ) + +on_error: + return( EXIT_FAILURE ); + +#endif /* defined( __GNUC__ ) && !defined( LIBFWEVT_DLL_IMPORT ) */ +} + diff --git a/tests/fwevt_test_date_time.c b/tests/fwevt_test_date_time.c index 2f6f9db..d6558c2 100644 --- a/tests/fwevt_test_date_time.c +++ b/tests/fwevt_test_date_time.c @@ -35,20 +35,32 @@ #include "../libfwevt/libfwevt_date_time.h" -/* Tests the libfwevt_utf8_string_copy_to_filetime function +/* Tests the libfwevt_filetime_copy_from_utf16_stream function * Returns 1 if successful or 0 if not */ -int fwevt_test_utf8_string_copy_to_filetime( +int fwevt_test_filetime_copy_from_utf16_stream( void ) { + uint8_t utf16_stream1[ 62 ] = { + '1', 0, '6', 0, '0', 0, '1', 0, '-', 0, '0', 0, '1', 0, '-', 0, + '0', 0, '1', 0, 'T', 0, '0', 0, '0', 0, ':', 0, '0', 0, '0', 0, + ':', 0, '0', 0, '0', 0, '.', 0, '0', 0, '0', 0, '0', 0, '0', 0, + '0', 0, '0', 0, '0', 0, '0', 0, '0', 0, 'Z', 0, 0, 0 }; + + uint8_t utf16_stream2[ 62 ] = { + '2', 0, '0', 0, '2', 0, '2', 0, '-', 0, '0', 0, '7', 0, '-', 0, + '0', 0, '6', 0, 'T', 0, '1', 0, '2', 0, ':', 0, '2', 0, '4', 0, + ':', 0, '4', 0, '0', 0, '.', 0, '6', 0, '0', 0, '8', 0, '1', 0, + '1', 0, '5', 0, '5', 0, '0', 0, '0', 0, 'Z', 0, 0, 0 }; + libcerror_error_t *error = NULL; uint64_t filetime = 0; int result = 0; - result = libfwevt_utf8_string_copy_to_filetime( - (uint8_t *) "1601-01-01T00:00:00.000000000Z", - 31, + result = libfwevt_filetime_copy_from_utf16_stream( &filetime, + utf16_stream1, + 62, &error ); FWEVT_TEST_ASSERT_EQUAL_INT( @@ -65,10 +77,10 @@ int fwevt_test_utf8_string_copy_to_filetime( "error", error ); - result = libfwevt_utf8_string_copy_to_filetime( - (uint8_t *) "2022-07-06T12:24:40.608115500Z", - 31, + result = libfwevt_filetime_copy_from_utf16_stream( &filetime, + utf16_stream2, + 62, &error ); FWEVT_TEST_ASSERT_EQUAL_INT( @@ -112,8 +124,8 @@ int main( FWEVT_TEST_UNREFERENCED_PARAMETER( argv ) FWEVT_TEST_RUN( - "libfwevt_utf8_string_copy_to_filetime", - fwevt_test_utf8_string_copy_to_filetime ); + "libfwevt_filetime_copy_from_utf16_stream", + fwevt_test_filetime_copy_from_utf16_stream ); return( EXIT_SUCCESS ); diff --git a/tests/fwevt_test_libfvalue.h b/tests/fwevt_test_libfvalue.h deleted file mode 100644 index 07a4fc1..0000000 --- a/tests/fwevt_test_libfvalue.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * The libfvalue header wrapper - * - * Copyright (C) 2011-2024, Joachim Metz - * - * Refer to AUTHORS for acknowledgements. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -#if !defined( _FWEVT_TEST_LIBFVALUE_H ) -#define _FWEVT_TEST_LIBFVALUE_H - -#include - -/* Define HAVE_LOCAL_LIBFVALUE for local use of libfvalue - */ -#if defined( HAVE_LOCAL_LIBFVALUE ) - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#else - -/* If libtool DLL support is enabled set LIBFVALUE_DLL_IMPORT - * before including libfvalue.h - */ -#if defined( _WIN32 ) && defined( DLL_IMPORT ) -#define LIBFVALUE_DLL_IMPORT -#endif - -#include - -#endif /* defined( HAVE_LOCAL_LIBFVALUE ) */ - -#endif /* !defined( _FWEVT_TEST_LIBFVALUE_H ) */ - diff --git a/tests/fwevt_test_xml_tag.c b/tests/fwevt_test_xml_tag.c index fef7b12..d892ad8 100644 --- a/tests/fwevt_test_xml_tag.c +++ b/tests/fwevt_test_xml_tag.c @@ -29,7 +29,6 @@ #endif #include "fwevt_test_libcerror.h" -#include "fwevt_test_libfvalue.h" #include "fwevt_test_libfwevt.h" #include "fwevt_test_libuna.h" #include "fwevt_test_macros.h" @@ -546,7 +545,7 @@ int fwevt_test_xml_tag_set_value_type( */ result = libfwevt_xml_tag_set_value_type( xml_tag, - LIBFVALUE_VALUE_TYPE_BINARY_DATA, + LIBFWEVT_VALUE_TYPE_BINARY_DATA, &error ); FWEVT_TEST_ASSERT_EQUAL_INT( @@ -562,7 +561,7 @@ int fwevt_test_xml_tag_set_value_type( */ result = libfwevt_xml_tag_set_value_type( NULL, - LIBFVALUE_VALUE_TYPE_BINARY_DATA, + LIBFWEVT_VALUE_TYPE_BINARY_DATA, &error ); FWEVT_TEST_ASSERT_EQUAL_INT( @@ -579,121 +578,7 @@ int fwevt_test_xml_tag_set_value_type( result = libfwevt_xml_tag_set_value_type( xml_tag, - LIBFVALUE_VALUE_TYPE_INTEGER_32BIT, - &error ); - - FWEVT_TEST_ASSERT_EQUAL_INT( - "result", - result, - -1 ); - - FWEVT_TEST_ASSERT_IS_NOT_NULL( - "error", - error ); - - libcerror_error_free( - &error ); - - /* Clean up - */ - result = libfwevt_internal_xml_tag_free( - (libfwevt_internal_xml_tag_t **) &xml_tag, - &error ); - - FWEVT_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - FWEVT_TEST_ASSERT_IS_NULL( - "xml_tag", - xml_tag ); - - FWEVT_TEST_ASSERT_IS_NULL( - "error", - error ); - - return( 1 ); - -on_error: - if( error != NULL ) - { - libcerror_error_free( - &error ); - } - if( xml_tag != NULL ) - { - libfwevt_internal_xml_tag_free( - (libfwevt_internal_xml_tag_t **) &xml_tag, - NULL ); - } - return( 0 ); -} - -/* Tests the libfwevt_xml_tag_set_value_format_flags function - * Returns 1 if successful or 0 if not - */ -int fwevt_test_xml_tag_set_value_format_flags( - void ) -{ - libcerror_error_t *error = NULL; - libfwevt_xml_tag_t *xml_tag = NULL; - int result = 0; - - /* Initialize test - */ - result = libfwevt_xml_tag_initialize( - &xml_tag, - &error ); - - FWEVT_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - FWEVT_TEST_ASSERT_IS_NOT_NULL( - "xml_tag", - xml_tag ); - - FWEVT_TEST_ASSERT_IS_NULL( - "error", - error ); - - result = libfwevt_xml_tag_set_value_type( - xml_tag, - LIBFVALUE_VALUE_TYPE_BINARY_DATA, - &error ); - - FWEVT_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - FWEVT_TEST_ASSERT_IS_NULL( - "error", - error ); - - /* Test regular cases - */ - result = libfwevt_xml_tag_set_value_format_flags( - xml_tag, - LIBFVALUE_BINARY_DATA_FORMAT_TYPE_BASE16, - &error ); - - FWEVT_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - FWEVT_TEST_ASSERT_IS_NULL( - "error", - error ); - - /* Test error cases - */ - result = libfwevt_xml_tag_set_value_format_flags( - NULL, - LIBFVALUE_BINARY_DATA_FORMAT_TYPE_BASE16, + LIBFWEVT_VALUE_TYPE_INTEGER_32BIT, &error ); FWEVT_TEST_ASSERT_EQUAL_INT( @@ -775,7 +660,7 @@ int fwevt_test_xml_tag_set_value_data( result = libfwevt_xml_tag_set_value_type( xml_tag, - LIBFVALUE_VALUE_TYPE_BINARY_DATA, + LIBFWEVT_VALUE_TYPE_BINARY_DATA, &error ); FWEVT_TEST_ASSERT_EQUAL_INT( @@ -793,7 +678,6 @@ int fwevt_test_xml_tag_set_value_data( xml_tag, (uint8_t *) "data", 4, - 0, &error ); FWEVT_TEST_ASSERT_EQUAL_INT( @@ -811,7 +695,6 @@ int fwevt_test_xml_tag_set_value_data( NULL, (uint8_t *) "data", 4, - 0, &error ); FWEVT_TEST_ASSERT_EQUAL_INT( @@ -830,7 +713,6 @@ int fwevt_test_xml_tag_set_value_data( xml_tag, NULL, 4, - 0, &error ); FWEVT_TEST_ASSERT_EQUAL_INT( @@ -849,7 +731,6 @@ int fwevt_test_xml_tag_set_value_data( xml_tag, (uint8_t *) "data", (size_t) SSIZE_MAX + 1, - 0, &error ); FWEVT_TEST_ASSERT_EQUAL_INT( @@ -2969,15 +2850,15 @@ int fwevt_test_xml_tag_get_flags( int fwevt_test_xml_tag_get_utf8_xml_value_string_size( libfwevt_xml_tag_t *xml_tag ) { - libcerror_error_t *error = NULL; - size_t utf8_xml_value_string_size = 0; - int result = 0; + libcerror_error_t *error = NULL; + size_t utf8_xml_string_size = 0; + int result = 0; /* Test regular cases */ result = libfwevt_xml_tag_get_utf8_xml_value_string_size( (libfwevt_internal_xml_tag_t *) xml_tag, - &utf8_xml_value_string_size, + &utf8_xml_string_size, &error ); FWEVT_TEST_ASSERT_EQUAL_INT( @@ -2985,6 +2866,11 @@ int fwevt_test_xml_tag_get_utf8_xml_value_string_size( result, 1 ); + FWEVT_TEST_ASSERT_EQUAL_SIZE( + "utf8_xml_string_size", + utf8_xml_string_size, + (size_t) 9 ); + FWEVT_TEST_ASSERT_IS_NULL( "error", error ); @@ -2993,7 +2879,7 @@ int fwevt_test_xml_tag_get_utf8_xml_value_string_size( */ result = libfwevt_xml_tag_get_utf8_xml_value_string_size( NULL, - &utf8_xml_value_string_size, + &utf8_xml_string_size, &error ); FWEVT_TEST_ASSERT_EQUAL_INT( @@ -3042,7 +2928,10 @@ int fwevt_test_xml_tag_get_utf8_xml_value_string_size( int fwevt_test_xml_tag_get_utf8_xml_value_string_with_index( libfwevt_xml_tag_t *xml_tag ) { - uint8_t utf8_string[ 32 ]; + uint8_t expected_utf8_string[ 9 ] = { + '6', '4', '6', '1', '7', '4', '6', '1', 0 }; + + uint8_t utf8_string[ 12 ]; libcerror_error_t *error = NULL; size_t utf8_string_index = 0; @@ -3053,7 +2942,7 @@ int fwevt_test_xml_tag_get_utf8_xml_value_string_with_index( result = libfwevt_xml_tag_get_utf8_xml_value_string_with_index( (libfwevt_internal_xml_tag_t *) xml_tag, utf8_string, - 32, + 12, &utf8_string_index, &error ); @@ -3062,16 +2951,33 @@ int fwevt_test_xml_tag_get_utf8_xml_value_string_with_index( result, 1 ); + FWEVT_TEST_ASSERT_EQUAL_SIZE( + "utf8_string_index", + utf8_string_index, + (size_t) 9 ); + FWEVT_TEST_ASSERT_IS_NULL( "error", error ); + result = memory_compare( + expected_utf8_string, + utf8_string, + 9 ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + 0 ); + /* Test error cases */ + utf8_string_index = 0; + result = libfwevt_xml_tag_get_utf8_xml_value_string_with_index( NULL, utf8_string, - 32, + 12, &utf8_string_index, &error ); @@ -3090,7 +2996,7 @@ int fwevt_test_xml_tag_get_utf8_xml_value_string_with_index( result = libfwevt_xml_tag_get_utf8_xml_value_string_with_index( (libfwevt_internal_xml_tag_t *) xml_tag, NULL, - 32, + 12, &utf8_string_index, &error ); @@ -3128,7 +3034,7 @@ int fwevt_test_xml_tag_get_utf8_xml_value_string_with_index( result = libfwevt_xml_tag_get_utf8_xml_value_string_with_index( (libfwevt_internal_xml_tag_t *) xml_tag, utf8_string, - 32, + 12, NULL, &error ); @@ -3288,6 +3194,8 @@ int fwevt_test_xml_tag_get_utf8_xml_string_with_index( /* Test error cases */ + utf8_string_index = 0; + result = libfwevt_xml_tag_get_utf8_xml_string_with_index( NULL, 0, @@ -3385,15 +3293,15 @@ int fwevt_test_xml_tag_get_utf8_xml_string_with_index( int fwevt_test_xml_tag_get_utf16_xml_value_string_size( libfwevt_xml_tag_t *xml_tag ) { - libcerror_error_t *error = NULL; - size_t utf16_xml_value_string_size = 0; - int result = 0; + libcerror_error_t *error = NULL; + size_t utf16_xml_string_size = 0; + int result = 0; /* Test regular cases */ result = libfwevt_xml_tag_get_utf16_xml_value_string_size( (libfwevt_internal_xml_tag_t *) xml_tag, - &utf16_xml_value_string_size, + &utf16_xml_string_size, &error ); FWEVT_TEST_ASSERT_EQUAL_INT( @@ -3401,6 +3309,11 @@ int fwevt_test_xml_tag_get_utf16_xml_value_string_size( result, 1 ); + FWEVT_TEST_ASSERT_EQUAL_SIZE( + "utf16_xml_string_size", + utf16_xml_string_size, + (size_t) 9 ); + FWEVT_TEST_ASSERT_IS_NULL( "error", error ); @@ -3409,7 +3322,7 @@ int fwevt_test_xml_tag_get_utf16_xml_value_string_size( */ result = libfwevt_xml_tag_get_utf16_xml_value_string_size( NULL, - &utf16_xml_value_string_size, + &utf16_xml_string_size, &error ); FWEVT_TEST_ASSERT_EQUAL_INT( @@ -3458,7 +3371,10 @@ int fwevt_test_xml_tag_get_utf16_xml_value_string_size( int fwevt_test_xml_tag_get_utf16_xml_value_string_with_index( libfwevt_xml_tag_t *xml_tag ) { - uint16_t utf16_string[ 32 ]; + uint16_t expected_utf16_string[ 9 ] = { + '6', '4', '6', '1', '7', '4', '6', '1', 0 }; + + uint16_t utf16_string[ 12 ]; libcerror_error_t *error = NULL; size_t utf16_string_index = 0; @@ -3469,7 +3385,7 @@ int fwevt_test_xml_tag_get_utf16_xml_value_string_with_index( result = libfwevt_xml_tag_get_utf16_xml_value_string_with_index( (libfwevt_internal_xml_tag_t *) xml_tag, utf16_string, - 32, + 12, &utf16_string_index, &error ); @@ -3478,16 +3394,33 @@ int fwevt_test_xml_tag_get_utf16_xml_value_string_with_index( result, 1 ); + FWEVT_TEST_ASSERT_EQUAL_SIZE( + "utf16_string_index", + utf16_string_index, + (size_t) 9 ); + FWEVT_TEST_ASSERT_IS_NULL( "error", error ); + result = memory_compare( + expected_utf16_string, + utf16_string, + 9 ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + 0 ); + /* Test error cases */ + utf16_string_index = 0; + result = libfwevt_xml_tag_get_utf16_xml_value_string_with_index( NULL, utf16_string, - 32, + 12, &utf16_string_index, &error ); @@ -3506,7 +3439,7 @@ int fwevt_test_xml_tag_get_utf16_xml_value_string_with_index( result = libfwevt_xml_tag_get_utf16_xml_value_string_with_index( (libfwevt_internal_xml_tag_t *) xml_tag, NULL, - 32, + 12, &utf16_string_index, &error ); @@ -3544,7 +3477,7 @@ int fwevt_test_xml_tag_get_utf16_xml_value_string_with_index( result = libfwevt_xml_tag_get_utf16_xml_value_string_with_index( (libfwevt_internal_xml_tag_t *) xml_tag, utf16_string, - 32, + 12, NULL, &error ); @@ -3704,6 +3637,8 @@ int fwevt_test_xml_tag_get_utf16_xml_string_with_index( /* Test error cases */ + utf16_string_index = 0; + result = libfwevt_xml_tag_get_utf16_xml_string_with_index( NULL, 0, @@ -3845,18 +3780,12 @@ int main( "libfwevt_xml_tag_set_value_type", fwevt_test_xml_tag_set_value_type ); - FWEVT_TEST_RUN( - "libfwevt_xml_tag_set_value_format_flags", - fwevt_test_xml_tag_set_value_format_flags ); - FWEVT_TEST_RUN( "libfwevt_xml_tag_set_value_data", fwevt_test_xml_tag_set_value_data ); /* TODO: add tests for libfwevt_xml_tag_append_value_data */ - /* TODO: add tests for libfwevt_xml_tag_set_value_strings_array */ - /* TODO: add tests for libfwevt_xml_tag_append_attribute */ /* TODO: add tests for libfwevt_xml_tag_append_element */ @@ -3899,7 +3828,7 @@ int main( result = libfwevt_xml_tag_set_value_type( xml_tag, - LIBFVALUE_VALUE_TYPE_BINARY_DATA, + LIBFWEVT_VALUE_TYPE_BINARY_DATA, &error ); FWEVT_TEST_ASSERT_EQUAL_INT( @@ -3915,21 +3844,6 @@ int main( xml_tag, (uint8_t *) "data", 4, - 0, - &error ); - - FWEVT_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - FWEVT_TEST_ASSERT_IS_NULL( - "error", - error ); - - result = libfwevt_xml_tag_set_value_format_flags( - xml_tag, - LIBFVALUE_BINARY_DATA_FORMAT_TYPE_BASE16, &error ); FWEVT_TEST_ASSERT_EQUAL_INT( diff --git a/tests/fwevt_test_xml_value.c b/tests/fwevt_test_xml_value.c index ad97537..3b13ddb 100644 --- a/tests/fwevt_test_xml_value.c +++ b/tests/fwevt_test_xml_value.c @@ -59,7 +59,7 @@ int fwevt_test_xml_value_initialize( */ result = libfwevt_xml_value_initialize( &xml_value, - LIBFVALUE_VALUE_TYPE_BINARY_DATA, + LIBFWEVT_VALUE_TYPE_BINARY_DATA, &error ); FWEVT_TEST_ASSERT_EQUAL_INT( @@ -96,7 +96,7 @@ int fwevt_test_xml_value_initialize( */ result = libfwevt_xml_value_initialize( NULL, - LIBFVALUE_VALUE_TYPE_BINARY_DATA, + LIBFWEVT_VALUE_TYPE_BINARY_DATA, &error ); FWEVT_TEST_ASSERT_EQUAL_INT( @@ -115,7 +115,7 @@ int fwevt_test_xml_value_initialize( result = libfwevt_xml_value_initialize( &xml_value, - LIBFVALUE_VALUE_TYPE_BINARY_DATA, + LIBFWEVT_VALUE_TYPE_BINARY_DATA, &error ); xml_value = NULL; @@ -144,7 +144,7 @@ int fwevt_test_xml_value_initialize( result = libfwevt_xml_value_initialize( &xml_value, - LIBFVALUE_VALUE_TYPE_BINARY_DATA, + LIBFWEVT_VALUE_TYPE_BINARY_DATA, &error ); if( fwevt_test_malloc_attempts_before_fail != -1 ) @@ -187,7 +187,7 @@ int fwevt_test_xml_value_initialize( result = libfwevt_xml_value_initialize( &xml_value, - LIBFVALUE_VALUE_TYPE_BINARY_DATA, + LIBFWEVT_VALUE_TYPE_BINARY_DATA, &error ); if( fwevt_test_memset_attempts_before_fail != -1 ) @@ -285,13 +285,13 @@ int fwevt_test_xml_value_get_type( { libcerror_error_t *error = NULL; int result = 0; - int type = 0; + uint8_t value_type = 0; /* Test regular cases */ result = libfwevt_xml_value_get_type( xml_value, - &type, + &value_type, &error ); FWEVT_TEST_ASSERT_EQUAL_INT( @@ -299,10 +299,10 @@ int fwevt_test_xml_value_get_type( result, 1 ); - FWEVT_TEST_ASSERT_EQUAL_INT( - "type", - type, - LIBFVALUE_VALUE_TYPE_BINARY_DATA ); + FWEVT_TEST_ASSERT_EQUAL_UINT8( + "value_type", + value_type, + (uint8_t) LIBFWEVT_VALUE_TYPE_BINARY_DATA ); FWEVT_TEST_ASSERT_IS_NULL( "error", @@ -312,7 +312,7 @@ int fwevt_test_xml_value_get_type( */ result = libfwevt_xml_value_get_type( NULL, - &type, + &value_type, &error ); FWEVT_TEST_ASSERT_EQUAL_INT( @@ -355,21 +355,21 @@ int fwevt_test_xml_value_get_type( return( 0 ); } -/* Tests the libfwevt_xml_value_get_number_of_value_entries function +/* Tests the libfwevt_xml_value_get_number_of_data_segments function * Returns 1 if successful or 0 if not */ -int fwevt_test_xml_value_get_number_of_value_entries( +int fwevt_test_xml_value_get_number_of_data_segments( libfwevt_xml_value_t *xml_value ) { libcerror_error_t *error = NULL; - int number_of_value_entries = 0; + int number_of_data_segments = 0; int result = 0; /* Test regular cases */ - result = libfwevt_xml_value_get_number_of_value_entries( + result = libfwevt_xml_value_get_number_of_data_segments( xml_value, - &number_of_value_entries, + &number_of_data_segments, &error ); FWEVT_TEST_ASSERT_EQUAL_INT( @@ -378,8 +378,8 @@ int fwevt_test_xml_value_get_number_of_value_entries( 1 ); FWEVT_TEST_ASSERT_EQUAL_INT( - "number_of_value_entries", - number_of_value_entries, + "number_of_data_segments", + number_of_data_segments, 1 ); FWEVT_TEST_ASSERT_IS_NULL( @@ -388,9 +388,9 @@ int fwevt_test_xml_value_get_number_of_value_entries( /* Test error cases */ - result = libfwevt_xml_value_get_number_of_value_entries( + result = libfwevt_xml_value_get_number_of_data_segments( NULL, - &number_of_value_entries, + &number_of_data_segments, &error ); FWEVT_TEST_ASSERT_EQUAL_INT( @@ -405,7 +405,7 @@ int fwevt_test_xml_value_get_number_of_value_entries( libcerror_error_free( &error ); - result = libfwevt_xml_value_get_number_of_value_entries( + result = libfwevt_xml_value_get_number_of_data_segments( xml_value, NULL, &error ); @@ -511,6 +511,390 @@ int fwevt_test_xml_value_get_data_size( return( 0 ); } +/* Tests the libfwevt_xml_value_get_data_as_utf8_string_size function + * Returns 1 if successful or 0 if not + */ +int fwevt_test_xml_value_get_data_as_utf8_string_size( + libfwevt_xml_value_t *xml_value ) +{ + libcerror_error_t *error = NULL; + size_t utf8_xml_value_string_size = 0; + int result = 0; + + /* Test regular cases + */ + result = libfwevt_xml_value_get_data_as_utf8_string_size( + xml_value, + &utf8_xml_value_string_size, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FWEVT_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test error cases + */ + result = libfwevt_xml_value_get_data_as_utf8_string_size( + NULL, + &utf8_xml_value_string_size, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + result = libfwevt_xml_value_get_data_as_utf8_string_size( + xml_value, + NULL, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + return( 0 ); +} + +/* Tests the libfwevt_xml_value_get_data_as_utf8_string_with_index function + * Returns 1 if successful or 0 if not + */ +int fwevt_test_xml_value_get_data_as_utf8_string_with_index( + libfwevt_xml_value_t *xml_value ) +{ + uint8_t utf8_string[ 32 ]; + + libcerror_error_t *error = NULL; + size_t utf8_string_index = 0; + int result = 0; + + /* Test regular cases + */ + result = libfwevt_xml_value_get_data_as_utf8_string_with_index( + xml_value, + utf8_string, + 32, + &utf8_string_index, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FWEVT_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test error cases + */ + result = libfwevt_xml_value_get_data_as_utf8_string_with_index( + NULL, + utf8_string, + 32, + &utf8_string_index, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + result = libfwevt_xml_value_get_data_as_utf8_string_with_index( + xml_value, + NULL, + 32, + &utf8_string_index, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + result = libfwevt_xml_value_get_data_as_utf8_string_with_index( + xml_value, + utf8_string, + (size_t) SSIZE_MAX + 1, + &utf8_string_index, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + result = libfwevt_xml_value_get_data_as_utf8_string_with_index( + xml_value, + utf8_string, + 32, + NULL, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + return( 0 ); +} + +/* Tests the libfwevt_xml_value_get_data_as_utf16_string_size function + * Returns 1 if successful or 0 if not + */ +int fwevt_test_xml_value_get_data_as_utf16_string_size( + libfwevt_xml_value_t *xml_value ) +{ + libcerror_error_t *error = NULL; + size_t utf16_xml_value_string_size = 0; + int result = 0; + + /* Test regular cases + */ + result = libfwevt_xml_value_get_data_as_utf16_string_size( + xml_value, + &utf16_xml_value_string_size, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FWEVT_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test error cases + */ + result = libfwevt_xml_value_get_data_as_utf16_string_size( + NULL, + &utf16_xml_value_string_size, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + result = libfwevt_xml_value_get_data_as_utf16_string_size( + xml_value, + NULL, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + return( 0 ); +} + +/* Tests the libfwevt_xml_value_get_data_as_utf16_string_with_index function + * Returns 1 if successful or 0 if not + */ +int fwevt_test_xml_value_get_data_as_utf16_string_with_index( + libfwevt_xml_value_t *xml_value ) +{ + uint16_t utf16_string[ 32 ]; + + libcerror_error_t *error = NULL; + size_t utf16_string_index = 0; + int result = 0; + + /* Test regular cases + */ + result = libfwevt_xml_value_get_data_as_utf16_string_with_index( + xml_value, + utf16_string, + 32, + &utf16_string_index, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FWEVT_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test error cases + */ + result = libfwevt_xml_value_get_data_as_utf16_string_with_index( + NULL, + utf16_string, + 32, + &utf16_string_index, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + result = libfwevt_xml_value_get_data_as_utf16_string_with_index( + xml_value, + NULL, + 32, + &utf16_string_index, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + result = libfwevt_xml_value_get_data_as_utf16_string_with_index( + xml_value, + utf16_string, + (size_t) SSIZE_MAX + 1, + &utf16_string_index, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + result = libfwevt_xml_value_get_data_as_utf16_string_with_index( + xml_value, + utf16_string, + 32, + NULL, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + return( 0 ); +} + #endif /* #if defined( __GNUC__ ) && !defined( LIBFWEVT_DLL_IMPORT ) */ /* The main program @@ -529,6 +913,7 @@ int main( libcerror_error_t *error = NULL; libfwevt_xml_value_t *xml_value = NULL; + int data_segment_index = 0; int result = 0; #endif /* defined( __GNUC__ ) && !defined( LIBFWEVT_DLL_IMPORT ) */ @@ -548,11 +933,7 @@ int main( /* TODO: add tests for libfwevt_internal_xml_value_free */ - /* TODO: add tests for libfwevt_xml_value_set_format_flags */ - - /* TODO: add tests for libfwevt_xml_value_append_data */ - - /* TODO: add tests for libfwevt_xml_value_type_set_data_string */ + /* TODO: add tests for libfwevt_xml_value_append_data_segment */ #if !defined( __BORLANDC__ ) || ( __BORLANDC__ >= 0x0560 ) @@ -560,7 +941,7 @@ int main( */ result = libfwevt_xml_value_initialize( &xml_value, - LIBFVALUE_VALUE_TYPE_BINARY_DATA, + LIBFWEVT_VALUE_TYPE_BINARY_DATA, &error ); FWEVT_TEST_ASSERT_EQUAL_INT( @@ -576,12 +957,11 @@ int main( "error", error ); - result = libfwevt_xml_value_set_data( + result = libfwevt_xml_value_append_data_segment( xml_value, (uint8_t *) "data", 4, - 0, - 0, + &data_segment_index, &error ); FWEVT_TEST_ASSERT_EQUAL_INT( @@ -599,8 +979,8 @@ int main( xml_value ); FWEVT_TEST_RUN_WITH_ARGS( - "libfwevt_xml_value_get_number_of_value_entries", - fwevt_test_xml_value_get_number_of_value_entries, + "libfwevt_xml_value_get_number_of_data_segments", + fwevt_test_xml_value_get_number_of_data_segments, xml_value ); FWEVT_TEST_RUN_WITH_ARGS( @@ -610,31 +990,49 @@ int main( /* TODO: add tests for libfwevt_xml_value_copy_data */ - /* TODO: add tests for libfwevt_xml_value_copy_to_8bit */ + /* TODO: add tests for libfwevt_value_get_data_as_8bit_integer */ + + /* TODO: add tests for libfwevt_value_get_data_as_32bit_integer */ - /* TODO: add tests for libfwevt_xml_value_copy_to_32bit */ + /* TODO: add tests for libfwevt_value_get_data_as_64bit_integer */ - /* TODO: add tests for libfwevt_xml_value_copy_to_64bit */ + /* TODO: add tests for libfwevt_value_get_data_as_filetime */ /* TODO: add tests for libfwevt_xml_value_get_utf8_string_size_with_index */ /* TODO: add tests for libfwevt_xml_value_copy_to_utf8_string_with_index */ - /* TODO: add tests for libfwevt_xml_value_get_utf8_string_size */ + FWEVT_TEST_RUN_WITH_ARGS( + "libfwevt_xml_value_get_data_as_utf8_string_size", + fwevt_test_xml_value_get_data_as_utf8_string_size, + xml_value ); + + /* TODO: add tests for libfwevt_xml_value_get_data_as_utf8_string */ - /* TODO: add tests for libfwevt_xml_value_copy_to_utf8_string */ + FWEVT_TEST_RUN_WITH_ARGS( + "libfwevt_xml_value_get_data_as_utf8_string_with_index", + fwevt_test_xml_value_get_data_as_utf8_string_with_index, + xml_value ); /* TODO: add tests for libfwevt_xml_value_get_utf16_string_size_with_index */ /* TODO: add tests for libfwevt_xml_value_copy_to_utf16_string_with_index */ - /* TODO: add tests for libfwevt_xml_value_get_utf16_string_size */ + FWEVT_TEST_RUN_WITH_ARGS( + "libfwevt_xml_value_get_data_as_utf16_string_size", + fwevt_test_xml_value_get_data_as_utf16_string_size, + xml_value ); + + /* TODO: add tests for libfwevt_xml_value_get_data_as_utf16_string */ - /* TODO: add tests for libfwevt_xml_value_copy_to_utf16_string */ + FWEVT_TEST_RUN_WITH_ARGS( + "libfwevt_xml_value_get_data_as_utf16_string_with_index", + fwevt_test_xml_value_get_data_as_utf16_string_with_index, + xml_value ); #if defined( HAVE_DEBUG_OUTPUT ) - /* TODO: add tests for libfwevt_debug_print_xml_value */ + /* TODO: add tests for libfwevt_debug_print_xml_value_with_index */ #endif /* defined( HAVE_DEBUG_OUTPUT ) */ diff --git a/tests/syncsharedlibs.sh b/tests/syncsharedlibs.sh index ac154ba..0597e4f 100755 --- a/tests/syncsharedlibs.sh +++ b/tests/syncsharedlibs.sh @@ -7,7 +7,7 @@ EXIT_SUCCESS=0; EXIT_FAILURE=1; GIT_URL_PREFIX="https://github.com/libyal"; -SHARED_LIBS="libcerror libcthreads libcdata libcnotify libuna libfdatetime libfguid libfvalue"; +SHARED_LIBS="libcerror libcthreads libcdata libcnotify libuna libfdatetime libfguid libfwnt"; USE_HEAD=""; diff --git a/tests/test_library.ps1 b/tests/test_library.ps1 index c486e1f..217e116 100644 --- a/tests/test_library.ps1 +++ b/tests/test_library.ps1 @@ -6,7 +6,7 @@ $ExitSuccess = 0 $ExitFailure = 1 $ExitIgnore = 77 -$LibraryTests = "channel date_time error event keyword level manifest map notify opcode provider support task template xml_document xml_tag xml_template_value xml_token xml_value" +$LibraryTests = "channel data_segment date_time error event keyword level manifest map notify opcode provider support task template xml_document xml_tag xml_template_value xml_token xml_value" $LibraryTestsWithInput = "" $OptionSets = "" diff --git a/tests/test_library.sh b/tests/test_library.sh index a20837e..03e4b92 100755 --- a/tests/test_library.sh +++ b/tests/test_library.sh @@ -7,7 +7,7 @@ EXIT_SUCCESS=0; EXIT_FAILURE=1; EXIT_IGNORE=77; -LIBRARY_TESTS="channel date_time error event keyword level manifest map notify opcode provider support task template xml_document xml_tag xml_template_value xml_token xml_value"; +LIBRARY_TESTS="channel data_segment date_time error event keyword level manifest map notify opcode provider support task template xml_document xml_tag xml_template_value xml_token xml_value"; LIBRARY_TESTS_WITH_INPUT=""; OPTION_SETS=();