From f779a476b69f3e3c2843c829c52534ed3488d62f Mon Sep 17 00:00:00 2001 From: Joachim Metz Date: Fri, 19 Apr 2024 07:51:03 +0200 Subject: [PATCH] Worked on format support --- appveyor.yml | 4 ++ configure.ac | 2 +- include/libfwevt/definitions.h.in | 3 ++ libfwevt/libfwevt_definitions.h.in | 3 ++ libfwevt/libfwevt_xml_document.c | 68 ++++++++++++++++-------------- m4/python.m4 | 9 ++-- tests/fwevt_test_xml_document.c | 18 ++++---- tests/test_python_module.sh | 6 +-- 8 files changed, 65 insertions(+), 48 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 1d6d924..0cd75b3 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -242,6 +242,10 @@ environment: APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022 CONFIGURE_OPTIONS: "--enable-python" +matrix: + allow_failures: + - TARGET: mingw-w64-gcc-python + install: - cmd: if [%BUILD_ENVIRONMENT%]==[msbuild] ( git clone https://github.com/libyal/vstools.git ..\vstools ) diff --git a/configure.ac b/configure.ac index a09e611..5d935bc 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ AC_PREREQ([2.71]) AC_INIT( [libfwevt], - [20240416], + [20240419], [joachim.metz@gmail.com]) AC_CONFIG_SRCDIR( diff --git a/include/libfwevt/definitions.h.in b/include/libfwevt/definitions.h.in index 897cb87..6f7805b 100644 --- a/include/libfwevt/definitions.h.in +++ b/include/libfwevt/definitions.h.in @@ -43,6 +43,9 @@ enum LIBFWEVT_ENDIAN enum LIBFWEVT_XML_DOCUMENT_READ_FLAGS { LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DATA_OFFSETS = 0x01, + + /* The dependency identifiers flag has been deprecated and is no longer needed + */ LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DEPENDENCY_IDENTIFIERS = 0x02 }; diff --git a/libfwevt/libfwevt_definitions.h.in b/libfwevt/libfwevt_definitions.h.in index 498ed7b..a84b2fa 100644 --- a/libfwevt/libfwevt_definitions.h.in +++ b/libfwevt/libfwevt_definitions.h.in @@ -52,6 +52,9 @@ enum LIBFWEVT_XML_DOCUMENT_READ_FLAGS { LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DATA_OFFSETS = 0x01, + + /* The dependency identifiers flag has been deprecated and is no longer needed + */ LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DEPENDENCY_IDENTIFIERS = 0x02 }; diff --git a/libfwevt/libfwevt_xml_document.c b/libfwevt/libfwevt_xml_document.c index 7f762f2..60449e7 100644 --- a/libfwevt/libfwevt_xml_document.c +++ b/libfwevt/libfwevt_xml_document.c @@ -577,7 +577,7 @@ int libfwevt_xml_document_read_attribute( return( -1 ); } - if( ( flags & LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DATA_OFFSETS ) == 0 ) + if( ( flags & LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DATA_OFFSETS ) != 0 ) { additional_value_size = 4; @@ -650,7 +650,7 @@ int libfwevt_xml_document_read_attribute( libcnotify_print_data( &( xml_document_data[ xml_document_data_offset ] ), additional_value_size + 1, - 0 ); + LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); } #endif #if defined( HAVE_DEBUG_OUTPUT ) @@ -733,7 +733,7 @@ int libfwevt_xml_document_read_attribute( libcnotify_print_data( &( xml_document_data[ xml_document_data_offset ] ), trailing_data_size, - 0 ); + LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); } #endif xml_document_data_offset += trailing_data_size; @@ -1105,7 +1105,7 @@ int libfwevt_xml_document_read_cdata_section( libcnotify_print_data( xml_document_data, 3, - 0 ); + LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); } #endif byte_stream_copy_to_uint16_little_endian( @@ -1157,7 +1157,7 @@ int libfwevt_xml_document_read_cdata_section( libcnotify_print_data( &( xml_document_data[ 3 ] ), value_data_size, - 0 ); + LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); } #endif if( libfwevt_xml_tag_set_value_type( @@ -1691,22 +1691,12 @@ int libfwevt_xml_document_read_element( return( -1 ); } - if( ( flags & LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DATA_OFFSETS ) == 0 ) + if( ( flags & LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DATA_OFFSETS ) != 0 ) { additional_value_size = 4; } - if( ( flags & LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DEPENDENCY_IDENTIFIERS ) == 0 ) - { - element_size_offset = 1; - } - else - { - element_size_offset = 3; - } - xml_document_data = &( binary_data[ binary_data_offset ] ); - xml_document_data_size = binary_data_size - binary_data_offset; - - if( xml_document_data_size < ( element_size_offset + 4 + additional_value_size ) ) + if( ( binary_data_size < ( 5 + additional_value_size ) ) + || ( binary_data_offset > ( binary_data_size - 5 - additional_value_size ) ) ) { libcerror_error_set( error, @@ -1730,6 +1720,9 @@ int libfwevt_xml_document_read_element( goto on_error; } + xml_document_data = &( binary_data[ binary_data_offset ] ); + xml_document_data_size = binary_data_size - binary_data_offset; + do { if( ( template_value_array_recursion_depth < 0 ) @@ -1757,6 +1750,19 @@ int libfwevt_xml_document_read_element( goto on_error; } + /* Note that the dependency identifier is an optional value. + */ + element_size_offset = 1; + + byte_stream_copy_to_uint32_little_endian( + &( xml_document_data[ element_size_offset ] ), + element_size ); + + if( ( xml_document_data_size > 7 ) + && ( element_size > ( xml_document_data_size - 7 ) ) ) + { + element_size_offset = 3; + } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { @@ -1771,7 +1777,7 @@ int libfwevt_xml_document_read_element( libcnotify_print_data( xml_document_data, element_size_offset + 4 + additional_value_size, - 0 ); + LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); } #endif byte_stream_copy_to_uint32_little_endian( @@ -1877,7 +1883,7 @@ int libfwevt_xml_document_read_element( libcnotify_print_data( &( xml_document_data[ xml_document_data_offset ] ), trailing_data_size, - 0 ); + LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); } #endif xml_document_data_offset += trailing_data_size; @@ -2649,7 +2655,7 @@ int libfwevt_xml_document_read_entity_reference( return( -1 ); } - if( ( flags & LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DATA_OFFSETS ) == 0 ) + if( ( flags & LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DATA_OFFSETS ) != 0 ) { additional_value_size = 4; } @@ -2681,7 +2687,7 @@ int libfwevt_xml_document_read_entity_reference( libcnotify_print_data( xml_document_data, 1 + additional_value_size, - 0 ); + LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); } #endif #if defined( HAVE_DEBUG_OUTPUT ) @@ -2766,7 +2772,7 @@ int libfwevt_xml_document_read_entity_reference( libcnotify_print_data( &( xml_document_data[ xml_document_data_offset ] ), trailing_data_size, - 0 ); + LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); } #endif xml_token->size += trailing_data_size; @@ -3503,7 +3509,7 @@ int libfwevt_xml_document_read_name( libcnotify_print_data( xml_document_data, additional_value_size + 4, - 0 ); + LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); } #endif if( ( flags & LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DATA_OFFSETS ) != 0 ) @@ -3581,7 +3587,7 @@ int libfwevt_xml_document_read_name( libcnotify_print_data( &( xml_document_data[ xml_document_data_offset ] ), name_size, - 0 ); + LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); } #endif if( libfwevt_xml_tag_set_name_data( @@ -4173,7 +4179,7 @@ int libfwevt_xml_document_read_pi_data( libcnotify_print_data( &( xml_document_data[ 3 ] ), value_data_size, - 0 ); + LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); } #endif if( libfwevt_xml_tag_set_value_type( @@ -4332,7 +4338,7 @@ int libfwevt_xml_document_read_pi_target( return( -1 ); } - if( ( flags & LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DATA_OFFSETS ) == 0 ) + if( ( flags & LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DATA_OFFSETS ) != 0 ) { additional_value_size = 4; } @@ -4391,7 +4397,7 @@ int libfwevt_xml_document_read_pi_target( libcnotify_print_data( xml_document_data, 1 + additional_value_size, - 0 ); + LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); } #endif #if defined( HAVE_DEBUG_OUTPUT ) @@ -4485,7 +4491,7 @@ int libfwevt_xml_document_read_pi_target( libcnotify_print_data( &( xml_document_data[ 5 ] ), trailing_data_size, - 0 ); + LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); } #endif xml_token->size += trailing_data_size; @@ -4822,7 +4828,7 @@ int libfwevt_xml_document_read_template_instance( libcnotify_print_data( &( binary_data[ binary_data_offset ] ), trailing_data_size, - 0 ); + LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA ); } #endif xml_token->size += trailing_data_size; @@ -6068,7 +6074,7 @@ int libfwevt_xml_document_substitute_template_value( binary_data_size, binary_data_offset, ascii_codepage, - flags & ~( LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DEPENDENCY_IDENTIFIERS ), + flags, template_values_array, xml_tag, element_recursion_depth + 1, diff --git a/m4/python.m4 b/m4/python.m4 index baa991b..87f89bd 100644 --- a/m4/python.m4 +++ b/m4/python.m4 @@ -1,6 +1,6 @@ dnl Functions for Python bindings dnl -dnl Version: 20240416 +dnl Version: 20240418 dnl Function to check if the python binary is available dnl "python${PYTHON_VERSION} python python# python#.#" @@ -78,9 +78,10 @@ AC_DEFUN([AX_PYTHON_CHECK], dnl For CygWin and MinGW add the -no-undefined linker flag AS_CASE( - [$host_os], - [cygwin*],[PYTHON_LDFLAGS="${PYTHON_LDFLAGS} -no-undefined"], - [mingw*],[PYTHON_LDFLAGS="${PYTHON_LDFLAGS} -no-undefined"], + [$build], + [*-*-cygwin*],[PYTHON_LDFLAGS="${PYTHON_LDFLAGS} -no-undefined"], + [*-*-mingw*],[PYTHON_LDFLAGS="${PYTHON_LDFLAGS} -no-undefined"], + [*-*-msys*],[PYTHON_LDFLAGS="${PYTHON_LDFLAGS} -no-undefined"], [*],[]) dnl Check for the existence of Python.h diff --git a/tests/fwevt_test_xml_document.c b/tests/fwevt_test_xml_document.c index 7aa629f..388f640 100644 --- a/tests/fwevt_test_xml_document.c +++ b/tests/fwevt_test_xml_document.c @@ -4518,7 +4518,7 @@ int fwevt_test_xml_document_read( 65536, 0x850, LIBUNA_CODEPAGE_WINDOWS_1252, - LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DATA_OFFSETS | LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DEPENDENCY_IDENTIFIERS, + LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DATA_OFFSETS, &error ); FWEVT_TEST_ASSERT_EQUAL_INT( @@ -4538,7 +4538,7 @@ int fwevt_test_xml_document_read( 65536, 0x850, LIBUNA_CODEPAGE_WINDOWS_1252, - LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DATA_OFFSETS | LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DEPENDENCY_IDENTIFIERS, + LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DATA_OFFSETS, &error ); FWEVT_TEST_ASSERT_EQUAL_INT( @@ -4628,7 +4628,7 @@ int fwevt_test_xml_document_read_with_template_values( 65536, 0x850, LIBUNA_CODEPAGE_WINDOWS_1252, - LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DATA_OFFSETS | LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DEPENDENCY_IDENTIFIERS, + LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DATA_OFFSETS, NULL, &error ); @@ -4687,7 +4687,7 @@ int fwevt_test_xml_document_read_with_template_values( 65536, 0x850, LIBUNA_CODEPAGE_WINDOWS_1252, - LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DATA_OFFSETS | LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DEPENDENCY_IDENTIFIERS, + LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DATA_OFFSETS, NULL, &error ); @@ -4709,7 +4709,7 @@ int fwevt_test_xml_document_read_with_template_values( 65536, 0x850, LIBUNA_CODEPAGE_WINDOWS_1252, - LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DATA_OFFSETS | LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DEPENDENCY_IDENTIFIERS, + LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DATA_OFFSETS, NULL, &error ); @@ -4731,7 +4731,7 @@ int fwevt_test_xml_document_read_with_template_values( (size_t) SSIZE_MAX + 1, 0x850, LIBUNA_CODEPAGE_WINDOWS_1252, - LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DATA_OFFSETS | LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DEPENDENCY_IDENTIFIERS, + LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DATA_OFFSETS, NULL, &error ); @@ -4755,7 +4755,7 @@ int fwevt_test_xml_document_read_with_template_values( 65536, 65536, LIBUNA_CODEPAGE_WINDOWS_1252, - LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DATA_OFFSETS | LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DEPENDENCY_IDENTIFIERS, + LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DATA_OFFSETS, NULL, &error ); @@ -4779,7 +4779,7 @@ int fwevt_test_xml_document_read_with_template_values( 11, 0x850, LIBUNA_CODEPAGE_WINDOWS_1252, - LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DATA_OFFSETS | LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DEPENDENCY_IDENTIFIERS, + LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DATA_OFFSETS, NULL, &error ); @@ -5311,7 +5311,7 @@ int main( 65536, 0x850, LIBUNA_CODEPAGE_WINDOWS_1252, - LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DATA_OFFSETS | LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DEPENDENCY_IDENTIFIERS, + LIBFWEVT_XML_DOCUMENT_READ_FLAG_HAS_DATA_OFFSETS, &error ); FWEVT_TEST_ASSERT_EQUAL_INT( diff --git a/tests/test_python_module.sh b/tests/test_python_module.sh index 1ec1ac5..699f564 100755 --- a/tests/test_python_module.sh +++ b/tests/test_python_module.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Tests Python module functions and types. # -# Version: 20240416 +# Version: 20240417 EXIT_SUCCESS=0; EXIT_FAILURE=1; @@ -143,9 +143,9 @@ source ${TEST_RUNNER}; PLATFORM=`uname -s | sed 's/-.*$//'`; -if test "${PLATFORM}" = "MINGW64_NT"; +if test "${PLATFORM}" = "MINGW64_NT" || test "${PLATFORM}" = "MSYS_NT"; then - cp ../${LIBRARY_NAME}/.libs/${LIBRARY_NAME}-1.dll ../${PYTHON_MODULE}/libs/; + cp ../${LIBRARY_NAME}/.libs/*.dll ../${PYTHON_MODULE}/.libs/; cp ../${PYTHON_MODULE}/.libs/${PYTHON_MODULE}.dll ../${PYTHON_MODULE}/.libs/${PYTHON_MODULE}.pyd; fi