From 0339fb51f45ac9095972aaf7fa3ebb9ad4ba6921 Mon Sep 17 00:00:00 2001 From: Romain Tartiere Date: Mon, 27 Jun 2011 18:34:07 +0000 Subject: [PATCH] Enable WITH_DEBUG for Windows (Fixes issue 65) PR: Issue 65 Submitted by: glenn.ergeerts --- CMakeLists.txt | 9 +++------ cmake/config_windows.h.cmake | 2 ++ libfreefare/CMakeLists.txt | 1 + libfreefare/mifare_desfire_crypto.c | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5274627..9577fbc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ project(libfreefare C) cmake_minimum_required(VERSION 2.6) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/") +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/") add_definitions("-std=c99") @@ -26,13 +26,10 @@ endif(MINGW) message("CMAKE_C_FLAGS: " ${CMAKE_C_FLAGS}) message("CMAKE_SHARED_LINKER_FLAGS: " ${CMAKE_SHARED_LINKER_FLAGS}) -include_directories(${LIBNFC_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) +include_directories(${LIBNFC_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/contrib/libutil) set(LIBS ${LIBS} ${LIBNFC_LIBRARIES} ${OPENSSL_LIBRARIES}) -if(NOT DEFINED CMAKE_INSTALL_PREFIX) - message("CMAKE_INSTALL_PREFIX not defined") - set(CMAKE_INSTALL_PREFIX "c:/projects/EVENT/install") # TODO -endif(NOT DEFINED CMAKE_INSTALL_PREFIX) +option(WITH_DEBUG "Extra debug information is outputted when this is turned on" OFF) if(DEFINED CMAKE_INSTALL_LIBDIR) set(libdir ${CMAKE_INSTALL_LIBDIR}) diff --git a/cmake/config_windows.h.cmake b/cmake/config_windows.h.cmake index a05d0ea..a7a6210 100644 --- a/cmake/config_windows.h.cmake +++ b/cmake/config_windows.h.cmake @@ -20,6 +20,8 @@ #ifndef __CONFIG_WINDOWS_H__ #define __CONFIG_WINDOWS_H__ +#cmakedefine WITH_DEBUG + #include #define htole32(x) (x) diff --git a/libfreefare/CMakeLists.txt b/libfreefare/CMakeLists.txt index 282dd08..ada7db2 100644 --- a/libfreefare/CMakeLists.txt +++ b/libfreefare/CMakeLists.txt @@ -12,6 +12,7 @@ set(LIBRARY_SOURCES mifare_desfire_key mifare_ultralight tlv + ../contrib/libutil/hexdump ) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/libfreefare/mifare_desfire_crypto.c b/libfreefare/mifare_desfire_crypto.c index 1578288..4d4d158 100644 --- a/libfreefare/mifare_desfire_crypto.c +++ b/libfreefare/mifare_desfire_crypto.c @@ -423,7 +423,7 @@ mifare_cryto_preprocess_data (MifareTag tag, void *data, size_t *nbytes, off_t o break; default: warnx ("Unknown communication settings"); -#if WITH_DEBUG +#ifdef WITH_DEBUG abort (); #endif *nbytes = -1; @@ -473,7 +473,7 @@ mifare_cryto_postprocess_data (MifareTag tag, void *data, ssize_t *nbytes, int c mifare_cypher_blocks_chained (tag, NULL, NULL, edata, edl, MCD_SEND, MCO_ENCYPHER); if (0 != memcmp ((uint8_t *)data + *nbytes - 1, (uint8_t *)edata + edl - 8, 4)) { -#if WITH_DEBUG +#ifdef WITH_DEBUG warnx ("MACing not verified"); hexdump ((uint8_t *)data + *nbytes - 1, key_macing_length (key), "Expect ", 0); hexdump ((uint8_t *)edata + edl - 8, key_macing_length (key), "Actual ", 0); @@ -503,7 +503,7 @@ mifare_cryto_postprocess_data (MifareTag tag, void *data, ssize_t *nbytes, int c if (communication_settings & CMAC_VERIFY) { ((uint8_t *)data)[*nbytes - 9] = first_cmac_byte; if (0 != memcmp (MIFARE_DESFIRE (tag)->cmac, (uint8_t *)data + *nbytes - 9, 8)) { -#if WITH_DEBUG +#ifdef WITH_DEBUG warnx ("CMAC NOT verified :-("); hexdump ((uint8_t *)data + *nbytes - 9, 8, "Expect ", 0); hexdump (MIFARE_DESFIRE (tag)->cmac, 8, "Actual ", 0); @@ -625,7 +625,7 @@ mifare_cryto_postprocess_data (MifareTag tag, void *data, ssize_t *nbytes, int c } while (!verified && (end_crc_pos < *nbytes)); if (!verified) { -#if WITH_DEBUG +#ifdef WITH_DEBUG /* FIXME In some configurations, the file is transmitted PLAIN */ warnx ("CRC not verified in decyphered stream"); #endif @@ -637,7 +637,7 @@ mifare_cryto_postprocess_data (MifareTag tag, void *data, ssize_t *nbytes, int c break; default: warnx ("Unknown communication settings"); -#if WITH_DEBUG +#ifdef WITH_DEBUG abort (); #endif *nbytes = -1;