Skip to content

Commit 1a2036a

Browse files
author
lolololol
committed
model loader fix: local models
1 parent a4b90f8 commit 1a2036a

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

lib/sparkgap/attack.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,21 @@
66
import importlib.machinery
77
import importlib.util
88

9+
if "SPARKGAP_MDLDIR" in os.environ.keys():
10+
ENV_MDLDIR = os.environ["SPARKGAP_MDLDIR"]
11+
else:
12+
ENV_MDLDIR = "models"
13+
14+
CFG_KNOWNATTACKS = ["AES_LastRound_HD","AES_LastRound_HW","AES_SboxOutMasked_HW","AES_SboxOut_HD","AES_SboxOut_HW","AES_SboxOut_LSB","AES_TTableOut_HW","DES_SboxOut_HW","Keeloq","XorOut_HD","XorOut_HW"]
915
# ['attacks/__init__.py', 'attacks/AES_SboxOut_HW.py', 'attacks/DES_SboxOut_HW.py', 'attacks/AES_TTableOut_HW.py', 'attacks/XorOut_HW.py']
1016
def usage():
17+
global CFG_KNOWNATTACKS
1118
print("Attack model must be one of:")
12-
fl = glob.glob("support/attacks/*.py") # imported from ../
19+
for a in CFG_KNOWNATTACKS:
20+
print(" - %s" % a)
21+
fl = glob.glob("%s/*.py" % ENV_MDLDIR) # imported from ../
1322
for f in fl:
14-
fx = f.replace("support/attacks/","")
23+
fx = f.replace("%s/" % ENV_MDLDIR,"")
1524
fx2 = fx.replace(".py","")
1625
if fx2 == "__init__":
1726
continue
@@ -33,7 +42,10 @@ def fetchModel(modelname):
3342
return am
3443
print("Loading internal module from name '%s'" % modelname)
3544
try:
36-
f = importlib.import_module("sparkgap.attacks.%s" % modelname)
45+
if modelname in CFG_KNOWNATTACKS:
46+
f = importlib.import_module("sparkgap.attacks.%s" % (modelname))
47+
else:
48+
f = importlib.import_module("%s.%s" % (ENV_MDLDIR,modelname))
3749
return f.AttackModel()
3850
except Exception as ex:
3951
print(ex)

0 commit comments

Comments
 (0)