Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/npdmtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ typedef struct {
u8 _0xD;
u8 MainThreadPriority;
u8 DefaultCpuId;
u64 _0x10;
u32 _0x10;
u32 SystemResourceSize;
u32 ProcessCategory;
u32 MainThreadStackSize;
char Name[0x10];
Expand Down Expand Up @@ -219,6 +220,32 @@ int cJSON_GetU64(const cJSON *obj, const char *field, u64 *out) {
}
}

int cJSON_GetU32(const cJSON *obj, const char *field, u32 *out) {
const cJSON *config = cJSON_GetObjectItemCaseSensitive(obj, field);
if (cJSON_IsString(config) && (config->valuestring != NULL)) {
char *endptr = NULL;
*out = strtoul(config->valuestring, &endptr, 16);
if (config->valuestring == endptr) {
fprintf(stderr, "Failed to get %s (empty string)\n", field);
return 0;
} else if (errno == ERANGE) {
fprintf(stderr, "Failed to get %s (value out of range)\n", field);
return 0;
} else if (errno == EINVAL) {
fprintf(stderr, "Failed to get %s (not base16 string)\n", field);
return 0;
} else if (errno) {
fprintf(stderr, "Failed to get %s (unknown error)\n", field);
return 0;
} else {
return 1;
}
} else {
fprintf(stderr, "Failed to get %s (field not present).\n", field);
return 0;
}
}

int cJSON_GetU64FromObjectValue(const cJSON *config, u64 *out) {
if (cJSON_IsString(config) && (config->valuestring != NULL)) {
char *endptr = NULL;
Expand Down Expand Up @@ -305,6 +332,9 @@ int CreateNpdm(const char *json, void **dst, u32 *dst_size) {
status = 0;
goto NPDM_BUILD_END;
}

cJSON_GetU32(npdm_json, "system_resource_size", &header.SystemResourceSize); // optional

if (!cJSON_GetU8(npdm_json, "process_category", (u8 *)&header.ProcessCategory)) {
status = 0;
goto NPDM_BUILD_END;
Expand Down