General refactor and cleanup.

This commit is contained in:
2024-04-30 15:51:32 +01:00
parent 80d5a532de
commit 1f813feec9
56 changed files with 2858 additions and 3104 deletions

50
3rdparty/flac.cmake vendored
View File

@@ -42,20 +42,20 @@ include(TestBigEndian)
check_include_file("byteswap.h" HAVE_BYTESWAP_H) check_include_file("byteswap.h" HAVE_BYTESWAP_H)
check_include_file("inttypes.h" HAVE_INTTYPES_H) check_include_file("inttypes.h" HAVE_INTTYPES_H)
check_include_file("stdint.h" HAVE_STDINT_H) check_include_file("stdint.h" HAVE_STDINT_H)
if(MSVC) if (MSVC)
check_include_file("intrin.h" FLAC__HAS_X86INTRIN) check_include_file("intrin.h" FLAC__HAS_X86INTRIN)
else() else ()
check_include_file("x86intrin.h" FLAC__HAS_X86INTRIN) check_include_file("x86intrin.h" FLAC__HAS_X86INTRIN)
endif() endif ()
#check_function_exists(fseeko HAVE_FSEEKO) #check_function_exists(fseeko HAVE_FSEEKO)
check_c_source_compiles("int main() { return __builtin_bswap16 (0) ; }" HAVE_BSWAP16) check_c_source_compiles("int main() { return __builtin_bswap16 (0) ; }" HAVE_BSWAP16)
check_c_source_compiles("int main() { return __builtin_bswap32 (0) ; }" HAVE_BSWAP32) check_c_source_compiles("int main() { return __builtin_bswap32 (0) ; }" HAVE_BSWAP32)
if(NOT "${CMAKE_C_PLATFORM_ID}" MATCHES "MinGW" OR (NOT ${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm" AND NOT ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")) if (NOT "${CMAKE_C_PLATFORM_ID}" MATCHES "MinGW" OR (NOT ${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm" AND NOT ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64"))
test_big_endian(CPU_IS_BIG_ENDIAN) test_big_endian(CPU_IS_BIG_ENDIAN)
endif() endif ()
check_c_compiler_flag(-mstackrealign HAVE_STACKREALIGN_FLAG) check_c_compiler_flag(-mstackrealign HAVE_STACKREALIGN_FLAG)
@@ -64,11 +64,11 @@ include_directories("3rdparty/flac/include")
include_directories("${CMAKE_CURRENT_BINARY_DIR}/3rdparty/flac") include_directories("${CMAKE_CURRENT_BINARY_DIR}/3rdparty/flac")
add_definitions(-DHAVE_CONFIG_H) add_definitions(-DHAVE_CONFIG_H)
if(MSVC) if (MSVC)
add_definitions( add_definitions(
-D_CRT_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS
-D_USE_MATH_DEFINES) -D_USE_MATH_DEFINES)
endif() endif ()
option(WITH_ASM "Use any assembly optimization routines" ON) option(WITH_ASM "Use any assembly optimization routines" ON)
@@ -82,39 +82,39 @@ include(CheckCSourceCompiles)
include(CheckCPUArch) include(CheckCPUArch)
check_cpu_arch_x64(FLAC__CPU_X86_64) check_cpu_arch_x64(FLAC__CPU_X86_64)
if(NOT FLAC__CPU_X86_64) if (NOT FLAC__CPU_X86_64)
check_cpu_arch_x86(FLAC__CPU_IA32) check_cpu_arch_x86(FLAC__CPU_IA32)
endif() endif ()
if(FLAC__CPU_X86_64 OR FLAC__CPU_IA32) if (FLAC__CPU_X86_64 OR FLAC__CPU_IA32)
set(FLAC__ALIGN_MALLOC_DATA 1) set(FLAC__ALIGN_MALLOC_DATA 1)
option(WITH_AVX "Enable AVX, AVX2 optimizations" ON) option(WITH_AVX "Enable AVX, AVX2 optimizations" ON)
endif() endif ()
include(CheckLanguage) include(CheckLanguage)
check_language(ASM_NASM) check_language(ASM_NASM)
if(CMAKE_ASM_NASM_COMPILER) if (CMAKE_ASM_NASM_COMPILER)
enable_language(ASM_NASM) enable_language(ASM_NASM)
add_definitions(-DFLAC__HAS_NASM) add_definitions(-DFLAC__HAS_NASM)
endif() endif ()
if(NOT WITH_ASM) if (NOT WITH_ASM)
add_definitions(-DFLAC__NO_ASM) add_definitions(-DFLAC__NO_ASM)
endif() endif ()
if(FLAC__CPU_IA32) if (FLAC__CPU_IA32)
if(WITH_ASM AND CMAKE_ASM_NASM_COMPILER) if (WITH_ASM AND CMAKE_ASM_NASM_COMPILER)
add_subdirectory(ia32) add_subdirectory(ia32)
endif() endif ()
option(WITH_SSE "Enable SSE2 optimizations" ON) option(WITH_SSE "Enable SSE2 optimizations" ON)
check_c_compiler_flag(-msse2 HAVE_MSSE2_FLAG) check_c_compiler_flag(-msse2 HAVE_MSSE2_FLAG)
if(WITH_SSE) if (WITH_SSE)
add_compile_options( add_compile_options(
$<$<BOOL:${HAVE_MSSE2_FLAG}>:-msse2> $<$<BOOL:${HAVE_MSSE2_FLAG}>:-msse2>
$<$<BOOL:${MSVC}>:/arch:SSE2>) $<$<BOOL:${MSVC}>:/arch:SSE2>)
endif() endif ()
endif() endif ()
include_directories("3rdparty/flac/src/libFLAC/include") include_directories("3rdparty/flac/src/libFLAC/include")
@@ -157,15 +157,15 @@ target_compile_definitions(aaruformat PUBLIC FLAC__NO_DLL)
target_compile_definitions(aaruformat PUBLIC FLAC__NO_FILEIO) target_compile_definitions(aaruformat PUBLIC FLAC__NO_FILEIO)
# Disable fortify source when not-release or when cross-building with MingW for WoA # Disable fortify source when not-release or when cross-building with MingW for WoA
if(CMAKE_BUILD_TYPE STREQUAL Debug OR CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo OR "${CMAKE_C_PLATFORM_ID}" MATCHES "MinGW") if (CMAKE_BUILD_TYPE STREQUAL Debug OR CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo OR "${CMAKE_C_PLATFORM_ID}" MATCHES "MinGW")
set(DODEFINE_FORTIFY_SOURCE 0) set(DODEFINE_FORTIFY_SOURCE 0)
endif() endif ()
set_property(TARGET aaruformat PROPERTY C_VISIBILITY_PRESET hidden) set_property(TARGET aaruformat PROPERTY C_VISIBILITY_PRESET hidden)
if(ARCHITECTURE_IS_64BIT) if (ARCHITECTURE_IS_64BIT)
set(ENABLE_64_BIT_WORDS 1) set(ENABLE_64_BIT_WORDS 1)
endif() endif ()
configure_file(3rdparty/flac/config.cmake.h.in 3rdparty/flac/config.h) configure_file(3rdparty/flac/config.cmake.h.in 3rdparty/flac/config.h)

40
3rdparty/lzma.cmake vendored
View File

@@ -10,27 +10,27 @@ target_compile_definitions(aaruformat PUBLIC _7ZIP_ST)
# All assembly for x86 and x64 disabled because it uses a custom, non GAS, non MASM, assembler # All assembly for x86 and x64 disabled because it uses a custom, non GAS, non MASM, assembler
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "AMD64") if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "AMD64")
set(IS_X64 1) set(IS_X64 1)
target_compile_definitions(aaruformat PUBLIC IS_X64) target_compile_definitions(aaruformat PUBLIC IS_X64)
# if(NOT "${CMAKE_C_COMPILER_ID}" MATCHES "AppleClang") # if(NOT "${CMAKE_C_COMPILER_ID}" MATCHES "AppleClang")
# set(USE_ASM 1) # set(USE_ASM 1)
# endif() # endif()
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "i686") elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "i686")
set(IS_X86 1) set(IS_X86 1)
target_compile_definitions(aaruformat PUBLIC IS_X86) target_compile_definitions(aaruformat PUBLIC IS_X86)
# set(USE_ASM 1) # set(USE_ASM 1)
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64") elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
set(IS_ARM64 1) set(IS_ARM64 1)
target_compile_definitions(aaruformat PUBLIC IS_ARM64) target_compile_definitions(aaruformat PUBLIC IS_ARM64)
set(USE_ASM 1) set(USE_ASM 1)
endif() endif ()
if("${CMAKE_C_COMPILER_ID}" MATCHES "AppleClang" OR "${CMAKE_C_COMPILER_ID}" MATCHES "Clang") if ("${CMAKE_C_COMPILER_ID}" MATCHES "AppleClang" OR "${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
set(USE_CLANG 1) set(USE_CLANG 1)
target_compile_definitions(aaruformat PUBLIC USE_CLANG) target_compile_definitions(aaruformat PUBLIC USE_CLANG)
endif() endif ()
#target_compile_options(lzma PUBLIC -Wall) #target_compile_options(lzma PUBLIC -Wall)
#target_compile_options(lzma PUBLIC -Werror) #target_compile_options(lzma PUBLIC -Werror)
@@ -38,12 +38,12 @@ endif()
target_compile_definitions(aaruformat PUBLIC $<$<COMPILE_LANGUAGE:ASM>:-DABI_LINUX>) target_compile_definitions(aaruformat PUBLIC $<$<COMPILE_LANGUAGE:ASM>:-DABI_LINUX>)
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "AMD64") if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "AMD64")
target_compile_options(aaruformat PUBLIC $<$<COMPILE_LANGUAGE:ASM>:-elf64>) target_compile_options(aaruformat PUBLIC $<$<COMPILE_LANGUAGE:ASM>:-elf64>)
else() else ()
target_compile_options(aaruformat PUBLIC $<$<COMPILE_LANGUAGE:ASM>:-elf>) target_compile_options(aaruformat PUBLIC $<$<COMPILE_LANGUAGE:ASM>:-elf>)
target_compile_definitions(aaruformat PUBLIC $<$<COMPILE_LANGUAGE:ASM>:-DABI_CDECL>) target_compile_definitions(aaruformat PUBLIC $<$<COMPILE_LANGUAGE:ASM>:-DABI_CDECL>)
endif() endif ()
#target_sources(aaruformat PRIVATE ${LZMA_C_DIRECTORY}/7zAlloc.c) #target_sources(aaruformat PRIVATE ${LZMA_C_DIRECTORY}/7zAlloc.c)
#target_sources(aaruformat PRIVATE ${LZMA_C_DIRECTORY}/7zArcIn.c) #target_sources(aaruformat PRIVATE ${LZMA_C_DIRECTORY}/7zArcIn.c)
@@ -98,11 +98,11 @@ target_sources(aaruformat PRIVATE ${LZMA_C_DIRECTORY}/LzmaLib.c)
#target_sources(aaruformat PRIVATE ${LZMA_ASM_DIRECTORY}/x86/7zCrcOpt.asm) #target_sources(aaruformat PRIVATE ${LZMA_ASM_DIRECTORY}/x86/7zCrcOpt.asm)
if(USE_ASM) if (USE_ASM)
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "i686" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "AMD64") if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "i686" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "AMD64")
set(USE_X86_ASM 1) set(USE_X86_ASM 1)
endif() endif ()
endif() endif ()
#if(USE_X86_ASM) #if(USE_X86_ASM)
# target_sources(aaruformat PRIVATE ${LZMA_ASM_DIRECTORY}/x86/7zCrcOpt.asm) # target_sources(aaruformat PRIVATE ${LZMA_ASM_DIRECTORY}/x86/7zCrcOpt.asm)
@@ -118,20 +118,20 @@ endif()
# target_sources(aaruformat PRIVATE ${LZMA_C_DIRECTORY}/AesOpt.c) # target_sources(aaruformat PRIVATE ${LZMA_C_DIRECTORY}/AesOpt.c)
#endif() #endif()
if(USE_LZMA_DEC_ASM) if (USE_LZMA_DEC_ASM)
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "AMD64") if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "AMD64")
target_sources(aaruformat PRIVATE ${LZMA_ASM_DIRECTORY}/x86/LzmaDecOpt.asm) target_sources(aaruformat PRIVATE ${LZMA_ASM_DIRECTORY}/x86/LzmaDecOpt.asm)
endif() endif ()
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64") if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
target_sources(aaruformat PRIVATE ${LZMA_ASM_DIRECTORY}/arm64/LzmaDecOpt.S) target_sources(aaruformat PRIVATE ${LZMA_ASM_DIRECTORY}/arm64/LzmaDecOpt.S)
# target_sources(aaruformat PRIVATE ${LZMA_ASM_DIRECTORY}/arm64/7zAsm.S) # target_sources(aaruformat PRIVATE ${LZMA_ASM_DIRECTORY}/arm64/7zAsm.S)
endif() endif ()
target_sources(aaruformat PRIVATE ${LZMA_C_DIRECTORY}/LzmaDec.c) target_sources(aaruformat PRIVATE ${LZMA_C_DIRECTORY}/LzmaDec.c)
else() else ()
target_sources(aaruformat PRIVATE ${LZMA_C_DIRECTORY}/LzmaDec.c) target_sources(aaruformat PRIVATE ${LZMA_C_DIRECTORY}/LzmaDec.c)
endif() endif ()
#target_sources(aaruformat PRIVATE ${LZMA_C_DIRECTORY}/XzDec.c) #target_sources(aaruformat PRIVATE ${LZMA_C_DIRECTORY}/XzDec.c)
#target_sources(aaruformat PRIVATE ${LZMA_C_DIRECTORY}/XzEnc.c) #target_sources(aaruformat PRIVATE ${LZMA_C_DIRECTORY}/XzEnc.c)

View File

@@ -16,29 +16,29 @@ cmake_minimum_required(VERSION 3.13)
# You should have received a copy of the GNU Lesser General Public # You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, see <http://www.gnu.org/licenses/>. # License along with this library; if not, see <http://www.gnu.org/licenses/>.
IF(APPLE) IF (APPLE)
IF("${CMAKE_OSX_ARCHITECTURES}" STREQUAL "") IF ("${CMAKE_OSX_ARCHITECTURES}" STREQUAL "")
SET(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "Build architectures for Mac OS X" FORCE) SET(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "Build architectures for Mac OS X" FORCE)
ENDIF() ENDIF ()
ENDIF(APPLE) ENDIF (APPLE)
project(libaaruformat C) project(libaaruformat C)
add_compile_definitions(__STDC_FORMAT_MACROS=1) add_compile_definitions(__STDC_FORMAT_MACROS=1)
if("${CMAKE_C_COMPILER_ID}" MATCHES "MSVC" AND "${CMAKE_C_COMPILER_ARCHITECTURE_ID}" MATCHES "ARMV7") if ("${CMAKE_C_COMPILER_ID}" MATCHES "MSVC" AND "${CMAKE_C_COMPILER_ARCHITECTURE_ID}" MATCHES "ARMV7")
set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD 11)
else() else ()
set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD 99)
endif() endif ()
if("${CMAKE_C_PLATFORM_ID}" MATCHES "MinGW") if ("${CMAKE_C_PLATFORM_ID}" MATCHES "MinGW")
if("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "aarch64" OR "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "arm") if ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "aarch64" OR "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "arm")
set(WIN32 TRUE) set(WIN32 TRUE)
endif() endif ()
add_link_options(-static-libgcc) add_link_options(-static-libgcc)
endif() endif ()
message("Detected system processor: ${CMAKE_SYSTEM_PROCESSOR}") message("Detected system processor: ${CMAKE_SYSTEM_PROCESSOR}")
message("Detected vs platform name: ${CMAKE_C_COMPILER_ARCHITECTURE_ID}") message("Detected vs platform name: ${CMAKE_C_COMPILER_ARCHITECTURE_ID}")
@@ -48,50 +48,50 @@ message("Detected platform: ${CMAKE_C_PLATFORM_ID}")
message("Size of (void*): ${CMAKE_SIZEOF_VOID_P}") message("Size of (void*): ${CMAKE_SIZEOF_VOID_P}")
# Check if target is 64-bit # Check if target is 64-bit
if("${CMAKE_SIZEOF_VOID_P}" MATCHES "8" OR "${CMAKE_C_COMPILER_ARCHITECTURE_ID}" MATCHES "x64" OR "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "x86_64" OR "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "AMD64" OR "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "aarch64") if ("${CMAKE_SIZEOF_VOID_P}" MATCHES "8" OR "${CMAKE_C_COMPILER_ARCHITECTURE_ID}" MATCHES "x64" OR "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "x86_64" OR "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "AMD64" OR "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "aarch64")
set(ARCHITECTURE_IS_64BIT TRUE) set(ARCHITECTURE_IS_64BIT TRUE)
endif() endif ()
if("${CMAKE_BUILD_TYPE}" MATCHES "Release") if ("${CMAKE_BUILD_TYPE}" MATCHES "Release")
add_compile_definitions(NDEBUG) add_compile_definitions(NDEBUG)
if("${CMAKE_C_COMPILER_ID}" MATCHES "MSVC") if ("${CMAKE_C_COMPILER_ID}" MATCHES "MSVC")
add_compile_options("/O2" "/fp:fast") add_compile_options("/O2" "/fp:fast")
if(${CMAKE_C_COMPILER_ARCHITECTURE_ID} MATCHES "X86" OR ${CMAKE_C_COMPILER_ARCHITECTURE_ID} MATCHES "x64") if (${CMAKE_C_COMPILER_ARCHITECTURE_ID} MATCHES "X86" OR ${CMAKE_C_COMPILER_ARCHITECTURE_ID} MATCHES "x64")
add_compile_options("/arch:SSE2") add_compile_options("/arch:SSE2")
endif() endif ()
else() else ()
add_compile_options(-ffast-math -O3) add_compile_options(-ffast-math -O3)
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "i686" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "AMD64") if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "i686" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "AMD64")
if(NOT "${CMAKE_C_COMPILER_ID}" MATCHES "AppleClang") if (NOT "${CMAKE_C_COMPILER_ID}" MATCHES "AppleClang")
add_compile_options(-march=core2 -mtune=westmere -mfpmath=sse) add_compile_options(-march=core2 -mtune=westmere -mfpmath=sse)
endif() endif ()
add_compile_options(-msse3) add_compile_options(-msse3)
if(NOT "${CMAKE_C_PLATFORM_ID}" MATCHES "MinGW") if (NOT "${CMAKE_C_PLATFORM_ID}" MATCHES "MinGW")
add_compile_options(-flto) add_compile_options(-flto)
endif() endif ()
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64") elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
if(NOT "${CMAKE_C_COMPILER_ID}" MATCHES "AppleClang") if (NOT "${CMAKE_C_COMPILER_ID}" MATCHES "AppleClang")
add_compile_options(-march=armv8-a) add_compile_options(-march=armv8-a)
endif() endif ()
if(NOT "${CMAKE_C_PLATFORM_ID}" MATCHES "MinGW") if (NOT "${CMAKE_C_PLATFORM_ID}" MATCHES "MinGW")
add_compile_options(-flto) add_compile_options(-flto)
endif() endif ()
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "armv7l" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm") elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "armv7l" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
if(NOT "${CMAKE_C_COMPILER_ID}" MATCHES "AppleClang") if (NOT "${CMAKE_C_COMPILER_ID}" MATCHES "AppleClang")
add_compile_options(-march=armv7+fp -mfpu=vfpv3-d16) add_compile_options(-march=armv7+fp -mfpu=vfpv3-d16)
endif() endif ()
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "mips") elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "mips")
if(NOT "${CMAKE_C_PLATFORM_ID}" MATCHES "MinGW") if (NOT "${CMAKE_C_PLATFORM_ID}" MATCHES "MinGW")
add_compile_options(-flto) add_compile_options(-flto)
endif() endif ()
endif() endif ()
endif() endif ()
endif() endif ()
add_library(aaruformat SHARED include/aaruformat/consts.h include/aaruformat/enums.h include/aaru.h include/aaruformat.h add_library(aaruformat SHARED include/aaruformat/consts.h include/aaruformat/enums.h include/aaru.h include/aaruformat.h
include/aaruformat/decls.h include/aaruformat/structs.h src/identify.c src/open.c include/aaruformat/context.h include/aaruformat/decls.h include/aaruformat/structs.h src/identify.c src/open.c include/aaruformat/context.h
@@ -106,29 +106,29 @@ include(3rdparty/flac.cmake)
include(3rdparty/lzma.cmake) include(3rdparty/lzma.cmake)
MACRO(TARGET_LINK_LIBRARIES_WHOLE_ARCHIVE target) MACRO(TARGET_LINK_LIBRARIES_WHOLE_ARCHIVE target)
if("${CMAKE_C_COMPILER_ID}" MATCHES "MSVC") if ("${CMAKE_C_COMPILER_ID}" MATCHES "MSVC")
FOREACH(arg IN LISTS ARGN) FOREACH (arg IN LISTS ARGN)
SET_TARGET_PROPERTIES( SET_TARGET_PROPERTIES(
${target} PROPERTIES LINK_FLAGS "/WHOLEARCHIVE:${lib}" ${target} PROPERTIES LINK_FLAGS "/WHOLEARCHIVE:${lib}"
) )
ENDFOREACH() ENDFOREACH ()
ELSE() ELSE ()
if("${CMAKE_C_COMPILER_ID}" MATCHES "AppleClang") if ("${CMAKE_C_COMPILER_ID}" MATCHES "AppleClang")
SET(LINK_FLAGS "-Wl,-all_load") SET(LINK_FLAGS "-Wl,-all_load")
SET(UNDO_FLAGS "-Wl,-noall_load") SET(UNDO_FLAGS "-Wl,-noall_load")
ELSE() ELSE ()
SET(LINK_FLAGS "-Wl,--whole-archive") SET(LINK_FLAGS "-Wl,--whole-archive")
SET(UNDO_FLAGS "-Wl,--no-whole-archive") SET(UNDO_FLAGS "-Wl,--no-whole-archive")
ENDIF() ENDIF ()
TARGET_LINK_LIBRARIES(${target} ${LINK_FLAGS} ${ARGN} ${UNDO_FLAGS}) TARGET_LINK_LIBRARIES(${target} ${LINK_FLAGS} ${ARGN} ${UNDO_FLAGS})
ENDIF() ENDIF ()
ENDMACRO() ENDMACRO()
if(NOT "${CMAKE_C_PLATFORM_ID}" MATCHES "MinGW" OR (NOT ${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm" AND NOT ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")) if (NOT "${CMAKE_C_PLATFORM_ID}" MATCHES "MinGW" OR (NOT ${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm" AND NOT ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64"))
set_property(TARGET aaruformat PROPERTY POSITION_INDEPENDENT_CODE TRUE) set_property(TARGET aaruformat PROPERTY POSITION_INDEPENDENT_CODE TRUE)
else() else ()
set_property(TARGET aaruformat PROPERTY POSITION_INDEPENDENT_CODE FALSE) set_property(TARGET aaruformat PROPERTY POSITION_INDEPENDENT_CODE FALSE)
endif() endif ()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake-modules") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake-modules")
@@ -137,32 +137,32 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake-modules")
find_package(OpenSSL QUIET) find_package(OpenSSL QUIET)
find_package(LibreSSL QUIET) find_package(LibreSSL QUIET)
if(OpenSSL_FOUND) if (OpenSSL_FOUND)
message("-- OpenSSL VERSION: ${OPENSSL_VERSION}") message("-- OpenSSL VERSION: ${OPENSSL_VERSION}")
endif() endif ()
if(LIBRESSL_FOUND) if (LIBRESSL_FOUND)
message("-- LibreSSL VERSION: ${LIBRESSL_VERSION}") message("-- LibreSSL VERSION: ${LIBRESSL_VERSION}")
endif() endif ()
if(OpenSSL_FOUND OR LIBRESSL_FOUND) if (OpenSSL_FOUND OR LIBRESSL_FOUND)
add_compile_definitions(AARU_HAS_SHA256) add_compile_definitions(AARU_HAS_SHA256)
endif() endif ()
if(LIBRESSL_FOUND) if (LIBRESSL_FOUND)
TARGET_LINK_LIBRARIES_WHOLE_ARCHIVE(aaruformat ${LIBRESSL_CRYPTO_LIBRARY}) TARGET_LINK_LIBRARIES_WHOLE_ARCHIVE(aaruformat ${LIBRESSL_CRYPTO_LIBRARY})
elseif(OpenSSL_FOUND) elseif (OpenSSL_FOUND)
TARGET_LINK_LIBRARIES_WHOLE_ARCHIVE(aaruformat ${OPENSSL_CRYPTO_LIBRARY}) TARGET_LINK_LIBRARIES_WHOLE_ARCHIVE(aaruformat ${OPENSSL_CRYPTO_LIBRARY})
endif() endif ()
include_directories(include 3rdparty/uthash/src) include_directories(include 3rdparty/uthash/src)
include(CheckLibraryExists) include(CheckLibraryExists)
check_library_exists(m log "" HAVE_LIB_M) check_library_exists(m log "" HAVE_LIB_M)
if(HAVE_LIB_M) if (HAVE_LIB_M)
TARGET_LINK_LIBRARIES_WHOLE_ARCHIVE(aaruformat m) TARGET_LINK_LIBRARIES_WHOLE_ARCHIVE(aaruformat m)
endif() endif ()
add_subdirectory(tests) add_subdirectory(tests)
add_subdirectory(tool) add_subdirectory(tool)

View File

@@ -1,4 +1,5 @@
# libaaruformat # libaaruformat
C implementation of [Aaru](https://www.github.com/aaru-dps/Aaru) file format. C implementation of [Aaru](https://www.github.com/aaru-dps/Aaru) file format.
Work in progress, don't expect it to work yet. Work in progress, don't expect it to work yet.
@@ -9,6 +10,7 @@ This means any hash or compression algorithm must be statically linked inside th
cmake is not a hard dependency, it's merely for the ease of using IDEs (specifically CLion). cmake is not a hard dependency, it's merely for the ease of using IDEs (specifically CLion).
Things still to be implemented that are already in the C# version: Things still to be implemented that are already in the C# version:
- Tape file blocks - Tape file blocks
- Automatic media type generation from C# enumeration - Automatic media type generation from C# enumeration
- Nuget package for linking with Aaru - Nuget package for linking with Aaru
@@ -17,6 +19,7 @@ Things still to be implemented that are already in the C# version:
- Deduplication (requires SHA256) - Deduplication (requires SHA256)
Things to be implemented not in the C# version: Things to be implemented not in the C# version:
- Compile for Dreamcast (KallistiOS preferibly) - Compile for Dreamcast (KallistiOS preferibly)
- Compile for PlayStation Portable - Compile for PlayStation Portable
- Compile for Wii - Compile for Wii

View File

@@ -1015,31 +1015,31 @@ typedef struct ImageInfo
/** Sector tags contained by the image */ /** Sector tags contained by the image */
// List<SectorTagType> ReadableSectorTags; // List<SectorTagType> ReadableSectorTags;
/** Image version */ /** Image version */
uint8_t* Version; uint8_t *Version;
/** Application that created the image */ /** Application that created the image */
uint8_t* Application; uint8_t *Application;
/** Version of the application that created the image */ /** Version of the application that created the image */
uint8_t* ApplicationVersion; uint8_t *ApplicationVersion;
/** Who (person) created the image? */ /** Who (person) created the image? */
uint8_t* Creator; uint8_t *Creator;
/** Image creation time */ /** Image creation time */
int64_t CreationTime; int64_t CreationTime;
/** Image last modification time */ /** Image last modification time */
int64_t LastModificationTime; int64_t LastModificationTime;
/** Title of the media represented by the image */ /** Title of the media represented by the image */
uint8_t* MediaTitle; uint8_t *MediaTitle;
/** Image comments */ /** Image comments */
uint8_t* Comments; uint8_t *Comments;
/** Manufacturer of the media represented by the image */ /** Manufacturer of the media represented by the image */
uint8_t* MediaManufacturer; uint8_t *MediaManufacturer;
/** Model of the media represented by the image */ /** Model of the media represented by the image */
uint8_t* MediaModel; uint8_t *MediaModel;
/** Serial number of the media represented by the image */ /** Serial number of the media represented by the image */
uint8_t* MediaSerialNumber; uint8_t *MediaSerialNumber;
/** Barcode of the media represented by the image */ /** Barcode of the media represented by the image */
uint8_t* MediaBarcode; uint8_t *MediaBarcode;
/** Part number of the media represented by the image */ /** Part number of the media represented by the image */
uint8_t* MediaPartNumber; uint8_t *MediaPartNumber;
/** Media type represented by the image */ /** Media type represented by the image */
uint32_t MediaType; uint32_t MediaType;
/** Number in sequence for the media represented by the image */ /** Number in sequence for the media represented by the image */
@@ -1047,13 +1047,13 @@ typedef struct ImageInfo
/** Last media of the sequence the media represented by the image corresponds to */ /** Last media of the sequence the media represented by the image corresponds to */
int32_t LastMediaSequence; int32_t LastMediaSequence;
/** Manufacturer of the drive used to read the media represented by the image */ /** Manufacturer of the drive used to read the media represented by the image */
uint8_t* DriveManufacturer; uint8_t *DriveManufacturer;
/** Model of the drive used to read the media represented by the image */ /** Model of the drive used to read the media represented by the image */
uint8_t* DriveModel; uint8_t *DriveModel;
/** Serial number of the drive used to read the media represented by the image */ /** Serial number of the drive used to read the media represented by the image */
uint8_t* DriveSerialNumber; uint8_t *DriveSerialNumber;
/** Firmware revision of the drive used to read the media represented by the image */ /** Firmware revision of the drive used to read the media represented by the image */
uint8_t* DriveFirmwareRevision; uint8_t *DriveFirmwareRevision;
/** Type of the media represented by the image to use in XML sidecars */ /** Type of the media represented by the image to use in XML sidecars */
uint8_t XmlMediaType; uint8_t XmlMediaType;
// CHS geometry... // CHS geometry...

View File

@@ -43,12 +43,12 @@ typedef struct Checksums
uint8_t md5[MD5_DIGEST_LENGTH]; uint8_t md5[MD5_DIGEST_LENGTH];
uint8_t sha1[SHA1_DIGEST_LENGTH]; uint8_t sha1[SHA1_DIGEST_LENGTH];
uint8_t sha256[SHA256_DIGEST_LENGTH]; uint8_t sha256[SHA256_DIGEST_LENGTH];
uint8_t* spamsum; uint8_t *spamsum;
} Checksums; } Checksums;
typedef struct mediaTagEntry typedef struct mediaTagEntry
{ {
uint8_t* data; uint8_t *data;
int32_t type; int32_t type;
uint32_t length; uint32_t length;
UT_hash_handle hh; UT_hash_handle hh;
@@ -59,52 +59,52 @@ typedef struct aaruformatContext
uint64_t magic; uint64_t magic;
uint8_t libraryMajorVersion; uint8_t libraryMajorVersion;
uint8_t libraryMinorVersion; uint8_t libraryMinorVersion;
FILE* imageStream; FILE *imageStream;
AaruHeader header; AaruHeader header;
uint8_t* sectorPrefix; uint8_t *sectorPrefix;
uint8_t* sectorPrefixCorrected; uint8_t *sectorPrefixCorrected;
uint8_t* sectorSuffix; uint8_t *sectorSuffix;
uint8_t* sectorSuffixCorrected; uint8_t *sectorSuffixCorrected;
uint8_t* sectorSubchannel; uint8_t *sectorSubchannel;
uint8_t* mode2Subheaders; uint8_t *mode2Subheaders;
uint8_t shift; uint8_t shift;
bool inMemoryDdt; bool inMemoryDdt;
uint64_t* userDataDdt; uint64_t *userDataDdt;
size_t mappedMemoryDdtSize; size_t mappedMemoryDdtSize;
uint32_t* sectorPrefixDdt; uint32_t *sectorPrefixDdt;
uint32_t* sectorSuffixDdt; uint32_t *sectorSuffixDdt;
GeometryBlockHeader geometryBlock; GeometryBlockHeader geometryBlock;
MetadataBlockHeader metadataBlockHeader; MetadataBlockHeader metadataBlockHeader;
uint8_t* metadataBlock; uint8_t *metadataBlock;
TracksHeader tracksHeader; TracksHeader tracksHeader;
TrackEntry* trackEntries; TrackEntry *trackEntries;
CicmMetadataBlock cicmBlockHeader; CicmMetadataBlock cicmBlockHeader;
uint8_t* cicmBlock; uint8_t *cicmBlock;
DumpHardwareHeader dumpHardwareHeader; DumpHardwareHeader dumpHardwareHeader;
struct DumpHardwareEntriesWithData* dumpHardwareEntriesWithData; struct DumpHardwareEntriesWithData *dumpHardwareEntriesWithData;
struct ImageInfo imageInfo; struct ImageInfo imageInfo;
CdEccContext* eccCdContext; CdEccContext *eccCdContext;
uint8_t numberOfDataTracks; uint8_t numberOfDataTracks;
TrackEntry* dataTracks; TrackEntry *dataTracks;
bool* readableSectorTags; bool *readableSectorTags;
struct CacheHeader blockHeaderCache; struct CacheHeader blockHeaderCache;
struct CacheHeader blockCache; struct CacheHeader blockCache;
struct Checksums checksums; struct Checksums checksums;
struct mediaTagEntry* mediaTags; struct mediaTagEntry *mediaTags;
} aaruformatContext; } aaruformatContext;
typedef struct DumpHardwareEntriesWithData typedef struct DumpHardwareEntriesWithData
{ {
DumpHardwareEntry entry; DumpHardwareEntry entry;
struct DumpExtent* extents; struct DumpExtent *extents;
uint8_t* manufacturer; uint8_t *manufacturer;
uint8_t* model; uint8_t *model;
uint8_t* revision; uint8_t *revision;
uint8_t* firmware; uint8_t *firmware;
uint8_t* serial; uint8_t *serial;
uint8_t* softwareName; uint8_t *softwareName;
uint8_t* softwareVersion; uint8_t *softwareVersion;
uint8_t* softwareOperatingSystem; uint8_t *softwareOperatingSystem;
} DumpHardwareEntriesWithData; } DumpHardwareEntriesWithData;
#pragma pack(push, 1) #pragma pack(push, 1)

View File

@@ -232,7 +232,8 @@ const static uint64_t crc64_table[4][256] = {
0xA0A13C6791602FF9, 0xBD4FB639B34C8E25, 0x9B7C28DBD5396C41, 0x8692A285F715CD9D, 0xD71B151F19D2A889, 0xA0A13C6791602FF9, 0xBD4FB639B34C8E25, 0x9B7C28DBD5396C41, 0x8692A285F715CD9D, 0xD71B151F19D2A889,
0xCAF59F413BFE0955, 0xECC601A35D8BEB31, 0xF1288BFD7FA74AED, 0x4FD56E9680052119, 0x523BE4C8A22980C5, 0xCAF59F413BFE0955, 0xECC601A35D8BEB31, 0xF1288BFD7FA74AED, 0x4FD56E9680052119, 0x523BE4C8A22980C5,
0x74087A2AC45C62A1, 0x69E6F074E670C37D, 0x386F47EE08B7A669, 0x2581CDB02A9B07B5, 0x03B253524CEEE5D1, 0x74087A2AC45C62A1, 0x69E6F074E670C37D, 0x386F47EE08B7A669, 0x2581CDB02A9B07B5, 0x03B253524CEEE5D1,
0x1E5CD90C6EC2440D}}; 0x1E5CD90C6EC2440D}
};
#define CRC64_ECMA_POLY 0xC96C5795D7870F42 #define CRC64_ECMA_POLY 0xC96C5795D7870F42
#define CRC64_ECMA_SEED 0xFFFFFFFFFFFFFFFF #define CRC64_ECMA_SEED 0xFFFFFFFFFFFFFFFF

