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

Commit 7f154e4

Browse files
committed
Implemented dumping raw WinHttpReadData results.
1 parent 58650c8 commit 7f154e4

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

Eldorado.HttpProxy/include/Logger.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
2-
#include <utility>
32
#include <fstream>
3+
#include <mutex>
44

55
class Logger
66
{
@@ -11,8 +11,9 @@ class Logger
1111
void Log(std::wstring message);
1212
void LogFormatA(const char* format, ...);
1313
void LogFormatW(const wchar_t* format, ...);
14-
14+
void LogRawData(std::wstring filename, const char* data, const int dataLength);
1515
private:
1616
std::wofstream log_stream;
17+
std::mutex log_mutex;
1718
};
1819

Eldorado.HttpProxy/module/winhttp.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ LIBRARY
22

33
EXPORTS
44
WinHttpCloseHandle @8
5-
WinHttpConnect @9
5+
WinHttpConnect @9
66
WinHttpOpen @16
77
WinHttpOpenRequest @17
88
WinHttpQueryHeaders @20
0 Bytes
Binary file not shown.

Eldorado.HttpProxy/source/Logger.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#include "Logger.h"
2+
#include <fstream>
3+
#include <iomanip>
24
#include <stdarg.h>
35
#include <time.h>
4-
#include <iomanip>
6+
#include <Windows.h>
57

68
Logger::Logger(const wchar_t* log_file)
79
{
@@ -45,4 +47,25 @@ void Logger::LogFormatW(const wchar_t* format, ...)
4547
vswprintf_s(message, messageSize, format, args);
4648
Log(message);
4749
va_end(args);
50+
}
51+
52+
void Logger::LogRawData(std::wstring filePrefix, const char* data, const int dataLength)
53+
{
54+
std::wstring filePath = L"winhttp";
55+
CreateDirectory(filePath.c_str(), nullptr);
56+
wchar_t tempFilePath[MAX_PATH];
57+
GetTempFileName(filePath.c_str(), filePrefix.c_str(), 0, tempFilePath);
58+
59+
LogFormatW(L"Logging raw data to %s", tempFilePath);
60+
61+
std::ofstream outfile;
62+
outfile.open(tempFilePath, std::ios::binary | std::ios::out);
63+
if (!outfile.is_open())
64+
{
65+
LogFormatW(L"Logging raw data to %s failed. Could not create temporary file.", tempFilePath);
66+
return;
67+
}
68+
outfile.write(data, dataLength);
69+
LogFormatW(L"Logged %d bytes raw data to %s", dataLength, tempFilePath);
70+
outfile.close();
4871
}

Eldorado.HttpProxy/source/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ BOOL WINAPI WinHttpReadData(
158158
BOOL result = oWinHttpReadData(hRequest, lpBuffer, dwNumberOfBytesToRead, lpdwNumberOfBytesRead);
159159
std::string readData = std::string(static_cast<char*>(lpBuffer), dwNumberOfBytesToRead);
160160
theLogger().LogFormatA("WinHttpReadData(%x, ...) returend: %s", hRequest, readData.c_str());
161+
theLogger().LogRawData(L"rd_", reinterpret_cast<const char*>(lpBuffer), dwNumberOfBytesToRead);
161162
return result;
162163
}
163164

0 commit comments

Comments
 (0)