From 3e60abce371a0ed1dc0ede6b86bae1e2384d8682 Mon Sep 17 00:00:00 2001 From: Joachim Metz Date: Fri, 4 Nov 2016 11:40:52 +0100 Subject: [PATCH] Moved XML plist support to libfplist --- .gitignore | 1 + Makefile.am | 5 + acinclude.m4 | 4 +- appveyor.yml | 4 +- configure.ac | 11 +- include/libfvde/definitions.h.in | 2 +- libfvde.pc.in | 2 +- libfvde.spec.in | 4 +- libfvde/Makefile.am | 18 +- libfvde/libfvde_encrypted_metadata.c | 39 +- libfvde/libfvde_encryption_context_plist.c | 119 +- libfvde/libfvde_encryption_context_plist.h | 11 +- libfvde/libfvde_libfplist.h | 51 + libfvde/libfvde_metadata.c | 39 +- libfvde/libfvde_xml_plist.c | 506 ------- libfvde/libfvde_xml_plist.h | 78 -- libfvde/libfvde_xml_plist_attribute.c | 269 ---- libfvde/libfvde_xml_plist_attribute.h | 73 - libfvde/libfvde_xml_plist_key.c | 1399 -------------------- libfvde/libfvde_xml_plist_key.h | 113 -- libfvde/libfvde_xml_plist_parser.y | 464 ------- libfvde/libfvde_xml_plist_scanner.l | 236 ---- libfvde/libfvde_xml_plist_tag.c | 628 --------- libfvde/libfvde_xml_plist_tag.h | 120 -- m4/libfplist.m4 | 176 +++ msvscpp/Makefile.am | 1 + msvscpp/libfplist/libfplist.vcproj | 273 ++++ msvscpp/libfvde.sln | 16 + msvscpp/libfvde/libfvde.vcproj | 56 +- synclibs.ps1 | 2 +- synclibs.sh | 2 +- tests/fvde_test_encryption_context_plist.c | 282 ++++ tests/fvde_test_logical_volume.c | 57 + tests/fvde_test_support.c | 2 +- tests/fvde_test_volume_group.c | 99 ++ tests/test_api_types.ps1 | 2 +- tests/test_api_types.sh | 2 +- 37 files changed, 1102 insertions(+), 4064 deletions(-) create mode 100644 libfvde/libfvde_libfplist.h delete mode 100644 libfvde/libfvde_xml_plist.c delete mode 100644 libfvde/libfvde_xml_plist.h delete mode 100644 libfvde/libfvde_xml_plist_attribute.c delete mode 100644 libfvde/libfvde_xml_plist_attribute.h delete mode 100644 libfvde/libfvde_xml_plist_key.c delete mode 100644 libfvde/libfvde_xml_plist_key.h delete mode 100644 libfvde/libfvde_xml_plist_parser.y delete mode 100644 libfvde/libfvde_xml_plist_scanner.l delete mode 100644 libfvde/libfvde_xml_plist_tag.c delete mode 100644 libfvde/libfvde_xml_plist_tag.h create mode 100644 m4/libfplist.m4 create mode 100644 msvscpp/libfplist/libfplist.vcproj create mode 100644 tests/fvde_test_encryption_context_plist.c create mode 100644 tests/fvde_test_logical_volume.c create mode 100644 tests/fvde_test_volume_group.c diff --git a/.gitignore b/.gitignore index 9dc9ada..9848d7c 100644 --- a/.gitignore +++ b/.gitignore @@ -151,6 +151,7 @@ stamp-h[1-9] /libfcache /libfdata /libfguid +/libfplist /libfvalue /libhmac /libuna diff --git a/Makefile.am b/Makefile.am index 3163deb..228ba4c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -17,6 +17,7 @@ SUBDIRS = \ libfcache \ libfdata \ libfguid \ + libfplist \ libfvalue \ libhmac \ libcaes \ @@ -96,6 +97,8 @@ library: (cd $(srcdir)/libfcache && $(MAKE) $(AM_MAKEFLAGS)) (cd $(srcdir)/libfdata && $(MAKE) $(AM_MAKEFLAGS)) (cd $(srcdir)/libfguid && $(MAKE) $(AM_MAKEFLAGS)) + (cd $(srcdir)/libfvalue && $(MAKE) $(AM_MAKEFLAGS)) + (cd $(srcdir)/libfplist && $(MAKE) $(AM_MAKEFLAGS)) (cd $(srcdir)/libhmac && $(MAKE) $(AM_MAKEFLAGS)) (cd $(srcdir)/libcaes && $(MAKE) $(AM_MAKEFLAGS)) (cd $(srcdir)/libfvde && $(MAKE) $(AM_MAKEFLAGS)) @@ -128,6 +131,8 @@ splint: (cd $(srcdir)/libfcache && $(MAKE) splint $(AM_MAKEFLAGS)) (cd $(srcdir)/libfdata && $(MAKE) splint $(AM_MAKEFLAGS)) (cd $(srcdir)/libfguid && $(MAKE) splint $(AM_MAKEFLAGS)) + (cd $(srcdir)/libfvalue && $(MAKE) splint $(AM_MAKEFLAGS)) + (cd $(srcdir)/libfplist && $(MAKE) splint $(AM_MAKEFLAGS)) (cd $(srcdir)/libhmac && $(MAKE) splint $(AM_MAKEFLAGS)) (cd $(srcdir)/libcaes && $(MAKE) splint $(AM_MAKEFLAGS)) (cd $(srcdir)/libfvde && $(MAKE) splint $(AM_MAKEFLAGS)) diff --git a/acinclude.m4 b/acinclude.m4 index 2b7c5a9..172eb75 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -2,7 +2,5 @@ dnl Function to detect if libfvde dependencies are available AC_DEFUN([AX_LIBFVDE_CHECK_LOCAL], [dnl Check for internationalization functions in libfvde/libfvde_i18n.c AC_CHECK_FUNCS([bindtextdomain]) - - AM_PROG_LEX - AC_PROG_YACC]) + ]) diff --git a/appveyor.yml b/appveyor.yml index 1a12c82..5302e1a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -18,8 +18,8 @@ install: before_build: - ps: .\synclibs.ps1 - ps: .\autogen.ps1 - - cmd: ..\win_flex_bison\win_flex.exe -Cf libfvde\libfvde_xml_plist_scanner.l && move lex.yy.c libfvde\libfvde_xml_plist_scanner.c - - cmd: ..\win_flex_bison\win_bison.exe -d -v -l -p xml_plist_scanner_ libfvde\libfvde_xml_plist_parser.y && move libfvde_xml_plist_parser.tab.c libfvde\libfvde_xml_plist_parser.c && move libfvde_xml_plist_parser.tab.h libfvde\libfvde_xml_plist_parser.h + - cmd: ..\win_flex_bison\win_flex.exe -Cf libfplist\libfplist_xml_scanner.l && move lex.yy.c libfplist\libfplist_xml_scanner.c + - cmd: ..\win_flex_bison\win_bison.exe -d -v -l -p xml_scanner_ libfplist\libfplist_xml_parser.y && move libfplist_xml_parser.tab.c libfplist\libfplist_xml_parser.c && move libfplist_xml_parser.tab.h libfplist\libfplist_xml_parser.h - cmd: C:\Python27\python.exe ..\libyal\scripts\msvscpp-convert.py --to 2010 msvscpp\libfvde.sln build: diff --git a/configure.ac b/configure.ac index bba6770..d7dffdb 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ AC_PREREQ( 2.59 ) AC_INIT( [libfvde], - [20161103], + [20161104], [joachim.metz@gmail.com]) AC_CONFIG_SRCDIR( @@ -91,12 +91,15 @@ AX_LIBFCACHE_CHECK_ENABLE dnl Check for enabling libfdata for file data types support AX_LIBFDATA_CHECK_ENABLE -dnl Check for enabling libfguid for file GUID/UUID support +dnl Check for enabling libfguid for GUID/UUID format support AX_LIBFGUID_CHECK_ENABLE dnl Check for enabling libfvalue for file value support AX_LIBFVALUE_CHECK_ENABLE +dnl Check for enabling libfplist for plist formats support +AX_LIBFPLIST_CHECK_ENABLE + dnl Check for enabling libhmac for message digest hash function support AX_LIBHMAC_CHECK_ENABLE @@ -183,7 +186,7 @@ CFLAGS="$CFLAGS -Wall"; dnl Check if requires and build requires should be set in spec file AS_IF( - [test "x$ac_cv_libcstring" = xyes || test "x$ac_cv_libcerror" = xyes || test "x$ac_cv_libcthreads" = xyes || test "x$ac_cv_libcdata" = xyes || test "x$ac_cv_libclocale" = xyes || test "x$ac_cv_libcnotify" = xyes || test "x$ac_cv_libcsplit" = xyes || test "x$ac_cv_libuna" = xyes || test "x$ac_cv_libcfile" = xyes || test "x$ac_cv_libcpath" = xyes || test "x$ac_cv_libbfio" = xyes || test "x$ac_cv_libfdata" = xyes || test "x$ac_cv_libfguid" = xyes || test "x$ac_cv_libfvalue" = xyes || test "x$ac_cv_zlib" != xno || test "x$ac_cv_libcaes" = xyes || test "x$ac_cv_libhmac" = xyes || test "x$ac_cv_libcrypto" = xyes], + [test "x$ac_cv_libcstring" = xyes || test "x$ac_cv_libcerror" = xyes || test "x$ac_cv_libcthreads" = xyes || test "x$ac_cv_libcdata" = xyes || test "x$ac_cv_libclocale" = xyes || test "x$ac_cv_libcnotify" = xyes || test "x$ac_cv_libcsplit" = xyes || test "x$ac_cv_libuna" = xyes || test "x$ac_cv_libcfile" = xyes || test "x$ac_cv_libcpath" = xyes || test "x$ac_cv_libbfio" = xyes || test "x$ac_cv_libfdata" = xyes || test "x$ac_cv_libfguid" = xyes || test "x$ac_cv_libfvalue" = xyes || test "x$ac_cv_libfplist" = xyes || test "x$ac_cv_zlib" != xno || test "x$ac_cv_libcaes" = xyes || test "x$ac_cv_libhmac" = xyes || test "x$ac_cv_libcrypto" = xyes], [AC_SUBST( [libfvde_spec_requires], [Requires:]) @@ -233,6 +236,7 @@ AC_CONFIG_FILES([libfcache/Makefile]) AC_CONFIG_FILES([libfdata/Makefile]) AC_CONFIG_FILES([libfguid/Makefile]) AC_CONFIG_FILES([libfvalue/Makefile]) +AC_CONFIG_FILES([libfplist/Makefile]) AC_CONFIG_FILES([libhmac/Makefile]) AC_CONFIG_FILES([libcaes/Makefile]) AC_CONFIG_FILES([libfvde/Makefile]) @@ -282,6 +286,7 @@ Building: libfdata support: $ac_cv_libfdata libfguid support: $ac_cv_libfguid libfvalue support: $ac_cv_libfvalue + libfplist support: $ac_cv_libfplist DEFLATE compression support: $ac_cv_uncompress libhmac support: $ac_cv_libhmac SHA256 support: $ac_cv_libhmac_sha256 diff --git a/include/libfvde/definitions.h.in b/include/libfvde/definitions.h.in index 16fc846..662e2f6 100644 --- a/include/libfvde/definitions.h.in +++ b/include/libfvde/definitions.h.in @@ -1,7 +1,7 @@ /* * Definitions for libfvde * - * Copyright (C) 2011-2016, Omar Choudary + * Copyright (C) 2011-2016, Omar Choudary , * Joachim Metz * * Refer to AUTHORS for acknowledgements. diff --git a/libfvde.pc.in b/libfvde.pc.in index b00d722..68504f9 100644 --- a/libfvde.pc.in +++ b/libfvde.pc.in @@ -7,6 +7,6 @@ Name: libfvde Description: Library to access the FileVault Drive Encryption (FVDE) format Version: @VERSION@ Libs: -L${libdir} -lfvde -Libs.private: @ax_libbfio_pc_libs_private@ @ax_libcaes_pc_libs_private@ @ax_libcdata_pc_libs_private@ @ax_libcerror_pc_libs_private@ @ax_libcfile_pc_libs_private@ @ax_libclocale_pc_libs_private@ @ax_libcnotify_pc_libs_private@ @ax_libcpath_pc_libs_private@ @ax_libcrypto_pc_libs_private@ @ax_libcsplit_pc_libs_private@ @ax_libcstring_pc_libs_private@ @ax_libcthreads_pc_libs_private@ @ax_libfcache_pc_libs_private@ @ax_libfdata_pc_libs_private@ @ax_libfguid_pc_libs_private@ @ax_libfvalue_pc_libs_private@ @ax_libhmac_pc_libs_private@ @ax_libuna_pc_libs_private@ @ax_pthread_pc_libs_private@ @ax_zlib_pc_libs_private@ +Libs.private: @ax_libbfio_pc_libs_private@ @ax_libcaes_pc_libs_private@ @ax_libcdata_pc_libs_private@ @ax_libcerror_pc_libs_private@ @ax_libcfile_pc_libs_private@ @ax_libclocale_pc_libs_private@ @ax_libcnotify_pc_libs_private@ @ax_libcpath_pc_libs_private@ @ax_libcrypto_pc_libs_private@ @ax_libcsplit_pc_libs_private@ @ax_libcstring_pc_libs_private@ @ax_libcthreads_pc_libs_private@ @ax_libfcache_pc_libs_private@ @ax_libfdata_pc_libs_private@ @ax_libfguid_pc_libs_private@ @ax_libfplist_pc_libs_private@ @ax_libfvalue_pc_libs_private@ @ax_libhmac_pc_libs_private@ @ax_libuna_pc_libs_private@ @ax_pthread_pc_libs_private@ @ax_zlib_pc_libs_private@ Cflags: -I${includedir} diff --git a/libfvde.spec.in b/libfvde.spec.in index 3d1c2bb..85d9d6b 100644 --- a/libfvde.spec.in +++ b/libfvde.spec.in @@ -7,8 +7,8 @@ License: LGPL Source: %{name}-%{version}.tar.gz URL: https://github.com/libyal/libfvde/ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) -@libfvde_spec_requires@ @ax_libbfio_spec_requires@ @ax_libcaes_spec_requires@ @ax_libcdata_spec_requires@ @ax_libcerror_spec_requires@ @ax_libcfile_spec_requires@ @ax_libclocale_spec_requires@ @ax_libcnotify_spec_requires@ @ax_libcpath_spec_requires@ @ax_libcrypto_spec_requires@ @ax_libcsplit_spec_requires@ @ax_libcstring_spec_requires@ @ax_libcthreads_spec_requires@ @ax_libfcache_spec_requires@ @ax_libfdata_spec_requires@ @ax_libfguid_spec_requires@ @ax_libhmac_spec_requires@ @ax_libuna_spec_requires@ @ax_zlib_spec_requires@ -@libfvde_spec_build_requires@ @ax_libbfio_spec_build_requires@ @ax_libcaes_spec_build_requires@ @ax_libcdata_spec_build_requires@ @ax_libcerror_spec_build_requires@ @ax_libcfile_spec_build_requires@ @ax_libclocale_spec_build_requires@ @ax_libcnotify_spec_build_requires@ @ax_libcpath_spec_build_requires@ @ax_libcrypto_spec_build_requires@ @ax_libcsplit_spec_build_requires@ @ax_libcstring_spec_build_requires@ @ax_libcthreads_spec_build_requires@ @ax_libfcache_spec_build_requires@ @ax_libfdata_spec_build_requires@ @ax_libfguid_spec_build_requires@ @ax_libuna_spec_build_requires@ @ax_zlib_spec_build_requires@ +@libfvde_spec_requires@ @ax_libbfio_spec_requires@ @ax_libcaes_spec_requires@ @ax_libcdata_spec_requires@ @ax_libcerror_spec_requires@ @ax_libcfile_spec_requires@ @ax_libclocale_spec_requires@ @ax_libcnotify_spec_requires@ @ax_libcpath_spec_requires@ @ax_libcrypto_spec_requires@ @ax_libcsplit_spec_requires@ @ax_libcstring_spec_requires@ @ax_libcthreads_spec_requires@ @ax_libfcache_spec_requires@ @ax_libfdata_spec_requires@ @ax_libfguid_spec_requires@ @ax_libfplist_spec_requires@ @ax_libfvalue_spec_requires@ @ax_libhmac_spec_requires@ @ax_libuna_spec_requires@ @ax_zlib_spec_requires@ +@libfvde_spec_build_requires@ @ax_libbfio_spec_build_requires@ @ax_libcaes_spec_build_requires@ @ax_libcdata_spec_build_requires@ @ax_libcerror_spec_build_requires@ @ax_libcfile_spec_build_requires@ @ax_libclocale_spec_build_requires@ @ax_libcnotify_spec_build_requires@ @ax_libcpath_spec_build_requires@ @ax_libcrypto_spec_build_requires@ @ax_libcsplit_spec_build_requires@ @ax_libcstring_spec_build_requires@ @ax_libcthreads_spec_build_requires@ @ax_libfcache_spec_build_requires@ @ax_libfdata_spec_build_requires@ @ax_libfguid_spec_build_requires@ @ax_libfplist_spec_build_requires@ @ax_libfvalue_spec_build_requires@ @ax_libuna_spec_build_requires@ @ax_zlib_spec_build_requires@ %description libfvde is a library to access the FileVault Drive Encryption (FVDE) format diff --git a/libfvde/Makefile.am b/libfvde/Makefile.am index 25a5cf8..b70294c 100644 --- a/libfvde/Makefile.am +++ b/libfvde/Makefile.am @@ -1,6 +1,3 @@ -AM_LFLAGS = -Cf -AM_YFLAGS = -d -v -l -p xml_plist_scanner_ - AM_CPPFLAGS = \ -I$(top_srcdir)/include \ -I$(top_srcdir)/common \ @@ -19,13 +16,12 @@ AM_CPPFLAGS = \ @LIBFDATA_CPPFLAGS@ \ @LIBFGUID_CPPFLAGS@ \ @LIBFVALUE_CPPFLAGS@ \ + @LIBFPLIST_CPPFLAGS@ \ @ZLIB_CPPFLAGS@ \ @LIBCRYPTO_CPPFLAGS@ \ @LIBHMAC_CPPFLAGS@ \ @LIBCAES_CPPFLAGS@ -BUILT_SOURCES = libfvde_xml_plist_parser.h - lib_LTLIBRARIES = libfvde.la libfvde_la_SOURCES = \ @@ -58,6 +54,7 @@ libfvde_la_SOURCES = \ libfvde_libfcache.h \ libfvde_libfdata.h \ libfvde_libfguid.h \ + libfvde_libfplist.h \ libfvde_libfvalue.h \ libfvde_libhmac.h \ libfvde_libuna.h \ @@ -70,13 +67,7 @@ libfvde_la_SOURCES = \ libfvde_types.h \ libfvde_unused.h \ libfvde_volume.c libfvde_volume.h \ - libfvde_volume_group.c libfvde_volume_group.h \ - libfvde_xml_plist.c libfvde_xml_plist.h \ - libfvde_xml_plist_attribute.c libfvde_xml_plist_attribute.h \ - libfvde_xml_plist_key.c libfvde_xml_plist_key.h \ - libfvde_xml_plist_parser.y \ - libfvde_xml_plist_scanner.l \ - libfvde_xml_plist_tag.c libfvde_xml_plist_tag.h + libfvde_volume_group.c libfvde_volume_group.h libfvde_la_LIBADD = \ @LIBCSTRING_LIBADD@ \ @@ -94,6 +85,7 @@ libfvde_la_LIBADD = \ @LIBFDATA_LIBADD@ \ @LIBFGUID_LIBADD@ \ @LIBFVALUE_LIBADD@ \ + @LIBFPLIST_LIBADD@ \ @ZLIB_LIBADD@ \ @LIBHMAC_LIBADD@ \ @LIBCAES_LIBADD@ \ @@ -105,8 +97,6 @@ libfvde_la_LDFLAGS = -no-undefined -version-info 1:0:0 EXTRA_DIST = \ libfvde_definitions.h.in \ - libfvde_xml_plist_parser.c libfvde_xml_plist_parser.h \ - libfvde_xml_plist_scanner.c \ libfvde.rc \ libfvde.rc.in diff --git a/libfvde/libfvde_encrypted_metadata.c b/libfvde/libfvde_encrypted_metadata.c index c77441d..79715aa 100644 --- a/libfvde/libfvde_encrypted_metadata.c +++ b/libfvde/libfvde_encrypted_metadata.c @@ -38,11 +38,10 @@ #include "libfvde_libcnotify.h" #include "libfvde_libcstring.h" #include "libfvde_libfguid.h" +#include "libfvde_libfplist.h" #include "libfvde_libfvalue.h" #include "libfvde_metadata_block.h" #include "libfvde_password.h" -#include "libfvde_xml_plist.h" -#include "libfvde_xml_plist_key.h" #include "fvde_metadata.h" @@ -1696,9 +1695,9 @@ int libfvde_encrypted_metadata_read_type_0x001a( size_t block_data_size, libcerror_error_t **error ) { - libfvde_xml_plist_t *xml_plist = NULL; - libfvde_xml_plist_key_t *root_key = NULL; - libfvde_xml_plist_key_t *xml_plist_key = NULL; + libfplist_plist_t *xml_plist = NULL; + libfplist_key_t *root_key = NULL; + libfplist_key_t *xml_plist_key = NULL; const uint8_t *xml_plist_data = NULL; static char *function = "libfvde_encrypted_metadata_read_type_0x001a"; size_t xml_length = 0; @@ -1876,7 +1875,7 @@ int libfvde_encrypted_metadata_read_type_0x001a( goto on_error; } - if( libfvde_xml_plist_initialize( + if( libfplist_plist_initialize( &xml_plist, error ) != 1 ) { @@ -1889,7 +1888,7 @@ int libfvde_encrypted_metadata_read_type_0x001a( goto on_error; } - if( libfvde_xml_plist_copy_from_byte_stream( + if( libfplist_plist_copy_from_byte_stream( xml_plist, xml_plist_data, xml_length + 1, @@ -1904,7 +1903,7 @@ int libfvde_encrypted_metadata_read_type_0x001a( goto on_error; } - if( libfvde_xml_plist_get_root_key( + if( libfplist_plist_get_root_key( xml_plist, &root_key, error ) != 1 ) @@ -1918,7 +1917,7 @@ int libfvde_encrypted_metadata_read_type_0x001a( goto on_error; } - if( libfvde_xml_plist_key_get_sub_key_by_utf8_name( + if( libfplist_key_get_sub_key_by_utf8_name( root_key, (uint8_t *) "com.apple.corestorage.lv.familyUUID", 35, @@ -1937,7 +1936,7 @@ int libfvde_encrypted_metadata_read_type_0x001a( #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { - if( libfvde_xml_plist_key_get_value_string( + if( libfplist_key_get_value_string( xml_plist_key, &string, &string_size, @@ -1963,7 +1962,7 @@ int libfvde_encrypted_metadata_read_type_0x001a( string = NULL; } #endif - if( libfvde_xml_plist_key_value_uuid_string_copy_to_byte_stream( + if( libfplist_key_value_uuid_string_copy_to_byte_stream( xml_plist_key, encrypted_metadata->logical_volume_family_identifier, 16, @@ -1978,7 +1977,7 @@ int libfvde_encrypted_metadata_read_type_0x001a( goto on_error; } - if( libfvde_xml_plist_key_free( + if( libfplist_key_free( &xml_plist_key, error ) != 1 ) { @@ -1991,7 +1990,7 @@ int libfvde_encrypted_metadata_read_type_0x001a( goto on_error; } - if( libfvde_xml_plist_key_get_sub_key_by_utf8_name( + if( libfplist_key_get_sub_key_by_utf8_name( root_key, (uint8_t *) "com.apple.corestorage.lv.size", 29, @@ -2007,7 +2006,7 @@ int libfvde_encrypted_metadata_read_type_0x001a( goto on_error; } - if( libfvde_xml_plist_key_get_value_integer( + if( libfplist_key_get_value_integer( xml_plist_key, (uint64_t *) &logical_volume_size, error ) != 1 ) @@ -2030,7 +2029,7 @@ int libfvde_encrypted_metadata_read_type_0x001a( logical_volume_size ); } #endif - if( libfvde_xml_plist_key_free( + if( libfplist_key_free( &xml_plist_key, error ) != 1 ) { @@ -2043,7 +2042,7 @@ int libfvde_encrypted_metadata_read_type_0x001a( goto on_error; } - if( libfvde_xml_plist_key_free( + if( libfplist_key_free( &root_key, error ) != 1 ) { @@ -2056,7 +2055,7 @@ int libfvde_encrypted_metadata_read_type_0x001a( goto on_error; } - if( libfvde_xml_plist_free( + if( libfplist_plist_free( &xml_plist, error ) != 1 ) { @@ -2089,19 +2088,19 @@ int libfvde_encrypted_metadata_read_type_0x001a( #endif if( xml_plist_key != NULL ) { - libfvde_xml_plist_key_free( + libfplist_key_free( &xml_plist_key, NULL ); } if( root_key != NULL ) { - libfvde_xml_plist_key_free( + libfplist_key_free( &root_key, NULL ); } if( xml_plist != NULL ) { - libfvde_xml_plist_free( + libfplist_plist_free( &xml_plist, NULL ); } diff --git a/libfvde/libfvde_encryption_context_plist.c b/libfvde/libfvde_encryption_context_plist.c index 6866a1d..0f438ba 100644 --- a/libfvde/libfvde_encryption_context_plist.c +++ b/libfvde/libfvde_encryption_context_plist.c @@ -27,11 +27,10 @@ #include "libfvde_encryption_context_plist.h" #include "libfvde_libcerror.h" #include "libfvde_libcnotify.h" +#include "libfvde_libfplist.h" #include "libfvde_libhmac.h" #include "libfvde_libuna.h" #include "libfvde_types.h" -#include "libfvde_xml_plist.h" -#include "libfvde_xml_plist_key.h" /* Creates an encryption context plist * Make sure the value plist is referencing, is set to NULL @@ -146,7 +145,7 @@ int libfvde_encryption_context_plist_free( } if( internal_plist->wrapped_volume_keys_key != NULL ) { - if( libfvde_xml_plist_key_free( + if( libfplist_key_free( &( internal_plist->wrapped_volume_keys_key ), error ) != 1 ) { @@ -162,7 +161,7 @@ int libfvde_encryption_context_plist_free( } if( internal_plist->crypto_users_key != NULL ) { - if( libfvde_xml_plist_key_free( + if( libfplist_key_free( &( internal_plist->crypto_users_key ), error ) != 1 ) { @@ -178,7 +177,7 @@ int libfvde_encryption_context_plist_free( } if( internal_plist->conversion_info_key != NULL ) { - if( libfvde_xml_plist_key_free( + if( libfplist_key_free( &( internal_plist->conversion_info_key ), error ) != 1 ) { @@ -194,7 +193,7 @@ int libfvde_encryption_context_plist_free( } if( internal_plist->xml_plist != NULL ) { - if( libfvde_xml_plist_free( + if( libfplist_plist_free( &( internal_plist->xml_plist ), error ) != 1 ) { @@ -851,7 +850,7 @@ int libfvde_encryption_context_plist_decrypt( on_error: if( internal_plist->xml_plist != NULL ) { - libfvde_xml_plist_free( + libfplist_plist_free( &( internal_plist->xml_plist ), NULL ); } @@ -879,8 +878,8 @@ int libfvde_encryption_context_plist_read_xml( libcerror_error_t **error ) { libfvde_internal_encryption_context_plist_t *internal_plist = NULL; - libfvde_xml_plist_key_t *encryption_context_key = NULL; - libfvde_xml_plist_key_t *root_key = NULL; + libfplist_key_t *encryption_context_key = NULL; + libfplist_key_t *root_key = NULL; static char *function = "libfvde_encryption_context_plist_read_xml"; int result = 0; @@ -941,7 +940,7 @@ int libfvde_encryption_context_plist_read_xml( goto on_error; } - if( libfvde_xml_plist_initialize( + if( libfplist_plist_initialize( &( internal_plist->xml_plist ), error ) != 1 ) { @@ -954,7 +953,7 @@ int libfvde_encryption_context_plist_read_xml( goto on_error; } - if( libfvde_xml_plist_copy_from_byte_stream( + if( libfplist_plist_copy_from_byte_stream( internal_plist->xml_plist, internal_plist->data_decrypted, (size_t) internal_plist->data_size, @@ -969,7 +968,7 @@ int libfvde_encryption_context_plist_read_xml( goto on_error; } - if( libfvde_xml_plist_get_root_key( + if( libfplist_plist_get_root_key( internal_plist->xml_plist, &root_key, error ) != 1 ) @@ -983,7 +982,7 @@ int libfvde_encryption_context_plist_read_xml( goto on_error; } - result = libfvde_xml_plist_key_get_sub_key_by_utf8_name( + result = libfplist_key_get_sub_key_by_utf8_name( root_key, (uint8_t *) "com.apple.corestorage.lvf.encryption.context", 44, @@ -1007,10 +1006,24 @@ int libfvde_encryption_context_plist_read_xml( } else { -/* TODO replace by function after refactoring */ - if( internal_plist->xml_plist->plist_tag != NULL ) + result = libfplist_plist_has_plist_root_element( + internal_plist->xml_plist, + error ); + + if( result == -1 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_GET_FAILED, + "%s: unable to determine if plist has plist root element.", + function ); + + goto on_error; + } + else if( result == 1 ) { - if( libfvde_xml_plist_free( + if( libfplist_plist_free( &( internal_plist->xml_plist ), error ) != 1 ) { @@ -1026,7 +1039,7 @@ int libfvde_encryption_context_plist_read_xml( return( 0 ); } } - if( libfvde_xml_plist_key_is_dict( + if( libfplist_key_is_dict( encryption_context_key, error ) != 1 ) { @@ -1039,7 +1052,7 @@ int libfvde_encryption_context_plist_read_xml( goto on_error; } - if( libfvde_xml_plist_key_get_sub_key_by_utf8_name( + if( libfplist_key_get_sub_key_by_utf8_name( encryption_context_key, (uint8_t *) "ConversionInfo", 14, @@ -1055,7 +1068,7 @@ int libfvde_encryption_context_plist_read_xml( goto on_error; } - if( libfvde_xml_plist_key_get_sub_key_by_utf8_name( + if( libfplist_key_get_sub_key_by_utf8_name( encryption_context_key, (uint8_t *) "CryptoUsers", 11, @@ -1071,7 +1084,7 @@ int libfvde_encryption_context_plist_read_xml( goto on_error; } - if( libfvde_xml_plist_key_get_array_number_of_entries( + if( libfplist_key_get_array_number_of_entries( internal_plist->crypto_users_key, &( internal_plist->number_of_crypto_users_entries ), error ) != 1 ) @@ -1085,7 +1098,7 @@ int libfvde_encryption_context_plist_read_xml( goto on_error; } - if( libfvde_xml_plist_key_get_sub_key_by_utf8_name( + if( libfplist_key_get_sub_key_by_utf8_name( encryption_context_key, (uint8_t *) "WrappedVolumeKeys", 17, @@ -1103,7 +1116,7 @@ int libfvde_encryption_context_plist_read_xml( } if( encryption_context_key != root_key ) { - if( libfvde_xml_plist_key_free( + if( libfplist_key_free( &encryption_context_key, error ) != 1 ) { @@ -1117,7 +1130,7 @@ int libfvde_encryption_context_plist_read_xml( goto on_error; } } - if( libfvde_xml_plist_key_free( + if( libfplist_key_free( &root_key, error ) != 1 ) { @@ -1135,38 +1148,38 @@ int libfvde_encryption_context_plist_read_xml( on_error: if( internal_plist->wrapped_volume_keys_key != NULL ) { - libfvde_xml_plist_key_free( + libfplist_key_free( &( internal_plist->wrapped_volume_keys_key ), NULL ); } if( internal_plist->crypto_users_key != NULL ) { - libfvde_xml_plist_key_free( + libfplist_key_free( &( internal_plist->crypto_users_key ), NULL ); } if( internal_plist->conversion_info_key != NULL ) { - libfvde_xml_plist_key_free( + libfplist_key_free( &( internal_plist->conversion_info_key ), NULL ); } if( ( encryption_context_key != NULL ) && ( encryption_context_key != root_key ) ) { - libfvde_xml_plist_key_free( + libfplist_key_free( &encryption_context_key, NULL ); } if( root_key != NULL ) { - libfvde_xml_plist_key_free( + libfplist_key_free( &root_key, NULL ); } if( internal_plist->xml_plist != NULL ) { - libfvde_xml_plist_free( + libfplist_plist_free( &( internal_plist->xml_plist ), NULL ); } @@ -1183,7 +1196,7 @@ int libfvde_encryption_context_plist_get_conversion_status( libcerror_error_t **error ) { libfvde_internal_encryption_context_plist_t *internal_plist = NULL; - libfvde_xml_plist_key_t *xml_plist_key = NULL; + libfplist_key_t *xml_plist_key = NULL; static char *function = "libfvde_encryption_context_plist_get_conversion_status"; if( plist == NULL ) @@ -1243,7 +1256,7 @@ int libfvde_encryption_context_plist_get_conversion_status( return( -1 ); } - if( libfvde_xml_plist_key_get_sub_key_by_utf8_name( + if( libfplist_key_get_sub_key_by_utf8_name( internal_plist->conversion_info_key, (uint8_t *) "ConversionStatus", 16, @@ -1259,7 +1272,7 @@ int libfvde_encryption_context_plist_get_conversion_status( goto on_error; } - if( libfvde_xml_plist_key_get_value_string( + if( libfplist_key_get_value_string( xml_plist_key, conversion_status, conversion_status_size, @@ -1286,7 +1299,7 @@ int libfvde_encryption_context_plist_get_conversion_status( 0 ); } #endif - if( libfvde_xml_plist_key_free( + if( libfplist_key_free( &xml_plist_key, error ) != 1 ) { @@ -1304,7 +1317,7 @@ int libfvde_encryption_context_plist_get_conversion_status( on_error: if( xml_plist_key != NULL ) { - libfvde_xml_plist_key_free( + libfplist_key_free( &xml_plist_key, NULL ); } @@ -1331,8 +1344,8 @@ int libfvde_encryption_context_plist_get_passphrase_wrapped_kek( libcerror_error_t **error ) { libfvde_internal_encryption_context_plist_t *internal_plist = NULL; - libfvde_xml_plist_key_t *xml_plist_array_entry = NULL; - libfvde_xml_plist_key_t *xml_plist_key = NULL; + libfplist_key_t *xml_plist_array_entry = NULL; + libfplist_key_t *xml_plist_key = NULL; static char *function = "libfvde_encryption_context_plist_get_passphrase_wrapped_kek"; if( plist == NULL ) @@ -1407,7 +1420,7 @@ int libfvde_encryption_context_plist_get_passphrase_wrapped_kek( { return( 0 ); } - if( libfvde_xml_plist_key_get_array_entry_by_index( + if( libfplist_key_get_array_entry_by_index( internal_plist->crypto_users_key, passphrase_wrapped_kek_index, &xml_plist_array_entry, @@ -1423,7 +1436,7 @@ int libfvde_encryption_context_plist_get_passphrase_wrapped_kek( goto on_error; } - if( libfvde_xml_plist_key_get_sub_key_by_utf8_name( + if( libfplist_key_get_sub_key_by_utf8_name( xml_plist_array_entry, (uint8_t *) "PassphraseWrappedKEKStruct", 26, @@ -1439,7 +1452,7 @@ int libfvde_encryption_context_plist_get_passphrase_wrapped_kek( goto on_error; } - if( libfvde_xml_plist_key_get_value_data( + if( libfplist_key_get_value_data( xml_plist_key, passphrase_wrapped_kek, passphrase_wrapped_kek_size, @@ -1466,7 +1479,7 @@ int libfvde_encryption_context_plist_get_passphrase_wrapped_kek( 0 ); } #endif - if( libfvde_xml_plist_key_free( + if( libfplist_key_free( &xml_plist_key, error ) != 1 ) { @@ -1479,7 +1492,7 @@ int libfvde_encryption_context_plist_get_passphrase_wrapped_kek( goto on_error; } - if( libfvde_xml_plist_key_free( + if( libfplist_key_free( &xml_plist_array_entry, error ) != 1 ) { @@ -1498,13 +1511,13 @@ int libfvde_encryption_context_plist_get_passphrase_wrapped_kek( on_error: if( xml_plist_key != NULL ) { - libfvde_xml_plist_key_free( + libfplist_key_free( &xml_plist_key, NULL ); } if( xml_plist_array_entry != NULL ) { - libfvde_xml_plist_key_free( + libfplist_key_free( &xml_plist_array_entry, NULL ); } @@ -1530,8 +1543,8 @@ int libfvde_encryption_context_plist_get_kek_wrapped_volume_key( libcerror_error_t **error ) { libfvde_internal_encryption_context_plist_t *internal_plist = NULL; - libfvde_xml_plist_key_t *xml_plist_array_entry = NULL; - libfvde_xml_plist_key_t *xml_plist_key = NULL; + libfplist_key_t *xml_plist_array_entry = NULL; + libfplist_key_t *xml_plist_key = NULL; static char *function = "libfvde_encryption_context_plist_get_kek_wrapped_volume_key"; if( plist == NULL ) @@ -1591,7 +1604,7 @@ int libfvde_encryption_context_plist_get_kek_wrapped_volume_key( return( -1 ); } - if( libfvde_xml_plist_key_is_array( + if( libfplist_key_is_array( internal_plist->wrapped_volume_keys_key, error ) != 1 ) { @@ -1604,7 +1617,7 @@ int libfvde_encryption_context_plist_get_kek_wrapped_volume_key( goto on_error; } - if( libfvde_xml_plist_key_get_array_entry_by_index( + if( libfplist_key_get_array_entry_by_index( internal_plist->wrapped_volume_keys_key, 1, &xml_plist_array_entry, @@ -1619,7 +1632,7 @@ int libfvde_encryption_context_plist_get_kek_wrapped_volume_key( goto on_error; } - if( libfvde_xml_plist_key_get_sub_key_by_utf8_name( + if( libfplist_key_get_sub_key_by_utf8_name( xml_plist_array_entry, (uint8_t *) "KEKWrappedVolumeKeyStruct", 25, @@ -1635,7 +1648,7 @@ int libfvde_encryption_context_plist_get_kek_wrapped_volume_key( goto on_error; } - if( libfvde_xml_plist_key_get_value_data( + if( libfplist_key_get_value_data( xml_plist_key, kek_wrapped_volume_key, kek_wrapped_volume_key_size, @@ -1662,7 +1675,7 @@ int libfvde_encryption_context_plist_get_kek_wrapped_volume_key( 0 ); } #endif - if( libfvde_xml_plist_key_free( + if( libfplist_key_free( &xml_plist_key, error ) != 1 ) { @@ -1675,7 +1688,7 @@ int libfvde_encryption_context_plist_get_kek_wrapped_volume_key( goto on_error; } - if( libfvde_xml_plist_key_free( + if( libfplist_key_free( &xml_plist_array_entry, error ) != 1 ) { @@ -1693,13 +1706,13 @@ int libfvde_encryption_context_plist_get_kek_wrapped_volume_key( on_error: if( xml_plist_key != NULL ) { - libfvde_xml_plist_key_free( + libfplist_key_free( &xml_plist_key, NULL ); } if( xml_plist_array_entry != NULL ) { - libfvde_xml_plist_key_free( + libfplist_key_free( &xml_plist_array_entry, NULL ); } diff --git a/libfvde/libfvde_encryption_context_plist.h b/libfvde/libfvde_encryption_context_plist.h index dc69a76..d0d1f37 100644 --- a/libfvde/libfvde_encryption_context_plist.h +++ b/libfvde/libfvde_encryption_context_plist.h @@ -30,9 +30,8 @@ #include "libfvde_extern.h" #include "libfvde_libbfio.h" #include "libfvde_libcerror.h" +#include "libfvde_libfplist.h" #include "libfvde_types.h" -#include "libfvde_xml_plist.h" -#include "libfvde_xml_plist_key.h" #if defined( __cplusplus ) extern "C" { @@ -56,15 +55,15 @@ struct libfvde_internal_encryption_context_plist /* The XML plist */ - libfvde_xml_plist_t *xml_plist; + libfplist_plist_t *xml_plist; /* The XML plist conversion info key */ - libfvde_xml_plist_key_t *conversion_info_key; + libfplist_key_t *conversion_info_key; /* The XML plist crypto users key */ - libfvde_xml_plist_key_t *crypto_users_key; + libfplist_key_t *crypto_users_key; /* The number of crypto users array entries */ @@ -72,7 +71,7 @@ struct libfvde_internal_encryption_context_plist /* The XML plist wrapped volume keys key */ - libfvde_xml_plist_key_t *wrapped_volume_keys_key; + libfplist_key_t *wrapped_volume_keys_key; }; LIBFVDE_EXTERN \ diff --git a/libfvde/libfvde_libfplist.h b/libfvde/libfvde_libfplist.h new file mode 100644 index 0000000..83f895a --- /dev/null +++ b/libfvde/libfvde_libfplist.h @@ -0,0 +1,51 @@ +/* + * The libfplist header wrapper + * + * Copyright (C) 2011-2016, Omar Choudary , + * Joachim Metz + * + * Refer to AUTHORS for acknowledgements. + * + * This software 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 software 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 software. If not, see . + */ + +#if !defined( _LIBFVDE_LIBFPLIST_H ) +#define _LIBFVDE_LIBFPLIST_H + +#include + +/* Define HAVE_LOCAL_LIBFPLIST for local use of libfplist + */ +#if defined( HAVE_LOCAL_LIBFPLIST ) + +#include +#include +#include +#include + +#else + +/* If libtool DLL support is enabled set LIBFPLIST_DLL_IMPORT + * before including libfplist.h + */ +#if defined( _WIN32 ) && defined( DLL_IMPORT ) +#define LIBFPLIST_DLL_IMPORT +#endif + +#include + +#endif /* defined( HAVE_LOCAL_LIBFPLIST ) */ + +#endif /* !defined( _LIBFVDE_LIBFPLIST_H ) */ + diff --git a/libfvde/libfvde_metadata.c b/libfvde/libfvde_metadata.c index 1fddd82..fee7391 100644 --- a/libfvde/libfvde_metadata.c +++ b/libfvde/libfvde_metadata.c @@ -30,10 +30,9 @@ #include "libfvde_libbfio.h" #include "libfvde_libcerror.h" #include "libfvde_libcnotify.h" +#include "libfvde_libfplist.h" #include "libfvde_metadata.h" #include "libfvde_metadata_block.h" -#include "libfvde_xml_plist.h" -#include "libfvde_xml_plist_key.h" #include "fvde_metadata.h" @@ -644,15 +643,15 @@ int libfvde_metadata_read_core_storage_plist( const uint8_t *xml_plist_data, libcerror_error_t **error ) { - libfvde_xml_plist_t *xml_plist = NULL; - libfvde_xml_plist_key_t *xml_plist_root_key = NULL; - libfvde_xml_plist_key_t *xml_plist_key = NULL; - static char *function = "libfvde_metadata_read_core_storage_plist"; - size_t xml_length = 0; + libfplist_plist_t *xml_plist = NULL; + libfplist_key_t *xml_plist_root_key = NULL; + libfplist_key_t *xml_plist_key = NULL; + static char *function = "libfvde_metadata_read_core_storage_plist"; + size_t xml_length = 0; #if defined( HAVE_DEBUG_OUTPUT ) - uint8_t *string = NULL; - size_t string_size = 0; + uint8_t *string = NULL; + size_t string_size = 0; #endif if( metadata == NULL ) @@ -709,7 +708,7 @@ int libfvde_metadata_read_core_storage_plist( goto on_error; } - if( libfvde_xml_plist_initialize( + if( libfplist_plist_initialize( &xml_plist, error ) != 1 ) { @@ -722,7 +721,7 @@ int libfvde_metadata_read_core_storage_plist( goto on_error; } - if( libfvde_xml_plist_copy_from_byte_stream( + if( libfplist_plist_copy_from_byte_stream( xml_plist, xml_plist_data, xml_length + 1, @@ -737,7 +736,7 @@ int libfvde_metadata_read_core_storage_plist( goto on_error; } - if( libfvde_xml_plist_get_root_key( + if( libfplist_plist_get_root_key( xml_plist, &xml_plist_root_key, error ) != 1 ) @@ -751,7 +750,7 @@ int libfvde_metadata_read_core_storage_plist( goto on_error; } - if( libfvde_xml_plist_key_get_sub_key_by_utf8_name( + if( libfplist_key_get_sub_key_by_utf8_name( xml_plist_root_key, (uint8_t *) "com.apple.corestorage.lvg.uuid", 30, @@ -770,7 +769,7 @@ int libfvde_metadata_read_core_storage_plist( #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { - if( libfvde_xml_plist_key_get_value_string( + if( libfplist_key_get_value_string( xml_plist_key, &string, &string_size, @@ -796,7 +795,7 @@ int libfvde_metadata_read_core_storage_plist( string = NULL; } #endif - if( libfvde_xml_plist_key_free( + if( libfplist_key_free( &xml_plist_key, error ) != 1 ) { @@ -809,7 +808,7 @@ int libfvde_metadata_read_core_storage_plist( goto on_error; } - if( libfvde_xml_plist_key_free( + if( libfplist_key_free( &xml_plist_root_key, error ) != 1 ) { @@ -822,7 +821,7 @@ int libfvde_metadata_read_core_storage_plist( goto on_error; } - if( libfvde_xml_plist_free( + if( libfplist_plist_free( &xml_plist, error ) != 1 ) { @@ -855,19 +854,19 @@ int libfvde_metadata_read_core_storage_plist( #endif if( xml_plist_key != NULL ) { - libfvde_xml_plist_key_free( + libfplist_key_free( &xml_plist_key, NULL ); } if( xml_plist_root_key != NULL ) { - libfvde_xml_plist_key_free( + libfplist_key_free( &xml_plist_root_key, NULL ); } if( xml_plist != NULL ) { - libfvde_xml_plist_free( + libfplist_plist_free( &xml_plist, NULL ); } diff --git a/libfvde/libfvde_xml_plist.c b/libfvde/libfvde_xml_plist.c deleted file mode 100644 index 3971c73..0000000 --- a/libfvde/libfvde_xml_plist.c +++ /dev/null @@ -1,506 +0,0 @@ -/* - * The XML plist functions - * - * Copyright (C) 2011-2016, Omar Choudary - * Joachim Metz - * - * Refer to AUTHORS for acknowledgements. - * - * This software 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 software 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 software. If not, see . - */ - -#include -#include -#include - -#include "libfvde_libcerror.h" -#include "libfvde_libcnotify.h" -#include "libfvde_xml_plist.h" -#include "libfvde_xml_plist_key.h" -#include "libfvde_xml_plist_parser.h" - -extern int xml_plist_parser_parse_buffer( - libfvde_xml_plist_t *xml_plist, - const uint8_t *buffer, - size_t buffer_size, - libcerror_error_t **error ); - -/* Creates an XML plist - * Make sure the value plist is referencing, is set to NULL - * Returns 1 if successful or -1 on error - */ -int libfvde_xml_plist_initialize( - libfvde_xml_plist_t **plist, - libcerror_error_t **error ) -{ - static char *function = "libfvde_xml_plist_initialize"; - - if( plist == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid plist.", - function ); - - return( -1 ); - } - if( *plist != NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, - "%s: invalid plist value already set.", - function ); - - return( -1 ); - } - *plist = memory_allocate_structure( - libfvde_xml_plist_t ); - - if( *plist == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_MEMORY, - LIBCERROR_MEMORY_ERROR_INSUFFICIENT, - "%s: unable to create plist.", - function ); - - goto on_error; - } - if( memory_set( - *plist, - 0, - sizeof( libfvde_xml_plist_t ) ) == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_MEMORY, - LIBCERROR_MEMORY_ERROR_SET_FAILED, - "%s: unable to clear plist.", - function ); - - goto on_error; - } - return( 1 ); - -on_error: - if( *plist != NULL ) - { - memory_free( - *plist ); - - *plist = NULL; - } - return( -1 ); -} - -/* Frees an XML plist - * Returns 1 if successful or -1 on error - */ -int libfvde_xml_plist_free( - libfvde_xml_plist_t **plist, - libcerror_error_t **error ) -{ - static char *function = "libfvde_xml_plist_free"; - int result = 1; - - if( plist == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid plist.", - function ); - - return( -1 ); - } - if( *plist != NULL ) - { - /* The root_tag and dict_tag are referenced and freed elsewhere */ - - if( libfvde_xml_plist_tag_free( - &( ( *plist )->root_tag ), - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, - "%s: unable to free XML plist root tag.", - function ); - - result = -1; - } - memory_free( - *plist ); - - *plist = NULL; - } - return( result ); -} - -/* Copies the XML plist from the byte stream - * Returns 1 if successful, 0 if not a valid plist or -1 on error - */ -int libfvde_xml_plist_copy_from_byte_stream( - libfvde_xml_plist_t *plist, - const uint8_t *byte_stream, - size_t byte_stream_size, - libcerror_error_t **error ) -{ - uint8_t *buffer = NULL; - static char *function = "libfvde_xml_plist_copy_from_byte_stream"; - size_t buffer_size = 0; - int result = 0; - - if( plist == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid plist.", - function ); - - return( -1 ); - } - if( plist->root_tag != NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, - "%s: invalid plist - XML plist root tag already set.", - function ); - - return( -1 ); - } - if( byte_stream == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid byte stream.", - function ); - - return( -1 ); - } - if( byte_stream_size > (size_t) INT_MAX ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, - "%s: invalid byte stream size value out of bounds.", - function ); - - return( -1 ); - } - /* Lex wants 2 zero bytes at the end of the buffer - */ - buffer_size = byte_stream_size + 1; - - buffer = (uint8_t *) memory_allocate( - sizeof( uint8_t ) * buffer_size ); - - if( buffer == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_MEMORY, - LIBCERROR_MEMORY_ERROR_INSUFFICIENT, - "%s: unable to create buffer.", - function ); - - goto on_error; - } - if( memory_copy( - buffer, - byte_stream, - byte_stream_size - 1 ) == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_MEMORY, - LIBCERROR_MEMORY_ERROR_COPY_FAILED, - "%s: unable to copy byte stream.", - function ); - - goto on_error; - } - /* Lex wants 2 zero bytes at the end of the buffer - */ - buffer[ buffer_size - 2 ] = 0; - buffer[ buffer_size - 1 ] = 0; - - result = xml_plist_parser_parse_buffer( - plist, - buffer, - buffer_size, - error ); - - if( result == -1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_IO, - LIBCERROR_IO_ERROR_READ_FAILED, - "%s: unable to parse XML plist.", - function ); - - goto on_error; - } - memory_free( - buffer ); - - buffer = NULL; - - return( 1 ); - -on_error: - if( buffer != NULL ) - { - memory_free( - buffer ); - } - return( -1 ); -} - -/* Retrieves the root key - * Returns 1 if successful, 0 if not available or -1 on error - */ -int libfvde_xml_plist_get_root_key( - libfvde_xml_plist_t *plist, - libfvde_xml_plist_key_t **key, - libcerror_error_t **error ) -{ - libfvde_xml_plist_tag_t *element_tag = NULL; - static char *function = "libfvde_xml_plist_get_root_key"; - int element_index = 0; - int number_of_elements = 0; - int result = 0; - - if( plist == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid plist.", - function ); - - return( -1 ); - } - if( plist->root_tag == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, - "%s: invalid plist - missing XML plist root tag.", - function ); - - return( -1 ); - } - if( key == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid key.", - function ); - - return( -1 ); - } - if( *key != NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, - "%s: invalid key value already set.", - function ); - - return( -1 ); - } - if( plist->root_tag == NULL ) - { - return( 0 ); - } - if( plist->dict_tag == NULL ) - { - result = libfvde_xml_plist_tag_compare_name( - plist->root_tag, - (uint8_t *) "dict", - 4, - error ); - - if( result == -1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to compare name of root tag.", - function ); - - return( -1 ); - } - else if( result != 0 ) - { - plist->dict_tag = plist->root_tag; - } - } - if( plist->dict_tag == NULL ) - { - /* Ignore the plist XML node - * - */ - result = libfvde_xml_plist_tag_compare_name( - plist->root_tag, - (uint8_t *) "plist", - 5, - error ); - - if( result == -1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to compare name of root tag.", - function ); - - return( -1 ); - } - else if( result != 0 ) - { - plist->plist_tag = plist->root_tag; - - if( libfvde_xml_plist_tag_get_number_of_elements( - plist->root_tag, - &number_of_elements, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve number of elements.", - function ); - - return( -1 ); - } - for( element_index = 0; - element_index < number_of_elements; - element_index++ ) - { - if( libfvde_xml_plist_tag_get_element( - plist->root_tag, - element_index, - &element_tag, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve element: %d.", - function, - element_index ); - - return( -1 ); - } - result = libfvde_xml_plist_tag_compare_name( - element_tag, - (uint8_t *) "text", - 4, - error ); - - if( result == -1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to compare name of element tag: %d.", - function, - element_index ); - - return( -1 ); - } - else if( result != 0 ) - { - /* Ignore text nodes - */ - continue; - } - result = libfvde_xml_plist_tag_compare_name( - element_tag, - (uint8_t *) "dict", - 4, - error ); - - if( result == -1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to compare name of element tag: %d.", - function, - element_index ); - - return( -1 ); - } - else if( result != 0 ) - { - plist->dict_tag = element_tag; - } - else - { - break; - } - } - } - } - if( plist->dict_tag == NULL ) - { - return( 0 ); - } - if( libfvde_xml_plist_key_initialize( - key, - NULL, - plist->dict_tag, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, - "%s: unable to create XML plist key.", - function ); - - return( -1 ); - } - return( 1 ); -} - diff --git a/libfvde/libfvde_xml_plist.h b/libfvde/libfvde_xml_plist.h deleted file mode 100644 index 4e3a038..0000000 --- a/libfvde/libfvde_xml_plist.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * XML plist functions - * - * Copyright (C) 2011-2016, Omar Choudary - * Joachim Metz - * - * Refer to AUTHORS for acknowledgements. - * - * This software 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 software 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 software. If not, see . - */ - -#if !defined( _LIBFVDE_XML_PLIST_H ) -#define _LIBFVDE_XML_PLIST_H - -#include -#include - -#include "libfvde_libcerror.h" -#include "libfvde_xml_plist_key.h" -#include "libfvde_xml_plist_tag.h" - -#if defined( __cplusplus ) -extern "C" { -#endif - -typedef struct libfvde_xml_plist libfvde_xml_plist_t; - -struct libfvde_xml_plist -{ - /* The XML plist tag - */ - libfvde_xml_plist_tag_t *plist_tag; - - /* The XML plist root tag - */ - libfvde_xml_plist_tag_t *root_tag; - - /* The XML plist (main) dict tag - */ - libfvde_xml_plist_tag_t *dict_tag; -}; - -int libfvde_xml_plist_initialize( - libfvde_xml_plist_t **plist, - libcerror_error_t **error ); - -int libfvde_xml_plist_free( - libfvde_xml_plist_t **plist, - libcerror_error_t **error ); - -int libfvde_xml_plist_copy_from_byte_stream( - libfvde_xml_plist_t *plist, - const uint8_t *byte_stream, - size_t byte_stream_size, - libcerror_error_t **error ); - -int libfvde_xml_plist_get_root_key( - libfvde_xml_plist_t *plist, - libfvde_xml_plist_key_t **key, - libcerror_error_t **error ); - -#if defined( __cplusplus ) -} -#endif - -#endif /* !defined( _LIBFVDE_XML_PLIST_H ) */ - diff --git a/libfvde/libfvde_xml_plist_attribute.c b/libfvde/libfvde_xml_plist_attribute.c deleted file mode 100644 index c9e9fd0..0000000 --- a/libfvde/libfvde_xml_plist_attribute.c +++ /dev/null @@ -1,269 +0,0 @@ -/* - * XML plist attribute functions - * - * Copyright (C) 2011-2016, Omar Choudary - * Joachim Metz - * - * Refer to AUTHORS for acknowledgements. - * - * This software 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 software 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 software. If not, see . - */ - -#include -#include -#include - -#include "libfvde_libcerror.h" -#include "libfvde_xml_plist_attribute.h" - -/* Creates a XML plist attribute - * Make sure the value attribute is referencing, is set to NULL - * Returns 1 if successful or -1 on error - */ -int libfvde_xml_plist_attribute_initialize( - libfvde_xml_plist_attribute_t **attribute, - const uint8_t *name, - size_t name_length, - const uint8_t *value, - size_t value_length, - libcerror_error_t **error ) -{ - static char *function = "libfvde_xml_plist_attribute_initialize"; - - if( attribute == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid XML plist attribute.", - function ); - - return( -1 ); - } - if( *attribute != NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, - "%s: invalid XML plist attribute value already set.", - function ); - - return( -1 ); - } - if( name == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid name.", - function ); - - return( -1 ); - } - if( name_length > (size_t) ( SSIZE_MAX - 1 ) ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, - "%s: invalid name length value exceeds maximum.", - function ); - - return( -1 ); - } - if( value == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid value.", - function ); - - return( -1 ); - } - if( value_length > (size_t) ( SSIZE_MAX - 1 ) ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, - "%s: invalid value length value exceeds maximum.", - function ); - - return( -1 ); - } - *attribute = memory_allocate_structure( - libfvde_xml_plist_attribute_t ); - - if( *attribute == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_MEMORY, - LIBCERROR_MEMORY_ERROR_INSUFFICIENT, - "%s: unable to create XML plist attribute.", - function ); - - goto on_error; - } - if( memory_set( - *attribute, - 0, - sizeof( libfvde_xml_plist_attribute_t ) ) == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_MEMORY, - LIBCERROR_MEMORY_ERROR_SET_FAILED, - "%s: unable to clear XML plist attribute.", - function ); - - memory_free( - *attribute ); - - *attribute = NULL; - - return( -1 ); - } - ( *attribute )->name_size = name_length + 1; - - ( *attribute )->name = (uint8_t *) memory_allocate( - sizeof( uint8_t ) * ( *attribute )->name_size ); - - if( ( *attribute )->name == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_MEMORY, - LIBCERROR_MEMORY_ERROR_INSUFFICIENT, - "%s: unable to create name.", - function ); - - goto on_error; - } - if( memory_copy( - ( *attribute )->name, - name, - name_length ) == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_MEMORY, - LIBCERROR_MEMORY_ERROR_COPY_FAILED, - "%s: unable to copy name.", - function ); - - goto on_error; - } - ( *attribute )->name[ name_length ] = 0; - - ( *attribute )->value_size = value_length + 1; - - ( *attribute )->value = (uint8_t *) memory_allocate( - sizeof( uint8_t ) * ( *attribute )->value_size ); - - if( ( *attribute )->value == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_MEMORY, - LIBCERROR_MEMORY_ERROR_INSUFFICIENT, - "%s: unable to create value.", - function ); - - goto on_error; - } - if( memory_copy( - ( *attribute )->value, - value, - value_length ) == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_MEMORY, - LIBCERROR_MEMORY_ERROR_COPY_FAILED, - "%s: unable to copy value.", - function ); - - goto on_error; - } - ( *attribute )->value[ value_length ] = 0; - - return( 1 ); - -on_error: - if( *attribute != NULL ) - { - if( ( *attribute )->value != NULL ) - { - memory_free( - ( *attribute )->value ); - } - if( ( *attribute )->name != NULL ) - { - memory_free( - ( *attribute )->name ); - } - memory_free( - *attribute ); - - *attribute = NULL; - } - return( -1 ); -} - -/* Frees a XML plist attribute - * Returns 1 if successful or -1 on error - */ -int libfvde_xml_plist_attribute_free( - libfvde_xml_plist_attribute_t **attribute, - libcerror_error_t **error ) -{ - static char *function = "libfvde_xml_plist_attribute_free"; - - if( attribute == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid XML plist attribute.", - function ); - - return( -1 ); - } - if( *attribute != NULL ) - { - if( ( *attribute )->value != NULL ) - { - memory_free( - ( *attribute )->value ); - } - if( ( *attribute )->name != NULL ) - { - memory_free( - ( *attribute )->name ); - } - memory_free( - *attribute ); - - *attribute = NULL; - } - return( 1 ); -} - diff --git a/libfvde/libfvde_xml_plist_attribute.h b/libfvde/libfvde_xml_plist_attribute.h deleted file mode 100644 index 0260db0..0000000 --- a/libfvde/libfvde_xml_plist_attribute.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * XML plist attribute functions - * - * Copyright (C) 2011-2016, Omar Choudary - * Joachim Metz - * - * Refer to AUTHORS for acknowledgements. - * - * This software 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 software 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 software. If not, see . - */ - -#if !defined( _LIBFVDE_XML_PLIST_ATTRIBUTE_H ) -#define _LIBFVDE_XML_PLIST_ATTRIBUTE_H - -#include -#include - -#include "libfvde_libcerror.h" - -#if defined( __cplusplus ) -extern "C" { -#endif - -typedef struct libfvde_xml_plist_attribute libfvde_xml_plist_attribute_t; - -struct libfvde_xml_plist_attribute -{ - /* The name - */ - uint8_t *name; - - /* The name size - */ - size_t name_size; - - /* The value (value) - */ - uint8_t *value; - - /* The value size - */ - size_t value_size; -}; - -int libfvde_xml_plist_attribute_initialize( - libfvde_xml_plist_attribute_t **attribute, - const uint8_t *name, - size_t name_length, - const uint8_t *value, - size_t value_length, - libcerror_error_t **error ); - -int libfvde_xml_plist_attribute_free( - libfvde_xml_plist_attribute_t **attribute, - libcerror_error_t **error ); - -#if defined( __cplusplus ) -} -#endif - -#endif /* !defined( _LIBFVDE_XML_PLIST_ATTRIBUTE_H ) */ - diff --git a/libfvde/libfvde_xml_plist_key.c b/libfvde/libfvde_xml_plist_key.c deleted file mode 100644 index 3a59e09..0000000 --- a/libfvde/libfvde_xml_plist_key.c +++ /dev/null @@ -1,1399 +0,0 @@ -/* - * The XML plist key functions - * - * Copyright (C) 2011-2016, Omar Choudary - * Joachim Metz - * - * Refer to AUTHORS for acknowledgements. - * - * This software 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 software 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 software. If not, see . - */ - -#include -#include -#include - -#include "libfvde_libcerror.h" -#include "libfvde_libcnotify.h" -#include "libfvde_libfguid.h" -#include "libfvde_libfvalue.h" -#include "libfvde_libuna.h" -#include "libfvde_xml_plist_key.h" -#include "libfvde_xml_plist_tag.h" - -/* Creates an XML plist key - * Make sure the value key is referencing, is set to NULL - * Returns 1 if successful or -1 on error - */ -int libfvde_xml_plist_key_initialize( - libfvde_xml_plist_key_t **key, - libfvde_xml_plist_tag_t *key_tag, - libfvde_xml_plist_tag_t *value_tag, - libcerror_error_t **error ) -{ - static char *function = "libfvde_xml_plist_key_initialize"; - int result = 0; - - if( key == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid key.", - function ); - - return( -1 ); - } - if( *key != NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, - "%s: invalid key value already set.", - function ); - - return( -1 ); - } - if( value_tag == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid XML plist value tag.", - function ); - - return( -1 ); - } - if( key_tag != NULL ) - { - result = libfvde_xml_plist_tag_compare_name( - key_tag, - (uint8_t *) "key", - 3, - error ); - - if( result == -1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to compare name of key tag.", - function ); - - return( -1 ); - } - else if( result == 0 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: unsupported key tag: %s.", - function, - key_tag->name ); - - return( -1 ); - } - } - *key = memory_allocate_structure( - libfvde_xml_plist_key_t ); - - if( *key == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_MEMORY, - LIBCERROR_MEMORY_ERROR_INSUFFICIENT, - "%s: unable to create key.", - function ); - - goto on_error; - } - if( memory_set( - *key, - 0, - sizeof( libfvde_xml_plist_key_t ) ) == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_MEMORY, - LIBCERROR_MEMORY_ERROR_SET_FAILED, - "%s: unable to clear key.", - function ); - - goto on_error; - } - ( *key )->key_tag = key_tag; - ( *key )->value_tag = value_tag; - - return( 1 ); - -on_error: - if( *key != NULL ) - { - memory_free( - *key ); - - *key = NULL; - } - return( -1 ); -} - -/* Frees an XML plist key - * Returns 1 if successful or -1 on error - */ -int libfvde_xml_plist_key_free( - libfvde_xml_plist_key_t **key, - libcerror_error_t **error ) -{ - static char *function = "libfvde_xml_plist_key_free"; - - if( key == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid key.", - function ); - - return( -1 ); - } - if( *key != NULL ) - { - /* The key_tag and value_tag are referenced and freed elsewhere */ - - memory_free( - *key ); - - *key = NULL; - } - return( 1 ); -} - -/* Determines if the value is an array - * Returns 1 if the value isan array, 0 if not or -1 on error - */ -int libfvde_xml_plist_key_is_array( - libfvde_xml_plist_key_t *key, - libcerror_error_t **error ) -{ - static char *function = "libfvde_xml_plist_key_is_array"; - int result = 0; - - if( key == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid key.", - function ); - - return( -1 ); - } - if( key->value_tag == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, - "%s: invalid key - missing value XML plist value tag.", - function ); - - return( -1 ); - } - result = libfvde_xml_plist_tag_compare_name( - key->value_tag, - (uint8_t *) "array", - 5, - error ); - - if( result == -1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to compare name of value tag.", - function ); - - return( -1 ); - } - return( result ); -} - -/* Determines if the value is a dict - * Returns 1 if the value is a dict, 0 if not or -1 on error - */ -int libfvde_xml_plist_key_is_dict( - libfvde_xml_plist_key_t *key, - libcerror_error_t **error ) -{ - static char *function = "libfvde_xml_plist_key_is_dict"; - int result = 0; - - if( key == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid key.", - function ); - - return( -1 ); - } - if( key->value_tag == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, - "%s: invalid key - missing value XML plist value tag.", - function ); - - return( -1 ); - } - result = libfvde_xml_plist_tag_compare_name( - key->value_tag, - (uint8_t *) "dict", - 4, - error ); - - if( result == -1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to compare name of value tag.", - function ); - - return( -1 ); - } - return( result ); -} - -/* Retrieves a data value - * Returns 1 if successful or -1 on error - */ -int libfvde_xml_plist_key_get_value_data( - libfvde_xml_plist_key_t *key, - uint8_t **data, - size_t *data_size, - libcerror_error_t **error ) -{ - static char *function = "libfvde_xml_plist_key_get_value_data"; - size_t value_index = 0; - size_t value_length = 0; - int result = 0; - - if( key == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid key.", - function ); - - return( -1 ); - } - if( key->value_tag == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, - "%s: invalid key - missing value XML plist value tag.", - 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 != NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, - "%s: invalid data value already set.", - function ); - - return( -1 ); - } - if( data_size == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid data size.", - function ); - - return( -1 ); - } - result = libfvde_xml_plist_tag_compare_name( - key->value_tag, - (uint8_t *) "data", - 4, - error ); - - if( result == -1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to compare name of value tag.", - function ); - - return( -1 ); - } - else if( result == 0 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: unsupported value tag: %s.", - function, - key->value_tag->name ); - - return( -1 ); - } - value_length = key->value_tag->value_size - 1; - - /* The base64 conversion function doesn't like an empty first line - */ - if( ( key->value_tag->value )[ 0 ] == '\n' ) - { - value_index += 1; - value_length -= 1; - } -#if defined( HAVE_DEBUG_OUTPUT ) - if( libcnotify_verbose != 0 ) - { - libcnotify_printf( - "%s: base64 encoded data:\n", - function ); - libcnotify_print_data( - (uint8_t *) &( ( key->value_tag->value )[ value_index ] ), - value_length, - 0 ); - } -#endif - if( libuna_base64_stream_size_to_byte_stream( - &( ( key->value_tag->value )[ value_index ] ), - value_length, - data_size, - LIBUNA_BASE64_VARIANT_ALPHABET_NORMAL | LIBUNA_BASE64_VARIANT_CHARACTER_LIMIT_NONE | LIBUNA_BASE64_VARIANT_PADDING_REQUIRED, - LIBUNA_BASE64_FLAG_STRIP_WHITESPACE, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_COPY_FAILED, - "%s: unable to determine size of base64 encoded data.", - function ); - - goto on_error; - } - *data = (uint8_t *) memory_allocate( - sizeof( uint8_t ) * *data_size ); - - if( *data == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_MEMORY, - LIBCERROR_MEMORY_ERROR_INSUFFICIENT, - "%s: unable to create data.", - function ); - - goto on_error; - } - if( libuna_base64_stream_copy_to_byte_stream( - &( ( key->value_tag->value )[ value_index ] ), - value_length, - *data, - *data_size, - LIBUNA_BASE64_VARIANT_ALPHABET_NORMAL | LIBUNA_BASE64_VARIANT_CHARACTER_LIMIT_NONE | LIBUNA_BASE64_VARIANT_PADDING_REQUIRED, - LIBUNA_BASE64_FLAG_STRIP_WHITESPACE, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_COPY_FAILED, - "%s: unable to copy base64 encoded data to byte stream.", - function ); - - goto on_error; - } - return( 1 ); - -on_error: - if( *data != NULL ) - { - memory_free( - *data ); - - *data = NULL; - } - *data_size = 0; - - return( -1 ); -} - -/* Retrieves an integer value - * Returns 1 if successful or -1 on error - */ -int libfvde_xml_plist_key_get_value_integer( - libfvde_xml_plist_key_t *key, - uint64_t *value_64bit, - libcerror_error_t **error ) -{ - static char *function = "libfvde_xml_plist_key_get_value_integer"; - int result = 0; - - if( key == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid key.", - function ); - - return( -1 ); - } - if( key->value_tag == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, - "%s: invalid key - missing value XML plist value tag.", - function ); - - return( -1 ); - } - result = libfvde_xml_plist_tag_compare_name( - key->value_tag, - (uint8_t *) "integer", - 7, - error ); - - if( result == -1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to compare name of value tag.", - function ); - - return( -1 ); - } - else if( result == 0 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: unsupported value tag: %s.", - function, - key->value_tag->name ); - - return( -1 ); - } -/* TODO add size support ? */ - if( libfvalue_utf8_string_copy_to_integer( - key->value_tag->value, - key->value_tag->value_size - 1, - (uint64_t *) value_64bit, - 64, - LIBFVALUE_INTEGER_FORMAT_TYPE_HEXADECIMAL | LIBFVALUE_INTEGER_FORMAT_FLAG_UNSIGNED, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_COPY_FAILED, - "%s: unable to convert value to integer.", - function ); - - return( -1 ); - } - return( 1 ); -} - -/* Retrieves a string value - * Returns 1 if successful or -1 on error - */ -int libfvde_xml_plist_key_get_value_string( - libfvde_xml_plist_key_t *key, - uint8_t **string, - size_t *string_size, - libcerror_error_t **error ) -{ - static char *function = "libfvde_xml_plist_key_get_value_string"; - int result = 0; - - if( key == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid key.", - function ); - - return( -1 ); - } - if( key->value_tag == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, - "%s: invalid key - missing value XML plist value tag.", - function ); - - return( -1 ); - } - if( string == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid string.", - function ); - - return( -1 ); - } - if( *string != NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, - "%s: invalid string value already set.", - function ); - - return( -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 ); - } - result = libfvde_xml_plist_tag_compare_name( - key->value_tag, - (uint8_t *) "string", - 6, - error ); - - if( result == -1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to compare name of value tag.", - function ); - - return( -1 ); - } - else if( result == 0 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: unsupported value tag: %s.", - function, - key->value_tag->name ); - - return( -1 ); - } - *string_size = key->value_tag->value_size; - - *string = memory_allocate( - sizeof( uint8_t ) * key->value_tag->value_size ); - - if( *string == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_MEMORY, - LIBCERROR_MEMORY_ERROR_INSUFFICIENT, - "%s: unable to create string.", - function ); - - goto on_error; - } - if( memory_copy( - *string, - key->value_tag->value, - key->value_tag->value_size ) == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_MEMORY, - LIBCERROR_MEMORY_ERROR_COPY_FAILED, - "%s: unable to copy string.", - function ); - - goto on_error; - } - return( 1 ); - -on_error: - if( *string != NULL ) - { - memory_free( - *string ); - - *string = NULL; - } - *string_size = 0; - - return( -1 ); -} - -/* Copies an UUID string value to a byte stream - * Returns 1 if successful or -1 on error - */ -int libfvde_xml_plist_key_value_uuid_string_copy_to_byte_stream( - libfvde_xml_plist_key_t *key, - uint8_t *byte_stream, - size_t byte_stream_size, - libcerror_error_t **error ) -{ - libfguid_identifier_t *guid = NULL; - uint8_t *string = NULL; - static char *function = "libfvde_xml_plist_key_value_uuid_string_copy_to_byte_stream"; - size_t string_size = 0; - int result = 0; - - if( libfvde_xml_plist_key_get_value_string( - key, - &string, - &string_size, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve logical volume family identifier.", - function ); - - goto on_error; - } - if( string_size == 0 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, - "%s: invalid string size value out of bounds.", - function ); - - return( -1 ); - } - if( libfguid_identifier_initialize( - &guid, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, - "%s: unable to create GUID.", - function ); - - goto on_error; - } - result = libfguid_identifier_copy_from_utf8_string( - guid, - (uint8_t *) string, - string_size - 1, - LIBFGUID_STRING_FORMAT_FLAG_USE_MIXED_CASE, - error ); - - if( result != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_SET_FAILED, - "%s: unable to copy GUID from string.", - function ); - - goto on_error; - } - memory_free( - string ); - - string = NULL; - - if( libfguid_identifier_copy_to_byte_stream( - guid, - byte_stream, - byte_stream_size, - LIBFGUID_ENDIAN_BIG, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_SET_FAILED, - "%s: unable to copy GUID to byte stream.", - function ); - - goto on_error; - } - if( libfguid_identifier_free( - &guid, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, - "%s: unable to free GUID.", - function ); - - goto on_error; - } - return( 1 ); - -on_error: -#if defined( HAVE_DEBUG_OUTPUT ) - if( string != NULL ) - { - memory_free( - string ); - } -#endif - if( guid != NULL ) - { - libfguid_identifier_free( - &guid, - NULL ); - } - return( -1 ); -} - -/* Retrieves the number of array entries - * Returns 1 if successful or -1 on error - */ -int libfvde_xml_plist_key_get_array_number_of_entries( - libfvde_xml_plist_key_t *key, - int *number_of_entries, - libcerror_error_t **error ) -{ - libfvde_xml_plist_tag_t *element_tag = NULL; - static char *function = "libfvde_xml_plist_key_get_array_number_of_entries"; - int element_index = 0; - int number_of_elements = 0; - int number_of_nodes = 0; - int result = 0; - - if( key == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid key.", - function ); - - return( -1 ); - } - if( key->value_tag == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, - "%s: invalid key - missing value XML plist value tag.", - function ); - - return( -1 ); - } - if( number_of_entries == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid number of entries.", - function ); - - return( -1 ); - } - result = libfvde_xml_plist_tag_compare_name( - key->value_tag, - (uint8_t *) "array", - 5, - error ); - - if( result == -1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to compare name of value tag.", - function ); - - return( -1 ); - } - else if( result == 0 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: unsupported value tag: %s.", - function, - key->value_tag->name ); - - return( -1 ); - } - if( libfvde_xml_plist_tag_get_number_of_elements( - key->value_tag, - &number_of_elements, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve number of elements.", - function ); - - return( -1 ); - } - for( element_index = 0; - element_index < number_of_elements; - element_index++ ) - { - if( libfvde_xml_plist_tag_get_element( - key->value_tag, - element_index, - &element_tag, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve element: %d.", - function, - element_index ); - - return( -1 ); - } - /* Ignore text nodes - */ - result = libfvde_xml_plist_tag_compare_name( - element_tag, - (uint8_t *) "text", - 4, - error ); - - if( result == -1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to compare name of value tag.", - function ); - - return( -1 ); - } - else if( result == 0 ) - { - number_of_nodes++; - } - } - *number_of_entries = number_of_nodes; - - return( 1 ); -} - -/* Retrieves a specific array entry - * Returns 1 if successful or -1 on error - */ -int libfvde_xml_plist_key_get_array_entry_by_index( - libfvde_xml_plist_key_t *key, - int array_entry_index, - libfvde_xml_plist_key_t **array_entry, - libcerror_error_t **error ) -{ - libfvde_xml_plist_tag_t *value_tag = NULL; - static char *function = "libfvde_xml_plist_key_get_array_entry_by_index"; - int entry_index = 0; - int element_index = 0; - int number_of_elements = 0; - int result = 0; - - if( key == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid key.", - function ); - - return( -1 ); - } - if( key->value_tag == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, - "%s: invalid key - missing value XML plist value tag.", - function ); - - return( -1 ); - } - if( array_entry_index < 0 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, - "%s: invalid array entry index value out of bounds.", - function ); - - return( -1 ); - } - if( array_entry == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid array entry.", - function ); - - return( -1 ); - } - if( *array_entry != NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, - "%s: invalid array entry value already set.", - function ); - - return( -1 ); - } - result = libfvde_xml_plist_tag_compare_name( - key->value_tag, - (uint8_t *) "array", - 5, - error ); - - if( result == -1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to compare name of value tag.", - function ); - - return( -1 ); - } - else if( result == 0 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: unsupported value tag: %s.", - function, - key->value_tag->name ); - - return( -1 ); - } - if( libfvde_xml_plist_tag_get_number_of_elements( - key->value_tag, - &number_of_elements, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve number of elements.", - function ); - - return( -1 ); - } - entry_index = array_entry_index; - - element_index = 0; - - while( element_index < number_of_elements ) - { - if( libfvde_xml_plist_tag_get_element( - key->value_tag, - element_index, - &value_tag, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve element: %d.", - function, - element_index ); - - return( -1 ); - } - /* Ignore text nodes - */ - result = libfvde_xml_plist_tag_compare_name( - value_tag, - (uint8_t *) "text", - 4, - error ); - - if( result == -1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to compare name of key tag.", - function ); - - return( -1 ); - } - else if( result == 0 ) - { - if( entry_index == 0 ) - { - break; - } - entry_index--; - } - element_index++; - } - if( element_index >= number_of_elements ) - { - return( 0 ); - } - if( libfvde_xml_plist_key_initialize( - array_entry, - NULL, - value_tag, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, - "%s: unable to create array entry: %d.", - function, - array_entry_index ); - - return( -1 ); - } - return( 1 ); -} - -/* Retrieves the sub key for the specific UTF-8 encoded name - * Returns 1 if successful, 0 if no such sub key or -1 on error - */ -int libfvde_xml_plist_key_get_sub_key_by_utf8_name( - libfvde_xml_plist_key_t *key, - const uint8_t *utf8_string, - size_t utf8_string_length, - libfvde_xml_plist_key_t **sub_key, - libcerror_error_t **error ) -{ - libfvde_xml_plist_tag_t *key_tag = NULL; - libfvde_xml_plist_tag_t *value_tag = NULL; - static char *function = "libfvde_xml_plist_key_get_sub_key_by_utf8_name"; - int element_index = 0; - int number_of_elements = 0; - int result = 0; - - if( key == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid key.", - function ); - - return( -1 ); - } - if( key->value_tag == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, - "%s: invalid key - missing value XML plist value tag.", - 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_length > (size_t) SSIZE_MAX ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, - "%s: invalid UTF-8 string length value exceeds maximum.", - function ); - - return( -1 ); - } - if( sub_key == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid sub key.", - function ); - - return( -1 ); - } - if( *sub_key != NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, - "%s: invalid sub key value already set.", - function ); - - return( -1 ); - } - result = libfvde_xml_plist_tag_compare_name( - key->value_tag, - (uint8_t *) "dict", - 4, - error ); - - if( result == -1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to compare name of value tag.", - function ); - - return( -1 ); - } - else if( result == 0 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: unsupported value tag: %s.", - function, - key->value_tag->name ); - - return( -1 ); - } - if( libfvde_xml_plist_tag_get_number_of_elements( - key->value_tag, - &number_of_elements, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve number of elements.", - function ); - - return( -1 ); - } - element_index = 0; - - while( element_index < number_of_elements ) - { - if( libfvde_xml_plist_tag_get_element( - key->value_tag, - element_index, - &key_tag, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve element: %d.", - function, - element_index ); - - return( -1 ); - } - result = libfvde_xml_plist_tag_compare_name( - key_tag, - (uint8_t *) "key", - 3, - error ); - - if( result == -1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to compare name of key tag.", - function ); - - return( -1 ); - } - else if( result != 0 ) - { - if( ( key_tag->value_size == ( utf8_string_length + 1 ) ) - && libcstring_narrow_string_compare( - key_tag->value, - utf8_string, - utf8_string_length ) == 0 ) - { - break; - } - } - element_index++; - } - if( element_index >= number_of_elements ) - { - return( 0 ); - } - element_index++; - - while( element_index < number_of_elements ) - { - if( libfvde_xml_plist_tag_get_element( - key->value_tag, - element_index, - &value_tag, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to retrieve element: %d.", - function, - element_index ); - - return( -1 ); - } - /* Ignore text nodes - */ - result = libfvde_xml_plist_tag_compare_name( - value_tag, - (uint8_t *) "text", - 4, - error ); - - if( result == -1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_GET_FAILED, - "%s: unable to compare name of value tag.", - function ); - - return( -1 ); - } - else if( result == 0 ) - { - break; - } - element_index++; - } - if( element_index >= number_of_elements ) - { - return( 0 ); - } - if( libfvde_xml_plist_key_initialize( - sub_key, - key_tag, - value_tag, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, - "%s: unable to create sub key.", - function ); - - return( -1 ); - } - return( 1 ); -} - diff --git a/libfvde/libfvde_xml_plist_key.h b/libfvde/libfvde_xml_plist_key.h deleted file mode 100644 index b05427a..0000000 --- a/libfvde/libfvde_xml_plist_key.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * XML plist key functions - * - * Copyright (C) 2011-2016, Omar Choudary - * Joachim Metz - * - * Refer to AUTHORS for acknowledgements. - * - * This software 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 software 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 software. If not, see . - */ - -#if !defined( _LIBFVDE_XML_PLIST_KEY_H ) -#define _LIBFVDE_XML_PLIST_KEY_H - -#include -#include - -#include "libfvde_libcerror.h" -#include "libfvde_xml_plist_tag.h" - -#if defined( __cplusplus ) -extern "C" { -#endif - -typedef struct libfvde_xml_plist_key libfvde_xml_plist_key_t; - -struct libfvde_xml_plist_key -{ - /* The XML plist key tag - */ - libfvde_xml_plist_tag_t *key_tag; - - /* The XML plist value tag - */ - libfvde_xml_plist_tag_t *value_tag; -}; - -int libfvde_xml_plist_key_initialize( - libfvde_xml_plist_key_t **key, - libfvde_xml_plist_tag_t *key_tag, - libfvde_xml_plist_tag_t *value_tag, - libcerror_error_t **error ); - -int libfvde_xml_plist_key_free( - libfvde_xml_plist_key_t **key, - libcerror_error_t **error ); - -int libfvde_xml_plist_key_is_array( - libfvde_xml_plist_key_t *key, - libcerror_error_t **error ); - -int libfvde_xml_plist_key_is_dict( - libfvde_xml_plist_key_t *key, - libcerror_error_t **error ); - -int libfvde_xml_plist_key_get_value_data( - libfvde_xml_plist_key_t *key, - uint8_t **data, - size_t *data_size, - libcerror_error_t **error ); - -int libfvde_xml_plist_key_get_value_integer( - libfvde_xml_plist_key_t *key, - uint64_t *value_64bit, - libcerror_error_t **error ); - -int libfvde_xml_plist_key_get_value_string( - libfvde_xml_plist_key_t *key, - uint8_t **string, - size_t *string_size, - libcerror_error_t **error ); - -int libfvde_xml_plist_key_value_uuid_string_copy_to_byte_stream( - libfvde_xml_plist_key_t *key, - uint8_t *byte_stream, - size_t byte_stream_size, - libcerror_error_t **error ); - -int libfvde_xml_plist_key_get_array_number_of_entries( - libfvde_xml_plist_key_t *key, - int *number_of_entries, - libcerror_error_t **error ); - -int libfvde_xml_plist_key_get_array_entry_by_index( - libfvde_xml_plist_key_t *key, - int array_entry_index, - libfvde_xml_plist_key_t **array_entry, - libcerror_error_t **error ); - -int libfvde_xml_plist_key_get_sub_key_by_utf8_name( - libfvde_xml_plist_key_t *key, - const uint8_t *utf8_string, - size_t utf8_string_length, - libfvde_xml_plist_key_t **sub_key, - libcerror_error_t **error ); - -#if defined( __cplusplus ) -} -#endif - -#endif /* !defined( _LIBFVDE_XML_PLIST_KEY_H ) */ - diff --git a/libfvde/libfvde_xml_plist_parser.y b/libfvde/libfvde_xml_plist_parser.y deleted file mode 100644 index 5d04e89..0000000 --- a/libfvde/libfvde_xml_plist_parser.y +++ /dev/null @@ -1,464 +0,0 @@ -%{ -/* - * XML plist scanner functions - * - * Copyright (C) 2011-2016, Omar Choudary - * Joachim Metz - * - * Refer to AUTHORS for acknowledgements. - * - * This software 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 software 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 software. If not, see . - */ - -#include -#include - -#if defined( HAVE_STDLIB_H ) || defined( WINAPI ) -#include -#endif - -#include "libfvde_libcerror.h" -#include "libfvde_libcnotify.h" -#include "libfvde_types.h" -#include "libfvde_xml_plist.h" -#include "libfvde_xml_plist_tag.h" - -#define YYMALLOC xml_plist_scanner_alloc -#define YYREALLOC xml_plist_scanner_realloc -#define YYFREE xml_plist_scanner_free - -#define YYLEX_PARAM NULL -#define YYPARSE_PARAM parser_state - -#if defined( HAVE_DEBUG_OUTPUT ) -#define xml_plist_parser_rule_print( string ) \ - if( libcnotify_verbose != 0 ) libcnotify_printf( "xml_plist_parser: rule: %s\n", string ) -#else -#define xml_plist_parser_rule_print( string ) -#endif - -%} - -/* %name-prefix="xml_plist_scanner_" replaced by -p xml_plist_scanner_ */ -/* %no-lines replaced by -l */ - -%lex-param { (void *) NULL } -%parse-param { void *parser_state } - -%start xml_plist_main - -%union -{ - /* The numeric value - */ - uint32_t numeric_value; - - /* The string value - */ - struct xml_plist_string_value - { - /* The string data - */ - const char *data; - - /* The string length - */ - size_t length; - - } string_value; -} - -%{ - -typedef struct xml_plist_parser_state xml_plist_parser_state_t; - -struct xml_plist_parser_state -{ - /* The XML plist - */ - libfvde_xml_plist_t *xml_plist; - - /* The error - */ - libcerror_error_t **error; - - /* The root tag - */ - libfvde_xml_plist_tag_t *root_tag; - - /* The current tag - */ - libfvde_xml_plist_tag_t *current_tag; - - /* The parent tag - */ - libfvde_xml_plist_tag_t *parent_tag; -}; - -typedef size_t yy_size_t; -typedef struct yy_buffer_state* YY_BUFFER_STATE; - -extern int xml_plist_scanner_suppress_error; - -extern int xml_plist_scanner_lex_destroy( - void ); - -extern void *xml_plist_scanner_alloc( - yy_size_t size ); - -extern void *xml_plist_scanner_realloc( - void *buffer, - yy_size_t size ); - -extern void *xml_plist_scanner_free( - void *buffer ); - -extern int xml_plist_scanner_lex( - void *user_data ); - -extern void xml_plist_scanner_error( - void *parser_state, - const char *error_string ); - -extern YY_BUFFER_STATE xml_plist_scanner__scan_buffer( - char *buffer, - yy_size_t buffer_size ); - -extern void xml_plist_scanner__delete_buffer( - YY_BUFFER_STATE buffer_state ); - -extern size_t xml_plist_scanner_buffer_offset; - -static char *xml_plist_parser_function = "xml_plist_parser"; - -int xml_plist_parser_parse_buffer( - libfvde_xml_plist_t *xml_plist, - const uint8_t *buffer, - size_t buffer_size, - libcerror_error_t **error ); - -%} - -/* Associativity rules - */ - -/* Token definitions - */ -%token XML_ATTRIBUTE_ASSIGN -%token XML_COMMENT -%token XML_DOCTYPE -%token XML_PROLOGUE -%token XML_TAG_END -%token XML_TAG_END_SINGLE - -%token XML_ATTRIBUTE_NAME -%token XML_ATTRIBUTE_VALUE -%token XML_TAG_CLOSE -%token XML_TAG_CONTENT -%token XML_TAG_OPEN_START - -%% - -/* Parser rules - */ - -xml_plist_main - : xml_prologue xml_doctype xml_tag_open xml_tags xml_tag_close - ; - -xml_prologue - : /* empty */ - | XML_PROLOGUE - ; - -xml_doctype - : /* empty */ - | XML_DOCTYPE - ; - -xml_tags - : /* empty */ - | xml_tag xml_tags - ; - -xml_tag - : xml_tag_open xml_tags xml_tag_close - | xml_tag_open xml_tag_content xml_tag_close - | xml_tag_single - ; - -xml_tag_open_start - : XML_TAG_OPEN_START - { - xml_plist_parser_rule_print( - "xml_tag_open_start" ); - - if( $1.data == NULL ) - { - libcerror_error_set( - ( (xml_plist_parser_state_t *) parser_state )->error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid tag name.", - xml_plist_parser_function ); - - YYABORT; - } - ( (xml_plist_parser_state_t *) parser_state )->current_tag = NULL; - - if( libfvde_xml_plist_tag_initialize( - &( ( (xml_plist_parser_state_t *) parser_state )->current_tag ), - (uint8_t *) $1.data, - $1.length, - ( (xml_plist_parser_state_t *) parser_state )->error ) != 1 ) - { - libcerror_error_set( - ( (xml_plist_parser_state_t *) parser_state )->error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, - "%s: unable to create XML plist tag.", - xml_plist_parser_function ); - - YYABORT; - } - if( ( (xml_plist_parser_state_t *) parser_state )->root_tag == NULL ) - { - ( (xml_plist_parser_state_t *) parser_state )->root_tag = ( (xml_plist_parser_state_t *) parser_state )->current_tag; - } - else - { - if( libfvde_xml_plist_tag_append_element( - ( (xml_plist_parser_state_t *) parser_state )->parent_tag, - ( (xml_plist_parser_state_t *) parser_state )->current_tag, - ( (xml_plist_parser_state_t *) parser_state )->error ) != 1 ) - { - libcerror_error_set( - ( (xml_plist_parser_state_t *) parser_state )->error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, - "%s: unable to append attribute.", - xml_plist_parser_function ); - - YYABORT; - } - } - ( (xml_plist_parser_state_t *) parser_state )->parent_tag = ( (xml_plist_parser_state_t *) parser_state )->current_tag; - } - ; - -xml_tag_open - : xml_tag_open_start xml_attributes XML_TAG_END - ; - -xml_tag_single - : xml_tag_open_start xml_attributes XML_TAG_END_SINGLE - { - xml_plist_parser_rule_print( - "xml_tag_single" ); - - if( ( (xml_plist_parser_state_t *) parser_state )->current_tag == NULL ) - { - libcerror_error_set( - ( (xml_plist_parser_state_t *) parser_state )->error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid current tag.", - xml_plist_parser_function ); - - YYABORT; - } - ( (xml_plist_parser_state_t *) parser_state )->parent_tag = ( (xml_plist_parser_state_t *) parser_state )->current_tag->parent_tag; - ( (xml_plist_parser_state_t *) parser_state )->current_tag = ( (xml_plist_parser_state_t *) parser_state )->parent_tag; - } - ; - -xml_tag_close - : XML_TAG_CLOSE - { - xml_plist_parser_rule_print( - "xml_tag_close" ); - - if( $1.data == NULL ) - { - libcerror_error_set( - ( (xml_plist_parser_state_t *) parser_state )->error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid tag name.", - xml_plist_parser_function ); - - YYABORT; - } - if( ( (xml_plist_parser_state_t *) parser_state )->current_tag == NULL ) - { - libcerror_error_set( - ( (xml_plist_parser_state_t *) parser_state )->error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid current tag.", - xml_plist_parser_function ); - - YYABORT; - } - if( ( ( (xml_plist_parser_state_t *) parser_state )->current_tag->name_size != ( $1.length + 1 ) ) - || ( libcstring_narrow_string_compare( - ( (xml_plist_parser_state_t *) parser_state )->current_tag->name, - $1.data, - $1.length ) != 0 ) ) - { - libcerror_error_set( - ( (xml_plist_parser_state_t *) parser_state )->error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: mismatch in tag name.", - xml_plist_parser_function ); - - YYABORT; - } - ( (xml_plist_parser_state_t *) parser_state )->parent_tag = ( (xml_plist_parser_state_t *) parser_state )->current_tag->parent_tag; - ( (xml_plist_parser_state_t *) parser_state )->current_tag = ( (xml_plist_parser_state_t *) parser_state )->parent_tag; - } - ; - -xml_tag_content - : XML_TAG_CONTENT - { - xml_plist_parser_rule_print( - "xml_tag_content" ); - - if( $1.data == NULL ) - { - libcerror_error_set( - ( (xml_plist_parser_state_t *) parser_state )->error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid attribute value.", - xml_plist_parser_function ); - - YYABORT; - } - if( libfvde_xml_plist_tag_set_value( - ( (xml_plist_parser_state_t *) parser_state )->current_tag, - (uint8_t *) $1.data, - $1.length, - ( (xml_plist_parser_state_t *) parser_state )->error ) != 1 ) - { - libcerror_error_set( - ( (xml_plist_parser_state_t *) parser_state )->error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_SET_FAILED, - "%s: unable to set value.", - xml_plist_parser_function ); - - YYABORT; - } - } - ; - -xml_attributes - : /* empty */ - | xml_attribute xml_attributes - ; - -xml_attribute - : XML_ATTRIBUTE_NAME XML_ATTRIBUTE_ASSIGN XML_ATTRIBUTE_VALUE - { - xml_plist_parser_rule_print( - "xml_attribute" ); - - if( $1.data == NULL ) - { - libcerror_error_set( - ( (xml_plist_parser_state_t *) parser_state )->error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid attribute name.", - xml_plist_parser_function ); - - YYABORT; - } - if( $3.data == NULL ) - { - libcerror_error_set( - ( (xml_plist_parser_state_t *) parser_state )->error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid attribute value.", - xml_plist_parser_function ); - - YYABORT; - } - if( libfvde_xml_plist_tag_append_attribute( - ( (xml_plist_parser_state_t *) parser_state )->current_tag, - (uint8_t *) $1.data, - $1.length, - (uint8_t *) $3.data, - $3.length, - ( (xml_plist_parser_state_t *) parser_state )->error ) != 1 ) - { - libcerror_error_set( - ( (xml_plist_parser_state_t *) parser_state )->error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, - "%s: unable to append attribute.", - xml_plist_parser_function ); - - YYABORT; - } - } - ; - -%% - -int xml_plist_parser_parse_buffer( - libfvde_xml_plist_t *xml_plist, - const uint8_t *buffer, - size_t buffer_size, - libcerror_error_t **error ) -{ - xml_plist_parser_state_t parser_state; - - YY_BUFFER_STATE buffer_state = NULL; - size_t buffer_offset = 0; - int result = -1; - - buffer_state = xml_plist_scanner__scan_buffer( - (char *) &( buffer[ buffer_offset ] ), - buffer_size - buffer_offset ); - - xml_plist_scanner_buffer_offset = (size_t) buffer_offset; - - if( buffer_state != NULL ) - { - parser_state.xml_plist = xml_plist; - parser_state.error = error; - parser_state.root_tag = NULL; - parser_state.current_tag = NULL; - parser_state.parent_tag = NULL; - - if( xml_plist_scanner_parse( - &parser_state ) == 0 ) - { - xml_plist->root_tag = parser_state.root_tag; - - result = 1; - } - xml_plist_scanner__delete_buffer( - buffer_state ); - } - xml_plist_scanner_lex_destroy(); - - return( result ); -} - diff --git a/libfvde/libfvde_xml_plist_scanner.l b/libfvde/libfvde_xml_plist_scanner.l deleted file mode 100644 index 614a09a..0000000 --- a/libfvde/libfvde_xml_plist_scanner.l +++ /dev/null @@ -1,236 +0,0 @@ -%option prefix="xml_plist_scanner_" outfile="lex.yy.c" -%option never-interactive 8bit -%option noinput nounput noyylineno nounistd -%option noyyalloc noyyrealloc noyyfree - -%{ -/* - * XML plist scanner functions - * - * Copyright (C) 2011-2016, Omar Choudary - * Joachim Metz - * - * Refer to AUTHORS for acknowledgements. - * - * This software 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 software 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 software. If not, see . - */ - -#include -#include -#include - -#include "libfvde_libcnotify.h" -#include "libfvde_xml_plist_parser.h" - -#define YYLEX_PARAM NULL - -int xml_plist_scanner_suppress_error = 1; -size_t xml_plist_scanner_buffer_offset = 0; -size_t xml_plist_scanner_index = 0; - -#define YY_USER_ACTION xml_plist_scanner_buffer_offset += (size_t) xml_plist_scanner_leng; - -#if defined( HAVE_DEBUG_OUTPUT ) -#define xml_plist_scanner_token_print( string ) \ - if( libcnotify_verbose != 0 ) libcnotify_printf( "xml_plist_scanner: offset: %" PRIzd " token: %s\n", xml_plist_scanner_buffer_offset, string ) -#else -#define xml_plist_scanner_token_print( string ) -#endif - -%} - -end_of_line [\r\n|\n|\r] - -name [A-Za-z\x80-\xff_][A-Za-z\x80-\xff_0-9.-]* -escaped_value &#([0-9]+|x[0-9a-fA-F]+); - -xml_tag_content [^<]+ -xml_attribute_value \"([^"&]|{escaped_value})*\"|\'([^'&]|{escaped_value})*\' - -white_space [\a\b\c\e\f\t\v ]+ - -%s XML_CONTENT -%s XML_TAG - -%% - -{white_space}*"<"{name} { - xml_plist_scanner_token_print( - "XML_TAG_OPEN_START" ); - - BEGIN( XML_TAG ); - - xml_plist_scanner_index = 0; - - while( xml_plist_scanner_index < xml_plist_scanner_leng ) - { - if( xml_plist_scanner_text[ xml_plist_scanner_index++ ] == '<' ) - { - break; - } - } - xml_plist_scanner_lval.string_value.data = &( xml_plist_scanner_text[ xml_plist_scanner_index ] ); - xml_plist_scanner_lval.string_value.length = (size_t) xml_plist_scanner_leng - xml_plist_scanner_index; - - return( XML_TAG_OPEN_START ); -} - -{name} { - xml_plist_scanner_token_print( - "XML_ATTRIBUTE_NAME" ); - - xml_plist_scanner_lval.string_value.data = xml_plist_scanner_text; - xml_plist_scanner_lval.string_value.length = (size_t) xml_plist_scanner_leng; - - return( XML_ATTRIBUTE_NAME ); -} - -"=" { - xml_plist_scanner_token_print( - "XML_ATTRIBUTE_ASSIGN" ); - - return( XML_ATTRIBUTE_ASSIGN ); -} - -{xml_attribute_value} { - xml_plist_scanner_token_print( - "XML_ATTRIBUTE_VALUE" ); - - xml_plist_scanner_lval.string_value.data = &( xml_plist_scanner_text[ 1 ] ); - xml_plist_scanner_lval.string_value.length = (size_t) xml_plist_scanner_leng - 2; - - return( XML_ATTRIBUTE_VALUE ); -} - -"/>"{end_of_line}? { - xml_plist_scanner_token_print( - "XML_TAG_END_SINGLE" ); - - BEGIN( INITIAL ); - - return( XML_TAG_END_SINGLE ); -} - -">"{end_of_line}? { - xml_plist_scanner_token_print( - "XML_TAG_END" ); - - BEGIN( XML_CONTENT ); - - return( XML_TAG_END ); -} - -{xml_tag_content} { - xml_plist_scanner_token_print( - "XML_TAG_CONTENT" ); - - BEGIN( INITIAL ); - - xml_plist_scanner_lval.string_value.data = xml_plist_scanner_text; - xml_plist_scanner_lval.string_value.length = (size_t) xml_plist_scanner_leng; - - return( XML_TAG_CONTENT ); -} - -""{end_of_line}? { - xml_plist_scanner_token_print( - "XML_TAG_CLOSE" ); - - xml_plist_scanner_index = xml_plist_scanner_leng--; - - while( xml_plist_scanner_index > 2 ) - { - if( xml_plist_scanner_text[ --xml_plist_scanner_index ] == '>' ) - { - break; - } - } - xml_plist_scanner_lval.string_value.data = &( xml_plist_scanner_text[ 2 ] ); - xml_plist_scanner_lval.string_value.length = (size_t) xml_plist_scanner_index - 2; - - return( XML_TAG_CLOSE ); -} - -"]*">"{end_of_line}? { - xml_plist_scanner_token_print( - "XML_PROLOGUE" ); - - return( XML_PROLOGUE ); -} - -""{end_of_line}? { - xml_plist_scanner_token_print( - "XML_COMMENT" ); - - return( XML_COMMENT ); -} - -"]*">"{end_of_line}? { - xml_plist_scanner_token_print( - "XML_DOCTYPE" ); - - return( XML_DOCTYPE ); -} - -{end_of_line} ; - -{white_space} ; - -%% - -void *xml_plist_scanner_alloc( - yy_size_t size ) -{ - return( memory_allocate( - size ) ); -} - -void *xml_plist_scanner_realloc( - void *buffer, - yy_size_t size ) -{ - return( memory_reallocate( - buffer, - size ) ); -} - -void xml_plist_scanner_free( - void *buffer ) -{ - memory_free( - buffer ); -} - -int xml_plist_scanner_wrap( - void ) -{ - return( 1 ); -} - -void xml_plist_scanner_error( - void *parser_state, - const char *error_string ) -{ - if( xml_plist_scanner_suppress_error == 0 ) - { - fprintf( - stderr, - "%s at token: %s (offset: %" PRIzd " size: %" PRIzd ")\n", - error_string, - xml_plist_scanner_text, - xml_plist_scanner_buffer_offset - (size_t) xml_plist_scanner_leng, - (size_t) xml_plist_scanner_leng ); - } -} - diff --git a/libfvde/libfvde_xml_plist_tag.c b/libfvde/libfvde_xml_plist_tag.c deleted file mode 100644 index 844f847..0000000 --- a/libfvde/libfvde_xml_plist_tag.c +++ /dev/null @@ -1,628 +0,0 @@ -/* - * XML plist tag functions - * - * Copyright (C) 2011-2016, Omar Choudary - * Joachim Metz - * - * Refer to AUTHORS for acknowledgements. - * - * This software 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 software 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 software. If not, see . - */ - -#include -#include -#include - -#include "libfvde_libcdata.h" -#include "libfvde_libcerror.h" -#include "libfvde_xml_plist_attribute.h" -#include "libfvde_xml_plist_tag.h" - -/* Creates a XML plist tag - * Make sure the value tag is referencing, is set to NULL - * Returns 1 if successful or -1 on error - */ -int libfvde_xml_plist_tag_initialize( - libfvde_xml_plist_tag_t **tag, - const uint8_t *name, - size_t name_length, - libcerror_error_t **error ) -{ - static char *function = "libfvde_xml_plist_tag_initialize"; - - if( tag == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid XML plist tag.", - function ); - - return( -1 ); - } - if( *tag != NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, - "%s: invalid XML plist tag value already set.", - function ); - - return( -1 ); - } - if( name == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid name.", - function ); - - return( -1 ); - } - if( name_length > (size_t) ( SSIZE_MAX - 1 ) ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, - "%s: invalid name length value exceeds maximum.", - function ); - - return( -1 ); - } - *tag = memory_allocate_structure( - libfvde_xml_plist_tag_t ); - - if( *tag == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_MEMORY, - LIBCERROR_MEMORY_ERROR_INSUFFICIENT, - "%s: unable to create XML plist tag.", - function ); - - goto on_error; - } - if( memory_set( - *tag, - 0, - sizeof( libfvde_xml_plist_tag_t ) ) == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_MEMORY, - LIBCERROR_MEMORY_ERROR_SET_FAILED, - "%s: unable to clear XML plist tag.", - function ); - - memory_free( - *tag ); - - *tag = NULL; - - return( -1 ); - } - ( *tag )->name_size = name_length + 1; - - ( *tag )->name = (uint8_t *) memory_allocate( - sizeof( uint8_t ) * ( *tag )->name_size ); - - if( ( *tag )->name == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_MEMORY, - LIBCERROR_MEMORY_ERROR_INSUFFICIENT, - "%s: unable to create name.", - function ); - - goto on_error; - } - if( memory_copy( - ( *tag )->name, - name, - name_length ) == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_MEMORY, - LIBCERROR_MEMORY_ERROR_COPY_FAILED, - "%s: unable to copy name.", - function ); - - goto on_error; - } - ( *tag )->name[ name_length ] = 0; - - if( libcdata_array_initialize( - &( ( *tag )->attributes_array ), - 0, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, - "%s: unable to create attributes array.", - function ); - - goto on_error; - } - if( libcdata_array_initialize( - &( ( *tag )->elements_array ), - 0, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, - "%s: unable to create elements array.", - function ); - - goto on_error; - } - return( 1 ); - -on_error: - if( *tag != NULL ) - { - if( ( *tag )->attributes_array != NULL ) - { - libcdata_array_free( - &( ( *tag )->attributes_array ), - NULL, - NULL ); - } - if( ( *tag )->name != NULL ) - { - memory_free( - ( *tag )->name ); - } - memory_free( - *tag ); - - *tag = NULL; - } - return( -1 ); -} - -/* Frees a XML plist tag - * Returns 1 if successful or -1 on error - */ -int libfvde_xml_plist_tag_free( - libfvde_xml_plist_tag_t **tag, - libcerror_error_t **error ) -{ - static char *function = "libfvde_xml_plist_tag_free"; - int result = 1; - - if( tag == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid XML plist tag.", - function ); - - return( -1 ); - } - if( *tag != NULL ) - { - /* The parent_tag is referenced and freed elsewhere */ - - if( libcdata_array_free( - &( ( *tag )->elements_array ), - (int (*)(intptr_t **, libcerror_error_t **)) &libfvde_xml_plist_tag_free, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, - "%s: unable to free elements array.", - function ); - - result = -1; - } - if( libcdata_array_free( - &( ( *tag )->attributes_array ), - (int (*)(intptr_t **, libcerror_error_t **)) &libfvde_xml_plist_attribute_free, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, - "%s: unable to free attributes array.", - function ); - - result = -1; - } - if( ( *tag )->value != NULL ) - { - memory_free( - ( *tag )->value ); - } - if( ( *tag )->name != NULL ) - { - memory_free( - ( *tag )->name ); - } - memory_free( - *tag ); - - *tag = NULL; - } - return( result ); -} - -/* Compares the name - * Returns 1 if equal, 0 if not or -1 on error - */ -int libfvde_xml_plist_tag_compare_name( - libfvde_xml_plist_tag_t *tag, - const uint8_t *name, - size_t name_length, - libcerror_error_t **error ) -{ - static char *function = "libfvde_xml_plist_tag_compare_name"; - - if( tag == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid XML plist tag.", - function ); - - return( -1 ); - } - if( name == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid name.", - function ); - - return( -1 ); - } - if( name_length > (size_t) ( SSIZE_MAX - 1 ) ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, - "%s: invalid name length value exceeds maximum.", - function ); - - return( -1 ); - } - if( ( tag->name_size != ( name_length + 1 ) ) - || ( libcstring_narrow_string_compare( - tag->name, - name, - name_length ) != 0 ) ) - { - return( 0 ); - } - return( 1 ); -} - -/* Sets the value - * Returns 1 if successful or -1 on error - */ -int libfvde_xml_plist_tag_set_value( - libfvde_xml_plist_tag_t *tag, - const uint8_t *value, - size_t value_length, - libcerror_error_t **error ) -{ - static char *function = "libfvde_xml_plist_tag_set_value"; - - if( tag == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid XML plist tag.", - function ); - - return( -1 ); - } - if( value == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid value.", - function ); - - return( -1 ); - } - if( value_length > (size_t) ( SSIZE_MAX - 1 ) ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, - "%s: invalid value length value exceeds maximum.", - function ); - - return( -1 ); - } - if( tag->value != NULL ) - { - memory_free( - tag->value ); - - tag->value = NULL; - } - tag->value_size = value_length + 1; - - tag->value = (uint8_t *) memory_allocate( - sizeof( uint8_t ) * tag->value_size ); - - if( tag->value == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_MEMORY, - LIBCERROR_MEMORY_ERROR_INSUFFICIENT, - "%s: unable to create value.", - function ); - - goto on_error; - } - if( memory_copy( - tag->value, - value, - value_length ) == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_MEMORY, - LIBCERROR_MEMORY_ERROR_COPY_FAILED, - "%s: unable to copy value.", - function ); - - goto on_error; - } - tag->value[ value_length ] = 0; - - return( 1 ); - -on_error: - if( tag->value != NULL ) - { - memory_free( - tag->value ); - - tag->value = NULL; - } - tag->value_size = 0; - - return( -1 ); -} - -/* Appends an attribute - * Returns 1 if successful or -1 on error - */ -int libfvde_xml_plist_tag_append_attribute( - libfvde_xml_plist_tag_t *tag, - const uint8_t *name, - size_t name_length, - const uint8_t *value, - size_t value_length, - libcerror_error_t **error ) -{ - libfvde_xml_plist_attribute_t *attribute = NULL; - static char *function = "libfvde_xml_plist_tag_append_attribute"; - int entry_index = 0; - - if( tag == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid XML plist tag.", - function ); - - return( -1 ); - } - if( libfvde_xml_plist_attribute_initialize( - &attribute, - name, - name_length, - value, - value_length, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, - "%s: unable to create attribute.", - function ); - - goto on_error; - } - if( libcdata_array_append_entry( - tag->attributes_array, - &entry_index, - (intptr_t *) attribute, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, - "%s: unable to append attribute to array.", - function ); - - goto on_error; - } - return( 1 ); - -on_error: - if( attribute != NULL ) - { - libfvde_xml_plist_attribute_free( - &attribute, - NULL ); - } - return( -1 ); -} - -int libfvde_xml_plist_tag_append_element( - libfvde_xml_plist_tag_t *tag, - libfvde_xml_plist_tag_t *element_tag, - libcerror_error_t **error ) -{ - static char *function = "libfvde_xml_plist_tag_append_element"; - int entry_index = 0; - - if( tag == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid XML plist tag.", - function ); - - return( -1 ); - } - if( element_tag == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid XML plist element tag.", - function ); - - return( -1 ); - } - if( libcdata_array_append_entry( - tag->elements_array, - &entry_index, - (intptr_t *) element_tag, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, - "%s: unable to append element tag to array.", - function ); - - return( -1 ); - } - element_tag->parent_tag = tag; - - return( 1 ); -} - -/* Retrieves the number of elements - * Returns 1 if successful or -1 on error - */ -int libfvde_xml_plist_tag_get_number_of_elements( - libfvde_xml_plist_tag_t *tag, - int *number_of_elements, - libcerror_error_t **error ) -{ - static char *function = "libfvde_xml_plist_tag_get_number_of_elements"; - - if( tag == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid XML plist tag.", - function ); - - return( -1 ); - } - if( libcdata_array_get_number_of_entries( - tag->elements_array, - number_of_elements, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, - "%s: unable to retrieve number of entries.", - function ); - - return( -1 ); - } - return( 1 ); -} - -/* Retrieves a specific element - * Returns 1 if successful or -1 on error - */ -int libfvde_xml_plist_tag_get_element( - libfvde_xml_plist_tag_t *tag, - int element_index, - libfvde_xml_plist_tag_t **element_tag, - libcerror_error_t **error ) -{ - static char *function = "libfvde_xml_plist_tag_get_element"; - - if( tag == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid XML plist tag.", - function ); - - return( -1 ); - } - if( libcdata_array_get_entry_by_index( - tag->elements_array, - element_index, - (intptr_t **) element_tag, - error ) != 1 ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, - "%s: unable to retrieve entry: %d.", - function, - element_index ); - - return( -1 ); - } - return( 1 ); -} - diff --git a/libfvde/libfvde_xml_plist_tag.h b/libfvde/libfvde_xml_plist_tag.h deleted file mode 100644 index b9fb673..0000000 --- a/libfvde/libfvde_xml_plist_tag.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * XML plist tag functions - * - * Copyright (C) 2011-2016, Omar Choudary - * Joachim Metz - * - * Refer to AUTHORS for acknowledgements. - * - * This software 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 software 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 software. If not, see . - */ - -#if !defined( _LIBFVDE_XML_PLIST_TAG_H ) -#define _LIBFVDE_XML_PLIST_TAG_H - -#include -#include - -#include "libfvde_libcdata.h" -#include "libfvde_libcerror.h" - -#if defined( __cplusplus ) -extern "C" { -#endif - -typedef struct libfvde_xml_plist_tag libfvde_xml_plist_tag_t; - -struct libfvde_xml_plist_tag -{ - /* The parent tag - */ - libfvde_xml_plist_tag_t *parent_tag; - - /* The name - */ - uint8_t *name; - - /* The name size - */ - size_t name_size; - - /* The value (value) - */ - uint8_t *value; - - /* The value size - */ - size_t value_size; - - /* The attributes array - */ - libcdata_array_t *attributes_array; - - /* The elements array - */ - libcdata_array_t *elements_array; -}; - -int libfvde_xml_plist_tag_initialize( - libfvde_xml_plist_tag_t **tag, - const uint8_t *name, - size_t name_length, - libcerror_error_t **error ); - -int libfvde_xml_plist_tag_free( - libfvde_xml_plist_tag_t **tag, - libcerror_error_t **error ); - -int libfvde_xml_plist_tag_compare_name( - libfvde_xml_plist_tag_t *tag, - const uint8_t *name, - size_t name_length, - libcerror_error_t **error ); - -int libfvde_xml_plist_tag_set_value( - libfvde_xml_plist_tag_t *tag, - const uint8_t *value, - size_t value_length, - libcerror_error_t **error ); - -int libfvde_xml_plist_tag_append_attribute( - libfvde_xml_plist_tag_t *tag, - const uint8_t *name, - size_t name_length, - const uint8_t *value, - size_t value_length, - libcerror_error_t **error ); - -int libfvde_xml_plist_tag_append_element( - libfvde_xml_plist_tag_t *tag, - libfvde_xml_plist_tag_t *element_tag, - libcerror_error_t **error ); - -int libfvde_xml_plist_tag_get_number_of_elements( - libfvde_xml_plist_tag_t *tag, - int *number_of_elements, - libcerror_error_t **error ); - -int libfvde_xml_plist_tag_get_element( - libfvde_xml_plist_tag_t *tag, - int element_index, - libfvde_xml_plist_tag_t **element_tag, - libcerror_error_t **error ); - -#if defined( __cplusplus ) -} -#endif - -#endif /* !defined( _LIBFVDE_XML_PLIST_TAG_H ) */ - diff --git a/m4/libfplist.m4 b/m4/libfplist.m4 new file mode 100644 index 0000000..5b80a7b --- /dev/null +++ b/m4/libfplist.m4 @@ -0,0 +1,176 @@ +dnl Functions for libfplist +dnl +dnl Version: 20161104 + +dnl Function to detect if libfplist is available +dnl ac_libfplist_dummy is used to prevent AC_CHECK_LIB adding unnecessary -l arguments +AC_DEFUN([AX_LIBFPLIST_CHECK_LIB], + [dnl Check if parameters were provided + AS_IF( + [test "x$ac_cv_with_libfplist" != x && test "x$ac_cv_with_libfplist" != xno && test "x$ac_cv_with_libfplist" != xauto-detect], + [AS_IF( + [test -d "$ac_cv_with_libfplist"], + [CFLAGS="$CFLAGS -I${ac_cv_with_libfplist}/include" + LDFLAGS="$LDFLAGS -L${ac_cv_with_libfplist}/lib"], + [AC_MSG_WARN([no such directory: $ac_cv_with_libfplist]) + ]) + ]) + + AS_IF( + [test "x$ac_cv_with_libfplist" = xno], + [ac_cv_libfplist=no], + [dnl Check for a pkg-config file + AS_IF( + [test "x$cross_compiling" != "xyes" && test "x$PKGCONFIG" != "x"], + [PKG_CHECK_MODULES( + [libfplist], + [libfplist >= 20161104], + [ac_cv_libfplist=yes], + [ac_cv_libfplist=no]) + ]) + + AS_IF( + [test "x$ac_cv_libfplist" = xyes], + [ac_cv_libfplist_CPPFLAGS="$pkg_cv_libfplist_CFLAGS" + ac_cv_libfplist_LIBADD="$pkg_cv_libfplist_LIBS"], + [dnl Check for headers + AC_CHECK_HEADERS([libfplist.h]) + + AS_IF( + [test "x$ac_cv_header_libfplist_h" = xno], + [ac_cv_libfplist=no], + [dnl Check for the individual functions + ac_cv_libfplist=yes + AC_CHECK_LIB( + fplist, + libfplist_get_version, + [ac_cv_libfplist_dummy=yes], + [ac_cv_libfplist=no]) + + dnl Plist functions + AC_CHECK_LIB( + fplist, + libfplist_plist_initialize, + [ac_cv_libfplist_dummy=yes], + [ac_cv_libfplist=no]) + AC_CHECK_LIB( + fplist, + libfplist_plist_free, + [ac_cv_libfplist_dummy=yes], + [ac_cv_libfplist=no]) + AC_CHECK_LIB( + fplist, + libfplist_plist_copy_from_byte_stream, + [ac_cv_libfplist_dummy=yes], + [ac_cv_libfplist=no]) + AC_CHECK_LIB( + fplist, + libfplist_plist_has_plist_root_element, + [ac_cv_libfplist_dummy=yes], + [ac_cv_libfplist=no]) + AC_CHECK_LIB( + fplist, + libfplist_plist_get_root_key, + [ac_cv_libfplist_dummy=yes], + [ac_cv_libfplist=no]) + + dnl Key functions + AC_CHECK_LIB( + fplist, + libfplist_key_free, + [ac_cv_libfplist_dummy=yes], + [ac_cv_libfplist=no]) + + ac_cv_libfplist_LIBADD="-lfplist" + ]) + ]) + ]) + + AS_IF( + [test "x$ac_cv_libfplist" = xyes], + [AC_DEFINE( + [HAVE_LIBFPLIST], + [1], + [Define to 1 if you have the `fplist' library (-lfplist).]) + ]) + + AS_IF( + [test "x$ac_cv_libfplist" = xyes], + [AC_SUBST( + [HAVE_LIBFPLIST], + [1]) ], + [AC_SUBST( + [HAVE_LIBFPLIST], + [0]) + ]) + ]) + +dnl Function to detect if libfplist dependencies are available +AC_DEFUN([AX_LIBFPLIST_CHECK_LOCAL], + [AM_PROG_LEX + AC_PROG_YACC + + ac_cv_libfplist_CPPFLAGS="-I../libfplist"; + ac_cv_libfplist_LIBADD="../libfplist/libfplist.la"; + + ac_cv_libfplist=local + ]) + +dnl Function to detect how to enable libfplist +AC_DEFUN([AX_LIBFPLIST_CHECK_ENABLE], + [AX_COMMON_ARG_WITH( + [libfplist], + [libfplist], + [search for libfplist in includedir and libdir or in the specified DIR, or no if to use local version], + [auto-detect], + [DIR]) + + AX_LIBFPLIST_CHECK_LIB + + AS_IF( + [test "x$ac_cv_libfplist" != xyes], + [AX_LIBFPLIST_CHECK_LOCAL + + AC_DEFINE( + [HAVE_LOCAL_LIBFPLIST], + [1], + [Define to 1 if the local version of libfplist is used.]) + AC_SUBST( + [HAVE_LOCAL_LIBFPLIST], + [1]) + ]) + + AM_CONDITIONAL( + [HAVE_LOCAL_LIBFPLIST], + [test "x$ac_cv_libfplist" = xlocal]) + AS_IF( + [test "x$ac_cv_libfplist_CPPFLAGS" != "x"], + [AC_SUBST( + [LIBFPLIST_CPPFLAGS], + [$ac_cv_libfplist_CPPFLAGS]) + ]) + AS_IF( + [test "x$ac_cv_libfplist_LIBADD" != "x"], + [AC_SUBST( + [LIBFPLIST_LIBADD], + [$ac_cv_libfplist_LIBADD]) + ]) + + AS_IF( + [test "x$ac_cv_libfplist" = xyes], + [AC_SUBST( + [ax_libfplist_pc_libs_private], + [-lfplist]) + ]) + + AS_IF( + [test "x$ac_cv_libfplist" = xyes], + [AC_SUBST( + [ax_libfplist_spec_requires], + [libfplist]) + AC_SUBST( + [ax_libfplist_spec_build_requires], + [libfplist-devel]) + ]) + ]) + diff --git a/msvscpp/Makefile.am b/msvscpp/Makefile.am index 4bad13e..b95bbfd 100644 --- a/msvscpp/Makefile.am +++ b/msvscpp/Makefile.am @@ -22,6 +22,7 @@ MSVSCPP_FILES = \ libfcache/libfcache.vcproj \ libfdata/libfdata.vcproj \ libfguid/libfguid.vcproj \ + libfplist/libfplist.vcproj \ libfvalue/libfvalue.vcproj \ libfvde/libfvde.vcproj \ libhmac/libhmac.vcproj \ diff --git a/msvscpp/libfplist/libfplist.vcproj b/msvscpp/libfplist/libfplist.vcproj new file mode 100644 index 0000000..44a534d --- /dev/null +++ b/msvscpp/libfplist/libfplist.vcproj @@ -0,0 +1,273 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/msvscpp/libfvde.sln b/msvscpp/libfvde.sln index 4abdda1..50f0ee6 100644 --- a/msvscpp/libfvde.sln +++ b/msvscpp/libfvde.sln @@ -67,6 +67,17 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcaes", "libcaes\libcaes. {BD3A95FA-A3DE-4B79-A889-A7E5ECA4B69C} = {BD3A95FA-A3DE-4B79-A889-A7E5ECA4B69C} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libfplist", "libfplist\libfplist.vcproj", "{062E5AF8-1380-4E56-B380-03408D236C80}" + ProjectSection(ProjectDependencies) = postProject + {20FFC4C9-F44C-45F6-A827-4819B4DF3C9F} = {20FFC4C9-F44C-45F6-A827-4819B4DF3C9F} + {BD3A95FA-A3DE-4B79-A889-A7E5ECA4B69C} = {BD3A95FA-A3DE-4B79-A889-A7E5ECA4B69C} + {B9332DC8-7594-47DF-80C1-38922E0F4DFB} = {B9332DC8-7594-47DF-80C1-38922E0F4DFB} + {5304AD69-D449-4589-B2C9-E4607E56A51D} = {5304AD69-D449-4589-B2C9-E4607E56A51D} + {BC27FF34-C859-4A1A-95D6-FC89952E1910} = {BC27FF34-C859-4A1A-95D6-FC89952E1910} + {8C13E498-6369-4792-A0CF-B7134C54561B} = {8C13E498-6369-4792-A0CF-B7134C54561B} + {5B2101CC-F4B7-49C3-99B7-32D5D3F3CC66} = {5B2101CC-F4B7-49C3-99B7-32D5D3F3CC66} + EndProjectSection +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcfile", "libcfile\libcfile.vcproj", "{4C93BDD3-1804-47F3-9B34-F2DE0CAE1AE0}" ProjectSection(ProjectDependencies) = postProject {20FFC4C9-F44C-45F6-A827-4819B4DF3C9F} = {20FFC4C9-F44C-45F6-A827-4819B4DF3C9F} @@ -218,6 +229,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libfvde", "libfvde\libfvde. {F94DCC2D-2B49-453E-89B3-FD81992677D0} = {F94DCC2D-2B49-453E-89B3-FD81992677D0} {8C13E498-6369-4792-A0CF-B7134C54561B} = {8C13E498-6369-4792-A0CF-B7134C54561B} {5B2101CC-F4B7-49C3-99B7-32D5D3F3CC66} = {5B2101CC-F4B7-49C3-99B7-32D5D3F3CC66} + {062E5AF8-1380-4E56-B380-03408D236C80} = {062E5AF8-1380-4E56-B380-03408D236C80} {296B7770-E247-4800-B938-AEC6CC82DE2F} = {296B7770-E247-4800-B938-AEC6CC82DE2F} {D6DC307C-0CA0-4144-BB19-9C43B476280F} = {D6DC307C-0CA0-4144-BB19-9C43B476280F} {E2E45353-D420-4921-A2CF-59D9047262F8} = {E2E45353-D420-4921-A2CF-59D9047262F8} @@ -292,6 +304,10 @@ Global {E2E45353-D420-4921-A2CF-59D9047262F8}.Release|Win32.Build.0 = Release|Win32 {E2E45353-D420-4921-A2CF-59D9047262F8}.VSDebug|Win32.ActiveCfg = VSDebug|Win32 {E2E45353-D420-4921-A2CF-59D9047262F8}.VSDebug|Win32.Build.0 = VSDebug|Win32 + {062E5AF8-1380-4E56-B380-03408D236C80}.Release|Win32.ActiveCfg = Release|Win32 + {062E5AF8-1380-4E56-B380-03408D236C80}.Release|Win32.Build.0 = Release|Win32 + {062E5AF8-1380-4E56-B380-03408D236C80}.VSDebug|Win32.ActiveCfg = VSDebug|Win32 + {062E5AF8-1380-4E56-B380-03408D236C80}.VSDebug|Win32.Build.0 = VSDebug|Win32 {4C93BDD3-1804-47F3-9B34-F2DE0CAE1AE0}.Release|Win32.ActiveCfg = Release|Win32 {4C93BDD3-1804-47F3-9B34-F2DE0CAE1AE0}.Release|Win32.Build.0 = Release|Win32 {4C93BDD3-1804-47F3-9B34-F2DE0CAE1AE0}.VSDebug|Win32.ActiveCfg = VSDebug|Win32 diff --git a/msvscpp/libfvde/libfvde.vcproj b/msvscpp/libfvde/libfvde.vcproj index 1aae867..3c7f4e7 100644 --- a/msvscpp/libfvde/libfvde.vcproj +++ b/msvscpp/libfvde/libfvde.vcproj @@ -39,8 +39,8 @@ /> - - - - - - - - - - - - + + @@ -449,26 +429,6 @@ RelativePath="..\..\libfvde\libfvde_volume_group.h" > - - - - - - - - - - + * + * Refer to AUTHORS for acknowledgements. + * + * This software 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 software 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 software. If not, see . + */ + +#include +#include +#include + +#if defined( HAVE_STDLIB_H ) || defined( WINAPI ) +#include +#endif + +#include "fvde_test_libcerror.h" +#include "fvde_test_libcstring.h" +#include "fvde_test_libfvde.h" +#include "fvde_test_macros.h" +#include "fvde_test_memory.h" +#include "fvde_test_unused.h" + +/* Tests the libfvde_encryption_context_plist_initialize function + * Returns 1 if successful or 0 if not + */ +int fvde_test_encryption_context_plist_initialize( + void ) +{ + libcerror_error_t *error = NULL; + libfvde_encryption_context_plist_t *encryption_context_plist = NULL; + int result = 0; + + /* Test libfvde_encryption_context_plist_initialize + */ + result = libfvde_encryption_context_plist_initialize( + &encryption_context_plist, + &error ); + + FVDE_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FVDE_TEST_ASSERT_IS_NOT_NULL( + "encryption_context_plist", + encryption_context_plist ); + + FVDE_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = libfvde_encryption_context_plist_free( + &encryption_context_plist, + &error ); + + FVDE_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FVDE_TEST_ASSERT_IS_NULL( + "encryption_context_plist", + encryption_context_plist ); + + FVDE_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test error cases + */ + result = libfvde_encryption_context_plist_initialize( + NULL, + &error ); + + FVDE_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FVDE_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + encryption_context_plist = (libfvde_encryption_context_plist_t *) 0x12345678UL; + + result = libfvde_encryption_context_plist_initialize( + &encryption_context_plist, + &error ); + + FVDE_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FVDE_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + encryption_context_plist = NULL; + +#if defined( HAVE_FVDE_TEST_MEMORY ) + + /* Test libfvde_encryption_context_plist_initialize with malloc failing + */ + fvde_test_malloc_attempts_before_fail = 0; + + result = libfvde_encryption_context_plist_initialize( + &encryption_context_plist, + &error ); + + if( fvde_test_malloc_attempts_before_fail != -1 ) + { + fvde_test_malloc_attempts_before_fail = -1; + + if( encryption_context_plist != NULL ) + { + libfvde_encryption_context_plist_free( + &encryption_context_plist, + NULL ); + } + } + else + { + FVDE_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FVDE_TEST_ASSERT_IS_NULL( + "encryption_context_plist", + encryption_context_plist ); + + FVDE_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + } + /* Test libfvde_encryption_context_plist_initialize with memset failing + */ + fvde_test_memset_attempts_before_fail = 0; + + result = libfvde_encryption_context_plist_initialize( + &encryption_context_plist, + &error ); + + if( fvde_test_memset_attempts_before_fail != -1 ) + { + fvde_test_memset_attempts_before_fail = -1; + + if( encryption_context_plist != NULL ) + { + libfvde_encryption_context_plist_free( + &encryption_context_plist, + NULL ); + } + } + else + { + FVDE_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FVDE_TEST_ASSERT_IS_NULL( + "encryption_context_plist", + encryption_context_plist ); + + FVDE_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + } +#endif /* defined( HAVE_FVDE_TEST_MEMORY ) */ + + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + if( encryption_context_plist != NULL ) + { + libfvde_encryption_context_plist_free( + &encryption_context_plist, + NULL ); + } + return( 0 ); +} + +/* Tests the libfvde_encryption_context_plist_free function + * Returns 1 if successful or 0 if not + */ +int fvde_test_encryption_context_plist_free( + void ) +{ + libcerror_error_t *error = NULL; + int result = 0; + + /* Test error cases + */ + result = libfvde_encryption_context_plist_free( + NULL, + &error ); + + FVDE_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FVDE_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + return( 0 ); +} + +/* The main program + */ +#if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) +int wmain( + int argc FVDE_TEST_ATTRIBUTE_UNUSED, + wchar_t * const argv[] FVDE_TEST_ATTRIBUTE_UNUSED ) +#else +int main( + int argc FVDE_TEST_ATTRIBUTE_UNUSED, + char * const argv[] FVDE_TEST_ATTRIBUTE_UNUSED ) +#endif +{ + FVDE_TEST_UNREFERENCED_PARAMETER( argc ) + FVDE_TEST_UNREFERENCED_PARAMETER( argv ) + + FVDE_TEST_RUN( + "libfvde_encryption_context_plist_initialize", + fvde_test_encryption_context_plist_initialize ); + + FVDE_TEST_RUN( + "libfvde_encryption_context_plist_free", + fvde_test_encryption_context_plist_free ); + + return( EXIT_SUCCESS ); + +on_error: + return( EXIT_FAILURE ); +} + diff --git a/tests/fvde_test_logical_volume.c b/tests/fvde_test_logical_volume.c new file mode 100644 index 0000000..210bd25 --- /dev/null +++ b/tests/fvde_test_logical_volume.c @@ -0,0 +1,57 @@ +/* + * Library logical_volume type testing program + * + * Copyright (C) 2011-2016, Joachim Metz + * + * Refer to AUTHORS for acknowledgements. + * + * This software 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 software 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 software. If not, see . + */ + +#include +#include +#include + +#if defined( HAVE_STDLIB_H ) || defined( WINAPI ) +#include +#endif + +#include "fvde_test_libcerror.h" +#include "fvde_test_libcstring.h" +#include "fvde_test_libfvde.h" +#include "fvde_test_macros.h" +#include "fvde_test_memory.h" +#include "fvde_test_unused.h" + +/* The main program + */ +#if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) +int wmain( + int argc FVDE_TEST_ATTRIBUTE_UNUSED, + wchar_t * const argv[] FVDE_TEST_ATTRIBUTE_UNUSED ) +#else +int main( + int argc FVDE_TEST_ATTRIBUTE_UNUSED, + char * const argv[] FVDE_TEST_ATTRIBUTE_UNUSED ) +#endif +{ + FVDE_TEST_UNREFERENCED_PARAMETER( argc ) + FVDE_TEST_UNREFERENCED_PARAMETER( argv ) + + return( EXIT_SUCCESS ); + +on_error: + return( EXIT_FAILURE ); +} + diff --git a/tests/fvde_test_support.c b/tests/fvde_test_support.c index 6714bd1..3917fdd 100644 --- a/tests/fvde_test_support.c +++ b/tests/fvde_test_support.c @@ -25,8 +25,8 @@ #include #endif -#include "fvde_test_libcstring.h" #include "fvde_test_libcerror.h" +#include "fvde_test_libcstring.h" #include "fvde_test_libfvde.h" #include "fvde_test_macros.h" #include "fvde_test_unused.h" diff --git a/tests/fvde_test_volume_group.c b/tests/fvde_test_volume_group.c new file mode 100644 index 0000000..ed88699 --- /dev/null +++ b/tests/fvde_test_volume_group.c @@ -0,0 +1,99 @@ +/* + * Library volume_group type testing program + * + * Copyright (C) 2011-2016, Joachim Metz + * + * Refer to AUTHORS for acknowledgements. + * + * This software 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 software 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 software. If not, see . + */ + +#include +#include +#include + +#if defined( HAVE_STDLIB_H ) || defined( WINAPI ) +#include +#endif + +#include "fvde_test_libcerror.h" +#include "fvde_test_libcstring.h" +#include "fvde_test_libfvde.h" +#include "fvde_test_macros.h" +#include "fvde_test_memory.h" +#include "fvde_test_unused.h" + +/* Tests the libfvde_volume_group_free function + * Returns 1 if successful or 0 if not + */ +int fvde_test_volume_group_free( + void ) +{ + libcerror_error_t *error = NULL; + int result = 0; + + /* Test error cases + */ + result = libfvde_volume_group_free( + NULL, + &error ); + + FVDE_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FVDE_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + return( 0 ); +} + +/* The main program + */ +#if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) +int wmain( + int argc FVDE_TEST_ATTRIBUTE_UNUSED, + wchar_t * const argv[] FVDE_TEST_ATTRIBUTE_UNUSED ) +#else +int main( + int argc FVDE_TEST_ATTRIBUTE_UNUSED, + char * const argv[] FVDE_TEST_ATTRIBUTE_UNUSED ) +#endif +{ + FVDE_TEST_UNREFERENCED_PARAMETER( argc ) + FVDE_TEST_UNREFERENCED_PARAMETER( argv ) + + FVDE_TEST_RUN( + "libfvde_volume_group_free", + fvde_test_volume_group_free ); + + return( EXIT_SUCCESS ); + +on_error: + return( EXIT_FAILURE ); +} + diff --git a/tests/test_api_types.ps1 b/tests/test_api_types.ps1 index 1d49062..fcdf239 100644 --- a/tests/test_api_types.ps1 +++ b/tests/test_api_types.ps1 @@ -10,7 +10,7 @@ $TestPrefix = Split-Path -path ${Pwd}.Path -parent $TestPrefix = Split-Path -path ${TestPrefix} -leaf $TestPrefix = ${TestPrefix}.Substring(3) -$TestTypes = "volume" -split " " +$TestTypes = "volume volume_group logical_volume encryption_context_plist" -split " " $TestToolDirectory = "..\vs2010\Release" diff --git a/tests/test_api_types.sh b/tests/test_api_types.sh index 0269793..ed7ce4d 100755 --- a/tests/test_api_types.sh +++ b/tests/test_api_types.sh @@ -12,7 +12,7 @@ TEST_PREFIX=`basename ${TEST_PREFIX} | sed 's/^lib\([^-]*\).*$/\1/'`; TEST_PROFILE="lib${TEST_PREFIX}"; TEST_TYPES=""; -TEST_TYPES_WITH_INPUT="volume"; +TEST_TYPES_WITH_INPUT="volume volume_group logical_volume encryption_context_plist"; OPTION_SETS=""; TEST_TOOL_DIRECTORY=".";