From 278142fd2250991d0b36f2864a6ed997431c7324 Mon Sep 17 00:00:00 2001 From: Pablo Curiel Date: Mon, 27 Apr 2020 19:30:35 -0400 Subject: [PATCH] RomFS done. Modifications method still missing though. --- source/main.c | 19 +++++++++++++++++++ source/nca.h | 1 + source/pfs.h | 4 +++- source/romfs.h | 2 ++ source/services.c | 4 ++-- 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/source/main.c b/source/main.c index be3504b..ec6aad6 100644 --- a/source/main.c +++ b/source/main.c @@ -271,6 +271,25 @@ int main(int argc, char *argv[]) printf("romfs get file entry by path success: %s | %p\n", romfs_file_entry->name, romfs_file_entry); consoleUpdate(NULL); + if (romfsReadFileEntryData(&romfs_ctx, romfs_file_entry, buf, romfs_file_entry->size, 0)) + { + printf("romfs read file entry success\n"); + consoleUpdate(NULL); + + tmp_file = fopen("sdmc:/nxdt_test/mscorlib.dll-resources.dat", "wb"); + if (tmp_file) + { + fwrite(buf, 1, romfs_file_entry->size, tmp_file); + fclose(tmp_file); + tmp_file = NULL; + printf("romfs file entry data saved\n"); + } else { + printf("romfs file entry data not saved\n"); + } + } else { + printf("romfs read file entry failed\n"); + } + diff --git a/source/nca.h b/source/nca.h index aa54c89..1a34640 100644 --- a/source/nca.h +++ b/source/nca.h @@ -302,6 +302,7 @@ void ncaFreeCryptoBuffer(void); bool ncaInitializeContext(NcaContext *out, u8 storage_id, NcmContentStorage *ncm_storage, u8 hfs_partition_type, const NcmPackagedContentInfo *content_info, Ticket *tik); /// Reads raw encrypted data from a NCA using an input context, previously initialized by ncaInitializeContext(). +/// Input offset must be relative to the start of the NCA content file. bool ncaReadContentFile(NcaContext *ctx, void *out, u64 read_size, u64 offset); /// Reads decrypted data from a NCA FS section using an input context. diff --git a/source/pfs.h b/source/pfs.h index 86379a6..e374dfb 100644 --- a/source/pfs.h +++ b/source/pfs.h @@ -50,7 +50,7 @@ typedef struct { typedef struct { u64 hash_block_offset; ///< New hash block offset (relative to the start of the NCA content file). - u64 hash_block_size; ///< New hash block size. + u64 hash_block_size; ///< New hash block size (aligned to the AES block size from the NCA FS section). u8 *hash_block; ///< New hash block contents. u64 data_block_offset; ///< New data block offset (relative to the start of the NCA content file). u64 data_block_size; ///< New data block size (aligned to the NcaHierarchicalSha256 block size). @@ -69,9 +69,11 @@ NX_INLINE void pfsFreeContext(PartitionFileSystemContext *ctx) } /// Reads raw partition data using a partition FS context. +/// Input offset must be relative to the start of the partition FS. bool pfsReadPartitionData(PartitionFileSystemContext *ctx, void *out, u64 read_size, u64 offset); /// Reads data from a previously retrieved PartitionFileSystemEntry using a partition FS context. +/// Input offset must be relative to the start of the partition FS entry. bool pfsReadEntryData(PartitionFileSystemContext *ctx, PartitionFileSystemEntry *fs_entry, void *out, u64 read_size, u64 offset); /// Generates modified + encrypted hash and data blocks using a partition FS context + entry information. Both blocks are ready to be used to replace NCA content data during writing operations. diff --git a/source/romfs.h b/source/romfs.h index 41f056d..857c701 100644 --- a/source/romfs.h +++ b/source/romfs.h @@ -115,9 +115,11 @@ NX_INLINE void romfsFreeContext(RomFileSystemContext *ctx) } /// Reads raw filesystem data using a RomFS context. +/// Input offset must be relative to the start of the RomFS. bool romfsReadFileSystemData(RomFileSystemContext *ctx, void *out, u64 read_size, u64 offset); /// Reads data from a previously retrieved RomFileSystemFileEntry using a RomFS context. +/// Input offset must be relative to the start of the RomFS file entry. bool romfsReadFileEntryData(RomFileSystemContext *ctx, RomFileSystemFileEntry *file_entry, void *out, u64 read_size, u64 offset); /// Calculates the extracted RomFS size. diff --git a/source/services.c b/source/services.c index 80785be..6b074dc 100644 --- a/source/services.c +++ b/source/services.c @@ -215,7 +215,7 @@ static bool servicesClkGetServiceType(void *arg) if (!strlen(info->name) || strncmp(info->name, "clk", 3) != 0 || info->init_func != NULL || info->close_func != NULL) return false; /* Determine which service needs to be used to control hardware clock rates, depending on the system version */ - /* This may either be pcv (sysver lower than 8.0.0) or clkrst (sysver equal or greater than 8.0.0) */ + /* This may either be pcv (sysver lower than 8.0.0) or clkrst (sysver equal to or greater than 8.0.0) */ g_clkSvcUsePcv = hosversionBefore(8, 0, 0); /* Fill service info */ @@ -233,7 +233,7 @@ static bool servicesSplCryptoCheckAvailability(void *arg) ServicesInfoEntry *info = (ServicesInfoEntry*)arg; if (!strlen(info->name) || strncmp(info->name, "spl:mig", 7) != 0 || info->init_func == NULL || info->close_func == NULL) return false; - /* Check if spl:mig is available (sysver equal or greater than 4.0.0) */ + /* Check if spl:mig is available (sysver equal to or greater than 4.0.0) */ return !hosversionBefore(4, 0, 0); }