From bb0d3093040905677b2b8035b095bac2a3e3fe1f Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 19 Feb 2021 13:41:28 +0100 Subject: [PATCH] amii tool now using fileutils --- client/deps/amiitool/Makefile | 2 +- client/deps/amiitool/amiibo.c | 25 ++++++++++++++++--------- client/deps/amiitool/amiibo.h | 2 +- client/deps/amiitool/amiitool.c | 9 --------- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/client/deps/amiitool/Makefile b/client/deps/amiitool/Makefile index dd064227e..f72a675d8 100644 --- a/client/deps/amiitool/Makefile +++ b/client/deps/amiitool/Makefile @@ -1,5 +1,5 @@ MYSRCPATHS = -MYINCLUDES = -I. -I.. -I../jansson -I../../../common -I../../../common/mbedtls -I../../../include +MYINCLUDES = -I. -I.. -I../../../common -I../../../common/mbedtls -I../../../include -I../../src -I../../../include -I../jansson MYCFLAGS = MYDEFS = MYSRCS = \ diff --git a/client/deps/amiitool/amiibo.c b/client/deps/amiitool/amiibo.c index cbe3a0ba0..d41a291fa 100644 --- a/client/deps/amiitool/amiibo.c +++ b/client/deps/amiitool/amiibo.c @@ -9,7 +9,9 @@ #include "md.h" #include "aes.h" #include "commonutil.h" +#include "../src/fileutils.h" +#pragma endregion #define HMAC_POS_DATA 0x008 #define HMAC_POS_TAG 0x1B4 @@ -131,24 +133,29 @@ void nfc3d_amiibo_pack(const nfc3d_amiibo_keys *amiiboKeys, const uint8_t *plain nfc3d_amiibo_internal_to_tag(cipher, tag); } -bool nfc3d_amiibo_load_keys(nfc3d_amiibo_keys *amiiboKeys, const char *path) { - FILE *f = fopen(path, "rb"); - if (!f) { +bool nfc3d_amiibo_load_keys(nfc3d_amiibo_keys *amiiboKeys) { + +#define amiboo_key_fn "key_retail.bin" + + uint8_t *dump = NULL; + size_t bytes_read = 0; + if (loadFile_safe(amiboo_key_fn, "", (void **)&dump, &bytes_read) != PM3_SUCCESS) { + PrintAndLogEx(FAILED, "File: " _YELLOW_("%s") ": not found or locked.", amiboo_key_fn); return false; } - size_t len = fread(amiiboKeys, sizeof(*amiiboKeys), 1, f); - fclose(f); - - if (len != sizeof(*amiiboKeys)) { + if (bytes_read != sizeof(*amiiboKeys)) { + free(dump); return false; } - if ((amiiboKeys->data.magicBytesSize > 16) || - (amiiboKeys->tag.magicBytesSize > 16)) { + if ((amiiboKeys->data.magicBytesSize > 16) || (amiiboKeys->tag.magicBytesSize > 16)) { + free(dump); return false; } + memcpy(amiiboKeys, dump, bytes_read); + free(dump); return true; } diff --git a/client/deps/amiitool/amiibo.h b/client/deps/amiitool/amiibo.h index 47d544875..4ba0db7cd 100644 --- a/client/deps/amiitool/amiibo.h +++ b/client/deps/amiitool/amiibo.h @@ -25,7 +25,7 @@ typedef struct { bool nfc3d_amiibo_unpack(const nfc3d_amiibo_keys *amiiboKeys, const uint8_t *tag, uint8_t *plain); void nfc3d_amiibo_pack(const nfc3d_amiibo_keys *amiiboKeys, const uint8_t *plain, uint8_t *tag); -bool nfc3d_amiibo_load_keys(nfc3d_amiibo_keys *amiiboKeys, const char *path); +bool nfc3d_amiibo_load_keys(nfc3d_amiibo_keys *amiiboKeys); void nfc3d_amiibo_copy_app_data(const uint8_t *src, uint8_t *dst); #endif diff --git a/client/deps/amiitool/amiitool.c b/client/deps/amiitool/amiitool.c index d7cd08351..61f4abd81 100644 --- a/client/deps/amiitool/amiitool.c +++ b/client/deps/amiitool/amiitool.c @@ -33,15 +33,6 @@ void amiitool_usage(void) { ); } -static bool LoadAmiikey(nfc3d_amiibo_keys keys, char *keyfile) { - - if (!nfc3d_amiibo_load_keys(&keys, keyfile)) { - PrintAndLogEx(ERR, "Could not load keys from '%s'", keyfile); - return false; - } - return true; -} - int main(int argc, char **argv) { self = argv[0];