diff --git a/trunk/CMakeLists.txt b/trunk/CMakeLists.txt new file mode 100644 index 0000000..ad0dd6a --- /dev/null +++ b/trunk/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 2.8) +project(xmount) +set(CMAKE_C_FLAGS "-std=c99 -Wall") +add_subdirectory(libxmount_input) +#add_subdirectory(src) diff --git a/trunk/cmake_modules/FindLibAFF.cmake b/trunk/cmake_modules/FindLibAFF.cmake new file mode 100644 index 0000000..5418a9a --- /dev/null +++ b/trunk/cmake_modules/FindLibAFF.cmake @@ -0,0 +1,21 @@ +find_package(PkgConfig) +pkg_check_modules(PC_LIBAFF QUIET afflib) +set(LIBAFF_DEFINITIONS ${PC_LIBAFF_CFLAGS_OTHER}) + +find_path(LIBAFF_INCLUDE_DIR afflib/afflib.h + HINTS ${PC_LIBAFF_INCLUDEDIR} ${PC_LIBAFF_INCLUDE_DIRS} + PATH_SUFFIXES afflib) + +find_library(LIBAFF_LIBRARY NAMES afflib libafflib + HINTS ${PC_LIBAFF_LIBDIR} ${PC_LIBAFF_LIBRARY_DIRS} ) + +set(LIBAFF_LIBRARIES ${LIBAFF_LIBRARY}) +set(LIBAFF_INCLUDE_DIRS ${LIBAFF_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set LIBXML2_FOUND to TRUE +# if all listed variables are TRUE +find_package_handle_standard_args(LibAFF DEFAULT_MSG LIBAFF_LIBRARY LIBAFF_INCLUDE_DIR) + +mark_as_advanced(LIBAFF_INCLUDE_DIR LIBAFF_LIBRARY) + diff --git a/trunk/cmake_modules/FindLibEWF.cmake b/trunk/cmake_modules/FindLibEWF.cmake new file mode 100644 index 0000000..eddf49d --- /dev/null +++ b/trunk/cmake_modules/FindLibEWF.cmake @@ -0,0 +1,20 @@ +find_package(PkgConfig) +pkg_check_modules(PC_LIBEWF QUIET libewf) +set(LIBEWF_DEFINITIONS ${PC_LIBEWF_CFLAGS_OTHER}) + +find_path(LIBEWF_INCLUDE_DIR libewf.h + HINTS ${PC_LIBEWF_INCLUDEDIR} ${PC_LIBEWF_INCLUDE_DIRS} + PATH_SUFFIXES libewf ) + +find_library(LIBEWF_LIBRARY NAMES ewf libewf + HINTS ${PC_LIBEWF_LIBDIR} ${PC_LIBEWF_LIBRARY_DIRS} ) + +set(LIBEWF_LIBRARIES ${LIBEWF_LIBRARY}) +set(LIBEWF_INCLUDE_DIRS ${LIBEWF_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set LIBXML2_FOUND to TRUE +# if all listed variables are TRUE +find_package_handle_standard_args(LibEWF DEFAULT_MSG LIBEWF_LIBRARY LIBEWF_INCLUDE_DIR) + +mark_as_advanced(LIBEWF_INCLUDE_DIR LIBEWF_LIBRARY) diff --git a/trunk/libxmount_input/CMakeLists.txt b/trunk/libxmount_input/CMakeLists.txt new file mode 100644 index 0000000..3310462 --- /dev/null +++ b/trunk/libxmount_input/CMakeLists.txt @@ -0,0 +1,12 @@ +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules/") + +find_package(LibEWF) +if(LIBEWF_FOUND) + add_subdirectory(libxmount_input_ewf) +endif(LIBEWF_FOUND) + +find_package(LibAFF) +if(LIBAFF_FOUND) + add_subdirectory(libxmount_input_aff) +endif(LIBAFF_FOUND) + diff --git a/trunk/libxmount_input/libxmount_input.h b/trunk/libxmount_input/libxmount_input.h index cdb0f67..a6f5040 100644 --- a/trunk/libxmount_input/libxmount_input.h +++ b/trunk/libxmount_input/libxmount_input.h @@ -1,119 +1,127 @@ /******************************************************************************* * xmount Copyright (c) 2008-2014 by Gillen Daniel * * * * xmount is a small tool to "fuse mount" various image formats and enable * * virtual write access. * * * * This program is free software: you can redistribute it and/or modify it * * under the terms of the GNU General Public License as published by the Free * * Software Foundation, either version 3 of the License, or (at your option) * * any later version. * * * * This program is distributed in the hope that it will be useful, but WITHOUT * * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * * more details. * * * * You should have received a copy of the GNU General Public License along with * * this program. If not, see . * *******************************************************************************/ #ifndef LIBXMOUNT_INPUT_H #define LIBXMOUNT_INPUT_H #define LIBXMOUNT_INPUT_API_VERSION 1 +#include + //! Structure containing pointers to the lib's functions typedef struct s_LibXmountInputFunctions { /*! * Function to open input image * * \param pp_handle Pointer to store handle of opened image to * \param pp_filename_arr Array containing all specified input images * \param filename_arr_len Length of pp_filename_arr * \return 0 on success or error code */ int (*Open)(void **pp_handle, const char **pp_filename_arr, uint64_t filename_arr_len); /*! * Function to get the input image's size * * \param p_handle Handle to the opened image * \param p_size Pointer to store input image's size to * \return 0 on success or error code */ int (*Size)(void *p_handle, uint64_t *p_size); /*! * Function to read data from input image * * \param p_handle Handle to the opened image * \param offset Position at which to start reading * \param p_buf Buffer to store read data to * \param count Amount of bytes to read * \return 0 on success or error code */ int (*Read)(void *p_handle, uint64_t offset, unsigned char *p_buf, uint32_t count); /*! * Function to close an opened input image * * \param pp_handle Pointer to the handle of the opened image * \return 0 on success or error code */ int (*Close)(void **pp_handle); /*! * Function to return a string containing help messages for any supported * lib-specific options * * \param pp_help Pointer to a string to store null-terminated help text * \return 0 on success or error code */ int (*OptionsHelp)(const char **pp_help); /*! * Function to parse any lib-specific options * * \param p_handle Handle to the opened image * \param p_options String with specified options * \param pp_error Pointer to a string with error message * \return 0 on success or error code and error message */ int (*OptionsParse)(void *p_handle, char *p_options, char **pp_error); /*! * Function to get content to add to the info file * * \param p_handle Handle to the opened image * \param pp_info_buf Pointer to store the null-terminated content * \return 0 on success or error code */ int (*GetInfofileContent)(void *p_handle, const char **pp_info_buf); + /*! + * Function to free buffers that were allocated by lib + * + * \param p_buf Buffer to free + */ + void (*FreeBuffer)(void *p_buf); } ts_LibXmountInputFunctions, *pts_LibXmountInputFunctions; //! Get library API version /*! * \param p_ver Supported version */ void LibXmount_Input_GetApiVersion(uint8_t *p_ver); //! Get a list of supported formats /*! * Gets a list of supported input image formats. These are the strings * specified with xmount's --in command line option. * * \param ppp_arr Array containing supported format strings * \param p_arr_len Length of pp_arr */ void LibXmount_Input_GetSupportedFormats(char ***ppp_arr, uint8_t *p_arr_len); //! Get the lib's s_LibXmountInputFunctions structure /*! * \param pp_functions Functions */ -void LibXmount_Input_GetFunctions(tsLibXmountInputFunctions **pp_functions); +void LibXmount_Input_GetFunctions(ts_LibXmountInputFunctions **pp_functions); #endif // LIBXMOUNT_INPUT_H diff --git a/trunk/libxmount_input/libxmount_input_aff/CMakeLists.txt b/trunk/libxmount_input/libxmount_input_aff/CMakeLists.txt new file mode 100644 index 0000000..a9e9c4c --- /dev/null +++ b/trunk/libxmount_input/libxmount_input_aff/CMakeLists.txt @@ -0,0 +1,9 @@ +# TODO: https://www.mail-archive.com/cmake@cmake.org/msg32933.html + +cmake_minimum_required(VERSION 2.8) +project(libxmount_input_aff) +add_library(xmount_input_aff SHARED libxmount_input_aff.c) +install(TARGETS xmount_input_aff DESTINATION lib/xmount) +include_directories(${LIBAFF_INCLUDE_DIRS}) +set(LIBS ${LIBS} ${LIBAFF_LIBRARIES}) +target_link_libraries(xmount_input_aff ${LIBS}) diff --git a/trunk/libxmount_input/libxmount_input_aff/libxmount_input_aff.c b/trunk/libxmount_input/libxmount_input_aff/libxmount_input_aff.c new file mode 100644 index 0000000..9f5e128 --- /dev/null +++ b/trunk/libxmount_input/libxmount_input_aff/libxmount_input_aff.c @@ -0,0 +1,205 @@ +/******************************************************************************* +* xmount Copyright (c) 2008-2014 by Gillen Daniel * +* * +* xmount is a small tool to "fuse mount" various image formats and enable * +* virtual write access. * +* * +* This program is free software: you can redistribute it and/or modify it * +* under the terms of the GNU General Public License as published by the Free * +* Software Foundation, either version 3 of the License, or (at your option) * +* any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * +* more details. * +* * +* You should have received a copy of the GNU General Public License along with * +* this program. If not, see . * +*******************************************************************************/ + +#undef HAVE_LIBAFF_STATIC + +#include +#include + +#include "../libxmount_input.h" + +#ifndef HAVE_LIBAFF_STATIC + #include +#else + #include "libaff/lib/afflib.h" +#endif + +/******************************************************************************* + * Forward declarations + ******************************************************************************/ +int AffOpen(void **pp_handle, + const char **pp_filename_arr, + uint64_t filename_arr_len); +int AffSize(void *p_handle, + uint64_t *p_size); +int AffRead(void *p_handle, + uint64_t seek, + unsigned char *p_buf, + uint32_t count); +int AffClose(void **pp_handle); +int AffOptionsHelp(const char **pp_help); +int AffOptionsParse(void *p_handle, + char *p_options, + char **pp_error); +int AffGetInfofileContent(void *p_handle, + const char **pp_info_buf); +void AffFreeBuffer(void *p_buf); + +/******************************************************************************* + * LibXmount_Input API implementation + ******************************************************************************/ +/* + * LibXmount_Input_GetApiVersion + */ +void LibXmount_Input_GetApiVersion(uint8_t *p_ver) { + *p_ver=LIBXMOUNT_INPUT_API_VERSION; +} + +/* + * LibXmount_Input_GetSupportedFormats + */ +void LibXmount_Input_GetSupportedFormats(char ***ppp_arr, uint8_t *p_arr_len) { + // Alloc array containing 1 element with content "aff" + *ppp_arr=(char**)malloc(sizeof(char*)); + if(*ppp_arr==NULL) { + *p_arr_len=0; + return; + } + **ppp_arr=(char*)malloc(sizeof(char)*4); + if(**ppp_arr==NULL) { + free(*ppp_arr); + *ppp_arr=NULL; + *p_arr_len=0; + return; + } + strcpy(**ppp_arr,"aff"); + *p_arr_len=1; +} + +/* + * LibXmount_Input_GetFunctions + */ +void LibXmount_Input_GetFunctions(ts_LibXmountInputFunctions **pp_functions) { + *pp_functions= + (pts_LibXmountInputFunctions)malloc(sizeof(ts_LibXmountInputFunctions)); + if(*pp_functions==NULL) return; + + (*pp_functions)->Open=&AffOpen; + (*pp_functions)->Size=&AffSize; + (*pp_functions)->Read=&AffRead; + (*pp_functions)->Close=&AffClose; + (*pp_functions)->OptionsHelp=&AffOptionsHelp; + (*pp_functions)->OptionsParse=&AffOptionsParse; + (*pp_functions)->GetInfofileContent=&AffGetInfofileContent; + (*pp_functions)->FreeBuffer=&AffFreeBuffer; +} + +/******************************************************************************* + * Private + ******************************************************************************/ +/* + * AffOpen + */ +int AffOpen(void **pp_handle, + const char **pp_filename_arr, + uint64_t filename_arr_len) +{ + // We need at least one file + if(filename_arr_len==0) return 1; + + // Open AFF file + *pp_handle=(void*)af_open(pp_filename_arr[0],O_RDONLY,0); + if(!*pp_handle) { + // LOG_ERROR("Couldn't open AFF file!\n") + return 1; + } + + // Encrypted images aren't supported for now + if(af_cannot_decrypt((AFFILE*)*p_handle)) { + // LOG_ERROR("Encrypted AFF input images aren't supported yet!\n") + return 1; + } + + return 0; +} + +/* + * AffSize + */ +int AffSize(void *p_handle, uint64_t *p_size) { + *p_size=af_seek((AFFILE*)p_handle,0,SEEK_END); + // TODO: Check for error + return 0; +} + +/* + * AffRead + */ +int AffRead(void *p_handle, + uint64_t offset, + unsigned char *p_buf, + uint32_t count) +{ + af_seek((AFFILE*)p_handle,offset,SEEK_SET); + // TODO: Check for error + if(af_read((AFFILE*)p_handle,p_buf,count)!=count) { + // LOG_ERROR("Couldn't read %zd bytes from offset %" PRIu64 + // "!\n",ToRead,offset); + return 1; + } + return 0; +} + +/* + * AffClose + */ +int AffClose(void **pp_handle) { + af_close((AFFILE*)*p_handle); + // TODO: Check for error + return 0; +} + +/* + * AffOptionsHelp + */ +int AffOptionsHelp(const char **pp_help) { + *pp_help=NULL; + return 0; +} + +/* + * AffOptionsParse + */ +int AffOptionsParse(void *p_handle, char *p_options, char **pp_error) { + return 0; +} + +/* + * AffGetInfofileContent + */ +int AffGetInfofileContent(void *p_handle, const char **pp_info_buf) { + // TODO + *pp_info_buf=NULL; + return 0; +} + +/* + * AffFreeBuffer + */ +void AffFreeBuffer(void *p_buf) { + free(p_buf); +} + +/* + ----- Change history ----- + 20140724: * Initial version implementing AffOpen, AffSize, AffRead, AffClose, + AffOptionsHelp, AffOptionsParse and AffFreeBuffer +*/ + diff --git a/trunk/libxmount_input/libxmount_input_ewf/CMakeLists.txt b/trunk/libxmount_input/libxmount_input_ewf/CMakeLists.txt new file mode 100644 index 0000000..f9f35e5 --- /dev/null +++ b/trunk/libxmount_input/libxmount_input_ewf/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 2.8) +project(libxmount_input_ewf) +add_library(xmount_input_ewf SHARED libxmount_input_ewf.c) +install(TARGETS xmount_input_ewf DESTINATION lib/xmount) +include_directories(${LIBEWF_INCLUDE_DIRS}) +set(LIBS ${LIBS} ${LIBEWF_LIBRARIES}) +target_link_libraries(xmount_input_ewf ${LIBS}) diff --git a/trunk/libxmount_input/libxmount_input_ewf/libxmount_input_ewf.c b/trunk/libxmount_input/libxmount_input_ewf/libxmount_input_ewf.c index 5c277b1..d01c5f0 100644 --- a/trunk/libxmount_input/libxmount_input_ewf/libxmount_input_ewf.c +++ b/trunk/libxmount_input/libxmount_input_ewf/libxmount_input_ewf.c @@ -1,280 +1,297 @@ /******************************************************************************* * xmount Copyright (c) 2008-2014 by Gillen Daniel * * * * xmount is a small tool to "fuse mount" various image formats and enable * * virtual write access. * * * * This program is free software: you can redistribute it and/or modify it * * under the terms of the GNU General Public License as published by the Free * * Software Foundation, either version 3 of the License, or (at your option) * * any later version. * * * * This program is distributed in the hope that it will be useful, but WITHOUT * * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * * more details. * * * * You should have received a copy of the GNU General Public License along with * * this program. If not, see . * *******************************************************************************/ #undef HAVE_LIBEWF_STATIC -#include "config.h" - #include #include -#ifdef HAVE_LIBEWF +#include "../libxmount_input.h" + +#ifndef HAVE_LIBEWF_STATIC #include -#endif -#ifdef HAVE_LIBEWF_STATIC +#else #include "libewf/include/libewf.h" #endif -#include "../libxmount_input.h" - /******************************************************************************* * Forward declarations ******************************************************************************/ int EwfOpen(void **pp_handle, const char **pp_filename_arr, uint64_t filename_arr_len); int EwfSize(void *p_handle, uint64_t *p_size); int EwfRead(void *p_handle, uint64_t seek, unsigned char *p_buf, uint32_t count); int EwfClose(void **pp_handle); int EwfOptionsHelp(const char **pp_help); int EwfOptionsParse(void *p_handle, char *p_options, char **pp_error); int EwfGetInfofileContent(void *p_handle, const char **pp_info_buf); +void EwfFreeBuffer(void *p_buf); /******************************************************************************* * LibXmount_Input API implementation ******************************************************************************/ +/* + * LibXmount_Input_GetApiVersion + */ void LibXmount_Input_GetApiVersion(uint8_t *p_ver) { *p_ver=LIBXMOUNT_INPUT_API_VERSION; } +/* + * LibXmount_Input_GetSupportedFormats + */ void LibXmount_Input_GetSupportedFormats(char ***ppp_arr, uint8_t *p_arr_len) { - *ppp_arr=(char*)malloc(sizeof(char*)); + // Alloc array containing 1 element with content "ewf" + *ppp_arr=(char**)malloc(sizeof(char*)); if(*ppp_arr==NULL) { *p_arr_len=0; return; } - **ppp_arr=(char*)malloc(sizeof(char)*4); if(**ppp_arr==NULL) { free(*ppp_arr); *ppp_arr=NULL; *p_arr_len=0; return; } - strcpy(**ppp_arr,"ewf"); *p_arr_len=1; } -void LibXmount_Input_GetFunctions(tsLibXmountInputFunctions **pp_functions) { +/* + * LibXmount_Input_GetFunctions + */ +void LibXmount_Input_GetFunctions(ts_LibXmountInputFunctions **pp_functions) { *pp_functions= - (ptsLibXmountInputFunctions)malloc(sizeof(tsLibXmountInputFunctions)); + (pts_LibXmountInputFunctions)malloc(sizeof(ts_LibXmountInputFunctions)); if(*pp_functions==NULL) return; (*pp_functions)->Open=&EwfOpen; (*pp_functions)->Size=&EwfSize; (*pp_functions)->Read=&EwfRead; (*pp_functions)->Close=&EwfClose; (*pp_functions)->OptionsHelp=&EwfOptionsHelp; (*pp_functions)->OptionsParse=&EwfOptionsParse; (*pp_functions)->GetInfofileContent=&EwfGetInfofileContent; + (*pp_functions)->FreeBuffer=&EwfFreeBuffer; } /******************************************************************************* * Private ******************************************************************************/ +/* + * EwfOpen + */ int EwfOpen(void **pp_handle, const char **pp_filename_arr, uint64_t filename_arr_len) { -#if defined( HAVE_LIBEWF_V2_API ) - static libewf_handle_t *hEwfFile=NULL; -#else - static LIBEWF_HANDLE *hEwfFile=NULL; -#endif + // We need at least one file + if(filename_arr_len==0) return 1; + // Make sure all files are EWF files + for(uint64_t i=0;i