Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
#include <shlobj.h>
#include <time.h>
#include "Log.h"
#include <regex>

#define VERSION "2.10.0"
39 changes: 38 additions & 1 deletion src/Diag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,39 @@ void Diag::GetDir ( std::string directory )

Log::WriteFileToLog ( files[FILE_TEMP].c_str(), ( directory + " directory listing" ) ); // write the result to the log file with a description
}
bool CensorIPv6InFile(const std::string& filePath)
{
std::ifstream in(filePath, std::ios::in | std::ios::binary);
if (!in.is_open())
{
Log::WriteStringToLog("**** CensorIPv6InFile: Unable to open file for reading");
return false;
}

std::stringstream buffer;
buffer << in.rdbuf();
std::string content = buffer.str();
in.close();

// It's enough for ipconfig output
static const std::regex ipv6Regex(
R"(\b([0-9a-fA-F]{1,4}:){2,7}[0-9a-fA-F]{1,4}\b)"
);

content = std::regex_replace(content, ipv6Regex, "[IPv6 CENSORED]");

std::ofstream out(filePath, std::ios::out | std::ios::binary | std::ios::trunc);
if (!out.is_open())
{
Log::WriteStringToLog("**** CensorIPv6InFile: Unable to open file for writing");
return false;
}

out << content;
out.close();

return true;
}
DWORD Diag::DoSystemCommandWithOutput ( std::string command, int outputType, DWORD maxTimeMs )
{
Log::WriteDividerToLog();
Expand Down Expand Up @@ -757,7 +789,12 @@ DWORD Diag::DoSystemCommandWithOutput ( std::string command, int outputType, DWO
}

CloseHandle( h );

// Censor IPv6 ONLY if command contains ipconfig
if (command.find("ipconfig") != std::string::npos ||
command.find("IPCONFIG") != std::string::npos)
{
CensorIPv6InFile(files[FILE_TEMP]);
}
if ( outputType != OUTPUT_UNICODE )
{
Log::WriteFileToLog ( files[FILE_TEMP], ss.str() ); // write the result to the log file with the passed command argument as a description
Expand Down