diff options
| author | awuctl | 2022-08-23 16:48:54 +0000 |
|---|---|---|
| committer | awuctl | 2022-08-23 16:48:54 +0000 |
| commit | 840fb76d797319ca0542dccc92a08feb1e9a8264 (patch) | |
| tree | a22723328b0a0de267898a86ac6dd55bd6f42b82 /hwid_extract.py | |
| download | hwid-stuff-840fb76d797319ca0542dccc92a08feb1e9a8264.zip | |
initial commit
Diffstat (limited to 'hwid_extract.py')
| -rwxr-xr-x | hwid_extract.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/hwid_extract.py b/hwid_extract.py new file mode 100755 index 0000000..f3f5433 --- /dev/null +++ b/hwid_extract.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python + +from functools import reduce +import xml.etree.ElementTree as ET + +from base64 import b64decode + +class Ticket: + @staticmethod + def get_properties(genAuth: ET.Element) -> str: + properties = genAuth.find('./{*}genuineProperties/{*}properties') + return properties.text + + @staticmethod + def split_keyval(x: str) -> dict: + parameters = {} + + for params in x.split(';'): + if not params or params == '\x00': + break + key_val = params.split('=') + parameters[key_val[0]] = key_val[1] + return parameters + + @staticmethod + def get_hwid(genAuth: ET.Element) -> str: + props = Ticket.split_keyval(Ticket.get_properties(genAuth)) + params = Ticket.split_keyval(b64decode(props['SessionId'] + '===').decode('utf-16')) + + return params['Hwid'] + +if __name__ == '__main__': + import argparse + + main_parser = argparse.ArgumentParser( + 'hwid_extract', + description='Extract the binary hardware id from ticket' + ) + main_parser.add_argument('input', type=argparse.FileType('rb')) + main_parser.add_argument('output', type=argparse.FileType('wb'), nargs='?') + args = main_parser.parse_args() + + ticket = ET.parse(args.input).getroot() + hwid = Ticket.get_hwid(ticket) + + hwid_block = b64decode(hwid + '===') + if args.output is None: + print(hwid_block) + else: + args.output.write(hwid_block)
\ No newline at end of file |
