Skip to content

Instantly share code, notes, and snippets.

@azat
Last active December 20, 2015 13:29
Show Gist options
  • Save azat/6138699 to your computer and use it in GitHub Desktop.
Save azat/6138699 to your computer and use it in GitHub Desktop.
test-gdb-jump

test-gdb-jump

#include <stdlib.h>
#include <stdio.h>
#define CREATE_PAYLOAD(name) \
void name() { \
for (int i = 0; i < 10; ++i) { \
printf("Function: %s (%i)\n", __FUNCTION__, i); \
} \
}
CREATE_PAYLOAD(foo)
CREATE_PAYLOAD(bar)
CREATE_PAYLOAD(baz)
int main(int argc, char **argv)
{
foo();
bar();
baz();
return EXIT_SUCCESS;
}
#!/usr/bin/env bash
#
# This script will skip call of "foo" function
#
function call_addr()
{
objdump -D ./ex | egrep 'callq.*'$1'' | tr -d : | awk '{printf "0x%s", $1}'
}
FOO_CALL_ADDR=$(call_addr foo)
BAR_CALL_ADDR=$(call_addr bar)
gdb \
-ex "start" \
-ex "break *$FOO_CALL_ADDR" \
-ex "continue" \
-ex "jump *$BAR_CALL_ADDR" \
-ex "quit" \
\
./ex
#!/usr/bin/env bash
#gcc -Wl,--gc-sections -ffunction-sections -g3 -std=c99 -O0 -o ex ex.c
gcc -ffunction-sections -g3 -std=c99 -O0 -o ex ex.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment