File size: 1,315 Bytes
75d601d
77d0d5e
 
 
 
 
 
75d601d
 
 
 
 
 
 
 
77d0d5e
75d601d
 
 
 
 
77d0d5e
75d601d
 
 
 
 
 
 
 
 
 
 
 
 
 
77d0d5e
75d601d
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
# 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