1212from tkinter import filedialog , messagebox , ttk
1313import threading
1414import docx
15- import re
1615import pandas as pd
1716import csv
1817from striprtf .striprtf import rtf_to_text
@@ -37,7 +36,7 @@ def isAdmin():
3736 except AttributeError :
3837 is_admin = ctypes .windll .shell32 .IsUserAnAdmin () != 0
3938 return is_admin
40- def parse_docx (file ):
39+ def parse_docx (gui , file ):
4140 try :
4241 doc = docx .Document (file )
4342 for para in doc .paragraphs :
@@ -48,6 +47,7 @@ def parse_docx(file):
4847 for key in key_match :
4948 recovery_id = id_match [0 ] if id_match else "Unknown"
5049 data .append ({"File Path" : file , "Recovery Key ID" : recovery_id , "BitLocker Key" : key })
50+ gui .log_message (f"File { file } Key ID { recovery_id } Bitlocker Key { key } " , "info" )
5151 except Exception as e :
5252 print (f"Error parsing { file } : { e } " )
5353 return
@@ -101,31 +101,18 @@ def walk(folder):
101101 if file .endswith (('.txt' , '.TXT' , '.bek' , '.BEK' )):
102102 txt_Files .append (os .path .join (root , file ))
103103
104- def exhaustive_walk (folder ):
104+ def exhaustive_walk (gui , folder ):
105105 for root , dirs , files in os .walk (folder ):
106106 for file in files :
107107 # if file.endswith(('.txt', '.TXT', '.bek', '.BEK')):
108108 # txt_Files.append(os.path.join(root, file))
109109 if file .endswith (".docx" ):
110- parse_docx (os .path .join (root , file ))
110+ parse_docx (gui , os .path .join (root , file ))
111111 elif file .endswith (".xlsx" ):
112- parse_xlsx (os .path .join (root , file ))
112+ parse_xlsx (gui , os .path .join (root , file ))
113113 elif file .endswith (".rtf" ):
114- parse_rtf (os .path .join (root , file ))
114+ parse_rtf (gui , os .path .join (root , file ))
115115
116- def parse_txt (file ):
117- try :
118-
119- with open (file , 'r' , encoding = 'utf-8' ) as f :
120- text = f .read ()
121- key_match = key_pattern .findall (text )
122- id_match = id_pattern .findall (text )
123- if key_match :
124- for key in key_match :
125- recovery_id = id_match [0 ] if id_match else "Unknown"
126- data .append ({"File Path" : file , "Recovery Key ID" : recovery_id , "BitLocker Key" : key })
127- except Exception as e :
128- print (f"Error parsing { file } : { e } " )
129116
130117def name_search (gui ):
131118 for ele in txt_Files :
@@ -205,11 +192,11 @@ def UTF16LE_string_search(gui):
205192 for key in key_match :
206193 recovery_id = id_match [0 ] if id_match else "Unknown"
207194 data .append ({"File Path" : ele , "Recovery Key ID" : recovery_id , "BitLocker Key" : key })
208- for key in k :
209- Bit_Keys .append (ele )
210- gui .log_message (f"Found BitLocker key in file: { ele } " , "success" )
211- gui .log_message (f"Key: { key } " , "info" )
212- Collected_Keys .append (key )
195+
196+ Bit_Keys .append (ele )
197+ gui .log_message (f"Found BitLocker key in file: { ele } " , "success" )
198+ gui .log_message (f"Key: { key } " , "info" )
199+ Collected_Keys .append (key )
213200 except UnicodeDecodeError :
214201 # gui.log_message(f"Unable to decode file as UTF-16LE: {ele}", "warning")
215202 pass
@@ -223,6 +210,15 @@ def UTF16LE_string_search(gui):
223210 except Exception as e :
224211 gui .log_message (f"Error processing file { ele } : { str (e )} " , "error" )
225212
213+ def make_key_report (report_folder ):
214+ output_folder = report_folder
215+ csv_file = os .path .join (output_folder , "BitlockerKeyReport" + now .strftime ("%Y%m%d%H%M%S" ) + ".csv" )
216+ with open (csv_file , mode = 'w' , newline = '' , encoding = 'utf-8' ) as file :
217+ writer = csv .DictWriter (file , fieldnames = ["File Path" , "Recovery Key ID" , "BitLocker Key" ])
218+ writer .writeheader ()
219+ writer .writerows (data )
220+ # print(data)
221+
226222class BitlockerKeyFinderGUI :
227223 def __init__ (self , master ):
228224 self .master = master
@@ -283,7 +279,7 @@ def create_widgets(self):
283279 self .find_keys_button .pack (side = "left" , padx = 5 )
284280
285281 tk .Button (button_frame , text = "Help" , command = self .show_help , bg = "orange" , fg = "black" , relief = tk .RAISED ).pack (side = "left" , padx = 5 )
286-
282+
287283 # Console
288284 console_frame = tk .Frame (self .master , bg = "#333333" )
289285 console_frame .pack (fill = "both" , expand = True , padx = 10 , pady = 5 )
@@ -295,7 +291,8 @@ def create_widgets(self):
295291 self .console .tag_configure ("error" , foreground = "red" )
296292 self .console .tag_configure ("success" , foreground = "black" )
297293 self .console .tag_configure ("bold" , font = ("Arial" , 10 ,))
298-
294+ self .progress = ttk .Progressbar (self .master , orient = "horizontal" , length = 800 , mode = "determinate" )
295+ self .progress .pack (pady = 0 )
299296 clear_frame = tk .Frame (self .master , bg = "#f0f0f0" )
300297 clear_frame .pack (fill = "x" , padx = 10 , pady = (0 , 10 )) # Add padding at the bottom
301298 tk .Button (clear_frame , text = "Clear Window" , command = self .clear_console , bg = "#FF5722" , fg = "white" , relief = tk .RAISED ).pack ()
@@ -335,6 +332,8 @@ def start_find_keys_thread(self):
335332 # Start the find keys process in a separate thread
336333 thread = threading .Thread (target = self .find_keys )
337334 thread .start ()
335+
336+
338337
339338 def find_keys (self ):
340339 global Bit_Keys , txt_Files
@@ -344,15 +343,21 @@ def find_keys(self):
344343
345344 # Traverse the directory and find .txt and .BEK files
346345 walk (folder_path )
346+ total_files = len (txt_Files )
347+ self .progress ['value' ] = 0
348+ self .progress ['maximum' ] = total_files
347349
348350 if self .filename_var .get ():
349351 self .log_message (f"Searching for file names in { folder_path } " , "info" )
350352 name_search (self )
351353
352354 if self .exhaustive_search_var .get ():
353355 self .log_message (f"Conducting exhaustive string search in { folder_path } " , "info" )
354- exhaustive_walk (folder_path )
356+ exhaustive_walk (self , folder_path )
355357 exhaustive_search (self )
358+ make_key_report (self .output_entry .get ())
359+
360+
356361
357362 if self .utf16le_search_var .get ():
358363 self .log_message (f"Conducting UTF-16LE string search in { folder_path } " , "info" )
@@ -371,16 +376,7 @@ def find_keys(self):
371376 # Re-enable the Find Keys button
372377 self .find_keys_button .config (state = tk .NORMAL )
373378
374- def make_key_report (self ):
375- output_folder = self .output_entry .get ()
376- csv_file = os .path .join (output_folder , "BitlockerKeyReport" + now .strftime ("%Y%m%d%H%M%S" ) + ".csv" )
377- with open (csv_file , mode = 'w' , newline = '' , encoding = 'utf-8' ) as file :
378- writer = csv .DictWriter (file , fieldnames = ["File Path" , "Recovery Key ID" , "BitLocker Key" ])
379- writer .writeheader ()
380- writer .writerows (data )
381- # print(data)
382- self .log_message (f"Report generated: { csv_file } " )
383- print (f"Report generated: { csv_file } " )
379+
384380
385381
386382 def copy_key_files (self ):
0 commit comments