Added SafeMode enter/exit sections

This commit is contained in:
2Shirt 2019-09-15 18:47:52 -07:00
parent 78e3765730
commit b41027562a
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
17 changed files with 136 additions and 92 deletions

View file

@ -1,39 +0,0 @@
# Wizard Kit: Enter SafeMode by editing the BCD
import os
import sys
# Init
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
from functions.safemode import *
init_global_vars()
os.system('title {}: SafeMode Tool'.format(KIT_NAME_FULL))
if __name__ == '__main__':
try:
clear_screen()
print_info('{}: SafeMode Tool\n'.format(KIT_NAME_FULL))
other_results = {
'Error': {'CalledProcessError': 'Unknown Error'},
'Warning': {}}
if not ask('Enable booting to SafeMode (with Networking)?'):
abort()
# Configure SafeMode
try_and_print(message='Set BCD option...',
function=enable_safemode, other_results=other_results)
try_and_print(message='Enable MSI in SafeMode...',
function=enable_safemode_msi, other_results=other_results)
# Done
print_standard('\nDone.')
pause('Press Enter to reboot...')
reboot()
exit_script()
except SystemExit as sys_exit:
exit_script(sys_exit.code)
except:
major_exception()
# vim: sts=2 sw=2 ts=2

View file

@ -1,39 +0,0 @@
# Wizard Kit: Exit SafeMode by editing the BCD
import os
import sys
# Init
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
from functions.safemode import *
init_global_vars()
os.system('title {}: SafeMode Tool'.format(KIT_NAME_FULL))
if __name__ == '__main__':
try:
clear_screen()
print_info('{}: SafeMode Tool\n'.format(KIT_NAME_FULL))
other_results = {
'Error': {'CalledProcessError': 'Unknown Error'},
'Warning': {}}
if not ask('Disable booting to SafeMode?'):
abort()
# Configure SafeMode
try_and_print(message='Remove BCD option...',
function=disable_safemode, other_results=other_results)
try_and_print(message='Disable MSI in SafeMode...',
function=disable_safemode_msi, other_results=other_results)
# Done
print_standard('\nDone.')
pause('Press Enter to reboot...')
reboot()
exit_script()
except SystemExit as sys_exit:
exit_script(sys_exit.code)
except:
major_exception()
# vim: sts=2 sw=2 ts=2

37
scripts/safemode_enter.py Normal file
View file

@ -0,0 +1,37 @@
"""Wizard Kit: Enter SafeMode by editing the BCD"""
# vim: sts=2 sw=2 ts=2
import wk
def main():
"""Prompt user to enter safe mode."""
title = f'{wk.cfg.main.KIT_NAME_FULL}: SafeMode Tool'
try_print = wk.std.TryAndPrint()
wk.std.clear_screen()
wk.std.set_title(title)
wk.std.print_info(title)
print('')
# Ask
if not wk.std.ask('Enable booting to SafeMode (with Networking)?'):
wk.std.abort()
print('')
# Configure SafeMode
try_print.run('Set BCD option...', wk.os.win.enable_safemode)
try_print.run('Enable MSI in SafeMode...', wk.os.win.enable_safemode_msi)
# Done
print('Done.')
wk.std.pause('Press Enter to reboot...')
wk.std.run_program('shutdown -r -t 3'.split(), check=False)
if __name__ == '__main__':
try:
main()
except SystemExit:
raise
except: #pylint: disable=bare-except
wk.std.major_exception()

37
scripts/safemode_exit.py Normal file
View file

@ -0,0 +1,37 @@
"""Wizard Kit: Exit SafeMode by editing the BCD"""
# vim: sts=2 sw=2 ts=2
import wk
def main():
"""Prompt user to exit safe mode."""
title = f'{wk.cfg.main.KIT_NAME_FULL}: SafeMode Tool'
try_print = wk.std.TryAndPrint()
wk.std.clear_screen()
wk.std.set_title(title)
wk.std.print_info(title)
print('')
# Ask
if not wk.std.ask('Disable booting to SafeMode?'):
wk.std.abort()
print('')
# Configure SafeMode
try_print.run('Remove BCD option...', wk.os.win.disable_safemode)
try_print.run('Disable MSI in SafeMode...', wk.os.win.disable_safemode_msi)
# Done
print('Done.')
wk.std.pause('Press Enter to reboot...')
wk.std.run_program('shutdown -r -t 3'.split(), check=False)
if __name__ == '__main__':
try:
main()
except SystemExit:
raise
except: #pylint: disable=bare-except
wk.std.major_exception()

