-
Notifications
You must be signed in to change notification settings - Fork 5
/
signtool.py
73 lines (61 loc) · 2.16 KB
/
signtool.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from pathlib import Path
import urllib.request
import json
import shutil
import subprocess
DOWNLOADS = Path("Downloads")
RELEASES = Path("Releases")
def download(url):
with urllib.request.urlopen(url) as resp:
return resp.read()
# super crappy msi format parser just to find required .cab files
def get_msi_cabs(msi):
index = 0
while True:
index = msi.find(b".cab", index+4)
if index < 0:
return
yield msi[index-32:index+4].decode("ascii")
def get_sub_dirs(path):
return [x for x in path.iterdir() if x.is_dir()]
MANIFEST_URL = "https://aka.ms/vs/17/release/channel"
print("Checking Visual Studio Manifest...")
chman = json.loads(download(MANIFEST_URL))
vsman_url = chman["channelItems"][0]["payloads"][0]["url"]
license = chman["channelItems"][1]["localizedResources"][0]["license"]
vsman = json.loads(download(vsman_url))
packages = vsman["packages"]
version = ""
payloads = []
for i in range(len(packages)-1, -1, -1):
if packages[i]["id"].startswith("Win11SDK_10.0."):
version = packages[i]["version"]
payloads = packages[i]["payloads"]
break
def download_payload(filename):
for p in payloads:
if p["fileName"] == "Installers\\" + filename:
data = download(p["url"])
with open(DOWNLOADS / filename, "wb") as file:
file.write(data)
return data
yes = input(f"Do you accept Microsoft Visual Studio license: {license} [Y/N] ? ")
if yes.upper() not in ["", "YES", "Y"]:
exit(0)
MSI_FILENAME = "Windows SDK Signing Tools-x86_en-us.msi"
print(f"Downloading {MSI_FILENAME}...")
DOWNLOADS.mkdir(exist_ok=True)
msi = download_payload(MSI_FILENAME)
cabs = get_msi_cabs(msi)
for cab in cabs:
download_payload(cab)
print(f"Unpacking {MSI_FILENAME}...")
ARCHIVES = DOWNLOADS / "Archives"
shutil.rmtree(ARCHIVES, ignore_errors=True)
subprocess.run(["msiexec.exe", "/a", DOWNLOADS / MSI_FILENAME, "/quiet", "/qn", f"TARGETDIR={ARCHIVES.resolve()}"])
print(f"Creating Zip in {RELEASES.resolve()}...")
SDK = get_sub_dirs(ARCHIVES / "Windows Kits/10/bin")[0]
ARCHS = get_sub_dirs(SDK)
for arch in ARCHS:
shutil.make_archive(RELEASES / f"SignTool-{version}-{arch.name}", "zip", arch)
print("Done!")