add exe integrity selfcheck

This commit is contained in:
ed 2023-02-21 19:18:10 +00:00
parent 6deaf5c268
commit cedaf4809f
2 changed files with 31 additions and 0 deletions

View file

@ -96,4 +96,9 @@ $APPDATA/python/python$pyv/scripts/pyinstaller \
# ./upx.exe --best --ultra-brute --lzma -k dist/copyparty.exe
printf $(sha512sum ~/Downloads/dist/copyparty.exe | head -c 18 | sed -r 's/(..)/\\x\1/g') |
base64 | head -c12 >> dist/copyparty.exe
dist/copyparty.exe --version
curl -fkT dist/copyparty.exe -b cppwd=wark https://192.168.123.1:3923/copyparty$m.exe

View file

@ -1,5 +1,7 @@
# coding: utf-8
import base64
import hashlib
import os
import re
import shutil
@ -46,6 +48,30 @@ def confirm(rv):
sys.exit(rv or 1)
def ckck():
hs = hashlib.sha512()
with open(sys.executable, "rb") as f:
f.seek(-12, 2)
rem = f.tell()
esum = f.read().decode("ascii", "replace")
f.seek(0)
while rem:
buf = f.read(min(rem, 64 * 1024))
rem -= len(buf)
hs.update(buf)
if not buf:
t = "unexpected eof @ {} with {} left"
raise Exception(t.format(f.tell(), rem))
fsum = base64.b64encode(hs.digest()[:9]).decode("utf-8")
if fsum != esum:
t = "exe integrity check error; [{}] != [{}]"
raise Exception(t.format(esum, fsum))
ckck()
def meicln(mod):
pdir, mine = os.path.split(mod)
dirs = os.listdir(pdir)