If you are able to extract the 15 bytes from positions 0x34
and 0x52
(52-66) in the DigitalProductId
Registry Value as a Hex string, you can use the following Python (Python 3) script to convert the bytes to a Product Key:
import sys
def eprint(s, *args, **kwargs):
sys.stderr.write(s.format(*args, **kwargs) + '\n')
class KeyConv(object):
_alphabet = 'BCDFGHJKMPQRTVWXY2346789'
def __init__(self, val, verbose = False):
self._val = val
self._verbose = verbose
@classmethod
def _int_to_indices(cls, val):
while (val > 0):
yield (val % len(cls._alphabet))
val = val // len(cls._alphabet)
@property
def key(self):
a_idx = list(self._int_to_indices(self._val))
s_key = ''
for i in range(0, (25 - len(a_idx))):
s_key = s_key + self._alphabet[0]
for idx in reversed(a_idx):
s_key = s_key + self._alphabet[idx]
if len(s_key) != 25:
if self._verbose:
eprint('Invalid Product Key length: {} ({}) from 0x{:X}'.format(len(s_key), s_key, self._val))
s_key = s_key[-25:]
chunks_key = (s_key[(5 * pos):((5 * pos) + 5)] for pos in range(0, 5))
return '-'.join(chunks_key)
@classmethod
def from_hex_string(cls, shex, *args, **kwargs):
return cls(int(shex, 16), *args, **kwargs)
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(description="""Decode a Windows Registry value to the corresponding Product Key""")
parser.add_argument(dest='hexstring', help="""The hex string to decode (from the Registry)""", metavar='STRING')
parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', help="""Output more information about conversion""")
args = parser.parse_args()
k = KeyConv.from_hex_string(''.join(args.hexstring.split()).replace(',', '').replace('\\', ''), args.verbose)
print(k.key)
Sample run:
> python3 key-conv.py -v "A2 23 51 D0 2A 38 5D 22 C4 41 6B 87 43 C1 00"
Invalid Product Key length: 27 (CDKHCQQBBCW2TT7QRF42M6V3YQY) from 0xA22351D02A385D22C4416B8743C100
KHCQQ-BBCW2-TT7QR-F42M6-V3YQY
You can see the details about where to find the DigitalProductId
Value in another answer, but essentially, look in the Registry Key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
If you cannot access an interface to the machine, but can access the filesystem, find the Registry Hive at:
%WinDir%\system32\config\software
If you are having trouble extracting the data, you can Export the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
Key and then open the resulting .reg
file. If I wanted to expand the script, I could add a Registry or .reg
file extraction routine.