import of olds chapters

This commit is contained in:
2020-10-26 23:06:17 +01:00
parent 9a9d3108ba
commit d79a55fd2e
18 changed files with 600 additions and 18 deletions

55
chap/debug.tex Normal file
View File

@@ -0,0 +1,55 @@
\chapter{Debug}\index{Debug}
\label{chap:debug}
Quand plus rien ne marche, il existe encore un espoir...
\section{strace}\index{strace}
\section{LD\_PRELOAD}\index{LD\_PRELOAD}
\begin{lstlisting}[language=C]
/*
spy_getenv.so: spy_getenv.c Makefile
gcc -Wall -shared -fPIC $< -ldl -o $@
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#define __USE_GNU
#include <dlfcn.h>
typedef char * (*original_getenv)(const char *envname);
char *getenv(char *envname)
{
static char *arrow = "--getenv--> ";
static char *wtf = " --> WTF ?";
char *content;
original_getenv orig_getenv;
orig_getenv = (original_getenv)dlsym(RTLD_NEXT, "getenv");
write(STDERR_FILENO, arrow, strlen(arrow));
write(STDERR_FILENO, envname, strlen(envname));
content = orig_getenv(envname);
if (NULL != content) {
write(STDERR_FILENO, "=", 1);
write(STDERR_FILENO, content, strlen(content));
}
else {
write(STDERR_FILENO, wtf, strlen(wtf));
}
write(STDERR_FILENO, "\n", 1);
return content;
}
\end{lstlisting}