以下内容是劫持glib.c中标准printf函数的方法。是这篇 Docker容器内的监控命令数据修正思路的基础知识。对LD_PRELOAD熟悉可以不看。
劫持printf函数的Demo
[root@garnett-vm-1-3nskg test_ld]# ls
hijack_printf.c printf_hello.c
root@garnett-vm-1-3nskg test_ld]# cat printf_hello.c
#include <stdio.h>
main()
{
printf("hello garnett.wang!");
}
[root@garnett-vm-1-3nskg test_ld]# cat hijack_printf.c
#define _GNU_SOURCE
#include <stdio.h>
#include <dlfcn.h>
#include <stdlib.h>