Created
December 1, 2020 16:45
-
-
Save murx-/62bd9c0662c6afd08b8e00bfa1bee0e8 to your computer and use it in GitHub Desktop.
Use GDB to trace two variables and check if the offset/pointer value has grown beyond the end value
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
# Trace two variables and check if the offset/pointer value has grown beyond the end | |
# We assume/know that rl_point > rl_end is true as we use reverse debugging with rr | |
# We want to find the point were everything was okay. | |
# enter "interactive" python shell with 'pi' and exit after pasting with 'ctrl+d' | |
POINT_VAR_NAME = 'rl_point' | |
END_VAR_NAME = 'rl_end' | |
class bcolors: | |
FAIL = '\033[91m' | |
ENDC = '\033[0m' | |
BOLD = '\033[1m' | |
UNDERLINE = '\033[4m' | |
class CompareBreakpoint(gdb.Breakpoint): | |
def stop(self): | |
point_value = gdb.lookup_symbol(POINT_VAR_NAME)[0].value() | |
end_value = gdb.lookup_symbol(END_VAR_NAME)[0].value() | |
#if a difference of e.g. 1 is accetable | |
#if (end_value - point_value) < -1: | |
if point_value <= end_value: | |
print(f'{bcolors.FAIL} {bcolors.BOLD} {bcolors.UNDERLINE}') | |
print(f'[!] {END_VAR_NAME}: {end_value} \t {POINT_VAR_NAME}: {point_value}') | |
print(f'{bcolors.ENDC}', end='') | |
return True | |
return False | |
CompareBreakpoint(END_VAR_NAME, gdb.BP_WATCHPOINT, gdb.WP_WRITE) | |
CompareBreakpoint(POINT_VAR_NAME, gdb.BP_WATCHPOINT, gdb.WP_WRITE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment