prescript.py 945 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import ctypes
  2. import os
  3. import sys
  4. import traceback
  5. # setup sys.excepthook
  6. def excepthook(type, value, tb):
  7. sys.stderr.write("".join(traceback.format_exception(type, value, tb)))
  8. sys.stderr.flush()
  9. sys.exit(-1)
  10. sys.excepthook = excepthook
  11. lib = ctypes.CDLL("./python.so")
  12. lib.DifySeccomp.argtypes = [ctypes.c_uint32, ctypes.c_uint32, ctypes.c_bool]
  13. lib.DifySeccomp.restype = None
  14. # get running path
  15. running_path = sys.argv[1]
  16. if not running_path:
  17. exit(-1)
  18. # get decrypt key
  19. key = sys.argv[2]
  20. if not key:
  21. exit(-1)
  22. from base64 import b64decode
  23. key = b64decode(key)
  24. os.chdir(running_path)
  25. {{preload}}
  26. lib.DifySeccomp({{uid}}, {{gid}}, {{enable_network}})
  27. code = b64decode("{{code}}")
  28. def decrypt(code, key):
  29. key_len = len(key)
  30. code_len = len(code)
  31. code = bytearray(code)
  32. for i in range(code_len):
  33. code[i] = code[i] ^ key[i % key_len]
  34. return bytes(code)
  35. code = decrypt(code, key)
  36. exec(code)