Last active
October 16, 2023 22:09
-
-
Save 0xkarmacoma/746441c3a9c992144ed01e847aa219a4 to your computer and use it in GitHub Desktop.
enumerating possibles expression values with z3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from z3 import * | |
selector = BitVec('selector', 32) | |
expr = 107 + 4 * (selector % 16) | |
codesize = 128 | |
s = Solver() | |
s.add(expr < codesize) | |
possible_jump_table_values = set([]) | |
while True: | |
print(f"checking assertions [{', '.join([str(c) for c in s.assertions()])}]") | |
result = s.check() | |
print(f"result: {result}") | |
if result != sat: | |
break | |
model = s.model() | |
jump_table_value = model.evaluate(expr).as_long() | |
possible_jump_table_values.add(jump_table_value) | |
# make sure we get a different expr value next time | |
s.add(expr != jump_table_value) | |
print(f"possible jump table values: {possible_jump_table_values}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment