test.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import ctypes
  2. import os
  3. import sys
  4. import json
  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. import json
  16. import os
  17. import json
  18. import sys
  19. import traceback
  20. import os
  21. os.chdir("/var/sandbox/sandbox-python")
  22. lib.DifySeccomp(65537, 1001, 1)
  23. # declare main function here
  24. def main() -> dict:
  25. return {
  26. "message": [1, 2, 3]
  27. }
  28. from json import loads, dumps
  29. from base64 import b64decode
  30. # execute main function, and return the result
  31. # inputs is a dict, and it
  32. inputs = b64decode('e30=').decode('utf-8')
  33. output = main(**json.loads(inputs))
  34. # convert output to json and print
  35. output = dumps(output, indent=4)
  36. result = f'''<<RESULT>>
  37. {output}
  38. <<RESULT>>'''
  39. print(result)