Skip to content

Commit 16e8aa3

Browse files
committed
Merge branch 'drmext/master' #1
2 parents b9e2db9 + edfbc65 commit 16e8aa3

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

kg.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1+
import argparse
12
import re
2-
import sys
33
from random import randint
4-
from typing import List
54

65
from cryptography.hazmat.backends import default_backend
76
from cryptography.hazmat.primitives.asymmetric import dsa
87
from cryptography.hazmat.primitives.asymmetric.utils import decode_dss_signature
98
from cryptography.hazmat.primitives.hashes import SHA1
109

10+
parser = argparse.ArgumentParser()
11+
parser.add_argument("-i", "--hwid", help="Your hardware code", required=True)
12+
parser.add_argument("-o", "--output", help="Authorization file", default="Authorize.auz")
13+
parser.add_argument("-v", "--version", help="Ableton Live version", type=int, choices=range(9, 13), default=12)
14+
args = parser.parse_args()
15+
1116

1217
def construct_key(*, p, q, g, y, x) -> dsa.DSAPrivateKey:
1318
params = dsa.DSAParameterNumbers(p, q, g)
@@ -34,7 +39,7 @@ def fix_group_checksum(group_number: int, n: int) -> int:
3439
return n & 0xfff0 | checksum
3540

3641

37-
def overall_checksum(groups: List[int]) -> int:
42+
def overall_checksum(groups: list[int]) -> int:
3843
r = 0
3944
for i in range(20):
4045
g, digit = divmod(i, 4)
@@ -74,8 +79,12 @@ def generate_single(k: dsa.DSAPrivateKey, id1: int, id2: int, hwid: str) -> str:
7479
return f.format(serial, id1, id2, sig)
7580

7681

77-
def generate_all(k: dsa.DSAPrivateKey, hwid: str) -> str:
78-
yield generate_single(k, 0x0, 0xb0, hwid)
82+
def generate_all(k: dsa.DSAPrivateKey, hwid: str, version: int) -> str:
83+
ident = { 9: 0x90,
84+
10: 0xa0,
85+
11: 0xb0,
86+
12: 0xc0}
87+
yield generate_single(k, 0x0, ident[version], hwid)
7988
for i in range(0x40, 0xff + 1):
8089
yield generate_single(k, i, 0x10, hwid)
8190
for i in range(0x8000, 0x80ff + 1):
@@ -90,9 +99,11 @@ def generate_all(k: dsa.DSAPrivateKey, hwid: str) -> str:
9099
x=0xc369ea757b46484d1df3819cc4183f6f9a9bcf3c
91100
)
92101

93-
assert len(sys.argv) == 2, "Expected hardware ID as command line argument"
94-
hwid = sys.argv[1].upper()
95-
assert re.fullmatch(r"([0-9A-F]{4}-){5}[0-9A-F]{4}", hwid), "Expected hardware ID like 1111-1111-1111-1111-1111-1111"
102+
hwid = args.hwid.upper()
103+
if len(hwid) == 24:
104+
hwid = "-".join((hwid[:4], hwid[4:8], hwid[8:12], hwid[12:16], hwid[16:20], hwid[20:]))
105+
assert re.fullmatch(r"([0-9A-F]{4}-){5}[0-9A-F]{4}", hwid), f"Expected hardware ID like 1111-1111-1111-1111-1111-1111, not {hwid}"
96106

97-
for line in generate_all(team_r2r_key, hwid):
98-
print(line)
107+
lines = generate_all(team_r2r_key, hwid, args.version)
108+
with open(args.output, mode="w", newline="\n") as f:
109+
f.write("\n".join(lines))

0 commit comments

Comments
 (0)