Skip to content

Instantly share code, notes, and snippets.

@mcsalgado
Created January 3, 2017 02:33
Show Gist options
  • Save mcsalgado/5d255e6635f74f451d10bff4a32ff9be to your computer and use it in GitHub Desktop.
Save mcsalgado/5d255e6635f74f451d10bff4a32ff9be to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import os
gdb_script = """
set pagination off
break check_{}
run < guessing.txt
quit
"""
result = []
for check_number_to_break in range(1, 12):
with open('gdb_script', 'w') as fp:
print(gdb_script.format(check_number_to_break), file=fp)
for guess in map(chr, range(0, 256)):
result.append(guess)
with open('guessing.txt', 'w') as fp:
print(''.join(result), file=fp)
exit_status = os.system('gdb ./level2 --command=gdb_script | grep "Breakpoint 1, check_{}"'.format(check_number_to_break))
if exit_status != 256:
print(''.join(result))
break
result.pop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment