@@ -22,6 +22,12 @@ class VbaProject:
22
22
#data members of class
23
23
path = "." #path to the project root
24
24
25
+ #Each element is a chain of sector numbers for a particular stream.
26
+ streamSectors = []
27
+
28
+ #A list of sectors that contain FAT chain information.
29
+ fatSectors = []
30
+
25
31
#class default constructor
26
32
def __init__ (self , path ):
27
33
self .path = path
@@ -96,17 +102,24 @@ def header(self):
96
102
csectDif = LONG_ZERO
97
103
header += csectDif
98
104
99
- #sectFat = getFirst109FatSectors ()
105
+ #sectFat = writeFatSectorList ()
100
106
#header += sectFat
101
107
return header
102
108
109
+ def addStreamSectorList (self , list ):
110
+ """Add a list of sector numbers to the FAT table."""
111
+ self .streamSectors .append (list )
112
+
113
+ def countStreams (self ):
114
+ """Return the number of streams defined in the FAT table."""
115
+ return len (self .streamSectors )
116
+
103
117
def writeFat (i ):
104
118
return 1
105
119
106
120
def countFatChainSectors (self ):
107
121
"""Calculate the number of sectors needed to express the FAT chain."""
108
- #return self.getFatChainLength() / 512 + 1 #intdiv, roundup.
109
- return 1
122
+ return self .getFatChainLength () // 511 + 1
110
123
111
124
def getFirstDirectoryChainSector (self ):
112
125
return 1
@@ -120,22 +133,28 @@ def countMiniFatChainSectors(self):
120
133
def getFirstMiniChainSector (self ):
121
134
return 2
122
135
123
- def getFirst109FatSectors (self ):
124
- #return an array of 109 4-byte numbers
125
- #00000000 followed by FFFFFFFF 108 times
126
- return "00000000" ;
136
+ def writeFatSectorList (self ):
137
+ """Create a 436 byte stream of the first 109 FAT sectors, padded with \\ xFF"""
138
+ list = bytearray (b'\x00 \x00 \x00 \x00 ' )
139
+ if self .countFatChainSectors () > 1 :
140
+ #the second FAT sector is number 128.
141
+ pass
142
+ list = list .ljust (436 , b'\xff ' )
143
+ return list
144
+
145
+ def getFatSectors (self ):
146
+ sectorList = [0 ]
147
+ # add
148
+ return sectorList
127
149
128
150
def writeFatSector (self , i ):
129
151
"""return a 512 byte sector"""
130
152
return "FE FF FF FF"
131
153
# followed by 511 bytes
132
154
133
155
def getFatChainLength (self ):
134
- total = 0
135
- #get the length of the fat chain including termination and beginning codes
136
- #Total = getDirectoryChainLength() + 1
137
- #Total += getMiniFatChainLength() + 1
138
- #for stream in streams:
139
- # total += stream.getChainLength() + 1
140
- #total += total % 511 #add one double for each sector
156
+ """Count the number of entries in the complete FAT chain."""
157
+ total = 1
158
+ for stream in self .streamSectors :
159
+ total += len (stream ) + 1
141
160
return total
0 commit comments