From a501ef438acfb88bf822ea12e1fdd586e8e1baaf Mon Sep 17 00:00:00 2001 From: Louis Burda Date: Thu, 8 Jul 2021 16:38:54 +0200 Subject: use usual random ids for modelname and solidname in havoc 15, various smaller fixes --- checker/src/checker.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'checker/src/checker.py') diff --git a/checker/src/checker.py b/checker/src/checker.py index ee21a45..7da1719 100644 --- a/checker/src/checker.py +++ b/checker/src/checker.py @@ -173,20 +173,22 @@ def leetify(clean: str) -> str: return "".join([conv[c] if c in conv else c for c in out]) -def fakeid(havoc: bool = False) -> bytes: +def fakeid(havoc: bool = False, minlen: int = 20, maxlen: int = 60) -> bytes: if havoc: - idlen = rand.randint(10, 40) + idlen = rand.randint(minlen, maxlen) return bytes([rand.randint(32, 127) for i in range(idlen)]) else: - words = [] - for i in range(rand.randint(2, 3)): + idstr = b"" + while len(idstr) < minlen: word = rand.choice(wordlist) - words.append(leetify(word).encode() if randbool() else word.encode()) - return b"-".join(words) + if idstr != b"": + idstr += b"-" + idstr += leetify(word).encode() if randbool() else word.encode() + return idstr[:maxlen] def fakeids(n: int, havoc: bool = False) -> list[bytes]: - return [fakeid(havoc) for i in range(n)] + return [fakeid(havoc=havoc) for i in range(n)] def approx_equal(f1: float, f2: float, precision: int = 2) -> bool: @@ -1011,9 +1013,13 @@ async def havoc_fluff_upload(di: DependencyInjector) -> None: if len(extra_models) == 0: return model = rand.choice(extra_models) - modelname = os.path.basename(model).split("-")[0].encode() - modelname += bytes([rand.choice(b"0123456789") for i in range(5)]) stlfile = open(model, "rb").read() + if model.endswith("-bin.stl"): + modelname = fakeid(minlen=15, maxlen=15) + stlfile = modelname + stlfile[15:] # replaces "OpenSCAD Model\n" + else: + modelname = fakeid() + stlfile = stlfile.replace(b"OpenSCAD_Model", modelname) # Simple Upload session = await di.get(Session) -- cgit v1.2.3-71-gd317