-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdumpbin.py
More file actions
59 lines (49 loc) · 1.84 KB
/
dumpbin.py
File metadata and controls
59 lines (49 loc) · 1.84 KB
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
from pathlib import Path
import urllib.request
import json
import re
import shutil
import zipfile
DOWNLOADS = Path("Downloads")
RELEASES = Path("Releases")
def download(url):
with urllib.request.urlopen(url) as resp:
return resp.read()
def get_sub_dirs(path):
return [x for x in path.iterdir() if x.is_dir()]
MANIFEST_URL = "https://aka.ms/vs/stable/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 = ""
filename = ""
url = ""
for i in range(len(packages)-1, -1, -1):
if re.fullmatch(r"Microsoft.VC.[\d.]+.Tools.HostX64.TargetX64.base", packages[i]["id"]):
version = packages[i]["version"]
filename = packages[i]["payloads"][0]["fileName"]
url = packages[i]["payloads"][0]["url"]
break
yes = input(f"Do you accept Microsoft Visual Studio license: {license} [Y/N] ? ")
if yes.upper() not in ["", "YES", "Y"]:
exit(0)
print(f"Downloading {filename}...")
DOWNLOADS.mkdir(exist_ok=True)
with open(DOWNLOADS / filename, "wb") as file:
file.write(download(url))
print(f"Unpacking {filename}...")
ARCHIVES = DOWNLOADS / "Archives"
shutil.rmtree(ARCHIVES, ignore_errors=True)
shutil.unpack_archive(DOWNLOADS / filename, ARCHIVES, "zip")
print(f"Creating Zip in {RELEASES.resolve()}...")
BIN = get_sub_dirs(ARCHIVES / "Contents/VC/Tools/MSVC")[0] / "bin/Hostx64/x64"
RELEASES.mkdir(exist_ok=True)
files = ["dumpbin.exe", "link.exe", "link.exe.config", "tbbmalloc.dll", "mspdbcore.dll"]
with zipfile.ZipFile(RELEASES / f"dumpbin-{version}-x64.zip", "w", zipfile.ZIP_DEFLATED) as z:
for f in files:
path = BIN / f
z.write(path, path.name)
print("Done!")