forked from WerWolv/ImHex-Patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchromium_pak.hexpat
More file actions
81 lines (64 loc) · 1.94 KB
/
chromium_pak.hexpat
File metadata and controls
81 lines (64 loc) · 1.94 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#pragma author East_Arctica
#pragma description Chromium Pak File
import std.core;
import std.io;
struct IndexEntry {
u16 id;
u32 offset;
};
struct AliasEntry {
u16 id;
u16 index;
};
struct ResourceView {
u32 i = std::core::array_index();
u16 id = parent.entries[i].id;
u32 start = parent.entries[i].offset;
u32 end = parent.entries[i + 1].offset;
u32 length = (end >= start) ? (end - start) : 0;
u8 data[length] @ start;
// pak_util.py implies that this may also be gzip with a header of 0x1f 0x8b
bool is_brotli = (length > 8 && data[0] == 0x1e && data[1] == 0x9b);
if (is_brotli) {
u8 magic[2] @ start;
u48 decompressed_size @ start + 2;
// TODO: If brotli decompression is added to ImHex, add it here.
}
};
struct AliasResourceView {
u32 i = std::core::array_index();
u16 id = parent.aliases[i].id;
u16 idx = parent.aliases[i].index;
bool valid = (idx < parent.resource_count);
u32 start = valid ? parent.entries[idx].offset : 0;
u32 end = valid ? parent.entries[idx + 1].offset : 0;
u32 length = (valid && end >= start) ? (end - start) : 0;
u8 data[length] @ start;
};
enum PakEncoding : u8 {
binary = 0,
utf8 = 1,
utf16 = 2
};
struct Pak {
u32 version;
if (version == 4) {
u32 resource_count;
PakEncoding encoding;
IndexEntry entries[resource_count + 1];
ResourceView resources[resource_count];
} else if (version == 5) {
PakEncoding encoding;
padding[3];
u16 resource_count;
u16 alias_count;
IndexEntry entries[resource_count + 1];
AliasEntry aliases[alias_count];
ResourceView resources[resource_count];
AliasResourceView alias_resources[alias_count];
} else {
std::error("Unsupported pak version");
}
};
// Some pack files are stored gzipped and need to be gunzipped first
Pak pak @ 0x00;