mirror of
https://github.com/DarkMatterCore/nxdumptool.git
synced 2024-11-24 19:22:07 +00:00
utils: cleanup resource initialization code
Other changes include: * codebase: fix building with logging disabled. * codebase: remove superfluous log level guards. * defines: add SYSMMC_SUBDIR, EMUMMC_SUBDIR and SYSTEM_UPDATE_SUBDIR macros. * poc: use subdirectory macros in output path generation code. * poc: fix output directories for the eMMC FAT partition browser.
This commit is contained in:
parent
f817ec5009
commit
ca61151662
9 changed files with 246 additions and 179 deletions
|
@ -2615,7 +2615,7 @@ static bool saveGameCardImage(void *userdata)
|
|||
}
|
||||
|
||||
snprintf(path, MAX_ELEMENTS(path), " [%s][%s][%s].xci", prepend_key_area ? "KA" : "NKA", keep_certificate ? "C" : "NC", trim_dump ? "T" : "NT");
|
||||
filename = generateOutputGameCardFileName("Gamecard", path, true);
|
||||
filename = generateOutputGameCardFileName(GAMECARD_SUBDIR, path, true);
|
||||
if (!filename) goto end;
|
||||
|
||||
if (dev_idx == 1)
|
||||
|
@ -2740,7 +2740,7 @@ static bool saveGameCardHeader(void *userdata)
|
|||
crc = crc32Calculate(&gc_header, sizeof(GameCardHeader));
|
||||
snprintf(path, MAX_ELEMENTS(path), " (Header) (%08X).bin", crc);
|
||||
|
||||
filename = generateOutputGameCardFileName("Gamecard", path, true);
|
||||
filename = generateOutputGameCardFileName(GAMECARD_SUBDIR, path, true);
|
||||
if (!filename) goto end;
|
||||
|
||||
if (!saveFileData(filename, &gc_header, sizeof(GameCardHeader))) goto end;
|
||||
|
@ -2774,7 +2774,7 @@ static bool saveGameCardCardInfo(void *userdata)
|
|||
crc = crc32Calculate(&gc_cardinfo, sizeof(GameCardInfo));
|
||||
snprintf(path, MAX_ELEMENTS(path), " (CardInfo) (%08X).bin", crc);
|
||||
|
||||
filename = generateOutputGameCardFileName("Gamecard", path, true);
|
||||
filename = generateOutputGameCardFileName(GAMECARD_SUBDIR, path, true);
|
||||
if (!filename) goto end;
|
||||
|
||||
if (!saveFileData(filename, &gc_cardinfo, sizeof(GameCardInfo))) goto end;
|
||||
|
@ -2808,7 +2808,7 @@ static bool saveGameCardCertificate(void *userdata)
|
|||
crc = crc32Calculate(&gc_cert, sizeof(FsGameCardCertificate));
|
||||
snprintf(path, MAX_ELEMENTS(path), " (Certificate) (%08X).bin", crc);
|
||||
|
||||
filename = generateOutputGameCardFileName("Gamecard", path, true);
|
||||
filename = generateOutputGameCardFileName(GAMECARD_SUBDIR, path, true);
|
||||
if (!filename) goto end;
|
||||
|
||||
if (!saveFileData(filename, &gc_cert, sizeof(FsGameCardCertificate))) goto end;
|
||||
|
@ -2836,7 +2836,7 @@ static bool saveGameCardInitialData(void *userdata)
|
|||
crc = crc32Calculate(&(gc_security_information.initial_data), sizeof(GameCardInitialData));
|
||||
snprintf(path, MAX_ELEMENTS(path), " (Initial Data) (%08X).bin", crc);
|
||||
|
||||
filename = generateOutputGameCardFileName("Gamecard", path, true);
|
||||
filename = generateOutputGameCardFileName(GAMECARD_SUBDIR, path, true);
|
||||
if (!filename) goto end;
|
||||
|
||||
if (!saveFileData(filename, &(gc_security_information.initial_data), sizeof(GameCardInitialData))) goto end;
|
||||
|
@ -2869,7 +2869,7 @@ static bool saveGameCardSpecificData(void *userdata)
|
|||
crc = crc32Calculate(&(gc_security_information.specific_data), sizeof(GameCardSpecificData));
|
||||
snprintf(path, MAX_ELEMENTS(path), " (Specific Data) (%08X).bin", crc);
|
||||
|
||||
filename = generateOutputGameCardFileName("Gamecard", path, true);
|
||||
filename = generateOutputGameCardFileName(GAMECARD_SUBDIR, path, true);
|
||||
if (!filename) goto end;
|
||||
|
||||
if (!saveFileData(filename, &(gc_security_information.specific_data), sizeof(GameCardSpecificData))) goto end;
|
||||
|
@ -2901,7 +2901,7 @@ static bool saveGameCardIdSet(void *userdata)
|
|||
crc = crc32Calculate(&id_set, sizeof(FsGameCardIdSet));
|
||||
snprintf(path, MAX_ELEMENTS(path), " (Card ID Set) (%08X).bin", crc);
|
||||
|
||||
filename = generateOutputGameCardFileName("Gamecard", path, true);
|
||||
filename = generateOutputGameCardFileName(GAMECARD_SUBDIR, path, true);
|
||||
if (!filename) goto end;
|
||||
|
||||
if (!saveFileData(filename, &id_set, sizeof(FsGameCardIdSet))) goto end;
|
||||
|
@ -2934,7 +2934,7 @@ static bool saveGameCardUid(void *userdata)
|
|||
crc = crc32Calculate(&(gc_security_information.specific_data.card_uid), sizeof(gc_security_information.specific_data.card_uid));
|
||||
snprintf(path, MAX_ELEMENTS(path), " (Card UID) (%08X).bin", crc);
|
||||
|
||||
filename = generateOutputGameCardFileName("Gamecard", path, true);
|
||||
filename = generateOutputGameCardFileName(GAMECARD_SUBDIR, path, true);
|
||||
if (!filename) goto end;
|
||||
|
||||
if (!saveFileData(filename, &(gc_security_information.specific_data.card_uid), sizeof(gc_security_information.specific_data.card_uid))) goto end;
|
||||
|
@ -2996,7 +2996,7 @@ static bool saveGameCardRawHfsPartition(HashFileSystemContext *hfs_ctx)
|
|||
consolePrint("raw %s hfs partition size: 0x%lX (%s)\n", hfs_ctx->name, hfs_ctx->size, size_str);
|
||||
|
||||
snprintf(path, MAX_ELEMENTS(path), "/%s.hfs0", hfs_ctx->name);
|
||||
filename = generateOutputGameCardFileName("HFS/Raw", path, true);
|
||||
filename = generateOutputGameCardFileName(HFS_SUBDIR "/Raw", path, true);
|
||||
if (!filename) goto end;
|
||||
|
||||
if (dev_idx == 1)
|
||||
|
@ -3146,7 +3146,7 @@ static bool browseGameCardHfsPartition(void *userdata)
|
|||
|
||||
/* Generate output base path. */
|
||||
snprintf(subdir, MAX_ELEMENTS(subdir), "/%s", hfs_ctx.name);
|
||||
base_out_path = generateOutputGameCardFileName("HFS/Extracted", subdir, true);
|
||||
base_out_path = generateOutputGameCardFileName(HFS_SUBDIR "/Extracted", subdir, true);
|
||||
if (!base_out_path) goto end;
|
||||
|
||||
/* Display file browser. */
|
||||
|
@ -3413,7 +3413,7 @@ static bool saveTicket(void *userdata)
|
|||
crc = crc32Calculate(tik.data, tik.size);
|
||||
snprintf(path, MAX_ELEMENTS(path), " (%08X).tik", crc);
|
||||
|
||||
filename = generateOutputTitleFileName(title_info, "Ticket", path);
|
||||
filename = generateOutputTitleFileName(title_info, TICKET_SUBDIR, path);
|
||||
if (!filename) goto end;
|
||||
|
||||
if (!saveFileData(filename, tik.data, tik.size)) goto end;
|
||||
|
@ -3471,7 +3471,7 @@ static bool saveNintendoContentArchive(void *userdata)
|
|||
utilsGenerateFormattedSizeString((double)shared_thread_data->total_size, size_str, sizeof(size_str));
|
||||
consolePrint("nca size: 0x%lX (%s)\n", shared_thread_data->total_size, size_str);
|
||||
|
||||
snprintf(subdir, MAX_ELEMENTS(subdir), "NCA/%s", nca_thread_data.nca_ctx->storage_id == NcmStorageId_BuiltInSystem ? "System" : "User");
|
||||
snprintf(subdir, MAX_ELEMENTS(subdir), NCA_SUBDIR "/%s", nca_thread_data.nca_ctx->storage_id == NcmStorageId_BuiltInSystem ? "System" : "User");
|
||||
snprintf(path, MAX_ELEMENTS(path), "/%s.%s", nca_thread_data.nca_ctx->content_id_str, content_info->content_type == NcmContentType_Meta ? "cnmt.nca" : "nca");
|
||||
|
||||
filename = generateOutputTitleFileName(title_info, subdir, path);
|
||||
|
@ -3655,7 +3655,7 @@ static bool browseNintendoContentArchiveFsSection(void *userdata)
|
|||
|
||||
base_out_path = generateOutputLayeredFsFileName(title_id + nca_ctx->id_offset, NULL, section_type == NcaFsSectionType_PartitionFs ? "exefs" : "romfs");
|
||||
} else {
|
||||
snprintf(subdir, MAX_ELEMENTS(subdir), "NCA FS/%s/Extracted", nca_ctx->storage_id == NcmStorageId_BuiltInSystem ? "System" : "User");
|
||||
snprintf(subdir, MAX_ELEMENTS(subdir), NCA_FS_SUBDIR "/%s/Extracted", nca_ctx->storage_id == NcmStorageId_BuiltInSystem ? "System" : "User");
|
||||
snprintf(extension, MAX_ELEMENTS(extension), "/%s #%u/%u", titleGetNcmContentTypeName(nca_ctx->content_type), nca_ctx->id_offset, nca_fs_ctx->section_idx);
|
||||
|
||||
TitleInfo *title_info = (title_id == g_ncaUserTitleInfo->meta_key.id ? g_ncaUserTitleInfo : g_ncaBasePatchTitleInfo);
|
||||
|
@ -3725,19 +3725,25 @@ end:
|
|||
static bool browseEmmcPartition(void *userdata)
|
||||
{
|
||||
u8 bis_partition_id = (userdata ? *((u8*)userdata) : 0);
|
||||
const char *mount_name = NULL;
|
||||
const char *gpt_name = NULL, *mount_name = NULL;
|
||||
char *base_out_path = NULL;
|
||||
|
||||
bool success = false;
|
||||
|
||||
if (bis_partition_id < FsBisPartitionId_CalibrationFile || bis_partition_id > FsBisPartitionId_System || !(mount_name = bisStorageGetMountNameByBisPartitionId(bis_partition_id)))
|
||||
if (bis_partition_id < FsBisPartitionId_CalibrationFile || bis_partition_id > FsBisPartitionId_System)
|
||||
{
|
||||
consolePrint("invalid bis partition id! (%u)\n", bis_partition_id);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!(gpt_name = bisStorageGetGptPartitionNameByBisPartitionId(bis_partition_id)) || !(mount_name = bisStorageGetMountNameByBisPartitionId(bis_partition_id)))
|
||||
{
|
||||
consolePrint("failed to get names for bis partition id! (%u)\n", bis_partition_id);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* Generate output base path. */
|
||||
base_out_path = generateOutputGameCardFileName(utilsGetAtmosphereEmummcStatus() ? "emuMMC" : "sysMMC", mount_name, false);
|
||||
base_out_path = generateOutputGameCardFileName(utilsGetAtmosphereEmummcStatus() ? EMUMMC_SUBDIR : SYSMMC_SUBDIR, gpt_name, false);
|
||||
if (!base_out_path) goto end;
|
||||
|
||||
/* Display file browser. */
|
||||
|
@ -4437,7 +4443,7 @@ static bool saveRawPartitionFsSection(PartitionFileSystemContext *pfs_ctx, bool
|
|||
|
||||
filename = generateOutputLayeredFsFileName(title_id + nca_ctx->id_offset, NULL, "exefs.nsp");
|
||||
} else {
|
||||
snprintf(subdir, MAX_ELEMENTS(subdir), "NCA FS/%s/Raw", nca_ctx->storage_id == NcmStorageId_BuiltInSystem ? "System" : "User");
|
||||
snprintf(subdir, MAX_ELEMENTS(subdir), NCA_FS_SUBDIR "/%s/Raw", nca_ctx->storage_id == NcmStorageId_BuiltInSystem ? "System" : "User");
|
||||
snprintf(path, MAX_ELEMENTS(path), "/%s #%u/%u.nsp", titleGetNcmContentTypeName(nca_ctx->content_type), nca_ctx->id_offset, nca_fs_ctx->section_idx);
|
||||
|
||||
TitleInfo *title_info = (title_id == g_ncaUserTitleInfo->meta_key.id ? g_ncaUserTitleInfo : g_ncaBasePatchTitleInfo);
|
||||
|
@ -4597,7 +4603,7 @@ static bool saveRawRomFsSection(RomFileSystemContext *romfs_ctx, bool use_layere
|
|||
|
||||
filename = generateOutputLayeredFsFileName(title_id + nca_ctx->id_offset, NULL, "romfs.bin");
|
||||
} else {
|
||||
snprintf(subdir, MAX_ELEMENTS(subdir), "NCA FS/%s/Raw", nca_ctx->storage_id == NcmStorageId_BuiltInSystem ? "System" : "User");
|
||||
snprintf(subdir, MAX_ELEMENTS(subdir), NCA_FS_SUBDIR "/%s/Raw", nca_ctx->storage_id == NcmStorageId_BuiltInSystem ? "System" : "User");
|
||||
snprintf(path, MAX_ELEMENTS(path), "/%s #%u/%u.bin", titleGetNcmContentTypeName(nca_ctx->content_type), nca_ctx->id_offset, nca_fs_ctx->section_idx);
|
||||
|
||||
TitleInfo *title_info = (title_id == g_ncaUserTitleInfo->meta_key.id ? g_ncaUserTitleInfo : g_ncaBasePatchTitleInfo);
|
||||
|
@ -4896,7 +4902,7 @@ static void extractedHfsReadThreadFunc(void *arg)
|
|||
buf2 = usbAllocatePageAlignedBuffer(BLOCK_SIZE);
|
||||
|
||||
snprintf(hfs_path, MAX_ELEMENTS(hfs_path), "/%s", hfs_ctx->name);
|
||||
filename = generateOutputGameCardFileName("HFS/Extracted", hfs_path, true);
|
||||
filename = generateOutputGameCardFileName(HFS_SUBDIR "/Extracted", hfs_path, true);
|
||||
filename_len = (filename ? strlen(filename) : 0);
|
||||
|
||||
if (!shared_thread_data->total_size || !hfs_entry_count || !buf1 || !buf2 || !filename)
|
||||
|
@ -5278,7 +5284,7 @@ static void extractedPartitionFsReadThreadFunc(void *arg)
|
|||
|
||||
filename = generateOutputLayeredFsFileName(title_id + nca_ctx->id_offset, NULL, "exefs");
|
||||
} else {
|
||||
snprintf(subdir, MAX_ELEMENTS(subdir), "NCA FS/%s/Extracted", nca_ctx->storage_id == NcmStorageId_BuiltInSystem ? "System" : "User");
|
||||
snprintf(subdir, MAX_ELEMENTS(subdir), NCA_FS_SUBDIR "/%s/Extracted", nca_ctx->storage_id == NcmStorageId_BuiltInSystem ? "System" : "User");
|
||||
snprintf(pfs_path, MAX_ELEMENTS(pfs_path), "/%s #%u/%u", titleGetNcmContentTypeName(nca_ctx->content_type), nca_ctx->id_offset, nca_fs_ctx->section_idx);
|
||||
|
||||
TitleInfo *title_info = (title_id == g_ncaUserTitleInfo->meta_key.id ? g_ncaUserTitleInfo : g_ncaBasePatchTitleInfo);
|
||||
|
@ -5596,7 +5602,7 @@ static void extractedRomFsReadThreadFunc(void *arg)
|
|||
|
||||
filename = generateOutputLayeredFsFileName(title_id + nca_ctx->id_offset, NULL, "romfs");
|
||||
} else {
|
||||
snprintf(subdir, MAX_ELEMENTS(subdir), "NCA FS/%s/Extracted", nca_ctx->storage_id == NcmStorageId_BuiltInSystem ? "System" : "User");
|
||||
snprintf(subdir, MAX_ELEMENTS(subdir), NCA_FS_SUBDIR "/%s/Extracted", nca_ctx->storage_id == NcmStorageId_BuiltInSystem ? "System" : "User");
|
||||
snprintf(romfs_path, MAX_ELEMENTS(romfs_path), "/%s #%u/%u", titleGetNcmContentTypeName(nca_ctx->content_type), nca_ctx->id_offset, nca_fs_ctx->section_idx);
|
||||
|
||||
TitleInfo *title_info = (title_id == g_ncaUserTitleInfo->meta_key.id ? g_ncaUserTitleInfo : g_ncaBasePatchTitleInfo);
|
||||
|
@ -6193,7 +6199,7 @@ static void systemUpdateReadThreadFunc(void *arg)
|
|||
|
||||
snprintf(sys_upd_path, MAX_ELEMENTS(sys_upd_path), "/%.*s (%s)", (int)sizeof(sys_upd_dump_ctx->version_file.display_title),
|
||||
sys_upd_dump_ctx->version_file.display_title, utilsIsDevelopmentUnit() ? "Dev" : "Prod");
|
||||
filename = generateOutputGameCardFileName("System Update", sys_upd_path, false);
|
||||
filename = generateOutputGameCardFileName(SYSTEM_UPDATE_SUBDIR, sys_upd_path, false);
|
||||
filename_len = (filename ? strlen(filename) : 0);
|
||||
|
||||
if (!shared_thread_data->total_size || !buf1 || !buf2 || !filename)
|
||||
|
@ -6627,7 +6633,7 @@ static void nspThreadFunc(void *arg)
|
|||
}
|
||||
|
||||
/* Generate output path. */
|
||||
filename = generateOutputTitleFileName(title_info, "NSP", ".nsp");
|
||||
filename = generateOutputTitleFileName(title_info, NSP_SUBDIR, ".nsp");
|
||||
if (!filename) goto end;
|
||||
|
||||
/* Get free space on output storage. */
|
||||
|
|
|
@ -142,6 +142,15 @@ void logControlMutex(bool lock);
|
|||
#define LOG_MSG_BUF_ERROR(dst, dst_size, fmt, ...) do {} while(0)
|
||||
#define LOG_DATA_ERROR(data, data_size, fmt, ...) do {} while(0)
|
||||
|
||||
#define logWriteStringToLogFile(...) do {} while(0)
|
||||
#define logWriteFormattedStringToLogFile(...) do {} while(0)
|
||||
#define logWriteFormattedStringToBuffer(...) do {} while(0)
|
||||
#define logWriteBinaryDataToLogFile(...) do {} while(0)
|
||||
#define logFlushLogFile(...) do {} while(0)
|
||||
#define logCloseLogFile(...) do {} while(0)
|
||||
#define logGetLastMessage(...) NULL
|
||||
#define logControlMutex(...) do {} while(0)
|
||||
|
||||
#endif /* (LOG_LEVEL >= LOG_LEVEL_DEBUG) && (LOG_LEVEL < LOG_LEVEL_NONE) */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -75,12 +75,12 @@ void utilsCloseResources(void);
|
|||
/// Returns a pointer to the application launch path.
|
||||
const char *utilsGetLaunchPath(void);
|
||||
|
||||
/// Returns the nxlink socket descriptor, or -1 if an nxlink connection couldn't be established.
|
||||
int utilsGetNxLinkFileDescriptor(void);
|
||||
|
||||
/// Returns a pointer to the FsFileSystem object for the SD card.
|
||||
FsFileSystem *utilsGetSdCardFileSystemObject(void);
|
||||
|
||||
/// Returns the nxlink socket descriptor, or -1 if an nxlink connection couldn't be established.
|
||||
int utilsGetNxLinkFileDescriptor(void);
|
||||
|
||||
/// Commits SD card filesystem changes.
|
||||
/// Must be used after closing a file handle from the SD card.
|
||||
bool utilsCommitSdCardFileSystemChanges(void);
|
||||
|
|
|
@ -89,6 +89,9 @@
|
|||
#define TICKET_SUBDIR "Ticket"
|
||||
#define NCA_SUBDIR "NCA"
|
||||
#define NCA_FS_SUBDIR "NCA FS"
|
||||
#define SYSMMC_SUBDIR "sysMMC"
|
||||
#define EMUMMC_SUBDIR "emuMMC"
|
||||
#define SYSTEM_UPDATE_SUBDIR "System Update"
|
||||
|
||||
#define CONFIG_FILE_NAME APP_TITLE "_config.json"
|
||||
#define DEFAULT_CONFIG_PATH "romfs:/default_config.json"
|
||||
|
|
|
@ -101,14 +101,12 @@ static bool memRetrieveProgramMemory(MemoryLocation *location, bool is_segment)
|
|||
/* Clear output MemoryLocation element. */
|
||||
memFreeMemoryLocation(location);
|
||||
|
||||
#if LOG_LEVEL < LOG_LEVEL_NONE
|
||||
/* LOG_*() macros will be useless if the target program is the FS sysmodule. */
|
||||
/* This is because any FS I/O operation *will* lock up the console while FS itself is being debugged. */
|
||||
/* So we'll just log data to a temporary buffer using LOG_MSG_BUF_*() macros, then write it all out to the logfile after calling svcCloseHandle(). */
|
||||
/* However, we must prevent other threads from logging data as well in order to avoid a lock up, so we'll temporarily lock the logfile mutex. */
|
||||
/* We don't need to take care of manually (re)allocating memory for our buffer -- the log handler ABI takes care of that for us. */
|
||||
logControlMutex(true);
|
||||
#endif
|
||||
|
||||
/* Retrieve debug handle by program ID. */
|
||||
if (!memRetrieveDebugHandleFromProgramById(&debug_handle, location->program_id))
|
||||
|
@ -139,7 +137,6 @@ static bool memRetrieveProgramMemory(MemoryLocation *location, bool is_segment)
|
|||
/* Filter out unwanted memory pages. */
|
||||
if (MEM_INVALID_SEGMENT_PAGE_TYPE(mem_type) || mem_info.attr || (mem_info.perm & Perm_Rx) != Perm_Rx) continue;
|
||||
|
||||
#if LOG_LEVEL == LOG_LEVEL_DEBUG
|
||||
MEMLOG_DEBUG("svcQueryDebugProcessMemory info (FS .text segment lookup) (program %016lX, page 0x%X, debug handle 0x%X):\r\n" \
|
||||
"- addr: 0x%lX\r\n" \
|
||||
"- size: 0x%lX\r\n" \
|
||||
|
@ -150,7 +147,6 @@ static bool memRetrieveProgramMemory(MemoryLocation *location, bool is_segment)
|
|||
"- device_refcount: 0x%X", \
|
||||
location->program_id, page_info, debug_handle, mem_info.addr, mem_info.size, mem_info.type, mem_info.attr, mem_info.perm, \
|
||||
mem_info.ipc_refcount, mem_info.device_refcount);
|
||||
#endif
|
||||
|
||||
/* Update .text segment address. */
|
||||
last_text_addr = mem_info.addr;
|
||||
|
@ -182,7 +178,6 @@ static bool memRetrieveProgramMemory(MemoryLocation *location, bool is_segment)
|
|||
(is_segment && (MEM_INVALID_SEGMENT_PAGE_TYPE(mem_type) || !(((segment <<= 1) >> 1) & location->mask))) || \
|
||||
(!is_segment && location->program_id == FS_SYSMODULE_TID && MEM_INVALID_FS_PAGE_TYPE(mem_type))) continue;
|
||||
|
||||
#if LOG_LEVEL == LOG_LEVEL_DEBUG
|
||||
MEMLOG_DEBUG("svcQueryDebugProcessMemory info (program %016lX, page 0x%X, debug handle 0x%X):\r\n" \
|
||||
"- addr: 0x%lX\r\n" \
|
||||
"- size: 0x%lX\r\n" \
|
||||
|
@ -193,7 +188,6 @@ static bool memRetrieveProgramMemory(MemoryLocation *location, bool is_segment)
|
|||
"- device_refcount: 0x%X", \
|
||||
location->program_id, page_info, debug_handle, mem_info.addr, mem_info.size, mem_info.type, mem_info.attr, mem_info.perm, \
|
||||
mem_info.ipc_refcount, mem_info.device_refcount);
|
||||
#endif
|
||||
|
||||
/* Reallocate data buffer. */
|
||||
tmp = realloc(location->data, location->data_size + mem_info.size);
|
||||
|
@ -224,10 +218,8 @@ end:
|
|||
/* Close debug handle. */
|
||||
if (debug_handle != INVALID_HANDLE) svcCloseHandle(debug_handle);
|
||||
|
||||
#if LOG_LEVEL < LOG_LEVEL_NONE
|
||||
/* Unlock logfile mutex. */
|
||||
logControlMutex(false);
|
||||
#endif
|
||||
|
||||
if (success && (!location->data || !location->data_size))
|
||||
{
|
||||
|
|
|
@ -97,6 +97,11 @@ static bool g_exosphereIsEmummc = false;
|
|||
|
||||
static void _utilsGetLaunchPath(void);
|
||||
|
||||
static bool _utilsGetSdCardFileSystemObject(void);
|
||||
|
||||
static void _utilsGetNxLinkFileDescriptor(void);
|
||||
static void utilsCloseNxLinkFileDescriptor(void);
|
||||
|
||||
static bool utilsGetExosphereApiVersion(void);
|
||||
static bool utilsGetExosphereEmummcType(void);
|
||||
|
||||
|
@ -108,6 +113,16 @@ static bool utilsGetDevelopmentUnitFlag(void);
|
|||
|
||||
static bool utilsGetTerraUnitFlag(void);
|
||||
|
||||
#if LOG_LEVEL <= LOG_LEVEL_INFO
|
||||
static void utilsLogEnvironmentInfo(void);
|
||||
#endif
|
||||
|
||||
static bool utilsEnsureCorrectLaunchPath(void);
|
||||
|
||||
static void utilsEnableVideoRecording(void);
|
||||
|
||||
static void utilsPrintInitializationFailureMessage(void);
|
||||
|
||||
static void utilsOverclockSystem(bool overclock);
|
||||
static void utilsOverclockSystemAppletHook(AppletHookType hook, void *param);
|
||||
|
||||
|
@ -133,31 +148,17 @@ bool utilsInitializeResources(void)
|
|||
/* Retrieve pointer to the application launch path. */
|
||||
_utilsGetLaunchPath();
|
||||
|
||||
/* Retrieve pointer to the SD card FsFileSystem element. */
|
||||
if (!(g_sdCardFileSystem = fsdevGetDeviceFileSystem(DEVOPTAB_SDMC_DEVICE)))
|
||||
{
|
||||
LOG_MSG_ERROR("Failed to retrieve FsFileSystem object for the SD card!");
|
||||
break;
|
||||
}
|
||||
/* Retrieve pointer to the SD card's FsFileSystem service object. */
|
||||
if (!_utilsGetSdCardFileSystemObject()) break;
|
||||
|
||||
/*FsFileSystemAttribute fs_attr = {0};
|
||||
if (R_SUCCEEDED(fsFsGetFileSystemAttribute(g_sdCardFileSystem, &fs_attr)))
|
||||
{
|
||||
LOG_DATA_INFO(&fs_attr, sizeof(FsFileSystemAttribute), "SD card FS attributes:");
|
||||
}*/
|
||||
LOG_MSG_INFO(APP_TITLE " v" APP_VERSION " starting (" GIT_REV "). Built on " BUILD_TIMESTAMP ".");
|
||||
|
||||
/* Initialize needed services. */
|
||||
if (!servicesInitialize()) break;
|
||||
|
||||
/* Check if a valid nxlink host IP address was set by libnx. */
|
||||
/* If so, initialize nxlink connection without redirecting stdout and/or stderr. */
|
||||
if (__nxlink_host.s_addr != 0 && __nxlink_host.s_addr != INADDR_NONE) g_nxLinkSocketFd = nxlinkConnectToHost(false, false);
|
||||
|
||||
#if LOG_LEVEL <= LOG_LEVEL_INFO
|
||||
/* Log info messages. */
|
||||
LOG_MSG_INFO(APP_TITLE " v" APP_VERSION " starting (" GIT_REV "). Built on " BUILD_TIMESTAMP ".");
|
||||
if (g_nxLinkSocketFd >= 0) LOG_MSG_INFO("nxlink enabled! Host IP address: %s.", inet_ntoa(__nxlink_host));
|
||||
#endif
|
||||
/* Get nxlink file descriptor. */
|
||||
/* If available, it will be used by our logging interface. */
|
||||
_utilsGetNxLinkFileDescriptor();
|
||||
|
||||
/* Retrieve Exosphère API version. */
|
||||
if (!utilsGetExosphereApiVersion())
|
||||
|
@ -189,50 +190,12 @@ bool utilsInitializeResources(void)
|
|||
g_programAppletType = appletGetAppletType();
|
||||
|
||||
#if LOG_LEVEL <= LOG_LEVEL_INFO
|
||||
/* Log info messages. */
|
||||
u32 hos_version = hosversionGet();
|
||||
|
||||
LOG_MSG_INFO("Console info:\r\n" \
|
||||
"- Horizon OS version: %u.%u.%u.\r\n" \
|
||||
"- CFW: %s.\r\n" \
|
||||
"- eMMC type: %s.\r\n" \
|
||||
"- SoC type: %s.\r\n" \
|
||||
"- Development unit: %s.\r\n" \
|
||||
"- Terra flag: %s.\r\n" \
|
||||
"- Execution mode: %s.", \
|
||||
HOSVER_MAJOR(hos_version), HOSVER_MINOR(hos_version), HOSVER_MICRO(hos_version), \
|
||||
(g_customFirmwareType == UtilsCustomFirmwareType_Atmosphere ? "Atmosphère" : (g_customFirmwareType == UtilsCustomFirmwareType_SXOS ? "SX OS" : g_customFirmwareType == UtilsCustomFirmwareType_ReiNX ? "ReiNX" : "Unknown")), \
|
||||
g_exosphereIsEmummc ? "emuMMC" : "sysMMC", \
|
||||
utilsIsMarikoUnit() ? "Mariko" : "Erista", \
|
||||
g_isDevUnit ? "yes" : "no", \
|
||||
g_isTerraUnit ? "yes" : "no", \
|
||||
utilsIsAppletMode() ? "applet" : "title override");
|
||||
|
||||
LOG_MSG_INFO("Exosphère API version info:\r\n" \
|
||||
"- Release version: %u.%u.%u.\r\n" \
|
||||
"- PKG1 key generation: %u (0x%02X).\r\n" \
|
||||
"- Target firmware: %u.%u.%u.", \
|
||||
g_exosphereApiVersion.ams_ver_major, g_exosphereApiVersion.ams_ver_minor, g_exosphereApiVersion.ams_ver_micro, \
|
||||
g_exosphereApiVersion.key_generation, !g_exosphereApiVersion.key_generation ? g_exosphereApiVersion.key_generation : (g_exosphereApiVersion.key_generation + 1), \
|
||||
g_exosphereApiVersion.target_firmware.major, g_exosphereApiVersion.target_firmware.minor, g_exosphereApiVersion.target_firmware.micro);
|
||||
/* Log environment information. */
|
||||
utilsLogEnvironmentInfo();
|
||||
#endif
|
||||
|
||||
if (g_appLaunchPath)
|
||||
{
|
||||
LOG_MSG_INFO("Launch path: \"%s\".", g_appLaunchPath);
|
||||
|
||||
/* Move NRO if the launch path isn't the right one, then return. */
|
||||
/* TODO: uncomment this block whenever we are ready for a release. */
|
||||
/*if (strcmp(g_appLaunchPath, NRO_PATH) != 0)
|
||||
{
|
||||
utilsCreateDirectoryTree(NRO_PATH, false);
|
||||
remove(NRO_PATH);
|
||||
rename(g_appLaunchPath, NRO_PATH);
|
||||
|
||||
LOG_MSG_INFO("Moved NRO to \"%s\". Please reload the application.", NRO_PATH);
|
||||
break;
|
||||
}*/
|
||||
}
|
||||
/* Make sure the right launch path is being used. */
|
||||
if (!utilsEnsureCorrectLaunchPath()) break;
|
||||
|
||||
/* Initialize HTTP interface. */
|
||||
/* cURL must be initialized before starting any other threads. */
|
||||
|
@ -273,7 +236,7 @@ bool utilsInitializeResources(void)
|
|||
rc = romfsInit();
|
||||
if (R_FAILED(rc))
|
||||
{
|
||||
LOG_MSG_ERROR("Failed to mount " APP_TITLE "'s RomFS container!");
|
||||
LOG_MSG_ERROR("Failed to mount " APP_TITLE "'s RomFS container! (0x%X).", rc);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -286,48 +249,15 @@ bool utilsInitializeResources(void)
|
|||
/* Initialize eMMC BIS storage interface. */
|
||||
if (!bisStorageInitialize()) break;
|
||||
|
||||
/* Enable video recording if we're running under title override mode. */
|
||||
if (!utilsIsAppletMode())
|
||||
{
|
||||
bool flag = false;
|
||||
rc = appletIsGamePlayRecordingSupported(&flag);
|
||||
if (R_SUCCEEDED(rc) && flag)
|
||||
{
|
||||
rc = appletInitializeGamePlayRecording();
|
||||
if (R_FAILED(rc)) LOG_MSG_ERROR("appletInitializeGamePlayRecording failed! (0x%X).", rc);
|
||||
} else {
|
||||
LOG_MSG_ERROR("appletIsGamePlayRecordingSupported returned [0x%X, %u].", rc, flag);
|
||||
}
|
||||
}
|
||||
/* Enable video recording whenever possible. */
|
||||
utilsEnableVideoRecording();
|
||||
|
||||
/* Update flags. */
|
||||
ret = g_resourcesInit = true;
|
||||
}
|
||||
|
||||
if (!ret)
|
||||
{
|
||||
char *msg = NULL;
|
||||
size_t msg_size = 0;
|
||||
|
||||
/* Generate error message. */
|
||||
utilsAppendFormattedStringToBuffer(&msg, &msg_size, "An error occurred while initializing resources.");
|
||||
|
||||
#if LOG_LEVEL <= LOG_LEVEL_ERROR
|
||||
/* Get last log message. */
|
||||
char *log_msg = logGetLastMessage();
|
||||
if (log_msg)
|
||||
{
|
||||
utilsAppendFormattedStringToBuffer(&msg, &msg_size, "\n\n%s", log_msg);
|
||||
free(log_msg);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Print error message. */
|
||||
utilsPrintConsoleError(msg);
|
||||
|
||||
/* Free error message. */
|
||||
if (msg) free(msg);
|
||||
}
|
||||
/* Print error message, if applicable. */
|
||||
if (!ret) utilsPrintInitializationFailureMessage();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -384,27 +314,21 @@ void utilsCloseResources(void)
|
|||
httpExit();
|
||||
|
||||
/* Close nxlink socket. */
|
||||
if (g_nxLinkSocketFd >= 0)
|
||||
{
|
||||
close(g_nxLinkSocketFd);
|
||||
g_nxLinkSocketFd = -1;
|
||||
}
|
||||
utilsCloseNxLinkFileDescriptor();
|
||||
|
||||
/* Close initialized services. */
|
||||
servicesClose();
|
||||
|
||||
/* Replace application NRO (if needed). */
|
||||
/* TODO: uncomment this block whenever we're ready for a release. */
|
||||
/*if (g_appUpdated)
|
||||
/*if (g_resourcesInit && g_appUpdated)
|
||||
{
|
||||
remove(NRO_PATH);
|
||||
rename(NRO_TMP_PATH, NRO_PATH);
|
||||
}*/
|
||||
|
||||
#if LOG_LEVEL <= LOG_LEVEL_ERROR
|
||||
/* Close logfile. */
|
||||
logCloseLogFile();
|
||||
#endif
|
||||
|
||||
/* Unlock applet exit. */
|
||||
appletUnlockExit();
|
||||
|
@ -418,16 +342,16 @@ const char *utilsGetLaunchPath(void)
|
|||
return g_appLaunchPath;
|
||||
}
|
||||
|
||||
int utilsGetNxLinkFileDescriptor(void)
|
||||
{
|
||||
return g_nxLinkSocketFd;
|
||||
}
|
||||
|
||||
FsFileSystem *utilsGetSdCardFileSystemObject(void)
|
||||
{
|
||||
return g_sdCardFileSystem;
|
||||
}
|
||||
|
||||
int utilsGetNxLinkFileDescriptor(void)
|
||||
{
|
||||
return g_nxLinkSocketFd;
|
||||
}
|
||||
|
||||
bool utilsCommitSdCardFileSystemChanges(void)
|
||||
{
|
||||
return (g_sdCardFileSystem ? R_SUCCEEDED(fsFsCommit(g_sdCardFileSystem)) : false);
|
||||
|
@ -1384,6 +1308,32 @@ static void _utilsGetLaunchPath(void)
|
|||
}
|
||||
}
|
||||
|
||||
static bool _utilsGetSdCardFileSystemObject(void)
|
||||
{
|
||||
g_sdCardFileSystem = fsdevGetDeviceFileSystem(DEVOPTAB_SDMC_DEVICE);
|
||||
return (g_sdCardFileSystem != NULL);
|
||||
}
|
||||
|
||||
static void _utilsGetNxLinkFileDescriptor(void)
|
||||
{
|
||||
/* Check if a valid nxlink host IP address was set by libnx. */
|
||||
if (__nxlink_host.s_addr == 0 || __nxlink_host.s_addr == INADDR_NONE) return;
|
||||
|
||||
/* Initialize nxlink connection without redirecting stdout nor stderr. */
|
||||
g_nxLinkSocketFd = nxlinkConnectToHost(false, false);
|
||||
|
||||
#if LOG_LEVEL <= LOG_LEVEL_INFO
|
||||
if (g_nxLinkSocketFd >= 0) LOG_MSG_INFO("nxlink enabled! Host IP address: %s.", inet_ntoa(__nxlink_host));
|
||||
#endif
|
||||
}
|
||||
|
||||
static void utilsCloseNxLinkFileDescriptor(void)
|
||||
{
|
||||
if (g_nxLinkSocketFd < 0) return;
|
||||
close(g_nxLinkSocketFd);
|
||||
g_nxLinkSocketFd = -1;
|
||||
}
|
||||
|
||||
/* SMC config item available in Atmosphère and Atmosphère-based CFWs. */
|
||||
static bool utilsGetExosphereApiVersion(void)
|
||||
{
|
||||
|
@ -1465,6 +1415,101 @@ static bool utilsGetTerraUnitFlag(void)
|
|||
return R_SUCCEEDED(rc);
|
||||
}
|
||||
|
||||
#if LOG_LEVEL <= LOG_LEVEL_INFO
|
||||
static void utilsLogEnvironmentInfo(void)
|
||||
{
|
||||
u32 hos_version = hosversionGet();
|
||||
|
||||
LOG_MSG_INFO("Console info:\r\n" \
|
||||
"- Horizon OS version: %u.%u.%u.\r\n" \
|
||||
"- CFW: %s.\r\n" \
|
||||
"- eMMC type: %s.\r\n" \
|
||||
"- SoC type: %s.\r\n" \
|
||||
"- Development unit: %s.\r\n" \
|
||||
"- Terra flag: %s.\r\n" \
|
||||
"- Execution mode: %s.", \
|
||||
HOSVER_MAJOR(hos_version), HOSVER_MINOR(hos_version), HOSVER_MICRO(hos_version), \
|
||||
(g_customFirmwareType == UtilsCustomFirmwareType_Atmosphere ? "Atmosphère" : (g_customFirmwareType == UtilsCustomFirmwareType_SXOS ? "SX OS" : g_customFirmwareType == UtilsCustomFirmwareType_ReiNX ? "ReiNX" : "Unknown")), \
|
||||
g_exosphereIsEmummc ? "emuMMC" : "sysMMC", \
|
||||
utilsIsMarikoUnit() ? "Mariko" : "Erista", \
|
||||
g_isDevUnit ? "yes" : "no", \
|
||||
g_isTerraUnit ? "yes" : "no", \
|
||||
utilsIsAppletMode() ? "applet" : "title override");
|
||||
|
||||
LOG_MSG_INFO("Exosphère API version info:\r\n" \
|
||||
"- Release version: %u.%u.%u.\r\n" \
|
||||
"- PKG1 key generation: %u (0x%02X).\r\n" \
|
||||
"- Target firmware: %u.%u.%u.", \
|
||||
g_exosphereApiVersion.ams_ver_major, g_exosphereApiVersion.ams_ver_minor, g_exosphereApiVersion.ams_ver_micro, \
|
||||
g_exosphereApiVersion.key_generation, !g_exosphereApiVersion.key_generation ? g_exosphereApiVersion.key_generation : (g_exosphereApiVersion.key_generation + 1), \
|
||||
g_exosphereApiVersion.target_firmware.major, g_exosphereApiVersion.target_firmware.minor, g_exosphereApiVersion.target_firmware.micro);
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool utilsEnsureCorrectLaunchPath(void)
|
||||
{
|
||||
if (!g_appLaunchPath) return true;
|
||||
|
||||
LOG_MSG_INFO("Launch path: \"%s\".", g_appLaunchPath);
|
||||
|
||||
/* Move NRO if the launch path isn't the right one, then return. */
|
||||
/* TODO: uncomment this block whenever we are ready for a release. */
|
||||
/*if (strcasecmp(g_appLaunchPath, NRO_PATH) != 0)
|
||||
{
|
||||
utilsCreateDirectoryTree(NRO_PATH, false);
|
||||
remove(NRO_PATH);
|
||||
rename(g_appLaunchPath, NRO_PATH);
|
||||
|
||||
LOG_MSG_INFO("Moved NRO to \"%s\". Please reload the application.", NRO_PATH);
|
||||
return false;
|
||||
}*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void utilsEnableVideoRecording(void)
|
||||
{
|
||||
/* Make sure we're running under title override mode. */
|
||||
if (utilsIsAppletMode()) return;
|
||||
|
||||
Result rc = 0;
|
||||
bool flag = false;
|
||||
|
||||
/* Check if video recording is supported at all. */
|
||||
rc = appletIsGamePlayRecordingSupported(&flag);
|
||||
if (R_SUCCEEDED(rc) && flag)
|
||||
{
|
||||
/* Try to enable video recording. */
|
||||
rc = appletInitializeGamePlayRecording();
|
||||
if (R_FAILED(rc)) LOG_MSG_ERROR("appletInitializeGamePlayRecording failed! (0x%X).", rc);
|
||||
} else {
|
||||
LOG_MSG_ERROR("appletIsGamePlayRecordingSupported returned [0x%X, %u].", rc, flag);
|
||||
}
|
||||
}
|
||||
|
||||
static void utilsPrintInitializationFailureMessage(void)
|
||||
{
|
||||
char *msg = NULL;
|
||||
size_t msg_size = 0;
|
||||
|
||||
/* Generate error message. */
|
||||
utilsAppendFormattedStringToBuffer(&msg, &msg_size, "An error occurred while initializing resources.");
|
||||
|
||||
/* Get last log message. */
|
||||
char *log_msg = logGetLastMessage();
|
||||
if (log_msg)
|
||||
{
|
||||
utilsAppendFormattedStringToBuffer(&msg, &msg_size, "\n\n%s", log_msg);
|
||||
free(log_msg);
|
||||
}
|
||||
|
||||
/* Print error message. */
|
||||
utilsPrintConsoleError(msg);
|
||||
|
||||
/* Free error message. */
|
||||
if (msg) free(msg);
|
||||
}
|
||||
|
||||
static void utilsOverclockSystem(bool overclock)
|
||||
{
|
||||
u32 cpu_rate = ((overclock ? CPU_CLKRT_OVERCLOCKED : CPU_CLKRT_NORMAL) * 1000000);
|
||||
|
|
|
@ -102,7 +102,7 @@ static bool tikVerifyRsa2048Sha256Signature(const TikCommonBlock *tik_common_blo
|
|||
static bool tikGetEncryptedTitleKey(Ticket *tik);
|
||||
static bool tikGetDecryptedTitleKey(void *dst, const void *src, u8 key_generation);
|
||||
|
||||
static bool tikGetTitleKeyTypeFromRightsId(const FsRightsId *id, u8 *out);
|
||||
static bool tikGetTitleKeyTypeForRightsId(const FsRightsId *id, u8 *out);
|
||||
static bool tikRetrieveRightsIdsByTitleKeyType(FsRightsId **out, u32 *out_count, bool personalized);
|
||||
|
||||
static bool tikGetTicketEntryOffsetFromTicketList(save_ctx_t *save_ctx, u8 *buf, u64 buf_size, const FsRightsId *id, u8 titlekey_type, u64 *out_offset);
|
||||
|
@ -339,12 +339,16 @@ static bool tikRetrieveTicketFromEsSaveDataByRightsId(Ticket *dst, const FsRight
|
|||
}
|
||||
|
||||
/* Get titlekey type. */
|
||||
if (!tikGetTitleKeyTypeFromRightsId(id, &titlekey_type))
|
||||
if (!tikGetTitleKeyTypeForRightsId(id, &titlekey_type))
|
||||
{
|
||||
LOG_MSG_ERROR("Unable to retrieve ticket titlekey type!");
|
||||
goto end;
|
||||
}
|
||||
|
||||
#if LOG_LEVEL <= LOG_LEVEL_ERROR
|
||||
const char *tik_titlekey_type_str = g_tikTitleKeyTypeStrings[titlekey_type];
|
||||
#endif
|
||||
|
||||
/* Retrieve mount name for the eMMC BIS System partition. */
|
||||
if (!(mount_name = bisStorageGetMountNameByBisPartitionId(FsBisPartitionId_System)))
|
||||
{
|
||||
|
@ -358,21 +362,21 @@ static bool tikRetrieveTicketFromEsSaveDataByRightsId(Ticket *dst, const FsRight
|
|||
/* Open ES common/personalized system savefile. */
|
||||
if (!(save_ctx = save_open_savefile(savefile_path, 0)))
|
||||
{
|
||||
LOG_MSG_ERROR("Failed to open ES %s ticket system savefile!", g_tikTitleKeyTypeStrings[titlekey_type]);
|
||||
LOG_MSG_ERROR("Failed to open ES %s ticket system savefile!", tik_titlekey_type_str);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* Get ticket entry offset from ticket_list.bin. */
|
||||
if (!tikGetTicketEntryOffsetFromTicketList(save_ctx, buf, buf_size, id, titlekey_type, &ticket_offset))
|
||||
{
|
||||
LOG_MSG_ERROR("Unable to find an entry with a matching Rights ID in \"%s\" from ES %s ticket system save!", TIK_LIST_SAVEFILE_STORAGE_PATH, g_tikTitleKeyTypeStrings[titlekey_type]);
|
||||
LOG_MSG_ERROR("Unable to find an entry with a matching Rights ID in \"%s\" from ES %s ticket system save!", TIK_LIST_SAVEFILE_STORAGE_PATH, tik_titlekey_type_str);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* Get ticket entry from ticket.bin. */
|
||||
if (!tikRetrieveTicketEntryFromTicketBin(save_ctx, buf, buf_size, id, titlekey_type, ticket_offset))
|
||||
{
|
||||
LOG_MSG_ERROR("Unable to find a matching %s ticket entry for the provided Rights ID!", g_tikTitleKeyTypeStrings[titlekey_type]);
|
||||
LOG_MSG_ERROR("Unable to find a matching %s ticket entry for the provided Rights ID!", tik_titlekey_type_str);
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
@ -555,7 +559,7 @@ static bool tikGetDecryptedTitleKey(void *dst, const void *src, u8 key_generatio
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool tikGetTitleKeyTypeFromRightsId(const FsRightsId *id, u8 *out)
|
||||
static bool tikGetTitleKeyTypeForRightsId(const FsRightsId *id, u8 *out)
|
||||
{
|
||||
if (!id || !out)
|
||||
{
|
||||
|
@ -609,7 +613,7 @@ static bool tikRetrieveRightsIdsByTitleKeyType(FsRightsId **out, u32 *out_count,
|
|||
bool success = false;
|
||||
|
||||
#if LOG_LEVEL <= LOG_LEVEL_ERROR
|
||||
u8 str_idx = (personalized ? TikTitleKeyType_Personalized : TikTitleKeyType_Common);
|
||||
const char *tik_titlekey_type_str = (personalized ? g_tikTitleKeyTypeStrings[TikTitleKeyType_Personalized] : g_tikTitleKeyTypeStrings[TikTitleKeyType_Common]);
|
||||
#endif
|
||||
|
||||
*out = NULL;
|
||||
|
@ -619,13 +623,13 @@ static bool tikRetrieveRightsIdsByTitleKeyType(FsRightsId **out, u32 *out_count,
|
|||
rc = (personalized ? esCountPersonalizedTicket((s32*)&count) : esCountCommonTicket((s32*)&count));
|
||||
if (R_FAILED(rc))
|
||||
{
|
||||
LOG_MSG_ERROR("esCount%c%sTicket failed! (0x%X).", toupper(g_tikTitleKeyTypeStrings[str_idx][0]), g_tikTitleKeyTypeStrings[str_idx] + 1, rc);
|
||||
LOG_MSG_ERROR("esCount%c%sTicket failed! (0x%X).", toupper(*tik_titlekey_type_str), tik_titlekey_type_str + 1, rc);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!count)
|
||||
{
|
||||
LOG_MSG_WARNING("No %s tickets available!", g_tikTitleKeyTypeStrings[str_idx]);
|
||||
LOG_MSG_WARNING("No %s tickets available!", tik_titlekey_type_str);
|
||||
success = true;
|
||||
goto end;
|
||||
}
|
||||
|
@ -634,7 +638,7 @@ static bool tikRetrieveRightsIdsByTitleKeyType(FsRightsId **out, u32 *out_count,
|
|||
rights_ids = calloc(count, sizeof(FsRightsId));
|
||||
if (!rights_ids)
|
||||
{
|
||||
LOG_MSG_ERROR("Unable to allocate memory for %s rights IDs!", g_tikTitleKeyTypeStrings[str_idx]);
|
||||
LOG_MSG_ERROR("Unable to allocate memory for %s rights IDs!", tik_titlekey_type_str);
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
@ -643,7 +647,7 @@ static bool tikRetrieveRightsIdsByTitleKeyType(FsRightsId **out, u32 *out_count,
|
|||
success = (R_SUCCEEDED(rc) && ids_written);
|
||||
if (!success)
|
||||
{
|
||||
LOG_MSG_ERROR("esList%c%sTicket failed! (0x%X). Wrote %u entries, expected %u entries.", toupper(g_tikTitleKeyTypeStrings[str_idx][0]), g_tikTitleKeyTypeStrings[str_idx] + 1, rc, ids_written, count);
|
||||
LOG_MSG_ERROR("esList%c%sTicket failed! (0x%X). Wrote %u entries, expected %u entries.", toupper(*tik_titlekey_type_str), tik_titlekey_type_str + 1, rc, ids_written, count);
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
@ -673,17 +677,21 @@ static bool tikGetTicketEntryOffsetFromTicketList(save_ctx_t *save_ctx, u8 *buf,
|
|||
|
||||
bool last_entry_found = false, success = false;
|
||||
|
||||
#if LOG_LEVEL <= LOG_LEVEL_ERROR
|
||||
const char *tik_titlekey_type_str = g_tikTitleKeyTypeStrings[titlekey_type];
|
||||
#endif
|
||||
|
||||
/* Get FAT storage info for the ticket_list.bin stored within the opened system savefile. */
|
||||
if (!save_get_fat_storage_from_file_entry_by_path(save_ctx, TIK_LIST_SAVEFILE_STORAGE_PATH, &fat_storage, &ticket_list_bin_size))
|
||||
{
|
||||
LOG_MSG_ERROR("Failed to locate \"%s\" in ES %s ticket system save!", TIK_LIST_SAVEFILE_STORAGE_PATH, g_tikTitleKeyTypeStrings[titlekey_type]);
|
||||
LOG_MSG_ERROR("Failed to locate \"%s\" in ES %s ticket system save!", TIK_LIST_SAVEFILE_STORAGE_PATH, tik_titlekey_type_str);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* Validate ticket_list.bin size. */
|
||||
if (ticket_list_bin_size < sizeof(TikListEntry) || (ticket_list_bin_size % sizeof(TikListEntry)) != 0)
|
||||
{
|
||||
LOG_MSG_ERROR("Invalid size for \"%s\" in ES %s ticket system save! (0x%lX).", TIK_LIST_SAVEFILE_STORAGE_PATH, g_tikTitleKeyTypeStrings[titlekey_type], ticket_list_bin_size);
|
||||
LOG_MSG_ERROR("Invalid size for \"%s\" in ES %s ticket system save! (0x%lX).", TIK_LIST_SAVEFILE_STORAGE_PATH, tik_titlekey_type_str, ticket_list_bin_size);
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
@ -696,7 +704,7 @@ static bool tikGetTicketEntryOffsetFromTicketList(save_ctx_t *save_ctx, u8 *buf,
|
|||
/* Read current chunk. */
|
||||
if ((br = save_allocation_table_storage_read(&fat_storage, buf, total_br, buf_size)) != buf_size)
|
||||
{
|
||||
LOG_MSG_ERROR("Failed to read 0x%lX bytes chunk at offset 0x%lX from \"%s\" in ES %s ticket system save!", buf_size, total_br, TIK_LIST_SAVEFILE_STORAGE_PATH, g_tikTitleKeyTypeStrings[titlekey_type]);
|
||||
LOG_MSG_ERROR("Failed to read 0x%lX bytes chunk at offset 0x%lX from \"%s\" in ES %s ticket system save!", buf_size, total_br, TIK_LIST_SAVEFILE_STORAGE_PATH, tik_titlekey_type_str);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -749,17 +757,21 @@ static bool tikRetrieveTicketEntryFromTicketBin(save_ctx_t *save_ctx, u8 *buf, u
|
|||
|
||||
bool is_volatile = false, success = false;
|
||||
|
||||
#if LOG_LEVEL <= LOG_LEVEL_ERROR
|
||||
const char *tik_titlekey_type_str = g_tikTitleKeyTypeStrings[titlekey_type];
|
||||
#endif
|
||||
|
||||
/* Get FAT storage info for the ticket.bin stored within the opened system savefile. */
|
||||
if (!save_get_fat_storage_from_file_entry_by_path(save_ctx, TIK_DB_SAVEFILE_STORAGE_PATH, &fat_storage, &ticket_bin_size))
|
||||
{
|
||||
LOG_MSG_ERROR("Failed to locate \"%s\" in ES %s ticket system save!", TIK_DB_SAVEFILE_STORAGE_PATH, g_tikTitleKeyTypeStrings[titlekey_type]);
|
||||
LOG_MSG_ERROR("Failed to locate \"%s\" in ES %s ticket system save!", TIK_DB_SAVEFILE_STORAGE_PATH, tik_titlekey_type_str);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* Validate ticket.bin size. */
|
||||
if (ticket_bin_size < SIGNED_TIK_MIN_SIZE || (ticket_bin_size % SIGNED_TIK_MAX_SIZE) != 0 || ticket_bin_size < (ticket_offset + SIGNED_TIK_MAX_SIZE))
|
||||
{
|
||||
LOG_MSG_ERROR("Invalid size for \"%s\" in ES %s ticket system save! (0x%lX).", TIK_DB_SAVEFILE_STORAGE_PATH, g_tikTitleKeyTypeStrings[titlekey_type], ticket_bin_size);
|
||||
LOG_MSG_ERROR("Invalid size for \"%s\" in ES %s ticket system save! (0x%lX).", TIK_DB_SAVEFILE_STORAGE_PATH, tik_titlekey_type_str, ticket_bin_size);
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
@ -767,7 +779,7 @@ static bool tikRetrieveTicketEntryFromTicketBin(save_ctx_t *save_ctx, u8 *buf, u
|
|||
if ((br = save_allocation_table_storage_read(&fat_storage, buf, ticket_offset, SIGNED_TIK_MAX_SIZE)) != SIGNED_TIK_MAX_SIZE)
|
||||
{
|
||||
LOG_MSG_ERROR("Failed to read 0x%X-byte long ticket at offset 0x%lX from \"%s\" in ES %s ticket system save!", SIGNED_TIK_MAX_SIZE, ticket_offset, TIK_DB_SAVEFILE_STORAGE_PATH, \
|
||||
g_tikTitleKeyTypeStrings[titlekey_type]);
|
||||
tik_titlekey_type_str);
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
@ -781,7 +793,7 @@ static bool tikRetrieveTicketEntryFromTicketBin(save_ctx_t *save_ctx, u8 *buf, u
|
|||
/* Attempt to decrypt the ticket. */
|
||||
if (!tikDecryptVolatileTicket(buf, ticket_offset))
|
||||
{
|
||||
LOG_MSG_ERROR("Unable to decrypt volatile ticket at offset 0x%lX in \"%s\" from ES %s ticket system save!", ticket_offset, TIK_DB_SAVEFILE_STORAGE_PATH, g_tikTitleKeyTypeStrings[titlekey_type]);
|
||||
LOG_MSG_ERROR("Unable to decrypt volatile ticket at offset 0x%lX in \"%s\" from ES %s ticket system save!", ticket_offset, TIK_DB_SAVEFILE_STORAGE_PATH, tik_titlekey_type_str);
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
|
|
@ -1957,19 +1957,19 @@ static TitleApplicationMetadata *titleGenerateUserMetadataEntryFromControlNca(Ti
|
|||
return NULL;
|
||||
}
|
||||
|
||||
u64 control_data_size = 0, title_id = title_info->meta_key.id, app_id = titleGetApplicationIdByContentMetaKey(&(title_info->meta_key));
|
||||
u64 control_data_size = 0, app_id = titleGetApplicationIdByContentMetaKey(&(title_info->meta_key));
|
||||
TitleApplicationMetadata *app_metadata = NULL;
|
||||
|
||||
/* Retrieve application control data from Control NCA. */
|
||||
if (!titleGetApplicationControlDataFromControlNca(title_info, g_nsAppControlData, &control_data_size))
|
||||
{
|
||||
LOG_MSG_ERROR("Failed to retrieve application control data for %016lX!", title_id);
|
||||
LOG_MSG_ERROR("Failed to retrieve application control data for %016lX!", title_info->meta_key.id);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* Initialize application metadata entry using the control data we just retrieved. */
|
||||
app_metadata = titleInitializeUserMetadataEntryFromControlData(app_id, g_nsAppControlData, control_data_size);
|
||||
if (!app_metadata) LOG_MSG_ERROR("Failed to generate application metadata entry for %016lX!", title_id);
|
||||
if (!app_metadata) LOG_MSG_ERROR("Failed to generate application metadata entry for %016lX!", title_info->meta_key.id);
|
||||
|
||||
end:
|
||||
return app_metadata;
|
||||
|
@ -2018,7 +2018,6 @@ static bool titleGetApplicationControlDataFromControlNca(TitleInfo *title_info,
|
|||
return false;
|
||||
}
|
||||
|
||||
u64 title_id = title_info->meta_key.id;
|
||||
u8 storage_id = title_info->storage_id;
|
||||
u8 hfs_partition_type = (storage_id == NcmStorageId_GameCard ? HashFileSystemPartitionType_Secure : HashFileSystemPartitionType_None);
|
||||
|
||||
|
@ -2033,7 +2032,7 @@ static bool titleGetApplicationControlDataFromControlNca(TitleInfo *title_info,
|
|||
|
||||
bool success = false;
|
||||
|
||||
LOG_MSG_DEBUG("Retrieving application control data for %s %016lX in %s...", titleGetNcmContentMetaTypeName(title_info->meta_key.type), title_id, \
|
||||
LOG_MSG_DEBUG("Retrieving application control data for %s %016lX in %s...", titleGetNcmContentMetaTypeName(title_info->meta_key.type), title_info->meta_key.id, \
|
||||
titleGetNcmStorageIdName(title_info->storage_id));
|
||||
|
||||
/* Allocate memory for the NCA context. */
|
||||
|
@ -2047,14 +2046,14 @@ static bool titleGetApplicationControlDataFromControlNca(TitleInfo *title_info,
|
|||
/* Initialize NCA context. */
|
||||
if (!ncaInitializeContext(nca_ctx, storage_id, hfs_partition_type, &(title_info->meta_key), nacp_content, NULL))
|
||||
{
|
||||
LOG_MSG_ERROR("Failed to initialize NCA context for Control NCA from %016lX!", title_id);
|
||||
LOG_MSG_ERROR("Failed to initialize NCA context for Control NCA from %016lX!", title_info->meta_key.id);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* Initialize NACP context. */
|
||||
if (!nacpInitializeContext(&nacp_ctx, nca_ctx))
|
||||
{
|
||||
LOG_MSG_ERROR("Failed to initialize NACP context for %016lX!", title_id);
|
||||
LOG_MSG_ERROR("Failed to initialize NACP context for %016lX!", title_info->meta_key.id);
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
@ -2076,7 +2075,7 @@ static bool titleGetApplicationControlDataFromControlNca(TitleInfo *title_info,
|
|||
if (cur_title == (NacpTitle*)lang_entry)
|
||||
{
|
||||
lang_id = i;
|
||||
LOG_MSG_DEBUG("Selected language ID for %016lX: %u (%s).", title_id, lang_id, nacpGetLanguageString(lang_id));
|
||||
LOG_MSG_DEBUG("Selected language ID for %016lX: %u (%s).", title_info->meta_key.id, lang_id, nacpGetLanguageString(lang_id));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -3310,14 +3309,13 @@ static char *titleGetDisplayVersionString(TitleInfo *title_info)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
u64 title_id = title_info->meta_key.id;
|
||||
u8 storage_id = title_info->storage_id, hfs_partition_type = (storage_id == NcmStorageId_GameCard ? HashFileSystemPartitionType_Secure : 0);
|
||||
NcaContext *nca_ctx = NULL;
|
||||
NacpContext nacp_ctx = {0};
|
||||
char display_version[0x11] = {0}, *str = NULL;
|
||||
|
||||
LOG_MSG_DEBUG("Retrieving display version string for %s \"%s\" (%016lX) in %s...", titleGetNcmContentMetaTypeName(title_info->meta_key.type), \
|
||||
title_info->app_metadata->lang_entry.name, title_id, \
|
||||
title_info->app_metadata->lang_entry.name, title_info->meta_key.id, \
|
||||
titleGetNcmStorageIdName(title_info->storage_id));
|
||||
|
||||
/* Allocate memory for the NCA context. */
|
||||
|
@ -3331,14 +3329,14 @@ static char *titleGetDisplayVersionString(TitleInfo *title_info)
|
|||
/* Initialize NCA context. */
|
||||
if (!ncaInitializeContext(nca_ctx, storage_id, hfs_partition_type, &(title_info->meta_key), nacp_content, NULL))
|
||||
{
|
||||
LOG_MSG_ERROR("Failed to initialize NCA context for Control NCA from %016lX!", title_id);
|
||||
LOG_MSG_ERROR("Failed to initialize NCA context for Control NCA from %016lX!", title_info->meta_key.id);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* Initialize NACP context. */
|
||||
if (!nacpInitializeContext(&nacp_ctx, nca_ctx))
|
||||
{
|
||||
LOG_MSG_ERROR("Failed to initialize NACP context for %016lX!", title_id);
|
||||
LOG_MSG_ERROR("Failed to initialize NACP context for %016lX!", title_info->meta_key.id);
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
@ -3349,13 +3347,13 @@ static char *titleGetDisplayVersionString(TitleInfo *title_info)
|
|||
/* Check version string length. */
|
||||
if (!*display_version)
|
||||
{
|
||||
LOG_MSG_ERROR("Display version string from %016lX is empty!", title_id);
|
||||
LOG_MSG_ERROR("Display version string from %016lX is empty!", title_info->meta_key.id);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* Duplicate version string. */
|
||||
str = strdup(display_version);
|
||||
if (!str) LOG_MSG_ERROR("Failed to duplicate version string from %016lX!", title_id);
|
||||
if (!str) LOG_MSG_ERROR("Failed to duplicate version string from %016lX!", title_info->meta_key.id);
|
||||
|
||||
end:
|
||||
nacpFreeContext(&nacp_ctx);
|
||||
|
|
|
@ -724,7 +724,9 @@ static bool usbSendCommand(void)
|
|||
/* Write command header first. */
|
||||
if (!usbWrite(cmd_header, sizeof(UsbCommandHeader)))
|
||||
{
|
||||
#if LOG_LEVEL <= LOG_LEVEL_ERROR
|
||||
if (!g_usbDetectionThreadExitFlag) LOG_MSG_ERROR("Failed to write header for type 0x%X command!", cmd);
|
||||
#endif
|
||||
status = UsbStatusType_WriteCommandFailed;
|
||||
goto end;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue