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 #else
# error no function diversion system for this platform # error no function diversion system for this platform
#endif #endif

View File

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

View File

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

View File

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