I am trying to hook some glibc functions that has works with file names. Basically I need to modify the filename a bit, then pass it along with other arguments to the original glibc functions.
The code looks like this:
FILE *fopen(const char *filename, const char *modes) {
filename = modify(filename); // assuming we don't need to free the new filename pointer for now
using FuncT = FILE*(*) (const char *, const char *);
static FuncT originalFunc = (FuncT)dlsym(RTLD_NEXT, "fopen");
return originalFunc(filename, modes);
}
This works fine for most cases, but when it comes to variadic arguments for function like int execl(const char *path, const char *arg, ...)
, How can I do it properly?