Spaces:
Sleeping
Sleeping
Update encoder.py
Browse files- encoder.py +9 -7
encoder.py
CHANGED
|
@@ -1,5 +1,10 @@
|
|
| 1 |
# encoder.py
|
| 2 |
-
import io
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
def make_zip_bytes(filename: str, content: bytes) -> bytes:
|
| 5 |
bio = io.BytesIO()
|
|
@@ -8,14 +13,13 @@ def make_zip_bytes(filename: str, content: bytes) -> bytes:
|
|
| 8 |
return bio.getvalue()
|
| 9 |
|
| 10 |
def generate_junk(min_kb=10, max_kb=30):
|
| 11 |
-
n = random.randint(min_kb*1024, max_kb*1024)
|
| 12 |
chars = string.ascii_letters + string.digits + "_-"
|
| 13 |
return ''.join(random.choice(chars) for _ in range(n)).encode()
|
| 14 |
|
| 15 |
def build_simple_wrapper(zip_bytes: bytes, original_filename: str):
|
| 16 |
-
# This wrapper will base64-decode the zipped bytes and execute the contained script
|
| 17 |
b64 = base64.b64encode(zip_bytes).decode()
|
| 18 |
-
wrapper = f"""# Encrypted by JerryCoder Bot
|
| 19 |
import base64, io, zipfile, tempfile, os, sys
|
| 20 |
b = base64.b64decode('{b64}')
|
| 21 |
t = tempfile.mkdtemp(prefix='jc_')
|
|
@@ -28,9 +32,7 @@ exec(compile(open(path,'rb').read(), path, 'exec'), {{}})
|
|
| 28 |
return wrapper.encode()
|
| 29 |
|
| 30 |
def encode_bytes(file_bytes: bytes, filename: str):
|
| 31 |
-
# 1) zip original file
|
| 32 |
zip_b = make_zip_bytes(filename, file_bytes)
|
| 33 |
-
# you can add encryption steps here if desired
|
| 34 |
wrapper_bytes = build_simple_wrapper(zip_b, filename)
|
| 35 |
-
out_name =
|
| 36 |
return wrapper_bytes, out_name
|
|
|
|
| 1 |
# encoder.py
|
| 2 |
+
import io
|
| 3 |
+
import zipfile
|
| 4 |
+
import base64
|
| 5 |
+
import random
|
| 6 |
+
import string
|
| 7 |
+
from pathlib import Path
|
| 8 |
|
| 9 |
def make_zip_bytes(filename: str, content: bytes) -> bytes:
|
| 10 |
bio = io.BytesIO()
|
|
|
|
| 13 |
return bio.getvalue()
|
| 14 |
|
| 15 |
def generate_junk(min_kb=10, max_kb=30):
|
| 16 |
+
n = random.randint(min_kb * 1024, max_kb * 1024)
|
| 17 |
chars = string.ascii_letters + string.digits + "_-"
|
| 18 |
return ''.join(random.choice(chars) for _ in range(n)).encode()
|
| 19 |
|
| 20 |
def build_simple_wrapper(zip_bytes: bytes, original_filename: str):
|
|
|
|
| 21 |
b64 = base64.b64encode(zip_bytes).decode()
|
| 22 |
+
wrapper = f"""# Encrypted by JerryCoder Bot
|
| 23 |
import base64, io, zipfile, tempfile, os, sys
|
| 24 |
b = base64.b64decode('{b64}')
|
| 25 |
t = tempfile.mkdtemp(prefix='jc_')
|
|
|
|
| 32 |
return wrapper.encode()
|
| 33 |
|
| 34 |
def encode_bytes(file_bytes: bytes, filename: str):
|
|
|
|
| 35 |
zip_b = make_zip_bytes(filename, file_bytes)
|
|
|
|
| 36 |
wrapper_bytes = build_simple_wrapper(zip_b, filename)
|
| 37 |
+
out_name = Path(filename).stem + "_enc.py"
|
| 38 |
return wrapper_bytes, out_name
|