Last active
July 24, 2024 22:39
-
-
Save iTrooz/cc2b7e676fa7e73b5c089c81bf76ac45 to your computer and use it in GitHub Desktop.
Make a breakpoint when a certain text is written to stdout
This file contains hidden or 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
# Make a breakpoint when a certain text is written to stdout | |
# Note: only work with C/C++ binaries | |
set width 0 | |
set height 0 | |
set verbose off | |
# Modify this to search for a different string | |
# Case sensitive | |
set $STR_SEARCH = "hello world" | |
# See https://stackoverflow.com/a/25979468 | |
set $exit_syscall = 1 | |
catch syscall write | |
commands 1 | |
set $exit_syscall = ! $exit_syscall | |
if !$exit_syscall | |
continue | |
end | |
# Disable if you program copies the stdout or stderr fd | |
# Check for stdout or stderr fd | |
if $rdi != 1 && $rdi != 2 | |
continue | |
end | |
echo "Found write at fd:\n" | |
p $rdi | |
# Calculate string written | |
set $written_ptr=(char*)$rsi | |
set $written_len=$rdx | |
echo Written:\n | |
p *$written_ptr@$written_len | |
if (char*) strstr(*$written_ptr@$written_len, $STR_SEARCH) != 0 | |
echo Match found!\n | |
else | |
continue | |
# Comment this to drop to shell on any text written | |
end | |
end | |
run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment