Dann kannst du einfach die fopen Funktion mit Hilfe von ld wrappen:
Code:
#include <stdio.h>
// Nicht nötig, wenn mit int3 gearbeitet wird
fopen_called_with_foobar()
{
/* nichts */
}
//Deklarieren, damit GCC glücklich ist
FILE* __real_fopen(const char* path, const char* mode);
FILE* __wrap_fopen(const char* path, const char* mode)
{
if (!strcmp(path,"FOOBAR"))
{
fopen_called_with_foobar();
/* ALTERNATIV auf i386 Architektur */
// __asm ("int3");
}
return __real_fopen(path,mode);
}
int main()
{
FILE* f;
f = fopen("asdas","r");
if (!f)
{
perror("fopen asdas");
} else {
fclose(f);
}
f = fopen("FOOBAR","r");
if (!f)
{
perror("fopen FOOBAR");
} else {
fclose(f);
}
}
Das kannst du dann mit
Code:
gcc -Wl,--wrap,fdopen -g [weitere Optionen] Datei.c
compilieren.
Wenn du mit int3 gearbeitet hast, wird gdb automatisch stoppen, ansonsten einfach einen breakpoint auf file_called_with_foobar setzen.
Lesezeichen