-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhack-5.py
More file actions
33 lines (29 loc) · 690 Bytes
/
hack-5.py
File metadata and controls
33 lines (29 loc) · 690 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
### START: full.py
### START: myfunc.py
def myfunc():
return 6 / 2
### END: myfunc.py
# Modifying the code object
### START: hack.py
import new
co = myfunc.__code__
myconsts = (None, 10, 2)
co2 = new.code(co.co_argcount,
co.co_nlocals,
co.co_stacksize,
co.co_flags,
co.co_code,
myconsts,
co.co_names,
co.co_varnames,
co.co_filename,
co.co_name,
co.co_firstlineno,
co.co_lnotab)
### END: hack.py
# Injecting the code object
### START: inject.py
myfunc.__code__ = co2
print myfunc()
### END: inject.py
### END: full.py