-
Notifications
You must be signed in to change notification settings - Fork 3
/
verif.py
95 lines (68 loc) · 2.16 KB
/
verif.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# -*- coding: utf-8 -*-
#this file is a lobotomy of squirell.py, taken from NSCB.
#i basically removed entire parts of its code until i was left only with a verification routine, which i patched up a bit because code quality in the original squirrel.py is horrendous.
#usage: .venv/bin/python verif.py "file"
import argparse
import sys
import os
# import urllib3
os.chdir(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, 'lib')
try:
sys.path.insert(0, 'private')
except:pass
import Config
import Status
# # SET ENVIRONMENT
# squirrel_dir=os.path.abspath(os.curdir)
# NSCB_dir=os.path.abspath('../'+(os.curdir))
def verify(file):
try:
# urllib3.disable_warnings()
parser = argparse.ArgumentParser()
parser.add_argument('file',nargs='*')
Status.start()
import Fs
filename = file
# filename = "/home/themoon/Downloads/Cult_of_the_Lamb_-_Cult_of_the_Lamb_-_Cthulhu_Follower_Form_01002E7016C47001v0DLC(1).nsz"
dir=os.path.dirname(os.path.abspath(filename))
tmpfolder =os.path.join(dir,'tmp')
feed=''
buffer = 65536
if filename.lower().endswith(('.nsp','.nsz')):
f = Fs.Nsp(filename)
elif filename.lower().endswith('.xci'):
f = Fs.factory(filename)
f.open(filename, 'rb')
elif filename.lower().endswith('.xcz'):
f = Fs.Xci(filename)
else:
raise Exception("{1} does not have the appropriate extension".format(filename))
check,feed=f.verify()
if check == False:
f.flush()
f.close()
return False
verdict,headerlist,feed=f.verify_sig(feed,tmpfolder)
if verdict == False:
f.flush()
f.close()
return False
print(filename)
if filename.endswith('.nsz'):
verdict,feed=f.nsz_hasher(buffer,headerlist,verdict,feed)
elif filename.endswith('.xcz'):
verdict,feed=f.xcz_hasher(buffer,headerlist,verdict,feed)
else:
verdict,feed=f.verify_hash_nca(buffer,headerlist,verdict,feed)
f.flush()
f.close()
Status.close()
return verdict
except KeyboardInterrupt:
Config.isRunning = False
Status.close()
except BaseException as e:
Config.isRunning = False
Status.close()
raise e