Get the debug channel to work on Win32.

This commit is contained in:
Sam Hocevar 2010-10-06 21:10:15 +00:00 committed by sam
parent 6b942564a2
commit b69bd84604
4 changed files with 18 additions and 26 deletions

View File

@ -55,3 +55,4 @@ extern zzuf_table_t table_win32[];
#else
# error no function diversion system for this platform
#endif

View File

@ -68,9 +68,9 @@ HANDLE __stdcall NEW(CreateFileA)(LPCTSTR lpFileName, DWORD dwDesiredAccess,
ret = ORIG(CreateFileA)(lpFileName, dwDesiredAccess, dwShareMode,
lpSecurityAttributes, dwCreationDisposition,
dwFlagsAndAttributes, hTemplateFile);
debug("%s(\"%s\", %x, %x, ..., %x, %x, ...) = [%i]",
__func__, lpFileName, dwDesiredAccess, dwShareMode,
dwCreationDisposition, dwFlagsAndAttributes, (int)ret); \
debug("CreateFileA(\"%s\", 0x%x, 0x%x, ..., 0x%x, 0x%x, ...) = [%i]",
lpFileName, dwDesiredAccess, dwShareMode, dwCreationDisposition,
dwFlagsAndAttributes, (int)ret);
return ret;
}
#endif
@ -81,10 +81,14 @@ HANDLE __stdcall NEW(CreateFileW)(LPCWSTR lpFileName, DWORD dwDesiredAccess,
DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes,
HANDLE hTemplateFile)
{
fprintf(stderr, "CreateFileW(?)\n");
return ORIG(CreateFileW)(lpFileName, dwDesiredAccess, dwShareMode,
lpSecurityAttributes, dwCreationDisposition,
dwFlagsAndAttributes, hTemplateFile);
HANDLE ret;
ret = ORIG(CreateFileW)(lpFileName, dwDesiredAccess, dwShareMode,
lpSecurityAttributes, dwCreationDisposition,
dwFlagsAndAttributes, hTemplateFile);
debug("CreateFileW(\"%s\", 0x%x, 0x%x, ..., 0x%x, 0x%x, ...) = [%i]",
lpFileName, dwDesiredAccess, dwShareMode, dwCreationDisposition,
dwFlagsAndAttributes, (int)ret);
return ret;
}
#endif
@ -97,7 +101,6 @@ BOOL __stdcall NEW(ReadFile)(HANDLE hFile, LPVOID lpBuffer,
DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead,
LPOVERLAPPED lpOverlapped)
{
fprintf(stderr, "ReadFile(%i)\n", nNumberOfBytesToRead);
return ORIG(ReadFile)(hFile, lpBuffer, nNumberOfBytesToRead,
lpNumberOfBytesRead, lpOverlapped);
}
@ -110,32 +113,22 @@ BOOL __stdcall NEW(ReadFile)(HANDLE hFile, LPVOID lpBuffer,
#if defined HAVE_CLOSEHANDLE
BOOL __stdcall NEW(CloseHandle)(HANDLE hObject)
{
fprintf(stderr, "CloseHandle(%i)\n", hObject);
return ORIG(CloseHandle)(hObject);
}
#endif
/* Win32 function table */
#if defined _WIN32
#if defined HAVE_WINDOWS_H
# define DIVERT(x) { "kernel32.dll", #x, \
(void **)&x##_orig, (void *)x##_new }
# define DIVERT_END { NULL, NULL, NULL, NULL }
zzuf_table_t table_win32[] =
{
#if defined HAVE_CLOSEHANDLE
DIVERT(CloseHandle),
#endif
#if defined HAVE_CREATEFILEA
DIVERT(CreateFileA),
#endif
#if defined HAVE_CREATEFILEW
DIVERT(CreateFileW),
#endif
#if defined HAVE_READFILE
DIVERT(ReadFile),
#endif
DIVERT_END
};
#endif

View File

@ -116,7 +116,11 @@ void _zz_init(void)
tmp = getenv("ZZUF_DEBUGFD");
if(tmp)
#if defined _WIN32
_zz_debugfd = _open_osfhandle((HANDLE)atoi(tmp));
#else
_zz_debugfd = atoi(tmp);
#endif
/* We need this as soon as possible */
_zz_mem_init();

View File

@ -42,24 +42,18 @@ static void insert_funcs(void *);
HINSTANCE (WINAPI *LoadLibraryA_orig)(LPCSTR);
HINSTANCE WINAPI LoadLibraryA_new(LPCSTR path)
{
void *ret;
fprintf(stderr, "This is the diverted LoadLibraryA\n");
ret = LoadLibraryA_orig(path);
fprintf(stderr, "Now the real LoadLibraryA was called\n");
return ret;
return LoadLibraryA_orig(path);
}
BOOL (WINAPI *AllocConsole_orig)(void);
BOOL WINAPI AllocConsole_new(void)
{
fprintf(stderr, "Allocating console\n");
return AllocConsole_orig();
}
BOOL (WINAPI *AttachConsole_orig)(DWORD);
BOOL WINAPI AttachConsole_new(DWORD d)
{
fprintf(stderr, "Attaching console\n");
return AttachConsole_orig(d);
}
#endif