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

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

Remove useless code for Win32 diversions.

File size: 3.8 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 (__stdcall *ORIG(CreateFileA))(LPCTSTR, DWORD, DWORD,
41                                             LPSECURITY_ATTRIBUTES,
42                                             DWORD, DWORD, HANDLE);
43#endif
44#if defined HAVE_CREATEFILEA
45static HANDLE (__stdcall *ORIG(CreateFileW))(LPCWSTR, DWORD, DWORD,
46                                             LPSECURITY_ATTRIBUTES,
47                                             DWORD, DWORD, HANDLE);
48#endif
49#if defined HAVE_READFILE
50static BOOL (__stdcall *ORIG(ReadFile))(HANDLE, LPVOID, DWORD, LPDWORD,
51                                        LPOVERLAPPED);
52#endif
53#if defined HAVE_CLOSEHANDLE
54static BOOL (__stdcall *ORIG(CloseHandle))(HANDLE);
55#endif
56
57/*
58 * CreateFileA, CreateFileW
59 */
60
61#if defined HAVE_CREATEFILEA
62HANDLE __stdcall NEW(CreateFileA)(LPCTSTR lpFileName, DWORD dwDesiredAccess,
63           DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes,
64           DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes,
65           HANDLE hTemplateFile)
66{
67    fprintf(stderr, "CreateFileA(%s)\n", lpFileName);
68    return ORIG(CreateFileA)(lpFileName, dwDesiredAccess, dwShareMode,
69                             lpSecurityAttributes, dwCreationDisposition,
70                             dwFlagsAndAttributes, hTemplateFile);
71}
72#endif
73
74#if defined HAVE_CREATEFILEW
75HANDLE __stdcall NEW(CreateFileW)(LPCWSTR lpFileName, DWORD dwDesiredAccess,
76           DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes,
77           DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes,
78           HANDLE hTemplateFile)
79{
80    fprintf(stderr, "CreateFileW(?)\n");
81    return ORIG(CreateFileW)(lpFileName, dwDesiredAccess, dwShareMode,
82                             lpSecurityAttributes, dwCreationDisposition,
83                             dwFlagsAndAttributes, hTemplateFile);
84}
85#endif
86
87/*
88 * ReadFile
89 */
90
91#if defined HAVE_READFILE
92BOOL __stdcall NEW(ReadFile)(HANDLE hFile, LPVOID lpBuffer,
93           DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead,
94           LPOVERLAPPED lpOverlapped)
95{
96    fprintf(stderr, "ReadFile(%i)\n", nNumberOfBytesToRead);
97    return ORIG(ReadFile)(hFile, lpBuffer, nNumberOfBytesToRead,
98                          lpNumberOfBytesRead, lpOverlapped);
99}
100#endif
101
102/*
103 * CloseHandle
104 */
105
106#if defined HAVE_CLOSEHANDLE
107BOOL __stdcall NEW(CloseHandle)(HANDLE hObject)
108{
109    fprintf(stderr, "CloseHandle(%i)\n", hObject);
110    return ORIG(CloseHandle)(hObject);
111}
112#endif
113
114/* Win32 function table */
115#if defined _WIN32
116#   define DIVERT(x) { "kernel32.dll", #x, \
117                      (void **)&x##_orig, (void *)x##_new }
118#   define DIVERT_END { NULL, NULL, NULL, NULL }
119
120zzuf_table_t table_win32[] =
121{
122#if defined HAVE_CLOSEHANDLE
123    DIVERT(CloseHandle),
124#endif
125#if defined HAVE_CREATEFILEA
126    DIVERT(CreateFileA),
127#endif
128#if defined HAVE_CREATEFILEW
129    DIVERT(CreateFileW),
130#endif
131#if defined HAVE_READFILE
132    DIVERT(ReadFile),
133#endif
134    DIVERT_END
135};
136#endif
137
Note: See TracBrowser for help on using the repository browser.