Changeset 4829


Ignore:
Timestamp:
Jul 11, 2012, 7:39:13 PM (7 years ago)
Author:
wisk
Message:

win32 port starts to fuzz executable (only few functions related to file handling are implemented)

Location:
zzuf/trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/src/libzzuf/lib-win32.c

    r4827 r4829  
    7777                            lpSecurityAttributes, dwCreationDisposition,
    7878                            dwFlagsAndAttributes, hTemplateFile);
    79     debug("CreateFileA(\"%s\", 0x%x, 0x%x, {...}, 0x%x, 0x%x, {...}) = %i",
     79    debug("CreateFileA(\"%s\", 0x%x, 0x%x, {...}, 0x%x, 0x%x, {...}) = %#08x",
    8080          lpFileName, dwDesiredAccess, dwShareMode, dwCreationDisposition,
    8181          dwFlagsAndAttributes, (int)ret);
     82
     83    if(!_zz_ready || _zz_islocked(-1)) return ret;
     84    if (ret != INVALID_HANDLE_VALUE && dwCreationDisposition == OPEN_EXISTING && _zz_mustwatch(lpFileName))
     85    {
     86        _zz_register(ret);
     87    }
     88
    8289    return ret;
    8390}
     
    94101                            lpSecurityAttributes, dwCreationDisposition,
    95102                            dwFlagsAndAttributes, hTemplateFile);
    96     debug("CreateFileW(\"%S\", 0x%x, 0x%x, {...}, 0x%x, 0x%x, {...}) = %i",
     103    debug("CreateFileW(\"%S\", 0x%x, 0x%x, {...}, 0x%x, 0x%x, {...}) = %#08x",
    97104          lpFileName, dwDesiredAccess, dwShareMode, dwCreationDisposition,
    98105          dwFlagsAndAttributes, (int)ret);
     106
     107    if(!_zz_ready || _zz_islocked(-1)) return ret;
     108    if (ret != INVALID_HANDLE_VALUE && dwCreationDisposition == OPEN_EXISTING && _zz_mustwatch(lpFileName))
     109    {
     110        debug("handle %#08x is registered", ret);
     111        _zz_register(ret);
     112    }
     113
     114
    99115    return ret;
    100116}
     
    108124    ret = ORIG(ReOpenFile)(hOriginalFile, dwDesiredAccess,
    109125                           dwShareMode, dwFlags);
    110     debug("ReOpenFile(%i, 0x%x, 0x%x, 0x%x) = %i", (int)hOriginalFile,
     126    debug("ReOpenFile(%#08x, 0x%x, 0x%x, 0x%x) = %#08x", (int)hOriginalFile,
    111127          dwDesiredAccess, dwShareMode, dwFlags, (int)ret);
    112128    return ret;
     
    128144    debug("ReadFile(%#08x, %#08x, %#08x, %#08x, %#08x) = %s",
    129145        hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, lpOverlapped, (ret ? "TRUE" : "FALSE"));
     146
     147    if (!_zz_ready || !_zz_iswatched(hFile) /*|| !_zz_hostwatched(hFile)*/ || _zz_islocked(hFile) || !_zz_isactive(hFile))
     148        return ret;
     149
     150    if (ret)
     151    {
     152        DWORD bytes_read = lpNumberOfBytesRead ? *lpNumberOfBytesRead : nNumberOfBytesToRead;
     153        debug("fuzzing file %#08x\n", hFile);
     154        _zz_fuzz(hFile, lpBuffer, bytes_read);
     155        _zz_addpos(hFile, bytes_read);
     156    }
    130157    return ret;
    131158}
     
    140167{
    141168    BOOL ret;
     169
     170    /* TODO: Check if fuzzed application tries to close our debug channel */
     171
    142172    ret = ORIG(CloseHandle)(hObject);
    143     debug("CloseHandle(%i) = %s", (int)hObject, (ret ? "TRUE" : "FALSE"));
     173    debug("CloseHandle(%#08x) = %s", (int)hObject, (ret ? "TRUE" : "FALSE"));
     174    if (!_zz_ready || !_zz_iswatched(hObject) || _zz_islocked(hObject))
     175        return ret;
     176    _zz_unregister(hObject);
    144177    return ret;
    145178}
  • zzuf/trunk/src/zzuf.c

    r4828 r4829  
    907907                switch (exit_code)
    908908                {
    909                 case EXCEPTION_ACCESS_VIOLATION: fprintf(stderr, "child(%d) unhandled exception: Access Violation", opts->child[i].pid); break;
    910                 default: break;
     909                case EXCEPTION_ACCESS_VIOLATION: fprintf(stderr, "child(%d) unhandled exception: Access Violation\n", opts->child[i].pid); break;
     910                default: fprintf(stderr, "child(%d) exited with code %#08x\n", opts->child[i].pid, exit_code); break;
    911911                }
    912912            }
Note: See TracChangeset for help on using the changeset viewer.