1
0
Fork 0
mirror of https://github.com/DarkMatterCore/nxdumptool.git synced 2024-12-27 19:06:01 +00:00

BKTR: updated file entry detection.

This commit is contained in:
Pablo Curiel 2020-05-01 00:34:30 -04:00
parent efb9b2d103
commit e2b4ebc5d4
3 changed files with 72 additions and 4 deletions

View file

@ -246,6 +246,44 @@ bool bktrReadFileEntryData(BktrContext *ctx, RomFileSystemFileEntry *file_entry,
return true;
}
bool bktrIsFileEntryUpdated(BktrContext *ctx, RomFileSystemFileEntry *file_entry, bool *out)
{
if (!ctx || !ctx->body_offset || !ctx->indirect_block || !file_entry || !file_entry->size || file_entry->offset >= ctx->size || (file_entry->offset + file_entry->size) > ctx->size || !out)
{
LOGFILE("Invalid parameters!");
return false;
}
bool updated = false;
u64 file_offset = (ctx->offset + ctx->body_offset + file_entry->offset);
BktrIndirectStorageEntry *indirect_entry = NULL, *last_indirect_entry = NULL;
indirect_entry = bktrGetIndirectStorageEntry(ctx->indirect_block, file_offset);
if (!indirect_entry)
{
LOGFILE("Error retrieving BKTR Indirect Storage Entry at offset 0x%lX!", file_offset);
return false;
}
last_indirect_entry = indirect_entry;
while(last_indirect_entry->virtual_offset < (file_offset + file_entry->size)) last_indirect_entry++;
while(indirect_entry < last_indirect_entry)
{
if (indirect_entry->indirect_storage_index == BktrIndirectStorageIndex_Patch)
{
updated = true;
break;
}
indirect_entry++;
}
*out = updated;
return true;
}
static bool bktrPhysicalSectionRead(BktrContext *ctx, void *out, u64 read_size, u64 offset)
{
if (!ctx || !ctx->base_romfs_ctx.nca_fs_ctx || !ctx->indirect_block || !out || !read_size)

View file

@ -102,6 +102,9 @@ bool bktrReadFileSystemData(BktrContext *ctx, void *out, u64 read_size, u64 offs
/// Input offset must be relative to the start of the RomFS file entry data.
bool bktrReadFileEntryData(BktrContext *ctx, RomFileSystemFileEntry *file_entry, void *out, u64 read_size, u64 offset);
/// Checks if a RomFS file entry is updated by the Patch RomFS.
bool bktrIsFileEntryUpdated(BktrContext *ctx, RomFileSystemFileEntry *file_entry, bool *out);
/// Miscellaneous functions.
/// These are just wrappers for RomFS functions.

View file

@ -211,7 +211,7 @@ int main(int argc, char *argv[])
consoleUpdate(NULL);
bktr_file_entry = bktrGetFileEntryByPath(&bktr_ctx, "/Data/resources.assets");
/*bktr_file_entry = bktrGetFileEntryByPath(&bktr_ctx, "/Data/resources.assets");
if (!bktr_file_entry)
{
printf("bktr get file entry by path failed\n");
@ -219,7 +219,7 @@ int main(int argc, char *argv[])
}
printf("bktr get file entry by path success: %.*s | 0x%lX\n", bktr_file_entry->name_length, bktr_file_entry->name, bktr_file_entry->size);
consoleUpdate(NULL);
consoleUpdate(NULL);*/
/*tmp_file = fopen("sdmc:/nxdt_test/resources.assets", "wb");
if (tmp_file)
@ -245,9 +245,11 @@ int main(int argc, char *argv[])
}
} else {
printf("resources.assets not saved\n");
}*/
}
tmp_file = fopen("sdmc:/nxdt_test/romfs.bin", "wb");
consoleUpdate(NULL);*/
/*tmp_file = fopen("sdmc:/nxdt_test/romfs.bin", "wb");
if (tmp_file)
{
u64 curpos = 0, blksize = 0x400000;
@ -273,6 +275,31 @@ int main(int argc, char *argv[])
printf("romfs not saved\n");
}
consoleUpdate(NULL);*/
printf("updated file list:\n");
consoleUpdate(NULL);
u64 offset = 0;
bool updated = false;
char bktr_path[FS_MAX_PATH] = {0};
while(offset < bktr_ctx.patch_romfs_ctx.file_table_size)
{
if (!(bktr_file_entry = bktrGetFileEntryByOffset(&bktr_ctx, offset)))
{
printf("Failed to retrieve file entry!\n");
goto out2;
}
if (bktrIsFileEntryUpdated(&bktr_ctx, bktr_file_entry, &updated) && updated && bktrGeneratePathFromFileEntry(&bktr_ctx, bktr_file_entry, bktr_path, FS_MAX_PATH))
{
printf("%s\n", bktr_path);
consoleUpdate(NULL);
}
offset += ALIGN_UP(sizeof(RomFileSystemFileEntry) + bktr_file_entry->name_length, 4);
}