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

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

Mark diverted Win32 functions as stdcall, it's the correct calling
convention.

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