def parse (self, i): i += 1 self.refID = globals.getSignedInt(self.tokens[i:i+2]) i += 2 self.nameID = globals.getSignedInt(self.tokens[i:i+2]) i += 2 return i
def parseCellAddress (bytes): if len(bytes) != 4: globals.error("Byte size is %d but expected 4 bytes for cell address.\n"%len(bytes)) raise InvalidCellAddress row = globals.getSignedInt(bytes[0:2]) col = globals.getSignedInt(bytes[2:4]) colRelative = ((col & 0x4000) != 0) rowRelative = ((col & 0x8000) != 0) col = (col & 0x00FF) obj = CellAddress(col, row, colRelative, rowRelative) return obj
def parse (self, i): try: i += 1 self.sheet1 = globals.getSignedInt(self.tokens[i:i+2]) i += 2 if self.header == 0x0023: # 3A in EXTERNNAME expects a 2nd sheet index self.sheet2 = globals.getSignedInt(self.tokens[i:i+2]) i += 2 self.cell = parseCellAddress(self.tokens[i:i+4]) i += 4 except InvalidCellAddress: pass return i
def parseDirEntry(self, bytes): entry = Directory.Entry() entry.bytes = bytes name = globals.getUTF8FromUTF16(bytes[0:64]) entry.Name = name entry.CharBufferSize = getSignedInt(bytes[64:66]) entry.Type = getSignedInt(bytes[66:67]) entry.NodeColor = getSignedInt(bytes[67:68]) entry.DirIDLeft = getSignedInt(bytes[68:72]) entry.DirIDRight = getSignedInt(bytes[72:76]) entry.DirIDRoot = getSignedInt(bytes[76:80]) entry.UniqueID = bytes[80:96] entry.UserFlags = bytes[96:100] entry.TimeCreated = bytes[100:108] entry.TimeModified = bytes[108:116] entry.StreamSectorID = getSignedInt(bytes[116:120]) entry.StreamSize = getSignedInt(bytes[120:124]) entry.StreamLocation = StreamLocation.SAT if entry.Type != Directory.Type.RootStorage and entry.StreamSize < self.header.minStreamSize: entry.StreamLocation = StreamLocation.SSAT if entry.Type == Directory.Type.RootStorage and entry.StreamSectorID >= 0: # This is an existing root storage. self.RootStorage = entry return entry
def parseCellAddress(bytes): if len(bytes) != 4: globals.error( "Byte size is %d but expected 4 bytes for cell address.\n" % len(bytes)) raise InvalidCellAddress row = globals.getSignedInt(bytes[0:2]) col = globals.getSignedInt(bytes[2:4]) colRelative = ((col & 0x4000) != 0) rowRelative = ((col & 0x8000) != 0) col = (col & 0x00FF) obj = CellAddress(col, row, colRelative, rowRelative) return obj
def parseDirEntry(self, bytes): entry = Directory.Entry() entry.bytes = bytes name = globals.getUTF8FromUTF16(bytes[0:64]) entry.Name = name entry.CharBufferSize = getSignedInt(bytes[64:66]) entry.Type = getSignedInt(bytes[66:67]) entry.NodeColor = getSignedInt(bytes[67:68]) entry.DirIDLeft = getSignedInt(bytes[68:72]) entry.DirIDRight = getSignedInt(bytes[72:76]) entry.DirIDRoot = getSignedInt(bytes[76:80]) entry.UniqueID = bytes[80:96] entry.UserFlags = bytes[96:100] entry.TimeCreated = bytes[100:108] entry.TimeModified = bytes[108:116] entry.StreamSectorID = getSignedInt(bytes[116:120]) entry.StreamSize = getSignedInt(bytes[120:124]) entry.StreamLocation = StreamLocation.SAT if entry.Type != Directory.Type.RootStorage and \ entry.StreamSize < self.header.minStreamSize: entry.StreamLocation = StreamLocation.SSAT if entry.Type == Directory.Type.RootStorage and entry.StreamSectorID >= 0: # This is an existing root storage. self.RootStorage = entry return entry
def parse (self): ftokens = self.tokens length = len(ftokens) if self.sizeField: # first 2-bytes contain the length of the formula tokens length = globals.getSignedInt(self.tokens[0:2]) if length <= 0: return ftokens = self.tokens[2:2+length] length = len(ftokens) i = 0 while i < length: tk = ftokens[i] if type(tk) == type('c'): # get the ordinal of the character. tk = ord(tk) if not tokenMap.has_key(tk): # no token handler i += 1 continue # token handler exists. o = tokenMap[tk](self.header, ftokens) i = o.parse(i) self.text += o.getText() + ' ' i += 1
def parseCellRangeAddress (bytes): if len(bytes) != 8: raise InvalidCellAddress obj = CellRange() obj.firstRow = globals.getSignedInt(bytes[0:2]) obj.lastRow = globals.getSignedInt(bytes[2:4]) obj.firstCol = globals.getSignedInt(bytes[4:6]) obj.lastCol = globals.getSignedInt(bytes[6:8]) obj.isFirstColRelative = ((obj.firstCol & 0x4000) != 0) obj.isFirstRowRelative = ((obj.firstCol & 0x8000) != 0) obj.firstCol = (obj.firstCol & 0x00FF) obj.isLastColRelative = ((obj.lastCol & 0x4000) != 0) obj.isLastRowRelative = ((obj.lastCol & 0x8000) != 0) obj.lastCol = (obj.lastCol & 0x00FF) return obj
def parseCellRangeAddress(bytes): if len(bytes) != 8: raise InvalidCellAddress obj = CellRange() obj.firstRow = globals.getSignedInt(bytes[0:2]) obj.lastRow = globals.getSignedInt(bytes[2:4]) obj.firstCol = globals.getSignedInt(bytes[4:6]) obj.lastCol = globals.getSignedInt(bytes[6:8]) obj.isFirstColRelative = ((obj.firstCol & 0x4000) != 0) obj.isFirstRowRelative = ((obj.firstCol & 0x8000) != 0) obj.firstCol = (obj.firstCol & 0x00FF) obj.isLastColRelative = ((obj.lastCol & 0x4000) != 0) obj.isLastRowRelative = ((obj.lastCol & 0x8000) != 0) obj.lastCol = (obj.lastCol & 0x00FF) return obj
def parse (self, i): try: i += 1 self.extSheetId = globals.getSignedInt(self.tokens[i:i+2]) i += 2 self.cell = parseCellAddress(self.tokens[i:i+4]) i += 4 except InvalidCellAddress: pass return i
def parse (self, i): self.cellrange = None try: op = self.tokens[i] i += 1 self.extSheetId = globals.getSignedInt(self.tokens[i:i+2]) i += 2 self.cellrange = parseCellRangeAddress(self.tokens[i:i+8]) except InvalidCellAddress: pass return i
def buildArray(self): if len(self.array) > 0: # array already built. return numItems = int(self.sectorSize / 4) self.array = [] for secID in self.sectorIDs: pos = 512 + secID * self.sectorSize for i in xrange(0, numItems): beginPos = pos + i * 4 id = getSignedInt(self.bytes[beginPos : beginPos + 4]) self.array.append(id)
def buildArray(self): if len(self.array) > 0: # array already built. return numItems = int(self.sectorSize / 4) self.array = [] for secID in self.sectorIDs: pos = 512 + secID * self.sectorSize for i in xrange(0, numItems): beginPos = pos + i * 4 id = getSignedInt(self.bytes[beginPos:beginPos + 4]) self.array.append(id)
def parse (self, i): i += 1 # skip opcode self.errorNum = globals.getSignedInt(self.tokens[i:i+1]) i += 1 return i
def parse(self): # document ID and unique ID self.docId = self.bytes[0:8] self.uId = self.bytes[8:24] # revision and version self.revision = getSignedInt(self.bytes[24:26]) self.version = getSignedInt(self.bytes[26:28]) # byte order self.byteOrder = Header.byteOrder(self.bytes[28:30]) # sector size (usually 512 bytes) self.secSize = getSignedInt(self.bytes[30:32]) # short sector size (usually 64 bytes) self.secSizeShort = getSignedInt(self.bytes[32:34]) # total number of sectors in SAT (equals the number of sector IDs # stored in the MSAT). self.numSecSAT = getSignedInt(self.bytes[44:48]) self.__secIDFirstDirStrm = getSignedInt(self.bytes[48:52]) self.minStreamSize = getSignedInt(self.bytes[56:60]) self.__secIDFirstSSAT = getSignedInt(self.bytes[60:64]) self.numSecSSAT = getSignedInt(self.bytes[64:68]) self.__secIDFirstMSAT = getSignedInt(self.bytes[68:72]) self.numSecMSAT = getSignedInt(self.bytes[72:76]) # master sector allocation table self.MSAT = MSAT(2 ** self.secSize, self.bytes, self.params) # First part of MSAT consisting of an array of up to 109 sector IDs. # Each sector ID is 4 bytes in length. for i in xrange(0, 109): pos = 76 + i * 4 id = getSignedInt(self.bytes[pos : pos + 4]) if id == -1: break self.MSAT.appendSectorID(id) if self.__secIDFirstMSAT != -2: # additional sectors are used to store more SAT sector IDs. secID = self.__secIDFirstMSAT size = self.getSectorSize() inLoop = True while inLoop: pos = 512 + secID * size bytes = self.bytes[pos : pos + size] n = int(size / 4) for i in xrange(0, n): pos = i * 4 id = getSignedInt(bytes[pos : pos + 4]) if id < 0: inLoop = False break elif i == n - 1: # last sector ID - points to the next MSAT sector. secID = id break else: self.MSAT.appendSectorID(id) return 512
def parse(self): # document ID and unique ID self.docId = self.bytes[0:8] self.uId = self.bytes[8:24] # revision and version self.revision = getSignedInt(self.bytes[24:26]) self.version = getSignedInt(self.bytes[26:28]) # byte order self.byteOrder = Header.byteOrder(self.bytes[28:30]) # sector size (usually 512 bytes) self.secSize = getSignedInt(self.bytes[30:32]) # short sector size (usually 64 bytes) self.secSizeShort = getSignedInt(self.bytes[32:34]) # total number of sectors in SAT (equals the number of sector IDs # stored in the MSAT). self.numSecSAT = getSignedInt(self.bytes[44:48]) self.__secIDFirstDirStrm = getSignedInt(self.bytes[48:52]) self.minStreamSize = getSignedInt(self.bytes[56:60]) self.__secIDFirstSSAT = getSignedInt(self.bytes[60:64]) self.numSecSSAT = getSignedInt(self.bytes[64:68]) self.__secIDFirstMSAT = getSignedInt(self.bytes[68:72]) self.numSecMSAT = getSignedInt(self.bytes[72:76]) # master sector allocation table self.MSAT = MSAT(2**self.secSize, self.bytes, self.params) # First part of MSAT consisting of an array of up to 109 sector IDs. # Each sector ID is 4 bytes in length. for i in xrange(0, 109): pos = 76 + i * 4 id = getSignedInt(self.bytes[pos:pos + 4]) if id == -1: break self.MSAT.appendSectorID(id) if self.__secIDFirstMSAT != -2: # additional sectors are used to store more SAT sector IDs. secID = self.__secIDFirstMSAT size = self.getSectorSize() inLoop = True while inLoop: pos = 512 + secID * size bytes = self.bytes[pos:pos + size] n = int(size / 4) for i in xrange(0, n): pos = i * 4 id = getSignedInt(bytes[pos:pos + 4]) if id < 0: inLoop = False break elif i == n - 1: # last sector ID - points to the next MSAT sector. secID = id break else: self.MSAT.appendSectorID(id) return 512