source: zzuf/trunk/src/libzzuf/lib-win32.c @ 4661

Last change on this file since 4661 was 4661, checked in by Sam Hocevar, 10 years ago

Divert ReadFile?() and CloseHandle?().

File size: 3.4 KB
Line 
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 *  load-win32.c: loaded Win32 functions
15 */
16
17#include "config.h"
18
19#if defined HAVE_STDINT_H
20#   include <stdint.h>
21#elif defined HAVE_INTTYPES_H
22#   include <inttypes.h>
23#endif
24
25#include <stdio.h>
26
27#if defined HAVE_WINDOWS_H
28#   include <windows.h>
29#endif
30
31#include "common.h"
32#include "libzzuf.h"
33#include "lib-load.h"
34#include "debug.h"
35#include "fuzz.h"
36#include "fd.h"
37
38/* Kernel functions that we divert */
39#if defined HAVE_CREATEFILEA
40static HANDLE (*ORIG(CreateFileA))(LPCTSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES,
41                                   DWORD, DWORD, HANDLE);
42#endif
43#if defined HAVE_CREATEFILEA
44static HANDLE (*ORIG(CreateFileW))(LPCWSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES,
45                                   DWORD, DWORD, HANDLE);
46#endif
47#if defined HAVE_READFILE
48static BOOL (*ORIG(ReadFile))(HANDLE, LPVOID, DWORD, LPDWORD, LPOVERLAPPED);
49#endif
50#if defined HAVE_CLOSEHANDLE
51static BOOL (*ORIG(CloseHandle))(HANDLE);
52#endif
53
54/*
55 * CreateFileA, CreateFileW
56 */
57
58#if defined HAVE_CREATEFILEA
59HANDLE NEW(CreateFileA)(LPCTSTR lpFileName, DWORD dwDesiredAccess,
60           DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes,
61           DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes,
62           HANDLE hTemplateFile)
63{
64    fprintf(stderr, "CreateFileA diverted!\n");
65    return ORIG(CreateFileA)(lpFileName, dwDesiredAccess, dwShareMode,
66                             lpSecurityAttributes, dwCreationDisposition,
67                             dwFlagsAndAttributes, hTemplateFile);
68}
69#endif
70
71#if defined HAVE_CREATEFILEW
72HANDLE NEW(CreateFileW)(LPCWSTR lpFileName, DWORD dwDesiredAccess,
73           DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes,
74           DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes,
75           HANDLE hTemplateFile)
76{
77    fprintf(stderr, "CreateFileW diverted!\n");
78    return ORIG(CreateFileW)(lpFileName, dwDesiredAccess, dwShareMode,
79                             lpSecurityAttributes, dwCreationDisposition,
80                             dwFlagsAndAttributes, hTemplateFile);
81}
82#endif
83
84/*
85 * ReadFile
86 */
87
88#if defined HAVE_READFILE
89BOOL NEW(ReadFile)(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
90                   LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped)
91{
92    fprintf(stderr, "ReadFile diverted!\n");
93    return ORIG(ReadFile)(hFile, lpBuffer, nNumberOfBytesToRead,
94                          lpNumberOfBytesRead, lpOverlapped);
95}
96#endif
97
98/*
99 * CloseHandle
100 */
101
102#if defined HAVE_CLOSEHANDLE
103BOOL NEW(CloseHandle)(HANDLE hObject)
104{
105    fprintf(stderr, "CloseHandle diverted!\n");
106    return ORIG(CloseHandle)(hObject);
107}
108#endif
109
110/* Win32 function table */
111#if defined _WIN32
112zzuf_table_t table_win32[] =
113{
114#if defined HAVE_CLOSEHANDLE
115    DIVERT(CloseHandle),
116#endif
117#if defined HAVE_CREATEFILEA
118    DIVERT(CreateFileA),
119#endif
120#if defined HAVE_CREATEFILEW
121    DIVERT(CreateFileW),
122#endif
123#if defined HAVE_READFILE
124    DIVERT(ReadFile),
125#endif
126    DIVERT_END
127};
128#endif
129
Note: See TracBrowser for help on using the repository browser.