import winreg import hashlib from license_manager import LicenseManager class RegistryManager: # We will generate a path based on HWID hash to obscure it # Format: Software\{SHA256_of_HWID_First_16_Chars} @staticmethod def _get_reg_path(): hwid = LicenseManager.get_hardware_id() # Create a hash of the HWID to make it look like a random system key path_hash = hashlib.md5("WartanaProBackup_{}".format(hwid).encode()).hexdigest().upper() return "SOFTWARE\\{}".format(path_hash) @staticmethod def get_trial_count(): try: path = RegistryManager._get_reg_path() # Open Key key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, path, 0, winreg.KEY_READ) value, regtype = winreg.QueryValueEx(key, "SystemState") # Obscured value name too winreg.CloseKey(key) return int(value) except WindowsError: # Key not found, return 0 return 0 except Exception: return 3 # Fail safe -> block if error @staticmethod def increment_trial_count(): try: path = RegistryManager._get_reg_path() # Create key if not exists key = winreg.CreateKey(winreg.HKEY_CURRENT_USER, path) # Read current current = 0 try: val, _ = winreg.QueryValueEx(key, "SystemState") current = int(val) except: pass # Increment new_val = current + 1 winreg.SetValueEx(key, "SystemState", 0, winreg.REG_DWORD, new_val) winreg.CloseKey(key) return new_val except Exception as e: print("Reg Error: {}".format(e)) return 3 # Fail safe