View File

@@ -56,140 +56,95 @@
#define FORCE_INLINE static inline __attribute__((always_inline)) #define FORCE_INLINE static inline __attribute__((always_inline))
#endif #endif
AARU_EXPORT int AARU_CALL aaruf_identify(const char* filename); AARU_EXPORT int AARU_CALL aaruf_identify(const char *filename);
AARU_EXPORT int AARU_CALL aaruf_identify_stream(FILE* imageStream); AARU_EXPORT int AARU_CALL aaruf_identify_stream(FILE *imageStream);
AARU_EXPORT void* AARU_CALL aaruf_open(const char* filepath); AARU_EXPORT void *AARU_CALL aaruf_open(const char *filepath);
AARU_EXPORT int AARU_CALL aaruf_close(void* context); AARU_EXPORT int AARU_CALL aaruf_close(void *context);
AARU_EXPORT int32_t AARU_CALL aaruf_read_media_tag(void* context, uint8_t* data, int32_t tag, uint32_t* length); AARU_EXPORT int32_t AARU_CALL aaruf_read_media_tag(void *context, uint8_t *data, int32_t tag, uint32_t *length);
AARU_EXPORT crc64_ctx* AARU_CALL aaruf_crc64_init(); AARU_EXPORT crc64_ctx *AARU_CALL aaruf_crc64_init();
AARU_EXPORT int AARU_CALL aaruf_crc64_update(crc64_ctx* ctx, const uint8_t* data, uint32_t len); AARU_EXPORT int AARU_CALL aaruf_crc64_update(crc64_ctx *ctx, const uint8_t *data, uint32_t len);
AARU_EXPORT int AARU_CALL aaruf_crc64_final(crc64_ctx* ctx, uint64_t* crc); AARU_EXPORT int AARU_CALL aaruf_crc64_final(crc64_ctx *ctx, uint64_t *crc);
AARU_EXPORT void AARU_CALL aaruf_crc64_free(crc64_ctx* ctx); AARU_EXPORT void AARU_CALL aaruf_crc64_free(crc64_ctx *ctx);
AARU_EXPORT void AARU_CALL aaruf_crc64_slicing(uint64_t* previous_crc, const uint8_t* data, uint32_t len); AARU_EXPORT void AARU_CALL aaruf_crc64_slicing(uint64_t *previous_crc, const uint8_t *data, uint32_t len);
AARU_EXPORT uint64_t AARU_CALL aaruf_crc64_data(const uint8_t* data, uint32_t len); AARU_EXPORT uint64_t AARU_CALL aaruf_crc64_data(const uint8_t *data, uint32_t len);
AARU_EXPORT int32_t AARU_CALL aaruf_read_sector(void* context, uint64_t sectorAddress, uint8_t* data, uint32_t* length); AARU_EXPORT int32_t AARU_CALL aaruf_read_sector(void *context, uint64_t sectorAddress, uint8_t *data, uint32_t *length);
AARU_EXPORT int32_t AARU_CALL aaruf_read_sector_long(void* context, AARU_EXPORT int32_t AARU_CALL aaruf_read_sector_long(void *context, uint64_t sectorAddress, uint8_t *data,
uint64_t sectorAddress, uint32_t *length);
uint8_t* data,
uint32_t* length);
AARU_EXPORT int32_t AARU_CALL aaruf_verify_image(void* context); AARU_EXPORT int32_t AARU_CALL aaruf_verify_image(void *context);
AARU_EXPORT int32_t AARU_CALL aaruf_cst_transform(const uint8_t* interleaved, uint8_t* sequential, size_t length); AARU_EXPORT int32_t AARU_CALL aaruf_cst_transform(const uint8_t *interleaved, uint8_t *sequential, size_t length);
AARU_EXPORT int32_t AARU_CALL aaruf_cst_untransform(const uint8_t* sequential, uint8_t* interleaved, size_t length); AARU_EXPORT int32_t AARU_CALL aaruf_cst_untransform(const uint8_t *sequential, uint8_t *interleaved, size_t length);
AARU_EXPORT void* AARU_CALL aaruf_ecc_cd_init(); AARU_EXPORT void *AARU_CALL aaruf_ecc_cd_init();
AARU_EXPORT bool AARU_CALL aaruf_ecc_cd_is_suffix_correct(void* context, const uint8_t* sector); AARU_EXPORT bool AARU_CALL aaruf_ecc_cd_is_suffix_correct(void *context, const uint8_t *sector);
AARU_EXPORT bool AARU_CALL aaruf_ecc_cd_is_suffix_correct_mode2(void* context, const uint8_t* sector); AARU_EXPORT bool AARU_CALL aaruf_ecc_cd_is_suffix_correct_mode2(void *context, const uint8_t *sector);
AARU_EXPORT bool AARU_CALL aaruf_ecc_cd_check(void* context, AARU_EXPORT bool AARU_CALL aaruf_ecc_cd_check(void *context, const uint8_t *address, const uint8_t *data,
const uint8_t* address, uint32_t majorCount, uint32_t minorCount, uint32_t majorMult,
const uint8_t* data, uint32_t minorInc, const uint8_t *ecc, int32_t addressOffset,
uint32_t majorCount, int32_t dataOffset, int32_t eccOffset);
uint32_t minorCount,
uint32_t majorMult, AARU_EXPORT void AARU_CALL aaruf_ecc_cd_write(void *context, const uint8_t *address, const uint8_t *data,
uint32_t minorInc, uint32_t majorCount, uint32_t minorCount, uint32_t majorMult,
const uint8_t* ecc, uint32_t minorInc, uint8_t *ecc, int32_t addressOffset,
int32_t addressOffset, int32_t dataOffset, int32_t eccOffset);
int32_t dataOffset,
AARU_EXPORT void AARU_CALL aaruf_ecc_cd_write_sector(void *context, const uint8_t *address, const uint8_t *data,
uint8_t *ecc, int32_t addressOffset, int32_t dataOffset,
int32_t eccOffset); int32_t eccOffset);
AARU_EXPORT void AARU_CALL aaruf_ecc_cd_write(void* context, AARU_LOCAL void AARU_CALL aaruf_cd_lba_to_msf(int64_t pos, uint8_t *minute, uint8_t *second, uint8_t *frame);
const uint8_t* address,
const uint8_t* data,
uint32_t majorCount,
uint32_t minorCount,
uint32_t majorMult,
uint32_t minorInc,
uint8_t* ecc,
int32_t addressOffset,
int32_t dataOffset,
int32_t eccOffset);
AARU_EXPORT void AARU_CALL aaruf_ecc_cd_write_sector(void* context, AARU_EXPORT void AARU_CALL aaruf_ecc_cd_reconstruct_prefix(uint8_t *sector, uint8_t type, int64_t lba);
const uint8_t* address,
const uint8_t* data,
uint8_t* ecc,
int32_t addressOffset,
int32_t dataOffset,
int32_t eccOffset);
AARU_LOCAL void AARU_CALL aaruf_cd_lba_to_msf(int64_t pos, uint8_t* minute, uint8_t* second, uint8_t* frame); AARU_EXPORT void AARU_CALL aaruf_ecc_cd_reconstruct(void *context, uint8_t *sector, uint8_t type);
AARU_EXPORT void AARU_CALL aaruf_ecc_cd_reconstruct_prefix(uint8_t* sector, uint8_t type, int64_t lba); AARU_EXPORT uint32_t AARU_CALL aaruf_edc_cd_compute(void *context, uint32_t edc, const uint8_t *src, int size, int pos);
AARU_EXPORT void AARU_CALL aaruf_ecc_cd_reconstruct(void* context, uint8_t* sector, uint8_t type); AARU_EXPORT int32_t AARU_CALL aaruf_read_track_sector(void *context, uint8_t *data, uint64_t sectorAddress,
uint32_t *length, uint8_t track);
AARU_EXPORT uint32_t AARU_CALL aaruf_edc_cd_compute(void* context, uint32_t edc, const uint8_t* src, int size, int pos);
AARU_EXPORT int32_t AARU_CALL
aaruf_read_track_sector(void* context, uint8_t* data, uint64_t sectorAddress, uint32_t* length, uint8_t track);
AARU_LOCAL int32_t AARU_CALL aaruf_get_media_tag_type_for_datatype(int32_t type); AARU_LOCAL int32_t AARU_CALL aaruf_get_media_tag_type_for_datatype(int32_t type);
AARU_LOCAL int32_t AARU_CALL aaruf_get_xml_mediatype(int32_t type); AARU_LOCAL int32_t AARU_CALL aaruf_get_xml_mediatype(int32_t type);
AARU_EXPORT spamsum_ctx* AARU_CALL aaruf_spamsum_init(void); AARU_EXPORT spamsum_ctx *AARU_CALL aaruf_spamsum_init(void);
AARU_EXPORT int AARU_CALL aaruf_spamsum_update(spamsum_ctx* ctx, const uint8_t* data, uint32_t len); AARU_EXPORT int AARU_CALL aaruf_spamsum_update(spamsum_ctx *ctx, const uint8_t *data, uint32_t len);
AARU_EXPORT int AARU_CALL aaruf_spamsum_final(spamsum_ctx* ctx, uint8_t* result); AARU_EXPORT int AARU_CALL aaruf_spamsum_final(spamsum_ctx *ctx, uint8_t *result);
AARU_EXPORT void AARU_CALL aaruf_spamsum_free(spamsum_ctx* ctx); AARU_EXPORT void AARU_CALL aaruf_spamsum_free(spamsum_ctx *ctx);
AARU_LOCAL void fuzzy_engine_step(spamsum_ctx* ctx, uint8_t c); AARU_LOCAL void fuzzy_engine_step(spamsum_ctx *ctx, uint8_t c);
AARU_LOCAL void roll_hash(spamsum_ctx* ctx, uint8_t c); AARU_LOCAL void roll_hash(spamsum_ctx *ctx, uint8_t c);
AARU_LOCAL void fuzzy_try_reduce_blockhash(spamsum_ctx* ctx); AARU_LOCAL void fuzzy_try_reduce_blockhash(spamsum_ctx *ctx);
AARU_LOCAL void fuzzy_try_fork_blockhash(spamsum_ctx* ctx); AARU_LOCAL void fuzzy_try_fork_blockhash(spamsum_ctx *ctx);
AARU_EXPORT size_t AARU_CALL aaruf_flac_decode_redbook_buffer(uint8_t* dst_buffer, AARU_EXPORT size_t AARU_CALL aaruf_flac_decode_redbook_buffer(uint8_t *dst_buffer, size_t dst_size,
size_t dst_size, const uint8_t *src_buffer, size_t src_size);
const uint8_t* src_buffer,
size_t src_size);
AARU_EXPORT size_t AARU_CALL aaruf_flac_encode_redbook_buffer(uint8_t* dst_buffer, AARU_EXPORT size_t AARU_CALL aaruf_flac_encode_redbook_buffer(
size_t dst_size, uint8_t *dst_buffer, size_t dst_size, const uint8_t *src_buffer, size_t src_size, uint32_t blocksize,
const uint8_t* src_buffer, int32_t do_mid_side_stereo, int32_t loose_mid_side_stereo, const char *apodization, uint32_t max_lpc_order,
size_t src_size, uint32_t qlp_coeff_precision, int32_t do_qlp_coeff_prec_search, int32_t do_exhaustive_model_search,
uint32_t blocksize, uint32_t min_residual_partition_order, uint32_t max_residual_partition_order, const char *application_id,
int32_t do_mid_side_stereo,
int32_t loose_mid_side_stereo,
const char* apodization,
uint32_t max_lpc_order,
uint32_t qlp_coeff_precision,
int32_t do_qlp_coeff_prec_search,
int32_t do_exhaustive_model_search,
uint32_t min_residual_partition_order,
uint32_t max_residual_partition_order,
const char* application_id,
uint32_t application_id_len); uint32_t application_id_len);
AARU_EXPORT int32_t AARU_CALL aaruf_lzma_decode_buffer(uint8_t* dst_buffer, AARU_EXPORT int32_t AARU_CALL aaruf_lzma_decode_buffer(uint8_t *dst_buffer, size_t *dst_size, const uint8_t *src_buffer,
size_t* dst_size, size_t *src_size, const uint8_t *props, size_t propsSize);
const uint8_t* src_buffer,
size_t* src_size,
const uint8_t* props,
size_t propsSize);
AARU_EXPORT int32_t AARU_CALL aaruf_lzma_encode_buffer(uint8_t* dst_buffer, AARU_EXPORT int32_t AARU_CALL aaruf_lzma_encode_buffer(uint8_t *dst_buffer, size_t *dst_size, const uint8_t *src_buffer,
size_t* dst_size, size_t src_size, uint8_t *outProps, size_t *outPropsSize,
const uint8_t* src_buffer, int32_t level, uint32_t dictSize, int32_t lc, int32_t lp,
size_t src_size, int32_t pb, int32_t fb, int32_t numThreads);
uint8_t* outProps,
size_t* outPropsSize,
int32_t level,
uint32_t dictSize,
int32_t lc,
int32_t lp,
int32_t pb,
int32_t fb,
int32_t numThreads);
#if defined(__x86_64__) || defined(__amd64) || defined(_M_AMD64) || defined(_M_X64) || defined(__I386__) || \ #if defined(__x86_64__) || defined(__amd64) || defined(_M_AMD64) || defined(_M_X64) || defined(__I386__) || \
defined(__i386__) || defined(__THW_INTEL) || defined(_M_IX86) defined(__i386__) || defined(__THW_INTEL) || defined(_M_IX86)
@@ -198,7 +153,7 @@ AARU_EXPORT int have_clmul();
AARU_EXPORT int have_ssse3(); AARU_EXPORT int have_ssse3();
AARU_EXPORT int have_avx2(); AARU_EXPORT int have_avx2();
AARU_EXPORT CLMUL uint64_t AARU_CALL aaruf_crc64_clmul(uint64_t crc, const uint8_t* data, long length); AARU_EXPORT CLMUL uint64_t AARU_CALL aaruf_crc64_clmul(uint64_t crc, const uint8_t *data, long length);
#endif #endif
#if defined(__aarch64__) || defined(_M_ARM64) || defined(__arm__) || defined(_M_ARM) #if defined(__aarch64__) || defined(_M_ARM64) || defined(__arm__) || defined(_M_ARM)
@@ -206,7 +161,7 @@ AARU_EXPORT int have_neon();
AARU_EXPORT int have_arm_crc32(); AARU_EXPORT int have_arm_crc32();
AARU_EXPORT int have_arm_crypto(); AARU_EXPORT int have_arm_crypto();
AARU_EXPORT TARGET_WITH_SIMD uint64_t AARU_CALL aaruf_crc64_vmull(uint64_t previous_crc, const uint8_t* data, long len); AARU_EXPORT TARGET_WITH_SIMD uint64_t AARU_CALL aaruf_crc64_vmull(uint64_t previous_crc, const uint8_t *data, long len);
#endif #endif
#endif // LIBAARUFORMAT_DECLS_H #endif // LIBAARUFORMAT_DECLS_H

View File

@@ -58,8 +58,8 @@
#elif defined(__NetBSD__) #elif defined(__NetBSD__)
#include <sys/types.h>
#include <machine/bswap.h> #include <machine/bswap.h>
#include <sys/types.h>
#if defined(__BSWAP_RENAME) && !defined(__bswap_32) #if defined(__BSWAP_RENAME) && !defined(__bswap_32)
#define bswap_16(x) bswap16(x) #define bswap_16(x) bswap16(x)
#define bswap_32(x) bswap32(x) #define bswap_32(x) bswap32(x)
@@ -74,16 +74,16 @@
#include <stdint.h> #include <stdint.h>
#define bswap_16(x) ((uint16_t)((((uint16_t)(x)&0xff00) >> 8) | (((uint16_t)(x)&0x00ff) << 8))) #define bswap_16(x) ((uint16_t)((((uint16_t)(x) & 0xff00) >> 8) | (((uint16_t)(x) & 0x00ff) << 8)))
#define bswap_32(x) \ #define bswap_32(x) \
((uint32_t)((((uint32_t)(x)&0xff000000) >> 24) | (((uint32_t)(x)&0x00ff0000) >> 8) | \ ((uint32_t)((((uint32_t)(x) & 0xff000000) >> 24) | (((uint32_t)(x) & 0x00ff0000) >> 8) | \
(((uint32_t)(x)&0x0000ff00) << 8) | (((uint32_t)(x)&0x000000ff) << 24))) (((uint32_t)(x) & 0x0000ff00) << 8) | (((uint32_t)(x) & 0x000000ff) << 24)))
#define bswap_64(x) \ #define bswap_64(x) \
((uint64_t)((((uint64_t)(x)&0xff00000000000000ULL) >> 56) | (((uint64_t)(x)&0x00ff000000000000ULL) >> 40) | \ ((uint64_t)((((uint64_t)(x) & 0xff00000000000000ULL) >> 56) | (((uint64_t)(x) & 0x00ff000000000000ULL) >> 40) | \
(((uint64_t)(x)&0x0000ff0000000000ULL) >> 24) | (((uint64_t)(x)&0x000000ff00000000ULL) >> 8) | \ (((uint64_t)(x) & 0x0000ff0000000000ULL) >> 24) | (((uint64_t)(x) & 0x000000ff00000000ULL) >> 8) | \
(((uint64_t)(x)&0x00000000ff000000ULL) << 8) | (((uint64_t)(x)&0x0000000000ff0000ULL) << 24) | \ (((uint64_t)(x) & 0x00000000ff000000ULL) << 8) | (((uint64_t)(x) & 0x0000000000ff0000ULL) << 24) | \
(((uint64_t)(x)&0x000000000000ff00ULL) << 40) | (((uint64_t)(x)&0x00000000000000ffULL) << 56))) (((uint64_t)(x) & 0x000000000000ff00ULL) << 40) | (((uint64_t)(x) & 0x00000000000000ffULL) << 56)))
#endif #endif
#endif //LIBAARUFORMAT_ENDIAN_H #endif // LIBAARUFORMAT_ENDIAN_H

View File

