mirror of
https://github.com/DarkMatterCore/nxdumptool.git
synced 2024-11-22 18:26:39 +00:00
PFS0 read improved.
This commit is contained in:
parent
7c8bf5c831
commit
dccb33ab0c
3 changed files with 31 additions and 25 deletions
|
@ -220,32 +220,22 @@ int main(int argc, char *argv[])
|
|||
printf("pfs0 get entry by name succeeded\n");
|
||||
consoleUpdate(NULL);
|
||||
|
||||
u64 main_npdm_offset = 0;
|
||||
if (!pfs0GetEntryDataOffset(&pfs0_ctx, pfs0_entry, &main_npdm_offset))
|
||||
{
|
||||
printf("pfs0 get entry data offset failed\n");
|
||||
goto out2;
|
||||
}
|
||||
|
||||
printf("main.npdm offset = 0x%lX\n", main_npdm_offset);
|
||||
consoleUpdate(NULL);
|
||||
|
||||
tmp_file = fopen("sdmc:/nxdt_test/main.npdm", "wb");
|
||||
if (tmp_file)
|
||||
{
|
||||
u64 blksize = 0x400000;
|
||||
u64 total = pfs0_entry->size;
|
||||
|
||||
printf("main.npdm created: 0x%lX\n", total);
|
||||
printf("main.npdm created. Target size -> 0x%lX\n", total);
|
||||
consoleUpdate(NULL);
|
||||
|
||||
for(u64 curpos = 0; curpos < total; curpos += blksize)
|
||||
{
|
||||
if (blksize > (total - curpos)) blksize = (total - curpos);
|
||||
|
||||
if (!ncaReadFsSection(pfs0_ctx.nca_fs_ctx, buf, blksize, main_npdm_offset + curpos))
|
||||
if (!pfs0ReadEntryData(&pfs0_ctx, pfs0_entry, buf, blksize, 0))
|
||||
{
|
||||
printf("nca read section failed\n");
|
||||
printf("pfs0 read entry data failed\n");
|
||||
goto out2;
|
||||
}
|
||||
|
||||
|
@ -255,7 +245,7 @@ int main(int argc, char *argv[])
|
|||
fclose(tmp_file);
|
||||
tmp_file = NULL;
|
||||
|
||||
printf("nca read main.npdm success\n");
|
||||
printf("pfs0 read main.npdm success\n");
|
||||
} else {
|
||||
printf("main.npdm not created\n");
|
||||
}
|
||||
|
|
|
@ -58,8 +58,6 @@ bool pfs0InitializeContext(PartitionFileSystemContext *out, NcaFsSectionContext
|
|||
/* Read partial PFS0 header */
|
||||
u32 magic = 0;
|
||||
PartitionFileSystemHeader pfs0_header = {0};
|
||||
|
||||
u64 main_npdm_offset = 0;
|
||||
PartitionFileSystemEntry *main_npdm_entry = NULL;
|
||||
|
||||
if (!ncaReadFsSection(nca_fs_ctx, &pfs0_header, sizeof(PartitionFileSystemHeader), out->offset))
|
||||
|
@ -100,8 +98,30 @@ bool pfs0InitializeContext(PartitionFileSystemContext *out, NcaFsSectionContext
|
|||
}
|
||||
|
||||
/* Check if we're dealing with an ExeFS section */
|
||||
if ((main_npdm_entry = pfs0GetEntryByName(out, "main.npdm")) != NULL && pfs0GetEntryDataOffset(out, main_npdm_entry, &main_npdm_offset) && \
|
||||
ncaReadFsSection(out->nca_fs_ctx, &magic, sizeof(u32), main_npdm_offset) && __builtin_bswap32(magic) == NPDM_META_MAGIC) out->is_exefs = true;
|
||||
if ((main_npdm_entry = pfs0GetEntryByName(out, "main.npdm")) != NULL && pfs0ReadEntryData(out, main_npdm_entry, &magic, sizeof(u32), 0) && \
|
||||
__builtin_bswap32(magic) == NPDM_META_MAGIC) out->is_exefs = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pfs0ReadEntryData(PartitionFileSystemContext *ctx, PartitionFileSystemEntry *fs_entry, void *out, u64 read_size, u64 offset)
|
||||
{
|
||||
if (!ctx || !ctx->nca_fs_ctx || !ctx->hash_info || !ctx->size || !ctx->header_size || !ctx->header || !fs_entry || fs_entry->offset >= ctx->size || \
|
||||
(fs_entry->offset + fs_entry->size) > ctx->size || !out || !read_size || offset >= fs_entry->size || (offset + read_size) > fs_entry->size)
|
||||
{
|
||||
LOGFILE("Invalid parameters!");
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Calculate offset relative to the start of the NCA FS section */
|
||||
u64 section_offset = (ctx->offset + ctx->header_size + fs_entry->offset + offset);
|
||||
|
||||
/* Read entry data */
|
||||
if (!ncaReadFsSection(ctx->nca_fs_ctx, out, read_size, section_offset))
|
||||
{
|
||||
LOGFILE("Failed to read PFS0 entry data!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -59,6 +59,9 @@ static inline void pfs0FreeContext(PartitionFileSystemContext *ctx)
|
|||
memset(ctx, 0, sizeof(PartitionFileSystemContext));
|
||||
}
|
||||
|
||||
/// Reads data from a previously retrieved PartitionFileSystemEntry using a PFS0 context.
|
||||
bool pfs0ReadEntryData(PartitionFileSystemContext *ctx, PartitionFileSystemEntry *fs_entry, void *out, u64 read_size, u64 offset);
|
||||
|
||||
/// Miscellaneous functions.
|
||||
|
||||
static inline u32 pfs0GetEntryCount(PartitionFileSystemContext *ctx)
|
||||
|
@ -67,13 +70,6 @@ static inline u32 pfs0GetEntryCount(PartitionFileSystemContext *ctx)
|
|||
return ((PartitionFileSystemHeader*)ctx->header)->entry_count;
|
||||
}
|
||||
|
||||
static inline bool pfs0GetEntryDataOffset(PartitionFileSystemContext *ctx, PartitionFileSystemEntry *fs_entry, u64 *out_offset)
|
||||
{
|
||||
if (!ctx || !ctx->header_size || !ctx->header || !fs_entry || !out_offset) return false;
|
||||
*out_offset = (ctx->offset + ctx->header_size + fs_entry->offset); /* Relative to the start of the NCA FS section */
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline PartitionFileSystemEntry *pfs0GetEntryByIndex(PartitionFileSystemContext *ctx, u32 idx)
|
||||
{
|
||||
if (idx >= pfs0GetEntryCount(ctx)) return NULL;
|
||||
|
|
Loading…
Reference in a new issue