test.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. import json
  26. print(json.dumps({"hello": "world"}))
  27. from json import loads, dumps
  28. from base64 import b64decode
  29. # execute main function, and return the result
  30. # inputs is a dict, and it
  31. inputs = b64decode('e30=').decode('utf-8')
  32. output = main(**json.loads(inputs))
  33. # convert output to json and print
  34. output = dumps(output, indent=4)
  35. result = f'''<<RESULT>>
  36. {output}
  37. <<RESULT>>'''
  38. print(result)