View file

@ -1,4 +1,4 @@
'''WizardKit: wk module init'''
"""WizardKit: wk module init"""
# vim: sts=2 sw=2 ts=2
from sys import version_info as version

View file

@ -1,4 +1,4 @@
'''WizardKit: cfg module init'''
"""WizardKit: cfg module init"""
from wk.cfg import log
from wk.cfg import main

View file

@ -1,4 +1,4 @@
'''WizardKit: Config - Log'''
"""WizardKit: Config - Log"""
# vim: sts=2 sw=2 ts=2

View file

@ -1,6 +1,6 @@
'''WizardKit: Config - Main
"""WizardKit: Config - Main
NOTE: A non-standard format is used for BASH/BATCH/PYTHON compatibility'''
NOTE: A non-standard format is used for BASH/BATCH/PYTHON compatibility"""
# pylint: disable=bad-whitespace
# vim: sts=2 sw=2 ts=2

View file

@ -1,4 +1,4 @@
'''WizardKit: Config - Net'''
"""WizardKit: Config - Net"""
# vim: sts=2 sw=2 ts=2

View file

@ -1 +1 @@
'''WizardKit: hw module init'''
"""WizardKit: hw module init"""

View file

@ -1,4 +1,4 @@
'''WizardKit: I/O Functions'''
"""WizardKit: I/O Functions"""
# vim: sts=2 sw=2 ts=2
import os

View file

@ -1 +1 @@
'''WizardKit: kit module init'''
"""WizardKit: kit module init"""

View file

@ -1,4 +1,4 @@
'''WizardKit: Log Functions'''
"""WizardKit: Log Functions"""
# vim: sts=2 sw=2 ts=2
import atexit

View file

@ -1 +1,7 @@
'''WizardKit: os module init'''
"""WizardKit: os module init"""
# vim: sts=2 sw=2 ts=2
import os
if os.name == 'nt':
from wk.os import win

42
scripts/wk/os/win.py Normal file
View file

@ -0,0 +1,42 @@
"""WizardKit: Windows Functions"""
# vim: sts=2 sw=2 ts=2
from wk.std import run_program
# STATIC VARIABLES
REG_MSISERVER = r'HKLM\SYSTEM\CurrentControlSet\Control\SafeBoot\Network\MSIServer'
# Functions
def disable_safemode():
"""Edit BCD to remove safeboot value."""
cmd = ['bcdedit', '/deletevalue', '{default}', 'safeboot']
run_program(cmd)
def disable_safemode_msi():
"""Disable MSI access under safemode."""
cmd = ['reg', 'delete', REG_MSISERVER, '/f']
run_program(cmd)
def enable_safemode():
"""Edit BCD to set safeboot as default."""
cmd = ['bcdedit', '/set', '{default}', 'safeboot', 'network']
run_program(cmd)
def enable_safemode_msi():
"""Enable MSI access under safemode."""
cmd = ['reg', 'add', REG_MSISERVER, '/f']
run_program(cmd)
cmd = [
'reg', 'add', REG_MSISERVER, '/ve',
'/t', 'REG_SZ',
'/d', 'Service', '/f',
]
run_program(cmd)
if __name__ == '__main__':
print("This file is not meant to be called directly.")

View file

@ -1,4 +1,4 @@
'''WizardKit: Standard Functions'''
"""WizardKit: Standard Functions"""
# pylint: disable=too-many-lines
# vim: sts=2 sw=2 ts=2
@ -476,7 +476,7 @@ class TryAndPrint():
if exception_name not in self.list_warnings:
self.list_warnings.append(exception_name)
def run_function(
def run(
self, message, function, *args,
catch_all=True, print_return=False, verbose=False, **kwargs):
# pylint: disable=catching-non-exception

View file

@ -1 +1 @@
'''WizardKit: sw module init'''
"""WizardKit: sw module init"""