11#include < string>
22
33#include < Windows.h>
4- #include < tchar.h>
54#include " Logger.h"
65
76#include " winhttp_functions.h"
@@ -32,7 +31,7 @@ BOOL WINAPI WinHttpCloseHandle(
3231 IN HINTERNET hInternet
3332 )
3433{
35- theLogger ().LogFormat ( _T ( " Calling WinHttpCloseHandle(%x)" ) , hInternet);
34+ theLogger ().LogFormatW ( L " Calling WinHttpCloseHandle(%x)" , hInternet);
3635 return oWinHttpCloseHandle (hInternet);
3736}
3837
@@ -43,9 +42,9 @@ HINTERNET WINAPI WinHttpConnect(
4342 IN DWORD dwReserved
4443 )
4544{
46- theLogger ().LogFormat ( _T ( " Calling WinHttpConnect(%x, %s, %d)" ) , hSession, pswzServerName, nServerPort);
45+ theLogger ().LogFormatW ( L " Calling WinHttpConnect(%x, %s, %d)" , hSession, pswzServerName, nServerPort);
4746 HINTERNET result = oWinHttpConnect (hSession, pswzServerName, nServerPort, dwReserved);
48- theLogger ().LogFormat ( _T ( " WinHttpConnect(%x, %s, %d) returned %x" ) , hSession, pswzServerName, nServerPort, result);
47+ theLogger ().LogFormatW ( L " WinHttpConnect(%x, %s, %d) returned %x" , hSession, pswzServerName, nServerPort, result);
4948 return result;
5049}
5150
@@ -57,9 +56,9 @@ HINTERNET WINAPI WinHttpOpen(
5756 _In_ DWORD dwFlags
5857 )
5958{
60- theLogger ().LogFormat ( _T ( " Calling WinHttpOpen(...)" ) );
59+ theLogger ().LogFormatW ( L " Calling WinHttpOpen(...)" );
6160 HINTERNET result = oWinHttpOpen (pszAgentW, dwAccessType, pszProxyW, pszProxyBypassW, dwFlags);
62- theLogger ().LogFormat ( _T ( " WinHttpOpen(...) returned %x" ), result) ;
61+ theLogger ().LogFormatW ( L " WinHttpOpen(...) returned %x" ), result;
6362 return result;
6463}
6564
@@ -90,7 +89,7 @@ HINTERNET WINAPI WinHttpOpenRequest(
9089 pwszReferrer,
9190 ppwszAcceptTypes,
9291 dwFlags);
93- theLogger ().LogFormat ( _T ( " WinHttpOpenRequest(%x, ...) returned %x" ) , hConnect, result);
92+ theLogger ().LogFormatW ( L " WinHttpOpenRequest(%x, ...) returned %x" , hConnect, result);
9493 return result;
9594}
9695
@@ -144,7 +143,7 @@ BOOL WINAPI WinHttpQueryOption(
144143 IN OUT LPDWORD lpdwBufferLength
145144 )
146145{
147- theLogger ().LogFormat ( _T ( " Calling WinHttpQueryOption(%x, %d, ...)" ) , hInternet, dwOption);
146+ theLogger ().LogFormatW ( L " Calling WinHttpQueryOption(%x, %d, ...)" , hInternet, dwOption);
148147 return oWinHttpQueryOption (hInternet, dwOption, lpBuffer, lpdwBufferLength);
149148}
150149
@@ -155,7 +154,7 @@ BOOL WINAPI WinHttpReadData(
155154 OUT LPDWORD lpdwNumberOfBytesRead
156155 )
157156{
158- theLogger ().LogFormat ( _T ( " Calling WinHttpReadData(%x, ...)" ) , hRequest);
157+ theLogger ().LogFormatW ( L " Calling WinHttpReadData(%x, ...)" , hRequest);
159158 BOOL result = oWinHttpReadData (hRequest, lpBuffer, dwNumberOfBytesToRead, lpdwNumberOfBytesRead);
160159 std::string readData = std::string (static_cast <char *>(lpBuffer), dwNumberOfBytesToRead);
161160 theLogger ().LogFormatA (" WinHttpReadData(%x, ...) returend: %s" , hRequest, readData.c_str ());
@@ -167,7 +166,7 @@ BOOL WINAPI WinHttpReceiveResponse(
167166 IN LPVOID lpReserved
168167 )
169168{
170- theLogger ().LogFormat ( _T ( " Calling WinHttpReceiveResponse(%x, ...)" ) , hRequest);
169+ theLogger ().LogFormatW ( L " Calling WinHttpReceiveResponse(%x, ...)" , hRequest);
171170 return oWinHttpReceiveResponse (hRequest, lpReserved);
172171}
173172
@@ -181,7 +180,7 @@ BOOL WINAPI WinHttpSendRequest(
181180 IN DWORD_PTR dwContext
182181 )
183182{
184- theLogger ().LogFormat ( _T ( " Calling WinHttpSendRequest(%x, ...)" ) , hRequest);
183+ theLogger ().LogFormatW ( L " Calling WinHttpSendRequest(%x, ...)" , hRequest);
185184
186185 std::wstring header = dwHeadersLength == -1 ? std::wstring (lpszHeaders) : std::wstring (lpszHeaders, dwHeadersLength);
187186 theLogger ().LogFormatW (L" WinHttpSendRequest(%x, ...) called with header: %s" , hRequest, header.c_str ());
@@ -207,7 +206,7 @@ WINHTTP_STATUS_CALLBACK WINAPI WinHttpSetStatusCallback(
207206 IN DWORD_PTR dwReserved
208207 )
209208{
210- theLogger ().LogFormat ( _T ( " Calling WinHttpSetStatusCallback(%x, ...)" ) , hInternet);
209+ theLogger ().LogFormatW ( L " Calling WinHttpSetStatusCallback(%x, ...)" , hInternet);
211210 return oWinHttpSetStatusCallback (hInternet, lpfnInternetCallback, dwNotificationFlags, dwReserved);
212211}
213212
@@ -219,8 +218,8 @@ BOOL WINAPI WinHttpSetTimeouts(
219218 IN int nReceiveTimeout
220219 )
221220{
222- theLogger ().LogFormat (
223- _T ( " Calling WinHttpSetTimeouts(%x, %d, %d, %d, %d)" ) ,
221+ theLogger ().LogFormatW (
222+ L " Calling WinHttpSetTimeouts(%x, %d, %d, %d, %d)" ,
224223 hInternet,
225224 nResolveTimeout,
226225 nConnectTimeout,
@@ -232,19 +231,19 @@ BOOL WINAPI WinHttpSetTimeouts(
232231// dll functions
233232
234233Logger& theLogger () {
235- static Logger logger = Logger (_T ( " winhttp.log" ) );
234+ static Logger logger = Logger (L " winhttp.log" );
236235 return logger;
237236}
238237
239238void Exit (TCHAR* reason)
240239{
241- theLogger ().LogFormat ( _T ( " Exit called with reason (%s)" ) , reason);
240+ theLogger ().LogFormatW ( L " Exit called with reason (%s)" , reason);
242241 ExitProcess (1 );
243242}
244243
245244void Exit ()
246245{
247- Exit (_T ( " " ) );
246+ Exit (L" " );
248247}
249248
250249template <typename FunctionPointerType>
@@ -253,14 +252,14 @@ void SetOriginalDllFunctionAddress(const CHAR* originalFunctionName, FunctionPoi
253252 FARPROC originalFunctionAddress = GetProcAddress (g_original_dll_hInstance, originalFunctionName);
254253 if (!originalFunctionAddress)
255254 {
256- Exit (_T ( " Unable to get an original function address" ) );
255+ Exit (L " Unable to get an original function address" );
257256 }
258257 pFunctionPointer = reinterpret_cast <FunctionPointerType>(originalFunctionAddress);
259258}
260259
261260void InitializeOriginalDllFunctions ()
262261{
263- theLogger ().LogFormat ( _T ( " Initializing original function addresses" ) );
262+ theLogger ().LogFormatW ( L " Initializing original function addresses" );
264263 SetOriginalDllFunctionAddress (" WinHttpCloseHandle" , oWinHttpCloseHandle);
265264 SetOriginalDllFunctionAddress (" WinHttpConnect" , oWinHttpConnect);
266265 SetOriginalDllFunctionAddress (" WinHttpOpen" , oWinHttpOpen);
@@ -272,36 +271,36 @@ void InitializeOriginalDllFunctions()
272271 SetOriginalDllFunctionAddress (" WinHttpSendRequest" , oWinHttpSendRequest);
273272 SetOriginalDllFunctionAddress (" WinHttpSetStatusCallback" , oWinHttpSetStatusCallback);
274273 SetOriginalDllFunctionAddress (" WinHttpSetTimeouts" , oWinHttpSetTimeouts);
275- theLogger ().LogFormat ( _T ( " Original function addresses initialized" ) );
274+ theLogger ().LogFormatW ( L " Original function addresses initialized" );
276275}
277276
278277HMODULE LoadOriginalDll ()
279278{
280- theLogger ().LogFormat ( _T ( " Loading the original winhttp.dll" ) );
279+ theLogger ().LogFormatW ( L " Loading the original winhttp.dll" );
281280 TCHAR original_dll_path_buffer[MAX_PATH];
282281 GetSystemDirectory (original_dll_path_buffer, MAX_PATH);
283- _tcscat_s (original_dll_path_buffer, MAX_PATH, _T ( " \\ winhttp.dll" ));
282+ wcscat_s (original_dll_path_buffer, MAX_PATH, L "\\ winhttp.dll" );
284283
285284 HMODULE original_dll_hInstance = LoadLibrary (original_dll_path_buffer);
286285 if (!original_dll_hInstance)
287286 {
288- Exit (_T ( " Unable to load the original winhttp.dll" ) );
287+ Exit (L " Unable to load the original winhttp.dll" );
289288 }
290289
291- theLogger ().LogFormat ( _T ( " Original winhttp.dll was loaded successfully" ) );
290+ theLogger ().LogFormatW ( L " Original winhttp.dll was loaded successfully" );
292291 return original_dll_hInstance;
293292}
294293
295294void InitializeDll (HINSTANCE hInstance)
296295{
297- theLogger ().LogFormat ( _T ( " ( " ###############################################" ) );
298- theLogger().LogFormat(_T( " Initializing the winhttp proxy dll" ) );
296+ theLogger ().LogFormatW ( L" ###############################################" );
297+ theLogger ().LogFormatW ( L " Initializing the winhttp proxy dll" );
299298 DisableThreadLibraryCalls (hInstance);
300299 g_proxy_dll_hInstance = hInstance;
301300 g_original_dll_hInstance = LoadOriginalDll ();
302301 InitializeOriginalDllFunctions ();
303- theLogger().LogFormat(_T( " Proxy dll initialized" ) );
304- theLogger().LogFormat(_T( " ( " ###############################################" ) );
302+ theLogger ().LogFormatW ( L " Proxy dll initialized" );
303+ theLogger ().LogFormatW ( L" ###############################################" );
305304}
306305
307306BOOL WINAPI DllMain (HINSTANCE hInstance, DWORD reason, LPVOID /* reserved*/ )
0 commit comments