本文为USTC SSE CSAPP 2020 Fall实验二的记录,仅供参考,最后是第6题暴力破解的源代码
PPT链接在这里:CSAPP Lab2:Binary Bomb
下面是第6题暴力破解的源代码:
import os
import itertools
import subprocess
r = [1, 2, 3, 4, 5, 6]
rr = list(itertools.permutations(r))
print("len:", len(rr))
ans1 = "When I get angry, Mr. Bigglesworth gets upset.\n"
ans2 = "1 1 1 1 1 1\n"
ans3 = "0 -291\n"
ans4 = "9\n"
ans5 = "2534k1\n"
ans_above = ans1 + ans2 + ans3 + ans4 + ans5
temp_file = "./temp.txt"
command = "./bomb < " + temp_file
for l in rr:
ans6 = str(l).replace(",", " ")[1:-1] + "\n"
ans = ans_above + ans6
f = open(temp_file, "w")
f.write(ans)
f.close()
rc, rout = subprocess.getstatusoutput(command)
if "BOOM!!!" not in rout:
print(l)