Updated activation.py
This commit is contained in:
parent
765673db66
commit
36e419bca0
1 changed files with 46 additions and 44 deletions
|
|
@ -10,57 +10,59 @@ from os import environ
|
||||||
SLMGR = r'{}\System32\slmgr.vbs'.format(environ.get('SYSTEMROOT'))
|
SLMGR = r'{}\System32\slmgr.vbs'.format(environ.get('SYSTEMROOT'))
|
||||||
|
|
||||||
def activate_with_bios():
|
def activate_with_bios():
|
||||||
"""Attempt to activate Windows with a key stored in the BIOS."""
|
"""Attempt to activate Windows with a key stored in the BIOS."""
|
||||||
# Code borrowed from https://github.com/aeruder/get_win8key
|
# Code borrowed from https://github.com/aeruder/get_win8key
|
||||||
#####################################################
|
#####################################################
|
||||||
#script to query windows 8.x OEM key from PC firmware
|
#script to query windows 8.x OEM key from PC firmware
|
||||||
#ACPI -> table MSDM -> raw content -> byte offset 56 to end
|
#ACPI -> table MSDM -> raw content -> byte offset 56 to end
|
||||||
#ck, 03-Jan-2014 (christian@korneck.de)
|
#ck, 03-Jan-2014 (christian@korneck.de)
|
||||||
#####################################################
|
#####################################################
|
||||||
bios_key = None
|
bios_key = None
|
||||||
table = b"MSDM"
|
table = b"MSDM"
|
||||||
if acpi.FindAcpiTable(table) is True:
|
if acpi.FindAcpiTable(table) is True:
|
||||||
rawtable = acpi.GetAcpiTable(table)
|
rawtable = acpi.GetAcpiTable(table)
|
||||||
#http://msdn.microsoft.com/library/windows/hardware/hh673514
|
#http://msdn.microsoft.com/library/windows/hardware/hh673514
|
||||||
#byte offset 36 from beginning \
|
#byte offset 36 from beginning \
|
||||||
# = Microsoft 'software licensing data structure' \
|
# = Microsoft 'software licensing data structure' \
|
||||||
# / 36 + 20 bytes offset from beginning = Win Key
|
# / 36 + 20 bytes offset from beginning = Win Key
|
||||||
bios_key = rawtable[56:len(rawtable)].decode("utf-8")
|
bios_key = rawtable[56:len(rawtable)].decode("utf-8")
|
||||||
if bios_key is None:
|
if bios_key is None:
|
||||||
raise BIOSKeyNotFoundError
|
raise BIOSKeyNotFoundError
|
||||||
|
|
||||||
# Install Key
|
# Install Key
|
||||||
cmd = ['cscript', '//nologo', SLMGR, '/ipk', bios_key]
|
cmd = ['cscript', '//nologo', SLMGR, '/ipk', bios_key]
|
||||||
subprocess.run(cmd, check=False)
|
subprocess.run(cmd, check=False)
|
||||||
sleep(5)
|
sleep(5)
|
||||||
|
|
||||||
# Attempt activation
|
# Attempt activation
|
||||||
cmd = ['cscript', '//nologo', SLMGR, '/ato']
|
cmd = ['cscript', '//nologo', SLMGR, '/ato']
|
||||||
subprocess.run(cmd, check=False)
|
subprocess.run(cmd, check=False)
|
||||||
sleep(5)
|
sleep(5)
|
||||||
|
|
||||||
# Check status
|
# Check status
|
||||||
if not windows_is_activated():
|
if not windows_is_activated():
|
||||||
raise Exception('Activation Failed')
|
raise Exception('Activation Failed')
|
||||||
|
|
||||||
def get_activation_string():
|
def get_activation_string():
|
||||||
"""Get activation status, returns str."""
|
"""Get activation status, returns str."""
|
||||||
act_str = subprocess.run(
|
act_str = subprocess.run(
|
||||||
['cscript', '//nologo', SLMGR, '/xpr'], check=False,
|
['cscript', '//nologo', SLMGR, '/xpr'], check=False,
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
act_str = act_str.stdout.decode()
|
act_str = act_str.stdout.decode()
|
||||||
act_str = act_str.splitlines()
|
act_str = act_str.splitlines()
|
||||||
act_str = act_str[1].strip()
|
act_str = act_str[1].strip()
|
||||||
return act_str
|
return act_str
|
||||||
|
|
||||||
def windows_is_activated():
|
def windows_is_activated():
|
||||||
"""Check if Windows is activated via slmgr.vbs and return bool."""
|
"""Check if Windows is activated via slmgr.vbs and return bool."""
|
||||||
activation_string = subprocess.run(
|
activation_string = subprocess.run(
|
||||||
['cscript', '//nologo', SLMGR, '/xpr'], check=False,
|
['cscript', '//nologo', SLMGR, '/xpr'], check=False,
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
activation_string = activation_string.stdout.decode()
|
activation_string = activation_string.stdout.decode()
|
||||||
|
|
||||||
return bool(activation_string and 'permanent' in activation_string)
|
return bool(activation_string and 'permanent' in activation_string)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print("This file is not meant to be called directly.")
|
print("This file is not meant to be called directly.")
|
||||||
|
|
||||||
|
# vim: sts=2 sw=2 ts=2
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue