save: Full support for save reading

This commit is contained in:
shchmue 2019-10-18 11:19:46 -06:00
parent 884a0cf437
commit a62152cb6e
3 changed files with 26 additions and 3 deletions

View file

@ -13,7 +13,7 @@ all:
.c.o:
$(CC) $(INCLUDE) -c $(CFLAGS) -o $@ $<
hactool: 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
hactool: 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
$(CC) -o $@ $^ $(LDFLAGS) -L $(LIBDIR)
aes.o: aes.h types.h
@ -52,6 +52,8 @@ nca0_romfs.o: nca0_romfs.h ivfc.h types.h
rsa.o: rsa.h sha.h types.h
save.o: save.h ivfc.h aes.h sha.h filepath.h types.h
sha.o: sha.h types.h
utils.o: utils.h types.h

21
main.c
View file

@ -13,6 +13,7 @@
#include "extkeys.h"
#include "packages.h"
#include "nso.h"
#include "save.h"
static const char *prog_name = "hactool";
@ -97,6 +98,9 @@ static void usage(void) {
"NAX0 options:\n"
" --sdseed=seed Set console unique seed for SD card NAX0 encryption.\n"
" --sdpath=path Set relative path for NAX0 key derivation (ex: /registered/000000FF/cafebabecafebabecafebabecafebabe.nca).\n"
"Save data options:\n"
" --outdir=dir Specify save directory path.\n"
" --listfiles List files in save file."
"Key Derivation options:\n"
" --sbk=key Set console unique Secure Boot Key for key derivation.\n"
" --tseckey=key Set console unique TSEC Key for key derivation.\n"
@ -110,7 +114,7 @@ int main(int argc, char **argv) {
nca_ctx_t nca_ctx;
char input_name[0x200];
filepath_t keypath;
prog_name = (argc < 1) ? "hactool" : argv[0];
nca_init(&nca_ctx);
@ -180,6 +184,7 @@ int main(int argc, char **argv) {
{"saveini1json", 0, NULL, 38},
{"uncompressed", 1, NULL, 39},
{"disablekeywarns", 0, NULL, 40},
{"listfiles", 0, NULL, 41},
{NULL, 0, NULL, 0},
};
@ -237,6 +242,8 @@ int main(int argc, char **argv) {
nca_ctx.tool_ctx->file_type = FILETYPE_NAX0;
} else if (!strcmp(optarg, "keygen") || !strcmp(optarg, "keys") || !strcmp(optarg, "boot0") || !strcmp(optarg, "boot")) {
nca_ctx.tool_ctx->file_type = FILETYPE_BOOT0;
} else if (!strcmp(optarg, "save")) {
nca_ctx.tool_ctx->file_type = FILETYPE_SAVE;
}
break;
case 0: filepath_set(&nca_ctx.tool_ctx->settings.section_paths[0], optarg); break;
@ -390,6 +397,9 @@ int main(int argc, char **argv) {
case 40:
nca_ctx.tool_ctx->settings.skip_key_warnings = 1;
break;
case 41:
nca_ctx.tool_ctx->action |= ACTION_LISTFILES;
break;
default:
usage();
return EXIT_FAILURE;
@ -675,6 +685,15 @@ int main(int argc, char **argv) {
pki_print_keys(&new_keyset);
break;
}
case FILETYPE_SAVE: {
save_ctx_t save_ctx;
memset(&save_ctx, 0, sizeof(save_ctx));
save_ctx.file = tool_ctx.file;
save_ctx.tool_ctx = &tool_ctx;
save_process(&save_ctx);
save_free_contexts(&save_ctx);
break;
}
default: {
fprintf(stderr, "Unknown File Type!\n\n");
usage();

View file

@ -130,7 +130,8 @@ enum hactool_file_type
FILETYPE_KIP1,
FILETYPE_NSO0,
FILETYPE_NAX0,
FILETYPE_BOOT0
FILETYPE_BOOT0,
FILETYPE_SAVE
};
#define ACTION_INFO (1<<0)
@ -142,6 +143,7 @@ enum hactool_file_type
#define ACTION_EXTRACTINI1 (1<<6)
#define ACTION_ONLYUPDATEDROMFS (1<<7)
#define ACTION_SAVEINIJSON (1<<8)
#define ACTION_LISTFILES (1<<9)
struct nca_ctx; /* This will get re-defined by nca.h. */