- C 57.1%
- Linker Script 42.9%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| src | ||
| README.md | ||
You are debugging me, aren't you?
Debuggers are complicated beasts, and one of the tricks they employ to create breakpoints is they replace instructions in your program with interrupts. Whenever the instruction with breakpoint is to be executed, interrupt is triggered, control is transferred to the kernel, and kernel then transfers it to debugger.
Each part of this infrastructure is for sure interesting, but the important part for us is that the debugger modifies your program in memory. Since executable memory is memory just like any other, that means we can observe it, and try to detect changes made by debugger.
Here's how it works: at the linking stage we add text_start and
text_end markers around our program. During the startup we copy
our program to another location, and during execution we compare
stored program and actual program. Discrepancies mean that our
program was changed and we report changed blocks.
To build:
gcc -g -T src/script.ld src/main.c
To launch:
./a.out
To attach with debugger:
ps afx | grep a.out
# => pid + some shit
gdb a.out <pid>