forked from pplatoon/hacBrewPack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcnmt.c
47 lines (40 loc) · 1.58 KB
/
cnmt.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "cnmt.h"
#include "filepath.h"
#include "utils.h"
void cnmt_create(cnmt_ctx_t *cnmt_ctx, filepath_t *cnmt_filepath)
{
cnmt_extended_application_header_t cnmt_ext_header;
memset(&cnmt_ext_header, 0, sizeof(cnmt_ext_header));
// Common values
cnmt_ctx->cnmt_header.type = 0x80; // Application
cnmt_ctx->cnmt_header.extended_header_size = 0x10;
cnmt_ctx->cnmt_header.content_entry_count = 0x2;
cnmt_ext_header.patch_title_id = cnmt_ctx->cnmt_header.title_id + 0x800;
// Set content record types
cnmt_ctx->cnmt_content_records[0].type = 0x1; // Program
cnmt_ctx->cnmt_content_records[1].type = 0x3; // Control
printf("Writing metadata header\n");
FILE *cnmt_file;
cnmt_file = os_fopen(cnmt_filepath->os_path, OS_MODE_WRITE);
if (cnmt_file != NULL)
{
fwrite(&cnmt_ctx->cnmt_header, 1, sizeof(cnmt_header_t), cnmt_file);
fwrite(&cnmt_ext_header, 1, sizeof(cnmt_extended_application_header_t), cnmt_file);
}
else
{
fprintf(stderr, "Failed to create %s!\n", cnmt_filepath->char_path);
exit(EXIT_FAILURE);
}
// Write content records
uint8_t digest[0x20] = {0}; // Unknown value
printf("Writing content records\n");
fwrite(&cnmt_ctx->cnmt_content_records[0], sizeof(cnmt_content_record_t), 1, cnmt_file);
fwrite(&cnmt_ctx->cnmt_content_records[1], sizeof(cnmt_content_record_t), 1, cnmt_file);
fwrite(digest, 1, 0x20, cnmt_file);
fclose(cnmt_file);
}