1
0
Fork 0
mirror of https://github.com/DarkMatterCore/nxdumptool.git synced 2024-11-22 18:26:39 +00:00

Small PFS fix.

This commit is contained in:
Pablo Curiel 2020-04-28 00:38:24 -04:00
parent 2c252c03b2
commit 226fbd0e21
2 changed files with 28 additions and 5 deletions

View file

@ -1,4 +1,5 @@
todo:
```
todo:
hfs0: filelist generation methods
@ -9,12 +10,30 @@
romfs: data replacement methods
romfs: filelist generation methods
nacp mod:
1. Patch StartupUserAccount in control.nacp to 0x01.
2. Recalculate hash for the control.nacp file. Store it in the RomFS file hash table. -> Not so sure about this...
3. Recalculate hashes for the modified blocks, then perform chain hash calculation / replacement per each IVFC level up until reaching superblock hash.
4. Reencrypt all the modified blocks using the already known crypto properties. Keep the modified + encrypted blocks in memory.
5. Recalculate RomFS section header SHA-256 hash. Replace the section hash in the NCA header. Keep a copy of the modified NCA header in memory.
6. While generating the output dump, replace sections in the Control NCA with the previously modified + reencrypted blocks before writing data. Also replace the NCA header.
Result txIsFat32(bool *mode) {
Result rc = serviceDispatch(&g_tx, 137);
if (rc == 0xa08) {
*mode = false;
return 0;
} else if (rc == 0) {
*mode = true;
}
return rc;
}
```

View file

@ -158,9 +158,9 @@ bool pfsGenerateEntryPatch(PartitionFileSystemContext *ctx, PartitionFileSystemE
u64 data_block_start_offset = (ctx->offset + ALIGN_DOWN(partition_offset, block_size));
u64 data_block_end_offset = (ctx->offset + ALIGN_UP(partition_offset + data_size, block_size));
if (data_block_end_offset > (ctx->offset + ctx->size)) data_block_end_offset = (ctx->offset + ctx->size);
u64 data_block_size = (data_block_end_offset - data_block_start_offset);
u64 block_count = (hash_block_size / SHA256_HASH_SIZE);
u64 new_data_offset = (partition_offset - ALIGN_DOWN(partition_offset, block_size));
u8 *hash_table = NULL, *data_block = NULL;
@ -201,7 +201,11 @@ bool pfsGenerateEntryPatch(PartitionFileSystemContext *ctx, PartitionFileSystemE
memcpy(data_block + new_data_offset, data, data_size);
/* Recalculate hashes */
for(u64 i = 0; i < block_count; i++) sha256CalculateHash(hash_table + hash_block_start_offset + (i * SHA256_HASH_SIZE), data_block + (i * block_size), block_size);
for(u64 i = 0, j = 0; i < data_block_size; i += block_size, j++)
{
if (block_size > (data_block_size - i)) block_size = (data_block_size - i);
sha256CalculateHash(hash_table + hash_block_start_offset + (j * SHA256_HASH_SIZE), data_block + i, block_size);
}
/* Reencrypt hash block */
out->hash_block = ncaGenerateEncryptedFsSectionBlock(ctx->nca_fs_ctx, hash_table + hash_block_start_offset, hash_block_size, hash_table_offset + hash_block_start_offset, \