-
Notifications
You must be signed in to change notification settings - Fork 0
/
obsidian-file.hexpat
65 lines (56 loc) · 1.85 KB
/
obsidian-file.hexpat
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
#pragma description Obsidian Project File
#pragma magic [0x57 0x50 0x52 0x4A] @ 0
#pragma endian big
import hex.dec;
enum SectionFormats: u8 {
JSON = 0x00,
JSONDeflate = 0x01,
};
struct Header {
char magic[4];
u16 version;
char type[10];
SectionFormats metadataFormat;
u32 metadataOffset;
u32 metadataLength;
SectionFormats projectFormat;
u32 projectOffset;
u32 projectLength;
SectionFormats blobIndexFormat;
u32 blobIndexOffset;
u32 blobIndexLength;
u32 blobsOffset;
u32 blobsLength;
};
struct MetadataSection {
u8 metadata[parent.header.metadataLength] [[inline]];
if (parent.header.metadataFormat == SectionFormats::JSONDeflate) {
std::mem::Section decompressed = std::mem::create_section("MetadataSection (decompressed)");
hex::dec::zlib_decompress(metadata, decompressed, -15);
}
};
struct ProjectSection {
u8 project[parent.header.projectLength] [[inline]];
if (parent.header.projectFormat == SectionFormats::JSONDeflate) {
std::mem::Section decompressed = std::mem::create_section("ProjectSection (decompressed)");
hex::dec::zlib_decompress(project, decompressed, -15);
}
};
struct BlobIndexSection {
u8 blobIndex[parent.header.blobIndexLength] [[inline]];
if (parent.header.blobIndexFormat == SectionFormats::JSONDeflate) {
std::mem::Section decompressed = std::mem::create_section("BlobIndexSection (decompressed)");
hex::dec::zlib_decompress(blobIndex, decompressed, -15);
}
};
struct Blobs {
u8 blobs[parent.header.blobsLength] [[inline]];
};
struct ObsidianProjectFile {
Header header;
MetadataSection metadata @ header.metadataOffset;
ProjectSection project @ header.projectOffset;
BlobIndexSection blobIndex @ header.blobIndexOffset;
Blobs blobs @ header.blobsOffset;
};
ObsidianProjectFile file @ 0;