@@ -21,10 +21,10 @@
typedef struct typedef struct
{ {
const uint8_t* src_buffer; const uint8_t *src_buffer;
size_t src_len; size_t src_len;
size_t src_pos; size_t src_pos;
uint8_t* dst_buffer; uint8_t *dst_buffer;
size_t dst_len; size_t dst_len;
size_t dst_pos; size_t dst_pos;
uint8_t error; uint8_t error;

View File

@@ -10,15 +10,15 @@
struct CacheEntry struct CacheEntry
{ {
char* key; char *key;
void* value; void *value;
UT_hash_handle hh; UT_hash_handle hh;
}; };
struct CacheHeader struct CacheHeader
{ {
uint64_t max_items; uint64_t max_items;
struct CacheEntry* cache; struct CacheEntry *cache;
}; };
/** /**
@@ -27,7 +27,7 @@ struct CacheHeader
* @param key Key * @param key Key
* @return Value if found, NULL if not * @return Value if found, NULL if not
*/ */
void* find_in_cache(struct CacheHeader* cache, char* key); void *find_in_cache(struct CacheHeader *cache, char *key);
/** /**
* Adds an item to the specified cache * Adds an item to the specified cache
@@ -35,7 +35,7 @@ void* find_in_cache(struct CacheHeader* cache, char* key);
* @param key Key * @param key Key
* @param value Value * @param value Value
*/ */
void add_to_cache(struct CacheHeader* cache, char* key, void* value); void add_to_cache(struct CacheHeader *cache, char *key, void *value);
/** /**
* Finds an item in the specified cache using a 64-bit integer key * Finds an item in the specified cache using a 64-bit integer key
@@ -43,7 +43,7 @@ void add_to_cache(struct CacheHeader* cache, char* key, void* value);
* @param key Key * @param key Key
* @return Value if found, NULL if not * @return Value if found, NULL if not
*/ */
void* find_in_cache_uint64(struct CacheHeader* cache, uint64_t key); void *find_in_cache_uint64(struct CacheHeader *cache, uint64_t key);
/** /**
* Adds an item to the specified cache using a 64-bit integer key * Adds an item to the specified cache using a 64-bit integer key
@@ -51,6 +51,6 @@ void* find_in_cache_uint64(struct CacheHeader* cache, uint64_t key);
* @param key Key * @param key Key
* @param value Value * @param value Value
*/ */
void add_to_cache_uint64(struct CacheHeader* cache, uint64_t key, void* value); void add_to_cache_uint64(struct CacheHeader *cache, uint64_t key, void *value);
#endif // LIBAARUFORMAT_LRU_H #endif // LIBAARUFORMAT_LRU_H

View File

@@ -303,9 +303,9 @@ typedef struct Crc64Context
typedef struct CdEccContext typedef struct CdEccContext
{ {
bool initedEdc; bool initedEdc;
uint8_t* eccBTable; uint8_t *eccBTable;
uint8_t* eccFTable; uint8_t *eccFTable;
uint32_t* edcTable; uint32_t *edcTable;
} CdEccContext; } CdEccContext;
#pragma pack(pop) #pragma pack(pop)

View File

@@ -26,11 +26,11 @@
#include <aaruformat.h> #include <aaruformat.h>
int aaruf_close(void* context) int aaruf_close(void *context)
{ {
int i; int i;
mediaTagEntry* mediaTag; mediaTagEntry *mediaTag;
mediaTagEntry* tmpMediaTag; mediaTagEntry *tmpMediaTag;
if(context == NULL) if(context == NULL)
{ {
@@ -38,7 +38,7 @@ int aaruf_close(void* context)
return -1; return -1;
} }
aaruformatContext* ctx = context; aaruformatContext *ctx = context;
// Not a libaaruformat context // Not a libaaruformat context
if(ctx->magic != AARU_MAGIC) if(ctx->magic != AARU_MAGIC)

View File

@@ -154,13 +154,13 @@ TARGET_WITH_SIMD uint64x2_t mm_shuffle_epi8(uint64x2_t a, uint64x2_t b)
TARGET_WITH_SIMD uint64x2_t mm_srli_si128(uint64x2_t a, int imm) TARGET_WITH_SIMD uint64x2_t mm_srli_si128(uint64x2_t a, int imm)
{ {
uint8x16_t tmp[2] = {vreinterpretq_u8_u64(a), vdupq_n_u8(0)}; uint8x16_t tmp[2] = {vreinterpretq_u8_u64(a), vdupq_n_u8(0)};
return vreinterpretq_u64_u8(vld1q_u8(((uint8_t const*)tmp) + imm)); return vreinterpretq_u64_u8(vld1q_u8(((uint8_t const *)tmp) + imm));
} }
TARGET_WITH_SIMD uint64x2_t mm_slli_si128(uint64x2_t a, int imm) TARGET_WITH_SIMD uint64x2_t mm_slli_si128(uint64x2_t a, int imm)
{ {
uint8x16_t tmp[2] = {vdupq_n_u8(0), vreinterpretq_u8_u64(a)}; uint8x16_t tmp[2] = {vdupq_n_u8(0), vreinterpretq_u8_u64(a)};
return vreinterpretq_u64_u8(vld1q_u8(((uint8_t const*)tmp) + (16 - imm))); return vreinterpretq_u64_u8(vld1q_u8(((uint8_t const *)tmp) + (16 - imm)));
} }
#endif #endif

View File

@@ -20,10 +20,10 @@
#include <aaruformat.h> #include <aaruformat.h>
AARU_EXPORT crc64_ctx* AARU_CALL aaruf_crc64_init(void) AARU_EXPORT crc64_ctx *AARU_CALL aaruf_crc64_init(void)
{ {
int i, slice; int i, slice;
crc64_ctx* ctx = (crc64_ctx*)malloc(sizeof(crc64_ctx)); crc64_ctx *ctx = (crc64_ctx *)malloc(sizeof(crc64_ctx));
if(!ctx) return NULL; if(!ctx) return NULL;
@@ -32,7 +32,7 @@ AARU_EXPORT crc64_ctx* AARU_CALL aaruf_crc64_init(void)
return ctx; return ctx;
} }
AARU_EXPORT int AARU_CALL aaruf_crc64_update(crc64_ctx* ctx, const uint8_t* data, uint32_t len) AARU_EXPORT int AARU_CALL aaruf_crc64_update(crc64_ctx *ctx, const uint8_t *data, uint32_t len)
{ {
if(!ctx || !data) return -1; if(!ctx || !data) return -1;
@@ -62,17 +62,17 @@ AARU_EXPORT int AARU_CALL aaruf_crc64_update(crc64_ctx* ctx, const uint8_t* data
return 0; return 0;
} }
AARU_EXPORT void AARU_CALL aaruf_crc64_slicing(uint64_t* previous_crc, const uint8_t* data, uint32_t len) AARU_EXPORT void AARU_CALL aaruf_crc64_slicing(uint64_t *previous_crc, const uint8_t *data, uint32_t len)
{ {
uint64_t c = *previous_crc; uint64_t c = *previous_crc;
if(len > 4) if(len > 4)
{ {
const uint8_t* limit; const uint8_t *limit;
while((uintptr_t)(data)&3) while((uintptr_t)(data) & 3)
{ {
c = crc64_table[0][*data++ ^ ((c)&0xFF)] ^ ((c) >> 8); c = crc64_table[0][*data++ ^ ((c) & 0xFF)] ^ ((c) >> 8);
--len; --len;
} }
@@ -81,20 +81,20 @@ AARU_EXPORT void AARU_CALL aaruf_crc64_slicing(uint64_t* previous_crc, const uin
while(data < limit) while(data < limit)
{ {
const uint32_t tmp = c ^ *(const uint32_t*)(data); const uint32_t tmp = c ^ *(const uint32_t *)(data);
data += 4; data += 4;
c = crc64_table[3][((tmp)&0xFF)] ^ crc64_table[2][(((tmp) >> 8) & 0xFF)] ^ ((c) >> 32) ^ c = crc64_table[3][((tmp) & 0xFF)] ^ crc64_table[2][(((tmp) >> 8) & 0xFF)] ^ ((c) >> 32) ^
crc64_table[1][(((tmp) >> 16) & 0xFF)] ^ crc64_table[0][((tmp) >> 24)]; crc64_table[1][(((tmp) >> 16) & 0xFF)] ^ crc64_table[0][((tmp) >> 24)];
} }
} }
while(len-- != 0) c = crc64_table[0][*data++ ^ ((c)&0xFF)] ^ ((c) >> 8); while(len-- != 0) c = crc64_table[0][*data++ ^ ((c) & 0xFF)] ^ ((c) >> 8);
*previous_crc = c; *previous_crc = c;
} }
AARU_EXPORT int AARU_CALL aaruf_crc64_final(crc64_ctx* ctx, uint64_t* crc) AARU_EXPORT int AARU_CALL aaruf_crc64_final(crc64_ctx *ctx, uint64_t *crc)
{ {
if(!ctx) return -1; if(!ctx) return -1;
@@ -103,14 +103,14 @@ AARU_EXPORT int AARU_CALL aaruf_crc64_final(crc64_ctx* ctx, uint64_t* crc)
return 0; return 0;
} }
AARU_EXPORT void AARU_CALL aaruf_crc64_free(crc64_ctx* ctx) AARU_EXPORT void AARU_CALL aaruf_crc64_free(crc64_ctx *ctx)
{ {
if(ctx) free(ctx); if(ctx) free(ctx);
} }
AARU_EXPORT uint64_t AARU_CALL aaruf_crc64_data(const uint8_t* data, uint32_t len) AARU_EXPORT uint64_t AARU_CALL aaruf_crc64_data(const uint8_t *data, uint32_t len)
{ {
crc64_ctx* ctx = aaruf_crc64_init(); crc64_ctx *ctx = aaruf_crc64_init();
uint64_t crc = 0; uint64_t crc = 0;
if(!ctx) return crc; if(!ctx) return crc;

View File

@@ -66,9 +66,9 @@ static const uint8_t shuffleMasks[] = {
0x8f, 0x8e, 0x8d, 0x8c, 0x8b, 0x8a, 0x89, 0x88, 0x87, 0x86, 0x85, 0x84, 0x83, 0x82, 0x81, 0x80, 0x8f, 0x8e, 0x8d, 0x8c, 0x8b, 0x8a, 0x89, 0x88, 0x87, 0x86, 0x85, 0x84, 0x83, 0x82, 0x81, 0x80,
}; };
CLMUL static void shiftRight128(__m128i in, size_t n, __m128i* outLeft, __m128i* outRight) CLMUL static void shiftRight128(__m128i in, size_t n, __m128i *outLeft, __m128i *outRight)
{ {
const __m128i maskA = _mm_loadu_si128((const __m128i*)(shuffleMasks + (16 - n))); const __m128i maskA = _mm_loadu_si128((const __m128i *)(shuffleMasks + (16 - n)));
const __m128i maskB = _mm_xor_si128(maskA, _mm_cmpeq_epi8(_mm_setzero_si128(), _mm_setzero_si128())); const __m128i maskB = _mm_xor_si128(maskA, _mm_cmpeq_epi8(_mm_setzero_si128(), _mm_setzero_si128()));
*outLeft = _mm_shuffle_epi8(in, maskB); *outLeft = _mm_shuffle_epi8(in, maskB);
@@ -80,7 +80,7 @@ CLMUL static __m128i fold(__m128i in, __m128i foldConstants)
return _mm_xor_si128(_mm_clmulepi64_si128(in, foldConstants, 0x00), _mm_clmulepi64_si128(in, foldConstants, 0x11)); return _mm_xor_si128(_mm_clmulepi64_si128(in, foldConstants, 0x00), _mm_clmulepi64_si128(in, foldConstants, 0x11));
} }
AARU_EXPORT CLMUL uint64_t AARU_CALL aaruf_crc64_clmul(uint64_t crc, const uint8_t* data, long length) AARU_EXPORT CLMUL uint64_t AARU_CALL aaruf_crc64_clmul(uint64_t crc, const uint8_t *data, long length)
{ {
const uint64_t k1 = 0xe05dd497ca393ae4; // bitReflect(expMod65(128 + 64, poly, 1)) << 1; const uint64_t k1 = 0xe05dd497ca393ae4; // bitReflect(expMod65(128 + 64, poly, 1)) << 1;
const uint64_t k2 = 0xdabe95afc7875f40; // bitReflect(expMod65(128, poly, 1)) << 1; const uint64_t k2 = 0xdabe95afc7875f40; // bitReflect(expMod65(128, poly, 1)) << 1;
@@ -90,18 +90,18 @@ AARU_EXPORT CLMUL uint64_t AARU_CALL aaruf_crc64_clmul(uint64_t crc, const uint8
const __m128i foldConstants1 = _mm_set_epi64x(k2, k1); const __m128i foldConstants1 = _mm_set_epi64x(k2, k1);
const __m128i foldConstants2 = _mm_set_epi64x(p, mu); const __m128i foldConstants2 = _mm_set_epi64x(p, mu);
const uint8_t* end = data + length; const uint8_t *end = data + length;
// Align pointers // Align pointers
const __m128i* alignedData = (const __m128i*)((uintptr_t)data & ~(uintptr_t)15); const __m128i *alignedData = (const __m128i *)((uintptr_t)data & ~(uintptr_t)15);
const __m128i* alignedEnd = (const __m128i*)(((uintptr_t)end + 15) & ~(uintptr_t)15); const __m128i *alignedEnd = (const __m128i *)(((uintptr_t)end + 15) & ~(uintptr_t)15);
const size_t leadInSize = data - (const uint8_t*)alignedData; const size_t leadInSize = data - (const uint8_t *)alignedData;
const size_t leadOutSize = (const uint8_t*)alignedEnd - end; const size_t leadOutSize = (const uint8_t *)alignedEnd - end;
const size_t alignedLength = alignedEnd - alignedData; const size_t alignedLength = alignedEnd - alignedData;
const __m128i leadInMask = _mm_loadu_si128((const __m128i*)(shuffleMasks + (16 - leadInSize))); const __m128i leadInMask = _mm_loadu_si128((const __m128i *)(shuffleMasks + (16 - leadInSize)));
const __m128i data0 = _mm_blendv_epi8(_mm_setzero_si128(), _mm_load_si128(alignedData), leadInMask); const __m128i data0 = _mm_blendv_epi8(_mm_setzero_si128(), _mm_load_si128(alignedData), leadInMask);
#if defined(_WIN64) #if defined(_WIN64)

View File

@@ -31,10 +31,10 @@ static const uint8_t shuffleMasks[] = {
0x8f, 0x8e, 0x8d, 0x8c, 0x8b, 0x8a, 0x89, 0x88, 0x87, 0x86, 0x85, 0x84, 0x83, 0x82, 0x81, 0x80, 0x8f, 0x8e, 0x8d, 0x8c, 0x8b, 0x8a, 0x89, 0x88, 0x87, 0x86, 0x85, 0x84, 0x83, 0x82, 0x81, 0x80,
}; };
TARGET_WITH_SIMD FORCE_INLINE void shiftRight128(uint64x2_t in, size_t n, uint64x2_t* outLeft, uint64x2_t* outRight) TARGET_WITH_SIMD FORCE_INLINE void shiftRight128(uint64x2_t in, size_t n, uint64x2_t *outLeft, uint64x2_t *outRight)
{ {
const uint64x2_t maskA = const uint64x2_t maskA =
vreinterpretq_u64_u32(vld1q_u32((const uint32_t*)(const uint64x2_t*)(shuffleMasks + (16 - n)))); vreinterpretq_u64_u32(vld1q_u32((const uint32_t *)(const uint64x2_t *)(shuffleMasks + (16 - n))));
uint64x2_t b = vreinterpretq_u64_u8(vceqq_u8(vreinterpretq_u8_u64(vreinterpretq_u64_u32(vdupq_n_u32(0))), uint64x2_t b = vreinterpretq_u64_u8(vceqq_u8(vreinterpretq_u8_u64(vreinterpretq_u64_u32(vdupq_n_u32(0))),
vreinterpretq_u8_u64(vreinterpretq_u64_u32(vdupq_n_u32(0))))); vreinterpretq_u8_u64(vreinterpretq_u64_u32(vdupq_n_u32(0)))));
const uint64x2_t maskB = vreinterpretq_u64_u32(veorq_u32(vreinterpretq_u32_u64(maskA), vreinterpretq_u32_u64(b))); const uint64x2_t maskB = vreinterpretq_u64_u32(veorq_u32(vreinterpretq_u32_u64(maskA), vreinterpretq_u32_u64(b)));
@@ -49,7 +49,7 @@ TARGET_WITH_SIMD FORCE_INLINE uint64x2_t fold(uint64x2_t in, uint64x2_t foldCons
sse2neon_vmull_p64(vget_high_u64(in), vget_high_u64(foldConstants))); sse2neon_vmull_p64(vget_high_u64(in), vget_high_u64(foldConstants)));
} }
AARU_EXPORT TARGET_WITH_SIMD uint64_t AARU_CALL aaruf_crc64_vmull(uint64_t previous_crc, const uint8_t* data, long len) AARU_EXPORT TARGET_WITH_SIMD uint64_t AARU_CALL aaruf_crc64_vmull(uint64_t previous_crc, const uint8_t *data, long len)
{ {
const uint64_t k1 = 0xe05dd497ca393ae4; // bitReflect(expMod65(128 + 64, poly, 1)) << 1; const uint64_t k1 = 0xe05dd497ca393ae4; // bitReflect(expMod65(128 + 64, poly, 1)) << 1;
const uint64_t k2 = 0xdabe95afc7875f40; // bitReflect(expMod65(128, poly, 1)) << 1; const uint64_t k2 = 0xdabe95afc7875f40; // bitReflect(expMod65(128, poly, 1)) << 1;
@@ -59,26 +59,25 @@ AARU_EXPORT TARGET_WITH_SIMD uint64_t AARU_CALL aaruf_crc64_vmull(uint64_t previ
const uint64x2_t foldConstants1 = vcombine_u64(vcreate_u64(k1), vcreate_u64(k2)); const uint64x2_t foldConstants1 = vcombine_u64(vcreate_u64(k1), vcreate_u64(k2));
const uint64x2_t foldConstants2 = vcombine_u64(vcreate_u64(mu), vcreate_u64(p)); const uint64x2_t foldConstants2 = vcombine_u64(vcreate_u64(mu), vcreate_u64(p));
const uint8_t* end = data + len; const uint8_t *end = data + len;
// Align pointers // Align pointers
const uint64x2_t* alignedData = (const uint64x2_t*)((uintptr_t)data & ~(uintptr_t)15); const uint64x2_t *alignedData = (const uint64x2_t *)((uintptr_t)data & ~(uintptr_t)15);
const uint64x2_t* alignedEnd = (const uint64x2_t*)(((uintptr_t)end + 15) & ~(uintptr_t)15); const uint64x2_t *alignedEnd = (const uint64x2_t *)(((uintptr_t)end + 15) & ~(uintptr_t)15);
const size_t leadInSize = data - (const uint8_t*)alignedData; const size_t leadInSize = data - (const uint8_t *)alignedData;
const size_t leadOutSize = (const uint8_t*)alignedEnd - end; const size_t leadOutSize = (const uint8_t *)alignedEnd - end;
const size_t alignedLength = alignedEnd - alignedData; const size_t alignedLength = alignedEnd - alignedData;
const uint64x2_t leadInMask = const uint64x2_t leadInMask =
vreinterpretq_u64_u32(vld1q_u32((const uint32_t*)(const uint64x2_t*)(shuffleMasks + (16 - leadInSize)))); vreinterpretq_u64_u32(vld1q_u32((const uint32_t *)(const uint64x2_t *)(shuffleMasks + (16 - leadInSize))));
uint64x2_t a = vreinterpretq_u64_u32(vdupq_n_u32(0)); uint64x2_t a = vreinterpretq_u64_u32(vdupq_n_u32(0));
uint64x2_t b = vreinterpretq_u64_u32( uint64x2_t b = vreinterpretq_u64_u32(
vld1q_u32((const uint32_t*)alignedData)); // Use a signed shift right to create a mask with the sign bit vld1q_u32((const uint32_t *)alignedData)); // Use a signed shift right to create a mask with the sign bit
const uint64x2_t data0 = const uint64x2_t data0 =
vreinterpretq_u64_u8(vbslq_u8(vreinterpretq_u8_s8(vshrq_n_s8(vreinterpretq_s8_u64(leadInMask), 7)), vreinterpretq_u64_u8(vbslq_u8(vreinterpretq_u8_s8(vshrq_n_s8(vreinterpretq_s8_u64(leadInMask), 7)),
vreinterpretq_u8_u64(b), vreinterpretq_u8_u64(b), vreinterpretq_u8_u64(a)));
vreinterpretq_u8_u64(a)));
const uint64x2_t initialCrc = vsetq_lane_u64(~previous_crc, vdupq_n_u64(0), 0); const uint64x2_t initialCrc = vsetq_lane_u64(~previous_crc, vdupq_n_u64(0), 0);
@@ -98,7 +97,7 @@ AARU_EXPORT TARGET_WITH_SIMD uint64_t AARU_CALL aaruf_crc64_vmull(uint64_t previ
} }
else if(alignedLength == 2) else if(alignedLength == 2)
{ {
const uint64x2_t data1 = vreinterpretq_u64_u32(vld1q_u32((const uint32_t*)(alignedData + 1))); const uint64x2_t data1 = vreinterpretq_u64_u32(vld1q_u32((const uint32_t *)(alignedData + 1)));
if(len < 8) if(len < 8)
{ {
@@ -141,7 +140,7 @@ AARU_EXPORT TARGET_WITH_SIMD uint64_t AARU_CALL aaruf_crc64_vmull(uint64_t previ
while(len >= 32) while(len >= 32)
{ {
accumulator = fold(veorq_u64(vreinterpretq_u64_u32(vld1q_u32((const uint32_t*)alignedData)), accumulator), accumulator = fold(veorq_u64(vreinterpretq_u64_u32(vld1q_u32((const uint32_t *)alignedData)), accumulator),
foldConstants1); foldConstants1);
len -= 16; len -= 16;
@@ -149,12 +148,13 @@ AARU_EXPORT TARGET_WITH_SIMD uint64_t AARU_CALL aaruf_crc64_vmull(uint64_t previ
} }
uint64x2_t P; uint64x2_t P;
if(len == 16) P = veorq_u64(accumulator, vreinterpretq_u64_u32(vld1q_u32((const uint32_t*)alignedData))); if(len == 16)
P = veorq_u64(accumulator, vreinterpretq_u64_u32(vld1q_u32((const uint32_t *)alignedData)));
else else
{ {
const uint64x2_t end0 = const uint64x2_t end0 =
veorq_u64(accumulator, vreinterpretq_u64_u32(vld1q_u32((const uint32_t*)alignedData))); veorq_u64(accumulator, vreinterpretq_u64_u32(vld1q_u32((const uint32_t *)alignedData)));
const uint64x2_t end1 = vreinterpretq_u64_u32(vld1q_u32((const uint32_t*)(alignedData + 1))); const uint64x2_t end1 = vreinterpretq_u64_u32(vld1q_u32((const uint32_t *)(alignedData + 1)));
uint64x2_t A, B, C, D; uint64x2_t A, B, C, D;
shiftRight128(end0, leadOutSize, &A, &B); shiftRight128(end0, leadOutSize, &A, &B);

View File

@@ -22,7 +22,7 @@
#include <aaruformat.h> #include <aaruformat.h>
int32_t aaruf_cst_transform(const uint8_t* interleaved, uint8_t* sequential, size_t length) int32_t aaruf_cst_transform(const uint8_t *interleaved, uint8_t *sequential, size_t length)
{ {
uint8_t *p, *q, *r, *s, *t, *u, *v, *w; uint8_t *p, *q, *r, *s, *t, *u, *v, *w;
size_t qStart; size_t qStart;
@@ -156,7 +156,7 @@ int32_t aaruf_cst_transform(const uint8_t* interleaved, uint8_t* sequential, siz
return AARUF_STATUS_OK; return AARUF_STATUS_OK;
} }
int32_t aaruf_cst_untransform(const uint8_t* sequential, uint8_t* interleaved, size_t length) int32_t aaruf_cst_untransform(const uint8_t *sequential, uint8_t *interleaved, size_t length)
{ {
uint8_t *p, *q, *r, *s, *t, *u, *v, *w; uint8_t *p, *q, *r, *s, *t, *u, *v, *w;
size_t qStart; size_t qStart;

View File

@@ -24,16 +24,16 @@
#include <aaruformat.h> #include <aaruformat.h>
void* aaruf_ecc_cd_init() void *aaruf_ecc_cd_init()
{ {
CdEccContext* context; CdEccContext *context;
uint32_t edc, i, j; uint32_t edc, i, j;
context = (CdEccContext*)malloc(sizeof(CdEccContext)); context = (CdEccContext *)malloc(sizeof(CdEccContext));
if(context == NULL) return NULL; if(context == NULL) return NULL;
context->eccFTable = (uint8_t*)malloc(sizeof(uint8_t) * 256); context->eccFTable = (uint8_t *)malloc(sizeof(uint8_t) * 256);
if(context->eccFTable == NULL) if(context->eccFTable == NULL)
{ {
@@ -41,7 +41,7 @@ void* aaruf_ecc_cd_init()
return NULL; return NULL;
} }
context->eccBTable = (uint8_t*)malloc(sizeof(uint8_t) * 256); context->eccBTable = (uint8_t *)malloc(sizeof(uint8_t) * 256);
if(context->eccBTable == NULL) if(context->eccBTable == NULL)
{ {
@@ -49,7 +49,7 @@ void* aaruf_ecc_cd_init()
free(context); free(context);
return NULL; return NULL;
} }
context->edcTable = (uint32_t*)malloc(sizeof(uint32_t) * 256); context->edcTable = (uint32_t *)malloc(sizeof(uint32_t) * 256);
if(context->edcTable == NULL) if(context->edcTable == NULL)
{ {
@@ -74,15 +74,15 @@ void* aaruf_ecc_cd_init()
return context; return context;
} }
bool aaruf_ecc_cd_is_suffix_correct(void* context, const uint8_t* sector) bool aaruf_ecc_cd_is_suffix_correct(void *context, const uint8_t *sector)
{ {
CdEccContext* ctx; CdEccContext *ctx;
uint32_t storedEdc, edc, calculatedEdc; uint32_t storedEdc, edc, calculatedEdc;
int size, pos; int size, pos;
if(context == NULL || sector == NULL) return false; if(context == NULL || sector == NULL) return false;
ctx = (CdEccContext*)context; ctx = (CdEccContext *)context;
if(!ctx->initedEdc) return false; if(!ctx->initedEdc) return false;
@@ -108,16 +108,16 @@ bool aaruf_ecc_cd_is_suffix_correct(void* context, const uint8_t* sector)
return calculatedEdc == storedEdc; return calculatedEdc == storedEdc;
} }
bool aaruf_ecc_cd_is_suffix_correct_mode2(void* context, const uint8_t* sector) bool aaruf_ecc_cd_is_suffix_correct_mode2(void *context, const uint8_t *sector)
{ {
CdEccContext* ctx; CdEccContext *ctx;
uint32_t storedEdc, edc, calculatedEdc; uint32_t storedEdc, edc, calculatedEdc;
int size, pos; int size, pos;
uint8_t zeroaddress[4]; uint8_t zeroaddress[4];
if(context == NULL || sector == NULL) return false; if(context == NULL || sector == NULL) return false;
ctx = (CdEccContext*)context; ctx = (CdEccContext *)context;
if(!ctx->initedEdc) return false; if(!ctx->initedEdc) return false;
@@ -139,25 +139,17 @@ bool aaruf_ecc_cd_is_suffix_correct_mode2(void* context, const uint8_t* sector)
return calculatedEdc == storedEdc; return calculatedEdc == storedEdc;
} }
bool aaruf_ecc_cd_check(void* context, bool aaruf_ecc_cd_check(void *context, const uint8_t *address, const uint8_t *data, uint32_t majorCount,
const uint8_t* address, uint32_t minorCount, uint32_t majorMult, uint32_t minorInc, const uint8_t *ecc,
const uint8_t* data, int32_t addressOffset, int32_t dataOffset, int32_t eccOffset)
uint32_t majorCount,
uint32_t minorCount,
uint32_t majorMult,
uint32_t minorInc,
const uint8_t* ecc,
int32_t addressOffset,
int32_t dataOffset,
int32_t eccOffset)
{ {
CdEccContext* ctx; CdEccContext *ctx;
uint32_t size, major, idx, minor; uint32_t size, major, idx, minor;
uint8_t eccA, eccB, temp; uint8_t eccA, eccB, temp;
if(context == NULL || address == NULL || data == NULL || ecc == NULL) return false; if(context == NULL || address == NULL || data == NULL || ecc == NULL) return false;
ctx = (CdEccContext*)context; ctx = (CdEccContext *)context;
if(!ctx->initedEdc) return false; if(!ctx->initedEdc) return false;
@@ -184,25 +176,17 @@ bool aaruf_ecc_cd_check(void* context,
return true; return true;
} }
void aaruf_ecc_cd_write(void* context, void aaruf_ecc_cd_write(void *context, const uint8_t *address, const uint8_t *data, uint32_t majorCount,
const uint8_t* address, uint32_t minorCount, uint32_t majorMult, uint32_t minorInc, uint8_t *ecc, int32_t addressOffset,
const uint8_t* data, int32_t dataOffset, int32_t eccOffset)
uint32_t majorCount,
uint32_t minorCount,
uint32_t majorMult,
uint32_t minorInc,
uint8_t* ecc,
int32_t addressOffset,
int32_t dataOffset,
int32_t eccOffset)
{ {
CdEccContext* ctx; CdEccContext *ctx;
uint32_t size, major, idx, minor; uint32_t size, major, idx, minor;
uint8_t eccA, eccB, temp; uint8_t eccA, eccB, temp;
if(context == NULL || address == NULL || data == NULL || ecc == NULL) return; if(context == NULL || address == NULL || data == NULL || ecc == NULL) return;
ctx = (CdEccContext*)context; ctx = (CdEccContext *)context;
if(!ctx->initedEdc) return; if(!ctx->initedEdc) return;
@@ -229,28 +213,22 @@ void aaruf_ecc_cd_write(void* context,
} }
} }
void aaruf_ecc_cd_write_sector(void* context, void aaruf_ecc_cd_write_sector(void *context, const uint8_t *address, const uint8_t *data, uint8_t *ecc,
const uint8_t* address, int32_t addressOffset, int32_t dataOffset, int32_t eccOffset)
const uint8_t* data,
uint8_t* ecc,
int32_t addressOffset,
int32_t dataOffset,
int32_t eccOffset)
{ {
aaruf_ecc_cd_write(context, address, data, 86, 24, 2, 86, ecc, addressOffset, dataOffset, eccOffset); // P aaruf_ecc_cd_write(context, address, data, 86, 24, 2, 86, ecc, addressOffset, dataOffset, eccOffset); // P
aaruf_ecc_cd_write(context, address, data, 52, 43, 86, 88, ecc, addressOffset, dataOffset, eccOffset + 0xAC); // Q aaruf_ecc_cd_write(context, address, data, 52, 43, 86, 88, ecc, addressOffset, dataOffset, eccOffset + 0xAC); // Q
} }
void aaruf_cd_lba_to_msf(int64_t pos, uint8_t* minute, uint8_t* second, uint8_t* frame) void aaruf_cd_lba_to_msf(int64_t pos, uint8_t *minute, uint8_t *second, uint8_t *frame)
{ {
*minute = (uint8_t)((pos + 150) / 75 / 60); *minute = (uint8_t)((pos + 150) / 75 / 60);
*second = (uint8_t)((pos + 150) / 75 % 60); *second = (uint8_t)((pos + 150) / 75 % 60);
*frame = (uint8_t)((pos + 150) % 75); *frame = (uint8_t)((pos + 150) % 75);
} }
void aaruf_ecc_cd_reconstruct_prefix(uint8_t* sector, // must point to a full 2352-byte sector void aaruf_ecc_cd_reconstruct_prefix(uint8_t *sector, // must point to a full 2352-byte sector
uint8_t type, uint8_t type, int64_t lba)
int64_t lba)
{ {
uint8_t minute, second, frame; uint8_t minute, second, frame;
@@ -301,22 +279,23 @@ void aaruf_ecc_cd_reconstruct_prefix(uint8_t* sector, // must point to a full 23
sector[0x012] = sector[0x016]; sector[0x012] = sector[0x016];
sector[0x013] = sector[0x017]; sector[0x013] = sector[0x017];
break; break;
default: return; default:
return;
} }
} }
void aaruf_ecc_cd_reconstruct(void* context, void aaruf_ecc_cd_reconstruct(void *context,
uint8_t* sector, // must point to a full 2352-byte sector uint8_t *sector, // must point to a full 2352-byte sector
uint8_t type) uint8_t type)
{ {
uint32_t computedEdc; uint32_t computedEdc;
uint8_t zeroaddress[4]; uint8_t zeroaddress[4];
CdEccContext* ctx; CdEccContext *ctx;
if(context == NULL || sector == NULL) return; if(context == NULL || sector == NULL) return;
ctx = (CdEccContext*)context; ctx = (CdEccContext *)context;
if(!ctx->initedEdc) return; if(!ctx->initedEdc) return;
@@ -337,7 +316,8 @@ void aaruf_ecc_cd_reconstruct(void* context,
computedEdc = aaruf_edc_cd_compute(context, 0, sector, 0x91C, 0x10); computedEdc = aaruf_edc_cd_compute(context, 0, sector, 0x91C, 0x10);
memcpy(sector + 0x92C, &computedEdc, 4); memcpy(sector + 0x92C, &computedEdc, 4);
break; break;
default: return; default:
return;
} }
memset(&zeroaddress, 0, 4); memset(&zeroaddress, 0, 4);
@@ -361,8 +341,11 @@ void aaruf_ecc_cd_reconstruct(void* context,
sector[0x81B] = 0x00; sector[0x81B] = 0x00;
aaruf_ecc_cd_write_sector(context, sector, sector, sector, 0xC, 0x10, 0x81C); aaruf_ecc_cd_write_sector(context, sector, sector, sector, 0xC, 0x10, 0x81C);
break; break;
case CdMode2Form1: aaruf_ecc_cd_write_sector(context, zeroaddress, sector, sector, 0, 0x10, 0x81C); break; case CdMode2Form1:
default: return; aaruf_ecc_cd_write_sector(context, zeroaddress, sector, sector, 0, 0x10, 0x81C);
break;
default:
return;
} }
// //
@@ -370,13 +353,13 @@ void aaruf_ecc_cd_reconstruct(void* context,
// //
} }
uint32_t aaruf_edc_cd_compute(void* context, uint32_t edc, const uint8_t* src, int size, int pos) uint32_t aaruf_edc_cd_compute(void *context, uint32_t edc, const uint8_t *src, int size, int pos)
{ {
CdEccContext* ctx; CdEccContext *ctx;
if(context == NULL || src == NULL) return 0; if(context == NULL || src == NULL) return 0;
ctx = (CdEccContext*)context; ctx = (CdEccContext *)context;
if(!ctx->initedEdc) return 0; if(!ctx->initedEdc) return 0;

View File

@@ -27,23 +27,19 @@
#include "../3rdparty/flac/include/FLAC/stream_encoder.h" #include "../3rdparty/flac/include/FLAC/stream_encoder.h"
#include "flac.h" #include "flac.h"
static FLAC__StreamDecoderReadStatus static FLAC__StreamDecoderReadStatus read_callback(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[],
read_callback(const FLAC__StreamDecoder* decoder, FLAC__byte buffer[], size_t* bytes, void* client_data); size_t *bytes, void *client_data);
static FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder* decoder, static FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame,
const FLAC__Frame* frame, const FLAC__int32 *const buffer[], void *client_data);
const FLAC__int32* const buffer[], static void error_callback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status,
void* client_data); void *client_data);
static void
error_callback(const FLAC__StreamDecoder* decoder, FLAC__StreamDecoderErrorStatus status, void* client_data);
AARU_EXPORT size_t AARU_CALL aaruf_flac_decode_redbook_buffer(uint8_t* dst_buffer, AARU_EXPORT size_t AARU_CALL aaruf_flac_decode_redbook_buffer(uint8_t *dst_buffer, size_t dst_size,
size_t dst_size, const uint8_t *src_buffer, size_t src_size)
const uint8_t* src_buffer,
size_t src_size)
{ {
FLAC__StreamDecoder* decoder; FLAC__StreamDecoder *decoder;
FLAC__StreamDecoderInitStatus init_status; FLAC__StreamDecoderInitStatus init_status;
aaru_flac_ctx* ctx = (aaru_flac_ctx*)malloc(sizeof(aaru_flac_ctx)); aaru_flac_ctx *ctx = (aaru_flac_ctx *)malloc(sizeof(aaru_flac_ctx));
size_t ret_size; size_t ret_size;
memset(ctx, 0, sizeof(aaru_flac_ctx)); memset(ctx, 0, sizeof(aaru_flac_ctx));
@@ -66,8 +62,8 @@ AARU_EXPORT size_t AARU_CALL aaruf_flac_decode_redbook_buffer(uint8_t* dst
FLAC__stream_decoder_set_md5_checking(decoder, false); FLAC__stream_decoder_set_md5_checking(decoder, false);
init_status = FLAC__stream_decoder_init_stream( init_status = FLAC__stream_decoder_init_stream(decoder, read_callback, NULL, NULL, NULL, NULL, write_callback, NULL,
decoder, read_callback, NULL, NULL, NULL, NULL, write_callback, NULL, error_callback, ctx); error_callback, ctx);
if(init_status != FLAC__STREAM_DECODER_INIT_STATUS_OK) if(init_status != FLAC__STREAM_DECODER_INIT_STATUS_OK)
{ {
@@ -87,10 +83,10 @@ AARU_EXPORT size_t AARU_CALL aaruf_flac_decode_redbook_buffer(uint8_t* dst
return ret_size; return ret_size;
} }
static FLAC__StreamDecoderReadStatus static FLAC__StreamDecoderReadStatus read_callback(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[],
read_callback(const FLAC__StreamDecoder* decoder, FLAC__byte buffer[], size_t* bytes, void* client_data) size_t *bytes, void *client_data)
{ {
aaru_flac_ctx* ctx = (aaru_flac_ctx*)client_data; aaru_flac_ctx *ctx = (aaru_flac_ctx *)client_data;
if(ctx->src_len - ctx->src_pos < *bytes) *bytes = ctx->src_len - ctx->src_pos; if(ctx->src_len - ctx->src_pos < *bytes) *bytes = ctx->src_len - ctx->src_pos;
@@ -102,14 +98,12 @@ static FLAC__StreamDecoderReadStatus
return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
} }
static FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder* decoder, static FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame,
const FLAC__Frame* frame, const FLAC__int32 *const buffer[], void *client_data)
const FLAC__int32* const buffer[],
void* client_data)
{ {
aaru_flac_ctx* ctx = (aaru_flac_ctx*)client_data; aaru_flac_ctx *ctx = (aaru_flac_ctx *)client_data;
size_t i; size_t i;
uint16_t* buffer16 = (uint16_t*)(ctx->dst_buffer + ctx->dst_pos); uint16_t *buffer16 = (uint16_t *)(ctx->dst_buffer + ctx->dst_pos);
// Why FLAC does not interleave the channels as PCM do, oh the mistery, we could use memcpy instead of looping // Why FLAC does not interleave the channels as PCM do, oh the mistery, we could use memcpy instead of looping
for(i = 0; i < frame->header.blocksize && ctx->dst_pos < ctx->dst_len; i++) for(i = 0; i < frame->header.blocksize && ctx->dst_pos < ctx->dst_len; i++)
@@ -134,47 +128,34 @@ static FLAC__StreamDecoderWriteStatus write_callback(const FLAC__StreamDecoder*
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
} }
static void error_callback(const FLAC__StreamDecoder* decoder, FLAC__StreamDecoderErrorStatus status, void* client_data) static void error_callback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
{ {
aaru_flac_ctx* ctx = (aaru_flac_ctx*)client_data; aaru_flac_ctx *ctx = (aaru_flac_ctx *)client_data;
fprintf(stderr, "Got error callback: %s\n", FLAC__StreamDecoderErrorStatusString[status]); fprintf(stderr, "Got error callback: %s\n", FLAC__StreamDecoderErrorStatusString[status]);
ctx->error = 1; ctx->error = 1;
} }
static FLAC__StreamEncoderWriteStatus encoder_write_callback(const FLAC__StreamEncoder* encoder, static FLAC__StreamEncoderWriteStatus encoder_write_callback(const FLAC__StreamEncoder *encoder,
const FLAC__byte buffer[], const FLAC__byte buffer[], size_t bytes, uint32_t samples,
size_t bytes, uint32_t current_frame, void *client_data);
uint32_t samples,
uint32_t current_frame,
void* client_data);
AARU_EXPORT size_t AARU_CALL aaruf_flac_encode_redbook_buffer(uint8_t* dst_buffer, AARU_EXPORT size_t AARU_CALL aaruf_flac_encode_redbook_buffer(
size_t dst_size, uint8_t *dst_buffer, size_t dst_size, const uint8_t *src_buffer, size_t src_size, uint32_t blocksize,
const uint8_t* src_buffer, int32_t do_mid_side_stereo, int32_t loose_mid_side_stereo, const char *apodization, uint32_t max_lpc_order,
size_t src_size, uint32_t qlp_coeff_precision, int32_t do_qlp_coeff_prec_search, int32_t do_exhaustive_model_search,
uint32_t blocksize, uint32_t min_residual_partition_order, uint32_t max_residual_partition_order, const char *application_id,
int32_t do_mid_side_stereo,
int32_t loose_mid_side_stereo,
const char* apodization,
uint32_t max_lpc_order,
uint32_t qlp_coeff_precision,
int32_t do_qlp_coeff_prec_search,
int32_t do_exhaustive_model_search,
uint32_t min_residual_partition_order,
uint32_t max_residual_partition_order,
const char* application_id,
uint32_t application_id_len) uint32_t application_id_len)
{ {
FLAC__StreamEncoder* encoder; FLAC__StreamEncoder *encoder;
aaru_flac_ctx* ctx = (aaru_flac_ctx*)malloc(sizeof(aaru_flac_ctx)); aaru_flac_ctx *ctx = (aaru_flac_ctx *)malloc(sizeof(aaru_flac_ctx));
FLAC__StreamEncoderInitStatus init_status; FLAC__StreamEncoderInitStatus init_status;
size_t ret_size; size_t ret_size;
FLAC__int32* pcm; FLAC__int32 *pcm;
int i; int i;
int16_t* buffer16 = (int16_t*)src_buffer; int16_t *buffer16 = (int16_t *)src_buffer;
FLAC__StreamMetadata* metadata[1]; FLAC__StreamMetadata *metadata[1];
memset(ctx, 0, sizeof(aaru_flac_ctx)); memset(ctx, 0, sizeof(aaru_flac_ctx));
@@ -228,8 +209,8 @@ AARU_EXPORT size_t AARU_CALL aaruf_flac_encode_redbook_buffer(uint8_t* dst
if(application_id_len > 0 && application_id != NULL) if(application_id_len > 0 && application_id != NULL)
if((metadata[0] = FLAC__metadata_object_new(FLAC__METADATA_TYPE_APPLICATION)) != NULL) if((metadata[0] = FLAC__metadata_object_new(FLAC__METADATA_TYPE_APPLICATION)) != NULL)
FLAC__metadata_object_application_set_data( FLAC__metadata_object_application_set_data(metadata[0], (unsigned char *)application_id, application_id_len,
metadata[0], (unsigned char*)application_id, application_id_len, true); true);
FLAC__stream_encoder_set_metadata(encoder, metadata, 1); FLAC__stream_encoder_set_metadata(encoder, metadata, 1);
@@ -260,14 +241,11 @@ AARU_EXPORT size_t AARU_CALL aaruf_flac_encode_redbook_buffer(uint8_t* dst
return ret_size; return ret_size;
} }
static FLAC__StreamEncoderWriteStatus encoder_write_callback(const FLAC__StreamEncoder* encoder, static FLAC__StreamEncoderWriteStatus encoder_write_callback(const FLAC__StreamEncoder *encoder,
const FLAC__byte buffer[], const FLAC__byte buffer[], size_t bytes, uint32_t samples,
size_t bytes, uint32_t current_frame, void *client_data)
uint32_t samples,
uint32_t current_frame,
void* client_data)
{ {
aaru_flac_ctx* ctx = (aaru_flac_ctx*)client_data; aaru_flac_ctx *ctx = (aaru_flac_ctx *)client_data;
if(bytes > ctx->dst_len - ctx->dst_pos) bytes = ctx->dst_len - ctx->dst_pos; if(bytes > ctx->dst_len - ctx->dst_pos) bytes = ctx->dst_len - ctx->dst_pos;

View File

@@ -25,76 +25,146 @@ int32_t aaruf_get_media_tag_type_for_datatype(int32_t type)
{ {
switch(type) switch(type)
{ {
case CompactDiscPartialToc: return CD_TOC; case CompactDiscPartialToc:
case CompactDiscSessionInfo: return CD_SessionInfo; return CD_TOC;
case CompactDiscToc: return CD_FullTOC; case CompactDiscSessionInfo:
case CompactDiscPma: return CD_PMA; return CD_SessionInfo;
case CompactDiscAtip: return CD_ATIP; case CompactDiscToc:
case CompactDiscLeadInCdText: return CD_TEXT; return CD_FullTOC;
case DvdPfi: return DVD_PFI; case CompactDiscPma:
case DvdLeadInCmi: return DVD_CMI; return CD_PMA;
case DvdDiscKey: return DVD_DiscKey; case CompactDiscAtip:
case DvdBca: return DVD_BCA; return CD_ATIP;
case DvdDmi: return DVD_DMI; case CompactDiscLeadInCdText:
case DvdMediaIdentifier: return DVD_MediaIdentifier; return CD_TEXT;
case DvdMediaKeyBlock: return DVD_MKB; case DvdPfi:
case DvdRamDds: return DVDRAM_DDS; return DVD_PFI;
case DvdRamMediumStatus: return DVDRAM_MediumStatus; case DvdLeadInCmi:
case DvdRamSpareArea: return DVDRAM_SpareArea; return DVD_CMI;
case DvdRRmd: return DVDR_RMD; case DvdDiscKey:
case DvdRPrerecordedInfo: return DVDR_PreRecordedInfo; return DVD_DiscKey;
case DvdRMediaIdentifier: return DVDR_MediaIdentifier; case DvdBca:
case DvdRPfi: return DVDR_PFI; return DVD_BCA;
case DvdAdip: return DVD_ADIP; case DvdDmi:
case HdDvdCpi: return HDDVD_CPI; return DVD_DMI;
case HdDvdMediumStatus: return HDDVD_MediumStatus; case DvdMediaIdentifier:
case DvdDlLayerCapacity: return DVDDL_LayerCapacity; return DVD_MediaIdentifier;
case DvdDlMiddleZoneAddress: return DVDDL_MiddleZoneAddress; case DvdMediaKeyBlock:
case DvdDlJumpIntervalSize: return DVDDL_JumpIntervalSize; return DVD_MKB;
case DvdDlManualLayerJumpLba: return DVDDL_ManualLayerJumpLBA; case DvdRamDds:
case BlurayDi: return BD_DI; return DVDRAM_DDS;
case BlurayBca: return BD_BCA; case DvdRamMediumStatus:
case BlurayDds: return BD_DDS; return DVDRAM_MediumStatus;
case BlurayCartridgeStatus: return BD_CartridgeStatus; case DvdRamSpareArea:
case BluraySpareArea: return BD_SpareArea; return DVDRAM_SpareArea;
case AacsVolumeIdentifier: return AACS_VolumeIdentifier; case DvdRRmd:
case AacsSerialNumber: return AACS_SerialNumber; return DVDR_RMD;
case AacsMediaIdentifier: return AACS_MediaIdentifier; case DvdRPrerecordedInfo:
case AacsMediaKeyBlock: return AACS_MKB; return DVDR_PreRecordedInfo;
case AacsDataKeys: return AACS_DataKeys; case DvdRMediaIdentifier:
case AacsLbaExtents: return AACS_LBAExtents; return DVDR_MediaIdentifier;
case CprmMediaKeyBlock: return AACS_CPRM_MKB; case DvdRPfi:
case HybridRecognizedLayers: return Hybrid_RecognizedLayers; return DVDR_PFI;
case ScsiMmcWriteProtection: return MMC_WriteProtection; case DvdAdip:
case ScsiMmcDiscInformation: return MMC_DiscInformation; return DVD_ADIP;
case ScsiMmcTrackResourcesInformation: return MMC_TrackResourcesInformation; case HdDvdCpi:
case ScsiMmcPowResourcesInformation: return MMC_POWResourcesInformation; return HDDVD_CPI;
case ScsiInquiry: return SCSI_INQUIRY; case HdDvdMediumStatus:
case ScsiModePage2A: return SCSI_MODEPAGE_2A; return HDDVD_MediumStatus;
case AtaIdentify: return ATA_IDENTIFY; case DvdDlLayerCapacity:
case AtapiIdentify: return ATAPI_IDENTIFY; return DVDDL_LayerCapacity;
case PcmciaCis: return PCMCIA_CIS; case DvdDlMiddleZoneAddress:
case SecureDigitalCid: return SD_CID; return DVDDL_MiddleZoneAddress;
case SecureDigitalCsd: return SD_CSD; case DvdDlJumpIntervalSize:
case SecureDigitalScr: return SD_SCR; return DVDDL_JumpIntervalSize;
case SecureDigitalOcr: return SD_OCR; case DvdDlManualLayerJumpLba:
case MultiMediaCardCid: return MMC_CID; return DVDDL_ManualLayerJumpLBA;
case MultiMediaCardCsd: return MMC_CSD; case BlurayDi:
case MultiMediaCardOcr: return MMC_OCR; return BD_DI;
case MultiMediaCardExtendedCsd: return MMC_ExtendedCSD; case BlurayBca:
case XboxSecuritySector: return Xbox_SecuritySector; return BD_BCA;
case FloppyLeadOut: return Floppy_LeadOut; case BlurayDds:
case DvdDiscControlBlock: return DCB; return BD_DDS;
case CompactDiscFirstTrackPregap: return CD_FirstTrackPregap; case BlurayCartridgeStatus:
case CompactDiscLeadOut: return CD_LeadOut; return BD_CartridgeStatus;
case ScsiModeSense6: return SCSI_MODESENSE_6; case BluraySpareArea:
case ScsiModeSense10: return SCSI_MODESENSE_10; return BD_SpareArea;
case UsbDescriptors: return USB_Descriptors; case AacsVolumeIdentifier:
case XboxDmi: return Xbox_DMI; return AACS_VolumeIdentifier;
case XboxPfi: return Xbox_PFI; case AacsSerialNumber:
case CompactDiscMediaCatalogueNumber: return CD_MCN; return AACS_SerialNumber;
case CompactDiscLeadIn: return CD_LeadIn; case AacsMediaIdentifier:
default: return -1; return AACS_MediaIdentifier;
case AacsMediaKeyBlock:
return AACS_MKB;
case AacsDataKeys:
return AACS_DataKeys;
case AacsLbaExtents:
return AACS_LBAExtents;
case CprmMediaKeyBlock:
return AACS_CPRM_MKB;
case HybridRecognizedLayers:
return Hybrid_RecognizedLayers;
case ScsiMmcWriteProtection:
return MMC_WriteProtection;
case ScsiMmcDiscInformation:
return MMC_DiscInformation;
case ScsiMmcTrackResourcesInformation:
return MMC_TrackResourcesInformation;
case ScsiMmcPowResourcesInformation:
return MMC_POWResourcesInformation;
case ScsiInquiry:
return SCSI_INQUIRY;
case ScsiModePage2A:
return SCSI_MODEPAGE_2A;
case AtaIdentify:
return ATA_IDENTIFY;
case AtapiIdentify:
return ATAPI_IDENTIFY;
case PcmciaCis:
return PCMCIA_CIS;
case SecureDigitalCid:
return SD_CID;
case SecureDigitalCsd:
return SD_CSD;
case SecureDigitalScr:
return SD_SCR;
case SecureDigitalOcr:
return SD_OCR;
case MultiMediaCardCid:
return MMC_CID;
case MultiMediaCardCsd:
return MMC_CSD;
case MultiMediaCardOcr:
return MMC_OCR;
case MultiMediaCardExtendedCsd:
return MMC_ExtendedCSD;
case XboxSecuritySector:
return Xbox_SecuritySector;
case FloppyLeadOut:
return Floppy_LeadOut;
case DvdDiscControlBlock:
return DCB;
case CompactDiscFirstTrackPregap:
return CD_FirstTrackPregap;
case CompactDiscLeadOut:
return CD_LeadOut;
case ScsiModeSense6:
return SCSI_MODESENSE_6;
case ScsiModeSense10:
return SCSI_MODESENSE_10;
case UsbDescriptors:
return USB_Descriptors;
case XboxDmi:
return Xbox_DMI;
case XboxPfi:
return Xbox_PFI;
case CompactDiscMediaCatalogueNumber:
return CD_MCN;
case CompactDiscLeadIn:
return CD_LeadIn;
default:
return -1;
} }
} }
@@ -193,7 +263,9 @@ int32_t aaruf_get_xml_mediatype(int32_t type)
case MilCD: case MilCD:
case VideoNow: case VideoNow:
case VideoNowColor: case VideoNowColor:
case VideoNowXp: return OpticalDisc; case VideoNowXp:
default: return BlockMedia; return OpticalDisc;
default:
return BlockMedia;
} }
} }

View File

@@ -28,9 +28,9 @@
* @return If positive, confidence value, with 100 being maximum confidentiality, and 0 not recognizing the file. * @return If positive, confidence value, with 100 being maximum confidentiality, and 0 not recognizing the file.
* If negative, error value * If negative, error value
*/ */
int aaruf_identify(const char* filename) int aaruf_identify(const char *filename)
{ {
FILE* stream; FILE *stream;
stream = fopen(filename, "rb"); stream = fopen(filename, "rb");
@@ -50,7 +50,7 @@ int aaruf_identify(const char* filename)
* @return If positive, confidence value, with 100 being maximum confidentiality, and 0 not recognizing the file. * @return If positive, confidence value, with 100 being maximum confidentiality, and 0 not recognizing the file.
* If negative, error value * If negative, error value
*/ */
int aaruf_identify_stream(FILE* imageStream) int aaruf_identify_stream(FILE *imageStream)
{ {
fseek(imageStream, 0, SEEK_SET); fseek(imageStream, 0, SEEK_SET);

View File

@@ -8,9 +8,9 @@
// by Jehiah Czebotar 2011 - jehiah@gmail.com // by Jehiah Czebotar 2011 - jehiah@gmail.com
// this code is in the public domain http://unlicense.org/ // this code is in the public domain http://unlicense.org/
void* find_in_cache(struct CacheHeader* cache, char* key) void *find_in_cache(struct CacheHeader *cache, char *key)
{ {
struct CacheEntry* entry; struct CacheEntry *entry;
HASH_FIND_STR(cache->cache, key, entry); HASH_FIND_STR(cache->cache, key, entry);
if(entry) if(entry)
{ {
@@ -22,7 +22,7 @@ void* find_in_cache(struct CacheHeader* cache, char* key)
return NULL; return NULL;
} }
void add_to_cache(struct CacheHeader* cache, char* key, void* value) void add_to_cache(struct CacheHeader *cache, char *key, void *value)
{ {
struct CacheEntry *entry, *tmp_entry; struct CacheEntry *entry, *tmp_entry;
// TODO: Is this needed or we're just losing cycles? uthash does not free the entry // TODO: Is this needed or we're just losing cycles? uthash does not free the entry
@@ -45,9 +45,9 @@ void add_to_cache(struct CacheHeader* cache, char* key, void* value)
} }
} }
FORCE_INLINE char* int64_to_string(uint64_t number) FORCE_INLINE char *int64_to_string(uint64_t number)
{ {
char* charKey; char *charKey;
charKey = malloc(17); charKey = malloc(17);
@@ -72,12 +72,12 @@ FORCE_INLINE char* int64_to_string(uint64_t number)
return charKey; return charKey;
} }
void* find_in_cache_uint64(struct CacheHeader* cache, uint64_t key) void *find_in_cache_uint64(struct CacheHeader *cache, uint64_t key)
{ {
return find_in_cache(cache, int64_to_string(key)); return find_in_cache(cache, int64_to_string(key));
} }
void add_to_cache_uint64(struct CacheHeader* cache, uint64_t key, void* value) void add_to_cache_uint64(struct CacheHeader *cache, uint64_t key, void *value)
{ {
return add_to_cache(cache, int64_to_string(key), value); return add_to_cache(cache, int64_to_string(key), value);
} }

View File

@@ -23,30 +23,17 @@
#include "../3rdparty/lzma-21.03beta/C/LzmaLib.h" #include "../3rdparty/lzma-21.03beta/C/LzmaLib.h"
AARU_EXPORT int32_t AARU_CALL aaruf_lzma_decode_buffer(uint8_t* dst_buffer, AARU_EXPORT int32_t AARU_CALL aaruf_lzma_decode_buffer(uint8_t *dst_buffer, size_t *dst_size, const uint8_t *src_buffer,
size_t* dst_size, size_t *srcLen, const uint8_t *props, size_t propsSize)
const uint8_t* src_buffer,
size_t* srcLen,
const uint8_t* props,
size_t propsSize)
{ {
return LzmaUncompress(dst_buffer, dst_size, src_buffer, srcLen, props, propsSize); return LzmaUncompress(dst_buffer, dst_size, src_buffer, srcLen, props, propsSize);
} }
AARU_EXPORT int32_t AARU_CALL aaruf_lzma_encode_buffer(uint8_t* dst_buffer, AARU_EXPORT int32_t AARU_CALL aaruf_lzma_encode_buffer(uint8_t *dst_buffer, size_t *dst_size, const uint8_t *src_buffer,
size_t* dst_size, size_t srcLen, uint8_t *outProps, size_t *outPropsSize,
const uint8_t* src_buffer, int32_t level, uint32_t dictSize, int32_t lc, int32_t lp,
size_t srcLen, int32_t pb, int32_t fb, int32_t numThreads)
uint8_t* outProps,
size_t* outPropsSize,
int32_t level,
uint32_t dictSize,
int32_t lc,
int32_t lp,
int32_t pb,
int32_t fb,
int32_t numThreads)
{ {
return LzmaCompress( return LzmaCompress(dst_buffer, dst_size, src_buffer, srcLen, outProps, outPropsSize, level, dictSize, lc, lp, pb,
dst_buffer, dst_size, src_buffer, srcLen, outProps, outPropsSize, level, dictSize, lc, lp, pb, fb, numThreads); fb, numThreads);
} }

View File

@@ -28,29 +28,29 @@
#include <aaruformat.h> #include <aaruformat.h>
void* aaruf_open(const char* filepath) void *aaruf_open(const char *filepath)
{ {
aaruformatContext* ctx; aaruformatContext *ctx;
int errorNo; int errorNo;
size_t readBytes; size_t readBytes;
long pos; long pos;
IndexHeader idxHeader; IndexHeader idxHeader;
IndexEntry* idxEntries; IndexEntry *idxEntries;
uint8_t* data; uint8_t *data;
uint8_t* cmpData; uint8_t *cmpData;
uint8_t* cstData; uint8_t *cstData;
uint32_t* cdDdt; uint32_t *cdDdt;
uint64_t crc64; uint64_t crc64;
int i, j, k; int i, j, k;
uint16_t e; uint16_t e;
uint8_t lzmaProperties[LZMA_PROPERTIES_LENGTH]; uint8_t lzmaProperties[LZMA_PROPERTIES_LENGTH];
size_t lzmaSize; size_t lzmaSize;
ChecksumHeader checksum_header; ChecksumHeader checksum_header;
ChecksumEntry* checksum_entry; ChecksumEntry *checksum_entry;
mediaTagEntry* mediaTag; mediaTagEntry *mediaTag;
mediaTagEntry* oldMediaTag; mediaTagEntry *oldMediaTag;
ctx = (aaruformatContext*)malloc(sizeof(aaruformatContext)); ctx = (aaruformatContext *)malloc(sizeof(aaruformatContext));
memset(ctx, 0, sizeof(aaruformatContext)); memset(ctx, 0, sizeof(aaruformatContext));
if(ctx == NULL) if(ctx == NULL)
@@ -97,12 +97,10 @@ void* aaruf_open(const char* filepath)
return NULL; return NULL;
} }
fprintf(stderr, fprintf(stderr, "libaaruformat: Opening image version %d.%d\n", ctx->header.imageMajorVersion,
"libaaruformat: Opening image version %d.%d\n",
ctx->header.imageMajorVersion,
ctx->header.imageMinorVersion); ctx->header.imageMinorVersion);
ctx->readableSectorTags = (bool*)malloc(sizeof(bool) * MaxSectorTag); ctx->readableSectorTags = (bool *)malloc(sizeof(bool) * MaxSectorTag);
if(ctx->readableSectorTags == NULL) if(ctx->readableSectorTags == NULL)
{ {
@@ -115,20 +113,18 @@ void* aaruf_open(const char* filepath)
memset(ctx->readableSectorTags, 0, sizeof(bool) * MaxSectorTag); memset(ctx->readableSectorTags, 0, sizeof(bool) * MaxSectorTag);
ctx->imageInfo.Application = ctx->header.application; ctx->imageInfo.Application = ctx->header.application;
ctx->imageInfo.ApplicationVersion = (uint8_t*)malloc(32); ctx->imageInfo.ApplicationVersion = (uint8_t *)malloc(32);
if(ctx->imageInfo.ApplicationVersion != NULL) if(ctx->imageInfo.ApplicationVersion != NULL)
{ {
memset(ctx->imageInfo.ApplicationVersion, 0, 32); memset(ctx->imageInfo.ApplicationVersion, 0, 32);
sprintf((char*)ctx->imageInfo.ApplicationVersion, sprintf((char *)ctx->imageInfo.ApplicationVersion, "%d.%d", ctx->header.applicationMajorVersion,
"%d.%d",
ctx->header.applicationMajorVersion,
ctx->header.applicationMinorVersion); ctx->header.applicationMinorVersion);
} }
ctx->imageInfo.Version = (uint8_t*)malloc(32); ctx->imageInfo.Version = (uint8_t *)malloc(32);
if(ctx->imageInfo.Version != NULL) if(ctx->imageInfo.Version != NULL)
{ {
memset(ctx->imageInfo.Version, 0, 32); memset(ctx->imageInfo.Version, 0, 32);
sprintf((char*)ctx->imageInfo.Version, "%d.%d", ctx->header.imageMajorVersion, ctx->header.imageMinorVersion); sprintf((char *)ctx->imageInfo.Version, "%d.%d", ctx->header.imageMajorVersion, ctx->header.imageMinorVersion);
} }
ctx->imageInfo.MediaType = ctx->header.mediaType; ctx->imageInfo.MediaType = ctx->header.mediaType;
@@ -161,12 +157,10 @@ void* aaruf_open(const char* filepath)
return NULL; return NULL;
} }
fprintf(stderr, fprintf(stderr, "libaaruformat: Index at %" PRIu64 " contains %d entries\n", ctx->header.indexOffset,
"libaaruformat: Index at %" PRIu64 " contains %d entries\n",
ctx->header.indexOffset,
idxHeader.entries); idxHeader.entries);
idxEntries = (IndexEntry*)malloc(sizeof(IndexEntry) * idxHeader.entries); idxEntries = (IndexEntry *)malloc(sizeof(IndexEntry) * idxHeader.entries);
if(idxEntries == NULL) if(idxEntries == NULL)
{ {
@@ -191,11 +185,8 @@ void* aaruf_open(const char* filepath)
for(i = 0; i < idxHeader.entries; i++) for(i = 0; i < idxHeader.entries; i++)
{ {
fprintf(stderr, fprintf(stderr, "libaaruformat: Block type %4.4s with data type %d is indexed to be at %" PRIu64 "\n",
"libaaruformat: Block type %4.4s with data type %d is indexed to be at %" PRIu64 "\n", (char *)&idxEntries[i].blockType, idxEntries[i].dataType, idxEntries[i].offset);
(char*)&idxEntries[i].blockType,
idxEntries[i].dataType,
idxEntries[i].offset);
} }
bool foundUserDataDdt = false; bool foundUserDataDdt = false;
@@ -208,8 +199,7 @@ void* aaruf_open(const char* filepath)
{ {
fprintf(stderr, fprintf(stderr,
"libaaruformat: Could not seek to %" PRIu64 " as indicated by index entry %d, continuing...\n", "libaaruformat: Could not seek to %" PRIu64 " as indicated by index entry %d, continuing...\n",
idxEntries[i].offset, idxEntries[i].offset, i);
i);
continue; continue;
} }
@@ -227,8 +217,8 @@ void* aaruf_open(const char* filepath)
if(readBytes != sizeof(BlockHeader)) if(readBytes != sizeof(BlockHeader))
{ {
fprintf( fprintf(stderr, "libaaruformat: Could not read block header at %" PRIu64 "\n",
stderr, "libaaruformat: Could not read block header at %" PRIu64 "\n", idxEntries[i].offset); idxEntries[i].offset);
break; break;
} }
@@ -246,8 +236,7 @@ void* aaruf_open(const char* filepath)
if(blockHeader.identifier != idxEntries[i].blockType) if(blockHeader.identifier != idxEntries[i].blockType)
{ {
fprintf(stderr, fprintf(stderr, "libaaruformat: Incorrect identifier for data block at position %" PRIu64 "\n",
"libaaruformat: Incorrect identifier for data block at position %" PRIu64 "\n",
idxEntries[i].offset); idxEntries[i].offset);
break; break;
} }
@@ -257,39 +246,33 @@ void* aaruf_open(const char* filepath)
fprintf(stderr, fprintf(stderr,
"libaaruformat: Expected block with data type %4.4s at position %" PRIu64 "libaaruformat: Expected block with data type %4.4s at position %" PRIu64
" but found data type %4.4s\n", " but found data type %4.4s\n",
(char*)&idxEntries[i].blockType, (char *)&idxEntries[i].blockType, idxEntries[i].offset, (char *)&blockHeader.type);
idxEntries[i].offset,
(char*)&blockHeader.type);
break; break;
} }
fprintf(stderr, fprintf(stderr, "libaaruformat: Found data block with type %4.4s at position %" PRIu64 "\n",
"libaaruformat: Found data block with type %4.4s at position %" PRIu64 "\n", (char *)&idxEntries[i].blockType, idxEntries[i].offset);
(char*)&idxEntries[i].blockType,
idxEntries[i].offset);
if(blockHeader.compression == Lzma || blockHeader.compression == LzmaClauniaSubchannelTransform) if(blockHeader.compression == Lzma || blockHeader.compression == LzmaClauniaSubchannelTransform)
{ {
if(blockHeader.compression == LzmaClauniaSubchannelTransform && if(blockHeader.compression == LzmaClauniaSubchannelTransform &&
blockHeader.type != CdSectorSubchannel) blockHeader.type != CdSectorSubchannel)
{ {
fprintf(stderr, fprintf(stderr, "Invalid compression type %d for block with data type %d, continuing...\n",
"Invalid compression type %d for block with data type %d, continuing...\n", blockHeader.compression, blockHeader.type);
blockHeader.compression,
blockHeader.type);
break; break;
} }
lzmaSize = blockHeader.cmpLength - LZMA_PROPERTIES_LENGTH; lzmaSize = blockHeader.cmpLength - LZMA_PROPERTIES_LENGTH;
cmpData = (uint8_t*)malloc(lzmaSize); cmpData = (uint8_t *)malloc(lzmaSize);
if(cmpData == NULL) if(cmpData == NULL)
{ {
fprintf(stderr, "Cannot allocate memory for block, continuing...\n"); fprintf(stderr, "Cannot allocate memory for block, continuing...\n");
break; break;
} }
data = (uint8_t*)malloc(blockHeader.length); data = (uint8_t *)malloc(blockHeader.length);
if(data == NULL) if(data == NULL)
{ {
fprintf(stderr, "Cannot allocate memory for block, continuing...\n"); fprintf(stderr, "Cannot allocate memory for block, continuing...\n");
@@ -316,8 +299,8 @@ void* aaruf_open(const char* filepath)
} }
readBytes = blockHeader.length; readBytes = blockHeader.length;
errorNo = aaruf_lzma_decode_buffer( errorNo = aaruf_lzma_decode_buffer(data, &readBytes, cmpData, &lzmaSize, lzmaProperties,
data, &readBytes, cmpData, &lzmaSize, lzmaProperties, LZMA_PROPERTIES_LENGTH); LZMA_PROPERTIES_LENGTH);
if(errorNo != 0) if(errorNo != 0)
{ {
@@ -363,7 +346,7 @@ void* aaruf_open(const char* filepath)
} }
else if(blockHeader.compression == None) else if(blockHeader.compression == None)
{ {
data = (uint8_t*)malloc(blockHeader.length); data = (uint8_t *)malloc(blockHeader.length);
if(data == NULL) if(data == NULL)
{ {
fprintf(stderr, "Cannot allocate memory for block, continuing...\n"); fprintf(stderr, "Cannot allocate memory for block, continuing...\n");
@@ -381,8 +364,7 @@ void* aaruf_open(const char* filepath)
} }
else else
{ {
fprintf(stderr, fprintf(stderr, "libaaruformat: Found unknown compression type %d, continuing...\n",
"libaaruformat: Found unknown compression type %d, continuing...\n",
blockHeader.compression); blockHeader.compression);
break; break;
} }
@@ -399,8 +381,7 @@ void* aaruf_open(const char* filepath)
fprintf(stderr, fprintf(stderr,
"libaaruformat: Incorrect CRC found: 0x%" PRIx64 " found, expected 0x%" PRIx64 "libaaruformat: Incorrect CRC found: 0x%" PRIx64 " found, expected 0x%" PRIx64
", continuing...\n", ", continuing...\n",
crc64, crc64, blockHeader.crc64);
blockHeader.crc64);
break; break;
} }
} }
@@ -420,7 +401,8 @@ void* aaruf_open(const char* filepath)
break; break;
case CdSectorSuffix: case CdSectorSuffix:
case CdSectorSuffixCorrected: case CdSectorSuffixCorrected:
if(idxEntries[i].dataType == CdSectorSuffixCorrected) ctx->sectorSuffixCorrected = data; if(idxEntries[i].dataType == CdSectorSuffixCorrected)
ctx->sectorSuffixCorrected = data;
else else
ctx->sectorSuffix = data; ctx->sectorSuffix = data;
@@ -440,9 +422,11 @@ void* aaruf_open(const char* filepath)
ctx->sectorSubchannel = data; ctx->sectorSubchannel = data;
ctx->readableSectorTags[AppleSectorTag] = true; ctx->readableSectorTags[AppleSectorTag] = true;
break; break;
case CompactDiscMode2Subheader: ctx->mode2Subheaders = data; break; case CompactDiscMode2Subheader:
ctx->mode2Subheaders = data;
break;
default: default:
mediaTag = (mediaTagEntry*)malloc(sizeof(mediaTagEntry)); mediaTag = (mediaTagEntry *)malloc(sizeof(mediaTagEntry));
if(mediaTag == NULL) if(mediaTag == NULL)
{ {
@@ -474,8 +458,8 @@ void* aaruf_open(const char* filepath)
if(readBytes != sizeof(DdtHeader)) if(readBytes != sizeof(DdtHeader))
{ {
fprintf( fprintf(stderr, "libaaruformat: Could not read block header at %" PRIu64 "\n",
stderr, "libaaruformat: Could not read block header at %" PRIu64 "\n", idxEntries[i].offset); idxEntries[i].offset);
break; break;
} }
@@ -496,14 +480,14 @@ void* aaruf_open(const char* filepath)
case Lzma: case Lzma:
lzmaSize = ddtHeader.cmpLength - LZMA_PROPERTIES_LENGTH; lzmaSize = ddtHeader.cmpLength - LZMA_PROPERTIES_LENGTH;
cmpData = (uint8_t*)malloc(lzmaSize); cmpData = (uint8_t *)malloc(lzmaSize);
if(cmpData == NULL) if(cmpData == NULL)
{ {
fprintf(stderr, "Cannot allocate memory for DDT, continuing...\n"); fprintf(stderr, "Cannot allocate memory for DDT, continuing...\n");
break; break;
} }
ctx->userDataDdt = (uint64_t*)malloc(ddtHeader.length); ctx->userDataDdt = (uint64_t *)malloc(ddtHeader.length);
if(ctx->userDataDdt == NULL) if(ctx->userDataDdt == NULL)
{ {
fprintf(stderr, "Cannot allocate memory for DDT, continuing...\n"); fprintf(stderr, "Cannot allocate memory for DDT, continuing...\n");
@@ -532,12 +516,8 @@ void* aaruf_open(const char* filepath)
} }
readBytes = ddtHeader.length; readBytes = ddtHeader.length;
errorNo = aaruf_lzma_decode_buffer((uint8_t*)ctx->userDataDdt, errorNo = aaruf_lzma_decode_buffer((uint8_t *)ctx->userDataDdt, &readBytes, cmpData,
&readBytes, &lzmaSize, lzmaProperties, LZMA_PROPERTIES_LENGTH);
cmpData,
&lzmaSize,
lzmaProperties,
LZMA_PROPERTIES_LENGTH);
if(errorNo != 0) if(errorNo != 0)
{ {
@@ -573,12 +553,8 @@ void* aaruf_open(const char* filepath)
case None: case None:
#ifdef __linux__ #ifdef __linux__
ctx->mappedMemoryDdtSize = sizeof(uint64_t) * ddtHeader.entries; ctx->mappedMemoryDdtSize = sizeof(uint64_t) * ddtHeader.entries;
ctx->userDataDdt = mmap(NULL, ctx->userDataDdt = mmap(NULL, ctx->mappedMemoryDdtSize, PROT_READ, MAP_SHARED,
ctx->mappedMemoryDdtSize, fileno(ctx->imageStream), idxEntries[i].offset + sizeof(ddtHeader));
PROT_READ,
MAP_SHARED,
fileno(ctx->imageStream),
idxEntries[i].offset + sizeof(ddtHeader));
if(ctx->userDataDdt == MAP_FAILED) if(ctx->userDataDdt == MAP_FAILED)
{ {
@@ -595,8 +571,7 @@ void* aaruf_open(const char* filepath)
break; break;
#endif #endif
default: default:
fprintf(stderr, fprintf(stderr, "libaaruformat: Found unknown compression type %d, continuing...\n",
"libaaruformat: Found unknown compression type %d, continuing...\n",
blockHeader.compression); blockHeader.compression);
foundUserDataDdt = false; foundUserDataDdt = false;
break; break;
@@ -611,14 +586,14 @@ void* aaruf_open(const char* filepath)
case Lzma: case Lzma:
lzmaSize = ddtHeader.cmpLength - LZMA_PROPERTIES_LENGTH; lzmaSize = ddtHeader.cmpLength - LZMA_PROPERTIES_LENGTH;
cmpData = (uint8_t*)malloc(lzmaSize); cmpData = (uint8_t *)malloc(lzmaSize);
if(cmpData == NULL) if(cmpData == NULL)
{ {
fprintf(stderr, "Cannot allocate memory for DDT, continuing...\n"); fprintf(stderr, "Cannot allocate memory for DDT, continuing...\n");
break; break;
} }
cdDdt = (uint32_t*)malloc(ddtHeader.length); cdDdt = (uint32_t *)malloc(ddtHeader.length);
if(cdDdt == NULL) if(cdDdt == NULL)
{ {
fprintf(stderr, "Cannot allocate memory for DDT, continuing...\n"); fprintf(stderr, "Cannot allocate memory for DDT, continuing...\n");
@@ -647,12 +622,8 @@ void* aaruf_open(const char* filepath)
} }
readBytes = ddtHeader.length; readBytes = ddtHeader.length;
errorNo = aaruf_lzma_decode_buffer((uint8_t*)cdDdt, errorNo = aaruf_lzma_decode_buffer((uint8_t *)cdDdt, &readBytes, cmpData, &lzmaSize,
&readBytes, lzmaProperties, LZMA_PROPERTIES_LENGTH);
cmpData,
&lzmaSize,
lzmaProperties,
LZMA_PROPERTIES_LENGTH);
if(errorNo != 0) if(errorNo != 0)
{ {
@@ -680,7 +651,8 @@ void* aaruf_open(const char* filepath)
return NULL; return NULL;
} }
if(idxEntries[i].dataType == CdSectorPrefixCorrected) ctx->sectorPrefixDdt = cdDdt; if(idxEntries[i].dataType == CdSectorPrefixCorrected)
ctx->sectorPrefixDdt = cdDdt;
else if(idxEntries[i].dataType == CdSectorSuffixCorrected) else if(idxEntries[i].dataType == CdSectorSuffixCorrected)
ctx->sectorSuffixDdt = cdDdt; ctx->sectorSuffixDdt = cdDdt;
else else
@@ -690,7 +662,7 @@ void* aaruf_open(const char* filepath)
// TODO: Check CRC // TODO: Check CRC
case None: case None:
cdDdt = (uint32_t*)malloc(ddtHeader.entries * sizeof(uint32_t)); cdDdt = (uint32_t *)malloc(ddtHeader.entries * sizeof(uint32_t));
if(mediaTag == NULL) if(mediaTag == NULL)
{ {
@@ -707,7 +679,8 @@ void* aaruf_open(const char* filepath)
break; break;
} }
if(idxEntries[i].dataType == CdSectorPrefixCorrected) ctx->sectorPrefixDdt = cdDdt; if(idxEntries[i].dataType == CdSectorPrefixCorrected)
ctx->sectorPrefixDdt = cdDdt;
else if(idxEntries[i].dataType == CdSectorSuffixCorrected) else if(idxEntries[i].dataType == CdSectorSuffixCorrected)
ctx->sectorSuffixDdt = cdDdt; ctx->sectorSuffixDdt = cdDdt;
else else
@@ -715,8 +688,7 @@ void* aaruf_open(const char* filepath)
break; break;
default: default:
fprintf(stderr, fprintf(stderr, "libaaruformat: Found unknown compression type %d, continuing...\n",
"libaaruformat: Found unknown compression type %d, continuing...\n",
blockHeader.compression); blockHeader.compression);
break; break;
} }
@@ -735,11 +707,8 @@ void* aaruf_open(const char* filepath)
if(ctx->geometryBlock.identifier == GeometryBlock) if(ctx->geometryBlock.identifier == GeometryBlock)
{ {
fprintf(stderr, fprintf(stderr, "libaaruformat: Geometry set to %d cylinders %d heads %d sectors per track\n",
"libaaruformat: Geometry set to %d cylinders %d heads %d sectors per track\n", ctx->geometryBlock.cylinders, ctx->geometryBlock.heads, ctx->geometryBlock.sectorsPerTrack);
ctx->geometryBlock.cylinders,
ctx->geometryBlock.heads,
ctx->geometryBlock.sectorsPerTrack);
ctx->imageInfo.Cylinders = ctx->geometryBlock.cylinders; ctx->imageInfo.Cylinders = ctx->geometryBlock.cylinders;
ctx->imageInfo.Heads = ctx->geometryBlock.heads; ctx->imageInfo.Heads = ctx->geometryBlock.heads;
@@ -763,15 +732,14 @@ void* aaruf_open(const char* filepath)
if(ctx->metadataBlockHeader.identifier != idxEntries[i].blockType) if(ctx->metadataBlockHeader.identifier != idxEntries[i].blockType)
{ {
memset(&ctx->metadataBlockHeader, 0, sizeof(MetadataBlockHeader)); memset(&ctx->metadataBlockHeader, 0, sizeof(MetadataBlockHeader));
fprintf(stderr, fprintf(stderr, "libaaruformat: Incorrect identifier for data block at position %" PRIu64 "\n",
"libaaruformat: Incorrect identifier for data block at position %" PRIu64 "\n",
idxEntries[i].offset); idxEntries[i].offset);
break; break;
} }
ctx->imageInfo.ImageSize += ctx->metadataBlockHeader.blockSize; ctx->imageInfo.ImageSize += ctx->metadataBlockHeader.blockSize;
ctx->metadataBlock = (uint8_t*)malloc(ctx->metadataBlockHeader.blockSize); ctx->metadataBlock = (uint8_t *)malloc(ctx->metadataBlockHeader.blockSize);
if(ctx->metadataBlock == NULL) if(ctx->metadataBlock == NULL)
{ {
@@ -793,9 +761,7 @@ void* aaruf_open(const char* filepath)
{ {
ctx->imageInfo.MediaSequence = ctx->metadataBlockHeader.mediaSequence; ctx->imageInfo.MediaSequence = ctx->metadataBlockHeader.mediaSequence;
ctx->imageInfo.LastMediaSequence = ctx->metadataBlockHeader.lastMediaSequence; ctx->imageInfo.LastMediaSequence = ctx->metadataBlockHeader.lastMediaSequence;
fprintf(stderr, fprintf(stderr, "libaaruformat: Setting media sequence as %d of %d\n", ctx->imageInfo.MediaSequence,
"libaaruformat: Setting media sequence as %d of %d\n",
ctx->imageInfo.MediaSequence,
ctx->imageInfo.LastMediaSequence); ctx->imageInfo.LastMediaSequence);
} }
@@ -803,11 +769,10 @@ void* aaruf_open(const char* filepath)
ctx->metadataBlockHeader.creatorOffset + ctx->metadataBlockHeader.creatorLength <= ctx->metadataBlockHeader.creatorOffset + ctx->metadataBlockHeader.creatorLength <=
ctx->metadataBlockHeader.blockSize) ctx->metadataBlockHeader.blockSize)
{ {
ctx->imageInfo.Creator = (uint8_t*)malloc(ctx->metadataBlockHeader.creatorLength); ctx->imageInfo.Creator = (uint8_t *)malloc(ctx->metadataBlockHeader.creatorLength);
if(ctx->imageInfo.Creator != NULL) if(ctx->imageInfo.Creator != NULL)
{ {
memcpy(ctx->imageInfo.Creator, memcpy(ctx->imageInfo.Creator, ctx->metadataBlock + ctx->metadataBlockHeader.creatorOffset,
ctx->metadataBlock + ctx->metadataBlockHeader.creatorOffset,
ctx->metadataBlockHeader.creatorLength); ctx->metadataBlockHeader.creatorLength);
} }
} }
@@ -816,11 +781,10 @@ void* aaruf_open(const char* filepath)
ctx->metadataBlockHeader.commentsOffset + ctx->metadataBlockHeader.commentsLength <= ctx->metadataBlockHeader.commentsOffset + ctx->metadataBlockHeader.commentsLength <=
ctx->metadataBlockHeader.blockSize) ctx->metadataBlockHeader.blockSize)
{ {
ctx->imageInfo.Comments = (uint8_t*)malloc(ctx->metadataBlockHeader.commentsLength); ctx->imageInfo.Comments = (uint8_t *)malloc(ctx->metadataBlockHeader.commentsLength);
if(ctx->imageInfo.Comments != NULL) if(ctx->imageInfo.Comments != NULL)
{ {
memcpy(ctx->imageInfo.Comments, memcpy(ctx->imageInfo.Comments, ctx->metadataBlock + ctx->metadataBlockHeader.commentsOffset,
ctx->metadataBlock + ctx->metadataBlockHeader.commentsOffset,
ctx->metadataBlockHeader.commentsLength); ctx->metadataBlockHeader.commentsLength);
} }
} }
@@ -829,7 +793,7 @@ void* aaruf_open(const char* filepath)
ctx->metadataBlockHeader.mediaTitleOffset + ctx->metadataBlockHeader.mediaTitleLength <= ctx->metadataBlockHeader.mediaTitleOffset + ctx->metadataBlockHeader.mediaTitleLength <=
ctx->metadataBlockHeader.blockSize) ctx->metadataBlockHeader.blockSize)
{ {
ctx->imageInfo.MediaTitle = (uint8_t*)malloc(ctx->metadataBlockHeader.mediaTitleLength); ctx->imageInfo.MediaTitle = (uint8_t *)malloc(ctx->metadataBlockHeader.mediaTitleLength);
if(ctx->imageInfo.MediaTitle != NULL) if(ctx->imageInfo.MediaTitle != NULL)
{ {
memcpy(ctx->imageInfo.MediaTitle, memcpy(ctx->imageInfo.MediaTitle,
@@ -844,7 +808,7 @@ void* aaruf_open(const char* filepath)
ctx->metadataBlockHeader.blockSize) ctx->metadataBlockHeader.blockSize)
{ {
ctx->imageInfo.MediaManufacturer = ctx->imageInfo.MediaManufacturer =
(uint8_t*)malloc(ctx->metadataBlockHeader.mediaManufacturerLength); (uint8_t *)malloc(ctx->metadataBlockHeader.mediaManufacturerLength);
if(ctx->imageInfo.MediaManufacturer != NULL) if(ctx->imageInfo.MediaManufacturer != NULL)
{ {
memcpy(ctx->imageInfo.MediaManufacturer, memcpy(ctx->imageInfo.MediaManufacturer,
@@ -857,7 +821,7 @@ void* aaruf_open(const char* filepath)
ctx->metadataBlockHeader.mediaModelOffset + ctx->metadataBlockHeader.mediaModelLength <= ctx->metadataBlockHeader.mediaModelOffset + ctx->metadataBlockHeader.mediaModelLength <=
ctx->metadataBlockHeader.blockSize) ctx->metadataBlockHeader.blockSize)
{ {
ctx->imageInfo.MediaModel = (uint8_t*)malloc(ctx->metadataBlockHeader.mediaModelOffset); ctx->imageInfo.MediaModel = (uint8_t *)malloc(ctx->metadataBlockHeader.mediaModelOffset);
if(ctx->imageInfo.MediaModel != NULL) if(ctx->imageInfo.MediaModel != NULL)
{ {
memcpy(ctx->imageInfo.MediaModel, memcpy(ctx->imageInfo.MediaModel,
@@ -872,7 +836,7 @@ void* aaruf_open(const char* filepath)
ctx->metadataBlockHeader.blockSize) ctx->metadataBlockHeader.blockSize)
{ {
ctx->imageInfo.MediaSerialNumber = ctx->imageInfo.MediaSerialNumber =
(uint8_t*)malloc(ctx->metadataBlockHeader.mediaSerialNumberLength); (uint8_t *)malloc(ctx->metadataBlockHeader.mediaSerialNumberLength);
if(ctx->imageInfo.MediaSerialNumber != NULL) if(ctx->imageInfo.MediaSerialNumber != NULL)
{ {
memcpy(ctx->imageInfo.MediaSerialNumber, memcpy(ctx->imageInfo.MediaSerialNumber,
@@ -885,7 +849,7 @@ void* aaruf_open(const char* filepath)
ctx->metadataBlockHeader.mediaBarcodeOffset + ctx->metadataBlockHeader.mediaBarcodeLength <= ctx->metadataBlockHeader.mediaBarcodeOffset + ctx->metadataBlockHeader.mediaBarcodeLength <=
ctx->metadataBlockHeader.blockSize) ctx->metadataBlockHeader.blockSize)
{ {
ctx->imageInfo.MediaBarcode = (uint8_t*)malloc(ctx->metadataBlockHeader.mediaBarcodeLength); ctx->imageInfo.MediaBarcode = (uint8_t *)malloc(ctx->metadataBlockHeader.mediaBarcodeLength);
if(ctx->imageInfo.MediaBarcode != NULL) if(ctx->imageInfo.MediaBarcode != NULL)
{ {
memcpy(ctx->imageInfo.MediaBarcode, memcpy(ctx->imageInfo.MediaBarcode,
@@ -898,7 +862,7 @@ void* aaruf_open(const char* filepath)
ctx->metadataBlockHeader.mediaPartNumberOffset + ctx->metadataBlockHeader.mediaPartNumberLength <= ctx->metadataBlockHeader.mediaPartNumberOffset + ctx->metadataBlockHeader.mediaPartNumberLength <=
ctx->metadataBlockHeader.blockSize) ctx->metadataBlockHeader.blockSize)
{ {
ctx->imageInfo.MediaPartNumber = (uint8_t*)malloc(ctx->metadataBlockHeader.mediaPartNumberLength); ctx->imageInfo.MediaPartNumber = (uint8_t *)malloc(ctx->metadataBlockHeader.mediaPartNumberLength);
if(ctx->imageInfo.MediaPartNumber != NULL) if(ctx->imageInfo.MediaPartNumber != NULL)
{ {
memcpy(ctx->imageInfo.MediaPartNumber, memcpy(ctx->imageInfo.MediaPartNumber,
@@ -913,7 +877,7 @@ void* aaruf_open(const char* filepath)
ctx->metadataBlockHeader.blockSize) ctx->metadataBlockHeader.blockSize)
{ {
ctx->imageInfo.DriveManufacturer = ctx->imageInfo.DriveManufacturer =
(uint8_t*)malloc(ctx->metadataBlockHeader.driveManufacturerLength); (uint8_t *)malloc(ctx->metadataBlockHeader.driveManufacturerLength);
if(ctx->imageInfo.DriveManufacturer != NULL) if(ctx->imageInfo.DriveManufacturer != NULL)
{ {
memcpy(ctx->imageInfo.DriveManufacturer, memcpy(ctx->imageInfo.DriveManufacturer,
@@ -926,7 +890,7 @@ void* aaruf_open(const char* filepath)
ctx->metadataBlockHeader.driveModelOffset + ctx->metadataBlockHeader.driveModelLength <= ctx->metadataBlockHeader.driveModelOffset + ctx->metadataBlockHeader.driveModelLength <=
ctx->metadataBlockHeader.blockSize) ctx->metadataBlockHeader.blockSize)
{ {
ctx->imageInfo.DriveModel = (uint8_t*)malloc(ctx->metadataBlockHeader.driveModelLength); ctx->imageInfo.DriveModel = (uint8_t *)malloc(ctx->metadataBlockHeader.driveModelLength);
if(ctx->imageInfo.DriveModel != NULL) if(ctx->imageInfo.DriveModel != NULL)
{ {
memcpy(ctx->imageInfo.DriveModel, memcpy(ctx->imageInfo.DriveModel,
@@ -941,7 +905,7 @@ void* aaruf_open(const char* filepath)
ctx->metadataBlockHeader.blockSize) ctx->metadataBlockHeader.blockSize)
{ {
ctx->imageInfo.DriveSerialNumber = ctx->imageInfo.DriveSerialNumber =
(uint8_t*)malloc(ctx->metadataBlockHeader.driveSerialNumberLength); (uint8_t *)malloc(ctx->metadataBlockHeader.driveSerialNumberLength);
if(ctx->imageInfo.DriveSerialNumber != NULL) if(ctx->imageInfo.DriveSerialNumber != NULL)
{ {
memcpy(ctx->imageInfo.DriveSerialNumber, memcpy(ctx->imageInfo.DriveSerialNumber,
@@ -956,7 +920,7 @@ void* aaruf_open(const char* filepath)
ctx->metadataBlockHeader.blockSize) ctx->metadataBlockHeader.blockSize)
{ {
ctx->imageInfo.DriveFirmwareRevision = ctx->imageInfo.DriveFirmwareRevision =
(uint8_t*)malloc(ctx->metadataBlockHeader.driveFirmwareRevisionLength); (uint8_t *)malloc(ctx->metadataBlockHeader.driveFirmwareRevisionLength);
if(ctx->imageInfo.DriveFirmwareRevision != NULL) if(ctx->imageInfo.DriveFirmwareRevision != NULL)
{ {
memcpy(ctx->imageInfo.DriveFirmwareRevision, memcpy(ctx->imageInfo.DriveFirmwareRevision,
@@ -979,14 +943,13 @@ void* aaruf_open(const char* filepath)
if(ctx->tracksHeader.identifier != TracksBlock) if(ctx->tracksHeader.identifier != TracksBlock)
{ {
memset(&ctx->tracksHeader, 0, sizeof(TracksHeader)); memset(&ctx->tracksHeader, 0, sizeof(TracksHeader));
fprintf(stderr, fprintf(stderr, "libaaruformat: Incorrect identifier for data block at position %" PRIu64 "\n",
"libaaruformat: Incorrect identifier for data block at position %" PRIu64 "\n",
idxEntries[i].offset); idxEntries[i].offset);
} }
ctx->imageInfo.ImageSize += sizeof(TrackEntry) * ctx->tracksHeader.entries; ctx->imageInfo.ImageSize += sizeof(TrackEntry) * ctx->tracksHeader.entries;
ctx->trackEntries = (TrackEntry*)malloc(sizeof(TrackEntry) * ctx->tracksHeader.entries); ctx->trackEntries = (TrackEntry *)malloc(sizeof(TrackEntry) * ctx->tracksHeader.entries);
if(ctx->trackEntries == NULL) if(ctx->trackEntries == NULL)
{ {
@@ -1004,8 +967,8 @@ void* aaruf_open(const char* filepath)
fprintf(stderr, "libaaruformat: Could not read metadata block, continuing...\n"); fprintf(stderr, "libaaruformat: Could not read metadata block, continuing...\n");
} }
crc64 = crc64 = aaruf_crc64_data((const uint8_t *)ctx->trackEntries,
aaruf_crc64_data((const uint8_t*)ctx->trackEntries, ctx->tracksHeader.entries * sizeof(TrackEntry)); ctx->tracksHeader.entries * sizeof(TrackEntry));
// Due to how C# wrote it, it is effectively reversed // Due to how C# wrote it, it is effectively reversed
if(ctx->header.imageMajorVersion <= AARUF_VERSION) crc64 = bswap_64(crc64); if(ctx->header.imageMajorVersion <= AARUF_VERSION) crc64 = bswap_64(crc64);
@@ -1015,14 +978,11 @@ void* aaruf_open(const char* filepath)
fprintf(stderr, fprintf(stderr,
"libaaruformat: Incorrect CRC found: 0x%" PRIx64 " found, expected 0x%" PRIx64 "libaaruformat: Incorrect CRC found: 0x%" PRIx64 " found, expected 0x%" PRIx64
", continuing...\n", ", continuing...\n",
crc64, crc64, ctx->tracksHeader.crc64);
ctx->tracksHeader.crc64);
break; break;
} }
fprintf(stderr, fprintf(stderr, "libaaruformat: Found %d tracks at position %" PRIu64 ".\n", ctx->tracksHeader.entries,
"libaaruformat: Found %d tracks at position %" PRIu64 ".\n",
ctx->tracksHeader.entries,
idxEntries[i].offset); idxEntries[i].offset);
ctx->imageInfo.HasPartitions = true; ctx->imageInfo.HasPartitions = true;
@@ -1060,14 +1020,13 @@ void* aaruf_open(const char* filepath)
if(ctx->cicmBlockHeader.identifier != CicmBlock) if(ctx->cicmBlockHeader.identifier != CicmBlock)
{ {
memset(&ctx->cicmBlockHeader, 0, sizeof(CicmMetadataBlock)); memset(&ctx->cicmBlockHeader, 0, sizeof(CicmMetadataBlock));
fprintf(stderr, fprintf(stderr, "libaaruformat: Incorrect identifier for data block at position %" PRIu64 "\n",
"libaaruformat: Incorrect identifier for data block at position %" PRIu64 "\n",
idxEntries[i].offset); idxEntries[i].offset);
} }
ctx->imageInfo.ImageSize += ctx->cicmBlockHeader.length; ctx->imageInfo.ImageSize += ctx->cicmBlockHeader.length;
ctx->cicmBlock = (uint8_t*)malloc(ctx->cicmBlockHeader.length); ctx->cicmBlock = (uint8_t *)malloc(ctx->cicmBlockHeader.length);
if(ctx->cicmBlock == NULL) if(ctx->cicmBlock == NULL)
{ {
@@ -1102,12 +1061,11 @@ void* aaruf_open(const char* filepath)
if(ctx->dumpHardwareHeader.identifier != DumpHardwareBlock) if(ctx->dumpHardwareHeader.identifier != DumpHardwareBlock)
{ {
memset(&ctx->dumpHardwareHeader, 0, sizeof(DumpHardwareHeader)); memset(&ctx->dumpHardwareHeader, 0, sizeof(DumpHardwareHeader));
fprintf(stderr, fprintf(stderr, "libaaruformat: Incorrect identifier for data block at position %" PRIu64 "\n",
"libaaruformat: Incorrect identifier for data block at position %" PRIu64 "\n",
idxEntries[i].offset); idxEntries[i].offset);
} }
data = (uint8_t*)malloc(ctx->dumpHardwareHeader.length); data = (uint8_t *)malloc(ctx->dumpHardwareHeader.length);
if(data == NULL) if(data == NULL)
{ {
@@ -1132,8 +1090,7 @@ void* aaruf_open(const char* filepath)
fprintf(stderr, fprintf(stderr,
"libaaruformat: Incorrect CRC found: 0x%" PRIx64 " found, expected 0x%" PRIx64 "libaaruformat: Incorrect CRC found: 0x%" PRIx64 " found, expected 0x%" PRIx64
", continuing...\n", ", continuing...\n",
crc64, crc64, ctx->dumpHardwareHeader.crc64);
ctx->dumpHardwareHeader.crc64);
break; break;
} }
} }
@@ -1141,7 +1098,7 @@ void* aaruf_open(const char* filepath)
free(data); free(data);
fseek(ctx->imageStream, -(long)readBytes, SEEK_CUR); fseek(ctx->imageStream, -(long)readBytes, SEEK_CUR);
ctx->dumpHardwareEntriesWithData = (DumpHardwareEntriesWithData*)malloc( ctx->dumpHardwareEntriesWithData = (DumpHardwareEntriesWithData *)malloc(
sizeof(DumpHardwareEntriesWithData) * ctx->dumpHardwareHeader.entries); sizeof(DumpHardwareEntriesWithData) * ctx->dumpHardwareHeader.entries);
if(ctx->dumpHardwareEntriesWithData == NULL) if(ctx->dumpHardwareEntriesWithData == NULL)
@@ -1152,14 +1109,13 @@ void* aaruf_open(const char* filepath)
break; break;
} }
memset(ctx->dumpHardwareEntriesWithData, memset(ctx->dumpHardwareEntriesWithData, 0,
0,
sizeof(DumpHardwareEntriesWithData) * ctx->dumpHardwareHeader.entries); sizeof(DumpHardwareEntriesWithData) * ctx->dumpHardwareHeader.entries);
for(e = 0; e < ctx->dumpHardwareHeader.entries; e++) for(e = 0; e < ctx->dumpHardwareHeader.entries; e++)
{ {
readBytes = fread( readBytes = fread(&ctx->dumpHardwareEntriesWithData[e].entry, 1, sizeof(DumpHardwareEntry),
&ctx->dumpHardwareEntriesWithData[e].entry, 1, sizeof(DumpHardwareEntry), ctx->imageStream); ctx->imageStream);
if(readBytes != sizeof(DumpHardwareEntry)) if(readBytes != sizeof(DumpHardwareEntry))
{ {
@@ -1171,23 +1127,21 @@ void* aaruf_open(const char* filepath)
if(ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength > 0) if(ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength > 0)
{ {
ctx->dumpHardwareEntriesWithData[e].manufacturer = ctx->dumpHardwareEntriesWithData[e].manufacturer =
(uint8_t*)malloc(ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength + 1); (uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength + 1);
if(ctx->dumpHardwareEntriesWithData[e].manufacturer != NULL) if(ctx->dumpHardwareEntriesWithData[e].manufacturer != NULL)
{ {
ctx->dumpHardwareEntriesWithData[e] ctx->dumpHardwareEntriesWithData[e]
.manufacturer[ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength] = 0; .manufacturer[ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength] = 0;
readBytes = fread(ctx->dumpHardwareEntriesWithData[e].manufacturer, readBytes =
1, fread(ctx->dumpHardwareEntriesWithData[e].manufacturer, 1,
ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength, ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength, ctx->imageStream);
ctx->imageStream);
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength) if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength)
{ {
free(ctx->dumpHardwareEntriesWithData[e].manufacturer); free(ctx->dumpHardwareEntriesWithData[e].manufacturer);
ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength = 0; ctx->dumpHardwareEntriesWithData[e].entry.manufacturerLength = 0;
fprintf(stderr, fprintf(stderr, "libaaruformat: Could not read dump hardware block entry manufacturer, "
"libaaruformat: Could not read dump hardware block entry manufacturer, "
"continuing...\n"); "continuing...\n");
} }
} }
@@ -1196,16 +1150,14 @@ void* aaruf_open(const char* filepath)
if(ctx->dumpHardwareEntriesWithData[e].entry.modelLength > 0) if(ctx->dumpHardwareEntriesWithData[e].entry.modelLength > 0)
{ {
ctx->dumpHardwareEntriesWithData[e].model = ctx->dumpHardwareEntriesWithData[e].model =
(uint8_t*)malloc(ctx->dumpHardwareEntriesWithData[e].entry.modelLength + 1); (uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.modelLength + 1);
if(ctx->dumpHardwareEntriesWithData[e].model != NULL) if(ctx->dumpHardwareEntriesWithData[e].model != NULL)
{ {
ctx->dumpHardwareEntriesWithData[e] ctx->dumpHardwareEntriesWithData[e]
.model[ctx->dumpHardwareEntriesWithData[e].entry.modelLength] = 0; .model[ctx->dumpHardwareEntriesWithData[e].entry.modelLength] = 0;
readBytes = fread(ctx->dumpHardwareEntriesWithData[e].model, readBytes = fread(ctx->dumpHardwareEntriesWithData[e].model, 1,
1, ctx->dumpHardwareEntriesWithData[e].entry.modelLength, ctx->imageStream);
ctx->dumpHardwareEntriesWithData[e].entry.modelLength,
ctx->imageStream);
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.modelLength) if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.modelLength)
{ {
@@ -1221,23 +1173,21 @@ void* aaruf_open(const char* filepath)
if(ctx->dumpHardwareEntriesWithData[e].entry.revisionLength > 0) if(ctx->dumpHardwareEntriesWithData[e].entry.revisionLength > 0)
{ {
ctx->dumpHardwareEntriesWithData[e].revision = ctx->dumpHardwareEntriesWithData[e].revision =
(uint8_t*)malloc(ctx->dumpHardwareEntriesWithData[e].entry.revisionLength + 1); (uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.revisionLength + 1);
if(ctx->dumpHardwareEntriesWithData[e].revision != NULL) if(ctx->dumpHardwareEntriesWithData[e].revision != NULL)
{ {
ctx->dumpHardwareEntriesWithData[e] ctx->dumpHardwareEntriesWithData[e]
.revision[ctx->dumpHardwareEntriesWithData[e].entry.revisionLength] = 0; .revision[ctx->dumpHardwareEntriesWithData[e].entry.revisionLength] = 0;
readBytes = fread(ctx->dumpHardwareEntriesWithData[e].revision, readBytes =
1, fread(ctx->dumpHardwareEntriesWithData[e].revision, 1,
ctx->dumpHardwareEntriesWithData[e].entry.revisionLength, ctx->dumpHardwareEntriesWithData[e].entry.revisionLength, ctx->imageStream);
ctx->imageStream);
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.revisionLength) if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.revisionLength)
{ {
free(ctx->dumpHardwareEntriesWithData[e].revision); free(ctx->dumpHardwareEntriesWithData[e].revision);
ctx->dumpHardwareEntriesWithData[e].entry.revisionLength = 0; ctx->dumpHardwareEntriesWithData[e].entry.revisionLength = 0;
fprintf(stderr, fprintf(stderr, "libaaruformat: Could not read dump hardware block entry revision, "
"libaaruformat: Could not read dump hardware block entry revision, "
"continuing...\n"); "continuing...\n");
} }
} }
@@ -1246,23 +1196,21 @@ void* aaruf_open(const char* filepath)
if(ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength > 0) if(ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength > 0)
{ {
ctx->dumpHardwareEntriesWithData[e].firmware = ctx->dumpHardwareEntriesWithData[e].firmware =
(uint8_t*)malloc(ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength + 1); (uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength + 1);
if(ctx->dumpHardwareEntriesWithData[e].firmware != NULL) if(ctx->dumpHardwareEntriesWithData[e].firmware != NULL)
{ {
ctx->dumpHardwareEntriesWithData[e] ctx->dumpHardwareEntriesWithData[e]
.firmware[ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength] = 0; .firmware[ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength] = 0;
readBytes = fread(ctx->dumpHardwareEntriesWithData[e].firmware, readBytes =
1, fread(ctx->dumpHardwareEntriesWithData[e].firmware, 1,
ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength, ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength, ctx->imageStream);
ctx->imageStream);
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength) if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength)
{ {
free(ctx->dumpHardwareEntriesWithData[e].firmware); free(ctx->dumpHardwareEntriesWithData[e].firmware);
ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength = 0; ctx->dumpHardwareEntriesWithData[e].entry.firmwareLength = 0;
fprintf(stderr, fprintf(stderr, "libaaruformat: Could not read dump hardware block entry firmware, "
"libaaruformat: Could not read dump hardware block entry firmware, "
"continuing...\n"); "continuing...\n");
} }
} }
@@ -1271,16 +1219,14 @@ void* aaruf_open(const char* filepath)
if(ctx->dumpHardwareEntriesWithData[e].entry.serialLength > 0) if(ctx->dumpHardwareEntriesWithData[e].entry.serialLength > 0)
{ {
ctx->dumpHardwareEntriesWithData[e].serial = ctx->dumpHardwareEntriesWithData[e].serial =
(uint8_t*)malloc(ctx->dumpHardwareEntriesWithData[e].entry.serialLength + 1); (uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.serialLength + 1);
if(ctx->dumpHardwareEntriesWithData[e].serial != NULL) if(ctx->dumpHardwareEntriesWithData[e].serial != NULL)
{ {
ctx->dumpHardwareEntriesWithData[e] ctx->dumpHardwareEntriesWithData[e]
.serial[ctx->dumpHardwareEntriesWithData[e].entry.serialLength] = 0; .serial[ctx->dumpHardwareEntriesWithData[e].entry.serialLength] = 0;
readBytes = fread(ctx->dumpHardwareEntriesWithData[e].serial, readBytes = fread(ctx->dumpHardwareEntriesWithData[e].serial, 1,
1, ctx->dumpHardwareEntriesWithData[e].entry.serialLength, ctx->imageStream);
ctx->dumpHardwareEntriesWithData[e].entry.serialLength,
ctx->imageStream);
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.serialLength) if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.serialLength)
{ {
@@ -1296,16 +1242,15 @@ void* aaruf_open(const char* filepath)
if(ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength > 0) if(ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength > 0)
{ {
ctx->dumpHardwareEntriesWithData[e].softwareName = ctx->dumpHardwareEntriesWithData[e].softwareName =
(uint8_t*)malloc(ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength + 1); (uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength + 1);
if(ctx->dumpHardwareEntriesWithData[e].softwareName != NULL) if(ctx->dumpHardwareEntriesWithData[e].softwareName != NULL)
{ {
ctx->dumpHardwareEntriesWithData[e] ctx->dumpHardwareEntriesWithData[e]
.softwareName[ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength] = 0; .softwareName[ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength] = 0;
readBytes = fread(ctx->dumpHardwareEntriesWithData[e].softwareName, readBytes =
1, fread(ctx->dumpHardwareEntriesWithData[e].softwareName, 1,
ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength, ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength, ctx->imageStream);
ctx->imageStream);
if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength) if(readBytes != ctx->dumpHardwareEntriesWithData[e].entry.softwareNameLength)
{ {
@@ -1321,14 +1266,13 @@ void* aaruf_open(const char* filepath)
if(ctx->dumpHardwareEntriesWithData[e].entry.softwareVersionLength > 0) if(ctx->dumpHardwareEntriesWithData[e].entry.softwareVersionLength > 0)
{ {
ctx->dumpHardwareEntriesWithData[e].softwareVersion = ctx->dumpHardwareEntriesWithData[e].softwareVersion =
(uint8_t*)malloc(ctx->dumpHardwareEntriesWithData[e].entry.softwareVersionLength + 1); (uint8_t *)malloc(ctx->dumpHardwareEntriesWithData[e].entry.softwareVersionLength + 1);
if(ctx->dumpHardwareEntriesWithData[e].softwareVersion != NULL) if(ctx->dumpHardwareEntriesWithData[e].softwareVersion != NULL)
{ {
ctx->dumpHardwareEntriesWithData[e] ctx->dumpHardwareEntriesWithData[e]
.softwareVersion[ctx->dumpHardwareEntriesWithData[e].entry.softwareVersionLength] = 0; .softwareVersion[ctx->dumpHardwareEntriesWithData[e].entry.softwareVersionLength] = 0;
readBytes = fread(ctx->dumpHardwareEntriesWithData[e].softwareVersion, readBytes = fread(ctx->dumpHardwareEntriesWithData[e].softwareVersion, 1,
1,
ctx->dumpHardwareEntriesWithData[e].entry.softwareVersionLength, ctx->dumpHardwareEntriesWithData[e].entry.softwareVersionLength,
ctx->imageStream); ctx->imageStream);
@@ -1345,15 +1289,14 @@ void* aaruf_open(const char* filepath)
if(ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength > 0) if(ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength > 0)
{ {
ctx->dumpHardwareEntriesWithData[e].softwareOperatingSystem = (uint8_t*)malloc( ctx->dumpHardwareEntriesWithData[e].softwareOperatingSystem = (uint8_t *)malloc(
ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength + 1); ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength + 1);
if(ctx->dumpHardwareEntriesWithData[e].softwareOperatingSystem != NULL) if(ctx->dumpHardwareEntriesWithData[e].softwareOperatingSystem != NULL)
{ {
ctx->dumpHardwareEntriesWithData[e].softwareOperatingSystem ctx->dumpHardwareEntriesWithData[e].softwareOperatingSystem
[ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength] = 0; [ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength] = 0;
readBytes = fread(ctx->dumpHardwareEntriesWithData[e].softwareOperatingSystem, readBytes = fread(ctx->dumpHardwareEntriesWithData[e].softwareOperatingSystem, 1,
1,
ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength, ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength,
ctx->imageStream); ctx->imageStream);
@@ -1361,28 +1304,24 @@ void* aaruf_open(const char* filepath)
{ {
free(ctx->dumpHardwareEntriesWithData[e].softwareOperatingSystem); free(ctx->dumpHardwareEntriesWithData[e].softwareOperatingSystem);
ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength = 0; ctx->dumpHardwareEntriesWithData[e].entry.softwareOperatingSystemLength = 0;
fprintf(stderr, fprintf(stderr, "libaaruformat: Could not read dump hardware block entry manufacturer, "
"libaaruformat: Could not read dump hardware block entry manufacturer, "
"continuing...\n"); "continuing...\n");
} }
} }
} }
ctx->dumpHardwareEntriesWithData[e].extents = ctx->dumpHardwareEntriesWithData[e].extents =
(DumpExtent*)malloc(sizeof(DumpExtent) * ctx->dumpHardwareEntriesWithData->entry.extents); (DumpExtent *)malloc(sizeof(DumpExtent) * ctx->dumpHardwareEntriesWithData->entry.extents);
if(ctx->dumpHardwareEntriesWithData[e].extents == NULL) if(ctx->dumpHardwareEntriesWithData[e].extents == NULL)
{ {
fprintf(stderr, fprintf(stderr, "libaaruformat: Could not allocate memory for dump hardware block extents, "
"libaaruformat: Could not allocate memory for dump hardware block extents, "
"continuing...\n"); "continuing...\n");
continue; continue;
} }
readBytes = fread(ctx->dumpHardwareEntriesWithData[e].extents, readBytes = fread(ctx->dumpHardwareEntriesWithData[e].extents, sizeof(DumpExtent),
sizeof(DumpExtent), ctx->dumpHardwareEntriesWithData[e].entry.extents, ctx->imageStream);
ctx->dumpHardwareEntriesWithData[e].entry.extents,
ctx->imageStream);
if(readBytes != ctx->dumpHardwareEntriesWithData->entry.extents) if(readBytes != ctx->dumpHardwareEntriesWithData->entry.extents)
{ {
@@ -1408,12 +1347,11 @@ void* aaruf_open(const char* filepath)
if(checksum_header.identifier != ChecksumBlock) if(checksum_header.identifier != ChecksumBlock)
{ {
memset(&checksum_header, 0, sizeof(ChecksumHeader)); memset(&checksum_header, 0, sizeof(ChecksumHeader));
fprintf(stderr, fprintf(stderr, "libaaruformat: Incorrect identifier for checksum block at position %" PRIu64 "\n",
"libaaruformat: Incorrect identifier for checksum block at position %" PRIu64 "\n",
idxEntries[i].offset); idxEntries[i].offset);
} }
data = (uint8_t*)malloc(checksum_header.length); data = (uint8_t *)malloc(checksum_header.length);
if(data == NULL) if(data == NULL)
{ {
@@ -1435,7 +1373,7 @@ void* aaruf_open(const char* filepath)
pos = 0; pos = 0;
for(j = 0; j < checksum_header.entries; j++) for(j = 0; j < checksum_header.entries; j++)
{ {
checksum_entry = (ChecksumEntry*)(&data[pos]); checksum_entry = (ChecksumEntry *)(&data[pos]);
pos += sizeof(ChecksumEntry); pos += sizeof(ChecksumEntry);
if(checksum_entry->type == Md5) if(checksum_entry->type == Md5)
@@ -1476,9 +1414,7 @@ void* aaruf_open(const char* filepath)
default: default:
fprintf(stderr, fprintf(stderr,
"libaaruformat: Unhandled block type %4.4s with data type %d is indexed to be at %" PRIu64 "\n", "libaaruformat: Unhandled block type %4.4s with data type %d is indexed to be at %" PRIu64 "\n",
(char*)&idxEntries[i].blockType, (char *)&idxEntries[i].blockType, idxEntries[i].dataType, idxEntries[i].offset);
idxEntries[i].dataType,
idxEntries[i].offset);
break; break;
} }
} }
@@ -1512,7 +1448,7 @@ void* aaruf_open(const char* filepath)
// TODO: Cache tracks and sessions? // TODO: Cache tracks and sessions?
// Initialize ECC for Compact Disc // Initialize ECC for Compact Disc
ctx->eccCdContext = (CdEccContext*)aaruf_ecc_cd_init(); ctx->eccCdContext = (CdEccContext *)aaruf_ecc_cd_init();
ctx->magic = AARU_MAGIC; ctx->magic = AARU_MAGIC;
ctx->libraryMajorVersion = LIBAARUFORMAT_MAJOR_VERSION; ctx->libraryMajorVersion = LIBAARUFORMAT_MAJOR_VERSION;

View File

@@ -21,10 +21,10 @@
#include <aaruformat.h> #include <aaruformat.h>
int32_t aaruf_read_media_tag(void* context, uint8_t* data, int32_t tag, uint32_t* length) int32_t aaruf_read_media_tag(void *context, uint8_t *data, int32_t tag, uint32_t *length)
{ {
aaruformatContext* ctx; aaruformatContext *ctx;
mediaTagEntry* item; mediaTagEntry *item;
if(context == NULL) return AARUF_ERROR_NOT_AARUFORMAT; if(context == NULL) return AARUF_ERROR_NOT_AARUFORMAT;
@@ -53,19 +53,19 @@ int32_t aaruf_read_media_tag(void* context, uint8_t* data, int32_t tag, uint32_t
return AARUF_STATUS_OK; return AARUF_STATUS_OK;
} }
int32_t aaruf_read_sector(void* context, uint64_t sectorAddress, uint8_t* data, uint32_t* length) int32_t aaruf_read_sector(void *context, uint64_t sectorAddress, uint8_t *data, uint32_t *length)
{ {
aaruformatContext* ctx; aaruformatContext *ctx;
uint64_t ddtEntry; uint64_t ddtEntry;
uint32_t offsetMask; uint32_t offsetMask;
uint64_t offset; uint64_t offset;
uint64_t blockOffset; uint64_t blockOffset;
BlockHeader* blockHeader; BlockHeader *blockHeader;
uint8_t* block; uint8_t *block;
size_t readBytes; size_t readBytes;
uint8_t lzmaProperties[LZMA_PROPERTIES_LENGTH]; uint8_t lzmaProperties[LZMA_PROPERTIES_LENGTH];
size_t lzmaSize; size_t lzmaSize;
uint8_t* cmpData; uint8_t *cmpData;
int errorNo; int errorNo;
if(context == NULL) return AARUF_ERROR_NOT_AARUFORMAT; if(context == NULL) return AARUF_ERROR_NOT_AARUFORMAT;
@@ -129,7 +129,7 @@ int32_t aaruf_read_sector(void* context, uint64_t sectorAddress, uint8_t* data,
switch(blockHeader->compression) switch(blockHeader->compression)
{ {
case None: case None:
block = (uint8_t*)malloc(blockHeader->length); block = (uint8_t *)malloc(blockHeader->length);
if(block == NULL) return AARUF_ERROR_NOT_ENOUGH_MEMORY; if(block == NULL) return AARUF_ERROR_NOT_ENOUGH_MEMORY;
readBytes = fread(block, 1, blockHeader->length, ctx->imageStream); readBytes = fread(block, 1, blockHeader->length, ctx->imageStream);
@@ -240,7 +240,8 @@ int32_t aaruf_read_sector(void* context, uint64_t sectorAddress, uint8_t* data,
free(cmpData); free(cmpData);
break; break;
default: return AARUF_ERROR_UNSUPPORTED_COMPRESSION; default:
return AARUF_ERROR_UNSUPPORTED_COMPRESSION;
} }
// Add block to cache // Add block to cache
@@ -251,9 +252,9 @@ int32_t aaruf_read_sector(void* context, uint64_t sectorAddress, uint8_t* data,
return AARUF_STATUS_OK; return AARUF_STATUS_OK;
} }
int32_t aaruf_read_track_sector(void* context, uint8_t* data, uint64_t sectorAddress, uint32_t* length, uint8_t track) int32_t aaruf_read_track_sector(void *context, uint8_t *data, uint64_t sectorAddress, uint32_t *length, uint8_t track)
{ {
aaruformatContext* ctx; aaruformatContext *ctx;
int i; int i;
if(context == NULL) return AARUF_ERROR_NOT_AARUFORMAT; if(context == NULL) return AARUF_ERROR_NOT_AARUFORMAT;
@@ -276,12 +277,12 @@ int32_t aaruf_read_track_sector(void* context, uint8_t* data, uint64_t sectorAdd
return AARUF_ERROR_TRACK_NOT_FOUND; return AARUF_ERROR_TRACK_NOT_FOUND;
} }
int32_t aaruf_read_sector_long(void* context, uint64_t sectorAddress, uint8_t* data, uint32_t* length) int32_t aaruf_read_sector_long(void *context, uint64_t sectorAddress, uint8_t *data, uint32_t *length)
{ {
aaruformatContext* ctx; aaruformatContext *ctx;
uint32_t bareLength; uint32_t bareLength;
uint32_t tagLength; uint32_t tagLength;
uint8_t* bareData; uint8_t *bareData;
int32_t res; int32_t res;
TrackEntry trk; TrackEntry trk;
int i; int i;
@@ -309,7 +310,7 @@ int32_t aaruf_read_sector_long(void* context, uint64_t sectorAddress, uint8_t* d
bareLength = 0; bareLength = 0;
aaruf_read_sector(context, sectorAddress, NULL, &bareLength); aaruf_read_sector(context, sectorAddress, NULL, &bareLength);
bareData = (uint8_t*)malloc(bareLength); bareData = (uint8_t *)malloc(bareLength);
if(bareData == NULL) return AARUF_ERROR_NOT_ENOUGH_MEMORY; if(bareData == NULL) return AARUF_ERROR_NOT_ENOUGH_MEMORY;
@@ -338,11 +339,14 @@ int32_t aaruf_read_sector_long(void* context, uint64_t sectorAddress, uint8_t* d
switch(trk.type) switch(trk.type)
{ {
case Audio: case Audio:
case Data: memcpy(data, bareData, bareLength); return res; case Data:
memcpy(data, bareData, bareLength);
return res;
case CdMode1: case CdMode1:
memcpy(data + 16, bareData, 2048); memcpy(data + 16, bareData, 2048);
if(ctx->sectorPrefix != NULL) memcpy(data, ctx->sectorPrefix + (sectorAddress * 16), 16); if(ctx->sectorPrefix != NULL)
memcpy(data, ctx->sectorPrefix + (sectorAddress * 16), 16);
else if(ctx->sectorPrefixDdt != NULL) else if(ctx->sectorPrefixDdt != NULL)
{ {
if((ctx->sectorPrefixDdt[sectorAddress] & CD_XFIX_MASK) == Correct) if((ctx->sectorPrefixDdt[sectorAddress] & CD_XFIX_MASK) == Correct)
@@ -367,7 +371,8 @@ int32_t aaruf_read_sector_long(void* context, uint64_t sectorAddress, uint8_t* d
if(res != AARUF_STATUS_OK) return res; if(res != AARUF_STATUS_OK) return res;
if(ctx->sectorSuffix != NULL) memcpy(data + 2064, ctx->sectorSuffix + sectorAddress * 288, 288); if(ctx->sectorSuffix != NULL)
memcpy(data + 2064, ctx->sectorSuffix + sectorAddress * 288, 288);
else if(ctx->sectorSuffixDdt != NULL) else if(ctx->sectorSuffixDdt != NULL)
{ {
if((ctx->sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) == Correct) if((ctx->sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) == Correct)
@@ -394,7 +399,8 @@ int32_t aaruf_read_sector_long(void* context, uint64_t sectorAddress, uint8_t* d
case CdMode2Formless: case CdMode2Formless:
case CdMode2Form1: case CdMode2Form1:
case CdMode2Form2: case CdMode2Form2:
if(ctx->sectorPrefix != NULL) memcpy(data, ctx->sectorPrefix + sectorAddress * 16, 16); if(ctx->sectorPrefix != NULL)
memcpy(data, ctx->sectorPrefix + sectorAddress * 16, 16);
else if(ctx->sectorPrefixDdt != NULL) else if(ctx->sectorPrefixDdt != NULL)
{ {
if((ctx->sectorPrefixDdt[sectorAddress] & CD_XFIX_MASK) == Correct) if((ctx->sectorPrefixDdt[sectorAddress] & CD_XFIX_MASK) == Correct)
@@ -452,7 +458,8 @@ int32_t aaruf_read_sector_long(void* context, uint64_t sectorAddress, uint8_t* d
memcpy(data + 16, bareData, 2336); memcpy(data + 16, bareData, 2336);
return res; return res;
default: return AARUF_ERROR_INVALID_TRACK_FORMAT; default:
return AARUF_ERROR_INVALID_TRACK_FORMAT;
} }
case BlockMedia: case BlockMedia:
switch(ctx->imageInfo.MediaType) switch(ctx->imageInfo.MediaType)
@@ -469,11 +476,18 @@ int32_t aaruf_read_sector_long(void* context, uint64_t sectorAddress, uint8_t* d
{ {
case AppleFileWare: case AppleFileWare:
case AppleProfile: case AppleProfile:
case AppleWidget: tagLength = 20; break; case AppleWidget:
tagLength = 20;
break;
case AppleSonySS: case AppleSonySS:
case AppleSonyDS: tagLength = 12; break; case AppleSonyDS:
case PriamDataTower: tagLength = 24; break; tagLength = 12;
default: return AARUF_ERROR_INCORRECT_MEDIA_TYPE; break;
case PriamDataTower:
tagLength = 24;
break;
default:
return AARUF_ERROR_INCORRECT_MEDIA_TYPE;
} }
bareLength = 512; bareLength = 512;
@@ -498,8 +512,10 @@ int32_t aaruf_read_sector_long(void* context, uint64_t sectorAddress, uint8_t* d
free(bareData); free(bareData);
return res; return res;
default: return AARUF_ERROR_INCORRECT_MEDIA_TYPE; default:
return AARUF_ERROR_INCORRECT_MEDIA_TYPE;
} }
default: return AARUF_ERROR_INCORRECT_MEDIA_TYPE; default:
return AARUF_ERROR_INCORRECT_MEDIA_TYPE;
} }
} }

View File

@@ -35,7 +35,7 @@
#endif #endif
static void cpuid(int info, unsigned* eax, unsigned* ebx, unsigned* ecx, unsigned* edx) static void cpuid(int info, unsigned *eax, unsigned *ebx, unsigned *ecx, unsigned *edx)
{ {
#ifdef _MSC_VER #ifdef _MSC_VER
unsigned int registers[4]; unsigned int registers[4];
@@ -58,7 +58,7 @@ static void cpuid(int info, unsigned* eax, unsigned* ebx, unsigned* ecx, unsigne
#endif #endif
} }
static void cpuidex(int info, int count, unsigned* eax, unsigned* ebx, unsigned* ecx, unsigned* edx) static void cpuidex(int info, int count, unsigned *eax, unsigned *ebx, unsigned *ecx, unsigned *edx)
{ {
#ifdef _MSC_VER #ifdef _MSC_VER
unsigned int registers[4]; unsigned int registers[4];

View File

@@ -34,9 +34,9 @@ static uint8_t b64[] = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x
0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76,
0x77, 0x78, 0x79, 0x7A, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F}; 0x77, 0x78, 0x79, 0x7A, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F};
AARU_EXPORT spamsum_ctx* AARU_CALL aaruf_spamsum_init(void) AARU_EXPORT spamsum_ctx *AARU_CALL aaruf_spamsum_init(void)
{ {
spamsum_ctx* ctx = (spamsum_ctx*)malloc(sizeof(spamsum_ctx)); spamsum_ctx *ctx = (spamsum_ctx *)malloc(sizeof(spamsum_ctx));
if(!ctx) return NULL; if(!ctx) return NULL;
memset(ctx, 0, sizeof(spamsum_ctx)); memset(ctx, 0, sizeof(spamsum_ctx));
@@ -48,7 +48,7 @@ AARU_EXPORT spamsum_ctx* AARU_CALL aaruf_spamsum_init(void)
return ctx; return ctx;
} }
AARU_EXPORT int AARU_CALL aaruf_spamsum_update(spamsum_ctx* ctx, const uint8_t* data, uint32_t len) AARU_EXPORT int AARU_CALL aaruf_spamsum_update(spamsum_ctx *ctx, const uint8_t *data, uint32_t len)
{ {
int i; int i;
if(!ctx || !data) return -1; if(!ctx || !data) return -1;
@@ -60,16 +60,16 @@ AARU_EXPORT int AARU_CALL aaruf_spamsum_update(spamsum_ctx* ctx, const uint8_t*
return 0; return 0;
} }
AARU_EXPORT void AARU_CALL aaruf_spamsum_free(spamsum_ctx* ctx) AARU_EXPORT void AARU_CALL aaruf_spamsum_free(spamsum_ctx *ctx)
{ {
if(ctx) free(ctx); if(ctx) free(ctx);
} }
#define ROLL_SUM(ctx) ((ctx)->roll.h1 + (ctx)->roll.h2 + (ctx)->roll.h3) #define ROLL_SUM(ctx) ((ctx)->roll.h1 + (ctx)->roll.h2 + (ctx)->roll.h3)
#define SUM_HASH(c, h) (((h)*HASH_PRIME) ^ (c)); #define SUM_HASH(c, h) (((h) * HASH_PRIME) ^ (c));
#define SSDEEP_BS(index) (MIN_BLOCKSIZE << (index)) #define SSDEEP_BS(index) (MIN_BLOCKSIZE << (index))
AARU_LOCAL inline void fuzzy_engine_step(spamsum_ctx* ctx, uint8_t c) AARU_LOCAL inline void fuzzy_engine_step(spamsum_ctx *ctx, uint8_t c)
{ {
uint32_t i; uint32_t i;
/* At each character we update the rolling hash and the normal hashes. /* At each character we update the rolling hash and the normal hashes.
@@ -122,7 +122,7 @@ AARU_LOCAL inline void fuzzy_engine_step(spamsum_ctx* ctx, uint8_t c)
} }
} }
AARU_LOCAL inline void roll_hash(spamsum_ctx* ctx, uint8_t c) AARU_LOCAL inline void roll_hash(spamsum_ctx *ctx, uint8_t c)
{ {
ctx->roll.h2 -= ctx->roll.h1; ctx->roll.h2 -= ctx->roll.h1;
ctx->roll.h2 += ROLLING_WINDOW * c; ctx->roll.h2 += ROLLING_WINDOW * c;
@@ -140,7 +140,7 @@ AARU_LOCAL inline void roll_hash(spamsum_ctx* ctx, uint8_t c)
ctx->roll.h3 ^= c; ctx->roll.h3 ^= c;
} }
AARU_LOCAL inline void fuzzy_try_reduce_blockhash(spamsum_ctx* ctx) AARU_LOCAL inline void fuzzy_try_reduce_blockhash(spamsum_ctx *ctx)
{ {
// assert(ctx->bh_start < ctx->bh_end); // assert(ctx->bh_start < ctx->bh_end);
@@ -160,7 +160,7 @@ AARU_LOCAL inline void fuzzy_try_reduce_blockhash(spamsum_ctx* ctx)
++ctx->bh_start; ++ctx->bh_start;
} }
AARU_LOCAL inline void fuzzy_try_fork_blockhash(spamsum_ctx* ctx) AARU_LOCAL inline void fuzzy_try_fork_blockhash(spamsum_ctx *ctx)
{ {
if(ctx->bh_end >= NUM_BLOCKHASHES) return; if(ctx->bh_end >= NUM_BLOCKHASHES) return;
@@ -176,7 +176,7 @@ AARU_LOCAL inline void fuzzy_try_fork_blockhash(spamsum_ctx* ctx)
++ctx->bh_end; ++ctx->bh_end;
} }
AARU_EXPORT int AARU_CALL aaruf_spamsum_final(spamsum_ctx* ctx, uint8_t* result) AARU_EXPORT int AARU_CALL aaruf_spamsum_final(spamsum_ctx *ctx, uint8_t *result)
{ {
uint32_t bi = ctx->bh_start; uint32_t bi = ctx->bh_start;
uint32_t h = ROLL_SUM(ctx); uint32_t h = ROLL_SUM(ctx);
@@ -206,7 +206,7 @@ AARU_EXPORT int AARU_CALL aaruf_spamsum_final(spamsum_ctx* ctx, uint8_t* result)
// assert(!(bi > 0 && ctx->bh[bi].d_len < SPAMSUM_LENGTH / 2)); // assert(!(bi > 0 && ctx->bh[bi].d_len < SPAMSUM_LENGTH / 2));
int i = snprintf((char*)result, (size_t)remain, "%lu:", (unsigned long)SSDEEP_BS(bi)); int i = snprintf((char *)result, (size_t)remain, "%lu:", (unsigned long)SSDEEP_BS(bi));
if(i <= 0) /* Maybe snprintf has set errno here? */ if(i <= 0) /* Maybe snprintf has set errno here? */
return -1; return -1;

View File

@@ -22,16 +22,16 @@
#define VERIFY_SIZE 1048576 #define VERIFY_SIZE 1048576
int32_t aaruf_verify_image(void* context) int32_t aaruf_verify_image(void *context)
{ {
aaruformatContext* ctx; aaruformatContext *ctx;
uint64_t crc64; uint64_t crc64;
int i; int i;
IndexHeader index_header; IndexHeader index_header;
IndexEntry* index_entries; IndexEntry *index_entries;
size_t read_bytes; size_t read_bytes;
void* buffer; void *buffer;
crc64_ctx* crc64_context; crc64_ctx *crc64_context;
BlockHeader block_header; BlockHeader block_header;
uint64_t verified_bytes; uint64_t verified_bytes;
DdtHeader ddt_header; DdtHeader ddt_header;
@@ -81,7 +81,7 @@ int32_t aaruf_verify_image(void* context)
return AARUF_ERROR_CANNOT_READ_INDEX; return AARUF_ERROR_CANNOT_READ_INDEX;
} }
crc64 = aaruf_crc64_data((const uint8_t*)index_entries, sizeof(IndexEntry) * index_header.entries); crc64 = aaruf_crc64_data((const uint8_t *)index_entries, sizeof(IndexEntry) * index_header.entries);
// Due to how C# wrote it, it is effectively reversed // Due to how C# wrote it, it is effectively reversed
if(ctx->header.imageMajorVersion <= AARUF_VERSION) crc64 = bswap_64(crc64); if(ctx->header.imageMajorVersion <= AARUF_VERSION) crc64 = bswap_64(crc64);
@@ -104,9 +104,7 @@ int32_t aaruf_verify_image(void* context)
for(i = 0; i < index_header.entries; i++) for(i = 0; i < index_header.entries; i++)
{ {
fprintf(stderr, fprintf(stderr, "Checking block with type %4.4s at position %" PRIu64 "\n", (char *)&index_entries[i].blockType,
"Checking block with type %4.4s at position %" PRIu64 "\n",
(char*)&index_entries[i].blockType,
index_entries[i].offset); index_entries[i].offset);
fseek(ctx->imageStream, index_entries[i].offset, SEEK_SET); fseek(ctx->imageStream, index_entries[i].offset, SEEK_SET);
@@ -233,7 +231,9 @@ int32_t aaruf_verify_image(void* context)
} }
break; break;
default: fprintf(stderr, "Ignoring block type %4.4s.\n", (char*)&index_entries[i].blockType); break; default:
fprintf(stderr, "Ignoring block type %4.4s.\n", (char *)&index_entries[i].blockType);
break;
} }
} }

View File

@@ -17,7 +17,7 @@
#define DIC_MAGIC 0x544D52464D434944 #define DIC_MAGIC 0x544D52464D434944
#define AARU_MAGIC 0x544D524655524141 #define AARU_MAGIC 0x544D524655524141
enum <uint> MediaType enum<uint> MediaType
{ {
Unknown = 0, Unknown = 0,
UnknownMO = 1, UnknownMO = 1,
@@ -590,14 +590,14 @@ enum <uint> MediaType
ODC5500R = 786 ODC5500R = 786
}; };
enum <ushort> CompressionType enum<ushort> CompressionType
{ {
None = 0, None = 0,
Lzma = 1, Lzma = 1,
Flac = 2 Flac = 2
}; };
enum <ushort> DataType enum<ushort> DataType
{ {
NoData = 0, NoData = 0,
UserData = 1, UserData = 1,
@@ -686,7 +686,7 @@ enum <ushort> DataType
BitstreamData = 84 BitstreamData = 84
}; };
enum <uint> BlockType enum<uint> BlockType
{ {
DataBlock = 0x4B4C4244, DataBlock = 0x4B4C4244,
DeDuplicationTable = 0X2A544444, DeDuplicationTable = 0X2A544444,
@@ -711,7 +711,7 @@ enum <uint> BlockType
TrackLayoutBlock = 0x594C4B54 TrackLayoutBlock = 0x594C4B54
}; };
enum <byte> TrackType enum<byte> TrackType
{ {
Audio = 0, Audio = 0,
Data = 1, Data = 1,
@@ -721,7 +721,7 @@ enum <byte> TrackType
CdMode2Form2 = 5 CdMode2Form2 = 5
}; };
enum <byte> ChecksumAlgorithm enum<byte> ChecksumAlgorithm
{ {
Invalid = 0, Invalid = 0,
Md5 = 1, Md5 = 1,
@@ -758,8 +758,8 @@ typedef struct
uint64 entries; uint64 entries;
uint64 cmpLength; uint64 cmpLength;
uint64 length; uint64 length;
uint64 cmpCrc64 <format=hex>; uint64 cmpCrc64<format = hex>;
uint64 crc64 <format=hex>; uint64 crc64<format = hex>;
} DdtHeader; } DdtHeader;
typedef struct typedef struct
@@ -779,8 +779,8 @@ typedef struct
uint64 entries; uint64 entries;
uint64 cmpLength; uint64 cmpLength;
uint64 length; uint64 length;
uint64 cmpCrc64 <format=hex>; uint64 cmpCrc64<format = hex>;
uint64 crc64 <format=hex>; uint64 crc64<format = hex>;
} Ddt2Header; } Ddt2Header;
typedef struct typedef struct
@@ -794,7 +794,7 @@ typedef struct
{ {
BlockType identifier; BlockType identifier;
ushort entries; ushort entries;
uint64 crc64 <format=hex>; uint64 crc64<format = hex>;
IndexEntry items[entries]; IndexEntry items[entries];
} Index; } Index;
@@ -802,7 +802,7 @@ typedef struct
{ {
BlockType identifier; BlockType identifier;
uint64 entries; uint64 entries;
uint64 crc64 <format=hex>; uint64 crc64<format = hex>;
IndexEntry items[entries]; IndexEntry items[entries];
} Index2; } Index2;
@@ -810,7 +810,7 @@ typedef struct
{ {
BlockType identifier; BlockType identifier;
uint64 entries; uint64 entries;
uint64 crc64 <format=hex>; uint64 crc64<format = hex>;
uint64 previous; uint64 previous;
IndexEntry items[entries]; IndexEntry items[entries];
} IndexContinuation; } IndexContinuation;
@@ -823,8 +823,8 @@ typedef struct
uint sectorSize; uint sectorSize;
uint cmpLength; uint cmpLength;
uint length; uint length;
uint64 cmpCrc64 <format=hex>; uint64 cmpCrc64<format = hex>;
uint64 crc64 <format=hex>; uint64 crc64<format = hex>;
} BlockHeader; } BlockHeader;
typedef struct typedef struct
@@ -927,19 +927,19 @@ typedef struct
BlockType identifier; BlockType identifier;
ushort entries; ushort entries;
uint length; uint length;
uint64 crc64 <format=hex>; uint64 crc64<format = hex>;
DumpHardwareEntry dumpHardware[entries]; DumpHardwareEntry dumpHardware[entries];
} DumpHardwareHeader <optimize=false>; } DumpHardwareHeader<optimize = false>;
typedef struct typedef struct
{ {
ChecksumAlgorithm type; ChecksumAlgorithm type;
uint length; uint length;
if(type == 4) if(type == 4)
char checksum[length] <format=hex>; char checksum[length]<format = hex>;
else else
byte checksum[length] <format=hex>; byte checksum[length]<format = hex>;
} ChecksumEntry <optimize=false>; } ChecksumEntry<optimize = false>;
typedef struct typedef struct
{ {
@@ -962,7 +962,7 @@ typedef struct
BlockType identifier; BlockType identifier;
uint entries; uint entries;
uint64 length; uint64 length;
uint64 crc64 <format=hex>; uint64 crc64<format = hex>;
TapeFileEntry files[entries]; TapeFileEntry files[entries];
} TapeFileHeader; } TapeFileHeader;
@@ -978,7 +978,7 @@ typedef struct
BlockType identifier; BlockType identifier;
byte entries; byte entries;
uint64 length; uint64 length;
uint64 crc64 <format=hex>; uint64 crc64<format = hex>;
TapePartitionEntry partitions[entries]; TapePartitionEntry partitions[entries];
} TapePartitionHeader; } TapePartitionHeader;
@@ -989,7 +989,7 @@ typedef struct
byte shift; byte shift;
uint64 entries; uint64 entries;
uint64 length; uint64 length;
uint64 crc64 <format=hex>; uint64 crc64<format = hex>;
uint64 pointers[entries]; uint64 pointers[entries];
} TwinSectorTable; } TwinSectorTable;
@@ -1023,7 +1023,7 @@ typedef struct
BlockType identifier; BlockType identifier;
uint16 entries; uint16 entries;
uint64 length; uint64 length;
uint64 crc64 <format=hex>; uint64 crc64<format = hex>;
CompactDiscIndexEntry indexes[entries]; CompactDiscIndexEntry indexes[entries];
} CompactDiscIndexesBlock; } CompactDiscIndexesBlock;
@@ -1040,7 +1040,7 @@ typedef struct
{ {
BlockType identifier; BlockType identifier;
uint16 entries; uint16 entries;
uint64 crc64 <format=hex>; uint64 crc64<format = hex>;
FluxDataEntry fluxes[entries]; FluxDataEntry fluxes[entries];
} FluxDataBlock; } FluxDataBlock;
@@ -1056,7 +1056,7 @@ typedef struct
{ {
BlockType identifier; BlockType identifier;
uint16 entries; uint16 entries;
uint64 crc64 <format=hex>; uint64 crc64<format = hex>;
BitstreamDataEntry bitstreams[entries]; BitstreamDataEntry bitstreams[entries];
} BitstreamDataBlock; } BitstreamDataBlock;
@@ -1069,7 +1069,7 @@ typedef struct
typedef struct typedef struct
{ {
BlockType identifier; BlockType identifier;
uint64 crc64 <format=hex>; uint64 crc64<format = hex>;
uint32 head; uint32 head;
uint16 track; uint16 track;
byte subtrack; byte subtrack;
@@ -1091,14 +1091,8 @@ FSeek(header.indexOffset);
local uint idxid = ReadUInt(); local uint idxid = ReadUInt();
FSeek(header.indexOffset); FSeek(header.indexOffset);
if(idxid == 0x32584449) if(idxid == 0x32584449) { Index2 index; }
{ else { Index index; }
Index2 index;
}
else
{
Index index;
}
for(i = 0; i < index.entries; i++) for(i = 0; i < index.entries; i++)
{ {

View File

@@ -2,9 +2,9 @@
#include <std/core.pat> #include <std/core.pat>
#include <std/mem.pat> #include <std/mem.pat>
#include <type/guid.pat>
#include <std/sys.pat>
#include <std/string.pat> #include <std/string.pat>
#include <std/sys.pat>
#include <type/guid.pat>
enum MediaType : u32 enum MediaType : u32
{ {
@@ -822,41 +822,29 @@ struct MetadataBlock
u32 driveFirmwareRevisionOffset; u32 driveFirmwareRevisionOffset;
u32 driveFirmwareRevisionLength; u32 driveFirmwareRevisionLength;
if(creatorLength > 0) if(creatorLength > 0) char16 creator[creatorLength];
char16 creator[creatorLength];
if(commentsLength > 0) if(commentsLength > 0) char16 comments[commentsLength];
char16 comments[commentsLength];
if(mediaTitleLength > 0) if(mediaTitleLength > 0) char16 mediaTitle[mediaTitleLength];
char16 mediaTitle[mediaTitleLength];
if(mediaManufacturerLength > 0) if(mediaManufacturerLength > 0) char16 mediaManufacturer[mediaManufacturerLength];
char16 mediaManufacturer[mediaManufacturerLength];
if(mediaModelLength > 0) if(mediaModelLength > 0) char16 mediaModel[mediaModelLength];
char16 mediaModel[mediaModelLength];
if(mediaSerialNumberLength > 0) if(mediaSerialNumberLength > 0) char16 mediaSerialNumber[mediaSerialNumberLength];
char16 mediaSerialNumber[mediaSerialNumberLength];
if(mediaBarcodeLength > 0) if(mediaBarcodeLength > 0) char16 mediaBarcode[mediaBarcodeLength];
char16 mediaBarcode[mediaBarcodeLength];
if(mediaPartNumberLength > 0) if(mediaPartNumberLength > 0) char16 mediaPartNumber[mediaPartNumberLength];
char16 mediaPartNumber[mediaPartNumberLength];
if(driveManufacturerLength > 0) if(driveManufacturerLength > 0) char16 driveManufacturer[driveManufacturerLength];
char16 driveManufacturer[driveManufacturerLength];
if(driveModelLength > 0) if(driveModelLength > 0) char16 driveModel[driveModelLength];
char16 driveModel[driveModelLength];
if(driveSerialNumberLength > 0) if(driveSerialNumberLength > 0) char16 driveSerialNumber[driveSerialNumberLength];
char16 driveSerialNumber[driveSerialNumberLength];
if(driveFirmwareRevisionLength > 0) if(driveFirmwareRevisionLength > 0) char16 driveFirmwareRevision[driveFirmwareRevisionLength];
char16 driveFirmwareRevision[driveFirmwareRevisionLength];
}; };
struct TrackEntry struct TrackEntry
@@ -942,29 +930,21 @@ struct DumpHardwareEntry
u32 softwareOperatingSystemLength; u32 softwareOperatingSystemLength;
u32 extents; u32 extents;
if(manufacturerLength > 0) if(manufacturerLength > 0) char manufacturer[manufacturerLength];
char manufacturer[manufacturerLength];
if(modelLength > 0) if(modelLength > 0) char model[modelLength];
char model[modelLength];
if(revisionLength > 0) if(revisionLength > 0) char revision[revisionLength];
char revision[revisionLength];
if(firmwareLength > 0) if(firmwareLength > 0) char firmware[firmwareLength];
char firmware[firmwareLength];
if(serialLength > 0) if(serialLength > 0) char serial[serialLength];
char serial[serialLength];
if(softwareNameLength > 0) if(softwareNameLength > 0) char name[softwareNameLength];
char name[softwareNameLength];
if(softwareVersionLength > 0) if(softwareVersionLength > 0) char version[softwareVersionLength];
char version[softwareVersionLength];
if(softwareOperatingSystemLength > 0) if(softwareOperatingSystemLength > 0) char operatingSystem[softwareOperatingSystemLength];
char operatingSystem[softwareOperatingSystemLength];
}; };
struct DumpHardwareBlock struct DumpHardwareBlock
@@ -1137,7 +1117,8 @@ struct Index
BlockType identifier; BlockType identifier;
std::assert(identifier == BlockType::Index || identifier == BlockType::Index2 || std::assert(identifier == BlockType::Index || identifier == BlockType::Index2 ||
identifier == BlockType::IndexContinuation, "Invalid index identifier!"); identifier == BlockType::IndexContinuation,
"Invalid index identifier!");
if(identifier == BlockType::Index2 || identifier == BlockType::IndexContinuation) if(identifier == BlockType::Index2 || identifier == BlockType::IndexContinuation)
u64 entries; u64 entries;
@@ -1172,4 +1153,4 @@ struct AaruHeader
} }
}; };
AaruHeader header @ 0x00; AaruHeader header @0x00;

View File

@@ -24,7 +24,7 @@ extern "C"
#define CRC32_ISO_POLY 0xEDB88320 #define CRC32_ISO_POLY 0xEDB88320
#define CRC32_ISO_SEED 0xFFFFFFFF #define CRC32_ISO_SEED 0xFFFFFFFF
uint32_t crc32_data(const uint8_t* data, uint32_t len) uint32_t crc32_data(const uint8_t *data, uint32_t len)
{ {
uint32_t localHashInt = CRC32_ISO_SEED; uint32_t localHashInt = CRC32_ISO_SEED;
uint32_t localTable[256]; uint32_t localTable[256];
@@ -35,7 +35,8 @@ extern "C"
uint32_t entry = (uint32_t)i; uint32_t entry = (uint32_t)i;
for(j = 0; j < 8; j++) for(j = 0; j < 8; j++)
if((entry & 1) == 1) entry = (entry >> 1) ^ CRC32_ISO_POLY; if((entry & 1) == 1)
entry = (entry >> 1) ^ CRC32_ISO_POLY;
else else
entry >>= 1; entry >>= 1;

View File

@@ -23,7 +23,7 @@ extern "C"
{ {
#endif #endif
uint32_t crc32_data(const uint8_t* data, uint32_t len); uint32_t crc32_data(const uint8_t *data, uint32_t len);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -29,19 +29,19 @@
#define EXPECTED_CRC64_63BYTES 0x29F331FC90702BF4 #define EXPECTED_CRC64_63BYTES 0x29F331FC90702BF4
#define EXPECTED_CRC64_2352BYTES 0x126435DB43477623 #define EXPECTED_CRC64_2352BYTES 0x126435DB43477623
static const uint8_t* buffer; static const uint8_t *buffer;
static const uint8_t* buffer_misaligned; static const uint8_t *buffer_misaligned;
class crc64Fixture : public ::testing::Test class crc64Fixture : public ::testing::Test
{ {
public: public:
crc64Fixture() crc64Fixture()
{ {
// initialization; // initialization;
// can also be done in SetUp() // can also be done in SetUp()
} }
protected: protected:
void SetUp() void SetUp()
{ {
char path[PATH_MAX]; char path[PATH_MAX];
@@ -50,19 +50,19 @@ class crc64Fixture : public ::testing::Test
getcwd(path, PATH_MAX); getcwd(path, PATH_MAX);
snprintf(filename, PATH_MAX, "%s/data/random", path); snprintf(filename, PATH_MAX, "%s/data/random", path);
FILE* file = fopen(filename, "rb"); FILE *file = fopen(filename, "rb");
buffer = (const uint8_t*)malloc(1048576); buffer = (const uint8_t *)malloc(1048576);
fread((void*)buffer, 1, 1048576, file); fread((void *)buffer, 1, 1048576, file);
fclose(file); fclose(file);
buffer_misaligned = (const uint8_t*)malloc(1048577); buffer_misaligned = (const uint8_t *)malloc(1048577);
memcpy((void*)(buffer_misaligned + 1), buffer, 1048576); memcpy((void *)(buffer_misaligned + 1), buffer, 1048576);
} }
void TearDown() void TearDown()
{ {
free((void*)buffer); free((void *)buffer);
free((void*)buffer_misaligned); free((void *)buffer_misaligned);
} }
~crc64Fixture() ~crc64Fixture()
@@ -75,7 +75,7 @@ class crc64Fixture : public ::testing::Test
TEST_F(crc64Fixture, crc64_auto) TEST_F(crc64Fixture, crc64_auto)
{ {
crc64_ctx* ctx = aaruf_crc64_init(); crc64_ctx *ctx = aaruf_crc64_init();
uint64_t crc; uint64_t crc;
EXPECT_NE(ctx, nullptr); EXPECT_NE(ctx, nullptr);
@@ -100,7 +100,7 @@ TEST_F(crc64Fixture, crc64_slicing)
TEST_F(crc64Fixture, crc64_auto_misaligned) TEST_F(crc64Fixture, crc64_auto_misaligned)
{ {
crc64_ctx* ctx = aaruf_crc64_init(); crc64_ctx *ctx = aaruf_crc64_init();
uint64_t crc; uint64_t crc;
EXPECT_NE(ctx, nullptr); EXPECT_NE(ctx, nullptr);
@@ -125,7 +125,7 @@ TEST_F(crc64Fixture, crc64_slicing_misaligned)
TEST_F(crc64Fixture, crc64_auto_15bytes) TEST_F(crc64Fixture, crc64_auto_15bytes)
{ {
crc64_ctx* ctx = aaruf_crc64_init(); crc64_ctx *ctx = aaruf_crc64_init();
uint64_t crc; uint64_t crc;
EXPECT_NE(ctx, nullptr); EXPECT_NE(ctx, nullptr);
@@ -150,7 +150,7 @@ TEST_F(crc64Fixture, crc64_slicing_15bytes)
TEST_F(crc64Fixture, crc64_auto_31bytes) TEST_F(crc64Fixture, crc64_auto_31bytes)
{ {
crc64_ctx* ctx = aaruf_crc64_init(); crc64_ctx *ctx = aaruf_crc64_init();
uint64_t crc; uint64_t crc;
EXPECT_NE(ctx, nullptr); EXPECT_NE(ctx, nullptr);
@@ -175,7 +175,7 @@ TEST_F(crc64Fixture, crc64_slicing_31bytes)
TEST_F(crc64Fixture, crc64_auto_63bytes) TEST_F(crc64Fixture, crc64_auto_63bytes)
{ {
crc64_ctx* ctx = aaruf_crc64_init(); crc64_ctx *ctx = aaruf_crc64_init();
uint64_t crc; uint64_t crc;
EXPECT_NE(ctx, nullptr); EXPECT_NE(ctx, nullptr);
@@ -200,7 +200,7 @@ TEST_F(crc64Fixture, crc64_slicing_63bytes)
TEST_F(crc64Fixture, crc64_auto_2352bytes) TEST_F(crc64Fixture, crc64_auto_2352bytes)
{ {
crc64_ctx* ctx = aaruf_crc64_init(); crc64_ctx *ctx = aaruf_crc64_init();
uint64_t crc; uint64_t crc;
EXPECT_NE(ctx, nullptr); EXPECT_NE(ctx, nullptr);

View File

@@ -28,18 +28,18 @@
#define EXPECTED_CRC32 0xdfbc99bb #define EXPECTED_CRC32 0xdfbc99bb
static const uint8_t* buffer; static const uint8_t *buffer;
class flacFixture : public ::testing::Test class flacFixture : public ::testing::Test
{ {
public: public:
flacFixture() flacFixture()
{ {
// initialization; // initialization;
// can also be done in SetUp() // can also be done in SetUp()
} }
protected: protected:
void SetUp() void SetUp()
{ {
char path[PATH_MAX]; char path[PATH_MAX];
@@ -48,13 +48,13 @@ class flacFixture : public ::testing::Test
getcwd(path, PATH_MAX); getcwd(path, PATH_MAX);
snprintf(filename, PATH_MAX, "%s/data/flac.flac", path); snprintf(filename, PATH_MAX, "%s/data/flac.flac", path);
FILE* file = fopen(filename, "rb"); FILE *file = fopen(filename, "rb");
buffer = (const uint8_t*)malloc(6534197); buffer = (const uint8_t *)malloc(6534197);
fread((void*)buffer, 1, 6534197, file); fread((void *)buffer, 1, 6534197, file);
fclose(file); fclose(file);
} }
void TearDown() { free((void*)buffer); } void TearDown() { free((void *)buffer); }
~flacFixture() ~flacFixture()
{ {
@@ -66,7 +66,7 @@ class flacFixture : public ::testing::Test
TEST_F(flacFixture, flac) TEST_F(flacFixture, flac)
{ {
auto* outBuf = (uint8_t*)malloc(9633792); auto *outBuf = (uint8_t *)malloc(9633792);
auto decoded = aaruf_flac_decode_redbook_buffer(outBuf, 9633792, buffer, 6534197); auto decoded = aaruf_flac_decode_redbook_buffer(outBuf, 9633792, buffer, 6534197);
@@ -86,46 +86,33 @@ TEST_F(flacFixture, flacCompress)
uint decmp_len = original_len; uint decmp_len = original_len;
char path[PATH_MAX]; char path[PATH_MAX];
char filename[PATH_MAX * 2]; char filename[PATH_MAX * 2];
FILE* file; FILE *file;
uint32_t original_crc, decmp_crc; uint32_t original_crc, decmp_crc;
const uint8_t* original; const uint8_t *original;
uint8_t* cmp_buffer; uint8_t *cmp_buffer;
uint8_t* decmp_buffer; uint8_t *decmp_buffer;
size_t newSize; size_t newSize;
// Allocate buffers // Allocate buffers
original = (const uint8_t*)malloc(original_len); original = (const uint8_t *)malloc(original_len);
cmp_buffer = (uint8_t*)malloc(cmp_len); cmp_buffer = (uint8_t *)malloc(cmp_len);
decmp_buffer = (uint8_t*)malloc(decmp_len); decmp_buffer = (uint8_t *)malloc(decmp_len);
// Read the file // Read the file
getcwd(path, PATH_MAX); getcwd(path, PATH_MAX);
snprintf(filename, PATH_MAX, "%s/data/audio.bin", path); snprintf(filename, PATH_MAX, "%s/data/audio.bin", path);
file = fopen(filename, "rb"); file = fopen(filename, "rb");
fread((void*)original, 1, original_len, file); fread((void *)original, 1, original_len, file);
fclose(file); fclose(file);
// Calculate the CRC // Calculate the CRC
original_crc = crc32_data(original, original_len); original_crc = crc32_data(original, original_len);
// Compress // Compress
newSize = aaruf_flac_encode_redbook_buffer(cmp_buffer, newSize = aaruf_flac_encode_redbook_buffer(
cmp_len, cmp_buffer, cmp_len, original, original_len, 4608, 1, 0, "partial_tukey(0/1.0/1.0)", 12, 0, 1, false, 0, 8,
original, "Aaru.Compression.Native.Tests", strlen("Aaru.Compression.Native.Tests"));
original_len,
4608,
1,
0,
"partial_tukey(0/1.0/1.0)",
12,
0,
1,
false,
0,
8,
"Aaru.Compression.Native.Tests",
strlen("Aaru.Compression.Native.Tests"));
cmp_len = newSize; cmp_len = newSize;
// Decompress // Decompress
@@ -137,7 +124,7 @@ TEST_F(flacFixture, flacCompress)
decmp_crc = crc32_data(decmp_buffer, decmp_len); decmp_crc = crc32_data(decmp_buffer, decmp_len);
// Free buffers // Free buffers
free((void*)original); free((void *)original);
free(cmp_buffer); free(cmp_buffer);
free(decmp_buffer); free(decmp_buffer);

View File

@@ -27,18 +27,18 @@
#define EXPECTED_CRC32 0x954bf76e #define EXPECTED_CRC32 0x954bf76e
static const uint8_t* buffer; static const uint8_t *buffer;
class lzmaFixture : public ::testing::Test class lzmaFixture : public ::testing::Test
{ {
public: public:
lzmaFixture() lzmaFixture()
{ {
// initialization; // initialization;
// can also be done in SetUp() // can also be done in SetUp()
} }
protected: protected:
void SetUp() void SetUp()
{ {
char path[PATH_MAX]; char path[PATH_MAX];
@@ -47,13 +47,13 @@ class lzmaFixture : public ::testing::Test
getcwd(path, PATH_MAX); getcwd(path, PATH_MAX);
snprintf(filename, PATH_MAX, "%s/data/lzma.bin", path); snprintf(filename, PATH_MAX, "%s/data/lzma.bin", path);
FILE* file = fopen(filename, "rb"); FILE *file = fopen(filename, "rb");
buffer = (const uint8_t*)malloc(1200275); buffer = (const uint8_t *)malloc(1200275);
fread((void*)buffer, 1, 1200275, file); fread((void *)buffer, 1, 1200275, file);
fclose(file); fclose(file);
} }
void TearDown() { free((void*)buffer); } void TearDown() { free((void *)buffer); }
~lzmaFixture() ~lzmaFixture()
{ {
@@ -68,7 +68,7 @@ TEST_F(lzmaFixture, lzma)
uint8_t params[] = {0x5D, 0x00, 0x00, 0x00, 0x02}; uint8_t params[] = {0x5D, 0x00, 0x00, 0x00, 0x02};
size_t destLen = 8388608; size_t destLen = 8388608;
size_t srcLen = 1200275; size_t srcLen = 1200275;
auto* outBuf = (uint8_t*)malloc(8388608); auto *outBuf = (uint8_t *)malloc(8388608);
auto err = aaruf_lzma_decode_buffer(outBuf, &destLen, buffer, &srcLen, params, 5); auto err = aaruf_lzma_decode_buffer(outBuf, &destLen, buffer, &srcLen, params, 5);
@@ -89,34 +89,34 @@ TEST_F(lzmaFixture, lzmaCompress)
size_t decmp_len = original_len; size_t decmp_len = original_len;
char path[PATH_MAX]; char path[PATH_MAX];
char filename[PATH_MAX * 2]; char filename[PATH_MAX * 2];
FILE* file; FILE *file;
uint32_t original_crc, decmp_crc; uint32_t original_crc, decmp_crc;
const uint8_t* original; const uint8_t *original;
uint8_t* cmp_buffer; uint8_t *cmp_buffer;
uint8_t* decmp_buffer; uint8_t *decmp_buffer;
int err; int err;
uint8_t props[5]; uint8_t props[5];
size_t props_len = 5; size_t props_len = 5;
// Allocate buffers // Allocate buffers
original = (const uint8_t*)malloc(original_len); original = (const uint8_t *)malloc(original_len);
cmp_buffer = (uint8_t*)malloc(cmp_len); cmp_buffer = (uint8_t *)malloc(cmp_len);
decmp_buffer = (uint8_t*)malloc(decmp_len); decmp_buffer = (uint8_t *)malloc(decmp_len);
// Read the file // Read the file
getcwd(path, PATH_MAX); getcwd(path, PATH_MAX);
snprintf(filename, PATH_MAX, "%s/data/data.bin", path); snprintf(filename, PATH_MAX, "%s/data/data.bin", path);
file = fopen(filename, "rb"); file = fopen(filename, "rb");
fread((void*)original, 1, original_len, file); fread((void *)original, 1, original_len, file);
fclose(file); fclose(file);
// Calculate the CRC // Calculate the CRC
original_crc = crc32_data(original, original_len); original_crc = crc32_data(original, original_len);
// Compress // Compress
err = aaruf_lzma_encode_buffer( err = aaruf_lzma_encode_buffer(cmp_buffer, &cmp_len, original, original_len, props, &props_len, 9, 1048576, 3, 0, 2,
cmp_buffer, &cmp_len, original, original_len, props, &props_len, 9, 1048576, 3, 0, 2, 273, 2); 273, 2);
EXPECT_EQ(err, 0); EXPECT_EQ(err, 0);
// Decompress // Decompress
@@ -128,7 +128,7 @@ TEST_F(lzmaFixture, lzmaCompress)
decmp_crc = crc32_data(decmp_buffer, decmp_len); decmp_crc = crc32_data(decmp_buffer, decmp_len);
// Free buffers // Free buffers
free((void*)original); free((void *)original);
free(cmp_buffer); free(cmp_buffer);
free(decmp_buffer); free(decmp_buffer);

View File

@@ -18,13 +18,13 @@
#ifdef AARU_HAS_SHA256 #ifdef AARU_HAS_SHA256
#include <openssl/sha.h>
#include <climits> #include <climits>
#include <cstdint> #include <cstdint>
#include <openssl/sha.h>
#include "gtest/gtest.h" #include "gtest/gtest.h"
static const uint8_t* buffer; static const uint8_t *buffer;
unsigned char expected_sha256[SHA256_DIGEST_LENGTH] = {0x4d, 0x1a, 0x6b, 0x8a, 0x54, 0x67, 0x00, 0xc4, 0x8e, 0xda, 0x70, unsigned char expected_sha256[SHA256_DIGEST_LENGTH] = {0x4d, 0x1a, 0x6b, 0x8a, 0x54, 0x67, 0x00, 0xc4, 0x8e, 0xda, 0x70,
0xd3, 0x39, 0x1c, 0x8f, 0x15, 0x8a, 0x8d, 0x12, 0xb2, 0x38, 0x92, 0xd3, 0x39, 0x1c, 0x8f, 0x15, 0x8a, 0x8d, 0x12, 0xb2, 0x38, 0x92,
@@ -32,14 +32,14 @@ unsigned char expected_sha256[SHA256_DIGEST_LENGTH] = {0x4d, 0x1a, 0x6b, 0x8a, 0
class sha256Fixture : public ::testing::Test class sha256Fixture : public ::testing::Test
{ {
public: public:
sha256Fixture() sha256Fixture()
{ {
// initialization; // initialization;
// can also be done in SetUp() // can also be done in SetUp()
} }
protected: protected:
void SetUp() void SetUp()
{ {
char path[PATH_MAX]; char path[PATH_MAX];
@@ -48,13 +48,13 @@ class sha256Fixture : public ::testing::Test
getcwd(path, PATH_MAX); getcwd(path, PATH_MAX);
snprintf(filename, PATH_MAX, "%s/data/random", path); snprintf(filename, PATH_MAX, "%s/data/random", path);
FILE* file = fopen(filename, "rb"); FILE *file = fopen(filename, "rb");
buffer = (const uint8_t*)malloc(1048576); buffer = (const uint8_t *)malloc(1048576);
fread((void*)buffer, 1, 1048576, file); fread((void *)buffer, 1, 1048576, file);
fclose(file); fclose(file);
} }
void TearDown() { free((void*)buffer); } void TearDown() { free((void *)buffer); }
~sha256Fixture() ~sha256Fixture()
{ {
@@ -66,18 +66,18 @@ class sha256Fixture : public ::testing::Test
#define EXPECT_ARRAY_EQ(reference, actual, element_count) \ #define EXPECT_ARRAY_EQ(reference, actual, element_count) \
{ \ { \
unsigned char* reference_ = static_cast<unsigned char*>(reference); \ unsigned char *reference_ = static_cast<unsigned char *>(reference); \
unsigned char* actual_ = static_cast<unsigned char*>(actual); \ unsigned char *actual_ = static_cast<unsigned char *>(actual); \
for(int cmp_i = 0; cmp_i < (element_count); cmp_i++) { EXPECT_EQ(reference_[cmp_i], actual_[cmp_i]); } \ for(int cmp_i = 0; cmp_i < (element_count); cmp_i++) { EXPECT_EQ(reference_[cmp_i], actual_[cmp_i]); } \
} }
TEST_F(sha256Fixture, sha256) TEST_F(sha256Fixture, sha256)
{ {
SHA256_CTX* ctx; SHA256_CTX *ctx;
unsigned char hash[SHA256_DIGEST_LENGTH]; unsigned char hash[SHA256_DIGEST_LENGTH];
int ret; int ret;
ctx = static_cast<SHA256_CTX*>(malloc(sizeof(SHA256_CTX))); ctx = static_cast<SHA256_CTX *>(malloc(sizeof(SHA256_CTX)));
EXPECT_NE(nullptr, ctx); EXPECT_NE(nullptr, ctx);

View File

@@ -29,19 +29,19 @@
#define EXPECTED_SPAMSUM_63BYTES "3:Ac4E9E5+S09q2kABV9:Ac4E9EgSs7kW9" #define EXPECTED_SPAMSUM_63BYTES "3:Ac4E9E5+S09q2kABV9:Ac4E9EgSs7kW9"
#define EXPECTED_SPAMSUM_2352BYTES "48:pasCLoANDXmjCz1p2OpPm+Gek3xmZfJJ5DD4BacmmlodQMQa/58Z:csK1Nxz7XFGeJS/flHMQu2Z" #define EXPECTED_SPAMSUM_2352BYTES "48:pasCLoANDXmjCz1p2OpPm+Gek3xmZfJJ5DD4BacmmlodQMQa/58Z:csK1Nxz7XFGeJS/flHMQu2Z"
static const uint8_t* buffer; static const uint8_t *buffer;
static const uint8_t* buffer_misaligned; static const uint8_t *buffer_misaligned;
class spamsumFixture : public ::testing::Test class spamsumFixture : public ::testing::Test
{ {
public: public:
spamsumFixture() spamsumFixture()
{ {
// initialization; // initialization;
// can also be done in SetUp() // can also be done in SetUp()
} }
protected: protected:
void SetUp() void SetUp()
{ {
char path[PATH_MAX]; char path[PATH_MAX];
@@ -50,19 +50,19 @@ class spamsumFixture : public ::testing::Test
getcwd(path, PATH_MAX); getcwd(path, PATH_MAX);
snprintf(filename, PATH_MAX, "%s/data/random", path); snprintf(filename, PATH_MAX, "%s/data/random", path);
FILE* file = fopen(filename, "rb"); FILE *file = fopen(filename, "rb");
buffer = (const uint8_t*)malloc(1048576); buffer = (const uint8_t *)malloc(1048576);
fread((void*)buffer, 1, 1048576, file); fread((void *)buffer, 1, 1048576, file);
fclose(file); fclose(file);
buffer_misaligned = (const uint8_t*)malloc(1048577); buffer_misaligned = (const uint8_t *)malloc(1048577);
memcpy((void*)(buffer_misaligned + 1), buffer, 1048576); memcpy((void *)(buffer_misaligned + 1), buffer, 1048576);
} }
void TearDown() void TearDown()
{ {
free((void*)buffer); free((void *)buffer);
free((void*)buffer_misaligned); free((void *)buffer_misaligned);
} }
~spamsumFixture() ~spamsumFixture()
@@ -75,102 +75,102 @@ class spamsumFixture : public ::testing::Test
TEST_F(spamsumFixture, spamsum_auto) TEST_F(spamsumFixture, spamsum_auto)
{ {
spamsum_ctx* ctx = aaruf_spamsum_init(); spamsum_ctx *ctx = aaruf_spamsum_init();
const char* spamsum = (const char*)malloc(FUZZY_MAX_RESULT); const char *spamsum = (const char *)malloc(FUZZY_MAX_RESULT);
EXPECT_NE(ctx, nullptr); EXPECT_NE(ctx, nullptr);
EXPECT_NE(spamsum, nullptr); EXPECT_NE(spamsum, nullptr);
aaruf_spamsum_update(ctx, buffer, 1048576); aaruf_spamsum_update(ctx, buffer, 1048576);
aaruf_spamsum_final(ctx, (uint8_t*)spamsum); aaruf_spamsum_final(ctx, (uint8_t *)spamsum);
aaruf_spamsum_free(ctx); aaruf_spamsum_free(ctx);
EXPECT_STREQ(spamsum, EXPECTED_SPAMSUM); EXPECT_STREQ(spamsum, EXPECTED_SPAMSUM);
free((void*)spamsum); free((void *)spamsum);
} }
TEST_F(spamsumFixture, spamsum_auto_misaligned) TEST_F(spamsumFixture, spamsum_auto_misaligned)
{ {
spamsum_ctx* ctx = aaruf_spamsum_init(); spamsum_ctx *ctx = aaruf_spamsum_init();
const char* spamsum = (const char*)malloc(FUZZY_MAX_RESULT); const char *spamsum = (const char *)malloc(FUZZY_MAX_RESULT);
EXPECT_NE(ctx, nullptr); EXPECT_NE(ctx, nullptr);
EXPECT_NE(spamsum, nullptr); EXPECT_NE(spamsum, nullptr);
aaruf_spamsum_update(ctx, buffer_misaligned + 1, 1048576); aaruf_spamsum_update(ctx, buffer_misaligned + 1, 1048576);
aaruf_spamsum_final(ctx, (uint8_t*)spamsum); aaruf_spamsum_final(ctx, (uint8_t *)spamsum);
aaruf_spamsum_free(ctx); aaruf_spamsum_free(ctx);
EXPECT_STREQ(spamsum, EXPECTED_SPAMSUM); EXPECT_STREQ(spamsum, EXPECTED_SPAMSUM);
free((void*)spamsum); free((void *)spamsum);
} }
TEST_F(spamsumFixture, spamsum_auto_15bytes) TEST_F(spamsumFixture, spamsum_auto_15bytes)
{ {
spamsum_ctx* ctx = aaruf_spamsum_init(); spamsum_ctx *ctx = aaruf_spamsum_init();
const char* spamsum = (const char*)malloc(FUZZY_MAX_RESULT); const char *spamsum = (const char *)malloc(FUZZY_MAX_RESULT);
EXPECT_NE(ctx, nullptr); EXPECT_NE(ctx, nullptr);
EXPECT_NE(spamsum, nullptr); EXPECT_NE(spamsum, nullptr);
aaruf_spamsum_update(ctx, buffer, 15); aaruf_spamsum_update(ctx, buffer, 15);
aaruf_spamsum_final(ctx, (uint8_t*)spamsum); aaruf_spamsum_final(ctx, (uint8_t *)spamsum);
aaruf_spamsum_free(ctx); aaruf_spamsum_free(ctx);
EXPECT_STREQ(spamsum, EXPECTED_SPAMSUM_15BYTES); EXPECT_STREQ(spamsum, EXPECTED_SPAMSUM_15BYTES);
free((void*)spamsum); free((void *)spamsum);
} }
TEST_F(spamsumFixture, spamsum_auto_31bytes) TEST_F(spamsumFixture, spamsum_auto_31bytes)
{ {
spamsum_ctx* ctx = aaruf_spamsum_init(); spamsum_ctx *ctx = aaruf_spamsum_init();
const char* spamsum = (const char*)malloc(FUZZY_MAX_RESULT); const char *spamsum = (const char *)malloc(FUZZY_MAX_RESULT);
EXPECT_NE(ctx, nullptr); EXPECT_NE(ctx, nullptr);
EXPECT_NE(spamsum, nullptr); EXPECT_NE(spamsum, nullptr);
aaruf_spamsum_update(ctx, buffer, 31); aaruf_spamsum_update(ctx, buffer, 31);
aaruf_spamsum_final(ctx, (uint8_t*)spamsum); aaruf_spamsum_final(ctx, (uint8_t *)spamsum);
aaruf_spamsum_free(ctx); aaruf_spamsum_free(ctx);
EXPECT_STREQ(spamsum, EXPECTED_SPAMSUM_31BYTES); EXPECT_STREQ(spamsum, EXPECTED_SPAMSUM_31BYTES);
free((void*)spamsum); free((void *)spamsum);
} }
TEST_F(spamsumFixture, spamsum_auto_63bytes) TEST_F(spamsumFixture, spamsum_auto_63bytes)
{ {
spamsum_ctx* ctx = aaruf_spamsum_init(); spamsum_ctx *ctx = aaruf_spamsum_init();
const char* spamsum = (const char*)malloc(FUZZY_MAX_RESULT); const char *spamsum = (const char *)malloc(FUZZY_MAX_RESULT);
EXPECT_NE(ctx, nullptr); EXPECT_NE(ctx, nullptr);
EXPECT_NE(spamsum, nullptr); EXPECT_NE(spamsum, nullptr);
aaruf_spamsum_update(ctx, buffer, 63); aaruf_spamsum_update(ctx, buffer, 63);
aaruf_spamsum_final(ctx, (uint8_t*)spamsum); aaruf_spamsum_final(ctx, (uint8_t *)spamsum);
aaruf_spamsum_free(ctx); aaruf_spamsum_free(ctx);
EXPECT_STREQ(spamsum, EXPECTED_SPAMSUM_63BYTES); EXPECT_STREQ(spamsum, EXPECTED_SPAMSUM_63BYTES);
free((void*)spamsum); free((void *)spamsum);
} }
TEST_F(spamsumFixture, spamsum_auto_2352bytes) TEST_F(spamsumFixture, spamsum_auto_2352bytes)
{ {
spamsum_ctx* ctx = aaruf_spamsum_init(); spamsum_ctx *ctx = aaruf_spamsum_init();
const char* spamsum = (const char*)malloc(FUZZY_MAX_RESULT); const char *spamsum = (const char *)malloc(FUZZY_MAX_RESULT);
EXPECT_NE(ctx, nullptr); EXPECT_NE(ctx, nullptr);
EXPECT_NE(spamsum, nullptr); EXPECT_NE(spamsum, nullptr);
aaruf_spamsum_update(ctx, buffer, 2352); aaruf_spamsum_update(ctx, buffer, 2352);
aaruf_spamsum_final(ctx, (uint8_t*)spamsum); aaruf_spamsum_final(ctx, (uint8_t *)spamsum);
aaruf_spamsum_free(ctx); aaruf_spamsum_free(ctx);
EXPECT_STREQ(spamsum, EXPECTED_SPAMSUM_2352BYTES); EXPECT_STREQ(spamsum, EXPECTED_SPAMSUM_2352BYTES);
free((void*)spamsum); free((void *)spamsum);
} }

View File

@@ -23,22 +23,15 @@
#include <aaruformat.h> #include <aaruformat.h>
int identify(char* path); int identify(char *path);
int info(char* path); int info(char *path);
char* byte_array_to_hex_string(const unsigned char* array, int array_size); char *byte_array_to_hex_string(const unsigned char *array, int array_size);
int read(unsigned long long sector_no, char* path); int read(unsigned long long sector_no, char *path);
int printhex(unsigned char* array, unsigned int length, int width, bool color); int printhex(unsigned char *array, unsigned int length, int width, bool color);
int read_long(unsigned long long sector_no, char* path); int read_long(unsigned long long sector_no, char *path);
int verify(char* path); int verify(char *path);
int verify_sectors(char* path); int verify_sectors(char *path);
bool check_cd_sector_channel(CdEccContext* context, bool check_cd_sector_channel(CdEccContext *context, uint8_t *sector, bool *unknown, bool *has_edc, bool *edc_correct,
uint8_t* sector, bool *has_ecc_p, bool *ecc_p_correct, bool *has_ecc_q, bool *ecc_q_correct);
bool* unknown,
bool* has_edc,
bool* edc_correct,
bool* has_ecc_p,
bool* ecc_p_correct,
bool* has_ecc_q,
bool* ecc_q_correct);
#endif // LIBAARUFORMAT_TOOL_AARUFORMATTOOL_H_ #endif // LIBAARUFORMAT_TOOL_AARUFORMATTOOL_H_

View File

@@ -22,15 +22,8 @@
#include <aaruformat.h> #include <aaruformat.h>
bool check_cd_sector_channel(CdEccContext* context, bool check_cd_sector_channel(CdEccContext *context, uint8_t *sector, bool *unknown, bool *has_edc, bool *edc_correct,
uint8_t* sector, bool *has_ecc_p, bool *ecc_p_correct, bool *has_ecc_q, bool *ecc_q_correct)
bool* unknown,
bool* has_edc,
bool* edc_correct,
bool* has_ecc_p,
bool* ecc_p_correct,
bool* has_ecc_q,
bool* ecc_q_correct)
{ {
int i; int i;
uint32_t storedEdc, edc, calculatedEdc; uint32_t storedEdc, edc, calculatedEdc;
@@ -58,10 +51,7 @@ bool check_cd_sector_channel(CdEccContext* context,
for(i = 0x010; i < 0x930; i++) for(i = 0x010; i < 0x930; i++)
if(sector[i] != 0x00) if(sector[i] != 0x00)
{ {
fprintf(stderr, fprintf(stderr, "Mode 0 sector with error at address: %2X:%2X:%2X.\n", sector[0x00C], sector[0x00D],
"Mode 0 sector with error at address: %2X:%2X:%2X.\n",
sector[0x00C],
sector[0x00D],
sector[0x00E]); sector[0x00E]);
return false; return false;
} }
@@ -76,11 +66,8 @@ bool check_cd_sector_channel(CdEccContext* context,
sector[0x815] != 0x00 || sector[0x816] != 0x00 || sector[0x817] != 0x00 || sector[0x818] != 0x00 || sector[0x815] != 0x00 || sector[0x816] != 0x00 || sector[0x817] != 0x00 || sector[0x818] != 0x00 ||
sector[0x819] != 0x00 || sector[0x81A] != 0x00 || sector[0x81B] != 0x00) sector[0x819] != 0x00 || sector[0x81A] != 0x00 || sector[0x81B] != 0x00)
{ {
fprintf(stderr, fprintf(stderr, "Mode 1 with data in reserved bytes at address: %2X:%2X:%2X.\n", sector[0x00C],
"Mode 1 with data in reserved bytes at address: %2X:%2X:%2X.\n", sector[0x00D], sector[0x00E]);
sector[0x00C],
sector[0x00D],
sector[0x00E]);
return false; return false;
} }
@@ -91,8 +78,8 @@ bool check_cd_sector_channel(CdEccContext* context,
*ecc_p_correct = aaruf_ecc_cd_check(context, sector, sector, 86, 24, 2, 86, sector, 0xC, 0x10, 0x81C); *ecc_p_correct = aaruf_ecc_cd_check(context, sector, sector, 86, 24, 2, 86, sector, 0xC, 0x10, 0x81C);
*ecc_q_correct = aaruf_ecc_cd_check(context, sector, sector, 52, 43, 86, 88, sector, 0xC, 0x10, 0x81C + 0xAC); *ecc_q_correct = aaruf_ecc_cd_check(context, sector, sector, 52, 43, 86, 88, sector, 0xC, 0x10, 0x81C + 0xAC);
storedEdc = storedEdc = (sector[0x813] << 24) + (sector[0x812] << 16) + (sector[0x811] << 8) +
(sector[0x813] << 24) + (sector[0x812] << 16) + (sector[0x811] << 8) + sector[0x810]; // TODO: Check casting sector[0x810]; // TODO: Check casting
edc = 0; edc = 0;
size = 0x810; size = 0x810;
pos = 0; pos = 0;
@@ -103,30 +90,19 @@ bool check_cd_sector_channel(CdEccContext* context,
if(!*edc_correct) if(!*edc_correct)
{ {
fprintf(stderr, fprintf(stderr, "Mode 1 sector at address: %2X:%2X:%2X, got CRC 0x%8X expected 0x%8X\n", sector[0x00C],
"Mode 1 sector at address: %2X:%2X:%2X, got CRC 0x%8X expected 0x%8X\n", sector[0x00D], sector[0x00E], calculatedEdc, storedEdc);
sector[0x00C],
sector[0x00D],
sector[0x00E],
calculatedEdc,
storedEdc);
} }
if(!*ecc_p_correct) if(!*ecc_p_correct)
{ {
fprintf(stderr, fprintf(stderr, "Mode 1 sector at address: %2X:%2X:%2X, fails ECC P check.\n", sector[0x00C], sector[0x00D],
"Mode 1 sector at address: %2X:%2X:%2X, fails ECC P check.\n",
sector[0x00C],
sector[0x00D],
sector[0x00E]); sector[0x00E]);
} }
if(!*ecc_q_correct) if(!*ecc_q_correct)
{ {
fprintf(stderr, fprintf(stderr, "Mode 1 sector at address: %2X:%2X:%2X, fails ECC Q check.\n", sector[0x00C], sector[0x00D],
"Mode 1 sector at address: %2X:%2X:%2X, fails ECC Q check.\n",
sector[0x00C],
sector[0x00D],
sector[0x00E]); sector[0x00E]);
} }
@@ -139,11 +115,8 @@ bool check_cd_sector_channel(CdEccContext* context,
{ {
if(sector[0x010] != sector[0x014] || sector[0x011] != sector[0x015] || sector[0x012] != sector[0x016] || if(sector[0x010] != sector[0x014] || sector[0x011] != sector[0x015] || sector[0x012] != sector[0x016] ||
sector[0x013] != sector[0x017]) sector[0x013] != sector[0x017])
fprintf(stderr, fprintf(stderr, "Subheader copies differ in mode 2 form 2 sector at address: %2X:%2X:%2X",
"Subheader copies differ in mode 2 form 2 sector at address: %2X:%2X:%2X", sector[0x00C], sector[0x00D], sector[0x00E]);
sector[0x00C],
sector[0x00D],
sector[0x00E]);
storedEdc = sector[0x91C]; storedEdc = sector[0x91C];
@@ -162,13 +135,8 @@ bool check_cd_sector_channel(CdEccContext* context,
if(!*edc_correct) if(!*edc_correct)
{ {
fprintf(stderr, fprintf(stderr, "Mode 2 sector at address: %2X:%2X:%2X, got CRC 0x%8X expected 0x%8X\n", sector[0x00C],
"Mode 2 sector at address: %2X:%2X:%2X, got CRC 0x%8X expected 0x%8X\n", sector[0x00D], sector[0x00E], calculatedEdc, storedEdc);
sector[0x00C],
sector[0x00D],
sector[0x00E],
calculatedEdc,
storedEdc);
} }
return *edc_correct; return *edc_correct;
@@ -190,41 +158,26 @@ bool check_cd_sector_channel(CdEccContext* context,
if(!*edc_correct) if(!*edc_correct)
{ {
fprintf(stderr, fprintf(stderr, "Mode 2 sector at address: %2X:%2X:%2X, got CRC 0x%8X expected 0x%8X\n", sector[0x00C],
"Mode 2 sector at address: %2X:%2X:%2X, got CRC 0x%8X expected 0x%8X\n", sector[0x00D], sector[0x00E], calculatedEdc, storedEdc);
sector[0x00C],
sector[0x00D],
sector[0x00E],
calculatedEdc,
storedEdc);
} }
if(!*ecc_p_correct) if(!*ecc_p_correct)
{ {
fprintf(stderr, fprintf(stderr, "Mode 2 sector at address: %2X:%2X:%2X, fails ECC P check.\n", sector[0x00C], sector[0x00D],
"Mode 2 sector at address: %2X:%2X:%2X, fails ECC P check.\n",
sector[0x00C],
sector[0x00D],
sector[0x00E]); sector[0x00E]);
} }
if(!*ecc_q_correct) if(!*ecc_q_correct)
{ {
fprintf(stderr, fprintf(stderr, "Mode 2 sector at address: %2X:%2X:%2X, fails ECC Q check.\n", sector[0x00C], sector[0x00D],
"Mode 2 sector at address: %2X:%2X:%2X, fails ECC Q check.\n",
sector[0x00C],
sector[0x00D],
sector[0x00E]); sector[0x00E]);
} }
return *edc_correct && *ecc_p_correct && *ecc_q_correct; return *edc_correct && *ecc_p_correct && *ecc_q_correct;
} }
fprintf(stderr, fprintf(stderr, "Unknown mode %d sector at address: %2X:%2X:%2X", sector[0x00F], sector[0x00C], sector[0x00D],
"Unknown mode %d sector at address: %2X:%2X:%2X",
sector[0x00F],
sector[0x00C],
sector[0x00D],
sector[0x00E]); sector[0x00E]);
return false; return false;

View File

@@ -22,9 +22,9 @@
#include "aaruformattool.h" #include "aaruformattool.h"
char* byte_array_to_hex_string(const unsigned char* array, int array_size) char *byte_array_to_hex_string(const unsigned char *array, int array_size)
{ {
char* hex_string = NULL; char *hex_string = NULL;
int j; int j;
int i; int i;

View File

@@ -19,7 +19,7 @@
#include <aaruformat.h> #include <aaruformat.h>
int identify(char* path) int identify(char *path)
{ {
int ret; int ret;

View File

@@ -25,14 +25,14 @@
#include "aaruformattool.h" #include "aaruformattool.h"
int info(char* path) int info(char *path)
{ {
aaruformatContext* ctx; aaruformatContext *ctx;
char* strBuffer; char *strBuffer;
UErrorCode u_error_code; UErrorCode u_error_code;
uint i, j; uint i, j;
mediaTagEntry* mediaTag; mediaTagEntry *mediaTag;
mediaTagEntry* tmpMediaTag; mediaTagEntry *tmpMediaTag;
ctx = aaruf_open(path); ctx = aaruf_open(path);
@@ -43,14 +43,14 @@ int info(char* path)
} }
printf("AaruFormat context information:\n"); printf("AaruFormat context information:\n");
printf("Magic number: %8.8s\n", (char*)&ctx->magic); printf("Magic number: %8.8s\n", (char *)&ctx->magic);
printf("Library version: %d.%d\n", ctx->libraryMajorVersion, ctx->libraryMinorVersion); printf("Library version: %d.%d\n", ctx->libraryMajorVersion, ctx->libraryMinorVersion);
printf("AaruFormat header:\n"); printf("AaruFormat header:\n");
printf("\tIdentifier: %8.8s\n", (char*)&ctx->header.identifier); printf("\tIdentifier: %8.8s\n", (char *)&ctx->header.identifier);
strBuffer = malloc(65); strBuffer = malloc(65);
memset(strBuffer, 0, 65); memset(strBuffer, 0, 65);
ucnv_convert(NULL, "UTF-16LE", strBuffer, 64, (const char*)ctx->header.application, 64, &u_error_code); ucnv_convert(NULL, "UTF-16LE", strBuffer, 64, (const char *)ctx->header.application, 64, &u_error_code);
if(u_error_code == U_ZERO_ERROR) printf("\tApplication: %s\n", strBuffer); if(u_error_code == U_ZERO_ERROR) printf("\tApplication: %s\n", strBuffer);
free(strBuffer); free(strBuffer);
@@ -88,30 +88,23 @@ int info(char* path)
if(ctx->sectorPrefixDdt != NULL) printf("Sector suffix DDT has been read to memory.\n"); if(ctx->sectorPrefixDdt != NULL) printf("Sector suffix DDT has been read to memory.\n");
if(ctx->geometryBlock.identifier == GeometryBlock) if(ctx->geometryBlock.identifier == GeometryBlock)
printf("Media has %d cylinders, %d heads and %d sectors per track.\n", printf("Media has %d cylinders, %d heads and %d sectors per track.\n", ctx->geometryBlock.cylinders,
ctx->geometryBlock.cylinders, ctx->geometryBlock.heads, ctx->geometryBlock.sectorsPerTrack);
ctx->geometryBlock.heads,
ctx->geometryBlock.sectorsPerTrack);
if(ctx->metadataBlockHeader.identifier == MetadataBlock) if(ctx->metadataBlockHeader.identifier == MetadataBlock)
{ {
printf("Metadata block:\n"); printf("Metadata block:\n");
if(ctx->metadataBlockHeader.mediaSequence > 0) if(ctx->metadataBlockHeader.mediaSequence > 0)
printf("\tMedia is no. %d in a set of %d media\n", printf("\tMedia is no. %d in a set of %d media\n", ctx->metadataBlockHeader.mediaSequence,
ctx->metadataBlockHeader.mediaSequence,
ctx->metadataBlockHeader.lastMediaSequence); ctx->metadataBlockHeader.lastMediaSequence);
if(ctx->metadataBlockHeader.creatorLength > 0) if(ctx->metadataBlockHeader.creatorLength > 0)
{ {
strBuffer = malloc(ctx->metadataBlockHeader.creatorLength + 1); strBuffer = malloc(ctx->metadataBlockHeader.creatorLength + 1);
memset(strBuffer, 0, ctx->metadataBlockHeader.creatorLength + 1); memset(strBuffer, 0, ctx->metadataBlockHeader.creatorLength + 1);
ucnv_convert(NULL, ucnv_convert(NULL, "UTF-16LE", strBuffer, (int)ctx->metadataBlockHeader.creatorLength,
"UTF-16LE", (char *)(ctx->metadataBlock + ctx->metadataBlockHeader.creatorOffset),
strBuffer, (int)ctx->metadataBlockHeader.creatorLength, &u_error_code);
(int)ctx->metadataBlockHeader.creatorLength,
(char*)(ctx->metadataBlock + ctx->metadataBlockHeader.creatorOffset),
(int)ctx->metadataBlockHeader.creatorLength,
&u_error_code);
printf("\tCreator: %s\n", strBuffer); printf("\tCreator: %s\n", strBuffer);
free(strBuffer); free(strBuffer);
} }
@@ -120,13 +113,9 @@ int info(char* path)
{ {
strBuffer = malloc(ctx->metadataBlockHeader.commentsLength + 1); strBuffer = malloc(ctx->metadataBlockHeader.commentsLength + 1);
memset(strBuffer, 0, ctx->metadataBlockHeader.commentsLength + 1); memset(strBuffer, 0, ctx->metadataBlockHeader.commentsLength + 1);
ucnv_convert(NULL, ucnv_convert(NULL, "UTF-16LE", strBuffer, (int)ctx->metadataBlockHeader.commentsLength,
"UTF-16LE", (char *)(ctx->metadataBlock + ctx->metadataBlockHeader.commentsOffset),
strBuffer, (int)ctx->metadataBlockHeader.commentsLength, &u_error_code);
(int)ctx->metadataBlockHeader.commentsLength,
(char*)(ctx->metadataBlock + ctx->metadataBlockHeader.commentsOffset),
(int)ctx->metadataBlockHeader.commentsLength,
&u_error_code);
printf("\tCreator: %s\n", strBuffer); printf("\tCreator: %s\n", strBuffer);
free(strBuffer); free(strBuffer);
} }
@@ -135,13 +124,9 @@ int info(char* path)
{ {
strBuffer = malloc(ctx->metadataBlockHeader.mediaTitleLength + 1); strBuffer = malloc(ctx->metadataBlockHeader.mediaTitleLength + 1);
memset(strBuffer, 0, ctx->metadataBlockHeader.mediaTitleLength + 1); memset(strBuffer, 0, ctx->metadataBlockHeader.mediaTitleLength + 1);
ucnv_convert(NULL, ucnv_convert(NULL, "UTF-16LE", strBuffer, (int)ctx->metadataBlockHeader.mediaTitleLength,
"UTF-16LE", (char *)(ctx->metadataBlock + ctx->metadataBlockHeader.mediaTitleOffset),
strBuffer, (int)ctx->metadataBlockHeader.mediaTitleLength, &u_error_code);
(int)ctx->metadataBlockHeader.mediaTitleLength,
(char*)(ctx->metadataBlock + ctx->metadataBlockHeader.mediaTitleOffset),
(int)ctx->metadataBlockHeader.mediaTitleLength,
&u_error_code);
printf("\tCreator: %s\n", strBuffer); printf("\tCreator: %s\n", strBuffer);
free(strBuffer); free(strBuffer);
} }
@@ -150,13 +135,9 @@ int info(char* path)
{ {
strBuffer = malloc(ctx->metadataBlockHeader.mediaManufacturerLength + 1); strBuffer = malloc(ctx->metadataBlockHeader.mediaManufacturerLength + 1);
memset(strBuffer, 0, ctx->metadataBlockHeader.mediaManufacturerLength + 1); memset(strBuffer, 0, ctx->metadataBlockHeader.mediaManufacturerLength + 1);
ucnv_convert(NULL, ucnv_convert(NULL, "UTF-16LE", strBuffer, (int)ctx->metadataBlockHeader.mediaManufacturerLength,
"UTF-16LE", (char *)(ctx->metadataBlock + ctx->metadataBlockHeader.mediaManufacturerOffset),
strBuffer, (int)ctx->metadataBlockHeader.mediaManufacturerLength, &u_error_code);
(int)ctx->metadataBlockHeader.mediaManufacturerLength,
(char*)(ctx->metadataBlock + ctx->metadataBlockHeader.mediaManufacturerOffset),
(int)ctx->metadataBlockHeader.mediaManufacturerLength,
&u_error_code);
printf("\tCreator: %s\n", strBuffer); printf("\tCreator: %s\n", strBuffer);
free(strBuffer); free(strBuffer);
} }
@@ -165,13 +146,9 @@ int info(char* path)
{ {
strBuffer = malloc(ctx->metadataBlockHeader.mediaModelLength + 1); strBuffer = malloc(ctx->metadataBlockHeader.mediaModelLength + 1);
memset(strBuffer, 0, ctx->metadataBlockHeader.mediaModelLength + 1); memset(strBuffer, 0, ctx->metadataBlockHeader.mediaModelLength + 1);
ucnv_convert(NULL, ucnv_convert(NULL, "UTF-16LE", strBuffer, (int)ctx->metadataBlockHeader.mediaModelLength,
"UTF-16LE", (char *)(ctx->metadataBlock + ctx->metadataBlockHeader.mediaModelOffset),
strBuffer, (int)ctx->metadataBlockHeader.mediaModelLength, &u_error_code);
(int)ctx->metadataBlockHeader.mediaModelLength,
(char*)(ctx->metadataBlock + ctx->metadataBlockHeader.mediaModelOffset),
(int)ctx->metadataBlockHeader.mediaModelLength,
&u_error_code);
printf("\tCreator: %s\n", strBuffer); printf("\tCreator: %s\n", strBuffer);
free(strBuffer); free(strBuffer);
} }
@@ -180,13 +157,9 @@ int info(char* path)
{ {
strBuffer = malloc(ctx->metadataBlockHeader.mediaSerialNumberLength + 1); strBuffer = malloc(ctx->metadataBlockHeader.mediaSerialNumberLength + 1);
memset(strBuffer, 0, ctx->metadataBlockHeader.mediaSerialNumberLength + 1); memset(strBuffer, 0, ctx->metadataBlockHeader.mediaSerialNumberLength + 1);
ucnv_convert(NULL, ucnv_convert(NULL, "UTF-16LE", strBuffer, (int)ctx->metadataBlockHeader.mediaSerialNumberLength,
"UTF-16LE", (char *)(ctx->metadataBlock + ctx->metadataBlockHeader.mediaSerialNumberOffset),
strBuffer, (int)ctx->metadataBlockHeader.mediaSerialNumberLength, &u_error_code);
(int)ctx->metadataBlockHeader.mediaSerialNumberLength,
(char*)(ctx->metadataBlock + ctx->metadataBlockHeader.mediaSerialNumberOffset),
(int)ctx->metadataBlockHeader.mediaSerialNumberLength,
&u_error_code);
printf("\tCreator: %s\n", strBuffer); printf("\tCreator: %s\n", strBuffer);
free(strBuffer); free(strBuffer);
} }
@@ -195,13 +168,9 @@ int info(char* path)
{ {
strBuffer = malloc(ctx->metadataBlockHeader.mediaBarcodeLength + 1); strBuffer = malloc(ctx->metadataBlockHeader.mediaBarcodeLength + 1);
memset(strBuffer, 0, ctx->metadataBlockHeader.mediaBarcodeLength + 1); memset(strBuffer, 0, ctx->metadataBlockHeader.mediaBarcodeLength + 1);
ucnv_convert(NULL, ucnv_convert(NULL, "UTF-16LE", strBuffer, (int)ctx->metadataBlockHeader.mediaBarcodeLength,
"UTF-16LE", (char *)(ctx->metadataBlock + ctx->metadataBlockHeader.mediaBarcodeOffset),
strBuffer, (int)ctx->metadataBlockHeader.mediaBarcodeLength, &u_error_code);
(int)ctx->metadataBlockHeader.mediaBarcodeLength,
(char*)(ctx->metadataBlock + ctx->metadataBlockHeader.mediaBarcodeOffset),
(int)ctx->metadataBlockHeader.mediaBarcodeLength,
&u_error_code);
printf("\tCreator: %s\n", strBuffer); printf("\tCreator: %s\n", strBuffer);
free(strBuffer); free(strBuffer);
} }
@@ -210,13 +179,9 @@ int info(char* path)
{ {
strBuffer = malloc(ctx->metadataBlockHeader.mediaPartNumberLength + 1); strBuffer = malloc(ctx->metadataBlockHeader.mediaPartNumberLength + 1);
memset(strBuffer, 0, ctx->metadataBlockHeader.mediaPartNumberLength + 1); memset(strBuffer, 0, ctx->metadataBlockHeader.mediaPartNumberLength + 1);
ucnv_convert(NULL, ucnv_convert(NULL, "UTF-16LE", strBuffer, (int)ctx->metadataBlockHeader.mediaPartNumberLength,
"UTF-16LE", (char *)(ctx->metadataBlock + ctx->metadataBlockHeader.mediaPartNumberOffset),
strBuffer, (int)ctx->metadataBlockHeader.mediaPartNumberLength, &u_error_code);
(int)ctx->metadataBlockHeader.mediaPartNumberLength,
(char*)(ctx->metadataBlock + ctx->metadataBlockHeader.mediaPartNumberOffset),
(int)ctx->metadataBlockHeader.mediaPartNumberLength,
&u_error_code);
printf("\tCreator: %s\n", strBuffer); printf("\tCreator: %s\n", strBuffer);
free(strBuffer); free(strBuffer);
} }
@@ -225,13 +190,9 @@ int info(char* path)
{ {
strBuffer = malloc(ctx->metadataBlockHeader.driveManufacturerLength + 1); strBuffer = malloc(ctx->metadataBlockHeader.driveManufacturerLength + 1);
memset(strBuffer, 0, ctx->metadataBlockHeader.driveManufacturerLength + 1); memset(strBuffer, 0, ctx->metadataBlockHeader.driveManufacturerLength + 1);
ucnv_convert(NULL, ucnv_convert(NULL, "UTF-16LE", strBuffer, (int)ctx->metadataBlockHeader.driveManufacturerLength,
"UTF-16LE", (char *)(ctx->metadataBlock + ctx->metadataBlockHeader.driveManufacturerOffset),
strBuffer, (int)ctx->metadataBlockHeader.driveManufacturerLength, &u_error_code);
(int)ctx->metadataBlockHeader.driveManufacturerLength,
(char*)(ctx->metadataBlock + ctx->metadataBlockHeader.driveManufacturerOffset),
(int)ctx->metadataBlockHeader.driveManufacturerLength,
&u_error_code);
printf("\tCreator: %s\n", strBuffer); printf("\tCreator: %s\n", strBuffer);
free(strBuffer); free(strBuffer);
} }
@@ -240,13 +201,9 @@ int info(char* path)
{ {
strBuffer = malloc(ctx->metadataBlockHeader.driveModelLength + 1); strBuffer = malloc(ctx->metadataBlockHeader.driveModelLength + 1);
memset(strBuffer, 0, ctx->metadataBlockHeader.driveModelLength + 1); memset(strBuffer, 0, ctx->metadataBlockHeader.driveModelLength + 1);
ucnv_convert(NULL, ucnv_convert(NULL, "UTF-16LE", strBuffer, (int)ctx->metadataBlockHeader.driveModelLength,
"UTF-16LE", (char *)(ctx->metadataBlock + ctx->metadataBlockHeader.driveModelOffset),
strBuffer, (int)ctx->metadataBlockHeader.driveModelLength, &u_error_code);
(int)ctx->metadataBlockHeader.driveModelLength,
(char*)(ctx->metadataBlock + ctx->metadataBlockHeader.driveModelOffset),
(int)ctx->metadataBlockHeader.driveModelLength,
&u_error_code);
printf("\tCreator: %s\n", strBuffer); printf("\tCreator: %s\n", strBuffer);
free(strBuffer); free(strBuffer);
} }
@@ -255,13 +212,9 @@ int info(char* path)
{ {
strBuffer = malloc(ctx->metadataBlockHeader.driveSerialNumberLength + 1); strBuffer = malloc(ctx->metadataBlockHeader.driveSerialNumberLength + 1);
memset(strBuffer, 0, ctx->metadataBlockHeader.driveSerialNumberLength + 1); memset(strBuffer, 0, ctx->metadataBlockHeader.driveSerialNumberLength + 1);
ucnv_convert(NULL, ucnv_convert(NULL, "UTF-16LE", strBuffer, (int)ctx->metadataBlockHeader.driveSerialNumberLength,
"UTF-16LE", (char *)(ctx->metadataBlock + ctx->metadataBlockHeader.driveSerialNumberOffset),
strBuffer, (int)ctx->metadataBlockHeader.driveSerialNumberLength, &u_error_code);
(int)ctx->metadataBlockHeader.driveSerialNumberLength,
(char*)(ctx->metadataBlock + ctx->metadataBlockHeader.driveSerialNumberOffset),
(int)ctx->metadataBlockHeader.driveSerialNumberLength,
&u_error_code);
printf("\tCreator: %s\n", strBuffer); printf("\tCreator: %s\n", strBuffer);
free(strBuffer); free(strBuffer);
} }
@@ -270,13 +223,9 @@ int info(char* path)
{ {
strBuffer = malloc(ctx->metadataBlockHeader.driveFirmwareRevisionLength + 1); strBuffer = malloc(ctx->metadataBlockHeader.driveFirmwareRevisionLength + 1);
memset(strBuffer, 0, ctx->metadataBlockHeader.driveFirmwareRevisionLength + 1); memset(strBuffer, 0, ctx->metadataBlockHeader.driveFirmwareRevisionLength + 1);
ucnv_convert(NULL, ucnv_convert(NULL, "UTF-16LE", strBuffer, (int)ctx->metadataBlockHeader.driveFirmwareRevisionLength,
"UTF-16LE", (char *)(ctx->metadataBlock + ctx->metadataBlockHeader.driveFirmwareRevisionOffset),
strBuffer, (int)ctx->metadataBlockHeader.driveFirmwareRevisionLength, &u_error_code);
(int)ctx->metadataBlockHeader.driveFirmwareRevisionLength,
(char*)(ctx->metadataBlock + ctx->metadataBlockHeader.driveFirmwareRevisionOffset),
(int)ctx->metadataBlockHeader.driveFirmwareRevisionLength,
&u_error_code);
printf("\tCreator: %s\n", strBuffer); printf("\tCreator: %s\n", strBuffer);
free(strBuffer); free(strBuffer);
} }
@@ -319,13 +268,10 @@ int info(char* path)
{ {
strBuffer = malloc(ctx->dumpHardwareEntriesWithData[i].entry.manufacturerLength + 1); strBuffer = malloc(ctx->dumpHardwareEntriesWithData[i].entry.manufacturerLength + 1);
memset(strBuffer, 0, ctx->dumpHardwareEntriesWithData[i].entry.manufacturerLength + 1); memset(strBuffer, 0, ctx->dumpHardwareEntriesWithData[i].entry.manufacturerLength + 1);
ucnv_convert(NULL, ucnv_convert(NULL, "UTF-8", strBuffer,
"UTF-8",
strBuffer,
(int)ctx->dumpHardwareEntriesWithData[i].entry.manufacturerLength, (int)ctx->dumpHardwareEntriesWithData[i].entry.manufacturerLength,
(char*)(ctx->dumpHardwareEntriesWithData[i].manufacturer), (char *)(ctx->dumpHardwareEntriesWithData[i].manufacturer),
(int)ctx->dumpHardwareEntriesWithData[i].entry.manufacturerLength, (int)ctx->dumpHardwareEntriesWithData[i].entry.manufacturerLength, &u_error_code);
&u_error_code);
printf("\t\tManufacturer: %s\n", strBuffer); printf("\t\tManufacturer: %s\n", strBuffer);
free(strBuffer); free(strBuffer);
} }
@@ -334,13 +280,9 @@ int info(char* path)
{ {
strBuffer = malloc(ctx->dumpHardwareEntriesWithData[i].entry.modelLength + 1); strBuffer = malloc(ctx->dumpHardwareEntriesWithData[i].entry.modelLength + 1);
memset(strBuffer, 0, ctx->dumpHardwareEntriesWithData[i].entry.modelLength + 1); memset(strBuffer, 0, ctx->dumpHardwareEntriesWithData[i].entry.modelLength + 1);
ucnv_convert(NULL, ucnv_convert(NULL, "UTF-8", strBuffer, (int)ctx->dumpHardwareEntriesWithData[i].entry.modelLength,
"UTF-8", (char *)(ctx->dumpHardwareEntriesWithData[i].model),
strBuffer, (int)ctx->dumpHardwareEntriesWithData[i].entry.modelLength, &u_error_code);
(int)ctx->dumpHardwareEntriesWithData[i].entry.modelLength,
(char*)(ctx->dumpHardwareEntriesWithData[i].model),
(int)ctx->dumpHardwareEntriesWithData[i].entry.modelLength,
&u_error_code);
printf("\t\tModel: %s\n", strBuffer); printf("\t\tModel: %s\n", strBuffer);
free(strBuffer); free(strBuffer);
} }
@@ -349,13 +291,9 @@ int info(char* path)
{ {
strBuffer = malloc(ctx->dumpHardwareEntriesWithData[i].entry.revisionLength + 1); strBuffer = malloc(ctx->dumpHardwareEntriesWithData[i].entry.revisionLength + 1);
memset(strBuffer, 0, ctx->dumpHardwareEntriesWithData[i].entry.revisionLength + 1); memset(strBuffer, 0, ctx->dumpHardwareEntriesWithData[i].entry.revisionLength + 1);
ucnv_convert(NULL, ucnv_convert(NULL, "UTF-8", strBuffer, (int)ctx->dumpHardwareEntriesWithData[i].entry.revisionLength,
"UTF-8", (char *)(ctx->dumpHardwareEntriesWithData[i].revision),
strBuffer, (int)ctx->dumpHardwareEntriesWithData[i].entry.revisionLength, &u_error_code);
(int)ctx->dumpHardwareEntriesWithData[i].entry.revisionLength,
(char*)(ctx->dumpHardwareEntriesWithData[i].revision),
(int)ctx->dumpHardwareEntriesWithData[i].entry.revisionLength,
&u_error_code);
printf("\t\tRevision: %s\n", strBuffer); printf("\t\tRevision: %s\n", strBuffer);
free(strBuffer); free(strBuffer);
} }
@@ -364,13 +302,9 @@ int info(char* path)
{ {
strBuffer = malloc(ctx->dumpHardwareEntriesWithData[i].entry.firmwareLength + 1); strBuffer = malloc(ctx->dumpHardwareEntriesWithData[i].entry.firmwareLength + 1);
memset(strBuffer, 0, ctx->dumpHardwareEntriesWithData[i].entry.firmwareLength + 1); memset(strBuffer, 0, ctx->dumpHardwareEntriesWithData[i].entry.firmwareLength + 1);
ucnv_convert(NULL, ucnv_convert(NULL, "UTF-8", strBuffer, (int)ctx->dumpHardwareEntriesWithData[i].entry.firmwareLength,
"UTF-8", (char *)(ctx->dumpHardwareEntriesWithData[i].firmware),
strBuffer, (int)ctx->dumpHardwareEntriesWithData[i].entry.firmwareLength, &u_error_code);
(int)ctx->dumpHardwareEntriesWithData[i].entry.firmwareLength,
(char*)(ctx->dumpHardwareEntriesWithData[i].firmware),
(int)ctx->dumpHardwareEntriesWithData[i].entry.firmwareLength,
&u_error_code);
printf("\t\tFirmware version: %s\n", strBuffer); printf("\t\tFirmware version: %s\n", strBuffer);
free(strBuffer); free(strBuffer);
} }
@@ -379,13 +313,9 @@ int info(char* path)
{ {
strBuffer = malloc(ctx->dumpHardwareEntriesWithData[i].entry.serialLength + 1); strBuffer = malloc(ctx->dumpHardwareEntriesWithData[i].entry.serialLength + 1);
memset(strBuffer, 0, ctx->dumpHardwareEntriesWithData[i].entry.serialLength + 1); memset(strBuffer, 0, ctx->dumpHardwareEntriesWithData[i].entry.serialLength + 1);
ucnv_convert(NULL, ucnv_convert(NULL, "UTF-8", strBuffer, (int)ctx->dumpHardwareEntriesWithData[i].entry.serialLength,
"UTF-8", (char *)(ctx->dumpHardwareEntriesWithData[i].serial),
strBuffer, (int)ctx->dumpHardwareEntriesWithData[i].entry.serialLength, &u_error_code);
(int)ctx->dumpHardwareEntriesWithData[i].entry.serialLength,
(char*)(ctx->dumpHardwareEntriesWithData[i].serial),
(int)ctx->dumpHardwareEntriesWithData[i].entry.serialLength,
&u_error_code);
printf("\t\tSerial number: %s\n", strBuffer); printf("\t\tSerial number: %s\n", strBuffer);
free(strBuffer); free(strBuffer);
} }
@@ -394,13 +324,10 @@ int info(char* path)
{ {
strBuffer = malloc(ctx->dumpHardwareEntriesWithData[i].entry.softwareNameLength + 1); strBuffer = malloc(ctx->dumpHardwareEntriesWithData[i].entry.softwareNameLength + 1);
memset(strBuffer, 0, ctx->dumpHardwareEntriesWithData[i].entry.softwareNameLength + 1); memset(strBuffer, 0, ctx->dumpHardwareEntriesWithData[i].entry.softwareNameLength + 1);
ucnv_convert(NULL, ucnv_convert(NULL, "UTF-8", strBuffer,
"UTF-8",
strBuffer,
(int)ctx->dumpHardwareEntriesWithData[i].entry.softwareNameLength, (int)ctx->dumpHardwareEntriesWithData[i].entry.softwareNameLength,
(char*)(ctx->dumpHardwareEntriesWithData[i].softwareName), (char *)(ctx->dumpHardwareEntriesWithData[i].softwareName),
(int)ctx->dumpHardwareEntriesWithData[i].entry.softwareNameLength, (int)ctx->dumpHardwareEntriesWithData[i].entry.softwareNameLength, &u_error_code);
&u_error_code);
printf("\t\tSoftware name: %s\n", strBuffer); printf("\t\tSoftware name: %s\n", strBuffer);
free(strBuffer); free(strBuffer);
} }
@@ -409,13 +336,10 @@ int info(char* path)
{ {
strBuffer = malloc(ctx->dumpHardwareEntriesWithData[i].entry.softwareVersionLength + 1); strBuffer = malloc(ctx->dumpHardwareEntriesWithData[i].entry.softwareVersionLength + 1);
memset(strBuffer, 0, ctx->dumpHardwareEntriesWithData[i].entry.softwareVersionLength + 1); memset(strBuffer, 0, ctx->dumpHardwareEntriesWithData[i].entry.softwareVersionLength + 1);
ucnv_convert(NULL, ucnv_convert(NULL, "UTF-8", strBuffer,
"UTF-8",
strBuffer,
(int)ctx->dumpHardwareEntriesWithData[i].entry.softwareVersionLength, (int)ctx->dumpHardwareEntriesWithData[i].entry.softwareVersionLength,
(char*)(ctx->dumpHardwareEntriesWithData[i].softwareVersion), (char *)(ctx->dumpHardwareEntriesWithData[i].softwareVersion),
(int)ctx->dumpHardwareEntriesWithData[i].entry.softwareVersionLength, (int)ctx->dumpHardwareEntriesWithData[i].entry.softwareVersionLength, &u_error_code);
&u_error_code);
printf("\t\tSoftware version: %s\n", strBuffer); printf("\t\tSoftware version: %s\n", strBuffer);
free(strBuffer); free(strBuffer);
} }
@@ -424,11 +348,9 @@ int info(char* path)
{ {
strBuffer = malloc(ctx->dumpHardwareEntriesWithData[i].entry.softwareOperatingSystemLength + 1); strBuffer = malloc(ctx->dumpHardwareEntriesWithData[i].entry.softwareOperatingSystemLength + 1);
memset(strBuffer, 0, ctx->dumpHardwareEntriesWithData[i].entry.softwareOperatingSystemLength + 1); memset(strBuffer, 0, ctx->dumpHardwareEntriesWithData[i].entry.softwareOperatingSystemLength + 1);
ucnv_convert(NULL, ucnv_convert(NULL, "UTF-8", strBuffer,
"UTF-8",
strBuffer,
(int)ctx->dumpHardwareEntriesWithData[i].entry.softwareOperatingSystemLength, (int)ctx->dumpHardwareEntriesWithData[i].entry.softwareOperatingSystemLength,
(char*)(ctx->dumpHardwareEntriesWithData[i].softwareOperatingSystem), (char *)(ctx->dumpHardwareEntriesWithData[i].softwareOperatingSystem),
(int)ctx->dumpHardwareEntriesWithData[i].entry.softwareOperatingSystemLength, (int)ctx->dumpHardwareEntriesWithData[i].entry.softwareOperatingSystemLength,
&u_error_code); &u_error_code);
printf("\t\tSoftware operating system: %s\n", strBuffer); printf("\t\tSoftware operating system: %s\n", strBuffer);
@@ -474,7 +396,7 @@ int info(char* path)
{ {
strBuffer = malloc(65); strBuffer = malloc(65);
memset(strBuffer, 0, 65); memset(strBuffer, 0, 65);
ucnv_convert(NULL, "UTF-16LE", strBuffer, 64, (const char*)ctx->imageInfo.Application, 64, &u_error_code); ucnv_convert(NULL, "UTF-16LE", strBuffer, 64, (const char *)ctx->imageInfo.Application, 64, &u_error_code);
if(u_error_code == U_ZERO_ERROR) printf("\tApplication: %s\n", strBuffer); if(u_error_code == U_ZERO_ERROR) printf("\tApplication: %s\n", strBuffer);
free(strBuffer); free(strBuffer);
} }
@@ -494,8 +416,7 @@ int info(char* path)
printf("\tMedia type: %u\n", ctx->imageInfo.MediaType); printf("\tMedia type: %u\n", ctx->imageInfo.MediaType);
if(ctx->imageInfo.MediaSequence > 0 || ctx->imageInfo.LastMediaSequence > 0) if(ctx->imageInfo.MediaSequence > 0 || ctx->imageInfo.LastMediaSequence > 0)
printf("\tMedia is number %d in a set of %d media\n", printf("\tMedia is number %d in a set of %d media\n", ctx->imageInfo.MediaSequence,
ctx->imageInfo.MediaSequence,
ctx->imageInfo.LastMediaSequence); ctx->imageInfo.LastMediaSequence);
if(ctx->imageInfo.DriveManufacturer != NULL) printf("\tDrive manufacturer: %s\n", ctx->imageInfo.DriveManufacturer); if(ctx->imageInfo.DriveManufacturer != NULL) printf("\tDrive manufacturer: %s\n", ctx->imageInfo.DriveManufacturer);
@@ -506,10 +427,8 @@ int info(char* path)
printf("\tDrive firmware revision: %s\n", ctx->imageInfo.DriveFirmwareRevision); printf("\tDrive firmware revision: %s\n", ctx->imageInfo.DriveFirmwareRevision);
printf("\tXML media type: %d\n", ctx->imageInfo.XmlMediaType); printf("\tXML media type: %d\n", ctx->imageInfo.XmlMediaType);
if(ctx->imageInfo.Cylinders > 0 || ctx->imageInfo.Heads > 0 || ctx->imageInfo.SectorsPerTrack > 0) if(ctx->imageInfo.Cylinders > 0 || ctx->imageInfo.Heads > 0 || ctx->imageInfo.SectorsPerTrack > 0)
printf("\tMedia has %d cylinders, %d heads and %d sectors per track\n", printf("\tMedia has %d cylinders, %d heads and %d sectors per track\n", ctx->imageInfo.Cylinders,
ctx->imageInfo.Cylinders, ctx->imageInfo.Heads, ctx->imageInfo.SectorsPerTrack);
ctx->imageInfo.Heads,
ctx->imageInfo.SectorsPerTrack);
if(ctx->checksums.hasMd5) if(ctx->checksums.hasMd5)
{ {

View File

@@ -111,7 +111,7 @@ void usage_verify_sectors()
printf("\t<filename>\tPath to AaruFormat image to verify.\n"); printf("\t<filename>\tPath to AaruFormat image to verify.\n");
} }
int main(int argc, char* argv[]) int main(int argc, char *argv[])
{ {
uint64_t sector_no = 0; uint64_t sector_no = 0;

View File

@@ -22,7 +22,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
int printhex(unsigned char* array, unsigned int length, int width, bool color) int printhex(unsigned char *array, unsigned int length, int width, bool color)
{ {
char length_hex[17]; char length_hex[17];
char str[256]; char str[256];

View File

@@ -24,12 +24,12 @@
#include "aaruformattool.h" #include "aaruformattool.h"
int read(unsigned long long sector_no, char* path) int read(unsigned long long sector_no, char *path)
{ {
aaruformatContext* ctx; aaruformatContext *ctx;
int32_t res; int32_t res;
uint32_t length; uint32_t length;
uint8_t* data; uint8_t *data;
ctx = aaruf_open(path); ctx = aaruf_open(path);
@@ -74,12 +74,12 @@ int read(unsigned long long sector_no, char* path)
aaruf_close(ctx); aaruf_close(ctx);
} }
int read_long(unsigned long long sector_no, char* path) int read_long(unsigned long long sector_no, char *path)
{ {
aaruformatContext* ctx; aaruformatContext *ctx;
int32_t res; int32_t res;
uint32_t length; uint32_t length;
uint8_t* data; uint8_t *data;
ctx = aaruf_open(path); ctx = aaruf_open(path);

View File

@@ -23,9 +23,9 @@
#include "aaruformattool.h" #include "aaruformattool.h"
int verify(char* path) int verify(char *path)
{ {
aaruformatContext* ctx; aaruformatContext *ctx;
uint32_t res; uint32_t res;
ctx = aaruf_open(path); ctx = aaruf_open(path);
@@ -38,7 +38,8 @@ int verify(char* path)
res = aaruf_verify_image(ctx); res = aaruf_verify_image(ctx);
if(res == AARUF_STATUS_OK) printf("Image blocks contain no errors.\n"); if(res == AARUF_STATUS_OK)
printf("Image blocks contain no errors.\n");
else if(res == AARUF_ERROR_INVALID_BLOCK_CRC) else if(res == AARUF_ERROR_INVALID_BLOCK_CRC)
printf("A block contains an invalid CRC value.\n"); printf("A block contains an invalid CRC value.\n");
else else
@@ -47,14 +48,14 @@ int verify(char* path)
return res; return res;
} }
int verify_sectors(char* path) int verify_sectors(char *path)
{ {
aaruformatContext* ctx; aaruformatContext *ctx;
uint64_t s; uint64_t s;
uint8_t* buffer; uint8_t *buffer;
uint32_t buffer_len = 2352; uint32_t buffer_len = 2352;
int32_t res; int32_t res;
CdEccContext* cd_ecc_context; CdEccContext *cd_ecc_context;
ctx = aaruf_open(path); ctx = aaruf_open(path);
bool verify_result; bool verify_result;
bool unknown, has_edc, edc_correct, has_ecc_p, ecc_p_correct, has_ecc_q, ecc_q_correct; bool unknown, has_edc, edc_correct, has_ecc_p, ecc_p_correct, has_ecc_q, ecc_q_correct;
@@ -89,15 +90,8 @@ int verify_sectors(char* path)
continue; continue;
} }
verify_result = check_cd_sector_channel(cd_ecc_context, verify_result = check_cd_sector_channel(cd_ecc_context, buffer, &unknown, &has_edc, &edc_correct, &has_ecc_p,
buffer, &ecc_p_correct, &has_ecc_q, &ecc_q_correct);
&unknown,
&has_edc,
&edc_correct,
&has_ecc_p,
&ecc_p_correct,
&has_ecc_q,
&ecc_q_correct);
if(verify_result) continue; if(verify_result) continue;
@@ -118,7 +112,8 @@ int verify_sectors(char* path)
any_error = true; any_error = true;
} }
if(any_error) printf("\rSome sectors had incorrect checksums.\n"); if(any_error)
printf("\rSome sectors had incorrect checksums.\n");
else else
printf("\rAll sector checksums are correct.\n"); printf("\rAll sector checksums are correct.\n");