-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathzpyi.py
57 lines (46 loc) · 1.34 KB
/
zpyi.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
###########################################
# Python script for zpyi #
# Original Author: #
# Saksham Sharma (sakshamsharma) #
# Email: saksham@acehack.org #
###########################################
import sys
import os
from math import *
if 'ZPYI_IMPORTS' in os.environ:
for module in os.environ['ZPYI_IMPORTS'].split(','):
_module = __import__(module, globals(), locals())
globals().update(_module.__dict__)
def cleanup():
try:
os.unlink(sys.argv[1])
except:
pass
args = []
with open(sys.argv[1]) as fifo:
codestr = fifo.readlines()
if len(sys.argv) > 2:
with open(sys.argv[2]) as argfile:
args = argfile.readlines()
# Use arguments to automate script even better
for i in range(0, len(args)):
sys.argv[i+1] = args[i]
code = ([ i for i in codestr if i.strip() ])
# Use try catch to return only after cleanup
try:
if len(code) == 1 and not code[0].startswith('print'):
# Commands like:
# '1+2'
# Also should display output
print (eval(code[0]))
else:
# Bigger commands
# 'a = 2
# print a'
exec("\n".join(code))
except Exception as error:
print ("Python statement invalid: ")
print (error.__doc__)
print ("{}".format(error))
cleanup()
sys.exit(0)