Include a (bad) method to dump with .cnmt.nca
This commit is contained in:
62
source/tegraexplorer/fs/keys.c
Normal file
62
source/tegraexplorer/fs/keys.c
Normal file
@@ -0,0 +1,62 @@
|
||||
#include "keys.h"
|
||||
#include "../../utils/types.h"
|
||||
#include "../../libs/fatfs/ff.h"
|
||||
#include "../../sec/se.h"
|
||||
#include "../../mem/heap.h"
|
||||
#include "../gfx/gfxutils.h"
|
||||
#include "../../config/ini.h"
|
||||
#include "../common/common.h"
|
||||
#include <string.h>
|
||||
|
||||
char *getKey(const char *search, link_t *inilist){
|
||||
LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, inilist, link){
|
||||
if (ini_sec->type == INI_CHOICE){
|
||||
LIST_FOREACH_ENTRY(ini_kv_t, kv, &ini_sec->kvs, link)
|
||||
{
|
||||
if (!strcmp(search, kv->key))
|
||||
return kv->val;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
u8 getHexSingle(const char c) {
|
||||
if (c >= '0' && c <= '9')
|
||||
return c - '0';
|
||||
if (c >= 'a' && c <= 'f')
|
||||
return c - 'a' + 10;
|
||||
}
|
||||
|
||||
u8 *getHex(const char *in){
|
||||
u32 len = strlen(in), count = 0;
|
||||
u8 *out = calloc(len / 2, sizeof(u8));
|
||||
|
||||
for (u32 i = 0; i < len; i += 2){
|
||||
out[count++] = (u8)(getHexSingle(in[i]) << 4) | (getHexSingle(in[i + 1]));
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
u8 *GetKey(const char *keypath, const char *keyName){
|
||||
LIST_INIT(inilist);
|
||||
char *key;
|
||||
u8 *hex = NULL;
|
||||
|
||||
if (!ini_parse(&inilist, keypath, false)){
|
||||
gfx_errDisplay("GetKey", ERR_INI_PARSE_FAIL, 1);
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
if ((key = getKey(keyName, &inilist)) == NULL){
|
||||
gfx_errDisplay("GetKey", ERR_INI_PARSE_FAIL, 2);
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
hex = getHex(key);
|
||||
|
||||
out_free:;
|
||||
list_empty(&inilist);
|
||||
return hex;
|
||||
}
|
||||
4
source/tegraexplorer/fs/keys.h
Normal file
4
source/tegraexplorer/fs/keys.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
#include "../../utils/types.h"
|
||||
|
||||
u8 *GetKey(const char *keypath, const char *keyName);
|
||||
46
source/tegraexplorer/fs/nca.c
Normal file
46
source/tegraexplorer/fs/nca.c
Normal file
@@ -0,0 +1,46 @@
|
||||
#include "nca.h"
|
||||
#include "keys.h"
|
||||
#include "../../utils/types.h"
|
||||
#include "../../libs/fatfs/ff.h"
|
||||
#include "../../sec/se.h"
|
||||
#include "../../mem/heap.h"
|
||||
#include "../gfx/gfxutils.h"
|
||||
#include "../../config/ini.h"
|
||||
#include "../common/common.h"
|
||||
#include <string.h>
|
||||
|
||||
int SetHeaderKey(){
|
||||
u8 *header_key = GetKey("sd:/switch/prod.keys", "header_key");
|
||||
|
||||
if (header_key == NULL)
|
||||
return -1;
|
||||
|
||||
se_aes_key_set(4, header_key + 0x00, 0x10);
|
||||
se_aes_key_set(5, header_key + 0x10, 0x10);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GetNcaType(char *ncaPath){
|
||||
FIL fp;
|
||||
u32 read_bytes = 0;
|
||||
|
||||
if (f_open(&fp, ncaPath, FA_READ | FA_OPEN_EXISTING))
|
||||
return -1;
|
||||
|
||||
u8 *dec_header = (u8*)malloc(0x600);
|
||||
|
||||
if (f_lseek(&fp, 0x200) || f_read(&fp, dec_header, 32, &read_bytes) || read_bytes != 32){
|
||||
f_close(&fp);
|
||||
free(dec_header);
|
||||
return -1;
|
||||
}
|
||||
|
||||
se_aes_xts_crypt(5,4,0,1,dec_header + 0x200, dec_header, 32, 1);
|
||||
|
||||
u8 ContentType = dec_header[0x205];
|
||||
|
||||
f_close(&fp);
|
||||
free(dec_header);
|
||||
return ContentType;
|
||||
}
|
||||
4
source/tegraexplorer/fs/nca.h
Normal file
4
source/tegraexplorer/fs/nca.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
int GetNcaType(char *ncaPath);
|
||||
int SetHeaderKey();
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "savesign.h"
|
||||
#include "keys.h"
|
||||
#include "../../utils/types.h"
|
||||
#include "../../libs/fatfs/ff.h"
|
||||
#include "../../sec/se.h"
|
||||
@@ -62,62 +63,15 @@ out_free:;
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
char *getKey(const char *search, link_t *inilist){
|
||||
LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, inilist, link){
|
||||
if (ini_sec->type == INI_CHOICE){
|
||||
LIST_FOREACH_ENTRY(ini_kv_t, kv, &ini_sec->kvs, link)
|
||||
{
|
||||
if (!strcmp(search, kv->key))
|
||||
return kv->val;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
u8 getHexSingle(const char c) {
|
||||
if (c >= '0' && c <= '9')
|
||||
return c - '0';
|
||||
if (c >= 'a' && c <= 'f')
|
||||
return c - 'a' + 10;
|
||||
}
|
||||
|
||||
u8 *getHex(const char *in){
|
||||
u32 len = strlen(in), count = 0;
|
||||
u8 *out = calloc(len / 2, sizeof(u8));
|
||||
|
||||
for (u32 i = 0; i < len; i += 2){
|
||||
out[count++] = (u8)(getHexSingle(in[i]) << 4) | (getHexSingle(in[i + 1]));
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
bool save_sign(const char *keypath, const char *savepath){
|
||||
LIST_INIT(inilist);
|
||||
char *key;
|
||||
u8 *hex;
|
||||
bool success = false;
|
||||
u8 *key = GetKey(keypath, "save_mac_key");
|
||||
|
||||
if (!ini_parse(&inilist, keypath, false)){
|
||||
gfx_errDisplay("save_sign", ERR_INI_PARSE_FAIL, 1);
|
||||
goto out_free;
|
||||
if (key == NULL){
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((key = getKey("save_mac_key", &inilist)) == NULL){
|
||||
gfx_errDisplay("save_sign", ERR_INI_PARSE_FAIL, 2);
|
||||
goto out_free;
|
||||
}
|
||||
if (!save_commit(savepath, key))
|
||||
return false;
|
||||
|
||||
hex = getHex(key);
|
||||
|
||||
if (!save_commit(savepath, hex))
|
||||
goto out_free;
|
||||
|
||||
success = true;
|
||||
|
||||
out_free:;
|
||||
list_empty(&inilist);
|
||||
return success;
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user