From a86649cb29ed8a979861ae93b51b501d5e51fc95 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 27 Sep 2022 23:34:54 -0700 Subject: [PATCH 01/13] Update main settings --- scripts/wk/cfg/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/wk/cfg/main.py b/scripts/wk/cfg/main.py index a2afda8a..7861fa71 100644 --- a/scripts/wk/cfg/main.py +++ b/scripts/wk/cfg/main.py @@ -14,7 +14,7 @@ ENABLED_UPLOAD_DATA=False ARCHIVE_PASSWORD='Abracadabra' KIT_NAME_FULL='WizardKit' KIT_NAME_SHORT='WK' -SUPPORT_MESSAGE='Please let 2Shirt know by opening an issue on GitHub' +SUPPORT_MESSAGE='Please let 2Shirt know by opening an issue on Gitea' # Text Formatting INDENT=4 @@ -27,8 +27,8 @@ TECH_PASSWORD='Abracadabra' # Time Zones ## See 'timedatectl list-timezones' for valid Linux values ## See 'tzutil /l' for valid Windows values -LINUX_TIME_ZONE='America/Denver' -WINDOWS_TIME_ZONE='Mountain Standard Time' +LINUX_TIME_ZONE='America/Los_Angeles' +WINDOWS_TIME_ZONE='Pacific Standard Time' if __name__ == '__main__': From 2b42bf9a8c44bec19572df80aedb7bd281a29638 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 27 Sep 2022 23:44:46 -0700 Subject: [PATCH 02/13] Update sources --- scripts/wk/cfg/sources.py | 31 +++++++++++++++---------------- scripts/wk/kit/build_win.py | 11 +---------- scripts/wk/setup/win.py | 2 +- 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/scripts/wk/cfg/sources.py b/scripts/wk/cfg/sources.py index a4307ced..d9b7c577 100644 --- a/scripts/wk/cfg/sources.py +++ b/scripts/wk/cfg/sources.py @@ -29,12 +29,12 @@ SOURCES = { 'VCRedist_2012_x64': 'https://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU_4/vcredist_x64.exe', 'VCRedist_2013_x32': 'https://aka.ms/highdpimfc2013x86enu', 'VCRedist_2013_x64': 'https://aka.ms/highdpimfc2013x64enu', - 'VCRedist_2019_x32': 'https://aka.ms/vs/16/release/vc_redist.x86.exe', - 'VCRedist_2019_x64': 'https://aka.ms/vs/16/release/vc_redist.x64.exe', + 'VCRedist_2022_x32': 'https://aka.ms/vs/17/release/vc_redist.x86.exe', + 'VCRedist_2022_x64': 'https://aka.ms/vs/17/release/vc_redist.x64.exe', # Build Kit - 'AIDA64': 'https://download.aida64.com/aida64engineer660.zip', - 'Adobe Reader DC': 'https://ardownload2.adobe.com/pub/adobe/reader/win/AcrobatDC/2101120039/AcroRdrDC2101120039_en_US.exe', + 'AIDA64': 'https://download.aida64.com/aida64engineer675.zip', + 'Adobe Reader DC': 'https://ardownload2.adobe.com/pub/adobe/reader/win/AcrobatDC/2200220191/AcroRdrDC2200220191_en_US.exe', 'Aria2': 'https://github.com/aria2/aria2/releases/download/release-1.36.0/aria2-1.36.0-win-32bit-build1.zip', 'Autoruns32': 'http://live.sysinternals.com/Autoruns.exe', 'Autoruns64': 'http://live.sysinternals.com/Autoruns64.exe', @@ -42,23 +42,22 @@ SOURCES = { 'BlueScreenView32': 'http://www.nirsoft.net/utils/bluescreenview.zip', 'BlueScreenView64': 'http://www.nirsoft.net/utils/bluescreenview-x64.zip', 'ERUNT': 'http://www.aumha.org/downloads/erunt.zip', - 'Everything32': 'https://www.voidtools.com/Everything-1.4.1.1009.x86.en-US.zip', - 'Everything64': 'https://www.voidtools.com/Everything-1.4.1.1009.x64.en-US.zip', - 'FastCopy': 'https://ftp.vector.co.jp/73/10/2323/FastCopy392_installer.exe', - 'Fluent-Metro': 'https://github.com/bonzibudd/Fluent-Metro/releases/download/v1.5.2/Fluent-Metro_1.5.2.zip', - 'FurMark': 'https://geeks3d.com/dl/get/569', - 'HWiNFO': 'https://www.sac.sk/download/utildiag/hwi_712.zip', 'IOBit Uninstaller': 'https://portableapps.com/redirect/?a=IObitUninstallerPortable&s=s&d=pa&f=IObitUninstallerPortable_7.5.0.7.paf.exe', - 'LibreOffice32': 'https://download.documentfoundation.org/libreoffice/stable/7.3.0/win/x86/LibreOffice_7.3.0_Win_x86.msi', - 'LibreOffice64': 'https://download.documentfoundation.org/libreoffice/stable/7.3.0/win/x86_64/LibreOffice_7.3.0_Win_x64.msi', + 'Everything32': 'https://www.voidtools.com/Everything-1.4.1.1020.x86.zip', + 'Everything64': 'https://www.voidtools.com/Everything-1.4.1.1020.x64.zip', + 'FastCopy': 'https://ftp.vector.co.jp/75/32/2323/FastCopy4.2.0_installer.exe', + 'Fluent-Metro': 'https://github.com/bonzibudd/Fluent-Metro/releases/download/v1.5.3/Fluent-Metro_1.5.3.zip', + 'FurMark': 'https://geeks3d.com/dl/get/696', + 'HWiNFO': 'https://www.sac.sk/download/utildiag/hwi_730.zip', + 'LibreOffice32': 'https://download.documentfoundation.org/libreoffice/stable/7.3.6/win/x86/LibreOffice_7.3.6_Win_x86.msi', + 'LibreOffice64': 'https://download.documentfoundation.org/libreoffice/stable/7.3.6/win/x86_64/LibreOffice_7.3.6_Win_x64.msi', 'Macs Fan Control': 'https://www.crystalidea.com/downloads/macsfancontrol_setup.exe', 'Neutron': 'http://keir.net/download/neutron.zip', 'Notepad++': 'https://github.com/notepad-plus-plus/notepad-plus-plus/releases/download/v8.1.9.3/npp.8.1.9.3.portable.minimalist.7z', - 'OpenShell': 'https://github.com/Open-Shell/Open-Shell-Menu/releases/download/v4.4.160/OpenShellSetup_4_4_160.exe', + 'OpenShell': 'https://github.com/Open-Shell/Open-Shell-Menu/releases/download/v4.4.170/OpenShellSetup_4_4_170.exe', 'PuTTY': 'https://the.earth.li/~sgtatham/putty/latest/w32/putty.zip', - 'SDIO Torrent': 'https://www.snappy-driver-installer.org/downloads/SDIO_Update.torrent', - 'TestDisk': 'https://www.cgsecurity.org/testdisk-7.2-WIP.win.zip', - 'WizTree': 'https://diskanalyzer.com/files/wiztree_4_07_portable.zip', + 'SDIO Torrent': 'https://www.glenn.delahoy.com/downloads/sdio/SDIO_Update.torrent', + 'WizTree': 'https://diskanalyzer.com/files/wiztree_4_10_portable.zip', 'XMPlay': 'https://support.xmplay.com/files/20/xmplay385.zip?v=47090', 'XMPlay 7z': 'https://support.xmplay.com/files/16/xmp-7z.zip?v=800962', 'XMPlay Game': 'https://support.xmplay.com/files/12/xmp-gme.zip?v=515637', diff --git a/scripts/wk/kit/build_win.py b/scripts/wk/kit/build_win.py index 595efeac..01b09bb1 100644 --- a/scripts/wk/kit/build_win.py +++ b/scripts/wk/kit/build_win.py @@ -251,6 +251,7 @@ def download_libreoffice(): for arch in 32, 64: out_path = INSTALLERS_DIR.joinpath(f'LibreOffice{arch}.msi') download_file(out_path, SOURCES[f'LibreOffice{arch}']) + sleep(1) def download_neutron(): @@ -357,15 +358,6 @@ def download_snappy_driver_installer_origin(): delete_from_temp('fake.7z') -def download_testdisk(): - """Download TestDisk.""" - archive = download_to_temp('testdisk_wip.zip', SOURCES['TestDisk']) - out_path = BIN_DIR.joinpath('TestDisk') - tmp_path = TMP_DIR.joinpath('TestDisk') - extract_archive(archive, tmp_path) - rename_item(tmp_path.joinpath('testdisk-7.2-WIP'), out_path) - delete_from_temp('TestDisk') - delete_from_temp('testdisk_wip.zip') def download_wiztree(): @@ -491,7 +483,6 @@ def build_kit(): try_print.run('OpenShell...', download_openshell) try_print.run('PuTTY...', download_putty) try_print.run('Snappy Driver Installer...', download_snappy_driver_installer_origin) - try_print.run('TestDisk...', download_testdisk) try_print.run('WizTree...', download_wiztree) try_print.run('XMPlay...', download_xmplay) try_print.run('XMPlay Music...', download_xmplay_music) diff --git a/scripts/wk/setup/win.py b/scripts/wk/setup/win.py index cb50e3ca..c399b0c6 100644 --- a/scripts/wk/setup/win.py +++ b/scripts/wk/setup/win.py @@ -812,7 +812,7 @@ def install_software_bundle(): def install_vcredists(): """Install latest supported Visual C++ runtimes.""" - for year in (2012, 2013, 2019): + for year in (2012, 2013, 2022): cmd_args = ['/install', '/passive', '/norestart'] if year == 2012: cmd_args.pop(0) From dd59f94f855d3b7d8e1c6c6f1ae82c6bcd3b6148 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 27 Sep 2022 23:46:19 -0700 Subject: [PATCH 03/13] Replace IOBit with UninstallView --- scripts/auto_repairs.py | 2 +- scripts/wk/cfg/sources.py | 3 ++- scripts/wk/kit/build_win.py | 25 ++++++++++++++----------- scripts/wk/repairs/win.py | 26 +++++++++++++------------- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/scripts/auto_repairs.py b/scripts/auto_repairs.py index 66db3732..8d572d07 100644 --- a/scripts/auto_repairs.py +++ b/scripts/auto_repairs.py @@ -69,7 +69,7 @@ BASE_MENUS = { ), 'Manual Steps': ( MenuEntry('AdwCleaner', 'auto_adwcleaner'), - MenuEntry('IO Bit Uninstaller', 'auto_iobit_uninstaller'), + MenuEntry('UninstallView', 'auto_uninstallview'), MenuEntry('Enable Windows Updates', 'auto_windows_updates_enable'), ), }, diff --git a/scripts/wk/cfg/sources.py b/scripts/wk/cfg/sources.py index d9b7c577..b516cb25 100644 --- a/scripts/wk/cfg/sources.py +++ b/scripts/wk/cfg/sources.py @@ -42,7 +42,6 @@ SOURCES = { 'BlueScreenView32': 'http://www.nirsoft.net/utils/bluescreenview.zip', 'BlueScreenView64': 'http://www.nirsoft.net/utils/bluescreenview-x64.zip', 'ERUNT': 'http://www.aumha.org/downloads/erunt.zip', - 'IOBit Uninstaller': 'https://portableapps.com/redirect/?a=IObitUninstallerPortable&s=s&d=pa&f=IObitUninstallerPortable_7.5.0.7.paf.exe', 'Everything32': 'https://www.voidtools.com/Everything-1.4.1.1020.x86.zip', 'Everything64': 'https://www.voidtools.com/Everything-1.4.1.1020.x64.zip', 'FastCopy': 'https://ftp.vector.co.jp/75/32/2323/FastCopy4.2.0_installer.exe', @@ -57,6 +56,8 @@ SOURCES = { 'OpenShell': 'https://github.com/Open-Shell/Open-Shell-Menu/releases/download/v4.4.170/OpenShellSetup_4_4_170.exe', 'PuTTY': 'https://the.earth.li/~sgtatham/putty/latest/w32/putty.zip', 'SDIO Torrent': 'https://www.glenn.delahoy.com/downloads/sdio/SDIO_Update.torrent', + 'UninstallView32': 'https://www.nirsoft.net/utils/uninstallview.zip', + 'UninstallView64': 'https://www.nirsoft.net/utils/uninstallview-x64.zip', 'WizTree': 'https://diskanalyzer.com/files/wiztree_4_10_portable.zip', 'XMPlay': 'https://support.xmplay.com/files/20/xmplay385.zip?v=47090', 'XMPlay 7z': 'https://support.xmplay.com/files/16/xmp-7z.zip?v=800962', diff --git a/scripts/wk/kit/build_win.py b/scripts/wk/kit/build_win.py index 01b09bb1..b3c4510b 100644 --- a/scripts/wk/kit/build_win.py +++ b/scripts/wk/kit/build_win.py @@ -230,16 +230,6 @@ def download_hwinfo(): delete_from_temp('HWiNFO.zip') -def download_iobit_uninstaller(): - """Download IOBit Uninstaller.""" - installer = CBIN_DIR.joinpath('IObitUninstallerPortable.exe') - download_file(installer, SOURCES['IOBit Uninstaller']) - popen_program([installer]) - sleep(1) - wait_for_procs('IObitUninstallerPortable.exe') - delete_item(installer) - - def download_macs_fan_control(): """Download Macs Fan Control.""" out_path = INSTALLERS_DIR.joinpath('Macs Fan Control.exe') @@ -358,6 +348,19 @@ def download_snappy_driver_installer_origin(): delete_from_temp('fake.7z') +def download_uninstallview(): + """Download UninstallView.""" + archive_32 = download_to_temp('uninstallview32.zip', SOURCES['UninstallView32']) + archive_64 = download_to_temp('uninstallview64.zip', SOURCES['UninstallView64']) + out_path = BIN_DIR.joinpath('UninstallView') + extract_archive(archive_64, out_path, 'UninstallView.exe') + rename_item( + out_path.joinpath('UninstallView.exe'), + out_path.joinpath('UninstallView64.exe'), + ) + extract_archive(archive_32, out_path) + delete_from_temp('uninstallview32.zip') + delete_from_temp('uninstallview64.zip') def download_wiztree(): @@ -475,7 +478,6 @@ def build_kit(): try_print.run('FastCopy...', download_fastcopy) try_print.run('FurMark...', download_furmark) try_print.run('HWiNFO...', download_hwinfo) - try_print.run('IOBit Uninstaller...', download_iobit_uninstaller) try_print.run('LibreOffice...', download_libreoffice) try_print.run('Macs Fan Control...', download_macs_fan_control) try_print.run('Neutron...', download_neutron) @@ -483,6 +485,7 @@ def build_kit(): try_print.run('OpenShell...', download_openshell) try_print.run('PuTTY...', download_putty) try_print.run('Snappy Driver Installer...', download_snappy_driver_installer_origin) + try_print.run('UninstallView...', download_uninstallview) try_print.run('WizTree...', download_wiztree) try_print.run('XMPlay...', download_xmplay) try_print.run('XMPlay Music...', download_xmplay_music) diff --git a/scripts/wk/repairs/win.py b/scripts/wk/repairs/win.py index 975824e5..c0ec2089 100644 --- a/scripts/wk/repairs/win.py +++ b/scripts/wk/repairs/win.py @@ -663,14 +663,6 @@ def auto_hitmanpro(group, name): save_settings(group, name, result=result) -def auto_iobit_uninstaller(group, name): - """Run IO Bit Uninstaller scan.""" - result = TRY_PRINT.run( - 'IO Bit Uninstaller...', run_iobit_uninstaller, msg_good='DONE', - ) - save_settings(group, name, result=result) - - def auto_kvrt(group, name): """Run KVRT scan.""" result = TRY_PRINT.run('KVRT...', run_kvrt, msg_good='DONE') @@ -774,6 +766,14 @@ def auto_system_restore_set_size(group, name): save_settings(group, name, result=result) +def auto_uninstallview(group, name): + """Run UninstallView.""" + result = TRY_PRINT.run( + 'UninstallView...', run_uninstallview, msg_good='DONE', + ) + save_settings(group, name, result=result) + + def auto_windows_updates_disable(group, name): """Disable Windows Updates.""" result = TRY_PRINT.run('Disable Windows Updates...', disable_windows_updates) @@ -963,11 +963,6 @@ def run_hitmanpro(): run_tool('HitmanPro', 'HitmanPro', *cmd_args, download=True) -def run_iobit_uninstaller(): - """Run IO Bit Uninstaller.""" - run_tool('IObitUninstallerPortable', 'IObitUninstallerPortable', cbin=True) - - def run_kvrt(): """Run KVRT scan.""" log_path = format_log_path(log_name='KVRT', timestamp=True, tool=True) @@ -1079,6 +1074,11 @@ def run_tdsskiller(): run_tool('TDSSKiller', 'TDSSKiller', *cmd_args, download=True) +def run_uninstallview(): + """Run UninstallView.""" + run_tool('UninstallView', 'UninstallView') + + # OS Built-in Functions def create_custom_power_plan(enable_sleep=True, keep_display_on=False): """Create new power plan and set as active.""" From 9f52daeec3cb54d2f41f3f8bf5df4b1275bedb80 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 27 Sep 2022 23:48:31 -0700 Subject: [PATCH 04/13] Reduce AutoRepair countdown Addresses issue #197 --- scripts/wk/cfg/repairs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/wk/cfg/repairs.py b/scripts/wk/cfg/repairs.py index d716d3b2..93bdef87 100644 --- a/scripts/wk/cfg/repairs.py +++ b/scripts/wk/cfg/repairs.py @@ -3,7 +3,7 @@ from wk.cfg.main import KIT_NAME_FULL -AUTO_REPAIR_DELAY_IN_SECONDS = 30 +AUTO_REPAIR_DELAY_IN_SECONDS = 3 AUTO_REPAIR_KEY = fr'Software\{KIT_NAME_FULL}\Auto Repairs' BLEACH_BIT_CLEANERS = ( # Applications From 3b89f1eabcbf5cd7a0dbb7118488cc7b0ba8619e Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 27 Sep 2022 23:50:13 -0700 Subject: [PATCH 05/13] Support download referer headers and redirects --- scripts/wk/kit/build_win.py | 6 +++--- scripts/wk/kit/tools.py | 20 ++++++++++++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/scripts/wk/kit/build_win.py b/scripts/wk/kit/build_win.py index b3c4510b..443768f1 100644 --- a/scripts/wk/kit/build_win.py +++ b/scripts/wk/kit/build_win.py @@ -75,10 +75,10 @@ def delete_from_temp(item_path): delete_item(TMP_DIR.joinpath(item_path), force=True, ignore_errors=True) -def download_to_temp(filename, source_url): +def download_to_temp(filename, source_url, referer=None): """Download file to temp dir, returns pathlib.Path.""" out_path = TMP_DIR.joinpath(filename) - download_file(out_path, source_url) + download_file(out_path, source_url, referer=referer) return out_path @@ -209,7 +209,7 @@ def download_fastcopy(): def download_furmark(): """Download FurMark.""" - installer = download_to_temp('FurMark_Setup.exe', SOURCES['FurMark']) + installer = download_to_temp('FurMark_Setup.exe', SOURCES['FurMark'], referer=SOURCES['FurMark']) out_path = BIN_DIR.joinpath('FurMark') tmp_path = TMP_DIR.joinpath('FurMarkInstall') run_program([installer, f'/DIR={tmp_path}', '/SILENT']) diff --git a/scripts/wk/kit/tools.py b/scripts/wk/kit/tools.py index 781d14d6..5edd5f15 100644 --- a/scripts/wk/kit/tools.py +++ b/scripts/wk/kit/tools.py @@ -11,7 +11,7 @@ import requests from wk.cfg.main import ARCHIVE_PASSWORD from wk.cfg.sources import DOWNLOAD_FREQUENCY, SOURCES from wk.exe import popen_program, run_program -from wk.std import GenericError +from wk.std import GenericError, sleep # STATIC VARIABLES @@ -30,7 +30,7 @@ CACHED_DIRS = {} # Functions -def download_file(out_path, source_url, as_new=False, overwrite=False): +def download_file(out_path, source_url, as_new=False, overwrite=False, referer=None): """Download a file using requests, returns pathlib.Path.""" out_path = pathlib.Path(out_path).resolve() name = out_path.name @@ -47,12 +47,24 @@ def download_file(out_path, source_url, as_new=False, overwrite=False): # Create destination directory out_path.parent.mkdir(parents=True, exist_ok=True) + # Update headers + headers = HEADERS.copy() + if referer: + headers['referer'] = referer + # Request download with requests.Session() as session: try: - response = session.get(source_url, headers=HEADERS, stream=True) + response = session.get(source_url, allow_redirects=True, headers=headers, stream=True) except requests.RequestException as _err: - download_failed = _err + try: + sleep(1) + response = session.get(source_url, allow_redirects=True, headers=headers, stream=True) + except requests.RequestException as _err: + download_failed = _err + else: + if not response.ok: + download_failed = response else: if not response.ok: download_failed = response From cafdf42a6d25f8dd5434cc51dff32a628c923d9d Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 27 Sep 2022 23:54:11 -0700 Subject: [PATCH 06/13] Use same log file for full AutoRepairs session --- scripts/wk/log.py | 18 ++++++++++++------ scripts/wk/repairs/win.py | 20 ++++++++++++++++++-- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/scripts/wk/log.py b/scripts/wk/log.py index 2cabd520..b69afb1f 100644 --- a/scripts/wk/log.py +++ b/scripts/wk/log.py @@ -40,7 +40,7 @@ def enable_debug_mode(): def format_log_path( log_dir=None, log_name=None, timestamp=False, - kit=False, tool=False): + kit=False, tool=False, append=False): """Format path based on args passed, returns pathlib.Path obj.""" log_path = pathlib.Path( f'{log_dir if log_dir else DEFAULT_LOG_DIR}/' @@ -54,7 +54,8 @@ def format_log_path( log_path = log_path.resolve() # Avoid clobbering - log_path = non_clobber_path(log_path) + if not append: + log_path = non_clobber_path(log_path) # Done return log_path @@ -121,10 +122,10 @@ def start(config=None): def update_log_path( - dest_dir=None, dest_name=None, keep_history=True, timestamp=True): + dest_dir=None, dest_name=None, keep_history=True, timestamp=True, append=False): """Moves current log file to new path and updates the root logger.""" root_logger = logging.getLogger() - new_path = format_log_path(dest_dir, dest_name, timestamp=timestamp) + new_path = format_log_path(dest_dir, dest_name, timestamp=timestamp, append=append) old_handler = None old_path = get_root_logger_path() os.makedirs(new_path.parent, exist_ok=True) @@ -147,10 +148,15 @@ def update_log_path( new_handler = logging.FileHandler(new_path, mode='a') new_handler.setFormatter(old_handler.formatter) - # Remove old_handler and log if empty + # Remove old_handler root_logger.removeHandler(old_handler) old_handler.close() - remove_empty_log(old_path) + + # Delete orignal log if needed + if keep_history: + remove_empty_log(old_path) + else: + old_path.unlink() # Add new handler root_logger.addHandler(new_handler) diff --git a/scripts/wk/repairs/win.py b/scripts/wk/repairs/win.py index c0ec2089..a1e8fc3f 100644 --- a/scripts/wk/repairs/win.py +++ b/scripts/wk/repairs/win.py @@ -38,7 +38,11 @@ from wk.io import ( rename_item, ) from wk.kit.tools import (download_tool, get_tool_path, run_tool) -from wk.log import format_log_path, update_log_path +from wk.log import ( + format_log_path, + get_root_logger_path, + update_log_path, + ) from wk.os.win import ( OS_VERSION, get_timezone, @@ -277,6 +281,7 @@ def init_run(options): def init_session(options): """Initialize Auto Repairs session.""" reg_set_value('HKCU', AUTO_REPAIR_KEY, 'SessionStarted', 1, 'DWORD') + reg_set_value('HKCU', AUTO_REPAIR_KEY, 'LogName', get_root_logger_path().stem, 'SZ') # Check timezone zone = get_timezone() @@ -347,7 +352,7 @@ def load_settings(menus): def run_auto_repairs(base_menus): """Run Auto Repairs.""" - update_log_path(dest_name='Auto Repairs', timestamp=True) + set_log_path() title = f'{KIT_NAME_FULL}: Auto Repairs' clear_screen() set_title(title) @@ -489,6 +494,17 @@ def save_settings(group, name, result=None, **kwargs): reg_set_value('HKCU', key_path, value_name, data, data_type) +def set_log_path(): + """Set log name using defaults or the saved registry value.""" + try: + log_path = reg_read_value('HKCU', AUTO_REPAIR_KEY, 'LogName') + except FileNotFoundError: + # Ignore and use default values + update_log_path(dest_name='Auto Repairs', timestamp=True) + else: + update_log_path(dest_name=log_path, keep_history=False, timestamp=False, append=True) + + def show_main_menu(base_menus, menus): """Show main menu and handle actions.""" while True: From 82e0de422b3591030855c7d6b9e3232a4ce1c9a7 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 27 Sep 2022 23:56:25 -0700 Subject: [PATCH 07/13] Add export_bitlocker.py script --- scripts/export_bitlocker.py | 11 +++++++++++ scripts/wk/os/win.py | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 scripts/export_bitlocker.py diff --git a/scripts/export_bitlocker.py b/scripts/export_bitlocker.py new file mode 100644 index 00000000..d44ff494 --- /dev/null +++ b/scripts/export_bitlocker.py @@ -0,0 +1,11 @@ +"""WizardKit: Export Bitlocker Tool""" +# vim: sts=2 sw=2 ts=2 + +import os +import sys + +os.chdir(os.path.dirname(os.path.realpath(__file__))) +sys.path.append(os.getcwd()) +import wk # pylint: disable=wrong-import-position + +wk.os.win.export_bitlocker_info() \ No newline at end of file diff --git a/scripts/wk/os/win.py b/scripts/wk/os/win.py index 331d75a4..187289ad 100644 --- a/scripts/wk/os/win.py +++ b/scripts/wk/os/win.py @@ -30,6 +30,7 @@ from wk.std import ( GenericWarning, bytes_to_string, color_string, + input_text, sleep, ) @@ -73,6 +74,7 @@ RAM_OK = 5.5 * 1024**3 # ~6 GiB assuming a bit of shared memory RAM_WARNING = 3.5 * 1024**3 # ~4 GiB assuming a bit of shared memory REG_MSISERVER = r'HKLM\SYSTEM\CurrentControlSet\Control\SafeBoot\Network\MSIServer' SLMGR = pathlib.Path(f'{os.environ.get("SYSTEMROOT")}/System32/slmgr.vbs') +SYSTEMDRIVE = os.environ.get('SYSTEMDRIVE') # Activation Functions @@ -166,6 +168,24 @@ def check_4k_alignment(show_alert=False): raise GenericError('One or more partitions are not 4K aligned') +def export_bitlocker_info(): + """Get Bitlocker info and save to the current directory.""" + commands = [ + ['manage-bde', '-status', SYSTEMDRIVE], + ['manage-bde', '-protectors', '-get', SYSTEMDRIVE], + ] + + # Get filename + file_name = input_text(prompt='Enter filename', allow_empty_response=False) + file_path = pathlib.Path(f'../../Bitlocker_{file_name}.txt').resolve() + + # Save info + with open(file_path, 'a') as _f: + for cmd in commands: + proc = run_program(cmd, check=False) + _f.write(f'{proc.stdout}\n\n') + + def get_installed_antivirus(): """Get list of installed antivirus programs, returns list.""" cmd = [ From 2df0bb504fb0c85590f4691b770a34039db0b896 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 27 Sep 2022 23:58:35 -0700 Subject: [PATCH 08/13] Reorganize kit layout and update launchers --- scripts/wk/cfg/launchers.py | 182 +++++++++++++++++------------------- 1 file changed, 87 insertions(+), 95 deletions(-) diff --git a/scripts/wk/cfg/launchers.py b/scripts/wk/cfg/launchers.py index 9e98d5fb..58e26187 100644 --- a/scripts/wk/cfg/launchers.py +++ b/scripts/wk/cfg/launchers.py @@ -4,42 +4,100 @@ LAUNCHERS = { r'': { # Root Dir - 'Auto Repairs': { + '0) Export BitLocker': { + 'L_TYPE': 'PyScript', + 'L_PATH': 'Scripts', + 'L_ITEM': 'export_bitlocker.py', + 'L_ELEV': 'True', + }, + '1) Auto Repairs': { 'L_TYPE': 'PyScript', 'L_PATH': 'Scripts', 'L_ITEM': 'auto_repairs.py', 'L_ELEV': 'True', }, - 'Auto Setup': { + '2) Windows Updates': { + 'L_TYPE': 'Executable', + 'L_PATH': '.', + 'L_ITEM': 'control', + 'L_ARGS': 'update', + 'L_ELEV': 'True', + }, + '3) Snappy Driver Installer Origin': { + 'L_TYPE': 'Executable', + 'L_PATH': 'SDIO', + 'L_ITEM': 'SDIO.exe', + 'L_ARGS': r'-log_dir "%client_dir%\Logs\Tools"', + }, + '4) Auto Setup': { 'L_TYPE': 'PyScript', 'L_PATH': 'Scripts', 'L_ITEM': 'auto_setup.py', 'L_ELEV': 'True', }, }, - r'Data Recovery': { - 'PhotoRec (CLI)': { + r'Tools': { + 'AIDA64': { 'L_TYPE': 'Executable', - 'L_PATH': 'TestDisk', - 'L_ITEM': 'photorec_win.exe', - 'L_ELEV': 'True', - 'L__CLI': 'True', + 'L_PATH': 'AIDA64', + 'L_ITEM': 'aida64.exe', }, - 'PhotoRec': { + 'Autoruns (with VirusTotal Scan)': { 'L_TYPE': 'Executable', - 'L_PATH': 'TestDisk', - 'L_ITEM': 'qphotorec_win.exe', + 'L_PATH': 'Sysinternals', + 'L_ITEM': 'Autoruns.exe', + 'L_ARGS': '-e', + 'Extra Code': [ + r'reg add HKCU\Software\Sysinternals\AutoRuns /v checkvirustotal /t REG_DWORD /d 1 /f >nul', + r'reg add HKCU\Software\Sysinternals\AutoRuns /v EulaAccepted /t REG_DWORD /d 1 /f >nul', + r'reg add HKCU\Software\Sysinternals\AutoRuns /v shownomicrosoft /t REG_DWORD /d 1 /f >nul', + r'reg add HKCU\Software\Sysinternals\AutoRuns /v shownowindows /t REG_DWORD /d 1 /f >nul', + r'reg add HKCU\Software\Sysinternals\AutoRuns /v showonlyvirustotal /t REG_DWORD /d 1 /f >nul', + r'reg add HKCU\Software\Sysinternals\AutoRuns /v submitvirustotal /t REG_DWORD /d 0 /f >nul', + r'reg add HKCU\Software\Sysinternals\AutoRuns /v verifysignatures /t REG_DWORD /d 1 /f >nul', + r'reg add HKCU\Software\Sysinternals\AutoRuns\SigCheck /v EulaAccepted /t REG_DWORD /d 1 /f >nul', + r'reg add HKCU\Software\Sysinternals\AutoRuns\Streams /v EulaAccepted /t REG_DWORD /d 1 /f >nul', + r'reg add HKCU\Software\Sysinternals\AutoRuns\VirusTotal /v VirusTotalTermsAccepted /t REG_DWORD /d 1 /f >nul', + ], + }, + 'BleachBit': { + 'L_TYPE': 'Executable', + 'L_PATH': 'BleachBit', + 'L_ITEM': 'bleachbit.exe', + }, + 'BlueScreenView': { + 'L_TYPE': 'Executable', + 'L_PATH': 'BlueScreenView', + 'L_ITEM': 'BlueScreenView.exe', + }, + 'ConEmu (as ADMIN)': { + 'L_TYPE': 'Executable', + 'L_PATH': 'ConEmu', + 'L_ITEM': 'ConEmu.exe', 'L_ELEV': 'True', }, - 'TestDisk': { + 'ConEmu': { 'L_TYPE': 'Executable', - 'L_PATH': 'TestDisk', - 'L_ITEM': 'testdisk_win.exe', - 'L_ELEV': 'True', - 'L__CLI': 'True', + 'L_PATH': 'ConEmu', + 'L_ITEM': 'ConEmu.exe', + }, + 'ERUNT': { + 'L_TYPE': 'Executable', + 'L_PATH': 'erunt', + 'L_ITEM': 'ERUNT.EXE', + 'L_ARGS': r'%client_dir%\Backups\Registry\%iso_date% sysreg curuser otherusers', + 'L_ELEV': 'True', + 'Extra Code': [ + r'call "%bin%\Scripts\init_client_dir.cmd" /Logs', + ], + }, + 'Everything': { + 'L_TYPE': 'Executable', + 'L_PATH': 'Everything', + 'L_ITEM': 'Everything.exe', + 'L_ARGS': '-nodb', + 'L_ELEV': 'True', }, - }, - r'Data Transfers': { 'FastCopy (as ADMIN)': { 'L_TYPE': 'Executable', 'L_PATH': 'FastCopy', @@ -137,51 +195,6 @@ LAUNCHERS = { r'call "%bin%\Scripts\init_client_dir.cmd" /Logs /Transfer', ], }, - }, - r'Diagnostics': { - 'AIDA64': { - 'L_TYPE': 'Executable', - 'L_PATH': 'AIDA64', - 'L_ITEM': 'aida64.exe', - }, - 'Autoruns (with VirusTotal Scan)': { - 'L_TYPE': 'Executable', - 'L_PATH': 'Sysinternals', - 'L_ITEM': 'Autoruns.exe', - 'L_ARGS': '-e', - 'Extra Code': [ - r'reg add HKCU\Software\Sysinternals\AutoRuns /v checkvirustotal /t REG_DWORD /d 1 /f >nul', - r'reg add HKCU\Software\Sysinternals\AutoRuns /v EulaAccepted /t REG_DWORD /d 1 /f >nul', - r'reg add HKCU\Software\Sysinternals\AutoRuns /v shownomicrosoft /t REG_DWORD /d 1 /f >nul', - r'reg add HKCU\Software\Sysinternals\AutoRuns /v shownowindows /t REG_DWORD /d 1 /f >nul', - r'reg add HKCU\Software\Sysinternals\AutoRuns /v showonlyvirustotal /t REG_DWORD /d 1 /f >nul', - r'reg add HKCU\Software\Sysinternals\AutoRuns /v submitvirustotal /t REG_DWORD /d 0 /f >nul', - r'reg add HKCU\Software\Sysinternals\AutoRuns /v verifysignatures /t REG_DWORD /d 1 /f >nul', - r'reg add HKCU\Software\Sysinternals\AutoRuns\SigCheck /v EulaAccepted /t REG_DWORD /d 1 /f >nul', - r'reg add HKCU\Software\Sysinternals\AutoRuns\Streams /v EulaAccepted /t REG_DWORD /d 1 /f >nul', - r'reg add HKCU\Software\Sysinternals\AutoRuns\VirusTotal /v VirusTotalTermsAccepted /t REG_DWORD /d 1 /f >nul', - ], - }, - 'BleachBit': { - 'L_TYPE': 'Executable', - 'L_PATH': 'BleachBit', - 'L_ITEM': 'bleachbit.exe', - }, - 'BlueScreenView': { - 'L_TYPE': 'Executable', - 'L_PATH': 'BlueScreenView', - 'L_ITEM': 'BlueScreenView.exe', - }, - 'ERUNT': { - 'L_TYPE': 'Executable', - 'L_PATH': 'erunt', - 'L_ITEM': 'ERUNT.EXE', - 'L_ARGS': r'%client_dir%\Backups\Registry\%iso_date% sysreg curuser otherusers', - 'L_ELEV': 'True', - 'Extra Code': [ - r'call "%bin%\Scripts\init_client_dir.cmd" /Logs', - ], - }, 'FurMark': { 'L_TYPE': 'Executable', 'L_PATH': 'FurMark', @@ -211,31 +224,6 @@ LAUNCHERS = { r')', ], }, - 'Snappy Driver Installer Origin': { - 'L_TYPE': 'Executable', - 'L_PATH': 'SDIO', - 'L_ITEM': 'SDIO.exe', - }, - }, - r'Misc': { - 'ConEmu (as ADMIN)': { - 'L_TYPE': 'Executable', - 'L_PATH': 'ConEmu', - 'L_ITEM': 'ConEmu.exe', - 'L_ELEV': 'True', - }, - 'ConEmu': { - 'L_TYPE': 'Executable', - 'L_PATH': 'ConEmu', - 'L_ITEM': 'ConEmu.exe', - }, - 'Everything': { - 'L_TYPE': 'Executable', - 'L_PATH': 'Everything', - 'L_ITEM': 'Everything.exe', - 'L_ARGS': '-nodb', - 'L_ELEV': 'True', - }, 'Notepad++': { 'L_TYPE': 'Executable', 'L_PATH': 'notepadplusplus', @@ -246,6 +234,17 @@ LAUNCHERS = { 'L_PATH': 'PuTTY', 'L_ITEM': 'PUTTY.EXE', }, + 'Snappy Driver Installer Origin': { + 'L_TYPE': 'Executable', + 'L_PATH': 'SDIO', + 'L_ITEM': 'SDIO.exe', + }, + 'UninstallView': { + 'L_TYPE': 'Executable', + 'L_PATH': 'UninstallView', + 'L_ITEM': 'UninstallView.exe', + 'L_ELEV': 'True', + }, 'WizardKit Debug Console': { 'L_TYPE': 'Executable', 'L_PATH': 'ConEmu', @@ -270,13 +269,6 @@ LAUNCHERS = { 'L_ARGS': r'"%bin%\XMPlay\music.7z"', }, }, - r'Uninstallers': { - 'IObit Uninstaller': { - 'L_TYPE': 'Executable', - 'L_PATH': 'IObitUninstallerPortable', - 'L_ITEM': 'IObitUninstallerPortable.exe', - }, - }, } From e55cc41e2b479326f65f66e020372db761bf1cee Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Wed, 28 Sep 2022 00:00:26 -0700 Subject: [PATCH 09/13] Update the AutoRepairs scheduled task every run This is useful if the kit is being run from a different port and the letter changed between runs. --- scripts/wk/repairs/win.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/scripts/wk/repairs/win.py b/scripts/wk/repairs/win.py index a1e8fc3f..6cdc0bd5 100644 --- a/scripts/wk/repairs/win.py +++ b/scripts/wk/repairs/win.py @@ -162,6 +162,20 @@ def build_menus(base_menus, title): return menus +def update_scheduled_task(): + """Create (or update) scheduled task to start repairs.""" + cmd = [ + 'schtasks', '/create', '/f', + '/sc', 'ONLOGON', + '/tn', f'{KIT_NAME_FULL}-AutoRepairs', + '/rl', 'HIGHEST', + '/tr', fr'C:\Windows\System32\cmd.exe "/C {sys.executable} {sys.argv[0]}"', + ] + if IN_CONEMU: + cmd[-1] = f'{CONEMU_EXE} -run {sys.executable} {sys.argv[0]}' + run_program(cmd) + + def end_session(): """End Auto Repairs session.""" # Remove logon task @@ -254,6 +268,7 @@ def init(menus): def init_run(options): """Initialize Auto Repairs Run.""" + update_scheduled_task() if options['Kill Explorer']['Selected']: atexit.register(start_explorer) TRY_PRINT.run('Killing Explorer...', kill_explorer, msg_good='DONE') @@ -292,18 +307,6 @@ def init_session(options): if zone != WINDOWS_TIME_ZONE and ask(msg): set_timezone(WINDOWS_TIME_ZONE) - # Create logon task for Auto Repairs - cmd = [ - 'schtasks', '/create', '/f', - '/sc', 'ONLOGON', - '/tn', f'{KIT_NAME_FULL}-AutoRepairs', - '/rl', 'HIGHEST', - '/tr', fr'C:\Windows\System32\cmd.exe "/C {sys.executable} {sys.argv[0]}"', - ] - if IN_CONEMU: - cmd[-1] = f'{CONEMU_EXE} -run {sys.executable} {sys.argv[0]}' - run_program(cmd) - # One-time tasks if options['Run TDSSKiller (once)']['Selected']: TRY_PRINT.run('Running TDSSKiller...', run_tdsskiller, msg_good='DONE') From 360266543891e25bd4520b2cf8cf437a19799571 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Wed, 28 Sep 2022 00:01:48 -0700 Subject: [PATCH 10/13] Refactor auto_setup.py Combined the two STATIC VARIABLES sections --- scripts/auto_setup.py | 138 +++++++++++++++++++++--------------------- 1 file changed, 68 insertions(+), 70 deletions(-) diff --git a/scripts/auto_setup.py b/scripts/auto_setup.py index 7a676f94..e61c219e 100644 --- a/scripts/auto_setup.py +++ b/scripts/auto_setup.py @@ -9,7 +9,75 @@ sys.path.append(os.getcwd()) import wk # pylint: disable=wrong-import-position +# Classes +class MenuEntry(): + # pylint: disable=too-few-public-methods + """Simple class to allow cleaner code below.""" + def __init__(self, name, function=None, selected=True, **kwargs): + self.name = name + self.details = { + 'Function': function, + 'Selected': selected, + **kwargs, + } + + # STATIC VARIABLES +BASE_MENUS = { + 'Groups': { + 'Backup Settings': ( + MenuEntry('Backup Browsers', 'auto_backup_browser_profiles'), + MenuEntry('Backup Power Plans', 'auto_backup_power_plans'), + MenuEntry('Reset Power Plans', 'auto_reset_power_plans'), + MenuEntry('Set Custom Power Plan', 'auto_set_custom_power_plan'), + ), + 'Install Software': ( + MenuEntry('Visual C++ Runtimes', 'auto_install_vcredists'), + MenuEntry('Firefox', 'auto_install_firefox'), + MenuEntry('LibreOffice', 'auto_install_libreoffice', selected=False), + MenuEntry('Open Shell', 'auto_install_open_shell'), + MenuEntry('Software Bundle', 'auto_install_software_bundle'), + ), + 'Configure System': ( + MenuEntry('Open Shell', 'auto_config_open_shell'), + MenuEntry('Enable BSoD MiniDumps', 'auto_enable_bsod_minidumps'), + MenuEntry('Enable RegBack', 'auto_enable_regback'), + MenuEntry('Enable System Restore', 'auto_system_restore_enable'), + MenuEntry('Set System Restore Size', 'auto_system_restore_set_size'), + MenuEntry('Enable Windows Updates', 'auto_windows_updates_enable'), + MenuEntry('Windows Activation', 'auto_activate_windows'), + MenuEntry('Windows Explorer', 'auto_config_explorer'), + MenuEntry(r'Windows\Temp Fix', 'auto_windows_temp_fix'), + MenuEntry('Configure Browsers', 'auto_config_browsers'), + MenuEntry('Create System Restore', 'auto_system_restore_create'), + ), + 'System Information': ( + MenuEntry('AIDA64 Report', 'auto_export_aida64_report'), + MenuEntry('Backup Registry', 'auto_backup_registry'), + ), + 'System Summary': ( + MenuEntry('Operating System', 'auto_show_os_name'), + MenuEntry('Windows Activation', 'auto_show_os_activation'), + MenuEntry('Secure Boot', 'auto_show_secure_boot_status'), + MenuEntry('Installed RAM', 'auto_show_installed_ram'), + MenuEntry('Storage Status', 'auto_show_storage_status'), + MenuEntry('Virus Protection', 'auto_show_installed_antivirus'), + MenuEntry('Partitions 4K Aligned', 'auto_show_4k_alignment_check'), + ), + 'Run Programs': ( + MenuEntry('Device Manager', 'auto_open_device_manager'), + MenuEntry('HWiNFO Sensors', 'auto_open_hwinfo_sensors'), + MenuEntry('Windows Activation', 'auto_open_windows_activation'), + MenuEntry('Windows Updates', 'auto_open_windows_updates'), + MenuEntry('XMPlay', 'auto_open_xmplay'), + ), + }, + 'Actions': ( + MenuEntry('Load Preset'), + MenuEntry('Start', Separator=True), + MenuEntry('Quit'), + ), + } PRESETS = { 'Default': {}, # Will be built at runtime using BASE_MENUS 'Additional User': { @@ -86,76 +154,6 @@ PRESETS = { 'Custom': {}, # Will remain empty at runtime } -# Classes -class MenuEntry(): - # pylint: disable=too-few-public-methods - """Simple class to allow cleaner code below.""" - def __init__(self, name, function=None, selected=True, **kwargs): - self.name = name - self.details = { - 'Function': function, - 'Selected': selected, - **kwargs, - } - - -# STATIC VARIABLES -BASE_MENUS = { - 'Groups': { - 'Backup Settings': ( - MenuEntry('Backup Browsers', 'auto_backup_browser_profiles'), - MenuEntry('Backup Power Plans', 'auto_backup_power_plans'), - MenuEntry('Reset Power Plans', 'auto_reset_power_plans'), - MenuEntry('Set Custom Power Plan', 'auto_set_custom_power_plan'), - ), - 'Install Software': ( - MenuEntry('Visual C++ Runtimes', 'auto_install_vcredists'), - MenuEntry('Firefox', 'auto_install_firefox'), - MenuEntry('LibreOffice', 'auto_install_libreoffice', selected=False), - MenuEntry('Open Shell', 'auto_install_open_shell'), - MenuEntry('Software Bundle', 'auto_install_software_bundle'), - ), - 'Configure System': ( - MenuEntry('Configure Browsers', 'auto_config_browsers'), - MenuEntry('Open Shell', 'auto_config_open_shell'), - MenuEntry('Enable BSoD MiniDumps', 'auto_enable_bsod_minidumps'), - MenuEntry('Enable RegBack', 'auto_enable_regback'), - MenuEntry('Enable System Restore', 'auto_system_restore_enable'), - MenuEntry('Set System Restore Size', 'auto_system_restore_set_size'), - MenuEntry('Enable Windows Updates', 'auto_windows_updates_enable'), - MenuEntry('Windows Activation', 'auto_activate_windows'), - MenuEntry('Windows Explorer', 'auto_config_explorer'), - MenuEntry(r'Windows\Temp Fix', 'auto_windows_temp_fix'), - MenuEntry('Create System Restore', 'auto_system_restore_create'), - ), - 'System Information': ( - MenuEntry('AIDA64 Report', 'auto_export_aida64_report'), - MenuEntry('Backup Registry', 'auto_backup_registry'), - ), - 'System Summary': ( - MenuEntry('Operating System', 'auto_show_os_name'), - MenuEntry('Windows Activation', 'auto_show_os_activation'), - MenuEntry('Secure Boot', 'auto_show_secure_boot_status'), - MenuEntry('Installed RAM', 'auto_show_installed_ram'), - MenuEntry('Storage Status', 'auto_show_storage_status'), - MenuEntry('Virus Protection', 'auto_show_installed_antivirus'), - MenuEntry('Partitions 4K Aligned', 'auto_show_4k_alignment_check'), - ), - 'Run Programs': ( - MenuEntry('Device Manager', 'auto_open_device_manager'), - MenuEntry('HWiNFO Sensors', 'auto_open_hwinfo_sensors'), - MenuEntry('Windows Activation', 'auto_open_windows_activation'), - MenuEntry('Windows Updates', 'auto_open_windows_updates'), - MenuEntry('XMPlay', 'auto_open_xmplay'), - ), - }, - 'Actions': ( - MenuEntry('Load Preset'), - MenuEntry('Start', Separator=True), - MenuEntry('Quit'), - ), - } - if __name__ == '__main__': try: From d51bf9fe631bfd773bd5acf3ef950d0a2200f48a Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Wed, 28 Sep 2022 00:02:18 -0700 Subject: [PATCH 11/13] Add presets to AutoRepairs --- scripts/auto_repairs.py | 22 ++++++++---- scripts/wk/repairs/win.py | 70 ++++++++++++++++++++++++++++++++------- 2 files changed, 74 insertions(+), 18 deletions(-) diff --git a/scripts/auto_repairs.py b/scripts/auto_repairs.py index 8d572d07..2d033533 100644 --- a/scripts/auto_repairs.py +++ b/scripts/auto_repairs.py @@ -13,7 +13,7 @@ import wk # pylint: disable=wrong-import-position class MenuEntry(): # pylint: disable=too-few-public-methods """Simple class to allow cleaner code below.""" - def __init__(self, name, function=None, **kwargs): + def __init__(self, name, function=None, selected=True, **kwargs): self.name = name # Color reboot entries @@ -27,7 +27,7 @@ class MenuEntry(): # Set details self.details = { 'Function': function, - 'Selected': True, + 'Selected': selected, **kwargs, } @@ -74,23 +74,33 @@ BASE_MENUS = { ), }, 'Options': ( - MenuEntry('Kill Explorer'), + MenuEntry('Kill Explorer', selected=False), MenuEntry('Run RKill'), MenuEntry('Run TDSSKiller (once)'), MenuEntry('Sync Clock'), - MenuEntry('Use Autologon'), + MenuEntry('Use Autologon', selected=False), ), 'Actions': ( + MenuEntry('Load Preset'), MenuEntry('Options'), MenuEntry('Start', Separator=True), MenuEntry('Quit'), ), } - +PRESETS = { + 'Default': { # Will be expanded at runtime using BASE_MENUS + 'Options': ( + 'Run RKill', + 'Run TDSSKiller (once)', + 'Sync Clock', + ), + }, + 'Custom': {}, # Will remain empty at runtime + } if __name__ == '__main__': try: - wk.repairs.win.run_auto_repairs(BASE_MENUS) + wk.repairs.win.run_auto_repairs(BASE_MENUS, PRESETS) except KeyboardInterrupt: wk.std.abort() except SystemExit: diff --git a/scripts/wk/repairs/win.py b/scripts/wk/repairs/win.py index 6cdc0bd5..2fb22db3 100644 --- a/scripts/wk/repairs/win.py +++ b/scripts/wk/repairs/win.py @@ -87,6 +87,7 @@ GPUPDATE_SUCCESS_STRINGS = ( 'User Policy update has completed successfully.', ) IN_CONEMU = 'ConEmuPID' in os.environ +MENU_PRESETS = Menu() PROGRAMFILES_32 = os.environ.get( 'PROGRAMFILES(X86)', os.environ.get( 'PROGRAMFILES', r'C:\Program Files (x86)', @@ -111,7 +112,7 @@ for error in ('CalledProcessError', 'FileNotFoundError'): # Auto Repairs -def build_menus(base_menus, title): +def build_menus(base_menus, title, presets): """Build menus, returns dict.""" menus = {} menus['Main'] = Menu(title=f'{title}\n{color_string("Main Menu", "GREEN")}') @@ -158,6 +159,22 @@ def build_menus(base_menus, title): sys.modules[__name__], _function, ) + # Update presets + for group, entries in base_menus['Groups'].items(): + presets['Default'][group] = tuple( + entry.name for entry in entries if entry.details['Selected'] + ) + + # Update presets Menu + MENU_PRESETS.title = f'{title}\n{color_string("Load Preset", "GREEN")}' + MENU_PRESETS.add_option('Default') + for name in presets: + MENU_PRESETS.add_option(name) + MENU_PRESETS.add_option('Custom') + MENU_PRESETS.add_action('Main Menu') + MENU_PRESETS.add_action('Quit') + MENU_PRESETS.update() + # Done return menus @@ -238,13 +255,6 @@ def init(menus): """Initialize Auto Repairs.""" session_started = is_session_started() - # Run AVRemover - if not session_started: - TRY_PRINT.run( - 'Run AVRemover...', run_tool, 'AVRemover', 'AVRemover', - download=True, msg_good='DONE', - ) - # Check if autologon is needed if not session_started and is_autologon_enabled(): LOG.warning('Skipping Autologon to preserve current settings.') @@ -308,6 +318,11 @@ def init_session(options): set_timezone(WINDOWS_TIME_ZONE) # One-time tasks + if not session_started: + TRY_PRINT.run( + 'Run AVRemover...', run_tool, 'AVRemover', 'AVRemover', + download=True, msg_good='DONE', + ) if options['Run TDSSKiller (once)']['Selected']: TRY_PRINT.run('Running TDSSKiller...', run_tdsskiller, msg_good='DONE') print('') @@ -344,6 +359,32 @@ def is_session_started(): return session_started +def load_preset(menus, presets, title, enable_menu_exit=True): + """Load menu settings from preset and ask selection question(s).""" + if not enable_menu_exit: + MENU_PRESETS.actions['Main Menu'].update({'Disabled':True, 'Hidden':True}) + + # Get selection + selection = MENU_PRESETS.simple_select() + + # Exit early + if 'Main Menu' in selection: + return + if 'Quit' in selection: + raise SystemExit + + # Load preset + preset = presets[selection[0]] + for group, menu in menus.items(): + group_enabled = group in preset + for name in menu.options: + value = group_enabled and name in preset[group] + menu.options[name]['Selected'] = value + + # Re-enable Main Menu action if disabled + MENU_PRESETS.actions['Main Menu'].update({'Disabled':False, 'Hidden':False}) + + def load_settings(menus): """Load session settings from the registry.""" for group, menu in menus.items(): @@ -353,7 +394,7 @@ def load_settings(menus): menu.options[name].update(get_entry_settings(group, name)) -def run_auto_repairs(base_menus): +def run_auto_repairs(base_menus, presets): """Run Auto Repairs.""" set_log_path() title = f'{KIT_NAME_FULL}: Auto Repairs' @@ -364,7 +405,10 @@ def run_auto_repairs(base_menus): # Generate menus print_standard('Initializing...') - menus = build_menus(base_menus, title) + menus = build_menus(base_menus, title, presets) + + # Get repair preset + load_preset(menus, presets, title, enable_menu_exit=False) # Init try: @@ -376,7 +420,7 @@ def run_auto_repairs(base_menus): # Show Menu if session_started is None or not session_started: try: - show_main_menu(base_menus, menus) + show_main_menu(base_menus, menus, presets, title) except SystemExit: if ask('End session?'): end_session() @@ -508,13 +552,15 @@ def set_log_path(): update_log_path(dest_name=log_path, keep_history=False, timestamp=False, append=True) -def show_main_menu(base_menus, menus): +def show_main_menu(base_menus, menus, presets, title): """Show main menu and handle actions.""" while True: update_main_menu(menus) selection = menus['Main'].simple_select(update=False) if selection[0] in base_menus['Groups'] or selection[0] == 'Options': show_sub_menu(menus[selection[0]]) + if selection[0] == 'Load Preset': + load_preset(menus, presets, title) elif 'Start' in selection: break elif 'Quit' in selection: From 5aa49fe5e53a61ec8956915ceb82654bdd358801 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Wed, 28 Sep 2022 00:07:31 -0700 Subject: [PATCH 12/13] Stomp bugs and typos --- scripts/wk/kit/tools.py | 4 ++-- scripts/wk/log.py | 1 + scripts/wk/os/win.py | 2 +- scripts/wk/repairs/win.py | 13 ++++++------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/wk/kit/tools.py b/scripts/wk/kit/tools.py index 5edd5f15..0d59cb81 100644 --- a/scripts/wk/kit/tools.py +++ b/scripts/wk/kit/tools.py @@ -60,8 +60,8 @@ def download_file(out_path, source_url, as_new=False, overwrite=False, referer=N try: sleep(1) response = session.get(source_url, allow_redirects=True, headers=headers, stream=True) - except requests.RequestException as _err: - download_failed = _err + except requests.RequestException as _err2: + download_failed = _err2 else: if not response.ok: download_failed = response diff --git a/scripts/wk/log.py b/scripts/wk/log.py index b69afb1f..dfa09127 100644 --- a/scripts/wk/log.py +++ b/scripts/wk/log.py @@ -41,6 +41,7 @@ def enable_debug_mode(): def format_log_path( log_dir=None, log_name=None, timestamp=False, kit=False, tool=False, append=False): + # pylint: disable=too-many-arguments """Format path based on args passed, returns pathlib.Path obj.""" log_path = pathlib.Path( f'{log_dir if log_dir else DEFAULT_LOG_DIR}/' diff --git a/scripts/wk/os/win.py b/scripts/wk/os/win.py index 187289ad..a7fa6118 100644 --- a/scripts/wk/os/win.py +++ b/scripts/wk/os/win.py @@ -180,7 +180,7 @@ def export_bitlocker_info(): file_path = pathlib.Path(f'../../Bitlocker_{file_name}.txt').resolve() # Save info - with open(file_path, 'a') as _f: + with open(file_path, 'a', encoding='utf-8') as _f: for cmd in commands: proc = run_program(cmd, check=False) _f.write(f'{proc.stdout}\n\n') diff --git a/scripts/wk/repairs/win.py b/scripts/wk/repairs/win.py index 2fb22db3..01ffd56f 100644 --- a/scripts/wk/repairs/win.py +++ b/scripts/wk/repairs/win.py @@ -318,11 +318,10 @@ def init_session(options): set_timezone(WINDOWS_TIME_ZONE) # One-time tasks - if not session_started: - TRY_PRINT.run( - 'Run AVRemover...', run_tool, 'AVRemover', 'AVRemover', - download=True, msg_good='DONE', - ) + TRY_PRINT.run( + 'Run AVRemover...', run_tool, 'AVRemover', 'AVRemover', + download=True, msg_good='DONE', + ) if options['Run TDSSKiller (once)']['Selected']: TRY_PRINT.run('Running TDSSKiller...', run_tdsskiller, msg_good='DONE') print('') @@ -359,7 +358,7 @@ def is_session_started(): return session_started -def load_preset(menus, presets, title, enable_menu_exit=True): +def load_preset(menus, presets, enable_menu_exit=True): """Load menu settings from preset and ask selection question(s).""" if not enable_menu_exit: MENU_PRESETS.actions['Main Menu'].update({'Disabled':True, 'Hidden':True}) @@ -408,7 +407,7 @@ def run_auto_repairs(base_menus, presets): menus = build_menus(base_menus, title, presets) # Get repair preset - load_preset(menus, presets, title, enable_menu_exit=False) + load_preset(menus, presets, enable_menu_exit=False) # Init try: From 926b32b574d7efdecc98ae373ea55dd9971ed398 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Wed, 28 Sep 2022 00:30:31 -0700 Subject: [PATCH 13/13] Clean badblocks results to remove backspaces --- scripts/wk/cfg/hw.py | 1 + scripts/wk/hw/surface_scan.py | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/scripts/wk/cfg/hw.py b/scripts/wk/cfg/hw.py index 0790cf63..d0d1efb1 100644 --- a/scripts/wk/cfg/hw.py +++ b/scripts/wk/cfg/hw.py @@ -20,6 +20,7 @@ BADBLOCKS_REGEX = re.compile( r'^Pass completed, (\d+) bad blocks found. .(\d+)/(\d+)/(\d+) errors', re.IGNORECASE, ) +BADBLOCKS_RESULTS_REGEX = re.compile(r'^(.*?)\x08.*\x08(.*)') BADBLOCKS_SKIP_REGEX = re.compile(r'^(Checking|\[)', re.IGNORECASE) CPU_CRITICAL_TEMP = 99 CPU_FAILURE_TEMP = 90 diff --git a/scripts/wk/hw/surface_scan.py b/scripts/wk/hw/surface_scan.py index f6452bc5..50e7eecd 100644 --- a/scripts/wk/hw/surface_scan.py +++ b/scripts/wk/hw/surface_scan.py @@ -8,6 +8,7 @@ from subprocess import STDOUT from wk.cfg.hw import ( BADBLOCKS_LARGE_DISK, BADBLOCKS_REGEX, + BADBLOCKS_RESULTS_REGEX, BADBLOCKS_SKIP_REGEX, TEST_MODE_BADBLOCKS_LIMIT, ) @@ -33,6 +34,11 @@ def check_surface_scan_results(test_obj, log_path) -> None: if not line or BADBLOCKS_SKIP_REGEX.match(line): # Skip continue + + # Clean line by removing backspaces/etc + line = BADBLOCKS_RESULTS_REGEX.sub(r'\1 \2', line) + + # Add to report match = BADBLOCKS_REGEX.search(line) if match: if all(s == '0' for s in match.groups()):