npdmtool: generate FAC compatible with 4.1.0 and under

This commit is contained in:
Michael Scire 2020-07-08 16:59:14 -07:00 committed by Dave Murphy
parent 2c7bedf37b
commit f1ffee8e1d

View File

@ -411,44 +411,15 @@ int CreateNpdm(const char *json, void **dst, u32 *dst_size) {
goto NPDM_BUILD_END; goto NPDM_BUILD_END;
} }
cJSON_GetU64(fsaccess, "content_owner_id_min", &fac->CoiMin); fac->CoiMin = 0;
cJSON_GetU64(fsaccess, "content_owner_id_max", &fac->CoiMax); fac->CoiMax = 0;
fac->SdoiMin = 0;
cois = cJSON_GetObjectItemCaseSensitive(fsaccess, "content_owner_ids"); fac->SdoiMax = 0;
if (cJSON_IsArray(cois)) { fac->CoiCount = 0;
int idx = 0; fac->SdoiCount = 0;
u64 *content_owner_id = (u64 *)((u8 *)fac + sizeof(FilesystemAccessControl));
cJSON_ArrayForEach(coi, cois) {
if (!cJSON_GetU64FromObjectValue(coi, content_owner_id)) {
status = 0;
goto NPDM_BUILD_END;
}
++content_owner_id;
++idx;
}
fac->CoiCount = idx;
}
cJSON_GetU64(fsaccess, "save_data_owner_id_min", &fac->SdoiMin);
cJSON_GetU64(fsaccess, "save_data_owner_id_max", &fac->SdoiMax);
sdois = cJSON_GetObjectItemCaseSensitive(fsaccess, "save_data_owner_ids");
if (cJSON_IsArray(sdois)) {
int idx = 0;
u64 *save_data_owner_id = (u64 *)((u8 *)fac + sizeof(FilesystemAccessControl) + fac->CoiCount * sizeof(u64));
cJSON_ArrayForEach(sdoi, sdois) {
if (!cJSON_GetU64FromObjectValue(sdoi, save_data_owner_id)) {
status = 0;
goto NPDM_BUILD_END;
}
++save_data_owner_id;
++idx;
}
fac->SdoiCount = idx;
}
acid->FacOffset = sizeof(NpdmAcid); acid->FacOffset = sizeof(NpdmAcid);
acid->FacSize = sizeof(FilesystemAccessControl) + fac->CoiCount * sizeof(u64) + fac->SdoiCount * sizeof(u64); acid->FacSize = sizeof(FilesystemAccessControl);
acid->SacOffset = (acid->FacOffset + acid->FacSize + 0xF) & ~0xF; acid->SacOffset = (acid->FacOffset + acid->FacSize + 0xF) & ~0xF;
/* Fah. */ /* Fah. */
@ -456,14 +427,11 @@ int CreateNpdm(const char *json, void **dst, u32 *dst_size) {
fah->Version = 1; fah->Version = 1;
fah->Perms = fac->Perms; fah->Perms = fac->Perms;
fah->CoiOffset = sizeof(FilesystemAccessHeader); fah->CoiOffset = sizeof(FilesystemAccessHeader);
fah->CoiSize = fac->CoiCount ? 4 + fac->CoiCount * sizeof(u64) : 0; fah->CoiSize = 0;
fah->SdoiOffset = fah->CoiOffset + fah->CoiSize;
fah->SdoiSize = fac->SdoiCount ? 4 + fac->SdoiCount * sizeof(u64) : 0;
if (fac->CoiCount) { cois = cJSON_GetObjectItemCaseSensitive(fsaccess, "content_owner_ids");
if (cJSON_IsArray(cois)) {
u32 *count = (u32 *)((u8 *)fah + fah->CoiOffset); u32 *count = (u32 *)((u8 *)fah + fah->CoiOffset);
*count = fac->CoiCount;
u64 *id = (u64 *)((u8 *)count + sizeof(u32)); u64 *id = (u64 *)((u8 *)count + sizeof(u32));
cJSON_ArrayForEach(coi, cois) { cJSON_ArrayForEach(coi, cois) {
if (!cJSON_GetU64FromObjectValue(coi, id)) { if (!cJSON_GetU64FromObjectValue(coi, id)) {
@ -471,13 +439,20 @@ int CreateNpdm(const char *json, void **dst, u32 *dst_size) {
goto NPDM_BUILD_END; goto NPDM_BUILD_END;
} }
++id; ++id;
++(*count);
}
if (*count > 0) {
fah->CoiSize = sizeof(u32) + sizeof(u64) * (*count);
} }
} }
if (fac->SdoiCount) { fah->SdoiOffset = fah->CoiOffset + fah->CoiSize;
u32 *count = (u32 *)((u8 *)fah + fah->SdoiOffset); fah->SdoiSize = 0;
*count = fac->SdoiCount;
sdois = cJSON_GetObjectItemCaseSensitive(fsaccess, "save_data_owner_ids");
if (cJSON_IsArray(sdois)) {
u32 *count = (u32 *)((u8 *)fah + fah->SdoiOffset);
u64 *id = (u64 *)((u8 *)count + sizeof(u32)); u64 *id = (u64 *)((u8 *)count + sizeof(u32));
cJSON_ArrayForEach(sdoi, sdois) { cJSON_ArrayForEach(sdoi, sdois) {
if (!cJSON_GetU64FromObjectValue(sdoi, id)) { if (!cJSON_GetU64FromObjectValue(sdoi, id)) {
@ -485,6 +460,11 @@ int CreateNpdm(const char *json, void **dst, u32 *dst_size) {
goto NPDM_BUILD_END; goto NPDM_BUILD_END;
} }
++id; ++id;
++(*count);
}
if (*count > 0) {
fah->SdoiSize = sizeof(u32) + sizeof(u64) * (*count);
} }
} }