mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-20 01:49:59 -04:00
Import the base tree (MIT, see LICENSE)
This commit is contained in:
20
tools/hactool/mbedtls-asm-clobbers.patch
Normal file
20
tools/hactool/mbedtls-asm-clobbers.patch
Normal file
@@ -0,0 +1,20 @@
|
||||
Applied by tools/build_hactool.py to SciresM/hactool (ISC) at 1d64a83450e025622f3468c28fc4164dad2c5ef6, ours.
|
||||
The x86-64 multiply-accumulate asm of hactool's bundled mbedtls 2.6.1 (MULADDC in bn_mul.h) adds into memory through
|
||||
rdi and changes the flags without saying so. gcc happens to keep that code correct; clang (the Linux release's
|
||||
toolchain) keeps memory values in registers across it at -O1 and above, the RSA arithmetic goes wrong, and every
|
||||
signature check fails (NCA header, NPDM, ACID), which stops the merge of the update. Later mbedtls releases name the
|
||||
same two clobbers.
|
||||
|
||||
diff --git a/mbedtls/include/mbedtls/bn_mul.h b/mbedtls/include/mbedtls/bn_mul.h
|
||||
index cac3f14..c787b0a 100644
|
||||
--- a/mbedtls/include/mbedtls/bn_mul.h
|
||||
+++ b/mbedtls/include/mbedtls/bn_mul.h
|
||||
@@ -179,7 +179,7 @@
|
||||
#define MULADDC_STOP \
|
||||
: "+c" (c), "+D" (d), "+S" (s) \
|
||||
: "b" (b) \
|
||||
- : "rax", "rdx", "r8" \
|
||||
+ : "rax", "rdx", "r8", "memory", "cc" \
|
||||
);
|
||||
|
||||
#endif /* AMD64 */
|
||||
43
tools/hactool/portable.patch
Normal file
43
tools/hactool/portable.patch
Normal file
@@ -0,0 +1,43 @@
|
||||
Applied by tools/build_hactool.py to SciresM/hactool (ISC) at 1d64a83450e025622f3468c28fc4164dad2c5ef6.
|
||||
From MacNativeGames build_app.py build_hactool() (MIT, Copyright (c) 2026 MacNativeGames contributors), the parts
|
||||
that run on Windows: 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. Its funopen base-range hook is macOS-only and left out.
|
||||
|
||||
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;
|
||||
62
tools/hactool/unicode.patch
Normal file
62
tools/hactool/unicode.patch
Normal file
@@ -0,0 +1,62 @@
|
||||
Applied by tools/build_hactool.py after portable.patch. Ours: a manifest embedded through hactool.rc makes UTF-8 the
|
||||
process code page (Windows 10 1903 and later), so paths and user profiles with non-ASCII names reach filepath.c intact.
|
||||
|
||||
diff --git a/Makefile b/Makefile
|
||||
index e1913b8..73b7e3f 100644
|
||||
--- a/Makefile
|
||||
+++ b/Makefile
|
||||
@@ -13,9 +13,19 @@ all:
|
||||
.c.o:
|
||||
$(CC) $(INCLUDE) -c $(CFLAGS) -o $@ $<
|
||||
|
||||
-hactool$(EXEEXT): save.o sha.o aes.o extkeys.o rsa.o npdm.o bktr.o kip.o packages.o pki.o pfs0.o hfs0.o nca0_romfs.o romfs.o utils.o nax0.o nso.o lz4.o nca.o xci.o main.o filepath.o ConvertUTF.o cJSON.o
|
||||
+# Windows: a manifest makes UTF-8 the process code page (Windows 10 1903 and later), so argv, getenv and fopen carry
|
||||
+# UTF-8 as filepath.c expects: paths and user profiles with non-ASCII names work.
|
||||
+ifeq ($(EXEEXT),.exe)
|
||||
+WINDRES ?= windres
|
||||
+RESOURCES = hactool.res.o
|
||||
+endif
|
||||
+
|
||||
+hactool$(EXEEXT): save.o sha.o aes.o extkeys.o rsa.o npdm.o bktr.o kip.o packages.o pki.o pfs0.o hfs0.o nca0_romfs.o romfs.o utils.o nax0.o nso.o lz4.o nca.o xci.o main.o filepath.o ConvertUTF.o cJSON.o $(RESOURCES)
|
||||
$(CC) -o $@ $^ -L $(LIBDIR) $(LDFLAGS)
|
||||
|
||||
+hactool.res.o: hactool.rc hactool.manifest
|
||||
+ $(WINDRES) -O coff hactool.rc -o $@
|
||||
+
|
||||
aes.o: aes.h types.h
|
||||
|
||||
bktr.o: bktr.h types.h
|
||||
diff --git a/hactool.manifest b/hactool.manifest
|
||||
new file mode 100644
|
||||
index 0000000..4073219
|
||||
--- /dev/null
|
||||
+++ b/hactool.manifest
|
||||
@@ -0,0 +1,20 @@
|
||||
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||
+ <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
+ <security>
|
||||
+ <requestedPrivileges>
|
||||
+ <requestedExecutionLevel level="asInvoker"/>
|
||||
+ </requestedPrivileges>
|
||||
+ </security>
|
||||
+ </trustInfo>
|
||||
+ <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||
+ <application>
|
||||
+ <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
|
||||
+ </application>
|
||||
+ </compatibility>
|
||||
+ <application xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
+ <windowsSettings>
|
||||
+ <activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">UTF-8</activeCodePage>
|
||||
+ </windowsSettings>
|
||||
+ </application>
|
||||
+</assembly>
|
||||
diff --git a/hactool.rc b/hactool.rc
|
||||
new file mode 100644
|
||||
index 0000000..543aa10
|
||||
--- /dev/null
|
||||
+++ b/hactool.rc
|
||||
@@ -0,0 +1,2 @@
|
||||
+/* Windows: argv, getenv and the narrow file functions use UTF-8 (Windows 10 1903 and later), as filepath.c expects. */
|
||||
+1 24 "hactool.manifest"
|
||||
Reference in New Issue
Block a user