Commit e712f8cab1d83cb726253379f6f189b99829dc57

Authored by decalage2
1 parent 608f55c0

olemap: moved display code to functions

Showing 1 changed file with 35 additions and 29 deletions
oletools/olemap.py
... ... @@ -111,6 +111,38 @@ def sid_display(sid):
111 111 return sid
112 112  
113 113  
  114 +def show_fat(ole):
  115 + print('FAT:')
  116 + t = tablestream.TableStream([8, 12, 8, 8], header_row=['Sector #', 'Type', 'Offset', 'Next #'])
  117 + for i in range(ole.nb_sect):
  118 + fat_value = ole.fat[i]
  119 + fat_type = FAT_TYPES.get(fat_value, '<Data>')
  120 + color_type = FAT_COLORS.get(fat_value, FAT_COLORS['default'])
  121 + # compute offset based on sector size:
  122 + offset = ole.sectorsize * (i + 1)
  123 + # print '%8X: %-12s offset=%08X next=%8X' % (i, fat_type, 0, fat_value)
  124 + t.write_row(['%8X' % i, fat_type, '%08X' % offset, '%8X' % fat_value],
  125 + colors=[None, color_type, None, None])
  126 + t.close()
  127 + print('')
  128 +
  129 +
  130 +def show_minifat(ole):
  131 + print('MiniFAT:')
  132 + # load MiniFAT if it wasn't already done:
  133 + ole.loadminifat()
  134 + t = tablestream.TableStream([8, 12, 8, 8], header_row=['Sector #', 'Type', 'Offset', 'Next #'])
  135 + for i in range(len(ole.minifat)):
  136 + fat_value = ole.minifat[i]
  137 + fat_type = FAT_TYPES.get(fat_value, 'Data')
  138 + color_type = FAT_COLORS.get(fat_value, FAT_COLORS['default'])
  139 + # TODO: compute offset
  140 + # print('%8X: %-12s offset=%08X next=%8X' % (i, fat_type, 0, fat_value))
  141 + t.write_row(['%8X' % i, fat_type, 'N/A', '%8X' % fat_value],
  142 + colors=[None, color_type, None, None])
  143 + t.close()
  144 + print('')
  145 +
114 146 # === MAIN ===================================================================
115 147  
116 148 def main():
... ... @@ -138,8 +170,6 @@ def main():
138 170  
139 171 # print banner with version
140 172 print(BANNER)
141   - # print banner with version
142   - print('olemap %s - http://decalage.info/python/oletools' % __version__)
143 173  
144 174 for container, filename, data in xglob.iter_files(args, recursive=options.recursive,
145 175 zip_password=options.zip_password, zip_fname=options.zip_fname):
... ... @@ -156,33 +186,9 @@ def main():
156 186 else:
157 187 # normal filename
158 188 ole = olefile.OleFileIO(filename)
159   - print('FAT:')
160   - t = tablestream.TableStream([8, 12, 8, 8], header_row=['Sector #', 'Type', 'Offset', 'Next #'])
161   - for i in range(ole.nb_sect):
162   - fat_value = ole.fat[i]
163   - fat_type = FAT_TYPES.get(fat_value, '<Data>')
164   - color_type = FAT_COLORS.get(fat_value, FAT_COLORS['default'])
165   - # compute offset based on sector size:
166   - offset = ole.sectorsize * (i+1)
167   - # print '%8X: %-12s offset=%08X next=%8X' % (i, fat_type, 0, fat_value)
168   - t.write_row(['%8X' % i, fat_type, '%08X' % offset, '%8X' % fat_value],
169   - colors=[None, color_type, None, None])
170   - t.close()
171   - print('')
172   -
173   - print('MiniFAT:')
174   - # load MiniFAT if it wasn't already done:
175   - ole.loadminifat()
176   - t = tablestream.TableStream([8, 12, 8, 8], header_row=['Sector #', 'Type', 'Offset', 'Next #'])
177   - for i in range(len(ole.minifat)):
178   - fat_value = ole.minifat[i]
179   - fat_type = FAT_TYPES.get(fat_value, 'Data')
180   - color_type = FAT_COLORS.get(fat_value, FAT_COLORS['default'])
181   - # TODO: compute offset
182   - # print('%8X: %-12s offset=%08X next=%8X' % (i, fat_type, 0, fat_value))
183   - t.write_row(['%8X' % i, fat_type, 'N/A', '%8X' % fat_value],
184   - colors=[None, color_type, None, None])
185   - t.close()
  189 +
  190 + show_fat(ole)
  191 + show_minifat(ole)
186 192  
187 193 ole.close()
188 194  
... ...