1 | /* |
---|
2 | * zzuf - general purpose fuzzer |
---|
3 | * Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net> |
---|
4 | * All Rights Reserved |
---|
5 | * |
---|
6 | * This program is free software. It comes without any warranty, to |
---|
7 | * the extent permitted by applicable law. You can redistribute it |
---|
8 | * and/or modify it under the terms of the Do What The Fuck You Want |
---|
9 | * To Public License, Version 2, as published by Sam Hocevar. See |
---|
10 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
---|
11 | */ |
---|
12 | |
---|
13 | /* |
---|
14 | * lib-load.h: preload library functions |
---|
15 | */ |
---|
16 | |
---|
17 | /* Symbol loading stuff */ |
---|
18 | #define STR(x) #x |
---|
19 | #define ORIG(x) x##_orig |
---|
20 | |
---|
21 | #if defined HAVE_DLFCN_H |
---|
22 | # include <dlfcn.h> |
---|
23 | # define NEW(x) x |
---|
24 | # define LOADSYM(x) \ |
---|
25 | do { \ |
---|
26 | if(!ORIG(x)) \ |
---|
27 | { \ |
---|
28 | /* XXX: we try to initialise libzzuf as soon as possible, \ |
---|
29 | * otherwise we may miss a lot of stuff if we wait for \ |
---|
30 | * the linker to load us fully. */ \ |
---|
31 | _zz_init(); \ |
---|
32 | ORIG(x) = dlsym(RTLD_NEXT, STR(x)); \ |
---|
33 | } \ |
---|
34 | if(!ORIG(x)) \ |
---|
35 | abort(); \ |
---|
36 | } while(0) |
---|
37 | #elif defined _WIN32 |
---|
38 | # define NEW(x) x##_new |
---|
39 | # define LOADSYM(x) \ |
---|
40 | do { \ |
---|
41 | /* Nothing to do under Windows, everything is done as soon \ |
---|
42 | * as the process is launched. */ \ |
---|
43 | } while(0) |
---|
44 | |
---|
45 | typedef struct |
---|
46 | { |
---|
47 | char const *lib, *name; |
---|
48 | void **old; |
---|
49 | void *new; |
---|
50 | } |
---|
51 | zzuf_table_t; |
---|
52 | |
---|
53 | # define DIVERT(x) { "kernel32.dll", #x, \ |
---|
54 | (void **)&x##_orig, (void *)x##_new } |
---|
55 | # define DIVERT_END { NULL, NULL, NULL, NULL } |
---|
56 | |
---|
57 | extern zzuf_table_t table_stream[], |
---|
58 | table_win32[]; |
---|
59 | |
---|
60 | #else |
---|
61 | # error no function diversion system for this platform |
---|
62 | #endif |
---|
63 | |
---|