forked from dropbox/onenote-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
one_note_ptr.cpp
1438 lines (1400 loc) · 44.8 KB
/
one_note_ptr.cpp
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdlib.h>
#include <stdio.h>
#include "one_note.hpp"
#include "enums.hpp"
#include "properties.hpp"
int indent_level = 0;
bool quiet_parse = true;
std::string get_indent() {
std::string retval;
for (int i= 0; i < indent_level; ++i) {
retval+= " ";
}
return retval;
}
IncIndentLevel::IncIndentLevel(){
++indent_level;
}
IncIndentLevel::~IncIndentLevel(){
--indent_level;
}
DecIndentLevel::DecIndentLevel(){
--indent_level;
}
DecIndentLevel::~DecIndentLevel(){
++indent_level;
}
#define PROPERTY_ID_SWITCH(NAME, VAL) case VAL: return #NAME;
const char * propertyID_to_string(PropertyID pid) {
switch (pid.id) {
FOREACH_PROPERTY(PROPERTY_ID_SWITCH)
default:
return "Unknown Property ID";
}
}
std::string PropertyID::toString() const{
const char * retval = "unknown";
const char * unk = retval;
FOREACH_PROPERTY(PROPERTYSTRING)
char data[256];
if (retval == unk) {
sprintf(data, "id: 0x%x type 0x%x -- bit %d", id, (int)type, (int)inline_bool);
} else {
sprintf(data, "id: %s type 0x%x -- bit %d", retval, (int)type, (int)inline_bool);
}
return data;
}
std::string JCID::toString()const {
JCID nil;
if (memcmp(this, &nil, sizeof(nil)) == 0) {
return "null";
}
std::string retval;
switch(index) {
FOR_EACH_JCID(SWITCH_RETVAL_APPEND)
default:
retval += "unknown";
}
if (is_file_data) retval += " file_data";
if (is_property_set) retval += " property_set";
if (is_read_only) retval += " read_only";
return retval;
}
static const char * fnd_name(uint8_t fnd) {
using namespace CanRevise;
switch (fnd) {
case ObjectSpaceManifestRootFND: return "ObjectSpaceManifestRootFND";
case ObjectSpaceManifestListReferenceFND: return "ObjectSpaceManifestListReferenceFND";
case ObjectSpaceManifestListStartFND: return "ObjectSpaceManifestListStartFND";
case RevisionManifestListReferenceFND: return "RevisionManifestListReferenceFND";
case RevisionManifestListStartFND: return "RevisionManifestListStartFND";
case RevisionManifestStart4FND: return "RevisionManifestStart4FND";
case RevisionManifestEndFND: return "RevisionManifestEndFND";
case RevisionManifestStart6FND: return "RevisionManifestStart6FND";
case RevisionManifestStart7FND: return "RevisionManifestStart7FND";
case GlobalIdTableStartFNDX: return "GlobalIdTableStartFNDX";
case GlobalIdTableStart2FND: return "GlobalIdTableStart2FND";
case GlobalIdTableEntryFNDX: return "GlobalIdTableEntryFNDX";
case GlobalIdTableEntry2FNDX: return "GlobalIdTableEntry2FNDX";
case GlobalIdTableEntry3FNDX: return "GlobalIdTableEntry3FNDX";
case GlobalIdTableEndFNDX: return "GlobalIdTableEndFNDX";
case ObjectDeclarationWithRefCountFNDX: return "ObjectDeclarationWithRefCountFNDX";
case ObjectDeclarationWithRefCount2FNDX: return "ObjectDeclarationWithRefCount2FNDX";
case ObjectRevisionWithRefCountFNDX: return "ObjectRevisionWithRefCountFNDX";
case ObjectRevisionWithRefCount2FNDX : return "ObjectRevisionWithRefCount2FNDX";
case ObjectDeclaration2RefCountFND: return "ObjectDeclaration2RefCountFND";
case ObjectDeclaration2LargeRefCountFND: return "ObjectDeclaration2LargeRefCountFND";
case ReadOnlyObjectDeclaration2RefCountFND: return "ReadOnlyObjectDeclaration2RefCountFND";
case ReadOnlyObjectDeclaration2LargeRefCountFND: return "ReadOnlyObjectDeclaration2LargeRefCountFND";
case ObjectDeclarationFileData3RefCountFND: return "ObjectDeclarationFileData3RefCountFND";
case ObjectDeclarationFileData3LargeRefCountFND: return "ObjectDeclarationFileData3LargeRefCountFND";
case RootObjectReference2FNDX: return "RootObjectReference2FNDX";
case RootObjectReference3FND: return "RootObjectReference3FND";
case RevisionRoleDeclarationFND: return "RevisionRoleDeclarationFND";
case RevisionRoleAndContextDeclarationFND: return "RevisionRoleAndContextDeclarationFND";
case ObjectDataEncryptionKeyV2FNDX: return "ObjectDataEncryptionKeyV2FNDX";
case ObjectInfoDependencyOverridesFND: return "ObjectInfoDependencyOverridesFND";
case DataSignatureGroupDefinitionFND: return "DataSignatureGroupDefinitionFND";
case FileDataStoreListReferenceFND: return "FileDataStoreListReferenceFND";
case FileDataStoreObjectReferenceFND: return "FileDataStoreObjectReferenceFND";
case ObjectGroupListReferenceFND: return "ObjectGroupListReferenceFND";
case ObjectGroupStartFND: return "ObjectGroupStartFND";
case ObjectGroupEndFND: return "ObjectGroupEndFND";
case HashedChunkDescriptor2FND: return "HashedChunkDescriptor2FND";
case ChunkTerminatorFND: return "ChunkTerminatorFND";
default: return "UnknownFND";
}
}
const char * FileNode::fnd_name() const {
return ::fnd_name(id);
}
OneNotePtr::OneNotePtr(const OneNote*doc) {
document = doc;
offset = 0;
end = document->data.size();
}
error OneNotePtr::deserialize_bytes(uint8_t *data, uint64_t num_bytes) {
if (offset+num_bytes > end) {
return wrap(error::SEGV);
}
if (num_bytes != 0){
std::memcpy(data, &document->data[offset], num_bytes);
offset += num_bytes;
}
return Ok;
}
error OneNotePtr::deserialize_uint8_t(uint8_t *data) {
if (offset >= end) {
return wrap(error::SEGV);
}
*data = document->data[offset];
offset += 1;
return Ok;
}
error OneNotePtr::deserialize_uint16_t(uint16_t *data) {
if (offset + sizeof(*data) > end) {
return wrap(error::SEGV);
}
std::memcpy(data, &document->data[offset], sizeof(*data));
*data = htole16(*data);
offset += sizeof(*data);
return Ok;
}
error OneNotePtr::deserialize_uint32_t(uint32_t *data) {
if (offset + sizeof(*data) > end) {
return wrap(error::SEGV);
}
std::memcpy(data, &document->data[offset], sizeof(*data));
*data = htole32(*data);
offset += sizeof(*data);
return Ok;
}
error OneNotePtr::deserialize_uint64_t(uint64_t *data) {
if (offset + sizeof(*data) > end) {
return wrap(error::SEGV);
}
std::memcpy(data, &document->data[offset], sizeof(*data));
*data = htole64(*data);
offset += sizeof(*data);
return Ok;
}
error OneNotePtr::deserialize_GUID(GUID *data) {
return deserialize_bytes(data->guid, 16);
}
error OneNotePtr::deserialize_ExtendedGUID(ExtendedGUID *data) {
error errorA = deserialize_GUID(&data->guid);
error errorB = deserialize_uint32_t(&data->n);
if (errorA == Ok) {
return errorB;
}
return errorA;
}
error OneNotePtr::deserialize_CompactID(CompactID *data) {
error errorA = deserialize_uint8_t(&data->n);
error errorB = deserialize_bytes(&data->guidIndex.val[0], 3);
if (errorA != Ok) {
return errorA;
}
if (errorB != Ok) {
return errorB;
}
data->guid = ExtendedGUID::nil();
data->guid.n = data->n;
uint32_t index = data->guidIndex.value();
auto &global_id = document->revision_map[document->current_revision].global_id;
std::map<uint32_t, GUID>::iterator where = global_id.find(index);
if (where != global_id.end()) {
data->guid.guid = where->second;
} else {
printf("%sFailed Mapping %d/0x%x -> ????\n", get_indent().c_str(),
data->guidIndex.value(), data->n);
return wrap(error::COMPACT_ID_MISSING);
}
// printf("%sMapping %d/0x%x -> %s\n", get_indent().c_str(),
// data->guidIndex.value(), data->n, data->guid.toString().c_str());
return Ok;
}
error OneNotePtr::deserialize_FileChunkReference32(FileChunkReference32 *data) {
uint32_t stp;
error errorA = deserialize_uint32_t(&stp);
uint32_t cb;
error errorB = deserialize_uint32_t(&cb);
data->stp = stp;
data->cb = cb;
if (errorA == Ok) {
return errorB;
}
return errorA;
}
error OneNotePtr::deserialize_FileChunkReference64(FileChunkReference64 *data) {
error errorA = deserialize_uint64_t(&data->stp);
error errorB = deserialize_uint64_t(&data->cb);
if (errorA == Ok) {
return errorB;
}
return errorA;
}
error OneNotePtr::deserialize_FileChunkReference64x32(FileChunkReference64x32 *data) {
error errorA = deserialize_uint64_t(&data->stp);
uint32_t cb;
error errorB = deserialize_uint32_t(&cb);
data->cb = cb;
if (errorA == Ok) {
return errorB;
}
return errorA;
}
error OneNotePtr::deserialize_ObjectDeclarationWithRefCountBody(ObjectDeclarationWithRefCountBody *data) {
error errorA = deserialize_CompactID(&data->oid);
uint32_t jci_odcs_etc = 0;
error errorB = deserialize_uint32_t(&jci_odcs_etc);
uint16_t reserved = 0;
error errorC = deserialize_uint16_t(&reserved);
if (errorA != Ok) {
return errorA;
}
if (errorB != Ok) {
return errorB;
}
if (errorC != Ok) {
return errorC;
}
error err = data->jcid.read_uint10_t((jci_odcs_etc & 0x3ff));
if (err != Ok) {
return err;
}
uint8_t must_be_zero = (jci_odcs_etc >> 10) & 0xf;
uint8_t must_be_zeroA = ((jci_odcs_etc >> 14) &0x3);
data->fHasOidReferences = ((jci_odcs_etc >> 16) &0x1) ? true : false;
data->hasOsidReferences = ((jci_odcs_etc >> 17) &0x1) ? true : false;
if (jci_odcs_etc >> 18) {
return wrap(error::RESERVED_NONZERO);
}
if (reserved != 0 || must_be_zeroA != 0 || must_be_zero != 0) {
return wrap(error::RESERVED_NONZERO);
}
return Ok;
}
error OneNotePtr::deserialize_ObjectDeclaration2Body(ObjectDeclarationWithRefCountBody *data) {
error errorA = deserialize_CompactID(&data->oid);
uint32_t jcid = 0;
error errorB = deserialize_uint32_t(&jcid);
error err = data->jcid.read_uint32_t(jcid);
if (err != Ok) {
return err;
}
uint8_t has_refs = 0;
error errorC = deserialize_uint8_t(&has_refs);
if (errorA != Ok) {
return errorA;
}
if (errorB != Ok) {
return errorB;
}
if (errorC != Ok) {
return errorC;
}
data->fHasOidReferences = (has_refs&0x1) ? true : false;
data->hasOsidReferences = (has_refs&0x2) ? true : false;
return Ok;
}
error OneNotePtr::deserialize_PropertyID(PropertyID *data) {
uint32_t pid = 0;
error err = deserialize_uint32_t(&pid);
if (err != Ok) {
return err;
}
data->id = (pid & 0x3ffffff);
data->type = pid >> 26 & 0x1f;
if (data->type == 0x2) {
data->inline_bool = ((pid >> 31) & 0x1) ? true : false; // set the bool value from header
} else {
if ((pid >> 31) & 0x1) {
return wrap(error::RESERVED_NONZERO);
}
}
return Ok;
}
struct ObjectStreamCounters {
size_t oids_count;
size_t osids_count;
size_t context_ids_count;
ObjectStreamCounters() {
oids_count = 0;
osids_count = 0;
context_ids_count = 0;
}
};
const char * get_property_id_name(uint64_t id) {
const char * retval = "unknown";
FOREACH_PROPERTY(PROPERTYSTRING);
return retval;
}
error OneNotePtr::deserialize_PropertyValueFromPropertyID(PropertyID propertyID,
const ObjectSpaceObjectPropSet &streams,
ObjectStreamCounters *counters,
PropertyValue *data) {
data->propertyID = propertyID;
uint8_t val8=0;
uint16_t val16=0;
uint32_t val32=0;
uint64_t val64=0;
error err = Ok;
if (!quiet_parse) {
uint64_t id = propertyID.id;
const char *retval = get_property_id_name(id);
printf("\n%s<%s", get_indent().c_str(), retval);
}
IncIndentLevel inc;
switch(propertyID.type) {
case 0x1:
if (!quiet_parse){printf(" [] ");}
return Ok;
case 0x2:
if (!quiet_parse){
printf(" PropertyID bool(%d)", (int)propertyID.inline_bool);
}
data->scalar = propertyID.inline_bool ? 1 : 0;
return Ok;
case 0x3:
err = deserialize_uint8_t(&val8);
data->scalar = val8;
if (!quiet_parse) {
printf(" PropertyID byte(%ld)", data->scalar);
}
break;
case 0x4:
err = deserialize_uint16_t(&val16);
data->scalar = val16;
if (!quiet_parse) {
printf(" uint16 PropertyID short(%ld)", data->scalar);
}
break;
case 0x5:
err = deserialize_uint32_t(&val32);
data->scalar = val32;
if (!quiet_parse) {
printf(" PropertyID int(%ld)", data->scalar);
}
break;
case 0x6:
err = deserialize_uint64_t(&val64);
data->scalar = val64;
if (!quiet_parse) {
printf(" PropertyID long(%ld)", data->scalar);
}
break;
case 0x7:
err = deserialize_uint32_t(&val32);
if (err != Ok) {
return err;
}
if (!quiet_parse) {
printf(" raw data: (%d)[", val32);
}
{
data->rawData.stp = offset;
data->rawData.cb = 0;
if (offset + val32 > end) {
data->rawData.cb = end - offset;
offset = end;
return wrap(error::SEGV);
}
data->rawData.cb = val32;
offset += val32;
{
OneNotePtr content(*this);
error err = content.reposition(data->rawData);
if (err != Ok) {
return err;
}
if (!quiet_parse) {
content.dump_hex();
}
}
}
if (!quiet_parse) {
printf("]");
}
break;
case 0x9:
case 0xb:
case 0xd:
err = deserialize_uint32_t(&val32);
if (err != Ok) {
return err;
}
// fallthrough
case 0x8:
case 0xa:
case 0xc:
if (propertyID.type == 0x8 || propertyID.type == 0xa || propertyID.type == 0xc) {
val32 = 1;
}
{
const std::vector<CompactID> *stream = &streams.contextIDs.data;
const char * xtype = "contextID";
size_t *s_count = &counters->context_ids_count;
if (propertyID.type == 0x8 || propertyID.type == 0x9) {
stream = &streams.oids.data;
s_count = &counters->oids_count;
xtype = "OIDs";
}
if (propertyID.type == 0xa || propertyID.type == 0xb) {
stream = &streams.osids.data;
s_count = &counters->osids_count;
xtype = "OSIDS";
}
for (uint32_t i = 0; i < val32;++i) {
uint32_t index = (*s_count)++;
if (index < stream->size()) {
data->compactIDs.push_back((*stream)[index]);
if (!quiet_parse) {
printf(" %s[%s]",
xtype,
data->compactIDs.back().toString().c_str());
}
} else {
return wrap(error::SEGV);
}
}
}
break;
case 0x10:
err = deserialize_uint32_t(&val32);
if (err != Ok) {
return err;
}
{
PropertyID prop_id;
err = deserialize_PropertyID(&prop_id);
if (err != Ok) {
return err;
}
if (!quiet_parse) {
printf(" UnifiedSubPropertySet %d %s", val32, prop_id.toString().c_str());
}
data->propertySet.rgPridsData.resize(val32);
for (uint32_t i = 0;i < val32; ++i) {
err = deserialize_PropertyValueFromPropertyID(prop_id,
streams,
counters,
&data->propertySet.rgPridsData[i]);
if (err != Ok) {
data->propertySet.rgPridsData.resize(i);
return err;
}
}
}
break;
case 0x11:
if (!quiet_parse) {
printf(" SubPropertySet");
}
err = deserialize_PropertySet(streams, counters, &data->propertySet);
break;
default:
return wrap(error::INVALID_CONSTANT);
}
if (!quiet_parse) {
printf(">");
}
return err;
}
error OneNotePtr::deserialize_PropertySet(const ObjectSpaceObjectPropSet &streams,
ObjectStreamCounters *counters,
PropertySet *data) {
uint16_t count = 0;
error err = deserialize_uint16_t(&count);
if (err != Ok) {
return err;
}
data->rgPridsData.resize(count);
for (uint16_t i = 0; i < count; ++i) {
err = deserialize_PropertyID(&data->rgPridsData[i].propertyID);
if (err != Ok) {
return err;
}
if (!quiet_parse) {
printf("%sProperty %s\n", get_indent().c_str(), data->rgPridsData[i].propertyID.toString().c_str());
}
}
if (!quiet_parse) {
printf("%s%d elements in property set:", get_indent().c_str(), count);
}
for (uint16_t i = 0; i < count; ++i) {
err = deserialize_PropertyValueFromPropertyID(data->rgPridsData[i].propertyID,
streams,
counters,
&data->rgPridsData[i]);
}
if (!quiet_parse) {
printf("\n");
}
return Ok;
}
error OneNotePtr::postprocess_object_declaration_contents(FileNode *data,
const FileNodePtr& curPtr) {
data->gosid = data->sub_type.ObjectDeclarationWithRefCount.body.oid.guid;
document->guid_to_object[data->gosid] = curPtr;
if (data->sub_type.ObjectDeclarationWithRefCount.body.jcid.is_property_set) {
OneNotePtr objectSpacePropSetPtr(*this);
error err = objectSpacePropSetPtr.reposition(data->ref);
if (err != Ok) {
return err;
}
err = objectSpacePropSetPtr.deserialize_ObjectSpaceObjectPropSet(&data->sub_type.ObjectDeclarationWithRefCount.ObjectRef);
if (err != Ok) {
return err;
}
ObjectStreamCounters stream_counters;
err = objectSpacePropSetPtr.deserialize_PropertySet(data->sub_type.ObjectDeclarationWithRefCount.ObjectRef,
&stream_counters,
&data->property_set);
if (err != Ok) {
return err;
}
} else {
if (!data->sub_type.ObjectDeclarationWithRefCount.body.jcid.is_file_data) {
return wrap(error::INVALID_CONSTANT);
}
// this is FileData
data->is_file_data = true;
OneNotePtr content(*this);
error err = content.reposition(data->ref);
if (err != Ok) {
return err;
}
if (!quiet_parse) {
printf("%sRaw:", get_indent().c_str());
content.dump_hex();
printf("\n");
}
}
return Ok;
}
error OneNotePtr::deserialize_ObjectInfoDependencyOverrideData(ObjectInfoDependencyOverrideData *data) {
uint32_t num_8bit_overrides = 0;
uint32_t num_32bit_overrides = 0;
uint32_t crc = 0;
error errorA = deserialize_uint32_t(&num_8bit_overrides);
error errorB = deserialize_uint32_t(&num_32bit_overrides);
error errorC = deserialize_uint32_t(&crc);
if (errorA != Ok) {
return errorA;
}
if (errorB != Ok) {
return errorB;
}
if (errorC != Ok) {
return errorC;
}
for (uint32_t i = 0; i < num_8bit_overrides; ++i) {
uint8_t local = 0;
errorA = deserialize_uint8_t(&local);
if (errorA != Ok) {
return errorA;
}
data->overrides1.push_back(local);
}
for (uint32_t i = 0; i < num_32bit_overrides; ++i) {
uint32_t local = 0;
errorA = deserialize_uint32_t(&local);
if (errorA != Ok) {
return errorA;
}
data->overrides2.push_back(local);
}
return Ok;
}
error OneNotePtr::deserialize_FileNodeListHeader(FileNodeListHeader *data) {
error errorA = deserialize_uint64_t(&data->uintMagic);
error errorB = deserialize_uint32_t(&data->FileNodeListId);
error errorC = deserialize_uint32_t(&data->nFragmentSequence);
if (errorA == Ok) {
if (errorB == Ok) {
return errorC;
}
return errorB;
}
return errorA;
}
error OneNotePtr::deserialize_FileNode(FileNode *data,
FileNodePtr *curPath) {
const char * id_desc = "unknown";
data->is_file_data = false;
using namespace CanRevise;
OneNotePtr backup(*this);
uint32_t file_node_header;
data->gosid = ExtendedGUID::nil();
error err = deserialize_uint32_t(&file_node_header);
if (err != Ok) {
return err;
}
data->id = file_node_header & 0x3ff;
if (data->id == 0) {
return Ok;
}
if (!quiet_parse) {
printf("%sStart Node %s (%d)\n", get_indent().c_str(), fnd_name(data->id), (int)data->id);
}
IncIndentLevel inc;
data->size = (file_node_header >> 10) & 0x1fff;
if (this->end < backup.offset + data->size) {
// this node claims to have more space than the underlying chunk
return wrap(error::SEGV);
}
// reset the size to only be in scope of this FileNode
this->end = backup.offset + data->size;
uint8_t stp_format = (file_node_header >> 23) & 0x3;
uint8_t cb_format = (file_node_header >> 25) & 0x3;
data->base_type = (file_node_header >> 27) & 0xf;
uint8_t reserved = (file_node_header >> 31);
data->ref = FileChunkReference64::nil();
if (data->base_type == 1 || data->base_type == 2) {
deserialize_VarFileChunkReference(&data->ref, stp_format, cb_format);
} // otherwise ignore the data ref, since we're a type 0
if (data->base_type == 1 && !(data->ref == FileChunkReference64::nil())) {
OneNotePtr content(*this);
err = content.reposition(data->ref);
if (err != Ok) {
return err;
}
}
if (data->id == ObjectGroupStartFND) {
id_desc = "oid(group)";
err = deserialize_ExtendedGUID(&data->gosid);
if (err != Ok) {
return err;
}
//printf("%sgosid %s\n", get_indent().c_str(), data->gosid.toString().c_str());
} else if (data->id == ObjectGroupEndFND) {
// no data
} else if (data->id == ObjectSpaceManifestRootFND
|| data->id == ObjectSpaceManifestListStartFND) {
if (data->id == ObjectSpaceManifestRootFND) {
id_desc = "gosidRoot";
}else {
id_desc = "gosid";
}
err = deserialize_ExtendedGUID(&data->gosid);
if (err != Ok) {
return err;
}
//printf("%sgosid %s\n", get_indent().c_str(), data->gosid.toString().c_str());
} else if (data->id == ObjectSpaceManifestListReferenceFND) {
err = deserialize_ExtendedGUID(&data->gosid);
id_desc = "gosid";
if (err != Ok) {
return err;
}
//printf("%sgosid %s\n", get_indent().c_str(),data->gosid.toString().c_str());
//children parsed in generic base_type 2 parser
}else if (data->id == RevisionManifestListStartFND) {
err = deserialize_ExtendedGUID(&data->gosid);
id_desc = "gosid";
if (err != Ok) {
return err;
}
FileNodePtr parentPath(*curPath);
parentPath.offsets.pop_back();
document->registerRevisionManifestList(data->gosid, parentPath);
//printf("%sgosid %s\n", get_indent().c_str(),data->gosid.toString().c_str());
err = deserialize_uint32_t(&data->sub_type.
RevisionManifestListStart.nInstanceIgnored);
if (err != Ok) {
return err;
}
} else if (data->id == RevisionManifestStart4FND) {
err = deserialize_ExtendedGUID(&data->gosid); // the rid
id_desc = "rid";
//printf("%sgosid %s\n", get_indent().c_str(), data->gosid.toString().c_str());
if (err != Ok) {
return err;
}
err = deserialize_ExtendedGUID(&data->sub_type.RevisionManifest.ridDependent); // the rid
if (err != Ok) {
return err;
}
if (!quiet_parse) {
printf("%sdependent gosid %s\n", get_indent().c_str(), data->sub_type.RevisionManifest.ridDependent.toString().c_str());
}
err = deserialize_uint64_t(&data->sub_type.RevisionManifest.timeCreation);
if (err != Ok) {
return err;
}
err = deserialize_uint32_t(&data->sub_type.RevisionManifest.revisionRole);
if (err != Ok) {
return err;
}
err = deserialize_uint16_t(&data->sub_type.RevisionManifest.odcsDefault);
if (err != Ok) {
return err;
}
data->gctxid = ExtendedGUID::nil();
document->registerRevisionManifest(*data);
} else if (data->id == RevisionManifestStart6FND
|| data->id == RevisionManifestStart7FND) {
err = deserialize_ExtendedGUID(&data->gosid); // the rid
id_desc = "rid";
//printf("%sgosid %s\n", get_indent().c_str(), data->gosid.toString().c_str());
if (err != Ok) {
return err;
}
err = deserialize_ExtendedGUID(&data->sub_type.RevisionManifest.ridDependent); // the rid
if (err != Ok) {
return err;
}
if (!quiet_parse) {
printf("%sdependent gosid %s\n", get_indent().c_str(), data->sub_type.RevisionManifest.ridDependent.toString().c_str());
}
err = deserialize_uint32_t(&data->sub_type.RevisionManifest.revisionRole);
if (err != Ok) {
return err;
}
err = deserialize_uint16_t(&data->sub_type.RevisionManifest.odcsDefault);
if (err != Ok) {
return err;
}
data->gctxid = ExtendedGUID::nil();
if (data->id == RevisionManifestStart7FND) {
err = deserialize_ExtendedGUID(&data->gctxid); // the rid
if (err != Ok) {
return err;
}
}
document->registerAdditionalRevisionRole(data->gosid,
data->sub_type.RevisionManifest.revisionRole,
data->gctxid);
document->registerRevisionManifest(*data);
} else if (data->id == GlobalIdTableStartFNDX) {
err = deserialize_uint8_t(&data->sub_type.GlobalIdTableStartFNDX.reserved);
if (err != Ok) {
return err;
}
}else if (data->id == GlobalIdTableEntryFNDX) {
err = deserialize_uint32_t(&data->sub_type.GlobalIdTableEntryFNDX.index);
if (err != Ok) {
return err;
}
err = deserialize_GUID(&data->sub_type.GlobalIdTableEntryFNDX.guid);
if (err != Ok) {
return err;
}
document->revision_map[document->current_revision].global_id[data->sub_type.GlobalIdTableEntryFNDX.index] =
data->sub_type.GlobalIdTableEntryFNDX.guid;
}else if (data->id == GlobalIdTableEntry2FNDX) {
err = deserialize_uint32_t(&data->sub_type.GlobalIdTableEntry2FNDX.indexMapFrom);
if (err != Ok) {
return err;
}
err = deserialize_uint32_t(&data->sub_type.GlobalIdTableEntry2FNDX.indexMapTo);
if (err != Ok) {
return err;
}
ExtendedGUID dependent_revision =
document->revision_map[document->current_revision].dependent;
auto where = document->revision_map[dependent_revision].global_id.find(data->sub_type.GlobalIdTableEntry2FNDX.indexMapFrom);
if (where == document->revision_map[dependent_revision].global_id.end()) {
return wrap(error::COMPACT_ID_MISSING);
}
document->revision_map[document->current_revision].global_id[data->sub_type.GlobalIdTableEntry2FNDX.indexMapTo] = where->second;
}else if (data->id == GlobalIdTableEntry3FNDX) {
err = deserialize_uint32_t(&data->sub_type.GlobalIdTableEntry3FNDX.indexCopyFromStart);
if (err != Ok) {
return err;
}
err = deserialize_uint32_t(&data->sub_type.GlobalIdTableEntry3FNDX.entriesToCopy);
if (err != Ok) {
return err;
}
err = deserialize_uint32_t(&data->sub_type.GlobalIdTableEntry3FNDX.indexCopyToStart);
if (err != Ok) {
return err;
}
ExtendedGUID dependent_revision =
document->revision_map[document->current_revision].dependent;
for (uint32_t i = 0;i < data->sub_type.GlobalIdTableEntry3FNDX.entriesToCopy;
++i) {
auto &global_id = document->revision_map[dependent_revision].global_id;
auto where = global_id.find(data->sub_type.GlobalIdTableEntry3FNDX.indexCopyFromStart + i);
if (where == global_id.end()) {
return wrap(error::COMPACT_ID_MISSING);
}
document->revision_map[document->current_revision].global_id[data->sub_type.GlobalIdTableEntry3FNDX.indexCopyToStart + i] = where->second;
}
} else if (data->id == ObjectRevisionWithRefCountFNDX || data->id == ObjectRevisionWithRefCount2FNDX ) {
err = deserialize_CompactID(&data->sub_type.ObjectRevisionWithRefCountFNDX.oid); // the oid
if (err != Ok) {
return err;
}
if (data->id == ObjectRevisionWithRefCountFNDX) {
uint8_t ref = 0;
err = deserialize_uint8_t(&ref);
if (err != Ok) {
return err;
}
data->sub_type.ObjectRevisionWithRefCountFNDX.hasOidReferences = ref & 1;
data->sub_type.ObjectRevisionWithRefCountFNDX.hasOsidReferences = ref & 2;
data->sub_type.ObjectRevisionWithRefCountFNDX.cRef = (ref >> 2);
} else {
uint32_t ref = 0;
err = deserialize_uint32_t(&ref);
if (err != Ok) {
return err;
}
data->sub_type.ObjectRevisionWithRefCountFNDX.hasOidReferences = ref & 1;
data->sub_type.ObjectRevisionWithRefCountFNDX.hasOsidReferences = ref & 2;
if ((ref >> 2) != 0) {
return wrap(error::RESERVED_NONZERO);
}
err = deserialize_uint32_t(&data->sub_type.ObjectRevisionWithRefCountFNDX.cRef);
if (err != Ok) {
return err;
}
}
}else if (data->id == RootObjectReference2FNDX) {
err = deserialize_CompactID(&data->sub_type.RootObjectReference.oidRoot);
if (err != Ok) {
return err;
}
id_desc = "oidRoot";
data->gosid = data->sub_type.RootObjectReference.oidRoot.guid;
err = deserialize_uint32_t(&data->sub_type.RootObjectReference.RootObjectReferenceBase.RootRole);
if (err != Ok) {
return err;
}
if (!quiet_parse) {
printf("%sRoot role %d\n",get_indent().c_str(),
data->sub_type.RootObjectReference.RootObjectReferenceBase.RootRole);
}
}else if (data->id == RootObjectReference3FND) {
id_desc = "oidRoot";
err = deserialize_ExtendedGUID(&data->gosid);
if (err != Ok) {
return err;
}
err = deserialize_uint32_t(&data->sub_type.RootObjectReference.RootObjectReferenceBase.RootRole);
if (err != Ok) {
return err;
}
if (!quiet_parse) {
printf("%sRoot role %d\n",get_indent().c_str(), data->sub_type.RootObjectReference.RootObjectReferenceBase.RootRole);
}
}else if (data->id == RevisionRoleDeclarationFND ||
data->id == RevisionRoleAndContextDeclarationFND) {
err = deserialize_ExtendedGUID(&data->gosid);
if (err != Ok) {
return err;
}
err = deserialize_uint32_t(&data->sub_type.RevisionRoleDeclaration.RevisionRole);
if (err != Ok) {
return err;
}
if (data->id == RevisionRoleAndContextDeclarationFND) {
err = deserialize_ExtendedGUID(&data->gctxid);
if (err != Ok) {
return err;
}
}
document->registerAdditionalRevisionRole(data->gosid,
data->sub_type.RevisionRoleDeclaration.RevisionRole,
data->gctxid);
// FIXME: deal with ObjectDataEncryptionKey
} else if (data->id == ObjectInfoDependencyOverridesFND) {
OneNotePtr content(*this);
if (data->ref != FileChunkReference64::nil()) {
err = content.reposition(data->ref); // otherwise it's positioned right at this node
if (err != Ok) {
return err;
}
}
err = content.deserialize_ObjectInfoDependencyOverrideData(&data->sub_type.ObjectInfoDependencyOverrides.data);
if (err != Ok) {
return err;
}
} else if (data->id == FileDataStoreListReferenceFND) {
// already processed this
} else if (data->id == FileDataStoreObjectReferenceFND) {
OneNotePtr fileDataStorePtr(*this);
err = fileDataStorePtr.reposition(data->ref);
if (err != Ok) {
return err;
}
err = fileDataStorePtr.deserialize_FileDataStoreObject(&data->sub_type.FileDataStoreObjectReference.ref);
if (err != Ok) {
return err;
}
} else if (data->id == ObjectDeclarationWithRefCountFNDX ||
data->id == ObjectDeclarationWithRefCount2FNDX ||
data->id == ObjectDeclaration2RefCountFND ||
data->id == ObjectDeclaration2LargeRefCountFND ||
data->id == ReadOnlyObjectDeclaration2RefCountFND ||
data->id == ReadOnlyObjectDeclaration2LargeRefCountFND) {
data->sub_type.ObjectDeclarationWithRefCount.body.file_data_store_reference=false;
if (data->id == ObjectDeclarationWithRefCountFNDX ||
data->id == ObjectDeclarationWithRefCount2FNDX) {
err = deserialize_ObjectDeclarationWithRefCountBody(&data->sub_type.ObjectDeclarationWithRefCount.body);
} else { // one of the other 4 that use the ObjectDeclaration2Body
err = deserialize_ObjectDeclaration2Body(&data->sub_type.ObjectDeclarationWithRefCount.body);
}
if (err != Ok) {
return err;
}
if (data->id == ObjectDeclarationWithRefCountFNDX || data->id==ObjectDeclaration2RefCountFND || data->id == ReadOnlyObjectDeclaration2RefCountFND) {
uint8_t ref_cnt = 0;
err = deserialize_uint8_t(&ref_cnt);
data->sub_type.ObjectDeclarationWithRefCount.cRef = ref_cnt;
} else {
err = deserialize_uint32_t(&data->sub_type.ObjectDeclarationWithRefCount.cRef);
}
if (err != Ok) {
return err;
}
if (data->id == ReadOnlyObjectDeclaration2RefCountFND ||
data->id == ReadOnlyObjectDeclaration2LargeRefCountFND) {
err = deserialize_bytes(data->sub_type.ObjectDeclarationWithRefCount.read_only.md5, 16);
if (err != Ok) {
return err;
}
}
id_desc = "oid";
err = postprocess_object_declaration_contents(data, *curPath);
if (err != Ok) {
return err;
}
if (!quiet_parse) {
printf("%sRef Count JCID %s\n",get_indent().c_str(), data->sub_type.ObjectDeclarationWithRefCount.body.jcid.toString().c_str());
}
} else if (data->id == ObjectDeclarationFileData3RefCountFND ||
data->id == ObjectDeclarationFileData3LargeRefCountFND) {
err = deserialize_CompactID(&data->sub_type.ObjectDeclarationWithRefCount.body.oid);
if (err != Ok) {
return err;
}
uint32_t jcid;
err = deserialize_uint32_t(&jcid);
if (err != Ok) {
return err;
}
err = data->sub_type.ObjectDeclarationWithRefCount.body.jcid.read_uint32_t(jcid);
if (err != Ok) {
return err;
}
if (data->id == ObjectDeclarationFileData3RefCountFND) {
uint8_t ref_count;
err = deserialize_uint8_t(&ref_count);
data->sub_type.ObjectDeclarationWithRefCount.cRef = ref_count;
} else {
err = deserialize_uint32_t(&data->sub_type.ObjectDeclarationWithRefCount.cRef);
}
if (err != Ok) {
return err;
}
uint32_t cch = 0;
err = deserialize_uint32_t(&cch);
if (err != Ok) {