Changeset 4834 for zzuf


Ignore:
Timestamp:
Aug 3, 2012, 7:26:43 PM (7 years ago)
Author:
wisk
Message:

add new hook for windows (CreateFileMapping?(A|W), MapViewOfFile?, ReadFileEx?), re-enable option -U, start to port network on windows

Location:
zzuf/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/msvc/config.h

    r4832 r4834  
    2929#define HAVE_CREATEFILEA 1
    3030#define HAVE_CREATEFILEW 1
     31#define HAVE_CREATEFILEMAPPINGA 1
     32#define HAVE_CREATEFILEMAPPINGW 1
     33#define HAVE_MAPVIEWOFFILE 1
    3134/* #undef HAVE_DLADDR */
    3235/* #undef HAVE_DLFCN_H */
     
    7477#define HAVE_PROCESS_H 1
    7578#define HAVE_READFILE 1
     79#define HAVE_READFILEEX 1
    7680/* #undef HAVE_READV */
    7781#define HAVE_RECV 1
  • zzuf/trunk/src/libzzuf/lib-win32.c

    r4832 r4834  
    5858                                        LPOVERLAPPED);
    5959#endif
     60#if defined HAVE_READFILEEX
     61static BOOL (__stdcall *ORIG(ReadFileEx))(HANDLE, LPVOID, DWORD, LPDWORD,
     62    LPOVERLAPPED, LPOVERLAPPED_COMPLETION_ROUTINE);
     63#endif
     64#if defined HAVE_CREATEFILEMAPPINGA
     65static HANDLE (__stdcall *ORIG(CreateFileMappingA))(HANDLE, LPSECURITY_ATTRIBUTES,
     66                                                   DWORD, DWORD, DWORD, LPCSTR);
     67#endif
     68#if defined HAVE_CREATEFILEMAPPINGW
     69static HANDLE (__stdcall *ORIG(CreateFileMappingW))(HANDLE, LPSECURITY_ATTRIBUTES,
     70                                                   DWORD, DWORD, DWORD, LPCWSTR);
     71#endif
     72#ifdef HAVE_MAPVIEWOFFILE
     73static LPVOID (__stdcall *ORIG(MapViewOfFile))(HANDLE, DWORD, DWORD, DWORD, SIZE_T);
     74#endif
    6075#if defined HAVE_CLOSEHANDLE
    6176static BOOL (__stdcall *ORIG(CloseHandle))(HANDLE);
     
    142157    ret = ORIG(ReadFile)(hFile, lpBuffer, nNumberOfBytesToRead,
    143158                          lpNumberOfBytesRead, lpOverlapped);
    144     debug("ReadFile(%#08x, %#08x, %#08x, %#08x, %#08x) = %s",
     159    debug("ReadFile(%#08x, %p, %#08x, %#08x, %p) = %s",
    145160        hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, lpOverlapped, (ret ? "TRUE" : "FALSE"));
    146161
     
    159174#endif
    160175
     176#if defined HAVE_READFILEEX
     177BOOL __stdcall NEW(ReadFileEx)(HANDLE hFile, LPVOID lpBuffer,
     178    DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead,
     179    LPOVERLAPPED lpOverlapped, LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
     180{
     181    BOOL ret;
     182
     183    ret = ORIG(ReadFileEx)(hFile, lpBuffer, nNumberOfBytesToRead,
     184        lpNumberOfBytesRead, lpOverlapped, lpCompletionRoutine);
     185
     186    debug("ReadFileEx(%#08x, %p, %#08x, %p, %p, %p) = %s",
     187        hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, lpOverlapped, lpCompletionRoutine, (ret ? "TRUE" : "FALSE"));
     188
     189    if (!_zz_ready || !_zz_iswatched(hFile) /*|| !_zz_hostwatched(hFile)*/ || _zz_islocked(hFile) || !_zz_isactive(hFile))
     190        return ret;
     191
     192    if (ret)
     193    {
     194        DWORD bytes_read = lpNumberOfBytesRead ? *lpNumberOfBytesRead : nNumberOfBytesToRead;
     195        debug("fuzzing file %#08x\n", hFile);
     196        _zz_fuzz(hFile, lpBuffer, bytes_read);
     197        _zz_addpos(hFile, bytes_read);
     198    }
     199    return ret;
     200}
     201#endif
     202
     203#if defined HAVE_CREATEFILEMAPPINGA
     204HANDLE __stdcall NEW(CreateFileMappingA)(HANDLE hFile, LPSECURITY_ATTRIBUTES lpAttributes,
     205            DWORD flProtect, DWORD dwMaximumSizeHigh, DWORD dwMaximumSizeLow,
     206            LPCSTR lpName)
     207{
     208    HANDLE ret;
     209    ret = ORIG(CreateFileMappingA)(hFile, lpAttributes,
     210        flProtect, dwMaximumSizeHigh, dwMaximumSizeLow,
     211        lpName);
     212
     213    debug("CreateFileMappingA(%#08x, %#08x, %#08x, %#08x, %#08x, %s) = %#08x",
     214        hFile, lpAttributes, flProtect, dwMaximumSizeHigh, dwMaximumSizeLow, lpName, ret);
     215
     216    if (ret == NULL) return ret;
     217
     218    if (!_zz_ready || !_zz_iswatched(hFile) /*|| !_zz_hostwatched(hFile)*/ || _zz_islocked(hFile) || !_zz_isactive(hFile) || _zz_islocked(-1))
     219        return ret;
     220
     221    debug("handle %#08x is registered", ret);
     222    _zz_register(ret);
     223
     224    return ret;
     225}
     226#endif
     227
     228#if defined HAVE_CREATEFILEMAPPINGW
     229HANDLE __stdcall NEW(CreateFileMappingW)(HANDLE hFile, LPSECURITY_ATTRIBUTES lpAttributes,
     230            DWORD flProtect, DWORD dwMaximumSizeHigh, DWORD dwMaximumSizeLow,
     231            LPCWSTR lpName)
     232{
     233    HANDLE ret;
     234    ret = ORIG(CreateFileMappingW)(hFile, lpAttributes,
     235        flProtect, dwMaximumSizeHigh, dwMaximumSizeLow,
     236        lpName);
     237
     238    debug("CreateFileMappingW(%#08x, %#08x, %#08x, %#08x, %#08x, %S) = %#08x",
     239        hFile, lpAttributes, flProtect, dwMaximumSizeHigh, dwMaximumSizeLow, lpName, ret);
     240
     241    if (ret == NULL) return ret;
     242
     243    if (!_zz_ready || !_zz_iswatched(hFile) /*|| !_zz_hostwatched(hFile)*/ || _zz_islocked(hFile) || !_zz_isactive(hFile) || _zz_islocked(-1))
     244        return ret;
     245
     246    debug("handle %#08x is registered", ret);
     247    _zz_register(ret);
     248
     249    return ret;
     250}
     251#endif
     252
     253#ifdef HAVE_MAPVIEWOFFILE
     254LPVOID __stdcall NEW(MapViewOfFile)(HANDLE hFileMappingObject, DWORD dwDesiredAccess,
     255    DWORD dwFileOffsetHigh, DWORD dwFileOffsetLow,
     256    SIZE_T dwNumberOfBytesToMap)
     257{
     258    LPVOID ret;
     259    ret = ORIG(MapViewOfFile)(hFileMappingObject, dwDesiredAccess,
     260        dwFileOffsetHigh, dwFileOffsetLow,
     261        dwNumberOfBytesToMap);
     262
     263    debug("MapViewOfFile(%#08x, %#08x, %#08x, %#08x, %#08x) = %p",
     264        hFileMappingObject, dwDesiredAccess, dwFileOffsetHigh, dwFileOffsetLow, dwNumberOfBytesToMap, ret);
     265
     266    return ret;
     267}
     268#endif
     269
    161270/*
    162271 * CloseHandle
     
    190299    DIVERT(CreateFileA),
    191300    DIVERT(CreateFileW),
     301    DIVERT(CreateFileMappingA),
     302    DIVERT(CreateFileMappingW),
     303    DIVERT(MapViewOfFile),
    192304    DIVERT(ReadFile),
     305    DIVERT(ReadFileEx),
    193306    DIVERT_END
    194307};
  • zzuf/trunk/src/libzzuf/network.c

    r4685 r4834  
    2929#   include <netinet/in.h>
    3030#   include <arpa/inet.h>
     31#elif defined HAVE_WINSOCK2_H
     32#   include <WinSock2.h>
     33#   include <WS2tcpip.h>
    3134#endif
    3235
     
    3639#include "network.h"
    3740
    38 #if defined HAVE_SYS_SOCKET_H
     41#if defined HAVE_SYS_SOCKET_H || defined (HAVE_WINDOWS_H)
    3942static unsigned int get_socket_ip(int);
    4043static int host_in_list(unsigned int, unsigned int const *);
     
    5457void _zz_network_init(void)
    5558{
    56     ;
     59#ifdef HAVE_WINSOCK2_H
     60    WSADATA wsa_data;
     61    WSAStartup(MAKEWORD(2,2), &wsa_data); /* LATER: handle error */
     62#endif
    5763}
    5864
    5965void _zz_network_fini(void)
    6066{
    61 #if defined HAVE_SYS_SOCKET_H
     67#if defined HAVE_SYS_SOCKET_H || defined (HAVE_WINDOWS_H)
    6268    if(ports != static_ports)
    6369        free(ports);
     
    6773        free(deny);
    6874#endif
     75
     76#if defined HAVE_WINSOCK2_H
     77    WSACleanup(); /* LATER: handle error */
     78#endif
    6979}
    7080
    7181void _zz_allow(char const *allowlist)
    7282{
    73 #if defined HAVE_SYS_SOCKET_H
     83#if defined HAVE_SYS_SOCKET_H || defined (HAVE_WINDOWS_H)
    7484    allow = create_host_list(allowlist, static_allow);
    7585#endif
     
    7888void _zz_deny(char const *denylist)
    7989{
    80 #if defined HAVE_SYS_SOCKET_H
     90#if defined HAVE_SYS_SOCKET_H || defined (HAVE_WINDOWS_H)
    8191    deny = create_host_list(denylist, static_deny);
    8292#endif
     
    8595void _zz_ports(char const *portlist)
    8696{
    87 #if defined HAVE_SYS_SOCKET_H
     97#if defined HAVE_SYS_SOCKET_H || defined (HAVE_WINDOWS_H)
    8898    ports = _zz_allocrange(portlist, static_ports);
    8999#endif
     
    92102int _zz_portwatched(int port)
    93103{
    94 #if defined HAVE_SYS_SOCKET_H
     104#if defined HAVE_SYS_SOCKET_H || defined (HAVE_WINDOWS_H)
    95105    if(!ports)
    96106        return 1;
     
    104114int _zz_hostwatched(int sock)
    105115{
    106 #if defined HAVE_SYS_SOCKET_H
     116#if defined HAVE_SYS_SOCKET_H || defined (HAVE_WINDOWS_H)
    107117    int watch = 1;
    108118    unsigned int ip;
     
    126136/* XXX: the following functions are local */
    127137
    128 #if defined HAVE_SYS_SOCKET_H
     138#if defined HAVE_SYS_SOCKET_H || defined HAVE_WINSOCK2_H
    129139static unsigned int *create_host_list(char const *list,
    130140                                      unsigned int *static_list)
     
    167177        }
    168178
    169         ret = inet_aton(buf, &addr);
     179        ret = inet_pton(AF_INET, buf, &addr);
    170180        if (ret)
    171181            iplist[i++] = addr.s_addr;
  • zzuf/trunk/src/zzuf.c

    r4833 r4834  
    792792static void clean_children(struct opts *opts)
    793793{
    794 #if defined HAVE_KILL
     794#if defined HAVE_KILL || defined HAVE_WINDOWS_H
    795795    int64_t now = _zz_time();
    796796#endif
    797797    int i, j;
    798798
    799 #if defined HAVE_KILL
     799#if defined HAVE_KILL || defined HAVE_WINDOWS_H
    800800    /* Terminate children if necessary */
    801801    for(i = 0; i < opts->maxchild; i++)
     
    810810                fprintf(stderr, "data output exceeded, sending SIGTERM\n");
    811811            }
     812#if defined HAVE_KILL
    812813            kill(opts->child[i].pid, SIGTERM);
     814#else
     815            /* We must invalidate fd */
     816            memset(opts->child[i].fd, -1, sizeof(opts->child[i].fd));
     817            TerminateProcess(opts->child[i].process_handle, 0x0);
     818#endif
    813819            opts->child[i].date = now;
    814820            opts->child[i].status = STATUS_SIGTERM;
     
    824830                fprintf(stderr, "running time exceeded, sending SIGTERM\n");
    825831            }
     832#if defined HAVE_KILL
    826833            kill(opts->child[i].pid, SIGTERM);
     834#else
     835            /* We must invalidate fd */
     836            memset(opts->child[i].fd, -1, sizeof(opts->child[i].fd));
     837            TerminateProcess(opts->child[i].process_handle, 0x0);
     838#endif
    827839            opts->child[i].date = now;
    828840            opts->child[i].status = STATUS_SIGTERM;
     
    841853                fprintf(stderr, "not responding, sending SIGKILL\n");
    842854            }
     855#if defined HAVE_KILL
    843856            kill(opts->child[i].pid, SIGKILL);
     857#else
     858            TerminateProcess(opts->child[i].process_handle, 0x0);
     859#endif
    844860            opts->child[i].status = STATUS_SIGKILL;
    845861        }
Note: See TracChangeset for help on using the changeset viewer.