Skip to content

Instantly share code, notes, and snippets.

@vesche
Created July 9, 2021 20:50
Show Gist options
  • Save vesche/e9e0e07221e463e63d1bad67542d483c to your computer and use it in GitHub Desktop.
Save vesche/e9e0e07221e463e63d1bad67542d483c to your computer and use it in GitHub Desktop.
import marshal, types
# >>> def x():
# ... return eval
# ...
# >>> x()('2+2')
# 4
# >>> import marshal
# >>> marshal.dumps(x.__code__)
# ...
result = types.FunctionType(marshal.loads(
b'\xe3\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00C\x00\x00\x00s\x04\x00\x00\x00t\x00S\x00)\x01N)\x01\xda\x04eval\xa9\x00r\x02\x00\x00\x00r\x02\x00\x00\x00\xfa\x07<stdin>\xda\x01x\x01\x00\x00\x00\xf3\x00\x00\x00\x00'
), locals())()('2+2')
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment