Files
NX2navi/tools/hactool/portable.patch
chrg6 1b39aabd37 Describe what the code does in comments and docs.
Comments say what the code does and why, docs/maxwell.md keeps the Maxwell facts, and fetch_refs.sh clones only the checkout the build reads. Code is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 05:04:40 -05:00

43 lines
2.2 KiB
Diff

Applied by tools/build_hactool.py to hactool (ISC) at 1d64a83450e025622f3468c28fc4164dad2c5ef6.
Copyright (c) 2026 MacNativeGames contributors (MIT; see THIRD_PARTY_NOTICES.md). MNG_TITLE_KEYS names the title-key
file, and the BKTR checks accept the subsection table padding and the subsection layout of newer cumulative updates.
diff --git a/main.c b/main.c
index 07f53cb..7921cc4 100644
--- a/main.c
+++ b/main.c
@@ -472,7 +472,7 @@ int main(int argc, char **argv) {
}
/* Try to load titlekeys. */
- FILE *titlekeyfile = open_key_file("title");
+ FILE *titlekeyfile = getenv("MNG_TITLE_KEYS") ? fopen(getenv("MNG_TITLE_KEYS"), "rb") : open_key_file("title");
if (titlekeyfile != NULL) {
extkeys_parse_titlekeys(&tool_ctx.settings, titlekeyfile);
}
diff --git a/nca.c b/nca.c
index 8a84366..2fe877f 100644
--- a/nca.c
+++ b/nca.c
@@ -1149,7 +1149,8 @@ void nca_process_bktr_section(nca_section_ctx_t *ctx) {
/* Validate magics. */
if (sb->relocation_header.magic == MAGIC_BKTR && sb->subsection_header.magic == MAGIC_BKTR) {
if (sb->relocation_header.offset + sb->relocation_header.size != sb->subsection_header.offset ||
- sb->subsection_header.offset + sb->subsection_header.size != ctx->size) {
+ sb->subsection_header.offset + sb->subsection_header.size > ctx->size ||
+ (ctx->size - (sb->subsection_header.offset + sb->subsection_header.size)) % 0x200 != 0) {
fprintf(stderr, "Invalid BKTR layout!\n");
exit(EXIT_FAILURE);
}
@@ -1180,7 +1181,9 @@ void nca_process_bktr_section(nca_section_ctx_t *ctx) {
ctx->bktr_ctx.relocation_block = relocs;
ctx->bktr_ctx.subsection_block = subs;
- if (ctx->bktr_ctx.subsection_block->total_size != sb->subsection_header.offset) {
+ if (ctx->bktr_ctx.subsection_block->total_size != sb->subsection_header.offset &&
+ (sb->relocation_header.size > sb->subsection_header.offset ||
+ ctx->bktr_ctx.subsection_block->total_size != sb->subsection_header.offset - sb->relocation_header.size)) {
free(relocs);
free(subs);
ctx->bktr_ctx.relocation_block = NULL;