From e12c0bf892ee590020c6ceebdd71ecb451739731 Mon Sep 17 00:00:00 2001 From: LoneWolf <122724872+FRLoneWolfFR@users.noreply.github.com> Date: Sun, 26 Mar 2023 21:10:20 +0200 Subject: [PATCH] Add files via upload (#150) --- webapp.py | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/webapp.py b/webapp.py index 88e6fb1..a87c78a 100644 --- a/webapp.py +++ b/webapp.py @@ -102,10 +102,39 @@ def ducky_main(request): return(response) -def cleanup_text(buffer): - return_buffer = buffer.replace('+', ' ').replace('%0D%0A', '\n') + '\n' - #print(return_buffer) - return(return_buffer) +_hexdig = '0123456789ABCDEFabcdef' +_hextobyte = None + +def cleanup_text(string): + """unquote('abc%20def') -> b'abc def'.""" + global _hextobyte + + if not string: + return b'' + + if isinstance(string, str): + string = string.encode('utf-8') + + bits = string.split(b'%') + if len(bits) == 1: + return string + + res = [bits[0]] + append = res.append + + if _hextobyte is None: + _hextobyte = {(a + b).encode(): bytes([int(a + b, 16)]) + for a in _hexdig for b in _hexdig} + + for item in bits[1:]: + try: + append(_hextobyte[item[:2]]) + append(item[2:]) + except KeyError: + append(b'%') + append(item) + + return b''.join(res).decode().replace('+',' ') web_app = WSGIApp() @@ -211,4 +240,4 @@ async def startWebService(): wsgiServer.start() while True: wsgiServer.update_poll() - await asyncio.sleep(0) + await asyncio.sleep(0) \ No newline at end of file