forked from dropbox/onenote-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enums.hpp
361 lines (345 loc) · 11.4 KB
/
enums.hpp
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
#ifndef _ENUMS_HPP_
#define _ENUMS_HPP_
#include <cstdint>
#include <string>
#include "one_note_ptr.hpp"
enum class PropertyIDtype {
ObjectID = 0x8,
ArrayOfObjectIDs = 0x9,
ObjectSpaceID = 0xa,
ArrayOfObjectSpaceIDs = 0xb,
ContextID = 0xc,
ArrayofContextIDs = 0xd,
};
const uint8_t ObjectSpaceManifestRootFND = 0x04;
const uint8_t ObjectSpaceManifestListReferenceFND = 0x08;
const uint8_t ObjectSpaceManifestListStartFND = 0x0c;
const uint8_t RevisionManifestListReferenceFND = 0x10;
const uint8_t RevisionManifestListStartFND = 0x14;
const uint8_t RevisionManifestStart4FND = 0x1b;
const uint8_t RevisionManifestEndFND = 0x1c;
const uint8_t RevisionManifestStart6FND = 0x1e;
const uint8_t RevisionManifestStart7FND = 0x1f;
const uint8_t GlobalIdTableStartFNDX = 0x21;
const uint8_t GlobalIdTableStart2FND = 0x22;
const uint8_t GlobalIdTableEntryFNDX = 0x24;
const uint8_t GlobalIdTableEntry2FNDX = 0x25;
const uint8_t GlobalIdTableEntry3FNDX = 0x26;
const uint8_t GlobalIdTableEndFNDX = 0x28;
namespace CanRevise {
const uint8_t ObjectDeclarationWithRefCountFNDX = 0x2d;
const uint8_t ObjectDeclarationWithRefCount2FNDX = 0x2e;
const uint8_t ObjectRevisionWithRefCountFNDX = 0x041;
const uint8_t ObjectRevisionWithRefCount2FNDX = 0x42;
const uint8_t ObjectDeclaration2RefCountFND = 0x0A4;
const uint8_t ObjectDeclaration2LargeRefCountFND = 0xA5;
const uint8_t ReadOnlyObjectDeclaration2RefCountFND = 0xc4;
const uint8_t ReadOnlyObjectDeclaration2LargeRefCountFND = 0xc5;
const uint8_t ObjectDeclarationFileData3RefCountFND = 0x72;
const uint8_t ObjectDeclarationFileData3LargeRefCountFND = 0x73;
}
const uint8_t RootObjectReference2FNDX = 0x59;
const uint8_t RootObjectReference3FND = 0x5a; // each root object must have a differe
const uint8_t RevisionRoleDeclarationFND = 0x5c;
const uint8_t RevisionRoleAndContextDeclarationFND = 0x5d;
const uint8_t ObjectDataEncryptionKeyV2FNDX = 0x7c;
const uint8_t ObjectInfoDependencyOverridesFND = 0x84;
const uint8_t DataSignatureGroupDefinitionFND = 0x8c;
const uint8_t FileDataStoreListReferenceFND = 0x90;
const uint8_t FileDataStoreObjectReferenceFND = 0x94;
const uint8_t ObjectGroupListReferenceFND = 0xb0;
const uint8_t ObjectGroupStartFND = 0xb4;
const uint8_t ObjectGroupEndFND = 0xb8;
const uint8_t HashedChunkDescriptor2FND = 0xc2;
const uint8_t ChunkTerminatorFND = 0xff;
struct uint24 {
uint8_t val[3];
uint8_t value() const {
uint32_t le = val[2];
le <<= 8;
le |= val[1];
le <<= 8;
le |= val[0];
return le;
}
};
struct CompactID {
uint8_t n;
uint24 guidIndex; //only occupies 24 bits
ExtendedGUID guid;
operator ExtendedGUID() const {
return guid;
}
std::string toString()const {
return guid.toString();
}
};
struct FileChunkReference64 {
uint64_t stp;
uint64_t cb;
static constexpr FileChunkReference64 nil() {return {
(uint64_t)-1, 0};}
bool operator ==(const FileChunkReference64&other)const {
return stp == other.stp && cb == other.cb;
}
bool operator !=(const FileChunkReference64&other)const {
return stp != other.stp || cb != other.cb;
}
};
/*
struct FileChunkReference64x32 {
uint64_t stp;
uint32_t cb;
static constexpr FileChunkReference64x32 nil() {return {
(uint64_t)-1, 0};}
};
*/
typedef FileChunkReference64 FileChunkReference32;
typedef FileChunkReference64 FileChunkReference64x32;
struct ObjectInfoDependencyOverrideData {
uint32_t c8bitOverrides;
uint32_t c32bitOverrides;
uint32_t crc;
std::vector<uint8_t> overrides1;
std::vector<uint32_t> overrides2;
};
struct FileNode;
struct FileNodeList {
std::vector<FileNode> children;
};
struct ObjectSpaceObjectStreamOfOIDsOSIDsOrContextIDs {
uint32_t count; // 24 bits
bool ExtendedStreamsPresent;
bool OsidsStreamNotPresent;
std::vector<CompactID> data;
};
struct PropertyID;
struct PropertyValue;
struct PropertySet {
std::vector<PropertyValue> rgPridsData;
void print(const OneNote*document)const;
};
struct ObjectSpaceObjectPropSet {
ObjectSpaceObjectStreamOfOIDsOSIDsOrContextIDs oids;
ObjectSpaceObjectStreamOfOIDsOSIDsOrContextIDs osids;
ObjectSpaceObjectStreamOfOIDsOSIDsOrContextIDs contextIDs;
PropertySet body;
void print(const OneNote*document)const;
};
struct PropertyValue {
PropertyID propertyID;
// union of one of these things based on the type of the corresponding PropertyID
uint64_t scalar; // holds a boolean value if type = 0x2, retrieved from header
// either ObjectID or ObjectSpaceID or ContextID (single value in array)
// either ArrayOfObjectIDs or ArrayOfObjectSpaceIDs or ArrayOfContextID
std::vector<CompactID> compactIDs;
PropertySet propertySet; // or used to house a single value
FileChunkReference64 rawData; // FourBytesOfLengthFollowedByData
void print(const OneNote*document) const;
};
struct FileDataStoreObject {
GUID header;
// uint64_t cbLength;implicit in the fileData FileChunkReference
uint32_t reserved0;
uint64_t reserved;
FileChunkReference64 fileData; //points to raw data
GUID footer; //MUST be {71FBA722-0F79-4A0B-BB13-899256426B24}.
};
struct JCID {
uint16_t index;
bool is_binary;
bool is_property_set;
bool is_graph_node;
bool is_file_data;
bool is_read_only;
JCID() {
memset(this, 0, sizeof(*this));
}
std::string toString()const;
error read_uint32_t(uint32_t full_index) {
index = full_index & 0xffff;
is_binary = ((full_index >> 16) & 1) == 1;
is_property_set = ((full_index >> 17) & 1) == 1;
is_graph_node = ((full_index >> 18) & 1) == 1;
is_file_data = ((full_index >> 19) & 1) == 1;
is_read_only = ((full_index >> 20) & 1) == 1;
if ((full_index >> 21) != 0) {
return wrap(error::RESERVED_NONZERO);
}
return Ok;
}
error read_uint10_t(uint16_t jci) {
memset(this, 0, sizeof(*this));
index = jci;
is_property_set = true;
return Ok;
}
};
struct ObjectDeclarationWithRefCountBody {
CompactID oid;
JCID jcid; // if this is a ObjectDeclarationWithRefCountBody, jci = 0x01
bool fHasOidReferences;
bool hasOsidReferences;
// the obj is a GUID in the file_data_store_reference
// for a ObjectDeclarationFileData3RefCountFND
bool file_data_store_reference;
};
struct FileNodeUnion {
struct {
uint32_t nInstanceIgnored;//ignored
}RevisionManifestListStart;
struct {
ExtendedGUID ridDependent;
uint64_t timeCreation; //ignored
uint32_t revisionRole;
uint16_t odcsDefault;// must be zero or 0x2 for RevisionManifestStart6
}RevisionManifest;
struct {
uint8_t reserved; // must be zero
} GlobalIdTableStartFNDX;
struct {
uint32_t index;
GUID guid;
}GlobalIdTableEntryFNDX;
struct {
uint32_t indexMapFrom;
uint32_t indexMapTo;
}GlobalIdTableEntry2FNDX;
struct {
uint32_t indexCopyFromStart;
uint32_t entriesToCopy;
uint32_t indexCopyToStart;
} GlobalIdTableEntry3FNDX;
struct {
ObjectSpaceObjectPropSet ref;
CompactID oid;
uint8_t hasOidReferences;
uint8_t hasOsidReferences;
uint32_t cRef;
} ObjectRevisionWithRefCountFNDX;
struct {
struct {
uint32_t RootRole;
} RootObjectReferenceBase;
CompactID oidRoot; // only if theis is a RootObjectReference2FNDX
} RootObjectReference;
struct {
uint32_t RevisionRole;
}RevisionRoleDeclaration;
struct {
// FIXME: populate this by parsing the FileNodeChunkReference?
ObjectInfoDependencyOverrideData data;
}ObjectInfoDependencyOverrides;
struct {
FileDataStoreObject ref;
} FileDataStoreObjectReference;
struct {
ObjectSpaceObjectPropSet ObjectRef;
ObjectDeclarationWithRefCountBody body;
uint32_t cRef;
struct {
uint8_t md5[16];
} read_only;
} ObjectDeclarationWithRefCount;
};
struct FileNode {
uint16_t id; //10 bits
uint16_t size; // 13 bits
//base_type 0, ignore stp&cb 1, reference to data 2) reference to FileNodeList
uint8_t base_type;
// for ObjectSpaceManifestRoot
// for ObjectSpaceManifestStart
// for ObjectSpaceManifestList
// for RevisionManifestListStart
// ObjectGroupStartFND
// ObjectGroupID for ObjectGroupListReferenceFND
// RID for RevisionManifestStart4FND
// DataSignatureGroup for RevisionManifestEndFND
ExtendedGUID gosid;
// only present for RevisionManfiest7FND and RevisionRoleAndContextDeclaration
ExtendedGUID gctxid;
GUID file_data_store_reference;
FileChunkReference64 ref;
PropertySet property_set;
bool is_file_data;
FileNodeList children; // for ObjectGroupListReference
const char *fnd_name() const;
void print(const OneNote*document)const;
bool has_gctxid() const {
return id == RevisionRoleAndContextDeclarationFND
|| id == RevisionManifestStart7FND;
}
ExtendedGUID get_gctxid() const {
return gctxid;
}
bool hasChildren()const {
return !children.children.empty();
}
const FileNodeList& Children()const {
return children;
}
bool hasData()const;
ObjectSpaceObjectPropSet data();
GUID fileDataStoreReference(); // for future reference of this object
bool isFile()const;
FileChunkReference64 file()const;
bool hasFileName()const;
std::string fileName()const;
GUID ifndf();
FileNodeUnion sub_type;
bool is_object_declaration() const;
JCID object_declaration_jcid() const;
};
#define FOREACH_HEADER_MEMBER(CB) \
CB(GUID, guidFileType) \
CB(GUID, guidFile) \
CB(GUID, guidLegacyFileVersion) \
CB(GUID, guidFileFormat) \
CB(uint32_t, ffvLastCode) \
CB(uint32_t, ffvNewestCode) \
CB(uint32_t, ffvOldestCode) \
CB(uint32_t, ffvOldestReader) \
CB(FileChunkReference32, fcrLegacyFreeChunkList) \
CB(FileChunkReference32, fcrLegacyTransactionLog) \
CB(uint32_t, cTransactionsInLog) \
CB(uint32_t, cbLegacyExpectedFileLength) \
CB(uint64_t, rgbPlaceholder) \
CB(FileChunkReference32, fcrLegacyFileNodeListRoot) \
CB(uint32_t, cbLegacyFreeSpaceInFreeChunkList) \
CB(uint8_t, ignoredZeroA) \
CB(uint8_t, ignoredZeroB) \
CB(uint8_t, ignoredZeroC) \
CB(uint8_t, ignoredZeroD) \
CB(GUID, guidAncestor) \
CB(uint32_t, crcName) \
CB(FileChunkReference64x32, fcrHashedChunkList) \
CB(FileChunkReference64x32, fcrTransactionLog) \
CB(FileChunkReference64x32, fcrFileNodeListRoot) \
CB(FileChunkReference64x32, fcrFreeChunkList) \
CB(uint64_t, cbExpectedFileLength) \
CB(uint64_t, cbFreeSpaceInFreeChunkList) \
CB(GUID, guidFileVersion) \
CB(uint64_t, nFileVersionGeneration) \
CB(GUID, guidDenyReadFileVersion) \
CB(uint32_t, grfDebugLogFlags) \
CB(FileChunkReference64x32, fcrDebugLogA) \
CB(FileChunkReference64x32, fcrDebugLogB) \
CB(uint32_t, buildInfoA) \
CB(uint32_t, buildInfoB) \
CB(uint32_t, buildInfoC) \
CB(uint32_t, buildInfoD)
#define MAKE_STRUCT(TYP, VAR) TYP VAR;
struct OneNotePtr;
struct FileNodeListHeader{
uint64_t uintMagic;
uint32_t FileNodeListId;
uint32_t nFragmentSequence;
};
struct Header {
// first FileNodeListFragment .. if nil, hash chunk does not list
FOREACH_HEADER_MEMBER(MAKE_STRUCT)
uint8_t reserved[728];
error deserialize(OneNotePtr* ptr);
};
#define DESERIALIZE(TYP, VAR) if ((err = ptr->deserialize_##TYP(&this->VAR)) != Ok) {return err;}
#endif