Add Logging utility for logging Http and Output calls
This commit is contained in:
parent
8f3192298d
commit
f432851d98
|
|
@ -0,0 +1,42 @@
|
||||||
|
#include "pch.h"
|
||||||
|
#include "Logger.h"
|
||||||
|
|
||||||
|
#pragma warning(disable : 4996)
|
||||||
|
|
||||||
|
HANDLE Logger::handle;
|
||||||
|
std::ofstream Logger::outputLog;
|
||||||
|
std::ofstream Logger::httpLog;
|
||||||
|
|
||||||
|
void Logger::Initialize(const std::string jobId)
|
||||||
|
{
|
||||||
|
AllocConsole();
|
||||||
|
freopen_s((FILE**)stdout, "CONOUT$", "w", stdout);
|
||||||
|
Logger::handle = CreateFileA("CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
|
SetStdHandle(STD_OUTPUT_HANDLE, Logger::handle);
|
||||||
|
|
||||||
|
Logger::outputLog = std::ofstream(jobId + std::string("-Output.txt"));
|
||||||
|
Logger::httpLog = std::ofstream(jobId + std::string("-Http.txt"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::Log(LogType type, const std::string message)
|
||||||
|
{
|
||||||
|
if (!handle) return;
|
||||||
|
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case LogType::Output:
|
||||||
|
outputLog << "[" << Logger::UtcTime() << "] " << message.c_str() << std::endl;
|
||||||
|
break;
|
||||||
|
case LogType::Http:
|
||||||
|
httpLog << "[" << Logger::UtcTime() << "] " << message.c_str() << std::endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Logger::UtcTime()
|
||||||
|
{
|
||||||
|
std::stringstream time;
|
||||||
|
std::time_t now = std::time(NULL);
|
||||||
|
time << std::put_time(std::localtime(&now), "%F %T");
|
||||||
|
return time.str();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "pch.h"
|
||||||
|
|
||||||
|
enum class LogType { Output, Http };
|
||||||
|
|
||||||
|
class Logger
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
static std::ofstream outputLog;
|
||||||
|
static std::ofstream httpLog;
|
||||||
|
public:
|
||||||
|
static HANDLE handle;
|
||||||
|
static void Initialize(const std::string jobId);
|
||||||
|
static void Log(LogType type, const std::string message);
|
||||||
|
static std::string UtcTime();
|
||||||
|
};
|
||||||
|
|
@ -158,6 +158,7 @@
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Config.h" />
|
<ClInclude Include="Config.h" />
|
||||||
|
<ClInclude Include="Logger.h" />
|
||||||
<ClInclude Include="LUrlParser.h" />
|
<ClInclude Include="LUrlParser.h" />
|
||||||
<ClInclude Include="Patches.h" />
|
<ClInclude Include="Patches.h" />
|
||||||
<ClInclude Include="pch.h" />
|
<ClInclude Include="pch.h" />
|
||||||
|
|
@ -166,6 +167,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="dllmain.cpp" />
|
<ClCompile Include="dllmain.cpp" />
|
||||||
|
<ClCompile Include="Logger.cpp" />
|
||||||
<ClCompile Include="LUrlParser.cpp">
|
<ClCompile Include="LUrlParser.cpp">
|
||||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
|
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
|
||||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
|
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,9 @@
|
||||||
<ClInclude Include="LUrlParser.h">
|
<ClInclude Include="LUrlParser.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="Logger.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="dllmain.cpp">
|
<ClCompile Include="dllmain.cpp">
|
||||||
|
|
@ -50,5 +53,8 @@
|
||||||
<ClCompile Include="LUrlParser.cpp">
|
<ClCompile Include="LUrlParser.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="Logger.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -1,12 +1,8 @@
|
||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "Config.h"
|
|
||||||
#include "RobloxMFCHooks.h"
|
#include "RobloxMFCHooks.h"
|
||||||
|
#include "Logger.h"
|
||||||
|
#include "Config.h"
|
||||||
#include "LUrlParser.h"
|
#include "LUrlParser.h"
|
||||||
|
|
||||||
static HANDLE handle;
|
|
||||||
static std::ofstream jobOutputLog;
|
|
||||||
static std::ofstream jobHttpLog;
|
|
||||||
|
|
||||||
static bool hasAuthUrlArg = false;
|
static bool hasAuthUrlArg = false;
|
||||||
static bool hasAuthTicketArg = false;
|
static bool hasAuthTicketArg = false;
|
||||||
static bool hasJoinArg = false;
|
static bool hasJoinArg = false;
|
||||||
|
|
@ -91,13 +87,7 @@ void __fastcall CRobloxCommandLineInfo__ParseParam_hook(CRobloxCommandLineInfo*
|
||||||
if (hasJobId && jobId.empty())
|
if (hasJobId && jobId.empty())
|
||||||
{
|
{
|
||||||
jobId = std::string(pszParam);
|
jobId = std::string(pszParam);
|
||||||
jobOutputLog = std::ofstream(jobId + std::string("-Output.txt"));
|
Logger::Initialize(jobId);
|
||||||
jobHttpLog = std::ofstream(jobId + std::string("-Http.txt"));
|
|
||||||
|
|
||||||
AllocConsole();
|
|
||||||
freopen_s((FILE**)stdout, "CONOUT$", "w", stdout);
|
|
||||||
handle = CreateFileA("CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
||||||
SetStdHandle(STD_OUTPUT_HANDLE, handle);
|
|
||||||
|
|
||||||
CCommandLineInfo__ParseLast(_this, bLast);
|
CCommandLineInfo__ParseLast(_this, bLast);
|
||||||
return;
|
return;
|
||||||
|
|
@ -174,7 +164,9 @@ BOOL __fastcall Http__trustCheck_hook(const char* url)
|
||||||
if (!parsedUrl.isValid())
|
if (!parsedUrl.isValid())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
jobHttpLog << url << std::endl;
|
#ifdef ARBITERBUILD
|
||||||
|
Logger::Log(LogType::Http, url);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (std::string("about:blank") == url)
|
if (std::string("about:blank") == url)
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -196,24 +188,24 @@ void __fastcall StandardOut__print_hook(void* _this, void*, int type, const std:
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case 1: // RBX::MESSAGE_OUTPUT:
|
case 1: // RBX::MESSAGE_OUTPUT:
|
||||||
jobOutputLog << "[RBX::MESSAGE_OUTPUT] " << message.c_str() << std::endl;
|
Logger::Log(LogType::Output, std::string("[MESSAGE_OUTPUT] ") + message);
|
||||||
SetConsoleTextAttribute(handle, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
|
SetConsoleTextAttribute(Logger::handle, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
|
||||||
break;
|
break;
|
||||||
case 0: // RBX::MESSAGE_INFO:
|
case 0: // RBX::MESSAGE_INFO:
|
||||||
jobOutputLog << "[RBX::MESSAGE_INFO] " << message.c_str() << std::endl;
|
Logger::Log(LogType::Output, std::string("[MESSAGE_INFO] ") + message);
|
||||||
SetConsoleTextAttribute(handle, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
|
SetConsoleTextAttribute(Logger::handle, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
|
||||||
break;
|
break;
|
||||||
case 2: // RBX::MESSAGE_WARNING:
|
case 2: // RBX::MESSAGE_WARNING:
|
||||||
jobOutputLog << "[RBX::MESSAGE_WARNING] " << message.c_str() << std::endl;
|
Logger::Log(LogType::Output, std::string("[MESSAGE_WARNING] ") + message);
|
||||||
SetConsoleTextAttribute(handle, FOREGROUND_RED | FOREGROUND_GREEN);
|
SetConsoleTextAttribute(Logger::handle, FOREGROUND_RED | FOREGROUND_GREEN);
|
||||||
break;
|
break;
|
||||||
case 3: // RBX::MESSAGE_ERROR:
|
case 3: // RBX::MESSAGE_ERROR:
|
||||||
jobOutputLog << "[RBX::MESSAGE_ERROR] " << message.c_str() << std::endl;
|
Logger::Log(LogType::Output, std::string("[MESSAGE_ERROR] ") + message);
|
||||||
SetConsoleTextAttribute(handle, FOREGROUND_RED | FOREGROUND_INTENSITY);
|
SetConsoleTextAttribute(Logger::handle, FOREGROUND_RED | FOREGROUND_INTENSITY);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
printf("%s\n", message.c_str());
|
printf("%s\n", message.c_str());
|
||||||
SetConsoleTextAttribute(handle, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
|
SetConsoleTextAttribute(Logger::handle, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
|
||||||
|
|
||||||
StandardOut__print(_this, type, message);
|
StandardOut__print(_this, type, message);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@
|
||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <iomanip>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
Loading…
Reference in New Issue