mirror of
https://github.com/d0k3/GodMode9.git
synced 2025-06-26 05:32:47 +00:00
Fix detection of trimmed NCSD images
This commit is contained in:
parent
baf1a645ca
commit
8947db2037
@ -40,7 +40,7 @@ u32 IdentifyFileType(const char* path) {
|
||||
return GAME_CIA; // CIA file
|
||||
} else if (ValidateNcsdHeader((NcsdHeader*) (void*) header) == 0) {
|
||||
NcsdHeader* ncsd = (NcsdHeader*) (void*) header;
|
||||
if (fsize >= (ncsd->size * NCSD_MEDIA_UNIT))
|
||||
if (fsize >= GetNcsdTrimmedSize(ncsd))
|
||||
return GAME_NCSD; // NCSD (".3DS") file
|
||||
} else if (ValidateNcchHeader((NcchHeader*) (void*) header) == 0) {
|
||||
NcchHeader* ncch = (NcchHeader*) (void*) header;
|
||||
|
@ -20,3 +20,15 @@ u32 ValidateNcsdHeader(NcsdHeader* header) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 GetNcsdTrimmedSize(NcsdHeader* header) {
|
||||
u32 data_units = 0;
|
||||
for (u32 i = 0; i < 8; i++) {
|
||||
NcchPartition* partition = header->partitions + i;
|
||||
u32 partition_end = partition->offset + partition->size;
|
||||
if (!partition->size) continue;
|
||||
data_units = (partition_end > data_units) ? partition_end : data_units;
|
||||
}
|
||||
|
||||
return data_units * NCSD_MEDIA_UNIT;
|
||||
}
|
||||
|
@ -32,3 +32,4 @@ typedef struct {
|
||||
} __attribute__((packed)) NcsdHeader;
|
||||
|
||||
u32 ValidateNcsdHeader(NcsdHeader* header);
|
||||
u32 GetNcsdTrimmedSize(NcsdHeader* header);
|
||||
|
Loading…
x
Reference in New Issue
Block a user