From bcd5ac2bc9d7537bdeabe0dac80b46e2bddf5c0f Mon Sep 17 00:00:00 2001 From: aaay-aaay <32845331+aaay-aaay@users.noreply.github.com> Date: Fri, 12 Apr 2019 14:11:01 +0100 Subject: [PATCH 1/2] Add ANOTHER Maybe --- .../06-maybe-keyword/solutions/pastebin-2.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 challenges/06-maybe-keyword/solutions/pastebin-2.py diff --git a/challenges/06-maybe-keyword/solutions/pastebin-2.py b/challenges/06-maybe-keyword/solutions/pastebin-2.py new file mode 100644 index 0000000..56b0194 --- /dev/null +++ b/challenges/06-maybe-keyword/solutions/pastebin-2.py @@ -0,0 +1,23 @@ +from ctypes import * +from sys import * +from sys import _getframe +from types import * +from random import * + +# there is no source code for this function + +class PatchedLocals(dict): + __getitem__ = FunctionType(CodeType( + 2, 0, 2, 10, 0, b'd\0\x83\0j\0d\1\x19\0d\2k\2r\x1cd\5d\3d\4\x83\1\x83\1S\0d\6j\1d\0\x83\0j\0d\7\x19\0d\0\x83\0j\0d\1\x19\0\x83\2S\0', (_getframe, 'item', 'Maybe', getrandbits, 1, bool, dict, 'self'), + ('f_locals', '__getitem__'), ('self', 'item'), __file__, '__getitem__', 7, b'', (), ('__class__',) + ), {}) + def __setitem__(self, item, value): + if item == 'Maybe': + raise SyntaxError("can't assign to keyword") + super().__setitem__(item, value) + def __delitem__(self, item): + if item == 'Maybe': + raise SyntaxError("can't delete keyword") + super().__delitem__(item) + +py_object.from_address(id(locals()) + sizeof(c_ssize_t)).value = PatchedLocals From 29b2d789a83b6d7858e778b85a05d76072f6fd76 Mon Sep 17 00:00:00 2001 From: aaay-aaay <32845331+aaay-aaay@users.noreply.github.com> Date: Fri, 12 Apr 2019 14:13:58 +0100 Subject: [PATCH 2/2] Remove __class__. --- challenges/06-maybe-keyword/solutions/pastebin-2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/challenges/06-maybe-keyword/solutions/pastebin-2.py b/challenges/06-maybe-keyword/solutions/pastebin-2.py index 56b0194..63ee163 100644 --- a/challenges/06-maybe-keyword/solutions/pastebin-2.py +++ b/challenges/06-maybe-keyword/solutions/pastebin-2.py @@ -9,7 +9,7 @@ class PatchedLocals(dict): __getitem__ = FunctionType(CodeType( 2, 0, 2, 10, 0, b'd\0\x83\0j\0d\1\x19\0d\2k\2r\x1cd\5d\3d\4\x83\1\x83\1S\0d\6j\1d\0\x83\0j\0d\7\x19\0d\0\x83\0j\0d\1\x19\0\x83\2S\0', (_getframe, 'item', 'Maybe', getrandbits, 1, bool, dict, 'self'), - ('f_locals', '__getitem__'), ('self', 'item'), __file__, '__getitem__', 7, b'', (), ('__class__',) + ('f_locals', '__getitem__'), ('self', 'item'), __file__, '__getitem__', 7, b'', (), () ), {}) def __setitem__(self, item, value): if item == 'Maybe':