diff --git a/hash_longterm.py b/hash_longterm.py index ca9e5d008e5a9a377cb4adbaa2884fe1b4f5bfbd..7ec760d9c3a0f06487a34453a24c21e926594a4b 100644 --- a/hash_longterm.py +++ b/hash_longterm.py @@ -6,15 +6,6 @@ from termcolor import colored from src.drive_handle import DriveHandle -__log_file_path: str = None - - -def log(message: str): - with open(__log_file_path, "a") as file: - file.write(f"{message}\n") - return message - - if __name__ == "__main__": # check rights if not pyuac.isUserAdmin(): @@ -52,9 +43,6 @@ if __name__ == "__main__": case("max_iterations"): max_iterations = int(arguments.get("max_iterations")) - case("log_file_path"): - __log_file_path = arguments.get("log_file_path") - case("max_memory"): # max_memory is passed in MiB max_memory = int(arguments.get("max_memory")) @@ -67,13 +55,13 @@ if __name__ == "__main__": drive_handle: DriveHandle = DriveHandle(drive_letter, format_drive, max_memory) # write random data to the disk - print(colored(log("[Hash-Longtermstudy] Starting the hash run!"), "light_blue")) + print(colored("[Hash-Longtermstudy] Starting the hash run!", "light_blue")) drive_handle.copy_demo_files() - print(colored(log("[Hash-Longtermstudy] Waiting 120s for the OS to flush the write buffer."), "cyan")) + print(colored("[Hash-Longtermstudy] Waiting 120s for the OS to flush the write buffer.", "cyan")) drive_handle.flush_cache() time.sleep(120) # create hash - print(colored(log(f"[Hash-Longtermstudy] The hash prior to the deletion is {drive_handle.generate_hash()}"), "light_blue")) + print(colored(f"[Hash-Longtermstudy] The hash prior to the deletion is {drive_handle.generate_hash()}", "light_blue")) # remember cluster for DRAT check compare_cluster_number: int = drive_handle.get_clusters_for_file(f'{drive_handle.get_path()}demo\\t5\\000503.text')[0] @@ -87,41 +75,41 @@ if __name__ == "__main__": drive_handle.set_read_only(True) # check for DRAT - print(colored(log("[Hash-Longtermstudy] Testing for DRAT/DZAT."), "light_grey")) + print(colored("[Hash-Longtermstudy] Testing for DRAT/DZAT.", "light_grey")) cluster_values: bytes = drive_handle.read_cluster(compare_cluster_number) if (cluster_values != compare_cluster_values): # DRAT or DZAT - print(colored(log(f"[Hash-Longtermstudy] Cluster {compare_cluster_number} read a different value immediately after deletion. DRAT or DZAT is likely."), "yellow")) - print(colored(log("[Hash-Longtermstudy] SSD usage likely due to DRAT/DZAT. Skipping test."), "red")) + print(colored(f"[Hash-Longtermstudy] Cluster {compare_cluster_number} read a different value immediately after deletion. DRAT or DZAT is likely.", "yellow")) + print(colored("[Hash-Longtermstudy] SSD usage likely due to DRAT/DZAT. Skipping test.", "red")) drive_handle.set_read_only(False) # SSD usage likely exit() else: - print(colored(log("[Hash-Longtermstudy] No DRAT/DZAT detected."), "yellow")) + print(colored("[Hash-Longtermstudy] No DRAT/DZAT detected.", "yellow")) # repeadetly create the hash prior_hash: str = None iteration = 0 while True: - print(colored(log(f"[Hash-Longtermstudy] Waiting {wait_time}s until generating the next hash."), "light_grey")) + print(colored(f"[Hash-Longtermstudy] Waiting {wait_time}s until generating the next hash.", "light_grey")) time.sleep(wait_time) current_hash = drive_handle.generate_hash() - print(colored(log(f"[Hash-Longtermstudy] The current hash of the drive is {current_hash}"), "light_blue")) + print(colored(f"[Hash-Longtermstudy] The current hash of the drive is {current_hash}", "light_blue")) iteration += 1 if prior_hash is None: prior_hash = current_hash continue elif prior_hash != current_hash: # hash changed - print(colored(log("[Hash-Longtermstudy] The drive hash changed."), "yellow")) + print(colored("[Hash-Longtermstudy] The drive hash changed.", "yellow")) if iteration >= threshold: - print(colored(log(f"[Hash-Longtermstudy] The threshold of {threshold} changes before measuring is exceeded. This change is likely to be caused by wear levelling."), "yellow")) + print(colored(f"[Hash-Longtermstudy] The threshold of {threshold} changes before measuring is exceeded. This change is likely to be caused by wear levelling.", "yellow")) break else: - print(colored(log(f"[Hash-Longtermstudy] The threshold of {threshold} changes before measuring is not exceeded yet. Currently at iteration {iteration}. Continuing..."), "yellow")) + print(colored(f"[Hash-Longtermstudy] The threshold of {threshold} changes before measuring is not exceeded yet. Currently at iteration {iteration}. Continuing...", "yellow")) prior_hash = current_hash if iteration >= max_iterations: - print(colored(log(f"[Hash-Longtermstudy] Reached iteration {iteration} (max iterations was set to {max_iterations}). Stopping the test."), "red")) + print(colored(f"[Hash-Longtermstudy] Reached iteration {iteration} (max iterations was set to {max_iterations}). Stopping the test.", "red")) break # release drive