test.py 941 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import ctypes
  2. import json
  3. import os
  4. import sys
  5. import traceback
  6. # setup sys.excepthook
  7. def excepthook(type, value, tb):
  8. sys.stderr.write("".join(traceback.format_exception(type, value, tb)))
  9. sys.stderr.flush()
  10. sys.exit(-1)
  11. sys.excepthook = excepthook
  12. lib = ctypes.CDLL("/var/sandbox/sandbox-python/python.so")
  13. lib.DifySeccomp.argtypes = [ctypes.c_uint32, ctypes.c_uint32, ctypes.c_bool]
  14. lib.DifySeccomp.restype = None
  15. os.chdir("/var/sandbox/sandbox-python")
  16. lib.DifySeccomp(65537, 1001, 1)
  17. # declare main function here
  18. def main() -> dict:
  19. return {"message": [1, 2, 3]}
  20. from base64 import b64decode
  21. from json import dumps, loads
  22. # execute main function, and return the result
  23. # inputs is a dict, and it
  24. inputs = b64decode("e30=").decode("utf-8")
  25. output = main(**json.loads(inputs))
  26. # convert output to json and print
  27. output = dumps(output, indent=4)
  28. result = f"""<<RESULT>>
  29. {output}
  30. <<RESULT>>"""
  31. print(result)