-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
93 lines (74 loc) 路 2.03 KB
/
Copy pathrun.py
File metadata and controls
93 lines (74 loc) 路 2.03 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import subprocess
import os
import json
LANG = "c"
NAME = "resolve/horse.exe"
INPUT = "db/horse.json"
USER = "GIT"
F1 = open(INPUT, "r")
data = json.loads(F1.read())
F1.close()
def runShell():
for i in range(len(data["input"])):
if LANG == 'py':
CMD = "py " + NAME
else:
CMD = NAME
sp = subprocess.Popen(
CMD,
stdin = subprocess.PIPE,
stdout = subprocess.PIPE,
)
A = '\n'.join(
'\n'.join(
str(b) for b in e
)
for e in data["input"][i]
)
response = sp.communicate(input=A)[0].decode().strip().split('\r\n')
print [
check(response,data["output"][i]),
response,
data["output"][i]
]
def runInject():
F1 = open(NAME, "r")
C = F1.read()
F1.close()
for i in range(len(data["input"])):
print("-----seq"+str(i)+"------")
A = ','.join(
','.join(
str(b) for b in e
)
for e in data["input"][i]
)
code = "import engine\n"+"engine.setSeq('"+str(A)+"')\n"+"raw_input = engine.raw_input\n"+"open = engine.open\n"+C
path = USER+".o"
F = open(path, 'w')
F.write(code)
F.close()
try:
retcode = subprocess.check_output("py " + path, shell=True)
response = retcode.strip().split('\r\n')
print [
check(response,data["output"][i]),
response,
data["output"][i]
]
except subprocess.CalledProcessError as e:
def illegal():
print "Error illegal native action\n"
def hack():
print "Don't try to hack\n"
{
2:hack,
3:illegal
}[e.returncode]()
def check(Response,Mask) :
try:
assert Response == Mask
return 1
except:
return 0
runShell()