Skip to content
This repository was archived by the owner on Jun 22, 2020. It is now read-only.

Commit 3447998

Browse files
committed
Changed usage of _TCHAR to wchar_t
1 parent 93a16f0 commit 3447998

File tree

3 files changed

+31
-49
lines changed

3 files changed

+31
-49
lines changed

Eldorado.HttpProxy/include/Logger.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
#pragma once
2-
#include <tchar.h>
32
#include <utility>
43
#include <fstream>
54

65
class Logger
76
{
87
public:
9-
Logger(const _TCHAR* log_file);
8+
Logger(const wchar_t* log_file);
109
~Logger();
1110

1211
void Log(std::wstring message);
13-
void LogFormat(const _TCHAR* format, ...);
1412
void LogFormatA(const char* format, ...);
1513
void LogFormatW(const wchar_t* format, ...);
1614

Eldorado.HttpProxy/source/Logger.cpp

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <time.h>
44
#include <iomanip>
55

6-
Logger::Logger(const _TCHAR* log_file)
6+
Logger::Logger(const wchar_t* log_file)
77
{
88
log_stream.open(log_file, std::ios::out | std::ios::app);
99
}
@@ -18,23 +18,8 @@ void Logger::Log(std::wstring message)
1818
time_t time = std::time(nullptr);
1919
tm localtime;
2020
localtime_s(&localtime, &time);
21-
log_stream << _T("[") << std::put_time(&localtime, _T("%d.%m.%Y %H:%M:%S")) << _T("] ");
22-
log_stream << message.c_str() << _T("\n") << std::flush;
23-
}
24-
25-
void Logger::LogFormat(const _TCHAR* format, ...)
26-
{
27-
const int messageSize = 131072;
28-
_TCHAR message[messageSize];
29-
va_list args;
30-
va_start(args, format);
31-
_vstprintf_s(message, messageSize, format, args);
32-
time_t time = std::time(nullptr);
33-
tm localtime;
34-
localtime_s(&localtime, &time);
35-
log_stream << _T("[") << std::put_time(&localtime, _T("%d.%m.%Y %H:%M:%S")) << _T("] ");
36-
log_stream << message << _T("\n") << std::flush;
37-
va_end(args);
21+
log_stream << L"[" << std::put_time(&localtime, L"%d.%m.%Y %H:%M:%S") << L"] ";
22+
log_stream << message.c_str() << L"\n" << std::flush;
3823
}
3924

4025
void Logger::LogFormatA(const char* format, ...)

Eldorado.HttpProxy/source/main.cpp

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
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

234233
Logger& theLogger() {
235-
static Logger logger = Logger(_T("winhttp.log"));
234+
static Logger logger = Logger(L"winhttp.log");
236235
return logger;
237236
}
238237

239238
void 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

245244
void Exit()
246245
{
247-
Exit(_T(""));
246+
Exit(L"");
248247
}
249248

250249
template<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

261260
void 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

278277
HMODULE 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

295294
void 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

307306
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD reason, LPVOID /*reserved*/)

0 commit comments

Comments
 (0)