Spaces:
Sleeping
Sleeping
| # encoder.py | |
| import io | |
| import zipfile | |
| import base64 | |
| import random | |
| import string | |
| from pathlib import Path | |
| def make_zip_bytes(filename: str, content: bytes) -> bytes: | |
| bio = io.BytesIO() | |
| with zipfile.ZipFile(bio, "w", compression=zipfile.ZIP_DEFLATED) as z: | |
| z.writestr(filename, content) | |
| return bio.getvalue() | |
| def generate_junk(min_kb=10, max_kb=30): | |
| n = random.randint(min_kb * 1024, max_kb * 1024) | |
| chars = string.ascii_letters + string.digits + "_-" | |
| return ''.join(random.choice(chars) for _ in range(n)).encode() | |
| def build_simple_wrapper(zip_bytes: bytes, original_filename: str): | |
| b64 = base64.b64encode(zip_bytes).decode() | |
| wrapper = f"""# Encrypted by JerryCoder Bot | |
| import base64, io, zipfile, tempfile, os, sys | |
| b = base64.b64decode('{b64}') | |
| t = tempfile.mkdtemp(prefix='jc_') | |
| zipfile.ZipFile(io.BytesIO(b)).extractall(t) | |
| py = [f for f in os.listdir(t) if f.endswith('.py')][0] | |
| path = os.path.join(t, py) | |
| sys.argv = [path] + sys.argv[1:] | |
| exec(compile(open(path,'rb').read(), path, 'exec'), {{}}) | |
| """ | |
| return wrapper.encode() | |
| def encode_bytes(file_bytes: bytes, filename: str): | |
| zip_b = make_zip_bytes(filename, file_bytes) | |
| wrapper_bytes = build_simple_wrapper(zip_b, filename) | |
| out_name = Path(filename).stem + "_enc.py" | |
| return wrapper_bytes, out_name | |