Skip to content

Commit f1ffee8

Browse files
SciresMWinterMute
authored andcommitted
npdmtool: generate FAC compatible with 4.1.0 and under
1 parent 2c7bedf commit f1ffee8

1 file changed

Lines changed: 25 additions & 45 deletions

File tree

src/npdmtool.c

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -411,80 +411,60 @@ int CreateNpdm(const char *json, void **dst, u32 *dst_size) {
411411
goto NPDM_BUILD_END;
412412
}
413413

414-
cJSON_GetU64(fsaccess, "content_owner_id_min", &fac->CoiMin);
415-
cJSON_GetU64(fsaccess, "content_owner_id_max", &fac->CoiMax);
416-
417-
cois = cJSON_GetObjectItemCaseSensitive(fsaccess, "content_owner_ids");
418-
if (cJSON_IsArray(cois)) {
419-
int idx = 0;
420-
u64 *content_owner_id = (u64 *)((u8 *)fac + sizeof(FilesystemAccessControl));
421-
cJSON_ArrayForEach(coi, cois) {
422-
if (!cJSON_GetU64FromObjectValue(coi, content_owner_id)) {
423-
status = 0;
424-
goto NPDM_BUILD_END;
425-
}
426-
++content_owner_id;
427-
++idx;
428-
}
429-
fac->CoiCount = idx;
430-
}
431-
432-
cJSON_GetU64(fsaccess, "save_data_owner_id_min", &fac->SdoiMin);
433-
cJSON_GetU64(fsaccess, "save_data_owner_id_max", &fac->SdoiMax);
434-
435-
sdois = cJSON_GetObjectItemCaseSensitive(fsaccess, "save_data_owner_ids");
436-
if (cJSON_IsArray(sdois)) {
437-
int idx = 0;
438-
u64 *save_data_owner_id = (u64 *)((u8 *)fac + sizeof(FilesystemAccessControl) + fac->CoiCount * sizeof(u64));
439-
cJSON_ArrayForEach(sdoi, sdois) {
440-
if (!cJSON_GetU64FromObjectValue(sdoi, save_data_owner_id)) {
441-
status = 0;
442-
goto NPDM_BUILD_END;
443-
}
444-
++save_data_owner_id;
445-
++idx;
446-
}
447-
fac->SdoiCount = idx;
448-
}
414+
fac->CoiMin = 0;
415+
fac->CoiMax = 0;
416+
fac->SdoiMin = 0;
417+
fac->SdoiMax = 0;
418+
fac->CoiCount = 0;
419+
fac->SdoiCount = 0;
449420

450421
acid->FacOffset = sizeof(NpdmAcid);
451-
acid->FacSize = sizeof(FilesystemAccessControl) + fac->CoiCount * sizeof(u64) + fac->SdoiCount * sizeof(u64);
422+
acid->FacSize = sizeof(FilesystemAccessControl);
452423
acid->SacOffset = (acid->FacOffset + acid->FacSize + 0xF) & ~0xF;
453424

454425
/* Fah. */
455426
FilesystemAccessHeader *fah = (FilesystemAccessHeader *)((u8 *)aci0 + sizeof(NpdmAci0));
456427
fah->Version = 1;
457428
fah->Perms = fac->Perms;
458429
fah->CoiOffset = sizeof(FilesystemAccessHeader);
459-
fah->CoiSize = fac->CoiCount ? 4 + fac->CoiCount * sizeof(u64) : 0;
460-
fah->SdoiOffset = fah->CoiOffset + fah->CoiSize;
461-
fah->SdoiSize = fac->SdoiCount ? 4 + fac->SdoiCount * sizeof(u64) : 0;
430+
fah->CoiSize = 0;
462431

463-
if (fac->CoiCount) {
432+
cois = cJSON_GetObjectItemCaseSensitive(fsaccess, "content_owner_ids");
433+
if (cJSON_IsArray(cois)) {
464434
u32 *count = (u32 *)((u8 *)fah + fah->CoiOffset);
465-
*count = fac->CoiCount;
466-
467435
u64 *id = (u64 *)((u8 *)count + sizeof(u32));
468436
cJSON_ArrayForEach(coi, cois) {
469437
if (!cJSON_GetU64FromObjectValue(coi, id)) {
470438
status = 0;
471439
goto NPDM_BUILD_END;
472440
}
473441
++id;
442+
++(*count);
443+
}
444+
445+
if (*count > 0) {
446+
fah->CoiSize = sizeof(u32) + sizeof(u64) * (*count);
474447
}
475448
}
476449

477-
if (fac->SdoiCount) {
478-
u32 *count = (u32 *)((u8 *)fah + fah->SdoiOffset);
479-
*count = fac->SdoiCount;
450+
fah->SdoiOffset = fah->CoiOffset + fah->CoiSize;
451+
fah->SdoiSize = 0;
480452

453+
sdois = cJSON_GetObjectItemCaseSensitive(fsaccess, "save_data_owner_ids");
454+
if (cJSON_IsArray(sdois)) {
455+
u32 *count = (u32 *)((u8 *)fah + fah->SdoiOffset);
481456
u64 *id = (u64 *)((u8 *)count + sizeof(u32));
482457
cJSON_ArrayForEach(sdoi, sdois) {
483458
if (!cJSON_GetU64FromObjectValue(sdoi, id)) {
484459
status = 0;
485460
goto NPDM_BUILD_END;
486461
}
487462
++id;
463+
++(*count);
464+
}
465+
466+
if (*count > 0) {
467+
fah->SdoiSize = sizeof(u32) + sizeof(u64) * (*count);
488468
}
489469
}
490470

0 commit comments

Comments
 (0)