본문 바로가기
# technic/- reversing

z3 모든 경우의 수

by ddddh 2018. 9. 30.
from z3 import *


# find hidden menu route with z3 solver.
input = [BitVec("input[%d]" % i, 32) for i in range(4)]

s = Solver()


for i in range(4):
	s.add(input[i] >= 0, input[i] <= 11)


money = [199, 299, 499, 399]
payload = 0
for i in range(4):
	payload += (money[i] * input[i])

s.add( payload == 0x1C06)


try:
	while s.check() == sat:
		print "[!] z3 result: sat"

		m = s.model()
		applestore = [0, 0, 0, 0]
		for i in range(4):
			applestore[i] = int(str(m[input[i]]))

		print applestore
		# prevent next model from using the same assignment as a previous model
		s.add(Or(input[0] != m[input[0]], input[1] != m[input[1]], input[2] != m[input[2]], input[3] != m[input[3]],))	
		
	else:
		print "[!] z3 result: unsat"
		sys.exit(-1)


except Exception as e:
	print "[!] z3 error : %s" % (e)
	sys.exit(-1)

finally:
	print ""

s.add(Or(input[0] != m[input[0]], input[1] != m[input[1]], input[2] != m[input[2]], input[3] != m[input[3]],))


'# technic > - reversing' 카테고리의 다른 글

kakaotalk pc - 취약점 분석  (0) 2019.07.14
백신 분석 보고서. - 1 -  (0) 2018.10.20
ARM 32bit  (0) 2018.09.29
Reversing a gameboy binary(*.gb)  (0) 2018.09.28
[Android] SDK 버전 패치.  (2) 2017.04.27