Skip to content

Commit 2aa7672

Browse files
committed
signtool.py: add python script to build releases
1 parent 2972ab6 commit 2aa7672

3 files changed

Lines changed: 77 additions & 0 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Downloads/
2+
Releases/

signtool.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
python signtool.py
2+
pause

signtool.py

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

0 commit comments

Comments
 (0)