forked from Vector35/binaryninja-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverify_hashes.py
executable file
·34 lines (29 loc) · 1 KB
/
verify_hashes.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
#!/usr/bin/env python3
'''Simple script to verify SHA256 hashes and rename downloaded versions with their version number'''
import json
import requests
import hashlib
from pathlib import Path
class DownloadException(Exception):
pass
def sha256(path):
with open(filename,"rb") as f:
return hashlib.sha256(f.read()).hexdigest()
url = 'https://binary.ninja/js/hashes.json'
r = requests.get(url)
results = json.loads(r.text)
if not results['version']:
raise DownloadException('Hash file does not exist or is incomplete.')
version = results["version"]
for filename in results["hashes"]:
hash = results["hashes"][filename]
binfile = Path(filename)
if binfile.is_file():
if sha256(binfile) == hash:
newname = f"{filename[0:-4]}-{version}{filename[-4:]}"
print(f"SHA256 matches for {filename}, renaming to {newname}")
binfile.rename(newname)
else:
print(f"HASH FAILED for {filename}")
else:
print(f"No {filename} found")