diff --git a/frontend/src/main.c b/frontend/src/main.c index 59cedb8..3623d5e 100644 --- a/frontend/src/main.c +++ b/frontend/src/main.c @@ -10,6 +10,7 @@ #include "crc.h" #include #include +#include static void print_string(const char *const text, const size_t length) { @@ -290,13 +291,14 @@ static int decrypt(const CHR* const passphrase, const CHR* const input, const CH if (crc_actual != crc_expected) { - FPRINTF(stderr, T("CRC error: Checksum mismatch detected! [0x%016") FMT_I64X T(" vs. 0x%016") FMT_I64X T("\n\nWrong passphrase?\n\n"), crc_actual, crc_expected); + FPRINTF(stderr, T("CRC error: Checksum mismatch detected! [expected: 0x%016") T(PRIX64) T(", actual: 0x%016") T(PRIX64) T("]\n\n"), crc_actual, crc_expected); + FPUTS(T("Wrong passphrase or corrupted file?\n\n"), stderr); goto clean_up; } result = 0; - FPUTS(T("CRC checksum is correct :-)\n\n"), stderr); + FPUTS(T("CRC checksum is correct.\n\n"), stderr); fflush(stderr); clean_up: @@ -327,8 +329,8 @@ clean_up: int MAIN(int argc, CHR* argv[]) { - FPRINTF(stderr, T("MCrypt Utility [%") FMT_char T("]\n"), __DATE__" "__TIME__); - FPRINTF(stderr, T("Powered by libMCrypt v%") FMT_char T(" [%") FMT_char T("]\n\n"), LIBMCRYPT_VERSION, LIBMCRYPT_BUILDNO); + FPRINTF(stderr, T("MCrypt Utility [%") T(PRIstr) T("]\n"), __DATE__" "__TIME__); + FPRINTF(stderr, T("Powered by libMCrypt v%") T(PRIstr) T(" [%") T(PRIstr) T("]\n\n"), LIBMCRYPT_VERSION, LIBMCRYPT_BUILDNO); if (argc < 4) { diff --git a/frontend/src/platform.h b/frontend/src/platform.h index a4f3d21..7dca2c1 100644 --- a/frontend/src/platform.h +++ b/frontend/src/platform.h @@ -10,7 +10,6 @@ #define MAIN wmain #define CHR wchar_t #define _T(X) L##X -#define T(X) _T(X) #define STRLEN(X) wcslen((X)) #define STRICMP(X,Y) _wcsicmp((X),(Y)) #define FPUTS(X,Y) fputws((X),(Y)) @@ -20,25 +19,25 @@ #define FSTAT64(X,Y) _fstati64((X),(Y)) #define STAT64_T struct _stati64 #ifdef __MINGW32__ -#define FMT_char L"hs" -#define FMT_I64X L"llX" +#define PRIstr "hs" #else -#define FMT_char L"S" -#define FMT_I64X L"I64X" +#define PRIstr "S" #endif #else #define MAIN main #define CHR char +#define _T(X) X #define STRLEN(X) strlen((X)) -#define STRICMP(X,Y) stricmp((X),(Y)) +#define STRICMP(X,Y) strcasecmp((X),(Y)) #define FPUTS(X,Y) fputs((X),(Y)) #define FPRINTF(X,Y,...) fprintf((X),(Y),__VA_ARGS__) #define FOPEN(X,Y) fopen((X),(Y)) #define FILENO(X) fileno((X)) #define FSTAT64(X,Y) fstat64((X),(Y)) #define STAT64_T struct stat64 -#define FMT_char "s" -#define FMT_I64X L"llX" +#define PRIstr "s" #endif -#endif \ No newline at end of file +#define T(X) _T(X) + +#endif diff --git a/frontend/src/utils.c b/frontend/src/utils.c index 30e4789..d6e2ed2 100644 --- a/frontend/src/utils.c +++ b/frontend/src/utils.c @@ -6,13 +6,21 @@ #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN 1 #define _CRT_SECURE_NO_WARNINGS 1 +#else +#define _LARGEFILE64_SOURCE 1 #endif #include "utils.h" +#include #include #include + #ifdef _WIN32 #include +#include +#define S_IFMT _S_IFMT +#define S_IFDIR _S_IFDIR +#define S_IFIFO _S_IFIFO #endif void erase(void *const ptr, const size_t length) @@ -62,8 +70,8 @@ uint64_t get_file_size(FILE *const file) { return UINT64_MAX; } - uint16_t file_type = stat.st_mode & _S_IFMT; - if ((file_type != _S_IFDIR) && (file_type != _S_IFIFO)) + uint16_t file_type = stat.st_mode & S_IFMT; + if ((file_type != S_IFDIR) && (file_type != S_IFIFO)) { return (stat.st_size >= 0LL) ? ((uint64_t)stat.st_size) : 0U; } diff --git a/libMCrypt/src/utils.c b/libMCrypt/src/utils.c index 96bfd8a..8edb09d 100644 --- a/libMCrypt/src/utils.c +++ b/libMCrypt/src/utils.c @@ -9,6 +9,11 @@ #include "utils.h" +#ifdef __unix__ +#include +#include +#endif + int mcrypt_random_bytes(uint8_t* const buffer, const size_t length) { #ifdef _WIN32 @@ -38,7 +43,7 @@ int mcrypt_random_bytes(uint8_t* const buffer, const size_t length) const int fd = open(PATH[i], O_RDONLY); if (fd >= 0) { - if (read(fd, buffer, length) < length) + if (read(fd, buffer, length) >= length) { result = 0; }