diff --git a/pyOneNote/FileNode.py b/pyOneNote/FileNode.py index a5f04d0..1ff3da5 100644 --- a/pyOneNote/FileNode.py +++ b/pyOneNote/FileNode.py @@ -2,6 +2,7 @@ import struct from datetime import datetime, timedelta import locale +import math DEBUG = False @@ -9,6 +10,7 @@ class FileNodeListHeader: def __init__(self, file): self.uintMagic, self.FileNodeListID, self.nFragmentSequence = struct.unpack('<8sII', file.read(16)) + assert self.uintMagic == b'\xc4\xf4\xf7\xf5\xb1zV\xa4' class FileNodeList: @@ -107,7 +109,7 @@ def __init__(self, file, document): self.document= document self.file_node_header = FileNodeHeader(file) if DEBUG: - print(str(file.tell()) + ' ' + self.file_node_header.file_node_type + ' ' + str(self.file_node_header.baseType)) + print(str(hex(file.tell())) + ' ' + self.file_node_header.file_node_type + ' ' + str(self.file_node_header.baseType)) self.children = [] FileNode.count += 1 if self.file_node_header.file_node_type == "ObjectGroupStartFND": @@ -178,7 +180,8 @@ def __init__(self, file, document): current_offset = file.tell() if self.file_node_header.baseType == 2: - self.children.append(FileNodeList(file, self.document, self.data.ref)) + if hasattr(self, 'data') and not (self.data.ref.stp == 0 and self.data.ref.cb == 0): + self.children.append(FileNodeList(file, self.document, self.data.ref)) file.seek(current_offset) @@ -245,7 +248,7 @@ def isFcrNil(self): return res def __repr__(self): - return 'FileChunkReference:(stp:{}, cb:{})'.format(self.stp, self.cb) + return 'FileNodeChunkReference:(stp:{}, cb:{})'.format(self.stp, self.cb) class FileChunkReference64x32(FileNodeChunkReference): @@ -383,7 +386,12 @@ def __init__(self, file, file_node_header): self.guidReference = uuid.UUID(bytes_le=self.guidReference) current_offset = file.tell() file.seek(self.ref.stp) - self.fileDataStoreObject = FileDataStoreObject(file, self.ref) + try: + self.fileDataStoreObject = FileDataStoreObject(file, self.ref) + except: # noqa + # print(f'Error for datastore at {hex(current_offset)} // {self.ref.stp}') + self.fileDataStoreObject = None + pass file.seek(current_offset) def __str__(self): @@ -638,7 +646,11 @@ def __init__(self, file, OIDs, OSIDs, ContextIDs, document): count, = struct.unpack('{", "").replace("}", "") guid = guid.lower() if not guid in self._files: - self._files[guid] = {"extension": "", "content": "", "identity": ""} + self._files[guid] = {"extension": "", "content": b"", "identity": ""} self._files[guid]["extension"] = node.data.Extension.StringData self._files[guid]["identity"] = str(node.data.oid) return self._files