22
22
import urllib .request
23
23
import subprocess
24
24
import ctypes
25
+ import time
25
26
26
27
27
28
def BinarySIDtoStringSID (sid_str ):
@@ -155,7 +156,11 @@ def load_srumid_lookups(database):
155
156
id_lookup = {}
156
157
#Note columns 0 = Type, 1 = Index, 2 = Value
157
158
lookup_table = database .get_table_by_name ('SruDbIdMapTable' )
158
- column_lookup = dict ([(x .name ,index ) for index ,x in enumerate (lookup_table .columns )])
159
+ column_lookup = dict ([(x .name ,index ) for index ,x in enumerate (lookup_table .columns )])
160
+ num_lookups = ese_table_record_count (lookup_table )
161
+ if not num_lookups :
162
+ print (f"\n Unexpectedly. The number of records in the lookup table is zero." )
163
+ return ""
159
164
for rec_entry_num in range (lookup_table .number_of_records ):
160
165
bin_blob = smart_retrieve (lookup_table ,rec_entry_num , column_lookup ['IdBlob' ])
161
166
if smart_retrieve (lookup_table ,rec_entry_num , column_lookup ['IdType' ])== 3 :
@@ -314,23 +319,72 @@ def format_output(val, eachformat, eachstyle, xls_sheet):
314
319
new_cell .value = re .sub (r'[\000-\010]|[\013-\014]|[\016-\037]|[\x00-\x1f\x7f-\x9f]|[\uffff]' ,"" ,val )
315
320
return new_cell
316
321
322
+ def ese_table_guid_to_name (ese_table ):
323
+ if ese_table .name in template_tables :
324
+ tname ,tfields = template_tables .get (ese_table .name )
325
+ else :
326
+ tname = ese_table .get_name ()
327
+ return tname
328
+
329
+ def ese_table_get_record (ese_table , row_num ):
330
+ retry = 5
331
+ if row_num >= ese_table_record_count (ese_table ):
332
+ return None
333
+ while retry :
334
+ try :
335
+ ese_row = ese_table .get_record (row_num )
336
+ except Exception as e :
337
+ retry -= 1
338
+ time .sleep (0.1 )
339
+ error = e
340
+ else :
341
+ break
342
+ else :
343
+ tname = ese_table_guid_to_name (ese_table )
344
+ print ("Skipping corrupt row {0} in the {1} table. Because {2}" .format (row_num , tname , str (error )))
345
+ ese_row = None
346
+ return ese_row
347
+
348
+ def ese_table_record_count (ese_table ):
349
+ retry = 5
350
+ while retry :
351
+ try :
352
+ total_recs = ese_table .get_number_of_records ()
353
+ except :
354
+ retry -= 1
355
+ time .sleep (0.1 )
356
+ else :
357
+ break
358
+ else :
359
+ tname = ese_table_guid_to_name (x )
360
+ print (f"Table { tname } has an invalid number of records. { str (total_recs )} " )
361
+ total_recs = 0
362
+ return total_recs
363
+
317
364
318
365
def process_srum (ese_db , target_wb ):
319
366
"""Process all the tables and columns in the ESE database"""
320
- total_recs = sum ([x .number_of_records for x in ese_db .tables if x .name not in skip_tables ])
367
+ total_recs = 0
368
+ for each_table in ese_db .tables :
369
+ if each_table .name in skip_tables :
370
+ continue
371
+ total_recs += ese_table_record_count (each_table )
372
+
321
373
if not options .quiet :
322
374
print ("Processing {} records across {} tables" .format (total_recs ,ese_db .number_of_tables - len (skip_tables )))
323
375
for table_num in range (ese_db .number_of_tables ):
324
376
ese_table = ese_db .get_table (table_num )
325
377
if ese_table .name in skip_tables :
326
378
continue
327
- if ese_table .name in template_tables :
328
- tname ,tfields = template_tables .get (ese_table .name )
329
- else :
330
- tname = ese_table .name [1 :15 ]
379
+
380
+ tname = ese_table_guid_to_name (ese_table )
381
+ num_recs = ese_table_record_count (ese_table )
382
+ if not num_recs :
383
+ print (f"\n Skipping table with zero of records. { tname } " )
384
+ continue
331
385
332
386
if not options .quiet :
333
- print ("\n Now dumping table {} containing {} rows" .format (tname , ese_table . number_of_records ))
387
+ print ("\n Now dumping table {} containing {} rows" .format (tname , num_recs or "Unknown" ))
334
388
print ("While you wait, did you know ...\n {} \n " .format (next (ads )))
335
389
336
390
xls_sheet = target_wb .create_sheet (title = tname )
@@ -353,17 +407,14 @@ def process_srum(ese_db, target_wb ):
353
407
header_row .append (WriteOnlyCell (xls_sheet , value = eachcol .name ))
354
408
xls_sheet .append (header_row )
355
409
356
- for row_num in range (ese_table .number_of_records ):
357
- try :
358
- ese_row = ese_table .get_record (row_num )
359
- except Exception as e :
360
- print ("Skipping corrupt row {0} in the {1} table. Because {2}" .format (row_num , ese_table .name , str (e )))
361
- continue
410
+ for row_num in range (num_recs ):
411
+
412
+ ese_row = ese_table_get_record (ese_table ,row_num )
362
413
if ese_row == None :
363
414
continue
364
415
365
416
if not options .quiet and row_num % 500 == 0 :
366
- print ("\r |{0:-<50}| {1:3.2f}%" .format ("X" * ( 50 * row_num // ese_table . number_of_records ), 100 * row_num / ese_table . number_of_records ),end = "" )
417
+ print ("\r |{0:-<50}| {1:3.2f}%" .format ("X" * ( 50 * row_num // num_recs ), 100 * row_num / num_recs ),end = "" )
367
418
368
419
#The row is retrieved now use the template to figure out which ones you want and format them
369
420
xls_row = []
@@ -519,7 +570,7 @@ def extract_live_file():
519
570
[sg .OK (), sg .Cancel ()]]
520
571
521
572
# Create the Window
522
- window = sg .Window ('SRUM_DUMP 2.5 ' , layout )
573
+ window = sg .Window ('SRUM_DUMP 2.6 ' , layout )
523
574
524
575
while True :
525
576
event , values = window .Read ()
0 commit comments