From ff8773e0ff4e5c81de147d60978b8e12ec17236e Mon Sep 17 00:00:00 2001 From: Steven Smith Date: Thu, 30 Jun 2016 15:35:04 -0700 Subject: [PATCH] Revert removal of seed file support. --- source/core/util.c | 62 +++++++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/source/core/util.c b/source/core/util.c index 1c3fc40..7d1fb2a 100644 --- a/source/core/util.c +++ b/source/core/util.c @@ -256,36 +256,58 @@ static Result FSUSER_AddSeed(u64 titleId, const void* seed) { static u32 import_response_code = 0; Result util_import_seed(u64 titleId) { + char pathBuf[64]; + snprintf(pathBuf, 64, "/fbi/seed/%016llX.dat", titleId); + Result res = 0; - u8 region = CFG_REGION_USA; - CFGU_SecureInfoGetRegion(®ion); + FS_Path* fsPath = util_make_path_utf8(pathBuf); + if(fsPath != NULL) { + u8 seed[16]; - if(region <= CFG_REGION_TWN) { - static const char* regionStrings[] = {"JP", "US", "GB", "GB", "HK", "KR", "TW"}; + Handle fileHandle = 0; + if(R_SUCCEEDED(res = FSUSER_OpenFileDirectly(&fileHandle, ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, ""), *fsPath, FS_OPEN_READ, 0))) { + u32 bytesRead = 0; + res = FSFILE_Read(fileHandle, &bytesRead, 0, seed, sizeof(seed)); - char url[128]; - snprintf(url, 128, "https://kagiya-ctr.cdn.nintendo.net/title/0x%016llX/ext_key?country=%s", titleId, regionStrings[region]); + FSFILE_Close(fileHandle); + } - httpcContext context; - if(R_SUCCEEDED(res = httpcOpenContext(&context, HTTPC_METHOD_GET, url, 1))) { - if(R_SUCCEEDED(res = httpcSetSSLOpt(&context, SSLCOPT_DisableVerify)) && R_SUCCEEDED(res = httpcBeginRequest(&context)) && R_SUCCEEDED(res = httpcGetResponseStatusCode(&context, &import_response_code, 0))) { - if(import_response_code == 200) { - u8 seed[16]; + util_free_path_utf8(fsPath); - u32 bytesRead = 0; - if(R_SUCCEEDED(res = httpcDownloadData(&context, seed, sizeof(seed), &bytesRead))) { - res = FSUSER_AddSeed(titleId, seed); + if(R_FAILED(res)) { + u8 region = CFG_REGION_USA; + CFGU_SecureInfoGetRegion(®ion); + + if(region <= CFG_REGION_TWN) { + static const char* regionStrings[] = {"JP", "US", "GB", "GB", "HK", "KR", "TW"}; + + char url[128]; + snprintf(url, 128, "https://kagiya-ctr.cdn.nintendo.net/title/0x%016llX/ext_key?country=%s", titleId, regionStrings[region]); + + httpcContext context; + if(R_SUCCEEDED(res = httpcOpenContext(&context, HTTPC_METHOD_GET, url, 1))) { + if(R_SUCCEEDED(res = httpcSetSSLOpt(&context, SSLCOPT_DisableVerify)) && R_SUCCEEDED(res = httpcBeginRequest(&context)) && R_SUCCEEDED(res = httpcGetResponseStatusCode(&context, &import_response_code, 0))) { + if(import_response_code == 200) { + u32 bytesRead = 0; + res = httpcDownloadData(&context, seed, sizeof(seed), &bytesRead); + } else { + res = R_FBI_HTTP_RESPONSE_CODE; + } } - } else { - res = R_FBI_HTTP_RESPONSE_CODE; - } - } - httpcCloseContext(&context); + httpcCloseContext(&context); + } + } else { + res = R_FBI_OUT_OF_RANGE; + } + } + + if(R_SUCCEEDED(res)) { + res = FSUSER_AddSeed(titleId, seed); } } else { - res = R_FBI_OUT_OF_RANGE; + res = R_FBI_OUT_OF_MEMORY; } return res;