Skip to content

Commit

Permalink
Update to v0.8.
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkMatterCore committed Aug 12, 2021
1 parent fabda9c commit 0064709
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 68 deletions.
16 changes: 8 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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.*
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ Usage:
--------------

```
wad2bin v0.7 (c) DarkMatterCore.
Built: 16:57:46 Jul 1 2020.
Usage: wad2bin <keys.txt> <device.cert> <input WAD> <output dir> [<parent title ID> [--nullkey]]
wad2bin <keys.txt> <device.cert> <input WAD> <output dir> [<parent title ID> [--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.
Expand All @@ -19,23 +16,23 @@ 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:
--------------

* **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)**:
Expand Down Expand Up @@ -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.
Expand Down
26 changes: 13 additions & 13 deletions source/bin.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,15 @@ 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;
}

/* Read full IMET header. */
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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion source/cert.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion source/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
8 changes: 4 additions & 4 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) || \
Expand All @@ -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;
}
Expand Down Expand Up @@ -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__)
Expand Down
2 changes: 1 addition & 1 deletion source/tik.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion source/tmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
11 changes: 8 additions & 3 deletions source/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions source/u8.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down
Loading

0 comments on commit 0064709

Please sign in to comment.