forked from tiliarou/4NXCI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hfs0.h
59 lines (46 loc) · 1.51 KB
/
hfs0.h
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
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef NXCI_hfs0_H
#define NXCI_hfs0_H
#include "types.h"
#include "utils.h"
#include "settings.h"
#define MAGIC_HFS0 0x30534648
typedef struct {
uint32_t magic;
uint32_t num_files;
uint32_t string_table_size;
uint32_t reserved;
} hfs0_header_t;
typedef struct {
uint64_t offset;
uint64_t size;
uint32_t string_table_offset;
uint32_t hashed_size;
uint64_t reserved;
unsigned char hash[0x20];
} hfs0_file_entry_t;
typedef struct {
FILE *file;
uint64_t offset;
uint64_t size;
nxci_ctx_t *tool_ctx;
hfs0_header_t *header;
char *name;
} hfs0_ctx_t;
static inline hfs0_file_entry_t *hfs0_get_file_entry(hfs0_header_t *hdr, uint32_t i) {
if (i >= hdr->num_files) return NULL;
return (hfs0_file_entry_t *)((char *)(hdr) + sizeof(*hdr) + i * sizeof(hfs0_file_entry_t));
}
static inline char *hfs0_get_string_table(hfs0_header_t *hdr) {
return (char *)(hdr) + sizeof(*hdr) + hdr->num_files * sizeof(hfs0_file_entry_t);
}
static inline uint64_t hfs0_get_header_size(hfs0_header_t *hdr) {
return sizeof(*hdr) + hdr->num_files * sizeof(hfs0_file_entry_t) + hdr->string_table_size;
}
static inline char *hfs0_get_file_name(hfs0_header_t *hdr, uint32_t i) {
return hfs0_get_string_table(hdr) + hfs0_get_file_entry(hdr, i)->string_table_offset;
}
int process_extracted_nca(filepath_t *filepath,nxci_ctx_t *tool);
void hfs0_process(hfs0_ctx_t *ctx);
void hfs0_save(hfs0_ctx_t *ctx);
void hfs0_save_file(hfs0_ctx_t *ctx, uint32_t i, filepath_t *dirpath);
#endif