Created
September 8, 2019 22:04
-
-
Save moriyoshi/f08d5f8feeb7509e51d6cfe7d1e8ef98 to your computer and use it in GitHub Desktop.
Recover a XP product key from the registry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
# HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId | |
# offset from 28 (0x1c) to 43 (0x2b) | |
b = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] | |
digits = "BCDFGHJKMPQRTVWXY2346789" | |
def base24(b): | |
v = sum((256 ** i) * c for i, c in enumerate(b)) | |
for _ in range(int(math.ceil(math.log(256) * len(b) / math.log(24)))): | |
yield digits[v % 24] | |
v //= 24 | |
print(''.join(('-' if i % 5 == 0 else '') + c for i, c in enumerate(reversed(list(base24(b))[:25])))[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment