From 0064709772417df72d7c8bfe755c2cb9c0e51cd4 Mon Sep 17 00:00:00 2001 From: Pablo Curiel Date: Thu, 12 Aug 2021 15:50:59 -0400 Subject: [PATCH] Update to v0.8. --- .gitignore | 16 ++++++++-------- Makefile | 7 ++++++- README.md | 18 ++++++++++-------- source/bin.c | 26 +++++++++++++------------- source/cert.c | 2 +- source/keys.c | 2 +- source/main.c | 8 ++++---- source/tik.c | 2 +- source/tmd.c | 2 +- source/types.h | 11 ++++++++--- source/u8.c | 10 +++++----- source/utils.c | 14 +++++++------- source/utils.h | 4 +--- source/wad.c | 24 ++++++++++++------------ 14 files changed, 78 insertions(+), 68 deletions(-) diff --git a/.gitignore b/.gitignore index fc86141..ae0f568 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,12 @@ -/config.mk -/keys.txt -/device.cert -/wad2bin -/wad2bin.exe -/wad2bin_wad_data -/private -/content.bin +config.mk +keys.txt +wad2bin +wad2bin_wad_data +private +*.exe *.wad +*.bin +*.cert *.o *.so *.so.* diff --git a/Makefile b/Makefile index ac1f891..442bb57 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,9 @@ endif include $(TOPDIR)/config.mk PROJECT_NAME := wad2bin +PROJECT_AUTHOR := DarkMatterCore +PROJECT_VERSION := 0.8 + ifeq ($(strip $(findstring Windows,$(shell uname -s))),) TARGET := $(PROJECT_NAME) else @@ -24,12 +27,14 @@ BUILD_STATIC ?= 0 CFLAGS := -std=gnu11 -fPIC -O2 -Wall -Wextra -Wpedantic -Wno-implicit-fallthrough -Wno-missing-braces -static-libgcc -static-libstdc++ $(INCLUDE) LIBS := -lmbedtls -lmbedx509 -lmbedcrypto -lninty-233 + ifeq ($(BUILD_STATIC),1) CFLAGS += -static -s LIBS += -static -s endif -CFLAGS += -D_BSD_SOURCE -D_POSIX_SOURCE -D_POSIX_C_SOURCE=200112L -D_DEFAULT_SOURCE -D_FILE_OFFSET_BITS=64 +CFLAGS += -D_BSD_SOURCE -D_POSIX_SOURCE -D_POSIX_C_SOURCE=200112L -D_DEFAULT_SOURCE -D_FILE_OFFSET_BITS=64 +CFLAGS += -DPROJECT_NAME=\"${PROJECT_NAME}\" -DPROJECT_AUTHOR=\"${PROJECT_AUTHOR}\" -DPROJECT_VERSION=\"${PROJECT_VERSION}\" BUILD := build SOURCES := source diff --git a/README.md b/README.md index e717b17..4d78deb 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,7 @@ Usage: -------------- ``` -wad2bin v0.7 (c) DarkMatterCore. -Built: 16:57:46 Jul 1 2020. - -Usage: wad2bin [ [--nullkey]] +wad2bin [ [--nullkey]] Paths must not exceed 259 characters. Relative paths are supported. The required directory tree for the *.bin file(s) will be created at the output directory. @@ -19,8 +16,6 @@ Notes about DLC support: * Parent title ID is only required if the input WAD is a DLC. A 16 character long hex string is expected. * If "--nullkey" is set after the parent title ID, a null key will be used to encrypt DLC content data. Some older games (like Rock Band 2) depend on this to properly load DLC data when launched via the Disc Channel. - -For more information, please visit: https://github.com/DarkMatterCore/wad2bin. ``` Building instructions: @@ -28,14 +23,16 @@ Building instructions: * **Windows** (should you really bother? 32-bit binaries are provided): 1. A collection of Unix/Linux utilities such as `make`, `mkdir`, `rm`, `ar` and `cp`, as well as a `gnu11` standard compliant C compiler, are needed to build this project. There are a few ways to achieve this under Windows: - * Install [TDM-GCC](https://jmeubank.github.io/tdm-gcc/download) and [devkitPro + MSYS2](https://devkitpro.org/wiki/Getting_Started#Windows), or... + * Install [TDM-GCC](https://jmeubank.github.io/tdm-gcc/download), or... + * Install [devkitPro + MSYS2](https://devkitpro.org/wiki/Getting_Started#Windows): + * Install the `gcc` package by using the `pacman -Syu` and `pacman -S gcc` commands. * Install [MinGW + MSYS](http://www.mingw.org/wiki/Getting_Started), or... * (Untested) Under Windows 10: * Install the [Windows Subsystem for Linux (WSL)](https://docs.microsoft.com/en-us/windows/wsl/install-win10) distribution of your preference (I'll assume you chose Ubuntu). * Install the `gcc` package by using the `sudo apt update` and `sudo apt install gcc` commands. * Modify the Makefiles to use `wsl.exe` before each Unix command call. * Regardless of the option you end up choosing, please make sure your `PATH` environment variable has been properly updated! - 2. Create a copy of `config.mk.template` in the same directory and rename it to `config.mk`. + 2. Create a copy of `config.mk.template` in the same directory and rename it to `config.mk`. Modify it if you need to change the compiler name/alias. 3. Build using the `make` command. * **Unix-like OS (Linux / MacOS)**: @@ -155,6 +152,11 @@ wad2bin is licensed under GPLv3 or (at your option) any later version. Changelog: -------------- +**v0.8:** + +* Print `errno` values as part of error messages whenever possible. +* Use GCC `format` function attribute on `utilsPrintErrorMessage()`. + **v0.7:** * Removed parent title ID generation for DLC WADs. This doesn't work properly with games that are capable of using DLCs from other games. diff --git a/source/bin.c b/source/bin.c index 058b0fc..a9b303f 100644 --- a/source/bin.c +++ b/source/bin.c @@ -176,7 +176,7 @@ bool binGenerateContentBinFromUnpackedInstallableWadPackage(os_char_t *unpacked_ opening_bnr = os_fopen(unpacked_wad_path, OS_MODE_READ); if (!opening_bnr) { - ERROR_MSG("Failed to open \"" OS_PRINT_STR "\" in read mode!", unpacked_wad_path); + ERROR_MSG("Failed to open \"" OS_PRINT_STR "\" in read mode! (%d).", unpacked_wad_path, errno); return false; } @@ -184,7 +184,7 @@ bool binGenerateContentBinFromUnpackedInstallableWadPackage(os_char_t *unpacked_ res = fread(&cntbin_header, 1, sizeof(BinContentHeader), opening_bnr); if (res != sizeof(BinContentHeader)) { - ERROR_MSG("Failed to read IMET header from \"" OS_PRINT_STR "\"!", unpacked_wad_path); + ERROR_MSG("Failed to read IMET header from \"" OS_PRINT_STR "\"! (%d).", unpacked_wad_path, errno); goto out; } @@ -254,7 +254,7 @@ bool binGenerateContentBinFromUnpackedInstallableWadPackage(os_char_t *unpacked_ content_bin = os_fopen(out_path, OS_MODE_WRITE); if (!content_bin) { - ERROR_MSG("Failed to open \"" OS_PRINT_STR "\" in write mode!", out_path); + ERROR_MSG("Failed to open \"" OS_PRINT_STR "\" in write mode! (%d).", out_path, errno); goto out; } @@ -301,7 +301,7 @@ bool binGenerateContentBinFromUnpackedInstallableWadPackage(os_char_t *unpacked_ res = fwrite(&cntbin_header, 1, sizeof(BinContentHeader), content_bin); if (res != sizeof(BinContentHeader)) { - ERROR_MSG("Failed to write encrypted header (Part A) to \"" OS_PRINT_STR "\"!", out_path); + ERROR_MSG("Failed to write encrypted header (Part A) to \"" OS_PRINT_STR "\"! (%d).", out_path, errno); goto out; } @@ -316,7 +316,7 @@ bool binGenerateContentBinFromUnpackedInstallableWadPackage(os_char_t *unpacked_ res = fwrite(icon_bin, 1, icon_bin_size, content_bin); if (res != icon_bin_size) { - ERROR_MSG("Failed to write encrypted icon.bin (Part B) to \"" OS_PRINT_STR "\"!", out_path); + ERROR_MSG("Failed to write encrypted icon.bin (Part B) to \"" OS_PRINT_STR "\"! (%d).", out_path, errno); goto out; } @@ -361,7 +361,7 @@ bool binGenerateContentBinFromUnpackedInstallableWadPackage(os_char_t *unpacked_ res = fwrite(&bk_header, 1, sizeof(WadBackupPackageHeader), content_bin); if (res != sizeof(WadBackupPackageHeader)) { - ERROR_MSG("Failed to write plaintext \"Bk\" header (Part C) to \"" OS_PRINT_STR "\"!", out_path); + ERROR_MSG("Failed to write plaintext \"Bk\" header (Part C) to \"" OS_PRINT_STR "\"! (%d).", out_path, errno); goto out; } @@ -372,7 +372,7 @@ bool binGenerateContentBinFromUnpackedInstallableWadPackage(os_char_t *unpacked_ res = fwrite(tmd->data, 1, aligned_tmd_size, content_bin); if (res != aligned_tmd_size) { - ERROR_MSG("Failed to write plaintext TMD (Part D) to \"" OS_PRINT_STR "\"!", out_path); + ERROR_MSG("Failed to write plaintext TMD (Part D) to \"" OS_PRINT_STR "\"! (%d).", out_path, errno); goto out; } @@ -404,7 +404,7 @@ bool binGenerateContentBinFromUnpackedInstallableWadPackage(os_char_t *unpacked_ cnt_fd = os_fopen(unpacked_wad_path, OS_MODE_READ); if (!cnt_fd) { - ERROR_MSG("Failed to open unpacked content \"" OS_PRINT_STR "\" in read mode!", unpacked_wad_path); + ERROR_MSG("Failed to open unpacked content \"" OS_PRINT_STR "\" in read mode! (%d).", unpacked_wad_path, errno); goto out; } @@ -477,7 +477,7 @@ bool binGenerateContentBinFromUnpackedInstallableWadPackage(os_char_t *unpacked_ res = fwrite(&cert_area, 1, sizeof(BinContentCertArea), content_bin); if (res != sizeof(BinContentCertArea)) { - ERROR_MSG("Failed to write plaintext certificate area (Part F) to \"" OS_PRINT_STR "\"!", out_path); + ERROR_MSG("Failed to write plaintext certificate area (Part F) to \"" OS_PRINT_STR "\"! (%d).", out_path, errno); goto out; } @@ -578,7 +578,7 @@ bool binGenerateIndexedPackagesFromUnpackedInstallableWadPackage(os_char_t *unpa cnt_fd = os_fopen(unpacked_wad_path, OS_MODE_READ); if (!cnt_fd) { - printf("Content \"" OS_PRINT_STR "\" not found. Skipping...\n\n", unpacked_wad_path); + printf("Content \"" OS_PRINT_STR "\" not found (%d). Skipping...\n\n", unpacked_wad_path, errno); continue; } @@ -587,7 +587,7 @@ bool binGenerateIndexedPackagesFromUnpackedInstallableWadPackage(os_char_t *unpa if (!indexed_bin) { fclose(cnt_fd); - ERROR_MSG("Failed to open \"" OS_PRINT_STR "\" in write mode!", out_path); + ERROR_MSG("Failed to open \"" OS_PRINT_STR "\" in write mode! (%d).", out_path, errno); goto out; } @@ -624,7 +624,7 @@ bool binGenerateIndexedPackagesFromUnpackedInstallableWadPackage(os_char_t *unpa { fclose(indexed_bin); fclose(cnt_fd); - ERROR_MSG("Failed to write plaintext \"Bk\" header to \"" OS_PRINT_STR "\"!", out_path); + ERROR_MSG("Failed to write plaintext \"Bk\" header to \"" OS_PRINT_STR "\"! (%d).", out_path, errno); goto out; } @@ -634,7 +634,7 @@ bool binGenerateIndexedPackagesFromUnpackedInstallableWadPackage(os_char_t *unpa { fclose(indexed_bin); fclose(cnt_fd); - ERROR_MSG("Failed to write plaintext TMD to \"" OS_PRINT_STR "\"!", out_path); + ERROR_MSG("Failed to write plaintext TMD to \"" OS_PRINT_STR "\"! (%d).", out_path, errno); goto out; } diff --git a/source/cert.c b/source/cert.c index 71789a8..3ac590c 100644 --- a/source/cert.c +++ b/source/cert.c @@ -56,7 +56,7 @@ bool certReadCertificateChainFromFile(FILE *fd, u64 cert_chain_size, Certificate res = fread(out_chain->raw_chain, 1, cert_chain_size, fd); if (res != cert_chain_size) { - ERROR_MSG("Failed to read 0x%" PRIx64 " bytes long raw certificate chain!", cert_chain_size); + ERROR_MSG("Failed to read 0x%" PRIx64 " bytes long raw certificate chain! (%d).", cert_chain_size, errno); goto out; } diff --git a/source/keys.c b/source/keys.c index 0f3423f..fe911d9 100644 --- a/source/keys.c +++ b/source/keys.c @@ -424,7 +424,7 @@ static bool keysReadKeysFromFile(const os_char_t *keys_file_path) keys_file = os_fopen(keys_file_path, OS_MODE_READ); if (!keys_file) { - ERROR_MSG("Unable to open \"" OS_PRINT_STR "\" to retrieve keys!", keys_file_path); + ERROR_MSG("Unable to open \"" OS_PRINT_STR "\" to retrieve keys! (%d).", keys_file_path, errno); return false; } diff --git a/source/main.c b/source/main.c index d795faa..16e46d7 100644 --- a/source/main.c +++ b/source/main.c @@ -44,8 +44,8 @@ int main(int argc, char **argv) u32 required_ios = 0, tid_upper = 0; bool use_null_key = false; - printf("\nwad2bin v%s (c) DarkMatterCore.\n", VERSION); - printf("Built: %s %s.\n\n", __TIME__, __DATE__); + printf("\n" PROJECT_NAME " v" PROJECT_VERSION " (c) " PROJECT_AUTHOR ".\n"); + printf("Built on: %s %s.\n\n", __TIME__, __DATE__); if (argc < (PATH_COUNT + 1) || argc > (PATH_COUNT + 3) || strlen(argv[1]) >= MAX_PATH || strlen(argv[2]) >= MAX_PATH || strlen(argv[3]) >= MAX_PATH || \ (strlen(argv[4]) + SD_CONTENT_PATH_MAX_LENGTH) >= MAX_PATH || (argc >= (PATH_COUNT + 2) && strlen(argv[5]) != 16) || (argc == (PATH_COUNT + 3) && (strlen(argv[6]) != strlen(NULL_KEY_ARG) || \ @@ -59,7 +59,7 @@ int main(int argc, char **argv) printf("* Parent title ID is only required if the input WAD is a DLC. A 16 character long hex string is expected.\n"); printf("* If \"" NULL_KEY_ARG "\" is set after the parent title ID, a null key will be used to encrypt DLC content data.\n"); printf(" Some older games (like Rock Band 2) depend on this to properly load DLC data when launched via the Disc Channel.\n\n"); - printf("For more information, please visit: https://github.com/DarkMatterCore/wad2bin.\n\n"); + printf("For more information, please visit: https://github.com/" PROJECT_AUTHOR "/" PROJECT_NAME ".\n\n"); ret = -1; goto out; } @@ -90,7 +90,7 @@ int main(int argc, char **argv) if (i == PATH_COUNT) { /* Save temporary path and create it. */ - os_snprintf(paths[i], MAX_PATH, "." OS_PATH_SEPARATOR "wad2bin_wad_data"); + os_snprintf(paths[i], MAX_PATH, "." OS_PATH_SEPARATOR PROJECT_NAME "_wad_data"); os_mkdir(paths[i], 0777); } else { #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) diff --git a/source/tik.c b/source/tik.c index 61dc019..918790f 100644 --- a/source/tik.c +++ b/source/tik.c @@ -50,7 +50,7 @@ bool tikReadTicketFromFile(FILE *fd, u64 ticket_size, Ticket *out_ticket, Certif res = fread(out_ticket->data, 1, ticket_size, fd); if (res != ticket_size) { - ERROR_MSG("Failed to read 0x%" PRIx64 " bytes long ticket!", ticket_size); + ERROR_MSG("Failed to read 0x%" PRIx64 " bytes long ticket! (%d).", ticket_size, errno); goto out; } diff --git a/source/tmd.c b/source/tmd.c index 500d98f..1a5001e 100644 --- a/source/tmd.c +++ b/source/tmd.c @@ -50,7 +50,7 @@ bool tmdReadTitleMetadataFromFile(FILE *fd, u64 tmd_size, TitleMetadata *out_tmd res = fread(out_tmd->data, 1, tmd_size, fd); if (res != tmd_size) { - ERROR_MSG("Failed to read 0x%" PRIx64 " bytes long TMD!", tmd_size); + ERROR_MSG("Failed to read 0x%" PRIx64 " bytes long TMD! (%d).", tmd_size, errno); goto out; } diff --git a/source/types.h b/source/types.h index f09861f..6bdcae2 100644 --- a/source/types.h +++ b/source/types.h @@ -12,17 +12,22 @@ /// Creates a bitmask from a bit number. #ifndef BIT -#define BIT(n) (1U << (n)) +#define BIT(n) (1U << (n)) #endif /// Packs a struct so that it won't include padding bytes. #ifndef PACKED -#define PACKED __attribute__((packed)) +#define PACKED __attribute__((packed)) #endif /// Flags a function as (always) inline. #ifndef ALWAYS_INLINE -#define ALWAYS_INLINE __attribute__((always_inline)) static inline +#define ALWAYS_INLINE __attribute__((always_inline)) static inline +#endif + +/// Flags a function as printf-like. +#ifndef PRINTF_FORMAT +#define PRINTF_FORMAT(idx, arg) __attribute__((format(gnu_printf, idx, arg))) #endif typedef uint8_t u8; ///< 8-bit unsigned integer. diff --git a/source/u8.c b/source/u8.c index 80cbe97..95783a3 100644 --- a/source/u8.c +++ b/source/u8.c @@ -48,7 +48,7 @@ bool u8ContextInit(FILE *u8_fd, U8Context *ctx) res = fread(&u8_header, 1, sizeof(U8Header), u8_fd); if (res != sizeof(U8Header)) { - ERROR_MSG("Failed to read U8 header!"); + ERROR_MSG("Failed to read U8 header! (%d).", errno); return false; } @@ -70,7 +70,7 @@ bool u8ContextInit(FILE *u8_fd, U8Context *ctx) res = fread(&root_node, 1, sizeof(U8Node), u8_fd); if (res != sizeof(U8Node)) { - ERROR_MSG("Failed to read root U8 node!"); + ERROR_MSG("Failed to read root U8 node! (%d).", errno); return false; } @@ -114,7 +114,7 @@ bool u8ContextInit(FILE *u8_fd, U8Context *ctx) res = fread(nodes + 1, 1, sizeof(U8Node) * (node_count - 1), u8_fd); if (res != (sizeof(U8Node) * (node_count - 1))) { - ERROR_MSG("Failed to read U8 nodes!"); + ERROR_MSG("Failed to read U8 nodes! (%d).", errno); goto out; } @@ -130,7 +130,7 @@ bool u8ContextInit(FILE *u8_fd, U8Context *ctx) res = fread(str_table, 1, str_table_size, u8_fd); if (res != str_table_size) { - ERROR_MSG("Failed to read U8 string table!"); + ERROR_MSG("Failed to read U8 string table! (%d).", errno); goto out; } @@ -356,7 +356,7 @@ u8 *u8LoadFileData(U8Context *ctx, U8Node *file_node, u64 *out_size) { *out_size = file_node->size; } else { - ERROR_MSG("Failed to read file data from U8 node!"); + ERROR_MSG("Failed to read file data from U8 node! (%d).", errno); free(buf); buf = NULL; } diff --git a/source/utils.c b/source/utils.c index bb2c25f..4311528 100644 --- a/source/utils.c +++ b/source/utils.c @@ -22,7 +22,7 @@ #include "utils.h" #include "ConvertUTF.h" -void utilsPrintErrorMessage(const char *func_name, const char *fmt, ...) +PRINTF_FORMAT(2, 3) void utilsPrintErrorMessage(const char *func_name, const char *fmt, ...) { va_list args; @@ -81,7 +81,7 @@ bool utilsReadDataFromFile(const os_char_t *file_path, void *buf, u64 expected_s fd = os_fopen(file_path, OS_MODE_READ); if (!fd) { - ERROR_MSG("Failed to open \"" OS_PRINT_STR "\" in read mode!", file_path); + ERROR_MSG("Failed to open \"" OS_PRINT_STR "\" in read mode! (%d).", file_path, errno); return false; } @@ -101,7 +101,7 @@ bool utilsReadDataFromFile(const os_char_t *file_path, void *buf, u64 expected_s res = fread(buf, 1, expected_size, fd); if (res != expected_size) { - ERROR_MSG("Unable to read 0x%" PRIx64 " bytes block from \"" OS_PRINT_STR "\"!", expected_size, file_path); + ERROR_MSG("Unable to read 0x%" PRIx64 " bytes block from \"" OS_PRINT_STR "\"! (%d).", expected_size, file_path, errno); goto out; } @@ -129,7 +129,7 @@ bool utilsWriteDataToFile(const os_char_t *out_path, const void *buf, u64 size) fd = os_fopen(out_path, OS_MODE_WRITE); if (!fd) { - ERROR_MSG("Failed to open \"" OS_PRINT_STR "\" in write mode!", out_path); + ERROR_MSG("Failed to open \"" OS_PRINT_STR "\" in write mode! (%d).", out_path, errno); return false; } @@ -137,7 +137,7 @@ bool utilsWriteDataToFile(const os_char_t *out_path, const void *buf, u64 size) res = fwrite(buf, 1, size, fd); if (res != size) { - ERROR_MSG("Failed to write 0x%" PRIx64 " bytes block to \"" OS_PRINT_STR "\"!", size, out_path); + ERROR_MSG("Failed to write 0x%" PRIx64 " bytes block to \"" OS_PRINT_STR "\"! (%d).", size, out_path, errno); success = false; } @@ -193,7 +193,7 @@ bool utilsRemoveDirectoryRecursively(const os_char_t *dir_path) /* Open directory. */ if (!(dir = os_opendir(dir_path))) { - ERROR_MSG("Error opening directory \"" OS_PRINT_STR "\"!", dir_path); + ERROR_MSG("Error opening directory \"" OS_PRINT_STR "\"! (%d).", dir_path, errno); return false; } @@ -220,7 +220,7 @@ bool utilsRemoveDirectoryRecursively(const os_char_t *dir_path) /* Get entry status */ if (os_stat(name_buf, &st) < 0) { - ERROR_MSG("Failed to get entry status for \"" OS_PRINT_STR "\"!", name_buf); + ERROR_MSG("Failed to get entry status for \"" OS_PRINT_STR "\"! (%d).", name_buf, errno); success = false; break; } diff --git a/source/utils.h b/source/utils.h index 74eefdc..2924760 100644 --- a/source/utils.h +++ b/source/utils.h @@ -27,8 +27,6 @@ #include "types.h" #include "os.h" -#define VERSION "0.7" - /* Supress clang warnings about variadic macro arguments. */ #ifdef __clang__ #pragma clang diagnostic push @@ -67,7 +65,7 @@ /* "%s" is replaced by the desired filename using *printf functions. */ #define PRIVATE_PATH(dir) OS_PATH_SEPARATOR "private" OS_PATH_SEPARATOR "wii" OS_PATH_SEPARATOR dir OS_PATH_SEPARATOR "%s" -void utilsPrintErrorMessage(const char *func_name, const char *fmt, ...); +PRINTF_FORMAT(2, 3) void utilsPrintErrorMessage(const char *func_name, const char *fmt, ...); bool utilsConvertUTF8ToUTF16(os_char_t *dst, const char *src); diff --git a/source/wad.c b/source/wad.c index dfc0452..5297a6b 100644 --- a/source/wad.c +++ b/source/wad.c @@ -66,7 +66,7 @@ bool wadUnpackInstallablePackage(const os_char_t *wad_path, os_char_t *out_path, wad_fd = os_fopen(wad_path, OS_MODE_READ); if (!wad_fd) { - ERROR_MSG("Unable to open \"" OS_PRINT_STR "\" for reading!", wad_path); + ERROR_MSG("Unable to open \"" OS_PRINT_STR "\" for reading! (%d).", wad_path, errno); goto out; } @@ -85,7 +85,7 @@ bool wadUnpackInstallablePackage(const os_char_t *wad_path, os_char_t *out_path, res = fread(&wad_header, 1, sizeof(WadInstallablePackageHeader), wad_fd); if (res != sizeof(WadInstallablePackageHeader)) { - ERROR_MSG("Failed to read WAD header from \"" OS_PRINT_STR "\"!", wad_path); + ERROR_MSG("Failed to read WAD header from \"" OS_PRINT_STR "\"! (%d).", wad_path, errno); goto out; } @@ -402,7 +402,7 @@ bool wadWriteUnpackedContentToPackage(FILE *wad_fd, const u8 *titlekey, const u8 res = fread(buf, 1, blksize, cnt_fd); if (res != blksize) { - ERROR_MSG("Failed to read 0x%" PRIx64 " bytes plaintext chunk at offset 0x%" PRIx64 " from content \"%08" PRIx16 ".app\"!", blksize, offset, cnt_idx); + ERROR_MSG("Failed to read 0x%" PRIx64 " bytes plaintext chunk at offset 0x%" PRIx64 " from content \"%08" PRIx16 ".app\"! (%d).", blksize, offset, cnt_idx, errno); goto out; } @@ -427,7 +427,7 @@ bool wadWriteUnpackedContentToPackage(FILE *wad_fd, const u8 *titlekey, const u8 res = fwrite(buf, 1, write_size, wad_fd); if (res != write_size) { - ERROR_MSG("Failed to write 0x%" PRIx64 " bytes encrypted chunk at offset 0x%" PRIx64 " from content \"%08" PRIx16 ".app\"!", write_size, offset, cnt_idx); + ERROR_MSG("Failed to write 0x%" PRIx64 " bytes encrypted chunk at offset 0x%" PRIx64 " from content \"%08" PRIx16 ".app\"! (%d).", write_size, offset, cnt_idx, errno); goto out; } @@ -479,7 +479,7 @@ bool wadGenerateBogusInstallablePackage(os_char_t *out_path, CertificateChain *c wad_fd = os_fopen(out_path, OS_MODE_WRITE); if (!wad_fd) { - ERROR_MSG("Failed to open \"" OS_PRINT_STR "\" in write mode!", out_path); + ERROR_MSG("Failed to open \"" OS_PRINT_STR "\" in write mode! (%d).", out_path, errno); goto out; } @@ -498,7 +498,7 @@ bool wadGenerateBogusInstallablePackage(os_char_t *out_path, CertificateChain *c res = fwrite(&wad_header, 1, sizeof(WadInstallablePackageHeader), wad_fd); if (res != sizeof(WadInstallablePackageHeader)) { - ERROR_MSG("Failed to write installable WAD header to \"" OS_PRINT_STR "\"!", out_path); + ERROR_MSG("Failed to write installable WAD header to \"" OS_PRINT_STR "\"! (%d).", out_path, errno); goto out; } @@ -506,7 +506,7 @@ bool wadGenerateBogusInstallablePackage(os_char_t *out_path, CertificateChain *c res = fwrite(cert_chain->raw_chain, 1, aligned_cert_chain_size, wad_fd); if (res != aligned_cert_chain_size) { - ERROR_MSG("Failed to write certificate chain to \"" OS_PRINT_STR "\"!", out_path); + ERROR_MSG("Failed to write certificate chain to \"" OS_PRINT_STR "\"! (%d).", out_path, errno); goto out; } @@ -514,7 +514,7 @@ bool wadGenerateBogusInstallablePackage(os_char_t *out_path, CertificateChain *c res = fwrite(ticket->data, 1, aligned_ticket_size, wad_fd); if (res != aligned_ticket_size) { - ERROR_MSG("Failed to write ticket to \"" OS_PRINT_STR "\"!", out_path); + ERROR_MSG("Failed to write ticket to \"" OS_PRINT_STR "\"! (%d).", out_path, errno); goto out; } @@ -522,7 +522,7 @@ bool wadGenerateBogusInstallablePackage(os_char_t *out_path, CertificateChain *c res = fwrite(tmd->data, 1, aligned_tmd_size, wad_fd); if (res != aligned_tmd_size) { - ERROR_MSG("Failed to write TMD to \"" OS_PRINT_STR "\"!", out_path); + ERROR_MSG("Failed to write TMD to \"" OS_PRINT_STR "\"! (%d).", out_path, errno); goto out; } @@ -589,7 +589,7 @@ static bool wadUnpackContentFromInstallablePackage(FILE *wad_fd, const u8 *title cnt_fd = os_fopen(out_path, OS_MODE_WRITE); if (!cnt_fd) { - ERROR_MSG("Failed to open content file in write mode!"); + ERROR_MSG("Failed to open content file in write mode! (%d).", errno); goto out; } @@ -604,7 +604,7 @@ static bool wadUnpackContentFromInstallablePackage(FILE *wad_fd, const u8 *title res = fread(buf, 1, read_size, wad_fd); if (res != read_size) { - ERROR_MSG("Failed to read 0x%" PRIx64 " bytes encrypted chunk from content offset 0x%" PRIx64 "!", read_size, offset); + ERROR_MSG("Failed to read 0x%" PRIx64 " bytes encrypted chunk from content offset 0x%" PRIx64 "! (%d).", read_size, offset, errno); goto out; } @@ -622,7 +622,7 @@ static bool wadUnpackContentFromInstallablePackage(FILE *wad_fd, const u8 *title res = fwrite(buf, 1, blksize, cnt_fd); if (res != blksize) { - ERROR_MSG("Failed to write 0x%" PRIx64 " bytes decrypted chunk from content offset 0x%" PRIx64 "!", blksize, offset); + ERROR_MSG("Failed to write 0x%" PRIx64 " bytes decrypted chunk from content offset 0x%" PRIx64 "! (%d).", blksize, offset, errno); goto out; }