1
0
Fork 0
mirror of https://github.com/DarkMatterCore/nxdumptool.git synced 2024-12-23 09:02:06 +00:00

Another PFS patch test, works gucci.

This commit is contained in:
Pablo Curiel 2020-04-29 06:55:20 -04:00
parent d3278bc6f3
commit 08bfb89adb

View file

@ -26,6 +26,7 @@
#include <dirent.h>
#include "nca.h"
#include "pfs.h"
#include "romfs.h"
#include "rsa.h"
@ -75,7 +76,7 @@ int main(int argc, char *argv[])
};*/
// Untitled Goose Game's Program NCA
/*NcmPackagedContentInfo content_info = {
NcmPackagedContentInfo content_info = {
.hash = {
0x8E, 0xF9, 0x20, 0xD4, 0x5E, 0xE1, 0x9E, 0xD1, 0xD2, 0x04, 0xC4, 0xC8, 0x22, 0x50, 0x79, 0xE8,
0xD3, 0xE2, 0xE2, 0xA0, 0x66, 0xFD, 0x2B, 0xB6, 0x5C, 0x73, 0xF6, 0x89, 0xE2, 0x25, 0x0A, 0x82
@ -90,10 +91,10 @@ int main(int argc, char *argv[])
.content_type = NcmContentType_Program,
.id_offset = 0
}
};*/
};
// Untitled Goose Game's Control NCA
NcmPackagedContentInfo content_info = {
/*NcmPackagedContentInfo content_info = {
.hash = {
0xCE, 0x6E, 0x17, 0x1F, 0x93, 0x2D, 0x29, 0x28, 0xC1, 0x62, 0x94, 0x5B, 0x86, 0x2C, 0x42, 0x93,
0xAC, 0x2C, 0x0D, 0x3E, 0xD7, 0xCE, 0x07, 0xA2, 0x34, 0x33, 0x43, 0xD9, 0x21, 0x8A, 0xA3, 0xFE
@ -108,12 +109,11 @@ int main(int argc, char *argv[])
.content_type = NcmContentType_Control,
.id_offset = 0
}
};
};*/
u64 romfs_size = 0;
RomFileSystemFileEntry *romfs_file_entry = NULL;
RomFileSystemContext romfs_ctx = {0};
RomFileSystemFileEntryPatch romfs_patch = {0};
PartitionFileSystemEntry *pfs_entry = NULL;
PartitionFileSystemContext pfs_ctx = {0};
NcaHierarchicalSha256Patch pfs_patch = {0};
buf = malloc(0x400000);
if (!buf)
@ -164,162 +164,117 @@ int main(int argc, char *argv[])
consoleUpdate(NULL);
if (!romfsInitializeContext(&romfs_ctx, &(nca_ctx->fs_contexts[0])))
if (!pfsInitializeContext(&pfs_ctx, &(nca_ctx->fs_contexts[0])))
{
printf("romfs initialize ctx failed\n");
printf("pfs initialize ctx failed\n");
goto out2;
}
printf("romfs initialize ctx succeeded\n");
printf("pfs initialize ctx succeeded\n");
consoleUpdate(NULL);
tmp_file = fopen("sdmc:/nxdt_test/romfs_ctx.bin", "wb");
tmp_file = fopen("sdmc:/nxdt_test/pfs_ctx.bin", "wb");
if (tmp_file)
{
fwrite(&romfs_ctx, 1, sizeof(RomFileSystemContext), tmp_file);
fwrite(&pfs_ctx, 1, sizeof(PartitionFileSystemContext), tmp_file);
fclose(tmp_file);
tmp_file = NULL;
printf("romfs ctx saved\n");
printf("pfs ctx saved\n");
} else {
printf("romfs ctx not saved\n");
printf("pfs ctx not saved\n");
}
consoleUpdate(NULL);
tmp_file = fopen("sdmc:/nxdt_test/dir_table.bin", "wb");
tmp_file = fopen("sdmc:/nxdt_test/pfs_header.bin", "wb");
if (tmp_file)
{
fwrite(romfs_ctx.dir_table, 1, romfs_ctx.dir_table_size, tmp_file);
fwrite(pfs_ctx.header, 1, pfs_ctx.header_size, tmp_file);
fclose(tmp_file);
tmp_file = NULL;
printf("romfs dir table saved\n");
printf("pfs header saved\n");
} else {
printf("romfs dir table not saved\n");
printf("pfs header not saved\n");
}
consoleUpdate(NULL);
tmp_file = fopen("sdmc:/nxdt_test/file_table.bin", "wb");
if (tmp_file)
pfs_entry = pfsGetEntryByName(&pfs_ctx, "main.npdm");
if (!pfs_entry)
{
fwrite(romfs_ctx.file_table, 1, romfs_ctx.file_table_size, tmp_file);
fclose(tmp_file);
tmp_file = NULL;
printf("romfs file table saved\n");
} else {
printf("romfs file table not saved\n");
}
consoleUpdate(NULL);
if (romfsReadFileSystemData(&romfs_ctx, buf, romfs_ctx.size, 0))
{
printf("romfs read fs data success\n");
consoleUpdate(NULL);
tmp_file = fopen("sdmc:/nxdt_test/romfs.bin", "wb");
if (tmp_file)
{
fwrite(buf, 1, romfs_ctx.size, tmp_file);
fclose(tmp_file);
tmp_file = NULL;
printf("romfs data saved\n");
} else {
printf("romfs data not saved\n");
}
} else {
printf("romfs read fs data failed\n");
}
if (romfsGetTotalDataSize(&romfs_ctx, &romfs_size))
{
printf("romfs size succeeded: 0x%lX\n", romfs_size);
} else {
printf("romfs size failed\n");
}
consoleUpdate(NULL);
romfs_file_entry = romfsGetFileEntryByPath(&romfs_ctx, "/control.nacp");
if (!romfs_file_entry)
{
printf("romfs get file entry by path failed\n");
printf("pfs get entry by name failed\n");
goto out2;
}
printf("romfs get file entry by path success: %s | %p\n", romfs_file_entry->name, romfs_file_entry);
printf("pfs get entry by name succeeded\n");
consoleUpdate(NULL);
if (!romfsReadFileEntryData(&romfs_ctx, romfs_file_entry, buf, romfs_file_entry->size, 0))
if (!pfsReadEntryData(&pfs_ctx, pfs_entry, buf, pfs_entry->size, 0))
{
printf("romfs read file entry failed\n");
printf("pfs read entry data failed\n");
goto out2;
}
printf("romfs read file entry success\n");
printf("pfs read entry data succeeded\n");
consoleUpdate(NULL);
tmp_file = fopen("sdmc:/nxdt_test/control.nacp", "wb");
tmp_file = fopen("sdmc:/nxdt_test/main.npdm", "wb");
if (tmp_file)
{
fwrite(buf, 1, romfs_file_entry->size, tmp_file);
fwrite(buf, 1, pfs_entry->size, tmp_file);
fclose(tmp_file);
tmp_file = NULL;
printf("romfs file entry data saved\n");
printf("main.npdm saved\n");
} else {
printf("romfs file entry data not saved\n");
printf("main.npdm not saved\n");
}
consoleUpdate(NULL);
NacpStruct *nacp_data = (NacpStruct*)buf;
memset(nacp_data->lang, 0, MEMBER_SIZE(NacpStruct, lang));
for(u8 i = 0; i < 16; i++)
{
sprintf(nacp_data->lang[i].name, "nxdumptool");
sprintf(nacp_data->lang[i].author, "DarkMatterCore");
}
u32 acid_offset = 0;
memcpy(&acid_offset, buf + 0x78, sizeof(u32));
memcpy(buf + acid_offset + RSA2048_SIGNATURE_SIZE, rsa2048GetCustomAcidPublicKey(), RSA2048_SIGNATURE_SIZE);
tmp_file = fopen("sdmc:/nxdt_test/control_mod.nacp", "wb");
tmp_file = fopen("sdmc:/nxdt_test/main_mod.npdm", "wb");
if (tmp_file)
{
fwrite(buf, 1, romfs_file_entry->size, tmp_file);
fwrite(buf, 1, pfs_entry->size, tmp_file);
fclose(tmp_file);
tmp_file = NULL;
printf("romfs file entry mod data saved\n");
printf("main_mod.npdm saved\n");
} else {
printf("romfs file entry mod data not saved\n");
printf("main_mod.npdm not saved\n");
}
consoleUpdate(NULL);
if (!romfsGenerateFileEntryPatch(&romfs_ctx, romfs_file_entry, buf, MEMBER_SIZE(NacpStruct, lang), 0, &romfs_patch))
if (!pfsGenerateEntryPatch(&pfs_ctx, pfs_entry, buf + acid_offset + RSA2048_SIGNATURE_SIZE, RSA2048_SIGNATURE_SIZE, acid_offset + RSA2048_SIGNATURE_SIZE, &pfs_patch))
{
printf("romfs file entry patch failed\n");
printf("pfs entry patch failed\n");
goto out2;
}
printf("romfs file entry patch success\n");
printf("pfs entry patch succeeded\n");
consoleUpdate(NULL);
tmp_file = fopen("sdmc:/nxdt_test/romfs_patch.bin", "wb");
tmp_file = fopen("sdmc:/nxdt_test/pfs_patch.bin", "wb");
if (tmp_file)
{
fwrite(&romfs_patch, 1, sizeof(RomFileSystemFileEntryPatch), tmp_file);
fwrite(&pfs_patch, 1, sizeof(NcaHierarchicalSha256Patch), tmp_file);
fclose(tmp_file);
tmp_file = NULL;
printf("romfs patch saved\n");
printf("pfs patch saved\n");
} else {
printf("romfs patch not saved\n");
printf("pfs patch not saved\n");
}
for(u8 i = 0; i < (NCA_IVFC_HASH_DATA_LAYER_COUNT + 1); i++)
for(u8 i = 0; i < 2; i++)
{
NcaHashInfoLayerPatch *layer_patch = (i < NCA_IVFC_HASH_DATA_LAYER_COUNT ? &(romfs_patch.cur_format_patch.hash_data_layer_patch[i]) : &(romfs_patch.cur_format_patch.hash_target_layer_patch));
NcaHashInfoLayerPatch *layer_patch = (i == 0 ? &(pfs_patch.hash_data_layer_patch) : &(pfs_patch.hash_target_layer_patch));
if (!layer_patch->size || !layer_patch->data) continue;
char path[64];
sprintf(path, "sdmc:/nxdt_test/romfs_patch_l%u.bin", i);
sprintf(path, "sdmc:/nxdt_test/pfs_patch_l%u.bin", i);
tmp_file = fopen(path, "wb");
if (tmp_file)
@ -327,9 +282,9 @@ int main(int argc, char *argv[])
fwrite(layer_patch->data, 1, layer_patch->size, tmp_file);
fclose(tmp_file);
tmp_file = NULL;
printf("romfs patch #%u saved\n", i);
printf("pfs patch #%u saved\n", i);
} else {
printf("romfs patch #%u not saved\n", i);
printf("pfs patch #%u not saved\n", i);
}
consoleUpdate(NULL);
@ -376,9 +331,9 @@ out2:
if (tmp_file) fclose(tmp_file);
romfsFreeFileEntryPatch(&romfs_patch);
ncaFreeHierarchicalSha256Patch(&pfs_patch);
romfsFreeContext(&romfs_ctx);
pfsFreeContext(&pfs_ctx);
if (serviceIsActive(&(ncm_storage.s))) ncmContentStorageClose(&ncm_storage);