[Python] 纯文本查看 复制代码
print("Welcome to Processor's debugger!")
print("Please input you flag now!")
input = input()
if not input:
print("Are you kidding me?") #所有的print都要加()不然在python中报错
exit(0)
lenth = len(input)
if lenth <= 10:
print("Short flag!")
exit(0)
print("len:%d" % (lenth))
print("OK,let's debug it! You can 'Step' by 'Space'!")
print("--------------INFO--------------")
def debuginfo(dic, num):
print("eax: %d" % (dic['eax']))
print("ebx: %d" % (dic['ebx']))
print("ecx: %d" % (dic['ecx']))
print("zf: %d" % (dic['zf']))
print("--------------INFO--------------" + str(num)) #此处加了一个行号,打印看的更清楚
index = 0
idx = 0
arr = [
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
73, 79, 83
]
check = [
-56, -50, -118, -105, -98, -101, -117, -105, -96, -42, -80, 89, 78, 70,
177, 86, 126, 80, 80, 96, 177, 109, 28
]
result = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
dic = {'eax': 0, 'ebx': 0, 'ecx': 0, 'zf': 0}
list1 = []
list2 = []
while input != ' ': #循环需要修改为不等于,原题不该直接跳过循环无法调试了,同理所有的if判断也是一样修改
if index <= 10:
dic['eax'] = ~ord(input[index])
dic['ebx'] = 0
dic['ecx'] = index
dic['zf'] = 0
#debuginfo(dic, index)
if input != ' ':
dic['eax'] = dic['eax'] ^ arr[index]
dic['ebx'] = arr[index]
dic['ecx'] = index
dic['zf'] = 1
result[index] = dic['eax']
#debuginfo(dic, index)
'''
关键算法在这里:
check列表是最终结果,输入的flag需要和这个比较(在后面一个while中)。
第一部分: flag的前11位
分别取输入的字符串,逐个转换为10进制,然后按位取反运算(类似a=-x-1),结果在对应arr列表元素进行按位异或运算。
'''
reg1 = ((check[index] ^ arr[index]) + 1) * -1
list1.append(chr(reg1))
else:
dic['eax'] = ord(input[index]) + arr[index]
dic['ebx'] = arr[index]
dic['ecx'] = index
dic['zf'] = 1
#debuginfo(dic, index)
if input != ' ':
dic['eax'] = dic['eax'] ^ 0xcc
dic['ebx'] = 0xcc
dic['ecx'] = index
dic['zf'] = 1
result[index] = dic['eax']
#debuginfo(dic, index)
'''
第二部分: flag的后12位
分别取输入的字符串,逐个转换为10进制,然后加上arr列表对应元素,结果再和0xcc进行按位异或运算。
'''
reg2 = ((check[index] ^ 0xcc) - arr[index])
list2.append(chr(reg2))
index = index + 1
if index == 23 or index == lenth:
break
print(list1 + list2)
print('flag为'+''.join(list1 + list2))
while input != ' ':
dic['eax'] = result[idx]
dic['ebx'] = check[idx]
dic['ecx'] = idx
if dic['eax'] != dic['ebx']:
dic['zf'] = 1
print("Wrong flag, try again!")
#debuginfo(dic, idx)
exit(0)
else:
dic['zf'] = 0
#debuginfo(dic, idx)
idx = idx + 1
if idx == 23 or idx == lenth:
if lenth == 23:
print("Yes, you got it!")
exit(0)
else:
print("Close to right!")
exit(0)